Tests: Optionally configure tests exclusively, with an external CMake

Add an undocumented CMake_TEST_EXTERNAL_CMAKE option to name an external
CMake 'bin' directory.  Skip all main CMake binary builds and instead
configure the Tests directory to run using the external CMake provided.
This will provide a means to exercise the CMake test suite generating
for target platforms and compilers with which the CMake source does not
build.  That will allow us to raise the level of C++ features required
of a compiler to build our source while retaining tests for generating
projects with older compiler tools.
This commit is contained in:
Brad King 2014-03-03 15:24:03 -05:00
parent 9f5bd180c8
commit 9608ef6f40
2 changed files with 195 additions and 155 deletions

View File

@ -21,7 +21,9 @@ if(CMAKE_BOOTSTRAP)
unset(CMAKE_BOOTSTRAP CACHE) unset(CMAKE_BOOTSTRAP CACHE)
endif() endif()
set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin) if(NOT CMake_TEST_EXTERNAL_CMAKE)
set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
endif()
if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# Disallow architecture-specific try_run. It may not run on the host. # Disallow architecture-specific try_run. It may not run on the host.
@ -102,9 +104,11 @@ endmacro()
set(CMAKE_BUILD_ON_VISUAL_STUDIO 0) if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW ) set(CMAKE_BUILD_ON_VISUAL_STUDIO 0)
if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW )
set(CMAKE_BUILD_ON_VISUAL_STUDIO 1) set(CMAKE_BUILD_ON_VISUAL_STUDIO 1)
endif()
endif() endif()
@ -126,10 +130,20 @@ macro(CMAKE_SETUP_TESTING)
# the ctest from this cmake is used for testing # the ctest from this cmake is used for testing
# and not the ctest from the cmake building and testing # and not the ctest from the cmake building and testing
# cmake. # cmake.
if(CMake_TEST_EXTERNAL_CMAKE)
set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
foreach(exe cmake ctest cpack)
add_executable(${exe} IMPORTED)
set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
endforeach()
else()
set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest") set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake") set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack") set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
endif() endif()
endif()
# configure some files for testing # configure some files for testing
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
@ -362,7 +376,8 @@ macro (CMAKE_BUILD_UTILITIES)
endmacro () endmacro ()
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD") if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} execute_process(COMMAND ${CMAKE_CXX_COMPILER}
${CMAKE_CXX_COMPILER_ARG1} -dumpversion ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
OUTPUT_VARIABLE _GXX_VERSION OUTPUT_VARIABLE _GXX_VERSION
@ -375,6 +390,7 @@ if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
"Please use GXX 4.2 or greater to build CMake on OpenBSD\n" "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
"${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}") "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
endif() endif()
endif()
endif() endif()
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
@ -392,31 +408,33 @@ include (${CMAKE_ROOT}/Modules/Dart.cmake)
set_directory_properties(PROPERTIES set_directory_properties(PROPERTIES
TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake") TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
# where to write the resulting executables and libraries if(NOT CMake_TEST_EXTERNAL_CMAKE)
set(BUILD_SHARED_LIBS OFF) # where to write the resulting executables and libraries
set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.") set(BUILD_SHARED_LIBS OFF)
set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
"Where to put the libraries for CMake") "Where to put the libraries for CMake")
# The CMake executables usually do not need any rpath to run in the build or # The CMake executables usually do not need any rpath to run in the build or
# install tree. # install tree.
set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.") set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
# Load install destinations. # Load install destinations.
include(Source/CMakeInstallDestinations.cmake) include(Source/CMakeInstallDestinations.cmake)
if(BUILD_TESTING) if(BUILD_TESTING)
include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake) include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
endif()
# include special compile flags for some compilers
include(CompileFlags.cmake)
# no clue why we are testing for this here
include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
endif() endif()
# include special compile flags for some compilers
include(CompileFlags.cmake)
# no clue why we are testing for this here
include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
# CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
# #
# If not defined or "", this variable defaults to the server at # If not defined or "", this variable defaults to the server at
@ -434,23 +452,24 @@ if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
set(CMAKE_TESTS_CDASH_SERVER "http://www.cdash.org/CDash") set(CMAKE_TESTS_CDASH_SERVER "http://www.cdash.org/CDash")
endif() endif()
# build the utilities (a macro defined in this file) if(NOT CMake_TEST_EXTERNAL_CMAKE)
CMAKE_BUILD_UTILITIES() # build the utilities (a macro defined in this file)
CMAKE_BUILD_UTILITIES()
# On NetBSD ncurses is required, since curses doesn't have the wsyncup() # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
# function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib, # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
# which isn't in the default linker search path. So without RPATH ccmake # which isn't in the default linker search path. So without RPATH ccmake
# doesn't run and the build doesn't succeed since ccmake is executed for # doesn't run and the build doesn't succeed since ccmake is executed for
# generating the documentation. # generating the documentation.
if(BUILD_CursesDialog) if(BUILD_CursesDialog)
get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH) get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
set(CURSES_NEED_RPATH FALSE) set(CURSES_NEED_RPATH FALSE)
if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64") if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64")
set(CURSES_NEED_RPATH TRUE) set(CURSES_NEED_RPATH TRUE)
endif() endif()
endif() endif()
if(BUILD_QtDialog) if(BUILD_QtDialog)
if(APPLE) if(APPLE)
set(CMAKE_BUNDLE_VERSION set(CMAKE_BUNDLE_VERSION
"${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}") "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
@ -470,33 +489,35 @@ if(BUILD_QtDialog)
if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64") if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64")
set(QT_NEED_RPATH TRUE) set(QT_NEED_RPATH TRUE)
endif() endif()
endif() endif()
# The same might be true on other systems for other libraries. # The same might be true on other systems for other libraries.
# Then only enable RPATH if we have are building at least with cmake 2.4, # Then only enable RPATH if we have are building at least with cmake 2.4,
# since this one has much better RPATH features than cmake 2.2. # since this one has much better RPATH features than cmake 2.2.
# The executables are then built with the RPATH for the libraries outside # The executables are then built with the RPATH for the libraries outside
# the build tree, which is both the build and the install RPATH. # the build tree, which is both the build and the install RPATH.
if (UNIX) if (UNIX)
if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH) OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.") set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif() endif()
endif () endif ()
# add the uninstall support # add the uninstall support
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
@ONLY) @ONLY)
add_custom_target(uninstall add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
include (CMakeCPack.cmake) include (CMakeCPack.cmake)
endif()
# setup some Testing support (a macro defined in this file) # setup some Testing support (a macro defined in this file)
CMAKE_SETUP_TESTING() CMAKE_SETUP_TESTING()
@ -505,7 +526,8 @@ configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/DartLocal.conf" "${CMAKE_CURRENT_BINARY_DIR}/DartLocal.conf"
COPYONLY) COPYONLY)
if(NOT CMake_VERSION_IS_RELEASE) if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(NOT CMake_VERSION_IS_RELEASE)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND
NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
@ -527,30 +549,35 @@ if(NOT CMake_VERSION_IS_RELEASE)
unset(C_FLAGS_LIST) unset(C_FLAGS_LIST)
unset(CXX_FLAGS_LIST) unset(CXX_FLAGS_LIST)
endif() endif()
endif()
# build the remaining subdirectories
add_subdirectory(Source)
add_subdirectory(Utilities)
endif() endif()
# build the remaining subdirectories
add_subdirectory(Source)
add_subdirectory(Utilities)
add_subdirectory(Tests) add_subdirectory(Tests)
if(BUILD_TESTING) if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(BUILD_TESTING)
CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests") CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
endif() endif()
CMAKE_SET_TARGET_FOLDER(cmw9xcom "Utilities/Win9xCompat") CMAKE_SET_TARGET_FOLDER(cmw9xcom "Utilities/Win9xCompat")
if(TARGET documentation) if(TARGET documentation)
CMAKE_SET_TARGET_FOLDER(documentation "Documentation") CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
endif()
endif() endif()
# add a test # add a test
add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}" add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
--system-information -G "${CMAKE_GENERATOR}" ) --system-information -G "${CMAKE_GENERATOR}" )
# Install license file as it requires. if(NOT CMake_TEST_EXTERNAL_CMAKE)
install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR}) # Install license file as it requires.
install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
# Install script directories. # Install script directories.
install( install(
DIRECTORY Help Modules Templates DIRECTORY Help Modules Templates
DESTINATION ${CMAKE_DATA_DIR} DESTINATION ${CMAKE_DATA_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
@ -562,5 +589,6 @@ install(
WORLD_READ WORLD_EXECUTE WORLD_READ WORLD_EXECUTE
) )
# Install auxiliary files integrating with other tools. # Install auxiliary files integrating with other tools.
add_subdirectory(Auxiliary) add_subdirectory(Auxiliary)
endif()

View File

@ -57,9 +57,11 @@ if(BUILD_TESTING)
set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}") set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
endif() endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles" OR ("${CMAKE_GENERATOR}" MATCHES Ninja AND NOT WIN32)) if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles" OR ("${CMAKE_GENERATOR}" MATCHES Ninja AND NOT WIN32))
set(TEST_CompileCommandOutput 1) set(TEST_CompileCommandOutput 1)
endif() endif()
endif()
set(MAKE_IS_GNU ) set(MAKE_IS_GNU )
if(CMAKE_MAKE_PROGRAM MATCHES make) if(CMAKE_MAKE_PROGRAM MATCHES make)
@ -95,13 +97,17 @@ if(BUILD_TESTING)
list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}) list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
endif() endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
add_subdirectory(CMakeLib) add_subdirectory(CMakeLib)
endif()
add_subdirectory(CMakeOnly) add_subdirectory(CMakeOnly)
add_subdirectory(RunCMake) add_subdirectory(RunCMake)
add_subdirectory(FindPackageModeMakefileTest) add_subdirectory(FindPackageModeMakefileTest)
if(NOT CMake_TEST_EXTERNAL_CMAKE)
add_subdirectory(CTestTestMemcheck) add_subdirectory(CTestTestMemcheck)
endif()
# Collect a list of all test build directories. # Collect a list of all test build directories.
set(TEST_BUILD_DIRS) set(TEST_BUILD_DIRS)
@ -248,7 +254,9 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(SetLang SetLang) ADD_TEST_MACRO(SetLang SetLang)
ADD_TEST_MACRO(EmptyProperty EmptyProperty) ADD_TEST_MACRO(EmptyProperty EmptyProperty)
ADD_TEST_MACRO(ExternalOBJ ExternalOBJ) ADD_TEST_MACRO(ExternalOBJ ExternalOBJ)
if(NOT CMake_TEST_EXTERNAL_CMAKE)
ADD_TEST_MACRO(LoadCommand LoadedCommand) ADD_TEST_MACRO(LoadCommand LoadedCommand)
endif()
ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory) ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory)
ADD_TEST_MACRO(LinkLanguage LinkLanguage) ADD_TEST_MACRO(LinkLanguage LinkLanguage)
ADD_TEST_MACRO(LinkLine LinkLine) ADD_TEST_MACRO(LinkLine LinkLine)
@ -1018,6 +1026,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
"${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures") "${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures")
endif() endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
add_test(LoadedCommandOneConfig ${CMAKE_CTEST_COMMAND} add_test(LoadedCommandOneConfig ${CMAKE_CTEST_COMMAND}
--build-and-test --build-and-test
"${CMake_SOURCE_DIR}/Tests/LoadCommandOneConfig" "${CMake_SOURCE_DIR}/Tests/LoadCommandOneConfig"
@ -1028,6 +1037,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
--test-command LoadedCommand --test-command LoadedCommand
) )
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig") list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig")
endif()
add_test(complex ${CMAKE_CTEST_COMMAND} add_test(complex ${CMAKE_CTEST_COMMAND}
--build-and-test --build-and-test
@ -2771,5 +2781,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
WORKING_DIRECTORY ${CMake_BINARY_DIR}/Utilities/KWStyle) WORKING_DIRECTORY ${CMake_BINARY_DIR}/Utilities/KWStyle)
endif() endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
add_subdirectory(CMakeTests) add_subdirectory(CMakeTests)
endif()
endif() endif()