# a macro for tests that have a simple format where the name matches the
# directory and project
macro(ADD_TEST_MACRO NAME)
if(${ARGC} GREATER 1)
set(_test_command --test-command ${ARGN})
endif()
string(REPLACE "." "/" dir "${NAME}")
string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
add_test(NAME "${NAME}" COMMAND "${CMAKE_CTEST_COMMAND}"
--build-and-test
"${CMake_SOURCE_DIR}/Tests/${dir}"
"${CMake_BINARY_DIR}/Tests/${dir}"
--build-two-config
${build_generator_args}
--build-project ${proj}
${${NAME}_CTEST_OPTIONS}
--build-options
${${NAME}_BUILD_OPTIONS}
${_test_command})
unset(_test_command)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${dir}")
endmacro()
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckSwift.cmake)
# Fake a user home directory to avoid polluting the real one.
if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
file(MAKE_DIRECTORY "${TEST_HOME}")
file(WRITE "${TEST_HOME}/.cvspass" ":pserver:anoncvs@www.cmake.org:/cvsroot/KWSys A\n")
set(TEST_HOME_ENV_CODE "# Fake a user home directory to avoid polluting the real one.
# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
# need access to the real HOME directory.
if(NOT DEFINED ENV{CTEST_REAL_HOME})
set(ENV{CTEST_REAL_HOME} \"\$ENV{HOME}\")
endif()
set(ENV{HOME} \"${TEST_HOME}\")
")
endif()
# 3.9 or later provides a definitive answer to whether we are multi-config
# through a global property. Prior to 3.9, CMAKE_CONFIGURATION_TYPES being set
# is assumed to mean multi-config, but developers might modify it so it is
# technically not as reliable.
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
elseif(CMAKE_CONFIGURATION_TYPES)
set(_isMultiConfig True)
else()
set(_isMultiConfig False)
endif()
# Choose a default configuration for CTest tests.
set(CTestTest_CONFIG Debug)
if(NOT _isMultiConfig AND CMAKE_BUILD_TYPE)
set(CTestTest_CONFIG ${CMAKE_BUILD_TYPE})
endif()
configure_file(${CMake_SOURCE_DIR}/Tests/EnforceConfig.cmake.in
${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake @ONLY)
# Testing
if(BUILD_TESTING)
set(CMake_TEST_DEVENV "")
if(CMAKE_VS_DEVENV_COMMAND)
set(CMake_TEST_DEVENV "${CMAKE_VS_DEVENV_COMMAND}")
elseif(CMAKE_GENERATOR MATCHES "Visual Studio 9 " AND
NOT CMAKE_MAKE_PROGRAM MATCHES "[mM][sS][bB][uU][iI][lL][dD]\\.[eE][xX][eE]")
set(CMake_TEST_DEVENV "${CMAKE_MAKE_PROGRAM}")
endif()
if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "")
else()
set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles" OR ("${CMAKE_GENERATOR}" MATCHES Ninja AND NOT WIN32))
set(TEST_CompileCommandOutput 1)
endif()
endif()
set(MAKE_IS_GNU )
if(CMAKE_MAKE_PROGRAM MATCHES make)
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} no_such_target --version
RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_VARIABLE out)
if("${res}" STREQUAL "0")
if("${out}" MATCHES "GNU")
set(MAKE_IS_GNU 1)
endif()
endif()
endif()
# some old versions of make simply cannot handle spaces in paths
if (MAKE_IS_GNU OR
CMAKE_MAKE_PROGRAM MATCHES "nmake|gmake|wmake" OR
CMAKE_GENERATOR MATCHES "Visual Studio|Xcode|Borland")
set(MAKE_SUPPORTS_SPACES 1)
else()
set(MAKE_SUPPORTS_SPACES 0)
endif()
# assume no resources building to test
set(CMake_TEST_RESOURCES FALSE)
# for windows and cygwin assume we have resources
if(WIN32 OR CYGWIN)
set(CMake_TEST_RESOURCES TRUE)
endif()
# for borland and watcom there is no resource support
if(WATCOM OR BORLAND)
set(CMake_TEST_RESOURCES FALSE)
endif()
set(build_generator_args
--build-generator ${CMAKE_GENERATOR}
)
if(CMAKE_GENERATOR_PLATFORM)
list(APPEND build_generator_args
--build-generator-platform ${CMAKE_GENERATOR_PLATFORM}
)
endif()
if(CMAKE_GENERATOR_TOOLSET)
list(APPEND build_generator_args
--build-generator-toolset ${CMAKE_GENERATOR_TOOLSET}
)
endif()
if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
list(APPEND build_generator_args
--build-makeprogram ${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
)
endif()
# Look for rpmbuild to use for tests.
# The tool does not work with spaces in the path.
if(NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
find_program(RPMBUILD_EXECUTABLE NAMES rpmbuild)
else()
set(RPMBUILD_EXECUTABLE "RPMBUILD_EXECUTABLE-NOTFOUND")
endif()
if(RPMBUILD_EXECUTABLE)
set(CPACK_BINARY_RPM ON)
else()
set(CPACK_BINARY_RPM OFF)
endif()
# Look for dpkg to use for tests.
find_program(DPKG_EXECUTABLE NAMES dpkg)
if(DPKG_EXECUTABLE)
set(CPACK_BINARY_DEB ON)
else()
set(CPACK_BINARY_DEB OFF)
endif()
# Look for NuGet to use for tests.
find_program(NUGET_EXECUTABLE NAMES NuGet nuget)
if(NUGET_EXECUTABLE)
set(CPACK_BINARY_NUGET ON)
else()
set(CPACK_BINARY_NUGET OFF)
endif()
if(WIN32)
# Macro to search for available Windows CE SDKs in the windows Registry
macro(select_wince_sdk selected_reg selected_sdk)
if(CMAKE_HOST_WIN32)
execute_process(COMMAND reg QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs"
OUTPUT_VARIABLE sdk_reg
ERROR_VARIABLE my_err)
string(REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\Windows CE Tools\\\\SDKs\\\\" ";" sdk_list "${sdk_reg}")
list(LENGTH sdk_list sdk_list_len)
if (${sdk_list_len} GREATER 1)
list(GET sdk_list 1 _sdk) # The first entry is always empty due to the regex replace above
string(STRIP ${_sdk} _sdk) # Make sure there is no newline in the SDK name
endif()
# Build a key to be used by get_filename_component that is pointing to the SDK directory
set(_reg "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs\\${_sdk}]")
# Set return values
set(${selected_reg} ${_reg})
set(${selected_sdk} ${_sdk})
endif(CMAKE_HOST_WIN32)
endmacro(select_wince_sdk)
set(reg_vs10 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0;InstallDir]")
set(reg_vs11 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0;InstallDir]")
set(reg_vs12 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0;InstallDir]")
set(reg_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0;InstallDir]")
set(reg_ws80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]")
set(reg_ws81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]")
set(reg_ws10_0 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\Setup\\Build Tools for Windows 10;srcPath]")
set(reg_wp80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.0;InstallationFolder]")
set(reg_wp81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.1;InstallationFolder]")
select_wince_sdk(reg_wince wince_sdk)
set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]")
foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
get_filename_component(r "${reg_${reg}}" ABSOLUTE)
if(IS_DIRECTORY "${r}" AND NOT "${r}" STREQUAL "/registry")
set(${reg} 1)
else()