diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:20:25 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:20:25 +0900 |
commit | 50e508f0913d5580aa156327527da3d29a66b90c (patch) | |
tree | d581ffbad59a2becc33bc79e75e504de500a8e93 /Modules | |
parent | 37869418c616f7e57c34b9287c4c8f3671df20de (diff) | |
download | cmake-50e508f0913d5580aa156327527da3d29a66b90c.tar.gz cmake-50e508f0913d5580aa156327527da3d29a66b90c.tar.bz2 cmake-50e508f0913d5580aa156327527da3d29a66b90c.zip |
Imported Upstream version 3.19.0upstream/3.19.0
Diffstat (limited to 'Modules')
189 files changed, 4012 insertions, 2041 deletions
diff --git a/Modules/AndroidTestUtilities.cmake b/Modules/AndroidTestUtilities.cmake index 95e2ef7e9..ddccf586b 100644 --- a/Modules/AndroidTestUtilities.cmake +++ b/Modules/AndroidTestUtilities.cmake @@ -5,6 +5,8 @@ AndroidTestUtilities ------------------------ +.. versionadded:: 3.7 + Create a test that automatically loads specified data onto an Android device. Introduction diff --git a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in index a6e5fda38..46b8b2ab2 100644 --- a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in +++ b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in @@ -9,12 +9,23 @@ set(PACKAGE_VERSION "@CVF_VERSION@") -if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_COMPATIBLE FALSE) +if (PACKAGE_FIND_VERSION_RANGE) + # Package version must be in the requested version range + if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN) + OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX))) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + endif() else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) + if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() endif() endif() diff --git a/Modules/BasicConfigVersion-ExactVersion.cmake.in b/Modules/BasicConfigVersion-ExactVersion.cmake.in index 43fc4d0b1..3507a2283 100644 --- a/Modules/BasicConfigVersion-ExactVersion.cmake.in +++ b/Modules/BasicConfigVersion-ExactVersion.cmake.in @@ -9,6 +9,13 @@ # The variable CVF_VERSION must be set before calling configure_file(). +if (PACKAGE_FIND_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the version strategy " + "(ExactVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible " + "with this request. Only the lower endpoint of the range will be used.") +endif() + set(PACKAGE_VERSION "@CVF_VERSION@") if("@CVF_VERSION@" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version diff --git a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in index 8c3b6a212..662900d1b 100644 --- a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in +++ b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in @@ -9,6 +9,13 @@ # The variable CVF_VERSION must be set before calling configure_file(). +if (PACKAGE_FIND_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the version strategy " + "(SameMajorVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible " + "with this request. Only the lower endpoint of the range will be used.") +endif() + set(PACKAGE_VERSION "@CVF_VERSION@") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) diff --git a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in index e2030d230..bddf4ceaf 100644 --- a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in +++ b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in @@ -10,6 +10,13 @@ # The variable CVF_VERSION must be set before calling configure_file(). +if (PACKAGE_FIND_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the version strategy " + "(SameMinorVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible " + "with this request. Only the lower endpoint of the range will be used.") +endif() + set(PACKAGE_VERSION "@CVF_VERSION@") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index 2f3b9e1d3..f521d2220 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -894,11 +894,16 @@ function(fixup_bundle_item resolved_embedded_item exepath dirs) # to install_name_tool: # if(changes) - set(cmd ${CMAKE_INSTALL_NAME_TOOL} ${changes} "${resolved_embedded_item}") - execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result) - if(NOT install_name_tool_result EQUAL 0) - string(REPLACE ";" "' '" msg "'${cmd}'") - message(FATAL_ERROR "Command failed:\n ${msg}") + # Check for a script by extension (.bat,.sh,...) or if the file starts with "#!" (shebang) + file(READ ${resolved_embedded_item} file_contents LIMIT 5) + if(NOT "${resolved_embedded_item}" MATCHES "\\.(bat|c?sh|bash|ksh|cmd)$" AND + NOT file_contents MATCHES "^#!") + set(cmd ${CMAKE_INSTALL_NAME_TOOL} ${changes} "${resolved_embedded_item}") + execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result) + if(NOT install_name_tool_result EQUAL 0) + string(REPLACE ";" "' '" msg "'${cmd}'") + message(FATAL_ERROR "Command failed:\n ${msg}") + endif() endif() endif() endfunction() diff --git a/Modules/CMakeASMInformation.cmake b/Modules/CMakeASMInformation.cmake index 03195ccec..2dc1585df 100644 --- a/Modules/CMakeASMInformation.cmake +++ b/Modules/CMakeASMInformation.cmake @@ -96,15 +96,5 @@ if(NOT CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG) set(CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_ASM${ASM_DIALECT}_FLAG}) endif() -# to be done -if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY) - set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY) -endif() - -if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_MODULE) - set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_MODULE) -endif() - set(CMAKE_ASM${ASM_DIALECT}_INFOMATION_LOADED 1) - diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in index 704ad09fd..871e18e7b 100644 --- a/Modules/CMakeCUDACompiler.cmake.in +++ b/Modules/CMakeCUDACompiler.cmake.in @@ -3,6 +3,8 @@ set(CMAKE_CUDA_HOST_COMPILER "@CMAKE_CUDA_HOST_COMPILER@") set(CMAKE_CUDA_HOST_LINK_LAUNCHER "@CMAKE_CUDA_HOST_LINK_LAUNCHER@") set(CMAKE_CUDA_COMPILER_ID "@CMAKE_CUDA_COMPILER_ID@") set(CMAKE_CUDA_COMPILER_VERSION "@CMAKE_CUDA_COMPILER_VERSION@") +set(CMAKE_CUDA_DEVICE_LINKER "@CMAKE_CUDA_DEVICE_LINKER@") +set(CMAKE_CUDA_FATBINARY "@CMAKE_CUDA_FATBINARY@") set(CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT "@CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT@") set(CMAKE_CUDA_COMPILE_FEATURES "@CMAKE_CUDA_COMPILE_FEATURES@") set(CMAKE_CUDA03_COMPILE_FEATURES "@CMAKE_CUDA03_COMPILE_FEATURES@") @@ -44,6 +46,7 @@ if(CMAKE_CUDA_LIBRARY_ARCHITECTURE) endif() set(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "@CMAKE_CUDA_COMPILER_TOOLKIT_ROOT@") +set(CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT "@CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT@") set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "@CMAKE_CUDA_COMPILER_LIBRARY_ROOT@") set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "@CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES@") diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index f9f757452..58e6e2994 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -145,7 +145,7 @@ endif() #Specify how to compile when separable compilation has been requested if(NOT CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION) set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -dc <SOURCE> -o <OBJECT>") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} ${_CMAKE_CUDA_DEVICE_CODE} <SOURCE> -o <OBJECT>") endif() #Specify how to compile when whole compilation has been requested @@ -200,6 +200,11 @@ if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE) "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") endif() +# Used when device linking is handled by CMake. +if(NOT CMAKE_CUDA_DEVICE_LINK_COMPILE) + set(CMAKE_CUDA_DEVICE_LINK_COMPILE "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <FLAGS> -D__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__ -D__NV_EXTRA_INITIALIZATION=\"\" -D__NV_EXTRA_FINALIZATION=\"\" -DREGISTERLINKBINARYFILE=\\\"<REGISTER_FILE>\\\" -DFATBINFILE=\\\"<FATBINARY>\\\" ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c \"${CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT}/bin/crt/link.stub\" -o <OBJECT>") +endif() + unset(__IMPLICT_DLINK_FLAGS) set(CMAKE_CUDA_INFORMATION_LOADED 1) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index acd15df98..26fb38112 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -13,7 +13,8 @@ endfunction() function(compiler_id_detection outvar lang) - if (NOT lang STREQUAL Fortran AND NOT lang STREQUAL CSharp) + if (NOT lang STREQUAL Fortran AND NOT lang STREQUAL CSharp + AND NOT lang STREQUAL ISPC) file(GLOB lang_files "${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake") set(nonlang CXX) @@ -77,6 +78,8 @@ function(compiler_id_detection outvar lang) ARMCC AppleClang ARMClang + IntelDPCPP + IntelClang Clang GNU MSVC diff --git a/Modules/CMakeDependentOption.cmake b/Modules/CMakeDependentOption.cmake index 99d5070d6..96855d28f 100644 --- a/Modules/CMakeDependentOption.cmake +++ b/Modules/CMakeDependentOption.cmake @@ -8,21 +8,34 @@ CMakeDependentOption Macro to provide an option dependent on other options. This macro presents an option to the user only if a set of other -conditions are true. When the option is not presented a default value -is used, but any value set by the user is preserved for when the -option is presented again. Example invocation: +conditions are true. + +Usage: + +.. code-block:: cmake + + cmake_dependent_option(<option> "<help_text>" <value> <depends> <force>) + +Where ``<option>`` is available to the user if ``<depends>`` is true. When +``<option>`` is available, the given ``<help_text>`` and initial ``<value>`` +are used. If the ``<depends>`` condition is not true, ``<option>`` will not be +presented and will always have the value given by ``<force>``. Any value set by +the user is preserved for when the option is presented again. Each element in +the fourth parameter is evaluated as an if-condition, so +:ref:`Condition Syntax` can be used. + +Example invocation: .. code-block:: cmake - CMAKE_DEPENDENT_OPTION(USE_FOO "Use Foo" ON + cmake_dependent_option(USE_FOO "Use Foo" ON "USE_BAR;NOT USE_ZOT" OFF) -If USE_BAR is true and USE_ZOT is false, this provides an option -called USE_FOO that defaults to ON. Otherwise, it sets USE_FOO to -OFF. If the status of USE_BAR or USE_ZOT ever changes, any value for -the USE_FOO option is saved so that when the option is re-enabled it -retains its old value. Each element in the fourth parameter is -evaluated as an if-condition, so :ref:`Condition Syntax` can be used. +If ``USE_BAR`` is true and ``USE_ZOT`` is false, this provides an option called +``USE_FOO`` that defaults to ON. Otherwise, it sets ``USE_FOO`` to OFF and +hides the option from the user. If the status of ``USE_BAR`` or ``USE_ZOT`` +ever changes, any value for the ``USE_FOO`` option is saved so that when the +option is re-enabled it retains its old value. #]=======================================================================] macro(CMAKE_DEPENDENT_OPTION option doc default depends force) diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index bc8b86b89..a3e5a1229 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -11,7 +11,7 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER) if(NOT $ENV{ASM${ASM_DIALECT}} STREQUAL "") get_filename_component(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT $ENV{ASM${ASM_DIALECT}} PROGRAM PROGRAM_ARGS CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT) if(CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT) - set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT}" CACHE STRING "First argument to ASM${ASM_DIALECT} compiler") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT}" CACHE STRING "Arguments to ASM${ASM_DIALECT} compiler") endif() if(NOT EXISTS ${CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable ASM${ASM_DIALECT}:\n$ENV{ASM${ASM_DIALECT}}.") diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 664d08954..ae3abe9b2 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -43,7 +43,7 @@ else() if(NOT $ENV{CC} STREQUAL "") get_filename_component(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT) if(CMAKE_C_FLAGS_ENV_INIT) - set(CMAKE_C_COMPILER_ARG1 "${CMAKE_C_FLAGS_ENV_INIT}" CACHE STRING "First argument to C compiler") + set(CMAKE_C_COMPILER_ARG1 "${CMAKE_C_FLAGS_ENV_INIT}" CACHE STRING "Arguments to C compiler") endif() if(NOT EXISTS ${CMAKE_C_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.") @@ -87,7 +87,9 @@ else() "--target=arm-arm-none-eabi -mcpu=cortex-m3" ) endif() - +if(CMAKE_C_COMPILER_TARGET) + set(CMAKE_C_COMPILER_ID_TEST_FLAGS_FIRST "-c --target=${CMAKE_C_COMPILER_TARGET}") +endif() # Build a small source file to identify the compiler. if(NOT CMAKE_C_COMPILER_ID_RUN) set(CMAKE_C_COMPILER_ID_RUN 1) diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index fa497cd99..9220551f3 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -19,7 +19,7 @@ else() if(NOT $ENV{CUDACXX} STREQUAL "") get_filename_component(CMAKE_CUDA_COMPILER_INIT $ENV{CUDACXX} PROGRAM PROGRAM_ARGS CMAKE_CUDA_FLAGS_ENV_INIT) if(CMAKE_CUDA_FLAGS_ENV_INIT) - set(CMAKE_CUDA_COMPILER_ARG1 "${CMAKE_CUDA_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler") + set(CMAKE_CUDA_COMPILER_ARG1 "${CMAKE_CUDA_FLAGS_ENV_INIT}" CACHE STRING "Arguments to CXX compiler") endif() if(NOT EXISTS ${CMAKE_CUDA_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable CUDACXX:\n$ENV{CUDACXX}.\n${CMAKE_CUDA_COMPILER_INIT}") @@ -169,11 +169,14 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) + set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/nvlink${CMAKE_EXECUTABLE_SUFFIX}") + set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) - # CMAKE_CUDA_COMPILER_LIBRARY_ROOT contains the device library and version file. - # In a non-scattered installation this is equivalent to CMAKE_CUDA_COMPILER_TOOLKIT_ROOT. + # In a non-scattered installation the following are equivalent to CMAKE_CUDA_COMPILER_TOOLKIT_ROOT. # We first check for a non-scattered installation to prefer it over a scattered installation. + + # CMAKE_CUDA_COMPILER_LIBRARY_ROOT contains the device library and version file. if(EXISTS "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/version.txt") set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}") elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt") @@ -181,6 +184,15 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt") set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/cuda") endif() + + # CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT contains the linking stubs necessary for device linking and other low-level library files. + if(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/nvidia-cuda-toolkit/bin/crt/link.stub") + set(CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT "${CMAKE_SYSROOT_LINK}/usr/lib/nvidia-cuda-toolkit") + elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/nvidia-cuda-toolkit/bin/crt/link.stub") + set(CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/nvidia-cuda-toolkit") + else() + set(CMAKE_CUDA_COMPILER_TOOLKIT_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}") + endif() endif() set(CMAKE_CUDA_COMPILER_ID_FLAGS_ALWAYS "-v") @@ -189,6 +201,10 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) set(nvcc_test_flags "--keep --keep-dir tmp") if(CMAKE_CUDA_HOST_COMPILER) string(APPEND nvcc_test_flags " -ccbin=\"${CMAKE_CUDA_HOST_COMPILER}\"") + + # If the user has specified a host compiler we should fail instead of trying without. + # Succeeding detection without may result in confusing errors later on, see #21076. + set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON) endif() elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") if(WIN32) @@ -202,37 +218,38 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() endif() - # First try with the user-specified architectures. + # Append user-specified architectures. if(CMAKE_CUDA_ARCHITECTURES) - set(clang_archs "${clang_test_flags}") - set(nvcc_archs "${nvcc_test_flags}") - foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) # Strip specifiers as PTX vs binary doesn't matter. string(REGEX MATCH "[0-9]+" arch_name "${arch}") - string(APPEND clang_archs " --cuda-gpu-arch=sm_${arch_name}") - string(APPEND nvcc_archs " -gencode=arch=compute_${arch_name},code=sm_${arch_name}") + string(APPEND clang_test_flags " --cuda-gpu-arch=sm_${arch_name}") + string(APPEND nvcc_test_flags " -gencode=arch=compute_${arch_name},code=sm_${arch_name}") list(APPEND tested_architectures "${arch_name}") endforeach() - list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_archs}") - list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_archs}") + # If the user has specified architectures we'll want to fail during compiler detection if they don't work. + set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON) endif() - # Fallback default NVCC flags. - list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST ${nvcc_test_flags}) - - # Clang doesn't automatically select an architecture supported by the SDK. - # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups). - foreach(arch "20" "30" "52") - list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}") - endforeach() + if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") + if(NOT CMAKE_CUDA_ARCHITECTURES) + # Clang doesn't automatically select an architecture supported by the SDK. + # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups). + foreach(arch "20" "30" "52") + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}") + endforeach() + endif() - # Finally also try the default. - list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}") + # If the user specified CMAKE_CUDA_ARCHITECTURES this will include all the architecture flags. + # Otherwise this won't include any architecture flags and we'll fallback to Clang's defaults. + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}") + elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_test_flags}") + endif() # We perform compiler identification for a second time to extract implicit linking info and host compiler for NVCC. - # We also use it to verify that CMAKE_CUDA_ARCHITECTURES and additionaly on Clang that CUDA toolkit path works. + # We also use it to verify that CMAKE_CUDA_ARCHITECTURES and additionally on Clang that CUDA toolkit path works. # The latter could be done during compiler testing in the future to avoid doing this for Clang. # We need to unset the compiler ID otherwise CMAKE_DETERMINE_COMPILER_ID() doesn't work. set(CMAKE_CUDA_COMPILER_ID) @@ -295,7 +312,7 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") endforeach() endif() - # Find target directory. Account for crosscompiling. + # Find target directory when crosscompiling. if(CMAKE_CROSSCOMPILING) if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") # Support for NVPACK @@ -315,7 +332,10 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") if(EXISTS "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/${_CUDA_TARGET_NAME}") set(_CUDA_TARGET_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/${_CUDA_TARGET_NAME}") endif() - else() + endif() + + # If not already set we can simply use the toolkit root or it's a scattered installation. + if(NOT _CUDA_TARGET_DIR) set(_CUDA_TARGET_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}") endif() diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index ea241cfcb..905eb259a 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -42,7 +42,7 @@ else() if(NOT $ENV{CXX} STREQUAL "") get_filename_component(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT) if(CMAKE_CXX_FLAGS_ENV_INIT) - set(CMAKE_CXX_COMPILER_ARG1 "${CMAKE_CXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler") + set(CMAKE_CXX_COMPILER_ARG1 "${CMAKE_CXX_FLAGS_ENV_INIT}" CACHE STRING "Arguments to CXX compiler") endif() if(NOT EXISTS ${CMAKE_CXX_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.\n${CMAKE_CXX_COMPILER_INIT}") @@ -83,6 +83,10 @@ else() ) endif() +if(CMAKE_CXX_COMPILER_TARGET) + set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS_FIRST "-c --target=${CMAKE_CXX_COMPILER_TARGET}") +endif() + # Build a small source file to identify the compiler. if(NOT CMAKE_CXX_COMPILER_ID_RUN) set(CMAKE_CXX_COMPILER_ID_RUN 1) diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index cb1ab1dbe..2780399dc 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -107,16 +107,14 @@ macro(_cmake_find_compiler_path lang) if(CMAKE_${lang}_COMPILER) # we only get here if CMAKE_${lang}_COMPILER was specified using -D or a pre-made CMakeCache.txt # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE - # if CMAKE_${lang}_COMPILER is a list of length 2, use the first item as - # CMAKE_${lang}_COMPILER and the 2nd one as CMAKE_${lang}_COMPILER_ARG1 - list(LENGTH CMAKE_${lang}_COMPILER _CMAKE_${lang}_COMPILER_LIST_LENGTH) - if("${_CMAKE_${lang}_COMPILER_LIST_LENGTH}" EQUAL 2) - list(GET CMAKE_${lang}_COMPILER 1 CMAKE_${lang}_COMPILER_ARG1) - list(GET CMAKE_${lang}_COMPILER 0 CMAKE_${lang}_COMPILER) - endif() - unset(_CMAKE_${lang}_COMPILER_LIST_LENGTH) + # if CMAKE_${lang}_COMPILER is a list, use the first item as + # CMAKE_${lang}_COMPILER and the rest as CMAKE_${lang}_COMPILER_ARG1 + set(CMAKE_${lang}_COMPILER_ARG1 "${CMAKE_${lang}_COMPILER}") + list(POP_FRONT CMAKE_${lang}_COMPILER_ARG1 CMAKE_${lang}_COMPILER) + list(JOIN CMAKE_${lang}_COMPILER_ARG1 " " CMAKE_${lang}_COMPILER_ARG1) # find the compiler in the PATH if necessary + # if compiler (and arguments) comes from cache then synchronize cache with updated CMAKE_<LANG>_COMPILER get_filename_component(_CMAKE_USER_${lang}_COMPILER_PATH "${CMAKE_${lang}_COMPILER}" PATH) if(NOT _CMAKE_USER_${lang}_COMPILER_PATH) find_program(CMAKE_${lang}_COMPILER_WITH_PATH NAMES ${CMAKE_${lang}_COMPILER}) @@ -129,6 +127,12 @@ macro(_cmake_find_compiler_path lang) unset(_CMAKE_${lang}_COMPILER_CACHED) endif() unset(CMAKE_${lang}_COMPILER_WITH_PATH CACHE) + elseif (EXISTS ${CMAKE_${lang}_COMPILER}) + get_property(_CMAKE_${lang}_COMPILER_CACHED CACHE CMAKE_${lang}_COMPILER PROPERTY TYPE) + if(_CMAKE_${lang}_COMPILER_CACHED) + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE STRING "${lang} compiler" FORCE) + endif() + unset(_CMAKE_${lang}_COMPILER_CACHED) endif() endif() endmacro() diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 50d5cd188..7e5b3751b 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -33,7 +33,7 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) __TestCompiler_setTryCompileTargetType() # Avoid failing ABI detection on warnings. - string(REGEX REPLACE "(^| )-Werror(=[^ ]*)?( |$)" " " CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") + string(REGEX REPLACE "(^| )-Werror([= ][^ ]*)?( |$)" " " CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") # Save the current LC_ALL, LC_MESSAGES, and LANG environment variables # and set them to "C" that way GCC's "search starts here" text is in diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 1feaf911c..d90792602 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -14,8 +14,10 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) # Make sure user-specified compiler flags are used. if(CMAKE_${lang}_FLAGS) set(CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS}) - else() + elseif(DEFINED ENV{${flagvar}}) set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}}) + else(CMAKE_${lang}_FLAGS_INIT) + set(CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS_INIT}) endif() string(REPLACE " " ";" CMAKE_${lang}_COMPILER_ID_FLAGS_LIST "${CMAKE_${lang}_COMPILER_ID_FLAGS}") @@ -108,6 +110,28 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() + # For ISPC we need to explicitly query the version. + if(lang STREQUAL "ISPC" + AND CMAKE_${lang}_COMPILER + AND NOT CMAKE_${lang}_COMPILER_VERSION) + execute_process( + COMMAND "${CMAKE_${lang}_COMPILER}" + --version + OUTPUT_VARIABLE output ERROR_VARIABLE output + RESULT_VARIABLE result + TIMEOUT 10 + ) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Running the ${lang} compiler: \"${CMAKE_${lang}_COMPILER}\" -version\n" + "${output}\n" + ) + + if(output MATCHES [[ISPC\), ([0-9]+\.[0-9]+(\.[0-9]+)?)]]) + set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}") + endif() + endif() + + if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" @@ -248,7 +272,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_PostBuildEvent_Command "") if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$") set(id_cl_var "ClangClExecutable") - elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Cc][Ll][Aa][Nn][Gg][Cc][Ll]$") + elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Cc][Ll][Aa][Nn][Gg]([Cc][Ll]$|_[0-9])") set(id_cl "$(CLToolExe)") elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*") set(id_cl clang.exe) @@ -310,17 +334,36 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_PreferredToolArchitecture "") endif() if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone") + set(id_keyword "Win32Proj") set(id_system "<ApplicationType>Windows Phone</ApplicationType>") elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + set(id_keyword "Win32Proj") set(id_system "<ApplicationType>Windows Store</ApplicationType>") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(id_keyword "Android") + set(id_system "<ApplicationType>Android</ApplicationType>") else() + set(id_keyword "Win32Proj") set(id_system "") endif() - if(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)") + if(id_keyword STREQUAL "Android") + if(CMAKE_GENERATOR MATCHES "Visual Studio 14") + set(id_system_version "<ApplicationTypeRevision>2.0</ApplicationTypeRevision>") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + set(id_system_version "<ApplicationTypeRevision>3.0</ApplicationTypeRevision>") + else() + set(id_system_version "") + endif() + elseif(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)") set(id_system_version "<ApplicationTypeRevision>${CMAKE_MATCH_1}</ApplicationTypeRevision>") else() set(id_system_version "") endif() + if(id_keyword STREQUAL "Android") + set(id_config_type "DynamicLibrary") + else() + set(id_config_type "Application") + endif() if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) set(id_WindowsTargetPlatformVersion "<WindowsTargetPlatformVersion>${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}</WindowsTargetPlatformVersion>") endif() @@ -333,9 +376,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} string(APPEND id_CustomGlobals "<${CMAKE_MATCH_1}>${CMAKE_MATCH_2}</${CMAKE_MATCH_1}>\n ") endif() endforeach() - if(id_platform STREQUAL ARM64) + if(id_keyword STREQUAL "Android") + set(id_WindowsSDKDesktopARMSupport "") + elseif(id_platform STREQUAL "ARM64") set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>") - elseif(id_platform STREQUAL ARM) + elseif(id_platform STREQUAL "ARM") set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>") else() set(id_WindowsSDKDesktopARMSupport "") @@ -368,14 +413,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} endif() set(cuda_tools "CUDA ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}") set(id_compile "CudaCompile") - if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) - set(cuda_target "<TargetMachinePlatform>64</TargetMachinePlatform>") - endif() - foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) - string(REGEX MATCH "[0-9]+" arch_name "${arch}") - string(APPEND cuda_codegen "compute_${arch_name},sm_${arch_name};") - endforeach() - set(id_ItemDefinitionGroup_entry "<CudaCompile>${cuda_target}<AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions><CodeGeneration>${cuda_codegen}</CodeGeneration></CudaCompile>") + set(id_ItemDefinitionGroup_entry "<CudaCompile><AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions></CudaCompile>") set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]]) if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR) set(id_CudaToolkitCustomDir "<CudaToolkitCustomDir>${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc</CudaToolkitCustomDir>") @@ -385,6 +423,9 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} string(CONCAT id_Import_props [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.props" />]]) string(CONCAT id_Import_targets [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.targets" />]]) endif() + if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) + set(id_ItemDefinitionGroup_entry "<CudaCompile><TargetMachinePlatform>64</TargetMachinePlatform><AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions></CudaCompile>") + endif() if(CMAKE_CUDA_FLAGS MATCHES "(^| )-cudart +shared( |$)") set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart.lib</AdditionalDependencies>") else() @@ -475,9 +516,16 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} endif() if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT MATCHES "^$|[Mm][Aa][Cc][Oo][Ss]") # When targeting macOS, use only the host architecture. - set(id_archs [[ARCHS = "$(NATIVE_ARCH_ACTUAL)";]]) + if (_CMAKE_APPLE_ARCHS_DEFAULT) + set(id_archs "ARCHS = \"${_CMAKE_APPLE_ARCHS_DEFAULT}\";") + set(id_arch_active "ONLY_ACTIVE_ARCH = NO;") + else() + set(id_archs [[ARCHS = "$(NATIVE_ARCH_ACTUAL)";]]) + set(id_arch_active "ONLY_ACTIVE_ARCH = YES;") + endif() else() set(id_archs "") + set(id_arch_active "ONLY_ACTIVE_ARCH = YES;") endif() configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-3.pbxproj.in ${id_dir}/CompilerId${lang}.xcodeproj/project.pbxproj @ONLY) @@ -587,9 +635,12 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT} ") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}") - #if(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL) - # message(FATAL_ERROR "${MSG}") - #endif() + + # Some languages may know the correct/desired set of flags and want to fail right away if they don't work. + # This is currently only used by CUDA. + if(CMAKE_${lang}_COMPILER_ID_REQUIRE_SUCCESS) + message(FATAL_ERROR "${MSG}") + endif() # No output files should be inspected. set(COMPILER_${lang}_PRODUCED_FILES) @@ -706,7 +757,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS}) # The IAR-AVR compiler uses a binary format that places a '6' # character (0x34) before each character in the string. Strip - # out these characters without removing any legitamate characters. + # out these characters without removing any legitimate characters. if("${info}" MATCHES "(.)I.N.F.O.:.") string(REGEX REPLACE "${CMAKE_MATCH_1}(.)" "\\1" info "${info}") endif() diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 5f5a70ad3..8a574086e 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -26,7 +26,7 @@ else() if(NOT $ENV{FC} STREQUAL "") get_filename_component(CMAKE_Fortran_COMPILER_INIT $ENV{FC} PROGRAM PROGRAM_ARGS CMAKE_Fortran_FLAGS_ENV_INIT) if(CMAKE_Fortran_FLAGS_ENV_INIT) - set(CMAKE_Fortran_COMPILER_ARG1 "${CMAKE_Fortran_FLAGS_ENV_INIT}" CACHE STRING "First argument to Fortran compiler") + set(CMAKE_Fortran_COMPILER_ARG1 "${CMAKE_Fortran_FLAGS_ENV_INIT}" CACHE STRING "Arguments to Fortran compiler") endif() if(EXISTS ${CMAKE_Fortran_COMPILER_INIT}) else() diff --git a/Modules/CMakeDetermineISPCCompiler.cmake b/Modules/CMakeDetermineISPCCompiler.cmake new file mode 100644 index 000000000..ff2bf20bb --- /dev/null +++ b/Modules/CMakeDetermineISPCCompiler.cmake @@ -0,0 +1,96 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# determine the compiler to use for ISPC programs + +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) + +if( NOT (("${CMAKE_GENERATOR}" MATCHES "Make") OR ("${CMAKE_GENERATOR}" MATCHES "Ninja")) ) + message(FATAL_ERROR "ISPC language not currently supported by \"${CMAKE_GENERATOR}\" generator") +endif() + +# Load system-specific compiler preferences for this language. +include(Platform/${CMAKE_SYSTEM_NAME}-Determine-ISPC OPTIONAL) +include(Platform/${CMAKE_SYSTEM_NAME}-ISPC OPTIONAL) +if(NOT CMAKE_ISPC_COMPILER_NAMES) + set(CMAKE_ISPC_COMPILER_NAMES ispc) +endif() + + +if(NOT CMAKE_ISPC_COMPILER) + + set(CMAKE_ISPC_COMPILER_INIT NOTFOUND) + + # prefer the environment variable CC + if(NOT $ENV{ISPC} STREQUAL "") + get_filename_component(CMAKE_ISPC_COMPILER_INIT $ENV{ISPC} PROGRAM PROGRAM_ARGS CMAKE_ISPC_FLAGS_ENV_INIT) + if(CMAKE_ISPC_FLAGS_ENV_INIT) + set(CMAKE_ISPC_COMPILER_ARG1 "${CMAKE_ISPC_FLAGS_ENV_INIT}" CACHE STRING "First argument to ISPC compiler") + endif() + if(NOT EXISTS ${CMAKE_ISPC_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable ISPC:\n$ENV{ISPC}.") + endif() + endif() + + # next try prefer the compiler specified by the generator + if(CMAKE_GENERATOR_ISPC) + if(NOT CMAKE_ISPC_COMPILER_INIT) + set(CMAKE_ISPC_COMPILER_INIT ${CMAKE_GENERATOR_ISPC}) + endif() + endif() + + # finally list compilers to try + if(NOT CMAKE_ISPC_COMPILER_INIT) + set(CMAKE_ISPC_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}ispc ispc) + endif() + + # Find the compiler. + _cmake_find_compiler(ISPC) + +else() + _cmake_find_compiler_path(ISPC) +endif() +mark_as_advanced(CMAKE_ISPC_COMPILER) + +if(NOT CMAKE_ISPC_COMPILER_ID_RUN) +set(CMAKE_ISPC_COMPILER_ID_RUN 1) + + # Try to identify the compiler. + set(CMAKE_ISPC_COMPILER_ID) + set(CMAKE_ISPC_PLATFORM_ID) + + + set(CMAKE_ISPC_COMPILER_ID_TEST_FLAGS_FIRST + # setup logic to make sure ISPC outputs a file + "-o cmake_ispc_output" + ) + + include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) + CMAKE_DETERMINE_COMPILER_ID(ISPC ISPCFLAGS CMakeISPCCompilerId.ispc) + + _cmake_find_compiler_sysroot(ISPC) +endif() + +if (NOT _CMAKE_TOOLCHAIN_LOCATION) + get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ISPC_COMPILER}" PATH) +endif () + +set(_CMAKE_PROCESSING_LANGUAGE "ISPC") +include(CMakeFindBinUtils) +include(Compiler/${CMAKE_ISPC_COMPILER_ID}-FindBinUtils OPTIONAL) +unset(_CMAKE_PROCESSING_LANGUAGE) + +if(CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH) + set(_SET_CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH + "set(CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH [==[${CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH}]==])") +else() + set(_SET_CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH "") +endif() + + +# configure variables set in this file for fast reload later on +configure_file(${CMAKE_ROOT}/Modules/CMakeISPCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeISPCCompiler.cmake @ONLY) + +set(CMAKE_ISPC_COMPILER_ENV_VAR "ISPC") diff --git a/Modules/CMakeDetermineJavaCompiler.cmake b/Modules/CMakeDetermineJavaCompiler.cmake index 3092bb52d..db456c004 100644 --- a/Modules/CMakeDetermineJavaCompiler.cmake +++ b/Modules/CMakeDetermineJavaCompiler.cmake @@ -11,7 +11,7 @@ if(NOT CMAKE_Java_COMPILER) if(NOT $ENV{JAVA_COMPILER} STREQUAL "") get_filename_component(CMAKE_Java_COMPILER_INIT $ENV{JAVA_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT) if(CMAKE_Java_FLAGS_ENV_INIT) - set(CMAKE_Java_COMPILER_ARG1 "${CMAKE_Java_FLAGS_ENV_INIT}" CACHE STRING "First argument to Java compiler") + set(CMAKE_Java_COMPILER_ARG1 "${CMAKE_Java_FLAGS_ENV_INIT}" CACHE STRING "Arguments to Java compiler") endif() if(NOT EXISTS ${CMAKE_Java_COMPILER_INIT}) message(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.") diff --git a/Modules/CMakeDetermineOBJCCompiler.cmake b/Modules/CMakeDetermineOBJCCompiler.cmake index da09ebb5f..4b84c8af9 100644 --- a/Modules/CMakeDetermineOBJCCompiler.cmake +++ b/Modules/CMakeDetermineOBJCCompiler.cmake @@ -39,7 +39,7 @@ else() if($ENV{${var}} MATCHES ".+") get_filename_component(CMAKE_OBJC_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJC_FLAGS_ENV_INIT) if(CMAKE_OBJC_FLAGS_ENV_INIT) - set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C compiler") + set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "Arguments to Objective-C compiler") endif() if(NOT EXISTS ${CMAKE_OBJC_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") @@ -65,14 +65,11 @@ else() else() # we only get here if CMAKE_OBJC_COMPILER was specified using -D or a pre-made CMakeCache.txt # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE - # if CMAKE_OBJC_COMPILER is a list of length 2, use the first item as - # CMAKE_OBJC_COMPILER and the 2nd one as CMAKE_OBJC_COMPILER_ARG1 - - list(LENGTH CMAKE_OBJC_COMPILER _CMAKE_OBJC_COMPILER_LIST_LENGTH) - if("${_CMAKE_OBJC_COMPILER_LIST_LENGTH}" EQUAL 2) - list(GET CMAKE_OBJC_COMPILER 1 CMAKE_OBJC_COMPILER_ARG1) - list(GET CMAKE_OBJC_COMPILER 0 CMAKE_OBJC_COMPILER) - endif() + # if CMAKE_OBJC_COMPILER is a list, use the first item as + # CMAKE_OBJC_COMPILER and the rest as CMAKE_OBJC_COMPILER_ARG1 + set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_COMPILER}") + list(POP_FRONT CMAKE_OBJC_COMPILER_ARG1 CMAKE_OBJC_COMPILER) + list(JOIN CMAKE_OBJC_COMPILER_ARG1 " " CMAKE_OBJC_COMPILER_ARG1) # if a compiler was specified by the user but without path, # now try to find it with the full path diff --git a/Modules/CMakeDetermineOBJCXXCompiler.cmake b/Modules/CMakeDetermineOBJCXXCompiler.cmake index f96394c46..7403847f3 100644 --- a/Modules/CMakeDetermineOBJCXXCompiler.cmake +++ b/Modules/CMakeDetermineOBJCXXCompiler.cmake @@ -41,7 +41,7 @@ else() if($ENV{${var}} MATCHES ".+") get_filename_component(CMAKE_OBJCXX_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJCXX_FLAGS_ENV_INIT) if(CMAKE_OBJCXX_FLAGS_ENV_INIT) - set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C++ compiler") + set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "Arguments to Objective-C++ compiler") endif() if(NOT EXISTS ${CMAKE_OBJCXX_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") @@ -67,14 +67,11 @@ else() else() # we only get here if CMAKE_OBJCXX_COMPILER was specified using -D or a pre-made CMakeCache.txt # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE - # if CMAKE_OBJCXX_COMPILER is a list of length 2, use the first item as - # CMAKE_OBJCXX_COMPILER and the 2nd one as CMAKE_OBJCXX_COMPILER_ARG1 - - list(LENGTH CMAKE_OBJCXX_COMPILER _CMAKE_OBJCXX_COMPILER_LIST_LENGTH) - if("${_CMAKE_OBJCXX_COMPILER_LIST_LENGTH}" EQUAL 2) - list(GET CMAKE_OBJCXX_COMPILER 1 CMAKE_OBJCXX_COMPILER_ARG1) - list(GET CMAKE_OBJCXX_COMPILER 0 CMAKE_OBJCXX_COMPILER) - endif() + # if CMAKE_OBJCXX_COMPILER is a list, use the first item as + # CMAKE_OBJCXX_COMPILER and the rest as CMAKE_OBJCXX_COMPILER_ARG1 + set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_COMPILER}") + list(POP_FRONT CMAKE_OBJCXX_COMPILER_ARG1 CMAKE_OBJCXX_COMPILER) + list(JOIN CMAKE_OBJCXX_COMPILER_ARG1 " " CMAKE_OBJCXX_COMPILER_ARG1) # if a compiler was specified by the user but without path, # now try to find it with the full path diff --git a/Modules/CMakeDetermineRCCompiler.cmake b/Modules/CMakeDetermineRCCompiler.cmake index 8801e1632..f8d55a5c0 100644 --- a/Modules/CMakeDetermineRCCompiler.cmake +++ b/Modules/CMakeDetermineRCCompiler.cmake @@ -13,7 +13,7 @@ if(NOT CMAKE_RC_COMPILER) if(NOT $ENV{RC} STREQUAL "") get_filename_component(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT) if(CMAKE_RC_FLAGS_ENV_INIT) - set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "First argument to RC compiler") + set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "Arguments to RC compiler") endif() if(EXISTS ${CMAKE_RC_COMPILER_INIT}) else() diff --git a/Modules/CMakeDetermineSwiftCompiler.cmake b/Modules/CMakeDetermineSwiftCompiler.cmake index 688133f34..aaad5601d 100644 --- a/Modules/CMakeDetermineSwiftCompiler.cmake +++ b/Modules/CMakeDetermineSwiftCompiler.cmake @@ -27,7 +27,7 @@ elseif("${CMAKE_GENERATOR}" MATCHES "^Ninja") PROGRAM_ARGS CMAKE_Swift_FLAGS_ENV_INIT) if(CMAKE_Swift_FLAGS_ENV_INIT) set(CMAKE_Swift_COMPILER_ARG1 "${CMAKE_Swift_FLAGS_ENV_INIT}" CACHE - STRING "First argument to the Swift compiler") + STRING "Arguments to the Swift compiler") endif() if(NOT EXISTS ${CMAKE_Swift_COMPILER_INIT}) message(FATAL_ERROR "Could not find compiler set in environment variable SWIFTC\n$ENV{SWIFTC}.\n${CMAKE_Swift_COMPILER_INIT}") diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake index f3ec4da2d..cb4421aa9 100644 --- a/Modules/CMakeDetermineSystem.cmake +++ b/Modules/CMakeDetermineSystem.cmake @@ -46,10 +46,21 @@ if(CMAKE_HOST_UNIX) if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$|Android") exec_program(${CMAKE_UNAME} ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND - CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh") - # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc' - set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc") + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + # Check whether we are running under Rosetta on arm64 hardware. + execute_process(COMMAND sysctl -q hw.optional.arm64 + OUTPUT_VARIABLE _sysctl_stdout + ERROR_VARIABLE _sysctl_stderr + RESULT_VARIABLE _sysctl_result + ) + if(_sysctl_result EQUAL 0 AND _sysctl_stdout MATCHES "hw.optional.arm64: 1") + set(CMAKE_HOST_SYSTEM_PROCESSOR "arm64") + endif() + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh") + # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc' + set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc") + endif() endif() elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD") exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 73d57f0e0..d81fd1158 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -66,6 +66,7 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC" OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI") OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xNVIDIA") + OR (CMAKE_HOST_WIN32 AND "x${_CMAKE_PROCESSING_LANGUAGE}" STREQUAL "xISPC") OR (CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")) @@ -94,7 +95,11 @@ else() set(_CMAKE_ADDITIONAL_AR_NAMES "llvm-ar") set(_CMAKE_ADDITIONAL_RANLIB_NAMES "llvm-ranlib") set(_CMAKE_ADDITIONAL_STRIP_NAMES "llvm-strip") - set(_CMAKE_ADDITIONAL_LINKER_NAMES "ld.lld") + if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC") + set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link") + else() + set(_CMAKE_ADDITIONAL_LINKER_NAMES "ld.lld") + endif() set(_CMAKE_ADDITIONAL_NM_NAMES "llvm-nm") set(_CMAKE_ADDITIONAL_OBJDUMP_NAMES "llvm-objdump") set(_CMAKE_ADDITIONAL_OBJCOPY_NAMES "llvm-objcopy") diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index 6f665a626..649b6f7c8 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -77,10 +77,14 @@ function(GetDefaultWindowsPrefixBase var) # if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") set(arch_hint "x64") + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64") + set(arch_hint "x64") elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") set(arch_hint "ARM64") elseif("${CMAKE_GENERATOR}" MATCHES "ARM") set(arch_hint "ARM") + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM") + set(arch_hint "ARM") elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") set(arch_hint "x64") elseif("$ENV{LIB}" MATCHES "(amd64|ia64)") diff --git a/Modules/CMakeIOSInstallCombined.cmake b/Modules/CMakeIOSInstallCombined.cmake index 418bafd63..44bb622f4 100644 --- a/Modules/CMakeIOSInstallCombined.cmake +++ b/Modules/CMakeIOSInstallCombined.cmake @@ -80,6 +80,17 @@ function(_ios_install_combined_get_valid_archs sdk resultvar) cmake_policy(POP) endfunction() +# Make both arch lists a disjoint set by preferring the current SDK +# (starting with Xcode 12 arm64 is available as device and simulator arch on iOS) +function(_ios_install_combined_prune_common_archs corr_sdk corr_archs_var this_archs_var) + list(REMOVE_ITEM ${corr_archs_var} ${${this_archs_var}}) + + string(REPLACE ";" " " printable "${${corr_archs_var}}") + _ios_install_combined_message("Architectures (${corr_sdk}) after pruning: ${printable}") + + set("${corr_archs_var}" "${${corr_archs_var}}" PARENT_SCOPE) +endfunction() + # Final target can contain more architectures that specified by SDK. This # function will run 'lipo -info' and parse output. Result will be returned # as a CMake list. @@ -266,8 +277,9 @@ function(ios_install_combined target destination) _ios_install_combined_detect_sdks(this_sdk corr_sdk) # Get architectures of the target - _ios_install_combined_get_valid_archs("${corr_sdk}" corr_valid_archs) _ios_install_combined_get_valid_archs("${this_sdk}" this_valid_archs) + _ios_install_combined_get_valid_archs("${corr_sdk}" corr_valid_archs) + _ios_install_combined_prune_common_archs("${corr_sdk}" corr_valid_archs this_valid_archs) # Return if there are no valid architectures for the SDK. # (note that library already installed) diff --git a/Modules/CMakeISPCCompiler.cmake.in b/Modules/CMakeISPCCompiler.cmake.in new file mode 100644 index 000000000..28c31cc90 --- /dev/null +++ b/Modules/CMakeISPCCompiler.cmake.in @@ -0,0 +1,30 @@ +set(CMAKE_ISPC_COMPILER "@CMAKE_ISPC_COMPILER@") +set(CMAKE_ISPC_COMPILER_ARG1 "@CMAKE_ISPC_COMPILER_ARG1@") +set(CMAKE_ISPC_COMPILER_ID "@CMAKE_ISPC_COMPILER_ID@") +set(CMAKE_ISPC_COMPILER_VERSION "@CMAKE_ISPC_COMPILER_VERSION@") +set(CMAKE_ISPC_COMPILER_VERSION_INTERNAL "@CMAKE_ISPC_COMPILER_VERSION_INTERNAL@") + +set(CMAKE_ISPC_PLATFORM_ID "@CMAKE_ISPC_PLATFORM_ID@") +set(CMAKE_ISPC_SIMULATE_ID "@CMAKE_ISPC_SIMULATE_ID@") +set(CMAKE_ISPC_COMPILER_FRONTEND_VARIANT "@CMAKE_ISPC_COMPILER_FRONTEND_VARIANT@") +set(CMAKE_ISPC_SIMULATE_VERSION "@CMAKE_ISPC_SIMULATE_VERSION@") + +set(CMAKE_AR "@CMAKE_AR@") +set(CMAKE_ISPC_COMPILER_AR "@CMAKE_ISPC_COMPILER_AR@") +set(CMAKE_RANLIB "@CMAKE_RANLIB@") +set(CMAKE_ISPC_COMPILER_RANLIB "@CMAKE_ISPC_COMPILER_RANLIB@") + +set(CMAKE_ISPC_COMPILER_LOADED 1) +set(CMAKE_ISPC_COMPILER_WORKS @CMAKE_ISPC_COMPILER_WORKS@) +set(CMAKE_ISPC_ABI_COMPILED @CMAKE_ISPC_ABI_COMPILED@) + +set(CMAKE_ISPC_COMPILER_ENV_VAR "ISPC") + +set(CMAKE_ISPC_COMPILER_ID_RUN 1) +set(CMAKE_ISPC_SOURCE_FILE_EXTENSIONS ispc) +set(CMAKE_ISPC_IGNORE_EXTENSIONS o;O) + +set(CMAKE_ISPC_LINKER_PREFERENCE 0) +set(CMAKE_ISPC_LINKER_PREFERENCE_PROPAGATES 0) + +@CMAKE_ISPC_COMPILER_CUSTOM_CODE@ diff --git a/Modules/CMakeISPCCompilerABI.ispc b/Modules/CMakeISPCCompilerABI.ispc new file mode 100644 index 000000000..e23abcea6 --- /dev/null +++ b/Modules/CMakeISPCCompilerABI.ispc @@ -0,0 +1,20 @@ + +export void ispcCompilerABI() { + +#if defined(__GNU__) && defined(__ELF__) && defined(__ARM_EABI__) + print("INFO:abi[ELF ARMEABI]"); + static char const info_abi[] = +#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEB__) + print("INFO:abi[ELF ARM]"); +#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEL__) + print("INFO:abi[ELF ARM]"); + +#elif defined(__linux__) && defined(__ELF__) && defined(__amd64__) && \ + defined(__ILP32__) +print("INFO:abi[ELF X32]"); + +#elif defined(__ELF__) +print("INFO:abi[ELF]"); +#endif + +} diff --git a/Modules/CMakeISPCCompilerId.ispc.in b/Modules/CMakeISPCCompilerId.ispc.in new file mode 100644 index 000000000..03380f35f --- /dev/null +++ b/Modules/CMakeISPCCompilerId.ispc.in @@ -0,0 +1,62 @@ + +export void ispcCompilerId() { + +// Identify the compiler +#if defined(ISPC) + print("INFO:compiler[Intel]"); +#endif + +// Identify the platform +#if defined(__linux) || defined(__linux__) || defined(linux) + print("INFO:platform[Linux]"); +#elif defined(__CYGWIN__) + print("INFO:platform[Cygwin]"); +#elif defined(__MINGW32__) + print("INFO:platform[MinGW]"); +#elif defined(__APPLE__) + print("INFO:platform[Darwin]"); +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + print("INFO:platform[Windows]"); +#elif defined(__FreeBSD__) || defined(__FreeBSD) + print("INFO:platform[FreeBSD]"); +#elif defined(__NetBSD__) || defined(__NetBSD) + print("INFO:platform[NetBSD]"); +#elif defined(__OpenBSD__) || defined(__OPENBSD) + print("INFO:platform[OpenBSD]"); +#elif defined(__sun) || defined(sun) + print("INFO:platform[SunOS]"); +#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) + print("INFO:platform[AIX]"); +#elif defined(__hpux) || defined(__hpux__) + print("INFO:platform[HP-UX]"); +#elif defined(__HAIKU__) + print("INFO:platform[Haiku]"); +#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) + print("INFO:platform[BeOS]"); +#elif defined(__QNX__) || defined(__QNXNTO__) + print("INFO:platform[QNX]"); +#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) + print("INFO:platform[Tru64]"); +#elif defined(__riscos) || defined(__riscos__) + print("INFO:platform[RISCos]"); +#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) + print("INFO:platform[SINIX]"); +#elif defined(__UNIX_SV__) + print("INFO:platform[UNIX_SV]"); +#elif defined(__bsdos__) + print("INFO:platform[BSDOS]"); +#elif defined(_MPRAS) || defined(MPRAS) + print("INFO:platform[MP-RAS]"); +#elif defined(__osf) || defined(__osf__) + print("INFO:platform[OSF1]"); +#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) + print("INFO:platform[SCO_SV]"); +#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) + print("INFO:platform[ULTRIX]"); +#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) + print("INFO:platform[Xenix]"); +#else + print("INFO:platform[]"); +#endif + +} diff --git a/Modules/CMakeISPCInformation.cmake b/Modules/CMakeISPCInformation.cmake new file mode 100644 index 000000000..5acb68287 --- /dev/null +++ b/Modules/CMakeISPCInformation.cmake @@ -0,0 +1,65 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +if(UNIX) + set(CMAKE_ISPC_OUTPUT_EXTENSION .o) +else() + set(CMAKE_ISPC_OUTPUT_EXTENSION .obj) +endif() +set(CMAKE_INCLUDE_FLAG_ISPC "-I") + +# Load compiler-specific information. +if(CMAKE_ISPC_COMPILER_ID) + include(Compiler/${CMAKE_ISPC_COMPILER_ID}-ISPC OPTIONAL) +endif() + +# load the system- and compiler specific files +if(CMAKE_ISPC_COMPILER_ID) + # load a hardware specific file, mostly useful for embedded compilers + if(CMAKE_SYSTEM_PROCESSOR) + include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_ISPC_COMPILER_ID}-ISPC-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL) + endif() + include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_ISPC_COMPILER_ID}-ISPC OPTIONAL) +endif() + +# add the flags to the cache based +# on the initial values computed in the platform/*.cmake files +# use _INIT variables so that this only happens the first time +# and you can set these flags in the cmake cache +set(CMAKE_ISPC_FLAGS_INIT "$ENV{ISPCFLAGS} ${CMAKE_ISPC_FLAGS_INIT}") + +cmake_initialize_per_config_variable(CMAKE_ISPC_FLAGS "Flags used by the ISPC compiler") + +if(CMAKE_ISPC_STANDARD_LIBRARIES_INIT) + set(CMAKE_ISPC_STANDARD_LIBRARIES "${CMAKE_ISPC_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by default with all ISPC applications.") + mark_as_advanced(CMAKE_ISPC_STANDARD_LIBRARIES) +endif() + +if(NOT CMAKE_ISPC_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_ISPC_COMPILER_LAUNCHER}) + set(CMAKE_ISPC_COMPILER_LAUNCHER "$ENV{CMAKE_ISPC_COMPILER_LAUNCHER}" + CACHE STRING "Compiler launcher for ISPC.") +endif() + +include(CMakeCommonLanguageInclude) + +# now define the following rules: +# CMAKE_ISPC_COMPILE_OBJECT + +# Create a static archive incrementally for large object file counts. +if(NOT DEFINED CMAKE_ISPC_ARCHIVE_CREATE) + set(CMAKE_ISPC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") +endif() +if(NOT DEFINED CMAKE_ISPC_ARCHIVE_APPEND) + set(CMAKE_ISPC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") +endif() +if(NOT DEFINED CMAKE_ISPC_ARCHIVE_FINISH) + set(CMAKE_ISPC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") +endif() + +if(NOT CMAKE_ISPC_COMPILE_OBJECT) + set(CMAKE_ISPC_COMPILE_OBJECT + "<CMAKE_ISPC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> --emit-obj <SOURCE> -h <ISPC_HEADER>") +endif() + +set(CMAKE_ISPC_INFORMATION_LOADED 1) diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake index 22fc95366..1a7f9cf2b 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -159,6 +159,11 @@ If your project has more elaborated version matching rules, you will need to write your own custom ``ConfigVersion.cmake`` file instead of using this macro. +.. note:: ``COMPATIBILITY_MODE`` ``AnyNewerVersion`` handles the version range + if any is specified (see :command:`find_package` command for the details). + All other modes are incompatible with version ranges and will display an + author warning if one is specified. + If ``ARCH_INDEPENDENT`` is given, the installed package version will be considered compatible even if it was built for a different architecture than the requested architecture. Otherwise, an architecture check will be performed, diff --git a/Modules/CMakeParseImplicitIncludeInfo.cmake b/Modules/CMakeParseImplicitIncludeInfo.cmake index ff4c32561..7cd75488c 100644 --- a/Modules/CMakeParseImplicitIncludeInfo.cmake +++ b/Modules/CMakeParseImplicitIncludeInfo.cmake @@ -7,7 +7,7 @@ # for compilers that report them that way. on success we return the # list of dirs in id_var and set state_var to the 'done' state. function(cmake_parse_implicit_include_line line lang id_var log_var state_var) - # clear variables we append to (avoids possible polution from parent scopes) + # clear variables we append to (avoids possible pollution from parent scopes) unset(rv) set(log "") @@ -162,7 +162,7 @@ endfunction() function(cmake_parse_implicit_include_info text lang dir_var log_var state_var) set(state start) # values: start, loading, done - # clear variables we append to (avoids possible polution from parent scopes) + # clear variables we append to (avoids possible pollution from parent scopes) set(implicit_dirs_tmp) set(log "") diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in index 40668a3e6..0b81c88eb 100644 --- a/Modules/CMakePlatformId.h.in +++ b/Modules/CMakePlatformId.h.in @@ -206,6 +206,24 @@ # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif + +#elif defined(__TI_COMPILER_VERSION__) +# if defined(__TI_ARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__MSP430__) +# define ARCHITECTURE_ID "MSP430" + +# elif defined(__TMS320C28XX__) +# define ARCHITECTURE_ID "TMS320C28x" + +# elif defined(__TMS320C6X__) || defined(_TMS320C6X) +# define ARCHITECTURE_ID "TMS320C6x" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + #else # define ARCHITECTURE_ID #endif @@ -283,4 +301,3 @@ char const info_simulate_version[] = { array rather than assigning a pointer to a static array. */ char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; - diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake index 3734ec46a..03f2db2d2 100644 --- a/Modules/CMakeTestCCompiler.cmake +++ b/Modules/CMakeTestCCompiler.cmake @@ -11,7 +11,7 @@ endif() include(CMakeTestCompilerCommon) -# work around enforced code signing and / or missing exectuable target type +# work around enforced code signing and / or missing executable target type set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake index b9cb1dd0e..0d2d0b053 100644 --- a/Modules/CMakeTestCXXCompiler.cmake +++ b/Modules/CMakeTestCXXCompiler.cmake @@ -11,7 +11,7 @@ endif() include(CMakeTestCompilerCommon) -# work around enforced code signing and / or missing exectuable target type +# work around enforced code signing and / or missing executable target type set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) diff --git a/Modules/CMakeTestISPCCompiler.cmake b/Modules/CMakeTestISPCCompiler.cmake new file mode 100644 index 000000000..6b163936d --- /dev/null +++ b/Modules/CMakeTestISPCCompiler.cmake @@ -0,0 +1,43 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + + +if(CMAKE_ISPC_COMPILER_FORCED) + # The compiler configuration was forced by the user. + # Assume the user has configured all compiler information. + set(CMAKE_ISPC_COMPILER_WORKS TRUE) + return() +endif() + +include(CMakeTestCompilerCommon) + +# Make sure we try to compile as a STATIC_LIBRARY +set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +# # Try to identify the ABI and configure it into CMakeISPCCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(ISPC ${CMAKE_ROOT}/Modules/CMakeISPCCompilerABI.ispc) +if(CMAKE_ISPC_ABI_COMPILED) +# # The compiler worked so skip dedicated test below. + set(CMAKE_ISPC_COMPILER_WORKS TRUE) + message(STATUS "Check for working ISPC compiler: ${CMAKE_ISPC_COMPILER} - skipped") +endif() + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeISPCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeISPCCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeISPCCompiler.cmake) + +if(CMAKE_ISPC_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_ISPC_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_ISPC_ABI_FILES) +endif() + +set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) diff --git a/Modules/CMakeTestOBJCCompiler.cmake b/Modules/CMakeTestOBJCCompiler.cmake index 0e333c0ef..298272b85 100644 --- a/Modules/CMakeTestOBJCCompiler.cmake +++ b/Modules/CMakeTestOBJCCompiler.cmake @@ -11,7 +11,7 @@ endif() include(CMakeTestCompilerCommon) -# work around enforced code signing and / or missing exectuable target type +# work around enforced code signing and / or missing executable target type set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) diff --git a/Modules/CMakeTestOBJCXXCompiler.cmake b/Modules/CMakeTestOBJCXXCompiler.cmake index dc153a7b9..36e3efc50 100644 --- a/Modules/CMakeTestOBJCXXCompiler.cmake +++ b/Modules/CMakeTestOBJCXXCompiler.cmake @@ -11,7 +11,7 @@ endif() include(CMakeTestCompilerCommon) -# work around enforced code signing and / or missing exectuable target type +# work around enforced code signing and / or missing executable target type set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index d0cfc2b18..7529a1f43 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -22,9 +22,13 @@ section below for details. The generated binary installers will contain all files that have been installed via CMake's :command:`install` command (and the deprecated commands :command:`install_files`, :command:`install_programs`, and -:command:`install_targets`). Certain kinds of binary installers can be -configured such that users can select individual application components to -install. See the :module:`CPackComponent` module for further details. +:command:`install_targets`). Note that the ``DESTINATION`` option of the +:command:`install` command must be a relative path; otherwise installed files +are ignored by CPack. + +Certain kinds of binary installers can be configured such that users can select +individual application components to install. See the :module:`CPackComponent` +module for further details. Source packages (configured through ``CPackSourceConfig.cmake`` and generated by the :cpack_gen:`CPack Archive Generator`) will contain all source files in @@ -353,7 +357,7 @@ The following variables are for advanced uses of CPack: .. variable:: CPACK_INSTALL_SCRIPTS Extra CMake scripts executed by CPack during its local staging - installation, which is done right before packaging the files. + installation. They are executed before installing the files to be packaged. The scripts are not called by a standalone install (e.g.: ``make install``). For every script, the following variables will be set: :variable:`CMAKE_CURRENT_SOURCE_DIR`, :variable:`CMAKE_CURRENT_BINARY_DIR` @@ -362,6 +366,33 @@ The following variables are for advanced uses of CPack: an alternative variable for historical reasons, but its value is ignored if ``CMAKE_INSTALL_SCRIPTS`` is set and a warning will be issued. + See also :variable:`CPACK_PRE_BUILD_SCRIPTS` and + :variable:`CPACK_POST_BUILD_SCRIPTS` which can be used to specify scripts + to be executed later in the packaging process. + +.. variable:: CPACK_PRE_BUILD_SCRIPTS + + List of CMake scripts to execute after CPack has installed the files to + be packaged into a staging directory and before producing the package(s) + from those files. See also :variable:`CPACK_INSTALL_SCRIPTS` and + :variable:`CPACK_POST_BUILD_SCRIPTS`. + +.. variable:: CPACK_POST_BUILD_SCRIPTS + + List of CMake scripts to execute after CPack has produced the resultant + packages and before copying them back to the build directory. + See also :variable:`CPACK_INSTALL_SCRIPTS`, + :variable:`CPACK_PRE_BUILD_SCRIPTS` and :variable:`CPACK_PACKAGE_FILES`. + +.. variable:: CPACK_PACKAGE_FILES + + List of package files created in the staging directory, with each file + provided as a full absolute path. This variable is populated by CPack + just before invoking the post-build scripts listed in + :variable:`CPACK_POST_BUILD_SCRIPTS`. It is the preferred way for the + post-build scripts to know the set of package files to operate on. + Projects should not try to set this variable themselves. + .. variable:: CPACK_INSTALLED_DIRECTORIES Extra directories to install. @@ -420,7 +451,7 @@ endmacro() # find any variable that starts with CPACK and create a variable # _CPACK_OTHER_VARIABLES_ that contains SET commands for # each cpack variable. _CPACK_OTHER_VARIABLES_ is then -# used as an @ replacment in configure_file for the CPackConfig. +# used as an @ replacement in configure_file for the CPackConfig. function(cpack_encode_variables) set(commands "") get_cmake_property(res VARIABLES) diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake index 80a907ffd..6ce0bfcc8 100644 --- a/Modules/CPackIFW.cmake +++ b/Modules/CPackIFW.cmake @@ -5,6 +5,8 @@ CPackIFW -------- +.. versionadded:: 3.1 + This module looks for the location of the command-line utilities supplied with the `Qt Installer Framework <http://doc.qt.io/qtinstallerframework/index.html>`_ (QtIFW). @@ -359,6 +361,7 @@ set(_CPACK_IFW_PREFIXES "QtIFW-") set(_CPACK_IFW_VERSIONS + "4.0" "3.2" "3.2.0" "3.1" @@ -434,6 +437,16 @@ find_program(CPACK_IFW_DEVTOOL_EXECUTABLE ) mark_as_advanced(CPACK_IFW_DEVTOOL_EXECUTABLE) +# Look for 'archivegen' + +find_program(CPACK_IFW_ARCHIVEGEN_EXECUTABLE + NAMES archivegen + PATHS ${_CPACK_IFW_PATHS} + PATH_SUFFIXES ${_CPACK_IFW_SUFFIXES} + DOC "QtIFW archivegen command line client" + ) +mark_as_advanced(CPACK_IFW_ARCHIVEGEN_EXECUTABLE) + # ## Next code is included only once # @@ -454,7 +467,7 @@ mark_as_advanced(CPACK_IFW_FRAMEWORK_VERSION_TIMEOUT) if(CPACK_IFW_INSTALLERBASE_EXECUTABLE AND NOT CPACK_IFW_FRAMEWORK_VERSION_FORCED) set(CPACK_IFW_FRAMEWORK_VERSION) # Invoke version from "installerbase" executable - foreach(_ifw_version_argument --framework-version --version) + foreach(_ifw_version_argument --version --framework-version) if(NOT CPACK_IFW_FRAMEWORK_VERSION) execute_process(COMMAND "${CPACK_IFW_INSTALLERBASE_EXECUTABLE}" ${_ifw_version_argument} diff --git a/Modules/CPackIFWConfigureFile.cmake b/Modules/CPackIFWConfigureFile.cmake index 0abe0da37..296b13f72 100644 --- a/Modules/CPackIFWConfigureFile.cmake +++ b/Modules/CPackIFWConfigureFile.cmake @@ -5,6 +5,8 @@ CPackIFWConfigureFile --------------------- +.. versionadded:: 3.8 + The module defines :command:`configure_file` similar command to configure file templates prepared in QtIFW/SDK/Creator style. diff --git a/Modules/CSharpUtilities.cmake b/Modules/CSharpUtilities.cmake index 6a4b5c7f7..dedb146ac 100644 --- a/Modules/CSharpUtilities.cmake +++ b/Modules/CSharpUtilities.cmake @@ -5,6 +5,8 @@ CSharpUtilities --------------- +.. versionadded:: 3.8 + Functions to make configuration of CSharp/.NET targets easier. A collection of CMake utility functions useful for dealing with CSharp diff --git a/Modules/CTest.cmake b/Modules/CTest.cmake index 8109108ec..8265bd26e 100644 --- a/Modules/CTest.cmake +++ b/Modules/CTest.cmake @@ -174,7 +174,7 @@ if(BUILD_TESTING) "How many times to retry timed-out CTest submissions.") find_program(MEMORYCHECK_COMMAND - NAMES purify valgrind boundscheck drmemory + NAMES purify valgrind boundscheck drmemory cuda-memcheck compute-sanitizer PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]" DOC "Path to the memory checking command, used for memory error detection." diff --git a/Modules/CTestCoverageCollectGCOV.cmake b/Modules/CTestCoverageCollectGCOV.cmake index b1268bebf..a01a2fea2 100644 --- a/Modules/CTestCoverageCollectGCOV.cmake +++ b/Modules/CTestCoverageCollectGCOV.cmake @@ -5,6 +5,8 @@ CTestCoverageCollectGCOV ------------------------ +.. versionadded:: 3.2 + This module provides the ``ctest_coverage_collect_gcov`` function. This function runs gcov on all .gcda files found in the binary tree diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index 1452b5186..335b43713 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -34,24 +34,8 @@ effect or even a specific one is beyond the scope of this module. include_guard(GLOBAL) include(CheckCSourceCompiles) -include(CMakeCheckCompilerFlagCommonPatterns) - -function(check_c_compiler_flag _flag _var) - set(CMAKE_REQUIRED_DEFINITIONS "${_flag}") - - # Normalize locale during test compilation. - set(_locale_vars LC_ALL LC_MESSAGES LANG) - foreach(v IN LISTS _locale_vars) - set(_locale_vars_saved_${v} "$ENV{${v}}") - set(ENV{${v}} C) - endforeach() - check_compiler_flag_common_patterns(_common_patterns) - check_c_source_compiles("int main(void) { return 0; }" ${_var} - # Some compilers do not fail with a bad flag - FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU - ${_common_patterns} - ) - foreach(v IN LISTS _locale_vars) - set(ENV{${v}} ${_locale_vars_saved_${v}}) - endforeach() -endfunction() +include(Internal/CheckCompilerFlag) + +macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT) + cmake_check_compiler_flag(C "${_FLAG}" ${_RESULT}) +endmacro () diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index 67fc993be..698a007eb 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -66,80 +66,8 @@ Check if given C source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) macro(CHECK_C_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing C SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + cmake_check_source_compiles(C "${SOURCE}" ${VAR} ${ARGN}) endmacro() diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake index 7d116db8d..a99e47e83 100644 --- a/Modules/CheckCSourceRuns.cmake +++ b/Modules/CheckCSourceRuns.cmake @@ -65,81 +65,10 @@ subsequently be run. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceRuns) macro(CHECK_C_SOURCE_RUNS SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_run(${VAR}_EXITCODE ${VAR}_COMPILED - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} - "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) - # if it did not compile make the return value fail code of 1 - if(NOT ${VAR}_COMPILED) - set(${VAR}_EXITCODE 1) - endif() - # if the return value was 0 then it worked - if("${${VAR}_EXITCODE}" EQUAL 0) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing C SOURCE FILE Test ${VAR} succeeded with the following compile output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}}\n" - "Source file was:\n${SOURCE}\n") - else() - if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") - set(${VAR} "${${VAR}_EXITCODE}") - else() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - endif() - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing C SOURCE FILE Test ${VAR} failed with the following compile output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}_EXITCODE}\n" - "Source file was:\n${SOURCE}\n") - - endif() - endif() + set(_CheckSourceRuns_old_signature 1) + cmake_check_source_runs(C "${SOURCE}" ${VAR} ${ARGN}) + unset(_CheckSourceRuns_old_signature) endmacro() diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake index 544e9ac60..3bc346362 100644 --- a/Modules/CheckCXXCompilerFlag.cmake +++ b/Modules/CheckCXXCompilerFlag.cmake @@ -34,24 +34,8 @@ effect or even a specific one is beyond the scope of this module. include_guard(GLOBAL) include(CheckCXXSourceCompiles) -include(CMakeCheckCompilerFlagCommonPatterns) - -function(check_cxx_compiler_flag _flag _var) - set(CMAKE_REQUIRED_DEFINITIONS "${_flag}") - - # Normalize locale during test compilation. - set(_locale_vars LC_ALL LC_MESSAGES LANG) - foreach(v IN LISTS _locale_vars) - set(_locale_vars_saved_${v} "$ENV{${v}}") - set(ENV{${v}} C) - endforeach() - check_compiler_flag_common_patterns(_common_patterns) - check_cxx_source_compiles("int main() { return 0; }" ${_var} - # Some compilers do not fail with a bad flag - FAIL_REGEX "command line option .* is valid for .* but not for C\\\\+\\\\+" # GNU - ${_common_patterns} - ) - foreach(v IN LISTS _locale_vars) - set(ENV{${v}} ${_locale_vars_saved_${v}}) - endforeach() -endfunction() +include(Internal/CheckCompilerFlag) + +macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT) + cmake_check_compiler_flag(CXX "${_FLAG}" ${_RESULT}) +endmacro () diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake index c693d32b3..dc209b268 100644 --- a/Modules/CheckCXXSourceCompiles.cmake +++ b/Modules/CheckCXXSourceCompiles.cmake @@ -66,81 +66,8 @@ Check if given C++ source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + cmake_check_source_compiles(CXX "${SOURCE}" ${VAR} ${ARGN}) endmacro() diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index 408e183a3..c8ff3d7bf 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -65,81 +65,10 @@ subsequently be run. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceRuns) macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_run(${VAR}_EXITCODE ${VAR}_COMPILED - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} - "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) - - # if it did not compile make the return value fail code of 1 - if(NOT ${VAR}_COMPILED) - set(${VAR}_EXITCODE 1) - endif() - # if the return value was 0 then it worked - if("${${VAR}_EXITCODE}" EQUAL 0) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}}\n" - "Source file was:\n${SOURCE}\n") - else() - if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") - set(${VAR} "${${VAR}_EXITCODE}") - else() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - endif() - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}_EXITCODE}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + set(_CheckSourceRuns_old_signature 1) + cmake_check_source_runs(CXX "${SOURCE}" ${VAR} ${ARGN}) + unset(_CheckSourceRuns_old_signature) endmacro() diff --git a/Modules/CheckCompilerFlag.cmake b/Modules/CheckCompilerFlag.cmake new file mode 100644 index 000000000..77c07b95d --- /dev/null +++ b/Modules/CheckCompilerFlag.cmake @@ -0,0 +1,41 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +CheckCompilerFlag +--------------------- + +.. versionadded:: 3.19 + +Check whether the compiler supports a given flag. + +.. command:: check_compiler_flag + + .. code-block:: cmake + + check_compiler_flag(<lang> <flag> <var>) + +Check that the ``<flag>`` is accepted by the compiler without a diagnostic. +Stores the result in an internal cache entry named ``<var>``. + +This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable +and calls the ``check_source_compiles(<LANG>)`` function from the +:module:`CheckSourceCompiles` module. See documentation of that +module for a listing of variables that can otherwise modify the build. + +A positive result from this check indicates only that the compiler did not +issue a diagnostic message when given the flag. Whether the flag has any +effect or even a specific one is beyond the scope of this module. + +.. note:: + Since the :command:`try_compile` command forwards flags from variables + like :variable:`CMAKE_<LANG>_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags + in such variables may cause a false negative for this check. +#]=======================================================================] + +include_guard(GLOBAL) +include(Internal/CheckCompilerFlag) + +function(CHECK_COMPILER_FLAG _lang _flag _var) + cmake_check_compiler_flag(${_lang} "${_flag}" ${_var}) +endfunction() diff --git a/Modules/CheckFortranCompilerFlag.cmake b/Modules/CheckFortranCompilerFlag.cmake index 299cd8cfc..5b1cd0277 100644 --- a/Modules/CheckFortranCompilerFlag.cmake +++ b/Modules/CheckFortranCompilerFlag.cmake @@ -5,6 +5,8 @@ CheckFortranCompilerFlag ------------------------ +.. versionadded:: 3.3 + Check whether the Fortran compiler supports a given flag. .. command:: check_fortran_compiler_flag @@ -34,30 +36,8 @@ effect or even a specific one is beyond the scope of this module. include_guard(GLOBAL) include(CheckFortranSourceCompiles) -include(CMakeCheckCompilerFlagCommonPatterns) - -macro (CHECK_Fortran_COMPILER_FLAG _FLAG _RESULT) - set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") - - # Normalize locale during test compilation. - set(_CheckFortranCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) - foreach(v ${_CheckFortranCompilerFlag_LOCALE_VARS}) - set(_CheckFortranCompilerFlag_SAVED_${v} "$ENV{${v}}") - set(ENV{${v}} C) - endforeach() - CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckFortranCompilerFlag_COMMON_PATTERNS) - CHECK_Fortran_SOURCE_COMPILES(" program test\n stop\n end program" ${_RESULT} - # Some compilers do not fail with a bad flag - FAIL_REGEX "command line option .* is valid for .* but not for Fortran" # GNU - ${_CheckFortranCompilerFlag_COMMON_PATTERNS} - ) - foreach(v ${_CheckFortranCompilerFlag_LOCALE_VARS}) - set(ENV{${v}} ${_CheckFortranCompilerFlag_SAVED_${v}}) - unset(_CheckFortranCompilerFlag_SAVED_${v}) - endforeach() - unset(_CheckFortranCompilerFlag_LOCALE_VARS) - unset(_CheckFortranCompilerFlag_COMMON_PATTERNS) - - set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") +include(Internal/CheckCompilerFlag) + +macro (CHECK_FORTRAN_COMPILER_FLAG _FLAG _RESULT) + cmake_check_compiler_flag(Fortran "${_FLAG}" ${_RESULT}) endmacro () diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index 3354bfb25..5ede28457 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -5,6 +5,8 @@ CheckFortranSourceCompiles -------------------------- +.. versionadded:: 3.1 + Check if given Fortran source compiles and links into an executable. .. command:: check_fortran_source_compiles @@ -85,82 +87,10 @@ Check if given Fortran source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_SRC_EXT) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - if(NOT _SRC_EXT) - set(_SRC_EXT F) - endif() - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} - COMPILE_DEFINITIONS -D${VAR} ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} - "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Fortran SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Fortran SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + # Pass the SRC_EXT we used by default historically. + # A user-provided SRC_EXT argument in ARGN will override ours. + cmake_check_source_compiles(Fortran "${SOURCE}" ${VAR} SRC_EXT "F" ${ARGN}) endmacro() diff --git a/Modules/CheckFortranSourceRuns.cmake b/Modules/CheckFortranSourceRuns.cmake index f858b84a8..28f713fdf 100644 --- a/Modules/CheckFortranSourceRuns.cmake +++ b/Modules/CheckFortranSourceRuns.cmake @@ -5,6 +5,8 @@ CheckFortranSourceRuns ---------------------- +.. versionadded:: 3.14 + Check if given Fortran source compiles and links into an executable and can subsequently be run. @@ -81,93 +83,10 @@ subsequently be run. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceRuns) macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_SRC_EXT) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(SRC_EXT)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - if(NOT _SRC_EXT) - set(_SRC_EXT F90) - endif() - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_run(${VAR}_EXITCODE ${VAR}_COMPILED - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} - COMPILE_DEFINITIONS -D${VAR} ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} - -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} - "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) - - # if it did not compile make the return value fail code of 1 - if(NOT ${VAR}_COMPILED) - set(${VAR}_EXITCODE 1) - endif() - # if the return value was 0 then it worked - if("${${VAR}_EXITCODE}" EQUAL 0) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Fortran SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}}\n" - "Source file was:\n${SOURCE}\n") - else() - if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") - set(${VAR} "${${VAR}_EXITCODE}") - else() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - endif() - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Fortran SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}_EXITCODE}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + # Pass the SRC_EXT we used by default historically. + # A user-provided SRC_EXT argument in ARGN will override ours. + cmake_check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN}) endmacro() diff --git a/Modules/CheckIPOSupported.cmake b/Modules/CheckIPOSupported.cmake index 90a9f6180..1dd951d83 100644 --- a/Modules/CheckIPOSupported.cmake +++ b/Modules/CheckIPOSupported.cmake @@ -5,6 +5,8 @@ CheckIPOSupported ----------------- +.. versionadded:: 3.9 + Check whether the compiler supports an interprocedural optimization (IPO/LTO). Use this before enabling the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property. diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index d67d8d3ac..44387d4b4 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -20,7 +20,7 @@ test project. The result is cached in :variable:`CMAKE_<LANG>_COMPILER` as the compiler that was found, or ``NOTFOUND`` if the language cannot be enabled. For CUDA which can have an explicit host compiler, the cache :variable:`CMAKE_CUDA_HOST_COMPILER` variable will be set if it was required -for compilation. +for compilation (and cleared if it was not). Example: diff --git a/Modules/CheckLinkerFlag.cmake b/Modules/CheckLinkerFlag.cmake index beda5fe3c..3c7a8286e 100644 --- a/Modules/CheckLinkerFlag.cmake +++ b/Modules/CheckLinkerFlag.cmake @@ -5,6 +5,8 @@ CheckLinkerFlag --------------- +.. versionadded:: 3.18 + Check whether the compiler supports a given link flag. .. command:: check_linker_flag @@ -17,15 +19,12 @@ Check that the link ``<flag>`` is accepted by the ``<lang>`` compiler without a diagnostic. Stores the result in an internal cache entry named ``<var>``. This command temporarily sets the ``CMAKE_REQUIRED_LINK_OPTIONS`` variable -and calls the ``check_<lang>_source_compiles`` macro from the -``Check<lang>SourceCompiles`` module (:module:`CheckCSourceCompiles`, -:module:`CheckCSourceCompiles`, :module:`CheckCXXSourceCompiles`, -:module:`CheckOBJCSourceCompiles`, :module:`CheckOBJCXXSourceCompiles` or -:module:`CheckFortranSourceCompiles`). See documentation of these -modules for a listing of variables that can otherwise modify the build. - -The underlying implementation rely on :prop_tgt:`LINK_OPTIONS` property to -check the specified flag. The ``LINKER:`` prefix, as described in +and calls the :command:`check_source_compiles` command from the +:module:`CheckSourceCompiles` module. See that module's documentation +for a listing of variables that can otherwise modify the build. + +The underlying implementation relies on the :prop_tgt:`LINK_OPTIONS` property +to check the specified flag. The ``LINKER:`` prefix, as described in the :command:`target_link_options` command, can be used as well. A positive result from this check indicates only that the compiler did not @@ -49,7 +48,7 @@ function(CHECK_LINKER_FLAG _lang _flag _var) return() endif() - include (Check${_lang}SourceCompiles) + include (CheckSourceCompiles) set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}") @@ -64,6 +63,8 @@ function(CHECK_LINKER_FLAG _lang _flag _var) set (_source "int main() { return 0; }") elseif (_lang STREQUAL "Fortran") set (_source " program test\n stop\n end program") + elseif (_lang MATCHES "CUDA") + set (_source "__host__ int main() { return 0; }") elseif (_lang MATCHES "^(OBJC|OBJCXX)$") set (_source "#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }") else() @@ -72,7 +73,7 @@ function(CHECK_LINKER_FLAG _lang _flag _var) endif() check_compiler_flag_common_patterns(_common_patterns) - cmake_language (CALL check_${_lang}_source_compiles "${_source}" ${_var} ${_common_patterns}) + check_source_compiles(${_lang} "${_source}" ${_var} ${_common_patterns}) foreach(v IN LISTS _locale_vars) set(ENV{${v}} ${_locale_vars_saved_${v}}) diff --git a/Modules/CheckOBJCCompilerFlag.cmake b/Modules/CheckOBJCCompilerFlag.cmake index 1d975da88..d8d874175 100644 --- a/Modules/CheckOBJCCompilerFlag.cmake +++ b/Modules/CheckOBJCCompilerFlag.cmake @@ -5,6 +5,8 @@ CheckOBJCCompilerFlag --------------------- +.. versionadded:: 3.16 + Check whether the Objective-C compiler supports a given flag. .. command:: check_objc_compiler_flag @@ -34,31 +36,8 @@ effect or even a specific one is beyond the scope of this module. include_guard(GLOBAL) include(CheckOBJCSourceCompiles) -include(CMakeCheckCompilerFlagCommonPatterns) +include(Internal/CheckCompilerFlag) macro (CHECK_OBJC_COMPILER_FLAG _FLAG _RESULT) - set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") - - # Normalize locale during test compilation. - set(_CheckOBJCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) - foreach(v ${_CheckOBJCCompilerFlag_LOCALE_VARS}) - set(_CheckOBJCCompilerFlag_SAVED_${v} "$ENV{${v}}") - set(ENV{${v}} OBJC) - endforeach() - CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckOBJCCompilerFlag_COMMON_PATTERNS) - CHECK_OBJC_SOURCE_COMPILES("#ifndef __OBJC__\n# error \"Not an Objective-C compiler\"\n#endif\nint main(void) { return 0; }" ${_RESULT} - # Some compilers do not fail with a bad flag - FAIL_REGEX "command line option .* is valid for .* but not for Objective-C" # GNU - FAIL_REGEX "argument unused during compilation: .*" # Clang - ${_CheckOBJCCompilerFlag_COMMON_PATTERNS} - ) - foreach(v ${_CheckOBJCCompilerFlag_LOCALE_VARS}) - set(ENV{${v}} ${_CheckOBJCCompilerFlag_SAVED_${v}}) - unset(_CheckOBJCCompilerFlag_SAVED_${v}) - endforeach() - unset(_CheckOBJCCompilerFlag_LOCALE_VARS) - unset(_CheckOBJCCompilerFlag_COMMON_PATTERNS) - - set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") + cmake_check_compiler_flag(OBJC "${_FLAG}" ${_RESULT}) endmacro () diff --git a/Modules/CheckOBJCSourceCompiles.cmake b/Modules/CheckOBJCSourceCompiles.cmake index 601f1fa44..c268ef905 100644 --- a/Modules/CheckOBJCSourceCompiles.cmake +++ b/Modules/CheckOBJCSourceCompiles.cmake @@ -5,6 +5,8 @@ CheckOBJCSourceCompiles ----------------------- +.. versionadded:: 3.16 + Check if given Objective-C source compiles and links into an executable. .. command:: check_objc_source_compiles @@ -66,80 +68,8 @@ Check if given Objective-C source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.m" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.m - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Objective-C SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Objective-C SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + cmake_check_source_compiles(OBJC "${SOURCE}" ${VAR} ${ARGN}) endmacro() diff --git a/Modules/CheckOBJCSourceRuns.cmake b/Modules/CheckOBJCSourceRuns.cmake index 668469391..dd0330993 100644 --- a/Modules/CheckOBJCSourceRuns.cmake +++ b/Modules/CheckOBJCSourceRuns.cmake @@ -5,6 +5,8 @@ CheckOBJCSourceRuns ------------------- +.. versionadded:: 3.16 + Check if given Objective-C source compiles and links into an executable and can subsequently be run. @@ -65,81 +67,10 @@ subsequently be run. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceRuns) macro(CHECK_OBJC_SOURCE_RUNS SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.m" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_run(${VAR}_EXITCODE ${VAR}_COMPILED - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.m - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_OBJC_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_OBJC_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} - "${CHECK_OBJC_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) - # if it did not compile make the return value fail code of 1 - if(NOT ${VAR}_COMPILED) - set(${VAR}_EXITCODE 1) - endif() - # if the return value was 0 then it worked - if("${${VAR}_EXITCODE}" EQUAL 0) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Objective-C SOURCE FILE Test ${VAR} succeeded with the following compile output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}}\n" - "Source file was:\n${SOURCE}\n") - else() - if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") - set(${VAR} "${${VAR}_EXITCODE}") - else() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - endif() - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Objective-C SOURCE FILE Test ${VAR} failed with the following compile output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}_EXITCODE}\n" - "Source file was:\n${SOURCE}\n") - - endif() - endif() + set(_CheckSourceRuns_old_signature 1) + cmake_check_source_runs(OBJC "${SOURCE}" ${VAR} ${ARGN}) + unset(_CheckSourceRuns_old_signature) endmacro() diff --git a/Modules/CheckOBJCXXCompilerFlag.cmake b/Modules/CheckOBJCXXCompilerFlag.cmake index c32741b54..3f3f8fe38 100644 --- a/Modules/CheckOBJCXXCompilerFlag.cmake +++ b/Modules/CheckOBJCXXCompilerFlag.cmake @@ -5,6 +5,8 @@ CheckOBJCXXCompilerFlag ----------------------- +.. versionadded:: 3.16 + Check whether the Objective-C++ compiler supports a given flag. .. command:: check_objcxx_compiler_flag @@ -34,31 +36,8 @@ effect or even a specific one is beyond the scope of this module. include_guard(GLOBAL) include(CheckOBJCXXSourceCompiles) -include(CMakeCheckCompilerFlagCommonPatterns) +include(Internal/CheckCompilerFlag) macro (CHECK_OBJCXX_COMPILER_FLAG _FLAG _RESULT) - set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") - - # Normalize locale during test compilation. - set(_CheckOBJCXXCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) - foreach(v ${_CheckOBJCXXCompilerFlag_LOCALE_VARS}) - set(_CheckOBJCXXCompilerFlag_SAVED_${v} "$ENV{${v}}") - set(ENV{${v}} OBJCXX) - endforeach() - CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckOBJCXXCompilerFlag_COMMON_PATTERNS) - CHECK_OBJCXX_SOURCE_COMPILES("#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }" ${_RESULT} - # Some compilers do not fail with a bad flag - FAIL_REGEX "command line option .* is valid for .* but not for Objective-C\\\\+\\\\+" # GNU - FAIL_REGEX "argument unused during compilation: .*" # Clang - ${_CheckOBJCXXCompilerFlag_COMMON_PATTERNS} - ) - foreach(v ${_CheckOBJCXXCompilerFlag_LOCALE_VARS}) - set(ENV{${v}} ${_CheckOBJCXXCompilerFlag_SAVED_${v}}) - unset(_CheckOBJCXXCompilerFlag_SAVED_${v}) - endforeach() - unset(_CheckOBJCXXCompilerFlag_LOCALE_VARS) - unset(_CheckOBJCXXCompilerFlag_COMMON_PATTERNS) - - set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") + cmake_check_compiler_flag(OBJCXX "${_FLAG}" ${_RESULT}) endmacro () diff --git a/Modules/CheckOBJCXXSourceCompiles.cmake b/Modules/CheckOBJCXXSourceCompiles.cmake index 2ee79f48a..11869343a 100644 --- a/Modules/CheckOBJCXXSourceCompiles.cmake +++ b/Modules/CheckOBJCXXSourceCompiles.cmake @@ -5,6 +5,8 @@ CheckOBJCXXSourceCompiles ------------------------- +.. versionadded:: 3.16 + Check if given Objective-C++ source compiles and links into an executable. .. command:: check_objcxx_source_compiles @@ -66,81 +68,8 @@ Check if given Objective-C++ source compiles and links into an executable. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) macro(CHECK_OBJCXX_SOURCE_COMPILES SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(_FAIL_REGEX) - set(_key) - foreach(arg ${ARGN}) - if("${arg}" MATCHES "^(FAIL_REGEX)$") - set(_key "${arg}") - elseif(_key) - list(APPEND _${_key} "${arg}") - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.mm" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_compile(${VAR} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.mm - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - - foreach(_regex ${_FAIL_REGEX}) - if("${OUTPUT}" MATCHES "${_regex}") - set(${VAR} 0) - endif() - endforeach() - - if(${VAR}) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Objective-C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - else() - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Objective-C++ SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + cmake_check_source_compiles(OBJCXX "${SOURCE}" ${VAR} ${ARGN}) endmacro() diff --git a/Modules/CheckOBJCXXSourceRuns.cmake b/Modules/CheckOBJCXXSourceRuns.cmake index 7f7e04f77..05a5e4cf5 100644 --- a/Modules/CheckOBJCXXSourceRuns.cmake +++ b/Modules/CheckOBJCXXSourceRuns.cmake @@ -5,6 +5,8 @@ CheckOBJCXXSourceRuns --------------------- +.. versionadded:: 3.16 + Check if given Objective-C++ source compiles and links into an executable and can subsequently be run. @@ -65,81 +67,10 @@ subsequently be run. #]=======================================================================] include_guard(GLOBAL) +include(Internal/CheckSourceRuns) macro(CHECK_OBJCXX_SOURCE_RUNS SOURCE VAR) - if(NOT DEFINED "${VAR}") - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") - if(CMAKE_REQUIRED_LINK_OPTIONS) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS - LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS) - endif() - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES - LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES) - endif() - if(CMAKE_REQUIRED_INCLUDES) - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - else() - set(CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES) - endif() - file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.mm" - "${SOURCE}\n") - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_START "Performing Test ${VAR}") - endif() - try_run(${VAR}_EXITCODE ${VAR}_COMPILED - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.mm - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - ${CHECK_OBJCXX_SOURCE_COMPILES_ADD_LINK_OPTIONS} - ${CHECK_OBJCXX_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} - "${CHECK_OBJCXX_SOURCE_COMPILES_ADD_INCLUDES}" - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) - - # if it did not compile make the return value fail code of 1 - if(NOT ${VAR}_COMPILED) - set(${VAR}_EXITCODE 1) - endif() - # if the return value was 0 then it worked - if("${${VAR}_EXITCODE}" EQUAL 0) - set(${VAR} 1 CACHE INTERNAL "Test ${VAR}") - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_PASS "Success") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Performing Objective-C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}}\n" - "Source file was:\n${SOURCE}\n") - else() - if(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") - set(${VAR} "${${VAR}_EXITCODE}") - else() - set(${VAR} "" CACHE INTERNAL "Test ${VAR}") - endif() - - if(NOT CMAKE_REQUIRED_QUIET) - message(CHECK_FAIL "Failed") - endif() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Performing Objective-C++ SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" - "...and run output:\n" - "${RUN_OUTPUT}\n" - "Return value: ${${VAR}_EXITCODE}\n" - "Source file was:\n${SOURCE}\n") - endif() - endif() + set(_CheckSourceRuns_old_signature 1) + cmake_check_source_runs(OBJCXX "${SOURCE}" ${VAR} ${ARGN}) + unset(_CheckSourceRuns_old_signature) endmacro() diff --git a/Modules/CheckPIESupported.cmake b/Modules/CheckPIESupported.cmake index 6d63f0bad..a99d8c41f 100644 --- a/Modules/CheckPIESupported.cmake +++ b/Modules/CheckPIESupported.cmake @@ -5,6 +5,8 @@ CheckPIESupported ----------------- +.. versionadded:: 3.14 + Check whether the linker supports Position Independent Code (PIE) or No Position Independent Code (NO_PIE) for executables. Use this to ensure that the :prop_tgt:`POSITION_INDEPENDENT_CODE` target diff --git a/Modules/CheckSourceCompiles.cmake b/Modules/CheckSourceCompiles.cmake new file mode 100644 index 000000000..ad74c3cad --- /dev/null +++ b/Modules/CheckSourceCompiles.cmake @@ -0,0 +1,82 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +#[=======================================================================[.rst: +CheckSourceCompiles +---------------------- + +.. versionadded:: 3.19 + +Check if given source compiles and links into an executable. + +.. command:: check_source_compiles + + .. code-block:: cmake + + check_source_compiles(<lang> <code> <resultVar> + [FAIL_REGEX <regex1> [<regex2>...]] + [SRC_EXT <extension>]) + + Check that the source supplied in ``<code>`` can be compiled as a source + file for the requested language and linked as an executable (so it must + contain at least a ``main()`` function). The result will be stored in the + internal cache variable specified by ``<resultVar>``, with a boolean true + value for success and boolean false for failure. If ``FAIL_REGEX`` is + provided, then failure is determined by checking if anything in the output + matches any of the specified regular expressions. + + By default, the test source file will be given a file extension that matches + the requested language. The ``SRC_EXT`` option can be used to override this + with ``.<extension>`` instead. + + The underlying check is performed by the :command:`try_compile` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_source_compiles()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_<LANG>_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``<resultVar>`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_compile` for further details). + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``<resultVar>``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``<code>`` changes. + In order to force the check to be re-evaluated, the variable named by + ``<resultVar>`` must be manually removed from the cache. + +#]=======================================================================] + + +include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) + +function(CHECK_SOURCE_COMPILES _lang _source _var) + cmake_check_source_compiles(${_lang} "${_source}" ${_var} ${ARGN}) +endfunction() diff --git a/Modules/CheckSourceRuns.cmake b/Modules/CheckSourceRuns.cmake new file mode 100644 index 000000000..8f1cf01ea --- /dev/null +++ b/Modules/CheckSourceRuns.cmake @@ -0,0 +1,80 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +#[=======================================================================[.rst: +CheckSourceRuns +------------------- + +.. versionadded:: 3.19 + +Check if given source compiles and links into an executable and can +subsequently be run. + +.. command:: check_source_runs + + .. code-block:: cmake + + check_source_runs(<lang> <code> <resultVar> + [SRC_EXT <extension>]) + + Check that the source supplied in ``<code>`` can be compiled as a source + file for the requested language, linked as an executable and then run. + The ``<code>`` must contain at least a ``main()`` function. If the ``<code>`` + could be built and run successfully, the internal cache variable specified by + ``<resultVar>`` will be set to 1, otherwise it will be set to an value that + evaluates to boolean false (e.g. an empty string or an error message). + + By default, the test source file will be given a file extension that matches + the requested language. The ``SRC_EXT`` option can be used to override this + with ``.<extension>`` instead. + + The underlying check is performed by the :command:`try_run` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_objc_source_runs()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_OBJC_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``<resultVar>`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LINK_OPTIONS`` + A :ref:`;-list <CMake Language Lists>` of options to add to the link + command (see :command:`try_run` for further details). + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``<resultVar>``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``<code>`` changes. + In order to force the check to be re-evaluated, the variable named by + ``<resultVar>`` must be manually removed from the cache. + +#]=======================================================================] + +include_guard(GLOBAL) +include(Internal/CheckSourceRuns) + +function(CHECK_SOURCE_RUNS _lang _source _var) + cmake_check_source_runs(${_lang} "${_source}" ${_var} ${ARGN}) +endfunction() diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake index 2b07b7cc0..17beadcb1 100644 --- a/Modules/CheckTypeSize.cmake +++ b/Modules/CheckTypeSize.cmake @@ -89,17 +89,38 @@ function(__check_type_size_impl type var map builtin language) message(CHECK_START "Check size of ${type}") endif() + # Perform language check + if(language STREQUAL "C") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) + elseif(language STREQUAL "CXX") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) + else() + message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") + endif() + # Include header files. set(headers) if(builtin) - if(HAVE_SYS_TYPES_H) - string(APPEND headers "#include <sys/types.h>\n") - endif() - if(HAVE_STDINT_H) - string(APPEND headers "#include <stdint.h>\n") - endif() - if(HAVE_STDDEF_H) - string(APPEND headers "#include <stddef.h>\n") + if(language STREQUAL "CXX" AND type MATCHES "^std::") + if(HAVE_SYS_TYPES_H) + string(APPEND headers "#include <sys/types.h>\n") + endif() + if(HAVE_CSTDINT) + string(APPEND headers "#include <cstdint>\n") + endif() + if(HAVE_CSTDDEF) + string(APPEND headers "#include <cstddef>\n") + endif() + else() + if(HAVE_SYS_TYPES_H) + string(APPEND headers "#include <sys/types.h>\n") + endif() + if(HAVE_STDINT_H) + string(APPEND headers "#include <stdint.h>\n") + endif() + if(HAVE_STDDEF_H) + string(APPEND headers "#include <stddef.h>\n") + endif() endif() endif() foreach(h ${CMAKE_EXTRA_INCLUDE_FILES}) @@ -107,14 +128,6 @@ function(__check_type_size_impl type var map builtin language) endforeach() # Perform the check. - - if(language STREQUAL "C") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) - elseif(language STREQUAL "CXX") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) - else() - message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") - endif() set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin) configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY) try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src} @@ -232,8 +245,13 @@ macro(CHECK_TYPE_SIZE TYPE VARIABLE) check_include_file(stddef.h HAVE_STDDEF_H) elseif(_language STREQUAL "CXX") check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) - check_include_file_cxx(stdint.h HAVE_STDINT_H) - check_include_file_cxx(stddef.h HAVE_STDDEF_H) + if("${TYPE}" MATCHES "^std::") + check_include_file_cxx(cstdint HAVE_CSTDINT) + check_include_file_cxx(cstddef HAVE_CSTDDEF) + else() + check_include_file_cxx(stdint.h HAVE_STDINT_H) + check_include_file_cxx(stddef.h HAVE_STDDEF_H) + endif() endif() endif() unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY) diff --git a/Modules/Compiler/ARMClang-ASM.cmake b/Modules/Compiler/ARMClang-ASM.cmake index ceff3e8ce..6a299be82 100644 --- a/Modules/Compiler/ARMClang-ASM.cmake +++ b/Modules/Compiler/ARMClang-ASM.cmake @@ -3,7 +3,7 @@ include(Compiler/ARMClang) set(CMAKE_ASM_OUTPUT_EXTENSION ".o") set(CMAKE_ASM_OUTPUT_EXTENSION_REPLACE 1) -set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <INCLUDES> <FLAGS> -c -o <OBJECT> <SOURCE>") +set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -c -o <OBJECT> <SOURCE>") set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS S;s;asm;msa) __compiler_armclang(ASM) diff --git a/Modules/Compiler/ARMClang.cmake b/Modules/Compiler/ARMClang.cmake index f100af843..da7a43c90 100644 --- a/Modules/Compiler/ARMClang.cmake +++ b/Modules/Compiler/ARMClang.cmake @@ -98,7 +98,7 @@ macro(__compiler_armclang lang) set(__mcpu_flag_set TRUE) endif() if(NOT __march_flag_set AND NOT __mcpu_flag_set) - message(FATAL_ERROR "Atleast one of the variables CMAKE_SYSTEM_PROCESSOR or CMAKE_SYSTEM_ARCH must be set for ARMClang\n" + message(FATAL_ERROR "At least one of the variables CMAKE_SYSTEM_PROCESSOR or CMAKE_SYSTEM_ARCH must be set for ARMClang\n" "Supported processor: ${CMAKE_${lang}_COMPILER_PROCESSOR_LIST}\n" " Supported Architecture: ${CMAKE_${lang}_COMPILER_ARCH_LIST}") endif() diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake index 2794f52bb..26a4bbd33 100644 --- a/Modules/Compiler/AppleClang-C.cmake +++ b/Modules/Compiler/AppleClang-C.cmake @@ -1,6 +1,8 @@ include(Compiler/Clang) __compiler_clang(C) +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90") set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90") diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake index 15edc21e9..611c67457 100644 --- a/Modules/Compiler/AppleClang-CXX.cmake +++ b/Modules/Compiler/AppleClang-CXX.cmake @@ -1,6 +1,8 @@ include(Compiler/Clang) __compiler_clang(CXX) +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) + if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") endif() diff --git a/Modules/Compiler/Clang-C.cmake b/Modules/Compiler/Clang-C.cmake index 7c4a263f6..fb6ffa7b0 100644 --- a/Modules/Compiler/Clang-C.cmake +++ b/Modules/Compiler/Clang-C.cmake @@ -8,6 +8,8 @@ endif() if("x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl") +elseif("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) endif() if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4) diff --git a/Modules/Compiler/Clang-CUDA.cmake b/Modules/Compiler/Clang-CUDA.cmake index 336827bf4..fd8c2b7c9 100644 --- a/Modules/Compiler/Clang-CUDA.cmake +++ b/Modules/Compiler/Clang-CUDA.cmake @@ -13,6 +13,7 @@ __compiler_clang_cxx_standards(CUDA) set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE TRUE) set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cuda") set(_CMAKE_CUDA_PTX_FLAG "--cuda-device-only -S") +set(_CMAKE_CUDA_DEVICE_CODE "-fgpu-rdc -c") # RulePlaceholderExpander expands crosscompile variables like sysroot and target only for CMAKE_<LANG>_COMPILER. Override the default. set(CMAKE_CUDA_LINK_EXECUTABLE "<CMAKE_CUDA_COMPILER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}") diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake index 789e99159..311d2b07f 100644 --- a/Modules/Compiler/Clang-CXX.cmake +++ b/Modules/Compiler/Clang-CXX.cmake @@ -2,7 +2,9 @@ include(Compiler/Clang) __compiler_clang(CXX) __compiler_clang_cxx_standards(CXX) + if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") endif() diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index f7858d788..27692c2fe 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -19,6 +19,7 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC" OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC") macro(__compiler_clang lang) + set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-imsvc ") endmacro() else() include(Compiler/GNU) @@ -106,6 +107,9 @@ else() if (NOT CMAKE_GENERATOR MATCHES "Xcode") set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") endif() + if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0.0 AND NOT __is_apple_clang) + set(CMAKE_${lang}_COMPILE_OPTIONS_INSTANTIATE_TEMPLATES_PCH -fpch-instantiate-templates) + endif() set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE> -Xclang -include -Xclang <PCH_HEADER>) set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER> -x ${__pch_header_${lang}}) endmacro() diff --git a/Modules/Compiler/GNU-C.cmake b/Modules/Compiler/GNU-C.cmake index ca286b397..8105a77f6 100644 --- a/Modules/Compiler/GNU-C.cmake +++ b/Modules/Compiler/GNU-C.cmake @@ -1,6 +1,8 @@ include(Compiler/GNU) __compiler_gnu(C) +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5) set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90") set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90") diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake index fcaaeab43..59ec05691 100644 --- a/Modules/Compiler/GNU-CXX.cmake +++ b/Modules/Compiler/GNU-CXX.cmake @@ -1,6 +1,8 @@ include(Compiler/GNU) __compiler_gnu(CXX) +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) + if (WIN32) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6) set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fno-keep-inline-dllexport") diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake index 296e2fdb8..f3938a9a2 100644 --- a/Modules/Compiler/IAR.cmake +++ b/Modules/Compiler/IAR.cmake @@ -42,6 +42,7 @@ include_guard() macro(__compiler_iar_ilink lang) set(CMAKE_EXECUTABLE_SUFFIX ".elf") + set(CMAKE_${lang}_OUTPUT_EXTENSION ".o") if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX") set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>") diff --git a/Modules/Compiler/Intel-C.cmake b/Modules/Compiler/Intel-C.cmake index ec3bfd88f..322f63d0d 100644 --- a/Modules/Compiler/Intel-C.cmake +++ b/Modules/Compiler/Intel-C.cmake @@ -28,6 +28,8 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") else() + set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") diff --git a/Modules/Compiler/Intel-CXX.cmake b/Modules/Compiler/Intel-CXX.cmake index b71b946e9..42adfd10c 100644 --- a/Modules/Compiler/Intel-CXX.cmake +++ b/Modules/Compiler/Intel-CXX.cmake @@ -42,6 +42,8 @@ if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") else() + set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.0) set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++20") set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++20") diff --git a/Modules/Compiler/Intel-ISPC.cmake b/Modules/Compiler/Intel-ISPC.cmake new file mode 100644 index 000000000..2e9792a23 --- /dev/null +++ b/Modules/Compiler/Intel-ISPC.cmake @@ -0,0 +1,22 @@ +include(Compiler/CMakeCommonCompilerMacros) + +# Not aware of any verbose flag for ISPC +#set(CMAKE_ISPC_VERBOSE_FLAG ) + +set(CMAKE_DEPFILE_FLAGS_ISPC "-M -MT <OBJECT> -MF <DEPFILE>") + +string(APPEND CMAKE_ISPC_FLAGS_INIT " ") +string(APPEND CMAKE_ISPC_FLAGS_DEBUG_INIT "-O0 -g") +string(APPEND CMAKE_ISPC_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") +string(APPEND CMAKE_ISPC_FLAGS_MINSIZEREL_INIT " -O1 -DNDEBUG") +string(APPEND CMAKE_ISPC_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") + +set(CMAKE_ISPC_COMPILE_OPTIONS_PIE --pic) +set(CMAKE_ISPC_COMPILE_OPTIONS_PIC --pic) + +set(CMAKE_INCLUDE_SYSTEM_FLAG_ISPC -isystem=) + +set(CMAKE_ISPC_RESPONSE_FILE_FLAG "@") +set(CMAKE_ISPC_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_ISPC_USE_RESPONSE_FILE_FOR_LIBRARIES 1) +set(CMAKE_ISPC_USE_RESPONSE_FILE_FOR_OBJECTS 1) diff --git a/Modules/Compiler/IntelClang-DetermineCompiler.cmake b/Modules/Compiler/IntelClang-DetermineCompiler.cmake new file mode 100644 index 000000000..3544be344 --- /dev/null +++ b/Modules/Compiler/IntelClang-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__clang__) && defined(__INTEL_CLANG_COMPILER)") + +include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake") + +string(APPEND _compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__INTEL_CLANG_COMPILER)") diff --git a/Modules/Compiler/IntelDPCPP-DetermineCompiler.cmake b/Modules/Compiler/IntelDPCPP-DetermineCompiler.cmake new file mode 100644 index 000000000..7bbb21c3a --- /dev/null +++ b/Modules/Compiler/IntelDPCPP-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__clang__) && defined(__INTEL_DPCPP_COMPILER__)") + +include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake") + +string(APPEND _compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__INTEL_DPCPP_COMPILER__)") diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index 318729402..95a51f66b 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -6,6 +6,7 @@ set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v") set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cu") set(_CMAKE_CUDA_PTX_FLAG "-ptx") +set(_CMAKE_CUDA_DEVICE_CODE "-dc") if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) # The -forward-unknown-to-host-compiler flag was only @@ -63,7 +64,7 @@ set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "cudadevrt;cudart_static") set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "cudadevrt;cudart") set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_NONE "") -if(UNIX) +if(UNIX AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX")) list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") endif() @@ -77,13 +78,20 @@ if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "") if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0) - set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14") + if(CMAKE_CUDA_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.10.25017) + set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14") + else() + set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "") + set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "") + endif() endif() if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 11.0) - set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17") - set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") + if(CMAKE_CUDA_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.11.25505) + set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17") + set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") + endif() endif() else() diff --git a/Modules/Compiler/OpenWatcom.cmake b/Modules/Compiler/OpenWatcom.cmake index 9efbfc282..a9625137a 100644 --- a/Modules/Compiler/OpenWatcom.cmake +++ b/Modules/Compiler/OpenWatcom.cmake @@ -86,7 +86,7 @@ set(CMAKE_C_CREATE_STATIC_LIBRARY set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY}) -# old CMake internaly used OpenWatcom version macros +# old CMake internally used OpenWatcom version macros # for backward compatibility if(NOT _CMAKE_WATCOM_VERSION) set(_CMAKE_WATCOM_VERSION 1) diff --git a/Modules/Compiler/PGI-CXX.cmake b/Modules/Compiler/PGI-CXX.cmake index c77de3605..2d7a303c9 100644 --- a/Modules/Compiler/PGI-CXX.cmake +++ b/Modules/Compiler/PGI-CXX.cmake @@ -4,19 +4,19 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG") string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.10) - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -A) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION --gnu_extensions) set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.10) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION --c++11 -A) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION --c++11) set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION --c++11 --gnu_extensions) set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.7) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14 -A) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14) set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION --c++14 --gnu_extensions) set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.1) - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION --c++17 -A) + set(CMAKE_CXX17_STANDARD_COMPILE_OPTION --c++17) set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION --c++17 --gnu_extensions) set(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT ON) endif() diff --git a/Modules/Compiler/TI-ASM.cmake b/Modules/Compiler/TI-ASM.cmake index a566d70e1..01965d2e5 100644 --- a/Modules/Compiler/TI-ASM.cmake +++ b/Modules/Compiler/TI-ASM.cmake @@ -1,8 +1,4 @@ -set(CMAKE_LIBRARY_PATH_FLAG "--search_path=") -set(CMAKE_LINK_LIBRARY_FLAG "--library=") -set(CMAKE_INCLUDE_FLAG_ASM "--include_path=") - -set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --compile_only --asm_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") -set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_ASM_COMPILER> <OBJECTS> --run_linker --output_file=<TARGET> <CMAKE_ASM_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>") +include(Compiler/TI) +__compiler_ti(ASM) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm;s;abs) diff --git a/Modules/Compiler/TI-C.cmake b/Modules/Compiler/TI-C.cmake index b060ee9bb..3c97afb3d 100644 --- a/Modules/Compiler/TI-C.cmake +++ b/Modules/Compiler/TI-C.cmake @@ -1,22 +1,67 @@ -set(CMAKE_LIBRARY_PATH_FLAG "--search_path=") -set(CMAKE_LINK_LIBRARY_FLAG "--library=") -set(CMAKE_INCLUDE_FLAG_C "--include_path=") +include(Compiler/TI) +__compiler_ti(C) -set(CMAKE_C90_STANDARD_COMPILE_OPTION "--c89") -set(CMAKE_C90_EXTENSION_COMPILE_OPTION "--c89 --relaxed_ansi") +# Architecture specific +# C99 versions: https://processors.wiki.ti.com/index.php/C99_Support_in_TI_Compilers -set(CMAKE_C99_STANDARD_COMPILE_OPTION "--c99") -set(CMAKE_C99_EXTENSION_COMPILE_OPTION "--c99 --relaxed_ansi") +if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + set(__COMPILER_TI_C99_VERSION_ARM 5.2) + set(__COMPILER_TI_C11_VERSION_ARM 18.12) -set(CMAKE_DEPFILE_FLAGS_C "--preproc_with_compile --preproc_dependency=<DEPFILE>") +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430") + set(__COMPILER_TI_C99_VERSION_MSP430 4.3) + set(__COMPILER_TI_C11_VERSION_MSP430 18.12) -set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> --compile_only --skip_assembler --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>") -set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> --preproc_only --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>") +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C28x") + set(__COMPILER_TI_C99_VERSION_TMS320C28x 6.3) + set(__COMPILER_TI_C11_VERSION_TMS320C28x 18.9) -set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> --compile_only --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") -set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>") -set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>") -set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET_NAME>.map <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") -set(CMAKE_ASM_RESPONSE_FILE_FLAG "--cmd_file=") -set(CMAKE_C_RESPONSE_FILE_FLAG "--cmd_file=") -set(CMAKE_C_RESPONSE_FILE_LINK_FLAG " ") +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C6x") + set(__COMPILER_TI_C99_VERSION_TMS320C6x 7.5) + +else() + # architecture not handled + return() + +endif() + + +if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "${__COMPILER_TI_C99_VERSION_${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}}") + + set(CMAKE_C90_STANDARD_COMPILE_OPTION "--c89" "--strict_ansi") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "--c89" "--relaxed_ansi") + + set(CMAKE_C99_STANDARD_COMPILE_OPTION "--c99" "--strict_ansi") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "--c99" "--relaxed_ansi") + + if(DEFINED __COMPILER_TI_C11_VERSION_${CMAKE_CXX_COMPILER_ARCHITECTURE_ID} AND + CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "${__COMPILER_TI_C11_VERSION_${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}}") + + set(CMAKE_C11_STANDARD_COMPILE_OPTION "--c11" "--strict_ansi") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "--c11" "--relaxed_ansi") + + endif() + +else() + + set(CMAKE_C90_STANDARD_COMPILE_OPTION "--strict_ansi") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "--relaxed_ansi") + +endif() + + +# Architecture specific + +if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + __compiler_check_default_language_standard(C 2.0 90) + +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430") + __compiler_check_default_language_standard(C 3.0 90) + +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C28x") + __compiler_check_default_language_standard(C 4.1 90) + +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C6x") + __compiler_check_default_language_standard(C 4.45 90) + +endif() diff --git a/Modules/Compiler/TI-CXX.cmake b/Modules/Compiler/TI-CXX.cmake index 783654373..4b6efcd7a 100644 --- a/Modules/Compiler/TI-CXX.cmake +++ b/Modules/Compiler/TI-CXX.cmake @@ -1,15 +1,71 @@ -set(CMAKE_LIBRARY_PATH_FLAG "--search_path=") -set(CMAKE_LINK_LIBRARY_FLAG "--library=") -set(CMAKE_INCLUDE_FLAG_CXX "--include_path=") +include(Compiler/TI) +__compiler_ti(CXX) -set(CMAKE_DEPFILE_FLAGS_CXX "--preproc_with_compile --preproc_dependency=<DEPFILE>") +# Architecture specific -set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> --compile_only --skip_assembler --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>") -set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> --preproc_only --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>") +if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + set(__COMPILER_TI_CXX03_VERSION 5.2) + set(__COMPILER_TI_CXX14_VERSION 18.1) -set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> --compile_only --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") -set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>") -set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>") -set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET_NAME>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") -set(CMAKE_CXX_RESPONSE_FILE_FLAG "--cmd_file=") -set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG " ") +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430") + set(__COMPILER_TI_CXX03_VERSION 4.4) + set(__COMPILER_TI_CXX14_VERSION 18.1) + +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C28x") + set(__COMPILER_TI_CXX03_VERSION 16.9) + +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C6x") + set(__COMPILER_TI_CXX03_VERSION 8.1) + set(__COMPILER_TI_CXX14_VERSION 8.3) + +else() + # architecture not handled + return() + +endif() + + +if(DEFINED __COMPILER_TI_CXX14_VERSION AND + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "${__COMPILER_TI_CXX14_VERSION}") + + # C++03 is not supported anymore + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "--strict_ansi") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "--relaxed_ansi") + + # C++11 was never supported + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "--strict_ansi") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "--relaxed_ansi") + + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "--c++14" "--strict_ansi") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "--c++14" "--relaxed_ansi") + + +elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "${__COMPILER_TI_CXX03_VERSION}") + + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "--c++03" "--strict_ansi") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "--c++03" "--relaxed_ansi") + +else() + + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "--strict_ansi") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "--relaxed_ansi") + +endif() + + +# Architecture specific +# CXX98 versions: https://processors.wiki.ti.com/index.php/C%2B%2B_Support_in_TI_Compilers + +if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + __compiler_check_default_language_standard(CXX 4.5 98 ${__COMPILER_TI_CXX14_VERSION} 14) + +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430") + __compiler_check_default_language_standard(CXX 3.0 98 ${__COMPILER_TI_CXX14_VERSION} 14) + +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C28x") + __compiler_check_default_language_standard(CXX 5.1 98) + +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "TMS320C6x") + __compiler_check_default_language_standard(CXX 6.1 98 ${__COMPILER_TI_CXX14_VERSION} 14) + +endif() diff --git a/Modules/Compiler/TI.cmake b/Modules/Compiler/TI.cmake new file mode 100644 index 000000000..f63168823 --- /dev/null +++ b/Modules/Compiler/TI.cmake @@ -0,0 +1,41 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# This module is shared by multiple languages; use include blocker. +if(__COMPILER_TI) + return() +endif() +set(__COMPILER_TI 1) + +include(Compiler/CMakeCommonCompilerMacros) + +set(__COMPILER_TI_SOURCE_FLAG_C "--c_file") +set(__COMPILER_TI_SOURCE_FLAG_CXX "--cpp_file") +set(__COMPILER_TI_SOURCE_FLAG_ASM "--asm_file") + +macro(__compiler_ti lang) + set(CMAKE_${lang}_RESPONSE_FILE_FLAG "--cmd_file=") + + set(CMAKE_INCLUDE_FLAG_${lang} "--include_path=") + set(CMAKE_DEPFILE_FLAGS_${lang} "--preproc_with_compile --preproc_dependency=<DEPFILE>") + + set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> --preproc_only ${__COMPILER_TI_SOURCE_FLAG_${lang}}=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>") + set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> --compile_only --skip_assembler ${__COMPILER_TI_SOURCE_FLAG_${lang}}=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>") + + set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> --compile_only ${__COMPILER_TI_SOURCE_FLAG_${lang}}=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") + + set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_FINISH "") + + # After the --run_linker flag a response file is not possible + set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "") + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 0) + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 0) + + set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> <FLAGS> --run_linker --output_file=<TARGET> --map_file=<TARGET_NAME>.map <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") +endmacro() + +set(CMAKE_LIBRARY_PATH_FLAG "--search_path=") +set(CMAKE_LINK_LIBRARY_FLAG "--library=") diff --git a/Modules/Compiler/XL-C.cmake b/Modules/Compiler/XL-C.cmake index 2077bdabd..78c44d5d7 100644 --- a/Modules/Compiler/XL-C.cmake +++ b/Modules/Compiler/XL-C.cmake @@ -6,6 +6,8 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG") # -qthreaded = Ensures that all optimizations will be thread-safe string(APPEND CMAKE_C_FLAGS_INIT " -qthreaded") +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -qsourcetype=c) + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) set(CMAKE_C90_STANDARD_COMPILE_OPTION "-qlanglvl=stdc89") set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-qlanglvl=extc89") diff --git a/Modules/Compiler/XL-CXX.cmake b/Modules/Compiler/XL-CXX.cmake index 41e3e1119..3b911f3d6 100644 --- a/Modules/Compiler/XL-CXX.cmake +++ b/Modules/Compiler/XL-CXX.cmake @@ -6,6 +6,8 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG") # -qthreaded = Ensures that all optimizations will be thread-safe string(APPEND CMAKE_CXX_FLAGS_INIT " -qthreaded") +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -+) + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) if(CMAKE_SYSTEM MATCHES "Linux") set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") @@ -32,6 +34,3 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1) endif () __compiler_check_default_language_standard(CXX 10.1 98) - -set(CMAKE_CXX_COMPILE_OBJECT - "<CMAKE_CXX_COMPILER> -+ <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") diff --git a/Modules/Compiler/XLClang-C.cmake b/Modules/Compiler/XLClang-C.cmake index 54c18a668..1668a4d0f 100644 --- a/Modules/Compiler/XLClang-C.cmake +++ b/Modules/Compiler/XLClang-C.cmake @@ -1,6 +1,8 @@ include(Compiler/XLClang) __compiler_xlclang(C) +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89") set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu89") diff --git a/Modules/Compiler/XLClang-CXX.cmake b/Modules/Compiler/XLClang-CXX.cmake index 9ea3d7cac..02638c791 100644 --- a/Modules/Compiler/XLClang-CXX.cmake +++ b/Modules/Compiler/XLClang-CXX.cmake @@ -1,6 +1,8 @@ include(Compiler/XLClang) __compiler_xlclang(CXX) +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1) set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in index b48a3323f..3598fc7e2 100644 --- a/Modules/CompilerId/VS-10.vcxproj.in +++ b/Modules/CompilerId/VS-10.vcxproj.in @@ -9,7 +9,7 @@ <PropertyGroup Label="Globals"> <ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid> <RootNamespace>CompilerId@id_lang@</RootNamespace> - <Keyword>Win32Proj</Keyword> + <Keyword>@id_keyword@</Keyword> @id_system@ @id_system_version@ @id_WindowsTargetPlatformVersion@ @@ -24,7 +24,7 @@ @id_PreferredToolArchitecture@ </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> + <ConfigurationType>@id_config_type@</ConfigurationType> @id_toolset@ <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> diff --git a/Modules/CompilerId/Xcode-3.pbxproj.in b/Modules/CompilerId/Xcode-3.pbxproj.in index 6fe17e541..aab357a1e 100644 --- a/Modules/CompilerId/Xcode-3.pbxproj.in +++ b/Modules/CompilerId/Xcode-3.pbxproj.in @@ -80,11 +80,11 @@ 1DEB928A08733DD80010E9CD = { isa = XCBuildConfiguration; buildSettings = { - ONLY_ACTIVE_ARCH = YES; CODE_SIGNING_REQUIRED = NO; CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)"; SYMROOT = .; @id_archs@ + @id_arch_active@ @id_toolset@ @id_lang_version@ @id_clang_cxx_library@ diff --git a/Modules/DartConfiguration.tcl.in b/Modules/DartConfiguration.tcl.in index 086ba0743..90a56e287 100644 --- a/Modules/DartConfiguration.tcl.in +++ b/Modules/DartConfiguration.tcl.in @@ -71,6 +71,8 @@ ValgrindCommand: @VALGRIND_COMMAND@ ValgrindCommandOptions: @VALGRIND_COMMAND_OPTIONS@ DrMemoryCommand: @DRMEMORY_COMMAND@ DrMemoryCommandOptions: @DRMEMORY_COMMAND_OPTIONS@ +CudaSanitizerCommand: @CUDA_SANITIZER_COMMAND@ +CudaSanitizerCommandOptions: @CUDA_SANITIZER_COMMAND_OPTIONS@ MemoryCheckType: @MEMORYCHECK_TYPE@ MemoryCheckSanitizerOptions: @MEMORYCHECK_SANITIZER_OPTIONS@ MemoryCheckCommand: @MEMORYCHECK_COMMAND@ diff --git a/Modules/ExternalData.cmake b/Modules/ExternalData.cmake index e5dbcd963..6fe8685ca 100644 --- a/Modules/ExternalData.cmake +++ b/Modules/ExternalData.cmake @@ -179,7 +179,7 @@ calling any of the functions provided by this module. .. variable:: ExternalData_URL_TEMPLATES - The ``ExternalData_URL_TEMPLATES`` may be set to provide a list of + The ``ExternalData_URL_TEMPLATES`` may be set to provide a list of URL templates using the placeholders ``%(algo)`` and ``%(hash)`` in each template. Data fetch rules try each URL template in order by substituting the hash algorithm name for ``%(algo)`` and the hash diff --git a/Modules/ExternalProject-download.cmake.in b/Modules/ExternalProject-download.cmake.in index 99fb91781..ff8c65908 100644 --- a/Modules/ExternalProject-download.cmake.in +++ b/Modules/ExternalProject-download.cmake.in @@ -105,54 +105,65 @@ set(retry_number 5) message(STATUS "Downloading... dst='@LOCAL@' - timeout='@TIMEOUT_MSG@'" + timeout='@TIMEOUT_MSG@' + inactivity timeout='@INACTIVITY_TIMEOUT_MSG@'" ) - +set(download_retry_codes 7 6 8 15) +set(skip_url_list) +set(status_code) foreach(i RANGE ${retry_number}) - sleep_before_download(${i}) - + if(status_code IN_LIST download_retry_codes) + sleep_before_download(${i}) + endif() foreach(url @REMOTE@) - message(STATUS "Using src='${url}'") + if(NOT url IN_LIST skip_url_list) + message(STATUS "Using src='${url}'") - @TLS_VERIFY_CODE@ - @TLS_CAINFO_CODE@ - @NETRC_CODE@ - @NETRC_FILE_CODE@ + @TLS_VERIFY_CODE@ + @TLS_CAINFO_CODE@ + @NETRC_CODE@ + @NETRC_FILE_CODE@ - file( + file( DOWNLOAD "${url}" "@LOCAL@" @SHOW_PROGRESS@ @TIMEOUT_ARGS@ + @INACTIVITY_TIMEOUT_ARGS@ STATUS status LOG log @USERPWD_ARGS@ @HTTP_HEADERS_ARGS@ - ) - - list(GET status 0 status_code) - list(GET status 1 status_string) - - if(status_code EQUAL 0) - check_file_hash(has_hash hash_is_good) - if(has_hash AND NOT hash_is_good) - message(STATUS "Hash mismatch, removing...") - file(REMOVE "@LOCAL@") + ) + + list(GET status 0 status_code) + list(GET status 1 status_string) + + if(status_code EQUAL 0) + check_file_hash(has_hash hash_is_good) + if(has_hash AND NOT hash_is_good) + message(STATUS "Hash mismatch, removing...") + file(REMOVE "@LOCAL@") + else() + message(STATUS "Downloading... done") + return() + endif() else() - message(STATUS "Downloading... done") - return() + string(APPEND logFailedURLs "error: downloading '${url}' failed + status_code: ${status_code} + status_string: ${status_string} + log: + --- LOG BEGIN --- + ${log} + --- LOG END --- + " + ) + if(NOT status_code IN_LIST download_retry_codes) + list(APPEND skip_url_list "${url}") + break() endif() - else() - string(APPEND logFailedURLs "error: downloading '${url}' failed - status_code: ${status_code} - status_string: ${status_string} - log: - --- LOG BEGIN --- - ${log} - --- LOG END --- - " - ) endif() + endif() endforeach() endforeach() diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index fcff5ddf8..8bbaf5a38 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -179,6 +179,9 @@ External Project Definition ``TIMEOUT <seconds>`` Maximum time allowed for file download operations. + ``INACTIVITY_TIMEOUT <seconds>`` + Terminate the operation after a period of inactivity. + ``HTTP_USERNAME <username>`` Username for the download operation if authentication is required. @@ -395,6 +398,9 @@ External Project Definition project also provides a cache variable or some other convenient method for setting the directory property). + This may cause a step target to be created automatically for the + ``download`` step. See policy :policy:`CMP0114`. + ``PATCH_COMMAND <cmd>...`` Specifies a custom command to patch the sources after an update. By default, no patch command is defined. Note that it can be quite difficult @@ -575,6 +581,8 @@ External Project Definition If enabled, the main build's default ALL target will not depend on the test step. This can be a useful way of ensuring the test step is defined but only gets invoked when manually requested. + This may cause a step target to be created automatically for either + the ``install`` or ``build`` step. See policy :policy:`CMP0114`. **Output Logging Options:** Each of the following ``LOG_...`` options can be used to wrap the relevant @@ -661,19 +669,21 @@ External Project Definition steps need to be triggered manually or if they need to be used as dependencies of other targets. If this option is not specified, the default value is taken from the ``EP_STEP_TARGETS`` directory property. - See :command:`ExternalProject_Add_Step` below for further discussion of - the effects of this option. + See :command:`ExternalProject_Add_StepTargets` below for further + discussion of the effects of this option. ``INDEPENDENT_STEP_TARGETS <step-target>...`` - Generate custom targets for the specified steps and prevent these targets + Deprecated. This is allowed only if policy :policy:`CMP0114` is not set + to ``NEW``. + Generates custom targets for the specified steps and prevent these targets from having the usual dependencies applied to them. If this option is not specified, the default value is taken from the ``EP_INDEPENDENT_STEP_TARGETS`` directory property. This option is mostly useful for allowing individual steps to be driven independently, such as for a CDash setup where each step should be initiated and reported individually rather than as one whole build. See - :command:`ExternalProject_Add_Step` below for further discussion of the - effects of this option. + :command:`ExternalProject_Add_StepTargets` below for further discussion + of the effects of this option. **Miscellaneous Options:** ``LIST_SEPARATOR <sep>`` @@ -769,6 +779,21 @@ control needed to implement such step-level capabilities. ``DEPENDS <file>...`` Files on which this custom step depends. + ``INDEPENDENT <bool>`` + Specifies whether this step is independent of the external dependencies + specified by the :command:`ExternalProject_Add`'s ``DEPENDS`` option. + The default is ``FALSE``. Steps marked as independent may depend only + on other steps marked independent. See policy :policy:`CMP0114`. + + Note that this use of the term "independent" refers only to independence + from external targets specified by the ``DEPENDS`` option and is + orthogonal to a step's dependencies on other steps. + + If a step target is created for an independent step by the + :command:`ExternalProject_Add` ``STEP_TARGETS`` option or by the + :command:`ExternalProject_Add_StepTargets` function, it will not depend + on the external targets, but may depend on targets for other steps. + ``BYPRODUCTS <file>...`` Files that will be generated by this custom step but which might or might not have their modification time updated by subsequent builds. This list of @@ -782,6 +807,8 @@ control needed to implement such step-level capabilities. ``EXCLUDE_FROM_MAIN <bool>`` When enabled, this option specifies that the external project's main target does not depend on the custom step. + This may cause step targets to be created automatically for the steps on + which this step depends. See policy :policy:`CMP0114`. ``WORKING_DIRECTORY <dir>`` Specifies the working directory to set before running the custom step's @@ -812,7 +839,7 @@ control needed to implement such step-level capabilities. .. code-block:: cmake - ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] <step1> [<step2>...]) + ExternalProject_Add_StepTargets(<name> <step1> [<step2>...]) Creating a target for a step allows it to be used as a dependency of another target or to be triggered manually. Having targets for specific steps also @@ -824,37 +851,53 @@ control needed to implement such step-level capabilities. through the step dependency chain, then all the previous steps will also run to ensure everything is up to date. - If the ``NO_DEPENDS`` option is specified, the step target will not depend on - the dependencies of the external project (i.e. on any dependencies of the - ``<name>`` custom target created by :command:`ExternalProject_Add`). This is - usually safe for the ``download``, ``update`` and ``patch`` steps, since they - do not typically require that the dependencies are updated and built. Using - ``NO_DEPENDS`` for any of the other pre-defined steps, however, may break - parallel builds. Only use ``NO_DEPENDS`` where it is certain that the named - steps genuinely do not have dependencies. For custom steps, consider whether - or not the custom commands require the dependencies to be configured, built - and installed. - Internally, :command:`ExternalProject_Add` calls :command:`ExternalProject_Add_Step` to create each step. If any - ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` were specified, then - ``ExternalProject_Add_StepTargets()`` will also be called after - :command:`ExternalProject_Add_Step`. ``INDEPENDENT_STEP_TARGETS`` have the - ``NO_DEPENDS`` option set, whereas ``STEP_TARGETS`` do not. Other than that, - the two options result in ``ExternalProject_Add_StepTargets()`` being called - in the same way. Even if a step is not mentioned in either of those two - options, ``ExternalProject_Add_StepTargets()`` can still be called later to - manually define a target for the step. - - The ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` options for - :command:`ExternalProject_Add` are generally the easiest way to ensure - targets are created for specific steps of interest. For custom steps, - ``ExternalProject_Add_StepTargets()`` must be called explicitly if a target - should also be created for that custom step. An alternative to these two - options is to populate the ``EP_STEP_TARGETS`` and - ``EP_INDEPENDENT_STEP_TARGETS`` directory properties. These act as defaults - for the step target options and can save having to repeatedly specify the - same set of step targets when multiple external projects are being defined. + ``STEP_TARGETS`` were specified, then ``ExternalProject_Add_StepTargets()`` + will also be called after :command:`ExternalProject_Add_Step`. Even if a + step is not mentioned in the ``STEP_TARGETS`` option, + ``ExternalProject_Add_StepTargets()`` can still be called later to manually + define a target for the step. + + The ``STEP_TARGETS`` option for :command:`ExternalProject_Add` is generally + the easiest way to ensure targets are created for specific steps of interest. + For custom steps, ``ExternalProject_Add_StepTargets()`` must be called + explicitly if a target should also be created for that custom step. + An alternative to these two options is to populate the ``EP_STEP_TARGETS`` + directory property. It acts as a default for the step target options and + can save having to repeatedly specify the same set of step targets when + multiple external projects are being defined. + + If :policy:`CMP0114` is set to ``NEW``, step targets are fully responsible + for holding the custom commands implementing their steps. The primary target + created by ``ExternalProject_Add`` depends on the step targets, and the + step targets depend on each other. The target-level dependencies match + the file-level dependencies used by the custom commands for each step. + The targets for steps created with :command:`ExternalProject_Add_Step`'s + ``INDEPENDENT`` option do not depend on the external targets specified + by :command:`ExternalProject_Add`'s ``DEPENDS`` option. The predefined + steps ``mkdir``, ``download``, ``update``, and ``patch`` are independent. + + If :policy:`CMP0114` is not ``NEW``, the following deprecated behavior + is available: + + * A deprecated ``NO_DEPENDS`` option may be specified immediately after the + ``<name>`` and before the first step. + If the ``NO_DEPENDS`` option is specified, the step target will not depend on + the dependencies of the external project (i.e. on any dependencies of the + ``<name>`` custom target created by :command:`ExternalProject_Add`). This is + usually safe for the ``download``, ``update`` and ``patch`` steps, since they + do not typically require that the dependencies are updated and built. Using + ``NO_DEPENDS`` for any of the other pre-defined steps, however, may break + parallel builds. Only use ``NO_DEPENDS`` where it is certain that the named + steps genuinely do not have dependencies. For custom steps, consider whether + or not the custom commands require the dependencies to be configured, built + and installed. + + * The ``INDEPENDENT_STEP_TARGETS`` option for :command:`ExternalProject_Add`, + or the ``EP_INDEPENDENT_STEP_TARGETS`` directory property, tells the + function to call ``ExternalProject_Add_StepTargets()`` internally + using the ``NO_DEPENDS`` option for the specified steps. .. command:: ExternalProject_Add_StepDependencies @@ -1300,7 +1343,7 @@ function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_r ) endfunction() -function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file) +function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout inactivity_timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file) if(timeout) set(TIMEOUT_ARGS TIMEOUT ${timeout}) set(TIMEOUT_MSG "${timeout} seconds") @@ -1308,6 +1351,14 @@ function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_p set(TIMEOUT_ARGS "# no TIMEOUT") set(TIMEOUT_MSG "none") endif() + if(inactivity_timeout) + set(INACTIVITY_TIMEOUT_ARGS INACTIVITY_TIMEOUT ${inactivity_timeout}) + set(INACTIVITY_TIMEOUT_MSG "${inactivity_timeout} seconds") + else() + set(INACTIVITY_TIMEOUT_ARGS "# no INACTIVITY_TIMEOUT") + set(INACTIVITY_TIMEOUT_MSG "none") + endif() + if(no_progress) set(SHOW_PROGRESS "") @@ -1979,41 +2030,138 @@ function(_ep_get_complete_stampfile name stampfile_var) endfunction() +function(_ep_step_add_target name step no_deps) + if(TARGET ${name}-${step}) + return() + endif() + get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114) + _ep_get_step_stampfile(${name} ${step} stamp_file) + cmake_policy(PUSH) + if(cmp0114 STREQUAL "NEW") + # To implement CMP0114 NEW behavior with Makefile generators, + # we need CMP0113 NEW behavior. + cmake_policy(SET CMP0113 NEW) + endif() + add_custom_target(${name}-${step} + DEPENDS ${stamp_file}) + cmake_policy(POP) + set_property(TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP 1) + set_property(TARGET ${name}-${step} PROPERTY LABELS ${name}) + set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}") + + if(cmp0114 STREQUAL "NEW") + # Add target-level dependencies for the step. + get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN) + if(NOT exclude_from_main) + add_dependencies(${name} ${name}-${step}) + endif() + _ep_step_add_target_dependencies(${name} ${step} ${step}) + _ep_step_add_target_dependents(${name} ${step} ${step}) + + get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT) + else() + if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$") + message(AUTHOR_WARNING "Using NO_DEPENDS for \"${step}\" step might break parallel builds") + endif() + set(independent ${no_deps}) + endif() + + # Depend on other external projects (target-level). + if(NOT independent) + get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS) + foreach(arg IN LISTS deps) + add_dependencies(${name}-${step} ${arg}) + endforeach() + endif() +endfunction() + + +function(_ep_step_add_target_dependencies name step node) + get_property(dependees TARGET ${name} PROPERTY _EP_${node}_INTERNAL_DEPENDEES) + list(REMOVE_DUPLICATES dependees) + foreach(dependee IN LISTS dependees) + get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN) + get_property(dependee_dependers TARGET ${name} PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS) + if(exclude_from_main OR dependee_dependers MATCHES ";") + # The step on which our step target depends itself has + # dependents in multiple targes. It needs a step target too + # so that there is a unique place for its custom command. + _ep_step_add_target("${name}" "${dependee}" "FALSE") + endif() + + if(TARGET ${name}-${dependee}) + add_dependencies(${name}-${step} ${name}-${dependee}) + else() + _ep_step_add_target_dependencies(${name} ${step} ${dependee}) + endif() + endforeach() +endfunction() + + +function(_ep_step_add_target_dependents name step node) + get_property(dependers TARGET ${name} PROPERTY _EP_${node}_INTERNAL_DEPENDERS) + list(REMOVE_DUPLICATES dependers) + foreach(depender IN LISTS dependers) + if(TARGET ${name}-${depender}) + add_dependencies(${name}-${depender} ${name}-${step}) + else() + _ep_step_add_target_dependents(${name} ${step} ${depender}) + endif() + endforeach() +endfunction() + + function(ExternalProject_Add_StepTargets name) + get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114) set(steps ${ARGN}) if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS") set(no_deps 1) list(REMOVE_AT steps 0) + else() + set(no_deps 0) endif() - foreach(step ${steps}) - if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$") - message(AUTHOR_WARNING "Using NO_DEPENDS for \"${step}\" step might break parallel builds") + if(cmp0114 STREQUAL "NEW") + if(no_deps) + message(FATAL_ERROR + "The 'NO_DEPENDS' option is no longer allowed. " + "It has been superseded by the per-step 'INDEPENDENT' option. " + "See policy CMP0114." + ) endif() - _ep_get_step_stampfile(${name} ${step} stamp_file) - add_custom_target(${name}-${step} - DEPENDS ${stamp_file}) - set_property(TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP 1) - set_property(TARGET ${name}-${step} PROPERTY LABELS ${name}) - set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}") - - # Depend on other external projects (target-level). - if(NOT no_deps) - get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS) - foreach(arg IN LISTS deps) - add_dependencies(${name}-${step} ${arg}) - endforeach() + elseif(cmp0114 STREQUAL "") + cmake_policy(GET_WARNING CMP0114 _cmp0114_warning) + string(APPEND _cmp0114_warning "\n" + "ExternalProject target '${name}' would depend on the targets for " + "step(s) '${steps}' under policy CMP0114, but this is being left out " + "for compatibility since the policy is not set." + ) + if(no_deps) + string(APPEND _cmp0114_warning + " Also, the NO_DEPENDS option is deprecated in favor of policy CMP0114." + ) endif() + message(AUTHOR_WARNING "${_cmp0114_warning}") + endif() + foreach(step ${steps}) + _ep_step_add_target("${name}" "${step}" "${no_deps}") endforeach() endfunction() function(ExternalProject_Add_Step name step) + get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114) _ep_get_complete_stampfile(${name} complete_stamp_file) _ep_get_step_stampfile(${name} ${step} stamp_file) _ep_parse_arguments(ExternalProject_Add_Step ${name} _EP_${step}_ "${ARGN}") + get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT) + if(independent STREQUAL "") + set(independent FALSE) + set_property(TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT "${independent}") + endif() + get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN) if(NOT exclude_from_main) add_custom_command(APPEND @@ -2024,12 +2172,21 @@ function(ExternalProject_Add_Step name step) # Steps depending on this step. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS) + set_property(TARGET ${name} APPEND PROPERTY _EP_${step}_INTERNAL_DEPENDERS ${dependers}) foreach(depender IN LISTS dependers) + set_property(TARGET ${name} APPEND PROPERTY _EP_${depender}_INTERNAL_DEPENDEES ${step}) _ep_get_step_stampfile(${name} ${depender} depender_stamp_file) add_custom_command(APPEND OUTPUT ${depender_stamp_file} DEPENDS ${stamp_file} ) + if(cmp0114 STREQUAL "NEW" AND NOT independent) + get_property(dep_independent TARGET ${name} PROPERTY _EP_${depender}_INDEPENDENT) + if(dep_independent) + message(FATAL_ERROR "ExternalProject '${name}' step '${depender}' is marked INDEPENDENT " + "but depends on step '${step}' that is not marked INDEPENDENT.") + endif() + endif() endforeach() # Dependencies on files. @@ -2040,9 +2197,18 @@ function(ExternalProject_Add_Step name step) # Dependencies on steps. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES) + set_property(TARGET ${name} APPEND PROPERTY _EP_${step}_INTERNAL_DEPENDEES ${dependees}) foreach(dependee IN LISTS dependees) + set_property(TARGET ${name} APPEND PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS ${step}) _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file) list(APPEND depends ${dependee_stamp_file}) + if(cmp0114 STREQUAL "NEW" AND independent) + get_property(dep_independent TARGET ${name} PROPERTY _EP_${dependee}_INDEPENDENT) + if(NOT dep_independent) + message(FATAL_ERROR "ExternalProject '${name}' step '${step}' is marked INDEPENDENT " + "but depends on step '${dependee}' that is not marked INDEPENDENT.") + endif() + endif() endforeach() # The command to run. @@ -2137,7 +2303,7 @@ function(ExternalProject_Add_Step name step) endif() foreach(st ${step_targets}) if("${st}" STREQUAL "${step}") - ExternalProject_Add_StepTargets(${name} ${step}) + _ep_step_add_target("${name}" "${step}" "FALSE") break() endif() endforeach() @@ -2146,12 +2312,37 @@ function(ExternalProject_Add_Step name step) if(NOT independent_step_targets) get_property(independent_step_targets DIRECTORY PROPERTY EP_INDEPENDENT_STEP_TARGETS) endif() - foreach(st ${independent_step_targets}) - if("${st}" STREQUAL "${step}") - ExternalProject_Add_StepTargets(${name} NO_DEPENDS ${step}) - break() + if(cmp0114 STREQUAL "NEW") + if(independent_step_targets) + message(FATAL_ERROR + "ExternalProject '${name}' option 'INDEPENDENT_STEP_TARGETS' is set to\n" + " ${independent_step_targets}\n" + "but the option is no longer allowed. " + "It has been superseded by the per-step 'INDEPENDENT' option. " + "See policy CMP0114." + ) endif() - endforeach() + else() + if(independent_step_targets AND cmp0114 STREQUAL "") + get_property(warned TARGET ${name} PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS) + if(NOT warned) + set_property(TARGET ${name} PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS 1) + cmake_policy(GET_WARNING CMP0114 _cmp0114_warning) + string(APPEND _cmp0114_warning "\n" + "ExternalProject '${name}' option INDEPENDENT_STEP_TARGETS is set to\n" + " ${independent_step_targets}\n" + "but the option is deprecated in favor of policy CMP0114." + ) + message(AUTHOR_WARNING "${_cmp0114_warning}") + endif() + endif() + foreach(st ${independent_step_targets}) + if("${st}" STREQUAL "${step}") + _ep_step_add_target("${name}" "${step}" "TRUE") + break() + endif() + endforeach() + endif() endfunction() @@ -2214,6 +2405,7 @@ function(_ep_add_mkdir_command name) _ep_get_configuration_subdir_suffix(cfgdir) ExternalProject_Add_Step(${name} mkdir + INDEPENDENT TRUE COMMENT "Creating directories for '${name}'" COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir} COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir} @@ -2512,6 +2704,7 @@ function(_ep_add_download_command name) string(REPLACE ";" "-" fname "${fname}") set(file ${download_dir}/${fname}) get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT) + get_property(inactivity_timeout TARGET ${name} PROPERTY _EP_INACTIVITY_TIMEOUT) get_property(no_progress TARGET ${name} PROPERTY _EP_DOWNLOAD_NO_PROGRESS) get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY) get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO) @@ -2521,7 +2714,7 @@ function(_ep_add_download_command name) get_property(http_password TARGET ${name} PROPERTY _EP_HTTP_PASSWORD) get_property(http_headers TARGET ${name} PROPERTY _EP_HTTP_HEADER) set(download_script "${stamp_dir}/download-${name}.cmake") - _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}" "${netrc}" "${netrc_file}") + _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${inactivity_timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}" "${netrc}" "${netrc_file}") set(cmd ${CMAKE_COMMAND} -P "${download_script}" COMMAND) if (no_extract) @@ -2588,6 +2781,7 @@ function(_ep_add_download_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(\${name} download + INDEPENDENT TRUE COMMENT \${comment} COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${work_dir} @@ -2751,6 +2945,7 @@ Update to Mercurial >= 2.1.1. endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} update + INDEPENDENT TRUE COMMENT \${comment} COMMAND ${__cmdQuoted} ALWAYS \${always} @@ -2797,6 +2992,7 @@ function(_ep_add_patch_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} patch + INDEPENDENT TRUE COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${work_dir} DEPENDEES \${patch_dep} @@ -2961,6 +3157,7 @@ function(_ep_add_configure_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} configure + INDEPENDENT FALSE COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${binary_dir} DEPENDEES patch @@ -3012,6 +3209,7 @@ function(_ep_add_build_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} build + INDEPENDENT FALSE COMMAND ${__cmdQuoted} BYPRODUCTS \${build_byproducts} WORKING_DIRECTORY \${binary_dir} @@ -3055,6 +3253,7 @@ function(_ep_add_install_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} install + INDEPENDENT FALSE COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${binary_dir} DEPENDEES build @@ -3122,6 +3321,7 @@ function(_ep_add_test_command name) endforeach() cmake_language(EVAL CODE " ExternalProject_Add_Step(${name} test + INDEPENDENT FALSE COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${binary_dir} ${dependees_args} @@ -3139,6 +3339,21 @@ function(ExternalProject_Add name) cmake_policy(GET CMP0097 _EP_CMP0097 PARENT_SCOPE # undocumented, do not use outside of CMake ) + cmake_policy(GET CMP0114 cmp0114 + PARENT_SCOPE # undocumented, do not use outside of CMake + ) + if(CMAKE_XCODE_BUILD_SYSTEM VERSION_GREATER_EQUAL 12 AND NOT cmp0114 STREQUAL "NEW") + message(AUTHOR_WARNING + "Policy CMP0114 is not set to NEW. " + "In order to support the Xcode \"new build system\", " + "this project must be updated to set policy CMP0114 to NEW." + "\n" + "Since CMake is generating for the Xcode \"new build system\", " + "ExternalProject_Add will use policy CMP0114's NEW behavior anyway, " + "but the generated build system may not match what the project intends." + ) + set(cmp0114 "NEW") + endif() _ep_get_configuration_subdir_suffix(cfgdir) @@ -3146,14 +3361,23 @@ function(ExternalProject_Add name) set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles) _ep_get_complete_stampfile(${name} complete_stamp_file) + cmake_policy(PUSH) + if(cmp0114 STREQUAL "NEW") + # To implement CMP0114 NEW behavior with Makefile generators, + # we need CMP0113 NEW behavior. + cmake_policy(SET CMP0113 NEW) + endif() # The "ALL" option to add_custom_target just tells it to not set the # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL # argument was passed, we explicitly set it for the target. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file}) + cmake_policy(POP) set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1) set_property(TARGET ${name} PROPERTY LABELS ${name}) set_property(TARGET ${name} PROPERTY FOLDER "ExternalProjectTargets/${name}") + set_property(TARGET ${name} PROPERTY _EP_CMP0114 "${cmp0114}") + _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}") _ep_set_directories(${name}) _ep_get_step_stampfile(${name} "done" done_stamp_file) diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index e05ca9692..40cc36214 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -5,6 +5,8 @@ FetchContent ------------------ +.. versionadded:: 3.11 + .. only:: html .. contents:: @@ -1036,6 +1038,11 @@ function(FetchContent_Populate contentName) message(FATAL_ERROR "Content ${contentName} already populated in ${${contentNameLower}_SOURCE_DIR}") endif() + __FetchContent_getSavedDetails(${contentName} contentDetails) + if("${contentDetails}" STREQUAL "") + message(FATAL_ERROR "No details have been set for content: ${contentName}") + endif() + string(TOUPPER ${contentName} contentNameUpper) set(FETCHCONTENT_SOURCE_DIR_${contentNameUpper} "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}" @@ -1043,14 +1050,41 @@ function(FetchContent_Populate contentName) if(FETCHCONTENT_SOURCE_DIR_${contentNameUpper}) # The source directory has been explicitly provided in the cache, - # so no population is required + # so no population is required. The build directory may still be specified + # by the declared details though. + + if(NOT EXISTS "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}") + message(FATAL_ERROR "Manually specified source directory is missing:\n" + " FETCHCONTENT_SOURCE_DIR_${contentNameUpper} --> ${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}") + endif() + set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}") - set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build") + + cmake_parse_arguments(savedDetails "" "BINARY_DIR" "" ${contentDetails}) + + if(savedDetails_BINARY_DIR) + set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR}) + else() + set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build") + endif() elseif(FETCHCONTENT_FULLY_DISCONNECTED) - # Bypass population and assume source is already there from a previous run - set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src") - set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build") + # Bypass population and assume source is already there from a previous run. + # Declared details may override the default source or build directories. + + cmake_parse_arguments(savedDetails "" "SOURCE_DIR;BINARY_DIR" "" ${contentDetails}) + + if(savedDetails_SOURCE_DIR) + set(${contentNameLower}_SOURCE_DIR ${savedDetails_SOURCE_DIR}) + else() + set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src") + endif() + + if(savedDetails_BINARY_DIR) + set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR}) + else() + set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build") + endif() else() # Support both a global "disconnect all updates" and a per-content @@ -1070,11 +1104,6 @@ function(FetchContent_Populate contentName) unset(quietFlag) endif() - __FetchContent_getSavedDetails(${contentName} contentDetails) - if("${contentDetails}" STREQUAL "") - message(FATAL_ERROR "No details have been set for content: ${contentName}") - endif() - set(__detailsQuoted) foreach(__item IN LISTS contentDetails) string(APPEND __detailsQuoted " [==[${__item}]==]") diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake index 243b9e077..c8a31a038 100644 --- a/Modules/FindArmadillo.cmake +++ b/Modules/FindArmadillo.cmake @@ -84,6 +84,7 @@ if(_ARMA_USE_WRAPPER) # Link to the armadillo wrapper library. find_library(ARMADILLO_LIBRARY NAMES armadillo + NAMES_PER_DIR PATHS "$ENV{ProgramFiles}/Armadillo/lib" "$ENV{ProgramFiles}/Armadillo/lib64" diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 60f178be7..e4353dfaf 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -27,6 +27,7 @@ The following variables may be set to influence this module's behavior: possibilities. List of vendors valid in this module: * ``Goto`` + * ``FlexiBLAS`` * ``OpenBLAS`` * ``FLAME`` * ``ATLAS PhiPACK`` @@ -36,7 +37,7 @@ The following variables may be set to influence this module's behavior: * ``SCSL`` * ``SGIMATH`` * ``IBMESSL`` - * ``Intel10_32`` (intel mkl v10 32 bit) + * ``Intel10_32`` (intel mkl v10 32 bit, threaded code) * ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model) * ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model) * ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model) @@ -208,6 +209,7 @@ macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _add if(_libraries_work) find_library(${_prefix}_${_library}_LIBRARY NAMES ${_library} + NAMES_PER_DIR PATHS ${_extaddlibdir} PATH_SUFFIXES ${_subdirs} ) @@ -397,6 +399,10 @@ if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") # Add threading/sequential libs set(BLAS_SEARCH_LIBS_WIN_THREAD "") + if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD + "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}") + endif() if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All") # old version list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD @@ -441,7 +447,7 @@ if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}") endif() - #older vesions of intel mkl libs + #older versions of intel mkl libs if(BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All") list(APPEND BLAS_SEARCH_LIBS "mkl") @@ -483,7 +489,9 @@ if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") endif() set(BLAS_mkl_LIB_PATH_SUFFIXES "compiler/lib" "compiler/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}" + "compiler/lib/${BLAS_mkl_ARCH_NAME}" "mkl/lib" "mkl/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}" + "mkl/lib/${BLAS_mkl_ARCH_NAME}" "lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}") foreach(IT ${BLAS_SEARCH_LIBS}) @@ -542,6 +550,22 @@ if(BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") endif() endif() +# FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/) +if(BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All") + if(NOT BLAS_LIBRARIES) + check_blas_libraries( + BLAS_LIBRARIES + BLAS + sgemm + "" + "flexiblas" + "" + "" + "" + ) + endif() +endif() + # OpenBLAS? (http://www.openblas.net) if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All") if(NOT BLAS_LIBRARIES) diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake index 98ab72cd8..5704d1d83 100644 --- a/Modules/FindBZip2.cmake +++ b/Modules/FindBZip2.cmake @@ -45,8 +45,8 @@ set(_BZIP2_PATHS PATHS find_path(BZIP2_INCLUDE_DIR bzlib.h ${_BZIP2_PATHS} PATH_SUFFIXES include) if (NOT BZIP2_LIBRARIES) - find_library(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 libbz2 libbzip2 ${_BZIP2_PATHS} PATH_SUFFIXES lib) - find_library(BZIP2_LIBRARY_DEBUG NAMES bz2d bzip2d libbz2d libbzip2d ${_BZIP2_PATHS} PATH_SUFFIXES lib) + find_library(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 libbz2 libbzip2 NAMES_PER_DIR ${_BZIP2_PATHS} PATH_SUFFIXES lib) + find_library(BZIP2_LIBRARY_DEBUG NAMES bz2d bzip2d libbz2d libbzip2d NAMES_PER_DIR ${_BZIP2_PATHS} PATH_SUFFIXES lib) include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) SELECT_LIBRARY_CONFIGURATIONS(BZIP2) diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 13981d3b8..00e4ff1d2 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -305,7 +305,7 @@ function(_boost_get_canonical_target_name component target_var) endfunction() macro(_boost_set_in_parent_scope name value) - # Set a variable in parent scope and make it visibile in current scope + # Set a variable in parent scope and make it visible in current scope set(${name} "${value}" PARENT_SCOPE) set(${name} "${value}") endmacro() @@ -442,10 +442,27 @@ if (NOT Boost_NO_BOOST_CMAKE) endif() endif() + set(_boost_FIND_PACKAGE_ARGS "") + if(Boost_NO_SYSTEM_PATHS) + list(APPEND _boost_FIND_PACKAGE_ARGS NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH) + endif() + # Do the same find_package call but look specifically for the CMake version. # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no # need to delegate them to this find_package call. - find_package(Boost QUIET NO_MODULE) + if(BOOST_ROOT AND NOT Boost_ROOT) + # Honor BOOST_ROOT by setting Boost_ROOT with CMP0074 NEW behavior. + cmake_policy(PUSH) + cmake_policy(SET CMP0074 NEW) + set(Boost_ROOT "${BOOST_ROOT}") + set(_Boost_ROOT_FOR_CONFIG 1) + endif() + find_package(Boost QUIET NO_MODULE ${_boost_FIND_PACKAGE_ARGS}) + if(_Boost_ROOT_FOR_CONFIG) + unset(_Boost_ROOT_FOR_CONFIG) + unset(Boost_ROOT) + cmake_policy(POP) + endif() if (DEFINED Boost_DIR) mark_as_advanced(Boost_DIR) endif () @@ -1183,7 +1200,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_TIMER_DEPENDENCIES chrono) set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.74.0) + if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.75.0) message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets") endif() endif() @@ -1270,10 +1287,8 @@ function(_Boost_COMPONENT_HEADERS component _hdrs) set(_Boost_UNIT_TEST_FRAMEWORK_HEADERS "boost/test/framework.hpp") set(_Boost_WAVE_HEADERS "boost/wave.hpp") set(_Boost_WSERIALIZATION_HEADERS "boost/archive/text_wiarchive.hpp") - if(WIN32) - set(_Boost_BZIP2_HEADERS "boost/iostreams/filter/bzip2.hpp") - set(_Boost_ZLIB_HEADERS "boost/iostreams/filter/zlib.hpp") - endif() + set(_Boost_BZIP2_HEADERS "boost/iostreams/filter/bzip2.hpp") + set(_Boost_ZLIB_HEADERS "boost/iostreams/filter/zlib.hpp") string(TOUPPER ${component} uppercomponent) set(${_hdrs} ${_Boost_${uppercomponent}_HEADERS} PARENT_SCOPE) @@ -1457,6 +1472,7 @@ else() # _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_DEPENDENCIES. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} + "1.74.0" "1.74" "1.73.0" "1.73" "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69" "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65" "1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60" diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index a93d4fd10..f04f57127 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -732,6 +732,8 @@ if(CMAKE_CROSSCOMPILING) # Support for aarch64 cross compilation if (ANDROID_ARCH_NAME STREQUAL "arm64") set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") + elseif (CMAKE_SYSTEM_NAME STREQUAL "QNX") + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-qnx") else() set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") endif (ANDROID_ARCH_NAME STREQUAL "arm64") @@ -902,7 +904,7 @@ if(CUDA_USE_STATIC_CUDA_RUNTIME) find_package(Threads REQUIRED) set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags}) - if(NOT APPLE) + if(NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX")) #On Linux, you must link against librt when using the static cuda runtime. find_library(CUDA_rt_LIBRARY rt) if (NOT CUDA_rt_LIBRARY) diff --git a/Modules/FindCUDA/run_nvcc.cmake b/Modules/FindCUDA/run_nvcc.cmake index ba3543306..17e12f8cf 100644 --- a/Modules/FindCUDA/run_nvcc.cmake +++ b/Modules/FindCUDA/run_nvcc.cmake @@ -155,7 +155,7 @@ macro(cuda_execute_process status command) # copy and paste a runnable command line. set(cuda_execute_process_string) foreach(arg ${ARGN}) - # If there are quotes, excape them, so they come through. + # If there are quotes, escape them, so they come through. string(REPLACE "\"" "\\\"" arg ${arg}) # Args with spaces need quotes around them to get them to be parsed as a single argument. if(arg MATCHES " ") diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index 47bc5466c..b3c8569bf 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -5,6 +5,8 @@ FindCUDAToolkit --------------- +.. versionadded:: 3.17 + This script locates the NVIDIA CUDA toolkit and the associated libraries, but does not require the ``CUDA`` language be enabled for a given project. This module does not search for the NVIDIA CUDA Samples. @@ -12,8 +14,7 @@ module does not search for the NVIDIA CUDA Samples. Search Behavior ^^^^^^^^^^^^^^^ -Finding the CUDA Toolkit requires finding the ``nvcc`` executable, which is -searched for in the following order: +The CUDA Toolkit search behavior uses the following order: 1. If the ``CUDA`` language has been enabled we will use the directory containing the compiler as the first search location for ``nvcc``. @@ -24,13 +25,12 @@ searched for in the following order: configuration variable are specified, the *configuration* variable takes precedence. - The directory specified here must be such that the executable ``nvcc`` can be - found underneath the directory specified by ``CUDAToolkit_ROOT``. If - ``CUDAToolkit_ROOT`` is specified, but no ``nvcc`` is found underneath, this - package is marked as **not** found. No subsequent search attempts are - performed. + The directory specified here must be such that the executable ``nvcc`` or + the appropriate ``version.txt`` file can be found underneath the specified + directory. -3. If the CUDA_PATH environment variable is defined, it will be searched. +3. If the CUDA_PATH environment variable is defined, it will be searched + for ``nvcc``. 4. The user's path is searched for ``nvcc`` using :command:`find_program`. If this is found, no subsequent search attempts are performed. Users are @@ -402,7 +402,7 @@ Result variables ``CUDAToolkit_VERSION`` The exact version of the CUDA Toolkit found (as reported by - ``nvcc --version``). + ``nvcc --version`` or ``version.txt``). ``CUDAToolkit_VERSION_MAJOR`` The major version of the CUDA Toolkit. @@ -431,8 +431,8 @@ Result variables ``CUDAToolkit_TARGET_DIR`` The path to the CUDA Toolkit directory including the target architecture - when cross-compiling. When not cross-compiling this will be equivalant to - ``CUDAToolkit_ROOT_DIR``. + when cross-compiling. When not cross-compiling this will be equivalent to + the parent directory of ``CUDAToolkit_BIN_DIR``. ``CUDAToolkit_NVCC_EXECUTABLE`` The path to the NVIDIA CUDA compiler ``nvcc``. Note that this path may @@ -491,31 +491,81 @@ if(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT) set(CUDAToolkit_BIN_DIR "${CUDAToolkit_ROOT_DIR}/bin") set(CUDAToolkit_NVCC_EXECUTABLE "${CUDAToolkit_BIN_DIR}/nvcc${CMAKE_EXECUTABLE_SUFFIX}") else() + + function(_CUDAToolkit_find_root_dir ) + cmake_parse_arguments(arg "" "" "SEARCH_PATHS;FIND_FLAGS" ${ARGN}) + + + if(NOT CUDAToolkit_BIN_DIR) + if(NOT CUDAToolkit_SENTINEL_FILE) + find_program(CUDAToolkit_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ${arg_SEARCH_PATHS} + ${arg_FIND_FLAGS} + ) + endif() + + if(NOT CUDAToolkit_NVCC_EXECUTABLE) + find_file(CUDAToolkit_SENTINEL_FILE + NAMES version.txt + PATHS ${arg_SEARCH_PATHS} + NO_DEFAULT_PATH + ) + endif() + + if(CUDAToolkit_NVCC_EXECUTABLE) + get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) + + set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) + mark_as_advanced(CUDAToolkit_BIN_DIR) + elseif(CUDAToolkit_SENTINEL_FILE) + get_filename_component(CUDAToolkit_BIN_DIR ${CUDAToolkit_SENTINEL_FILE} DIRECTORY ABSOLUTE) + set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}/bin") + + set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) + mark_as_advanced(CUDAToolkit_BIN_DIR) + endif() + endif() + + if(CUDAToolkit_BIN_DIR) + get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE) + set(CUDAToolkit_ROOT_DIR "${CUDAToolkit_ROOT_DIR}" PARENT_SCOPE) + endif() + + endfunction() + + function(_CUDAToolkit_find_version_file result_variable) + # We first check for a non-scattered installation to prefer it over a scattered installation. + if(CUDAToolkit_ROOT AND EXISTS "${CUDAToolkit_ROOT}/version.txt") + set(${result_variable} "${CUDAToolkit_ROOT}/version.txt" PARENT_SCOPE) + elseif(CUDAToolkit_ROOT_DIR AND EXISTS "${CUDAToolkit_ROOT_DIR}/version.txt") + set(${result_variable} "${CUDAToolkit_ROOT_DIR}/version.txt" PARENT_SCOPE) + elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt") + set(${result_variable} "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt" PARENT_SCOPE) + elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt") + set(${result_variable} "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt" PARENT_SCOPE) + endif() + endfunction() + # For NVCC we can easily deduce the SDK binary directory from the compiler path. if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_CUDA_COMPILER}" DIRECTORY) set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "") + # Try language provided path first. + _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_BIN_DIR}" FIND_FLAGS NO_DEFAULT_PATH) mark_as_advanced(CUDAToolkit_BIN_DIR) endif() - # Try language- or user-provided path first. - if(CUDAToolkit_BIN_DIR) - find_program(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${CUDAToolkit_BIN_DIR} - NO_DEFAULT_PATH - ) + # Try user provided path + if(NOT CUDAToolkit_ROOT_DIR AND CUDAToolkit_ROOT) + _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_ROOT}" FIND_FLAGS PATH_SUFFIXES bin NO_DEFAULT_PATH) + endif() + if(NOT CUDAToolkit_ROOT_DIR) + _CUDAToolkit_find_root_dir(FIND_FLAGS PATHS "ENV CUDA_PATH" PATH_SUFFIXES bin) endif() - # Search using CUDAToolkit_ROOT - find_program(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ENV CUDA_PATH - PATH_SUFFIXES bin - ) - - # If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error. - if(NOT CUDAToolkit_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) + # If the user specified CUDAToolkit_ROOT but the toolkit could not be found, this is an error. + if(NOT CUDAToolkit_ROOT_DIR AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) # Declare error messages now, print later depending on find_package args. set(fail_base "Could not find nvcc executable in path specified by") set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}") @@ -552,7 +602,7 @@ else() # We will also search the default symlink location /usr/local/cuda first since # if CUDAToolkit_ROOT is not specified, it is assumed that the symlinked # directory is the desired location. - if(NOT CUDAToolkit_NVCC_EXECUTABLE) + if(NOT CUDAToolkit_ROOT_DIR) if(UNIX) if(NOT APPLE) set(platform_base "/usr/local/cuda-") @@ -589,12 +639,8 @@ else() list(INSERT search_paths 0 "/usr/local/cuda") endif() - # Now search for nvcc again using the platform default search paths. - find_program(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${search_paths} - PATH_SUFFIXES bin - ) + # Now search for the toolkit again using the platform default search paths. + _CUDAToolkit_find_root_dir(SEARCH_PATHS "${search_paths}" FIND_FLAGS PATH_SUFFIXES bin) # We are done with these variables now, cleanup for caller. unset(platform_base) @@ -602,7 +648,7 @@ else() unset(versions) unset(search_paths) - if(NOT CUDAToolkit_NVCC_EXECUTABLE) + if(NOT CUDAToolkit_ROOT_DIR) if(CUDAToolkit_FIND_REQUIRED) message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.") elseif(NOT CUDAToolkit_FIND_QUIETLY) @@ -614,38 +660,26 @@ else() endif() endif() - if(NOT CUDAToolkit_BIN_DIR AND CUDAToolkit_NVCC_EXECUTABLE) - get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) - set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) - mark_as_advanced(CUDAToolkit_BIN_DIR) - endif() - - get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE) - - # CUDAToolkit_LIBRARY_ROOT contains the device library and version file. - # In a non-scattered installation this is equivalent to CUDAToolkit_ROOT_DIR. - # We first check for a non-scattered installation to prefer it over a scattered installation. - if(EXISTS "${CUDAToolkit_ROOT_DIR}/version.txt") - set(CUDAToolkit_LIBRARY_ROOT "${CUDAToolkit_ROOT_DIR}") - elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt") - set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_SYSROOT_LINK}/usr/lib/cuda") - elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt") - set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/cuda") + _CUDAToolkit_find_version_file( _CUDAToolkit_version_file ) + if(_CUDAToolkit_version_file) + # CUDAToolkit_LIBRARY_ROOT contains the device library and version file. + get_filename_component(CUDAToolkit_LIBRARY_ROOT "${_CUDAToolkit_version_file}" DIRECTORY ABSOLUTE) endif() + unset(_CUDAToolkit_version_file) endif() -# Handle cross compilation +# Find target directory when crosscompiling. if(CMAKE_CROSSCOMPILING) if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") # Support for NVPACK set(CUDAToolkit_TARGET_NAME "armv7-linux-androideabi") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") - # Support for arm cross compilation set(CUDAToolkit_TARGET_NAME "armv7-linux-gnueabihf") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") - # Support for aarch64 cross compilation if(ANDROID_ARCH_NAME STREQUAL "arm64") set(CUDAToolkit_TARGET_NAME "aarch64-linux-androideabi") + elseif (CMAKE_SYSTEM_NAME STREQUAL "QNX") + set(CUDAToolkit_TARGET_NAME "aarch64-qnx") else() set(CUDAToolkit_TARGET_NAME "aarch64-linux") endif(ANDROID_ARCH_NAME STREQUAL "arm64") @@ -664,7 +698,10 @@ if(CMAKE_CROSSCOMPILING) # PATh set(_CUDAToolkit_Pop_ROOT_PATH True) endif() -else() +endif() + +# If not already set we can simply use the toolkit root or it's a scattered installation. +if(NOT CUDAToolkit_TARGET_DIR) # Not cross compiling set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}") # Now that we have the real ROOT_DIR, find components inside it. @@ -693,7 +730,7 @@ if(CUDAToolkit_NVCC_EXECUTABLE AND set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}") set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_VERSION}") endif() -else() +elseif(CUDAToolkit_NVCC_EXECUTABLE) # Compute the version by invoking nvcc execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT) if(NVCC_OUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=]) @@ -703,6 +740,17 @@ else() set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") endif() unset(NVCC_OUT) +else() + _CUDAToolkit_find_version_file(version_file) + if(version_file) + file(READ "${version_file}" VERSION_INFO) + if(VERSION_INFO MATCHES [=[CUDA Version ([0-9]+)\.([0-9]+)\.([0-9]+)]=]) + set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}") + set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}") + set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") + endif() + endif() endif() # Find the CUDA Runtime Library libcudart @@ -719,7 +767,6 @@ if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY) message(STATUS "Unable to find cudart library.") endif() -unset(CUDAToolkit_ROOT_DIR) if(_CUDAToolkit_Pop_Prefix) list(REMOVE_AT CMAKE_PREFIX_PATH -1) unset(_CUDAToolkit_Pop_Prefix) @@ -732,13 +779,16 @@ find_package_handle_standard_args(CUDAToolkit REQUIRED_VARS CUDAToolkit_INCLUDE_DIR CUDA_CUDART - CUDAToolkit_NVCC_EXECUTABLE + CUDAToolkit_BIN_DIR VERSION_VAR CUDAToolkit_VERSION ) + +unset(CUDAToolkit_ROOT_DIR) mark_as_advanced(CUDA_CUDART CUDAToolkit_INCLUDE_DIR CUDAToolkit_NVCC_EXECUTABLE + CUDAToolkit_SENTINEL_FILE ) #----------------------------------------------------------------------------- @@ -812,7 +862,7 @@ if(CUDAToolkit_FOUND) target_link_libraries(CUDA::cudart_static_deps INTERFACE Threads::Threads ${CMAKE_DL_LIBS}) endif() - if(UNIX AND NOT APPLE) + if(UNIX AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX")) # On Linux, you must link against librt when using the static cuda runtime. find_library(CUDAToolkit_rt_LIBRARY rt) mark_as_advanced(CUDAToolkit_rt_LIBRARY) diff --git a/Modules/FindCURL.cmake b/Modules/FindCURL.cmake index be7e16ea5..74b36c6f7 100644 --- a/Modules/FindCURL.cmake +++ b/Modules/FindCURL.cmake @@ -92,6 +92,7 @@ if(NOT CURL_LIBRARY) curllib_static # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): libcurl + NAMES_PER_DIR HINTS ${PC_CURL_LIBRARY_DIRS} ) mark_as_advanced(CURL_LIBRARY_RELEASE) @@ -100,6 +101,7 @@ if(NOT CURL_LIBRARY) # Windows MSVC CMake builds in debug configuration on vcpkg: libcurl-d_imp libcurl-d + NAMES_PER_DIR HINTS ${PC_CURL_LIBRARY_DIRS} ) mark_as_advanced(CURL_LIBRARY_DEBUG) diff --git a/Modules/FindCurses.cmake b/Modules/FindCurses.cmake index ba56078a5..cde3a4d2d 100644 --- a/Modules/FindCurses.cmake +++ b/Modules/FindCurses.cmake @@ -156,7 +156,9 @@ if(CURSES_USE_NCURSES) CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" cbreak "" CURSES_NCURSES_HAS_CBREAK) - if(NOT CURSES_NCURSES_HAS_CBREAK) + CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" + nodelay "" CURSES_NCURSES_HAS_NODELAY) + if(NOT CURSES_NCURSES_HAS_CBREAK OR NOT CURSES_NCURSES_HAS_NODELAY) find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" HINTS "${_cursesLibDir}") find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" ) diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake index 184a9a24a..81fbbb758 100644 --- a/Modules/FindDoxygen.cmake +++ b/Modules/FindDoxygen.cmake @@ -709,8 +709,8 @@ if(TARGET Doxygen::doxygen) set(_doxyfile_in "${CMAKE_BINARY_DIR}/CMakeDoxyfile.in") set(_doxyfile_defaults "${CMAKE_BINARY_DIR}/CMakeDoxygenDefaults.cmake") - file(WRITE "${_doxyfile_in}" ${_Doxygen_dne_header}) - file(WRITE "${_doxyfile_defaults}" ${_Doxygen_dne_header}) + set(_doxyfile_in_contents "") + set(_doxyfile_defaults_contents "") # Get strings containing a configuration key from the template Doxyfile # we obtained from this version of Doxygen. Because some options are split @@ -742,19 +742,19 @@ if(TARGET Doxygen::doxygen) if(_Doxygen_param MATCHES "([A-Z][A-Z0-9_]+)( *)=( (.*))?") # Ok, this is a config key with a value if(CMAKE_MATCH_COUNT EQUAL 4) - file(APPEND "${_doxyfile_in}" - "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n") + string(APPEND _doxyfile_in_contents + "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n") # Remove the backslashes we had to preserve to handle newlines string(REPLACE "\\\n" "\n" _value "${CMAKE_MATCH_4}") - file(APPEND "${_doxyfile_defaults}" + string(APPEND _doxyfile_defaults_contents "if(NOT DEFINED DOXYGEN_${CMAKE_MATCH_1}) set(DOXYGEN_${CMAKE_MATCH_1} ${_value}) endif() ") # Ok, this is a config key with empty default value elseif(CMAKE_MATCH_COUNT EQUAL 2) - file(APPEND "${_doxyfile_in}" - "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n") + string(APPEND _doxyfile_in_contents + "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n") else() message(AUTHOR_WARNING "Unexpected line format! Code review required!\nFault line: ${_Doxygen_param}") @@ -764,6 +764,10 @@ endif() "Unexpected line format! Code review required!\nFault line: ${_Doxygen_param}") endif() endforeach() + file(WRITE "${_doxyfile_defaults}" "${_Doxygen_dne_header}" + "${_doxyfile_defaults_contents}") + file(WRITE "${_doxyfile_in}" "${_Doxygen_dne_header}" + "${_doxyfile_in_contents}") # Ok, dumped defaults are not needed anymore... file(REMOVE "${_Doxygen_tpl}") diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake index 15b419a61..b0bb02a56 100644 --- a/Modules/FindEXPAT.cmake +++ b/Modules/FindEXPAT.cmake @@ -38,7 +38,7 @@ pkg_check_modules(PC_EXPAT QUIET expat) find_path(EXPAT_INCLUDE_DIR NAMES expat.h HINTS ${PC_EXPAT_INCLUDE_DIRS}) # Look for the library. -find_library(EXPAT_LIBRARY NAMES expat libexpat HINTS ${PC_EXPAT_LIBRARY_DIRS}) +find_library(EXPAT_LIBRARY NAMES expat libexpat NAMES_PER_DIR HINTS ${PC_EXPAT_LIBRARY_DIRS}) if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h") file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str diff --git a/Modules/FindEnvModules.cmake b/Modules/FindEnvModules.cmake index 4dd5116cd..a4ac0b47f 100644 --- a/Modules/FindEnvModules.cmake +++ b/Modules/FindEnvModules.cmake @@ -5,6 +5,8 @@ FindEnvModules -------------- +.. versionadded:: 3.15 + Locate an environment module implementation and make commands available to CMake scripts to use them. This is compatible with both Lua-based Lmod and TCL-based EnvironmentModules. diff --git a/Modules/FindFontconfig.cmake b/Modules/FindFontconfig.cmake index a6f0180b3..522883137 100644 --- a/Modules/FindFontconfig.cmake +++ b/Modules/FindFontconfig.cmake @@ -5,6 +5,8 @@ FindFontconfig -------------- +.. versionadded:: 3.14 + Find Fontconfig headers and library. Imported Targets diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake index d5a143e81..cea9cd8c7 100644 --- a/Modules/FindGIF.cmake +++ b/Modules/FindGIF.cmake @@ -60,6 +60,7 @@ set(POTENTIAL_GIF_LIBS gif libgif ungif libungif giflib giflib4) find_library(GIF_LIBRARY NAMES ${POTENTIAL_GIF_LIBS} + NAMES_PER_DIR HINTS ENV GIF_DIR PATH_SUFFIXES lib diff --git a/Modules/FindGLEW.cmake b/Modules/FindGLEW.cmake index 27ffa1347..187b6a8d2 100644 --- a/Modules/FindGLEW.cmake +++ b/Modules/FindGLEW.cmake @@ -126,24 +126,25 @@ if(GLEW_VERBOSE) message(STATUS "FindGLEW: GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}") endif() -if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64" OR "${CMAKE_GENERATOR}" MATCHES "Win64") +if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(_arch "x64") else() set(_arch "Win32") endif() - set(__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) __glew_set_find_library_suffix(SHARED) find_library(GLEW_SHARED_LIBRARY_RELEASE NAMES GLEW glew glew32 + NAMES_PER_DIR PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch} PATHS ENV GLEW_ROOT) find_library(GLEW_SHARED_LIBRARY_DEBUG NAMES GLEWd glewd glew32d + NAMES_PER_DIR PATH_SUFFIXES lib lib64 PATHS ENV GLEW_ROOT) @@ -152,11 +153,13 @@ __glew_set_find_library_suffix(STATIC) find_library(GLEW_STATIC_LIBRARY_RELEASE NAMES GLEW glew glew32s + NAMES_PER_DIR PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch} PATHS ENV GLEW_ROOT) find_library(GLEW_STATIC_LIBRARY_DEBUG NAMES GLEWds glewds glew32ds + NAMES_PER_DIR PATH_SUFFIXES lib lib64 PATHS ENV GLEW_ROOT) diff --git a/Modules/FindGSL.cmake b/Modules/FindGSL.cmake index da1b3c4e4..3d4e7f939 100644 --- a/Modules/FindGSL.cmake +++ b/Modules/FindGSL.cmake @@ -5,6 +5,8 @@ FindGSL -------- +.. versionadded:: 3.2 + Find the native GNU Scientific Library (GSL) includes and libraries. The GNU Scientific Library (GSL) is a numerical library for C and C++ diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake index 53cab1a76..10e31b29f 100644 --- a/Modules/FindGTest.cmake +++ b/Modules/FindGTest.cmake @@ -96,6 +96,27 @@ function(__gtest_find_library _name) mark_as_advanced(${_name}) endfunction() +function(__gtest_find_library_configuration _name _lib _cfg_suffix) + set(_libs ${_lib}) + if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD") + # The provided /MD project files for Google Test add -md suffixes to the + # library names. + list(INSERT _libs 0 ${_lib}-md) + endif() + list(TRANSFORM _libs APPEND "${_cfg_suffix}") + + __gtest_find_library(${_name} ${_libs}) +endfunction() + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +function(__gtest_find_and_select_library_configurations _basename _lib) + __gtest_find_library_configuration(${_basename}_LIBRARY_RELEASE ${_lib} "") + __gtest_find_library_configuration(${_basename}_LIBRARY_DEBUG ${_lib} "d") + + select_library_configurations(${_basename}) + set(${_basename}_LIBRARY ${${_basename}_LIBRARY} PARENT_SCOPE) +endfunction() + macro(__gtest_determine_windows_library_type _var) if(EXISTS "${${_var}}") file(TO_NATIVE_PATH "${${_var}}" _lib_path) @@ -187,18 +208,13 @@ find_path(GTEST_INCLUDE_DIR gtest/gtest.h ) mark_as_advanced(GTEST_INCLUDE_DIR) -if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD") - # The provided /MD project files for Google Test add -md suffixes to the - # library names. - __gtest_find_library(GTEST_LIBRARY gtest-md gtest) - __gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd) - __gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main) - __gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind) -else() - __gtest_find_library(GTEST_LIBRARY gtest) - __gtest_find_library(GTEST_LIBRARY_DEBUG gtestd) - __gtest_find_library(GTEST_MAIN_LIBRARY gtest_main) - __gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind) +# Allow GTEST_LIBRARY and GTEST_MAIN_LIBRARY to be set manually, as the +# locations of the gtest and gtest_main libraries, respectively. +if(NOT GTEST_LIBRARY) + __gtest_find_and_select_library_configurations(GTEST gtest) +endif() +if(NOT GTEST_MAIN_LIBRARY) + __gtest_find_and_select_library_configurations(GTEST_MAIN gtest_main) endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index c9d15984d..0a92c7140 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -110,6 +110,18 @@ also be defined. With all components enabled, the following variables will be d ``HDF5_DIFF_EXECUTABLE`` path to the HDF5 dataset comparison tool +With all components enabled, the following targets will be defined: + +:: + + ``hdf5::hdf5`` + ``hdf5::hdf5_hl_cpp`` + ``hdf5::hdf5_fortran`` + ``hdf5::hdf5_hl`` + ``hdf5::hdf5_hl_cpp`` + ``hdf5::hdf5_hl_fortran`` + ``hdf5::h5diff`` + Hints ^^^^^ @@ -125,11 +137,14 @@ The following variables can be set to guide the search for HDF5 libraries and in Set ``true`` to skip trying to find ``hdf5-config.cmake``. #]=======================================================================] -# This module is maintained by Will Dicharry <wdicharry@stellarscience.com>. - include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +# We haven't found HDF5 yet. Clear its state in case it is set in the parent +# scope somewhere else. We can't rely on it because different components may +# have been requested for this call. +set(HDF5_FOUND OFF) + # List of the valid HDF5 components set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) @@ -197,9 +212,7 @@ macro(_HDF5_remove_duplicates_from_beginning _list_name) endif() endmacro() - # Test first if the current compilers automatically wrap HDF5 - function(_HDF5_test_regular_compiler_C success version is_parallel) set(scratch_directory ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) @@ -346,6 +359,7 @@ function( _HDF5_invoke_compiler language output_var return_value_var version_var # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python execute_process( COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} ${test_file} + WORKING_DIRECTORY ${scratch_dir} RESULT_VARIABLE return_value ) if(return_value) @@ -354,6 +368,7 @@ function( _HDF5_invoke_compiler language output_var return_value_var version_var else() execute_process( COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} ${test_file} + WORKING_DIRECTORY ${scratch_dir} OUTPUT_VARIABLE output ERROR_VARIABLE output RESULT_VARIABLE return_value @@ -971,6 +986,138 @@ if( HDF5_FOUND AND NOT HDF5_DIR) mark_as_advanced(HDF5_DIR) endif() +if (HDF5_FOUND) + if (NOT TARGET HDF5::HDF5) + add_library(HDF5::HDF5 INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") + set_target_properties(HDF5::HDF5 PROPERTIES + INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + unset(_hdf5_definitions) + endif () + + foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "its location.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) + set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) + endif () + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + IMPORTED_LOCATION "${_hdf5_location}" + IMPORTED_IMPLIB "${_hdf5_location}" + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + + if (NOT HDF5_FIND_HL) + continue () + endif () + + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5_hl") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_hl_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_hl_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "its location.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + IMPORTED_LOCATION "${_hdf5_location}" + IMPORTED_IMPLIB "${_hdf5_location}" + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + endforeach () + unset(hdf5_lang) + + if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) + add_executable(hdf5::h5diff IMPORTED) + set_target_properties(hdf5::h5diff PROPERTIES + IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") + endif () +endif () + if (HDF5_FIND_DEBUG) message(STATUS "HDF5_DIR: ${HDF5_DIR}") message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") diff --git a/Modules/FindICU.cmake b/Modules/FindICU.cmake index 38081f5fa..c8b3e1fb7 100644 --- a/Modules/FindICU.cmake +++ b/Modules/FindICU.cmake @@ -5,6 +5,8 @@ FindICU ------- +.. versionadded:: 3.7 + Find the International Components for Unicode (ICU) libraries and programs. diff --git a/Modules/FindIce.cmake b/Modules/FindIce.cmake index 5ce2b42d9..0f821e886 100644 --- a/Modules/FindIce.cmake +++ b/Modules/FindIce.cmake @@ -5,6 +5,8 @@ FindIce ------- +.. versionadded:: 3.1 + Find the ZeroC Internet Communication Engine (ICE) programs, libraries and datafiles. diff --git a/Modules/FindIconv.cmake b/Modules/FindIconv.cmake index bf20f6f7e..41b75509f 100644 --- a/Modules/FindIconv.cmake +++ b/Modules/FindIconv.cmake @@ -5,6 +5,8 @@ FindIconv --------- +.. versionadded:: 3.11 + This module finds the ``iconv()`` POSIX.1 functions on the system. These functions might be provided in the regular C library or externally in the form of an additional library. @@ -110,6 +112,7 @@ endif() find_library(Iconv_LIBRARY NAMES ${Iconv_LIBRARY_NAMES} + NAMES_PER_DIR DOC "iconv library (potentially the C library)") mark_as_advanced(Iconv_INCLUDE_DIR) diff --git a/Modules/FindIntl.cmake b/Modules/FindIntl.cmake index 3818d45ec..1a09a6097 100644 --- a/Modules/FindIntl.cmake +++ b/Modules/FindIntl.cmake @@ -5,6 +5,8 @@ FindIntl -------- +.. versionadded:: 3.2 + Find the Gettext libintl headers and libraries. This module reports information about the Gettext libintl @@ -40,7 +42,7 @@ find_path(Intl_INCLUDE_DIR mark_as_advanced(Intl_INCLUDE_DIR) # Find all Intl libraries -find_library(Intl_LIBRARY "intl" +find_library(Intl_LIBRARY "intl" NAMES_PER_DIR DOC "libintl libraries (if not in the C library)") mark_as_advanced(Intl_LIBRARY) diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake index bbca95286..5aa2d601f 100644 --- a/Modules/FindJNI.cmake +++ b/Modules/FindJNI.cmake @@ -215,6 +215,14 @@ set(_JNI_JAVA_DIRECTORIES_BASE /usr/local/jre-1.7.0 /usr/local/jdk-1.6.0 /usr/local/jre-1.6.0 + # FreeBSD specific paths for default JVM + /usr/local/openjdk15 + /usr/local/openjdk14 + /usr/local/openjdk13 + /usr/local/openjdk12 + /usr/local/openjdk11 + /usr/local/openjdk8 + /usr/local/openjdk7 # SuSE specific paths for default JVM /usr/lib64/jvm/java /usr/lib64/jvm/jre diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index 0bb698979..632fc9aa0 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -58,8 +58,8 @@ foreach(name ${jpeg_names}) endforeach() if(NOT JPEG_LIBRARY) - find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names}) - find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug}) + find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names} NAMES_PER_DIR) + find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug} NAMES_PER_DIR) include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(JPEG) mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG) diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake index 31e7de68c..4b71cee59 100644 --- a/Modules/FindLAPACK.cmake +++ b/Modules/FindLAPACK.cmake @@ -26,9 +26,10 @@ The following variables may be set to influence this module's behavior: If set, checks only the specified vendor, if not set checks all the possibilities. List of vendors valid in this module: + * ``FlexiBLAS`` * ``OpenBLAS`` * ``FLAME`` - * ``Intel10_32`` (intel mkl v10 32 bit) + * ``Intel10_32`` (intel mkl v10 32 bit, threaded code) * ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model) * ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model) * ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model) @@ -86,42 +87,38 @@ This module defines the following variables: find_package(LAPACK) #]=======================================================================] -# Check the language being used -if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED)) - if(LAPACK_FIND_REQUIRED) - message(FATAL_ERROR "FindLAPACK requires Fortran, C, or C++ to be enabled.") - else() - message(STATUS "Looking for LAPACK... - NOT found (Unsupported languages)") - return() - endif() -endif() - if(CMAKE_Fortran_COMPILER_LOADED) include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake) else() include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake) endif() include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -cmake_push_check_state() -set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY}) +macro(_lapack_find_library_setup) + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY}) -set(LAPACK_FOUND FALSE) -set(LAPACK95_FOUND FALSE) - -set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) -if(BLA_STATIC) - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(BLA_STATIC) + if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif() else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif() -else() - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - # for ubuntu's libblas3gf and liblapack3gf packages - set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # for ubuntu's libblas3gf and liblapack3gf packages + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf) + endif() endif() -endif() +endmacro() + +macro(_lapack_find_library_teardown) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + unset(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + cmake_pop_check_state() +endmacro() # TODO: move this stuff to a separate module @@ -162,6 +159,7 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _a if(_libraries_work) find_library(${_prefix}_${_library}_LIBRARY NAMES ${_library} + NAMES_PER_DIR PATHS ${_extaddlibdir} PATH_SUFFIXES ${_subdirs} ) @@ -172,6 +170,7 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _a endif() endif() endforeach() + unset(_library) if(_libraries_work) # Test this combination of libraries. @@ -195,185 +194,226 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _a else() set(${LIBRARIES} FALSE) endif() + + unset(_extaddlibdir) + unset(_libraries_work) + unset(_combined_name) #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}") endmacro() +macro(_lapack_find_dependency dep) + set(_lapack_quiet_arg) + if(LAPACK_FIND_QUIETLY) + set(_lapack_quiet_arg QUIET) + endif() + set(_lapack_required_arg) + if(LAPACK_FIND_REQUIRED) + set(_lapack_required_arg REQUIRED) + endif() + find_package(${dep} ${ARGN} + ${_lapack_quiet_arg} + ${_lapack_required_arg} + ) + if (NOT ${dep}_FOUND) + set(LAPACK_NOT_FOUND_MESSAGE "LAPACK could not be found because dependency ${dep} could not be found.") + endif() + + set(_lapack_required_arg) + set(_lapack_quiet_arg) +endmacro() + +_lapack_find_library_setup() + set(LAPACK_LINKER_FLAGS) set(LAPACK_LIBRARIES) set(LAPACK95_LIBRARIES) -if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) - find_package(BLAS) -else() - find_package(BLAS REQUIRED) +# Check the language being used +if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED)) + set(LAPACK_NOT_FOUND_MESSAGE + "FindLAPACK requires Fortran, C, or C++ to be enabled.") +endif() + +# Load BLAS +if(NOT LAPACK_NOT_FOUND_MESSAGE) + _lapack_find_dependency(BLAS) endif() -if(BLAS_FOUND) +# Search for different LAPACK distributions if BLAS is found +if(NOT LAPACK_NOT_FOUND_MESSAGE) set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS}) if(NOT $ENV{BLA_VENDOR} STREQUAL "") set(BLA_VENDOR $ENV{BLA_VENDOR}) - else() - if(NOT BLA_VENDOR) - set(BLA_VENDOR "All") - endif() + elseif(NOT BLA_VENDOR) + set(BLA_VENDOR "All") endif() # LAPACK in the Intel MKL 10+ library? - if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED) - # System-specific settings - if(NOT WIN32) - set(LAPACK_mkl_LM "-lm") - set(LAPACK_mkl_LDL "-ldl") - endif() - - if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) - find_package(Threads) - else() - find_package(Threads REQUIRED) - endif() - - if(BLA_VENDOR MATCHES "_64ilp") - set(LAPACK_mkl_ILP_MODE "ilp64") - else() - set(LAPACK_mkl_ILP_MODE "lp64") - endif() - - set(LAPACK_SEARCH_LIBS "") - - if(BLA_F95) - set(LAPACK_mkl_SEARCH_SYMBOL "cheev_f95") - set(_LIBRARIES LAPACK95_LIBRARIES) - set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES}) - - # old - list(APPEND LAPACK_SEARCH_LIBS - "mkl_lapack95") - # new >= 10.3 - list(APPEND LAPACK_SEARCH_LIBS - "mkl_intel_c") - list(APPEND LAPACK_SEARCH_LIBS - "mkl_lapack95_${LAPACK_mkl_ILP_MODE}") - else() - set(LAPACK_mkl_SEARCH_SYMBOL "cheev") - set(_LIBRARIES LAPACK_LIBRARIES) - set(_BLAS_LIBRARIES ${BLAS_LIBRARIES}) - - # old and new >= 10.3 - list(APPEND LAPACK_SEARCH_LIBS - "mkl_lapack") - endif() - - # MKL uses a multitude of partially platform-specific subdirectories: - if(BLA_VENDOR STREQUAL "Intel10_32") - set(LAPACK_mkl_ARCH_NAME "ia32") - else() - set(LAPACK_mkl_ARCH_NAME "intel64") - endif() - if(WIN32) - set(LAPACK_mkl_OS_NAME "win") - elseif(APPLE) - set(LAPACK_mkl_OS_NAME "mac") - else() - set(LAPACK_mkl_OS_NAME "lin") - endif() - if(DEFINED ENV{MKLROOT}) - file(TO_CMAKE_PATH "$ENV{MKLROOT}" LAPACK_mkl_MKLROOT) - # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead - # so we can better detect other relevant libraries in 'compiler' or 'tbb': - get_filename_component(LAPACK_mkl_MKLROOT_LAST_DIR "${LAPACK_mkl_MKLROOT}" NAME) - if(LAPACK_mkl_MKLROOT_LAST_DIR STREQUAL "mkl") - get_filename_component(LAPACK_mkl_MKLROOT "${LAPACK_mkl_MKLROOT}" DIRECTORY) - endif() - endif() - set(LAPACK_mkl_LIB_PATH_SUFFIXES - "compiler/lib" "compiler/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}" - "mkl/lib" "mkl/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}" - "lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}") - - # First try empty lapack libs - if(NOT ${_LIBRARIES}) - check_lapack_libraries( - ${_LIBRARIES} - LAPACK - ${LAPACK_mkl_SEARCH_SYMBOL} - "" - "" - "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}" - "${LAPACK_mkl_MKLROOT}" - "${LAPACK_mkl_LIB_PATH_SUFFIXES}" - "${_BLAS_LIBRARIES}" - ) - endif() - - # Then try the search libs - foreach(IT ${LAPACK_SEARCH_LIBS}) - string(REPLACE " " ";" SEARCH_LIBS ${IT}) - if(NOT ${_LIBRARIES}) - check_lapack_libraries( - ${_LIBRARIES} - LAPACK - ${LAPACK_mkl_SEARCH_SYMBOL} - "" - "${SEARCH_LIBS}" - "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}" - "${LAPACK_mkl_MKLROOT}" - "${LAPACK_mkl_LIB_PATH_SUFFIXES}" - "${_BLAS_LIBRARIES}" - ) - endif() - endforeach() - - unset(LAPACK_mkl_ILP_MODE) - unset(LAPACK_mkl_SEARCH_SYMBOL) - unset(LAPACK_mkl_LM) - unset(LAPACK_mkl_LDL) - unset(LAPACK_mkl_MKLROOT) - unset(LAPACK_mkl_ARCH_NAME) - unset(LAPACK_mkl_OS_NAME) - unset(LAPACK_mkl_LIB_PATH_SUFFIXES) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") + AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)) + # System-specific settings + if(NOT WIN32) + set(LAPACK_mkl_LM "-lm") + set(LAPACK_mkl_LDL "-ldl") endif() - endif() - # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2) - if(BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) + _lapack_find_dependency(Threads) + + if(BLA_VENDOR MATCHES "_64ilp") + set(LAPACK_mkl_ILP_MODE "ilp64") + else() + set(LAPACK_mkl_ILP_MODE "lp64") + endif() + + set(LAPACK_SEARCH_LIBS "") + + if(BLA_F95) + set(LAPACK_mkl_SEARCH_SYMBOL "cheev_f95") + set(_LIBRARIES LAPACK95_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES}) + + # old + list(APPEND LAPACK_SEARCH_LIBS + "mkl_lapack95") + # new >= 10.3 + list(APPEND LAPACK_SEARCH_LIBS + "mkl_intel_c") + list(APPEND LAPACK_SEARCH_LIBS + "mkl_lapack95_${LAPACK_mkl_ILP_MODE}") + else() + set(LAPACK_mkl_SEARCH_SYMBOL "cheev") + set(_LIBRARIES LAPACK_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS_LIBRARIES}) + + # old and new >= 10.3 + list(APPEND LAPACK_SEARCH_LIBS + "mkl_lapack") + endif() + + # MKL uses a multitude of partially platform-specific subdirectories: + if(BLA_VENDOR STREQUAL "Intel10_32") + set(LAPACK_mkl_ARCH_NAME "ia32") + else() + set(LAPACK_mkl_ARCH_NAME "intel64") + endif() + if(WIN32) + set(LAPACK_mkl_OS_NAME "win") + elseif(APPLE) + set(LAPACK_mkl_OS_NAME "mac") + else() + set(LAPACK_mkl_OS_NAME "lin") + endif() + if(DEFINED ENV{MKLROOT}) + file(TO_CMAKE_PATH "$ENV{MKLROOT}" LAPACK_mkl_MKLROOT) + # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead + # so we can better detect other relevant libraries in 'compiler' or 'tbb': + get_filename_component(LAPACK_mkl_MKLROOT_LAST_DIR "${LAPACK_mkl_MKLROOT}" NAME) + if(LAPACK_mkl_MKLROOT_LAST_DIR STREQUAL "mkl") + get_filename_component(LAPACK_mkl_MKLROOT "${LAPACK_mkl_MKLROOT}" DIRECTORY) + endif() + endif() + set(LAPACK_mkl_LIB_PATH_SUFFIXES + "compiler/lib" "compiler/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}" + "compiler/lib/${LAPACK_mkl_ARCH_NAME}" + "mkl/lib" "mkl/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}" + "mkl/lib/${LAPACK_mkl_ARCH_NAME}" + "lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}") + + # First try empty lapack libs + if(NOT ${_LIBRARIES}) check_lapack_libraries( - LAPACK_LIBRARIES + ${_LIBRARIES} LAPACK - cheev - "" - "goto2" - "" + ${LAPACK_mkl_SEARCH_SYMBOL} "" "" - "${BLAS_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}" + "${LAPACK_mkl_MKLROOT}" + "${LAPACK_mkl_LIB_PATH_SUFFIXES}" + "${_BLAS_LIBRARIES}" ) endif() + + # Then try the search libs + foreach(IT ${LAPACK_SEARCH_LIBS}) + string(REPLACE " " ";" SEARCH_LIBS ${IT}) + if(NOT ${_LIBRARIES}) + check_lapack_libraries( + ${_LIBRARIES} + LAPACK + ${LAPACK_mkl_SEARCH_SYMBOL} + "" + "${SEARCH_LIBS}" + "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}" + "${LAPACK_mkl_MKLROOT}" + "${LAPACK_mkl_LIB_PATH_SUFFIXES}" + "${_BLAS_LIBRARIES}" + ) + endif() + endforeach() + + unset(LAPACK_mkl_ILP_MODE) + unset(LAPACK_mkl_SEARCH_SYMBOL) + unset(LAPACK_mkl_LM) + unset(LAPACK_mkl_LDL) + unset(LAPACK_mkl_MKLROOT) + unset(LAPACK_mkl_ARCH_NAME) + unset(LAPACK_mkl_OS_NAME) + unset(LAPACK_mkl_LIB_PATH_SUFFIXES) + endif() + + # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2) + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "goto2" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) + endif() + + # FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/) + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "flexiblas" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # OpenBLAS? (http://www.openblas.net) - if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "openblas" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "openblas" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # ArmPL? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries) - if(BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All") - + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All")) # Check for 64bit Integer support if(BLA_VENDOR MATCHES "_ilp64") set(LAPACK_armpl_LIB "armpl_ilp64") @@ -386,36 +426,33 @@ if(BLAS_FOUND) set(LAPACK_armpl_LIB "${LAPACK_armpl_LIB}_mp") endif() - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "${LAPACK_armpl_LIB}" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "${LAPACK_armpl_LIB}" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # FLAME's blis library? (https://github.com/flame/blis) - if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "flame" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "flame" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # BLAS in acml library? @@ -426,106 +463,70 @@ if(BLAS_FOUND) endif() # Apple LAPACK library? - if(BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "Accelerate" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "Accelerate" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # Apple NAS (vecLib) library? - if(BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "vecLib" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "vecLib" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() # Generic LAPACK library? - if(BLA_VENDOR STREQUAL "Generic" OR - BLA_VENDOR STREQUAL "ATLAS" OR - BLA_VENDOR STREQUAL "All") - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "lapack" - "" - "" - "" - "${BLAS_LIBRARIES}" - ) - endif() + if(NOT LAPACK_LIBRARIES + AND (BLA_VENDOR STREQUAL "Generic" + OR BLA_VENDOR STREQUAL "ATLAS" + OR BLA_VENDOR STREQUAL "All")) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "lapack" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) endif() -else() - message(STATUS "LAPACK requires BLAS") endif() if(BLA_F95) - if(LAPACK95_LIBRARIES) - set(LAPACK95_FOUND TRUE) - else() - set(LAPACK95_FOUND FALSE) - endif() - if(NOT LAPACK_FIND_QUIETLY) - if(LAPACK95_FOUND) - message(STATUS "A library with LAPACK95 API found.") - else() - if(LAPACK_FIND_REQUIRED) - message(FATAL_ERROR - "A required library with LAPACK95 API not found. Please specify library location." - ) - else() - message(STATUS - "A library with LAPACK95 API not found. Please specify library location." - ) - endif() - endif() - endif() - set(LAPACK_FOUND "${LAPACK95_FOUND}") set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}") -else() - if(LAPACK_LIBRARIES) - set(LAPACK_FOUND TRUE) - else() - set(LAPACK_FOUND FALSE) - endif() +endif() - if(NOT LAPACK_FIND_QUIETLY) - if(LAPACK_FOUND) - message(STATUS "A library with LAPACK API found.") - else() - if(LAPACK_FIND_REQUIRED) - message(FATAL_ERROR - "A required library with LAPACK API not found. Please specify library location." - ) - else() - message(STATUS - "A library with LAPACK API not found. Please specify library location." - ) - endif() - endif() - endif() +if(LAPACK_NOT_FOUND_MESSAGE) + set(LAPACK_NOT_FOUND_MESSAGE + REASON_FAILURE_MESSAGE ${LAPACK_NOT_FOUND_MESSAGE}) +endif() +find_package_handle_standard_args(LAPACK REQUIRED_VARS LAPACK_LIBRARIES + ${LAPACK_NOT_FOUND_MESSAGE}) +unset(LAPACK_NOT_FOUND_MESSAGE) + +if(BLA_F95) + set(LAPACK95_FOUND ${LAPACK_FOUND}) endif() # On compilers that implicitly link LAPACK (such as ftn, cc, and CC on Cray HPC machines) @@ -534,7 +535,7 @@ if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES") set(LAPACK_LIBRARIES "") endif() -if(NOT TARGET LAPACK::LAPACK) +if(LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK) add_library(LAPACK::LAPACK INTERFACE IMPORTED) set(_lapack_libs "${LAPACK_LIBRARIES}") if(_lapack_libs AND TARGET BLAS::BLAS) @@ -551,5 +552,4 @@ if(NOT TARGET LAPACK::LAPACK) unset(_lapack_libs) endif() -cmake_pop_check_state() -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +_lapack_find_library_teardown() diff --git a/Modules/FindLTTngUST.cmake b/Modules/FindLTTngUST.cmake index 9cd17eb05..f478e4d24 100644 --- a/Modules/FindLTTngUST.cmake +++ b/Modules/FindLTTngUST.cmake @@ -5,6 +5,8 @@ FindLTTngUST ------------ +.. versionadded:: 3.6 + Find `Linux Trace Toolkit Next Generation (LTTng-UST) <http://lttng.org/>`__ library. diff --git a/Modules/FindLibLZMA.cmake b/Modules/FindLibLZMA.cmake index 200d6bf8d..4a79a1028 100644 --- a/Modules/FindLibLZMA.cmake +++ b/Modules/FindLibLZMA.cmake @@ -43,8 +43,8 @@ This module will set the following variables in your project: find_path(LIBLZMA_INCLUDE_DIR lzma.h ) if(NOT LIBLZMA_LIBRARY) - find_library(LIBLZMA_LIBRARY_RELEASE NAMES lzma liblzma PATH_SUFFIXES lib) - find_library(LIBLZMA_LIBRARY_DEBUG NAMES lzmad liblzmad PATH_SUFFIXES lib) + find_library(LIBLZMA_LIBRARY_RELEASE NAMES lzma liblzma NAMES_PER_DIR PATH_SUFFIXES lib) + find_library(LIBLZMA_LIBRARY_DEBUG NAMES lzmad liblzmad NAMES_PER_DIR PATH_SUFFIXES lib) include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(LIBLZMA) else() diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake index f551dfe1d..063160712 100644 --- a/Modules/FindLibXml2.cmake +++ b/Modules/FindLibXml2.cmake @@ -67,7 +67,7 @@ if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY) set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) endif() -find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 +find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 libxml2_a HINTS ${PC_LIBXML_LIBDIR} ${PC_LIBXML_LIBRARY_DIRS} diff --git a/Modules/FindLibinput.cmake b/Modules/FindLibinput.cmake index c1fe45562..88d5b2fb3 100644 --- a/Modules/FindLibinput.cmake +++ b/Modules/FindLibinput.cmake @@ -5,6 +5,8 @@ FindLibinput ------------ +.. versionadded:: 3.14 + Find libinput headers and library. Imported Targets diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index bbd40a4b0..b531e4740 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -760,7 +760,7 @@ function (_MPI_interrogate_compiler LANG) # Save the explicitly given link directories set(MPI_LINK_DIRECTORIES_LEFTOVER "${MPI_LINK_DIRECTORIES_WORK}") - # An MPI compiler wrapper could have its MPI libraries in the implictly + # An MPI compiler wrapper could have its MPI libraries in the implicitly # linked directories of the compiler itself. if(DEFINED CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES) list(APPEND MPI_LINK_DIRECTORIES_WORK "${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}") diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index d268717ac..01f04922f 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -993,7 +993,10 @@ function(matlab_add_mex) endif() endif() - if(NOT Matlab_VERSION_STRING VERSION_LESS "9.4") # For 9.4 (R2018a) and newer, add API macro + # For 9.4 (R2018a) and newer, add API macro. + # Add it for unknown versions too, just in case. + if(NOT Matlab_VERSION_STRING VERSION_LESS "9.4" + OR Matlab_VERSION_STRING STREQUAL "unknown") if(${${prefix}_R2018a}) set(MEX_API_MACRO "MATLAB_DEFAULT_RELEASE=R2018a") else() diff --git a/Modules/FindODBC.cmake b/Modules/FindODBC.cmake index 3f710dbb9..884653c75 100644 --- a/Modules/FindODBC.cmake +++ b/Modules/FindODBC.cmake @@ -5,6 +5,8 @@ FindODBC -------- +.. versionadded:: 3.12 + Find an Open Database Connectivity (ODBC) include directory and library. On Windows, when building with Visual Studio, this module assumes the ODBC diff --git a/Modules/FindOpenACC.cmake b/Modules/FindOpenACC.cmake index 398dcf54f..ed52e3591 100644 --- a/Modules/FindOpenACC.cmake +++ b/Modules/FindOpenACC.cmake @@ -5,6 +5,8 @@ FindOpenACC ----------- +.. versionadded:: 3.10 + Detect OpenACC support by the compiler. This module can be used to detect OpenACC support in a compiler. diff --git a/Modules/FindOpenCL.cmake b/Modules/FindOpenCL.cmake index 34a203e13..b3e5a9f8d 100644 --- a/Modules/FindOpenCL.cmake +++ b/Modules/FindOpenCL.cmake @@ -5,6 +5,8 @@ FindOpenCL ---------- +.. versionadded:: 3.1 + Finds Open Computing Language (OpenCL) IMPORTED Targets diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake index 17ffe85b3..110e7f963 100644 --- a/Modules/FindOpenGL.cmake +++ b/Modules/FindOpenGL.cmake @@ -132,19 +132,7 @@ endforeach() set(_OpenGL_CACHE_VARS) -if (CYGWIN) - find_path(OPENGL_INCLUDE_DIR GL/gl.h ) - list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) - - find_library(OPENGL_gl_LIBRARY opengl32 ) - find_library(OPENGL_glu_LIBRARY glu32 ) - - list(APPEND _OpenGL_CACHE_VARS - OPENGL_INCLUDE_DIR - OPENGL_gl_LIBRARY - OPENGL_glu_LIBRARY - ) -elseif (WIN32) +if (WIN32) if(BORLAND) set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32") diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake index ee40696eb..91a65fdda 100644 --- a/Modules/FindOpenSSL.cmake +++ b/Modules/FindOpenSSL.cmake @@ -27,11 +27,11 @@ This module defines the following :prop_tgt:`IMPORTED` targets: projects under MSVC. This target is available only if found OpenSSL version is not less than 0.9.8. By linking this target the above OpenSSL targets can be linked even if the project has different MSVC runtime configurations with - the above OpenSSL targets. This target has no effect on plaforms other than + the above OpenSSL targets. This target has no effect on platforms other than MSVC. NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target, -unless you certainly know what you are doing, it is always prefered to link +unless you certainly know what you are doing, it is always preferred to link ``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is linked at most once for the whole dependency graph of any library or executable: @@ -193,12 +193,18 @@ if(WIN32 AND NOT CYGWIN) endif() if(OPENSSL_USE_STATIC_LIBS) + set(_OPENSSL_STATIC_SUFFIX + "_static" + ) set(_OPENSSL_PATH_SUFFIXES "lib/VC/static" "VC/static" "lib" ) else() + set(_OPENSSL_STATIC_SUFFIX + "" + ) set(_OPENSSL_PATH_SUFFIXES "lib/VC" "VC" @@ -208,6 +214,17 @@ if(WIN32 AND NOT CYGWIN) find_library(LIB_EAY_DEBUG NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}d + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libeay32${_OPENSSL_STATIC_SUFFIX}d + crypto${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libcrypto${_OPENSSL_MSVC_RT_MODE}d libcryptod @@ -222,6 +239,17 @@ if(WIN32 AND NOT CYGWIN) find_library(LIB_EAY_RELEASE NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX} + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libeay32${_OPENSSL_STATIC_SUFFIX} + crypto${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libcrypto${_OPENSSL_MSVC_RT_MODE} libcrypto @@ -236,6 +264,17 @@ if(WIN32 AND NOT CYGWIN) find_library(SSL_EAY_DEBUG NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}d + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + ssleay32${_OPENSSL_STATIC_SUFFIX}d + ssl${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d libssl${_OPENSSL_MSVC_RT_MODE}d libssld @@ -250,6 +289,17 @@ if(WIN32 AND NOT CYGWIN) find_library(SSL_EAY_RELEASE NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX} + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + ssleay32${_OPENSSL_STATIC_SUFFIX} + ssl${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} libssl${_OPENSSL_MSVC_RT_MODE} libssl diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake index f1fe89af1..fd0e4e93e 100644 --- a/Modules/FindPNG.cmake +++ b/Modules/FindPNG.cmake @@ -76,8 +76,8 @@ if(ZLIB_FOUND) # For compatibility with versions prior to this multi-config search, honor # any PNG_LIBRARY that is already specified and skip the search. if(NOT PNG_LIBRARY) - find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES}) - find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG}) + find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES} NAMES_PER_DIR) + find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG} NAMES_PER_DIR) include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(PNG) mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG) diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index 4fb08259a..7af017136 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -5,16 +5,19 @@ FindPackageHandleStandardArgs ----------------------------- -This module provides a function intended to be used in :ref:`Find Modules` -implementing :command:`find_package(<PackageName>)` calls. It handles the -``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``. -It also sets the ``<PackageName>_FOUND`` variable. The package is -considered found if all variables listed contain valid results, e.g. -valid filepaths. +This module provides functions intended to be used in :ref:`Find Modules` +implementing :command:`find_package(<PackageName>)` calls. .. command:: find_package_handle_standard_args - There are two signatures:: + This command handles the ``REQUIRED``, ``QUIET`` and version-related + arguments of :command:`find_package`. It also sets the + ``<PackageName>_FOUND`` variable. The package is considered found if all + variables listed contain valid results, e.g. valid filepaths. + + There are two signatures: + + .. code-block:: cmake find_package_handle_standard_args(<PackageName> (DEFAULT_MSG|<custom-failure-message>) @@ -25,6 +28,7 @@ valid filepaths. [FOUND_VAR <result-var>] [REQUIRED_VARS <required-var>...] [VERSION_VAR <version-var>] + [HANDLE_VERSION_RANGE] [HANDLE_COMPONENTS] [CONFIG_MODE] [NAME_MISMATCHED] @@ -69,6 +73,11 @@ valid filepaths. version and the version which has been actually found, both if the version is ok or not. + ``HANDLE_VERSION_RANGE`` + Enable handling of a version range, if one is specified. Without this + option, a developer warning will be displayed if a version range is + specified. + ``HANDLE_COMPONENTS`` Enable handling of package components. In this case, the command will report which components have been found and which are missing, @@ -151,10 +160,54 @@ In this case, a ``FindAutmoc4.cmake`` module wraps a call to directory for ``automoc4``. Then the call to ``find_package_handle_standard_args`` produces a proper success/failure message. + +.. command:: find_package_check_version + + Helper function which can be used to check if a ``<version>`` is valid + against version-related arguments of :command:`find_package`. + + .. code-block:: cmake + + find_package_check_version(<version> <result-var> + [HANDLE_VERSION_RANGE] + [RESULT_MESSAGE_VARIABLE <message-var>] + ) + + The ``<result-var>`` will hold a boolean value giving the result of the check. + + The options are: + + ``HANDLE_VERSION_RANGE`` + Enable handling of a version range, if one is specified. Without this + option, a developer warning will be displayed if a version range is + specified. + + ``RESULT_MESSAGE_VARIABLE <message-var>`` + Specify a variable to get back a message describing the result of the check. + +Example for the usage: + +.. code-block:: cmake + + find_package_check_version(1.2.3 result HANDLE_VERSION_RANGE + RESULT_MESSAGE_VARIABLE reason) + if (result) + message (STATUS "${reason}") + else() + message (FATAL_ERROR "${reason}") + endif() #]=======================================================================] include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) + +cmake_policy(PUSH) +# numbers and boolean constants +cmake_policy (SET CMP0012 NEW) +# IN_LIST operator +cmake_policy (SET CMP0057 NEW) + + # internal helper macro macro(_FPHSA_FAILURE_MESSAGE _msg) set (__msg "${_msg}") @@ -207,10 +260,108 @@ macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) endmacro() +function(FIND_PACKAGE_CHECK_VERSION version result) + cmake_parse_arguments (PARSE_ARGV 2 FPCV "HANDLE_VERSION_RANGE;NO_AUTHOR_WARNING_VERSION_RANGE" "RESULT_MESSAGE_VARIABLE" "") + + if (FPCV_UNPARSED_ARGUMENTS) + message (FATAL_ERROR "find_package_check_version(): ${FPCV_UNPARSED_ARGUMENTS}: unexpected arguments") + endif() + if ("RESULT_MESSAGE_VARIABLE" IN_LIST FPCV_KEYWORDS_MISSING_VALUES) + message (FATAL_ERROR "find_package_check_version(): RESULT_MESSAGE_VARIABLE expects an argument") + endif() + + set (${result} FALSE PARENT_SCOPE) + if (FPCV_RESULT_MESSAGE_VARIABLE) + unset (${FPCV_RESULT_MESSAGE_VARIABLE} PARENT_SCOPE) + endif() + + if (CMAKE_FIND_PACKAGE_NAME) + set (package ${CMAKE_FIND_PACKAGE_NAME}) + else() + message (FATAL_ERROR "find_package_check_version(): Cannot be used outside a 'Find Module'") + endif() + + if (NOT FPCV_NO_AUTHOR_WARNING_VERSION_RANGE + AND ${package}_FIND_VERSION_RANGE AND NOT FPCV_HANDLE_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the option " + "HANDLE_VERSION_RANGE` is not passed to `find_package_check_version()`. " + "Only the lower endpoint of the range will be used.") + endif() + + + set (version_ok FALSE) + unset (version_msg) + + if (FPCV_HANDLE_VERSION_RANGE AND ${package}_FIND_VERSION_RANGE) + if ((${package}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" + AND version VERSION_GREATER_EQUAL ${package}_FIND_VERSION_MIN) + AND ((${package}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" + AND version VERSION_LESS_EQUAL ${package}_FIND_VERSION_MAX) + OR (${package}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" + AND version VERSION_LESS ${package}_FIND_VERSION_MAX))) + set (version_ok TRUE) + set(version_msg "(found suitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\")") + else() + set(version_msg "Found unsuitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\"") + endif() + elseif (DEFINED ${package}_FIND_VERSION) + if(${package}_FIND_VERSION_EXACT) # exact version required + # count the dots in the version string + string(REGEX REPLACE "[^.]" "" version_dots "${version}") + # add one dot because there is one dot more than there are components + string(LENGTH "${version_dots}." version_dots) + if (version_dots GREATER ${package}_FIND_VERSION_COUNT) + # Because of the C++ implementation of find_package() ${package}_FIND_VERSION_COUNT + # is at most 4 here. Therefore a simple lookup table is used. + if (${package}_FIND_VERSION_COUNT EQUAL 1) + set(version_regex "[^.]*") + elseif (${package}_FIND_VERSION_COUNT EQUAL 2) + set(version_regex "[^.]*\\.[^.]*") + elseif (${package}_FIND_VERSION_COUNT EQUAL 3) + set(version_regex "[^.]*\\.[^.]*\\.[^.]*") + else() + set(version_regex "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") + endif() + string(REGEX REPLACE "^(${version_regex})\\..*" "\\1" version_head "${version}") + if (NOT ${package}_FIND_VERSION VERSION_EQUAL version_head) + set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"") + else () + set(version_ok TRUE) + set(version_msg "(found suitable exact version \"${_FOUND_VERSION}\")") + endif () + else () + if (NOT ${package}_FIND_VERSION VERSION_EQUAL version) + set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"") + else () + set(version_ok TRUE) + set(version_msg "(found suitable exact version \"${version}\")") + endif () + endif () + else() # minimum version + if (${package}_FIND_VERSION VERSION_GREATER version) + set(version_msg "Found unsuitable version \"${version}\", but required is at least \"${${package}_FIND_VERSION}\"") + else() + set(version_ok TRUE) + set(version_msg "(found suitable version \"${version}\", minimum required is \"${${package}_FIND_VERSION}\")") + endif() + endif() + else () + set(version_ok TRUE) + set(version_msg "(found version \"${version}\")") + endif() + + set (${result} ${version_ok} PARENT_SCOPE) + if (FPCV_RESULT_MESSAGE_VARIABLE) + set (${FPCV_RESULT_MESSAGE_VARIABLE} "${version_msg}" PARENT_SCOPE) + endif() +endfunction() + + function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # Set up the arguments for `cmake_parse_arguments`. - set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED) + set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED HANDLE_VERSION_RANGE) set(oneValueArgs FAIL_MESSAGE REASON_FAILURE_MESSAGE VERSION_VAR FOUND_VAR) set(multiValueArgs REQUIRED_VARS) @@ -278,7 +429,14 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) "to follow a certain pattern.") endif () -# now that we collected all arguments, process them + if (${_NAME}_FIND_VERSION_RANGE AND NOT FPHSA_HANDLE_VERSION_RANGE) + message(AUTHOR_WARNING + "`find_package()` specify a version range but the module ${_NAME} does " + "not support this capability. Only the lower endpoint of the range " + "will be used.") + endif() + + # now that we collected all arguments, process them if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG") set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") @@ -364,61 +522,22 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) if (DEFINED ${_NAME}_FIND_VERSION) if(DEFINED ${FPHSA_VERSION_VAR}) set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}}) - - if(${_NAME}_FIND_VERSION_EXACT) # exact version required - # count the dots in the version string - string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${_FOUND_VERSION}") - # add one dot because there is one dot more than there are components - string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS) - if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT) - # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT - # is at most 4 here. Therefore a simple lookup table is used. - if (${_NAME}_FIND_VERSION_COUNT EQUAL 1) - set(_VERSION_REGEX "[^.]*") - elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2) - set(_VERSION_REGEX "[^.]*\\.[^.]*") - elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3) - set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*") - else () - set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") - endif () - string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${_FOUND_VERSION}") - unset(_VERSION_REGEX) - if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD) - set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")") - endif () - unset(_VERSION_HEAD) - else () - if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _FOUND_VERSION) - set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")") - endif () - endif () - unset(_VERSION_DOTS) - - else() # minimum version specified: - if (${_NAME}_FIND_VERSION VERSION_GREATER _FOUND_VERSION) - set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable version \"${_FOUND_VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") - endif () + if (FPHSA_HANDLE_VERSION_RANGE) + set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE) + else() + set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE) endif() - + find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG + ${FPCV_HANDLE_VERSION_RANGE}) else() - # if the package was not found, but a version was given, add that to the output: if(${_NAME}_FIND_VERSION_EXACT) - set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") + set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") + elseif (FPHSA_HANDLE_VERSION_RANGE AND ${_NAME}_FIND_VERSION_RANGE) + set(VERSION_MSG "(Required is version range \"${${_NAME}_FIND_VERSION_RANGE}\")") else() - set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") + set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") endif() - endif() else () # Check with DEFINED as the found version may be 0. @@ -464,3 +583,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) endfunction() + + +cmake_policy(POP) diff --git a/Modules/FindPatch.cmake b/Modules/FindPatch.cmake index 49988395b..41086517d 100644 --- a/Modules/FindPatch.cmake +++ b/Modules/FindPatch.cmake @@ -5,6 +5,8 @@ FindPatch --------- +.. versionadded:: 3.10 + The module defines the following variables: ``Patch_EXECUTABLE`` diff --git a/Modules/FindPerlLibs.cmake b/Modules/FindPerlLibs.cmake index 7e27f3188..d576b86cd 100644 --- a/Modules/FindPerlLibs.cmake +++ b/Modules/FindPerlLibs.cmake @@ -108,6 +108,9 @@ if (PERL_EXECUTABLE) if (NOT PERL_POSSIBLE_LIBRARY_NAMES) set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl) endif() + if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN") + list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING}) + endif() if (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN") # on MSYS and CYGWIN environments, current perl -V:libperl gives shared library name # rather than the import library. So, extends possible library names diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 93827d8be..2ad2c7e17 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -31,7 +31,13 @@ set(PKG_CONFIG_VERSION 1) if((NOT PKG_CONFIG_EXECUTABLE) AND (NOT "$ENV{PKG_CONFIG}" STREQUAL "")) set(PKG_CONFIG_EXECUTABLE "$ENV{PKG_CONFIG}" CACHE FILEPATH "pkg-config executable") endif() -find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable") + +set(PKG_CONFIG_NAMES "pkg-config") +if(CMAKE_HOST_WIN32) + list(PREPEND PKG_CONFIG_NAMES "pkg-config.bat") +endif() + +find_program(PKG_CONFIG_EXECUTABLE NAMES ${PKG_CONFIG_NAMES} DOC "pkg-config executable") mark_as_advanced(PKG_CONFIG_EXECUTABLE) set(_PKG_CONFIG_FAILURE_MESSAGE "") @@ -47,7 +53,9 @@ if (PKG_CONFIG_EXECUTABLE) string(APPEND _PKG_CONFIG_FAILURE_MESSAGE "The command\n" " \"${PKG_CONFIG_EXECUTABLE}\" --version\n" - " failed with output\n${_PKG_CONFIG_VERSION_ERROR}" + " failed with output:\n${PKG_CONFIG_VERSION_STRING}\n" + " stderr: \n${_PKG_CONFIG_VERSION_ERROR}\n" + " result: \n${_PKG_CONFIG_VERSION_RESULT}" ) set(PKG_CONFIG_EXECUTABLE "") unset(PKG_CONFIG_VERSION_STRING) diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index 1927aa4b8..1970b26a3 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -87,7 +87,7 @@ set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to wher set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS} - "12" "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") + "13" "12" "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") # Define additional search paths for root directories. set( PostgreSQL_ROOT_DIRECTORIES diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index e09717db8..4bf54efe3 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -376,17 +376,19 @@ function(_protobuf_find_libraries name filename) else() find_library(${name}_LIBRARY_RELEASE NAMES ${filename} + NAMES_PER_DIR PATHS ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release) mark_as_advanced(${name}_LIBRARY_RELEASE) find_library(${name}_LIBRARY_DEBUG NAMES ${filename}d ${filename} + NAMES_PER_DIR PATHS ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug) mark_as_advanced(${name}_LIBRARY_DEBUG) select_library_configurations(${name}) - if(UNIX AND Threads_FOUND) + if(UNIX AND Threads_FOUND AND ${name}_LIBRARY) list(APPEND ${name}_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) endif() diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index 01b82c4b2..5fc6a3b21 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -5,9 +5,15 @@ FindPython ---------- +.. versionadded:: 3.12 + Find Python interpreter, compiler and development environment (include directories and libraries). +When a version is requested, it can be specified as a simple value or as a +range. For a detailed description of version range usage and capabilities, +refer to the :command:`find_package` command. + The following components are supported: * ``Interpreter``: search for Python interpreter. @@ -44,7 +50,7 @@ To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and If components ``Interpreter`` and ``Development`` (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by ``CMake`` - configuration. This contraint does not apply if only ``Interpreter`` + configuration. This constraint does not apply if only ``Interpreter`` component is specified. Imported Targets @@ -136,6 +142,9 @@ This module will set the following variables in your project System has the Python development artifacts for Python embedding. ``Python_INCLUDE_DIRS`` The Python include directories. +``Python_LINK_OPTIONS`` + The Python link options. Some configurations require specific link options + for a correct build and execution. ``Python_LIBRARIES`` The Python libraries. ``Python_LIBRARY_DIRS`` @@ -155,7 +164,7 @@ This module will set the following variables in your project ``Python_NumPy_FOUND`` System has the NumPy. ``Python_NumPy_INCLUDE_DIRS`` - The NumPy include directries. + The NumPy include directories. ``Python_NumPy_VERSION`` The NumPy version. @@ -189,7 +198,7 @@ Hints * ``ON``: Corresponding flag is selected. * ``OFF``: Corresponding flag is not selected. - * ``ANY``: The two posibilties (``ON`` and ``OFF``) will be searched. + * ``ANY``: The two possibilities (``ON`` and ``OFF``) will be searched. From this 3-tuple, various ABIs will be searched starting from the most specialized to the most general. Moreover, ``debug`` versions will be @@ -326,7 +335,7 @@ setting the following variables: ``Python_LIBRARY`` The path to the library. It will be used to compute the - variables ``Python_LIBRARIES``, ``Python_LIBRAY_DIRS`` and + variables ``Python_LIBRARIES``, ``Python_LIBRARY_DIRS`` and ``Python_RUNTIME_LIBRARY_DIRS``. ``Python_INCLUDE_DIR`` @@ -347,7 +356,7 @@ setting the following variables: When an artifact is specified, all ``HINTS`` will be ignored and no search will be performed for this artifact. - If more than one artifact is specified, it is the user's responsability to + If more than one artifact is specified, it is the user's responsibility to ensure the consistency of the various artifacts. By default, this module supports multiple calls in different directories of a @@ -355,7 +364,7 @@ project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, ``CMake`` cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior -can be controled with the following variable: +can be controlled with the following variable: ``Python_ARTIFACTS_INTERACTIVE`` Selects the behavior of the module. This is a boolean variable: @@ -385,13 +394,39 @@ module suffix will include the ``Python_SOABI`` value, if any. #]=======================================================================] -set (_PYTHON_PREFIX Python) +cmake_policy(PUSH) +# numbers and boolean constants +cmake_policy (SET CMP0012 NEW) -if (DEFINED Python_FIND_VERSION) + +set (_PYTHON_PREFIX Python) +unset (_Python_REQUIRED_VERSION_MAJOR) +unset (_Python_REQUIRED_VERSIONS) + +if (Python_FIND_VERSION_RANGE) + # compute list of major versions + foreach (_Python_MAJOR IN ITEMS 3 2) + if (_Python_MAJOR VERSION_GREATER_EQUAL Python_FIND_VERSION_MIN_MAJOR + AND ((Python_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _Python_MAJOR VERSION_LESS_EQUAL Python_FIND_VERSION_MAX) + OR (Python_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND _Python_MAJOR VERSION_LESS Python_FIND_VERSION_MAX))) + list (APPEND _Python_REQUIRED_VERSIONS ${_Python_MAJOR}) + endif() + endforeach() + list (LENGTH _Python_REQUIRED_VERSIONS _Python_VERSION_COUNT) + if (_Python_VERSION_COUNT EQUAL 0) + unset (_Python_REQUIRED_VERSIONS) + elseif (_Python_VERSION_COUNT EQUAL 1) + set (_Python_REQUIRED_VERSION_MAJOR ${_Python_REQUIRED_VERSIONS}) + endif() +elseif (DEFINED Python_FIND_VERSION) set (_Python_REQUIRED_VERSION_MAJOR ${Python_FIND_VERSION_MAJOR}) +else() + set (_Python_REQUIRED_VERSIONS 3 2) +endif() +if (_Python_REQUIRED_VERSION_MAJOR) include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake) -else() +elseif (_Python_REQUIRED_VERSIONS) # iterate over versions in quiet and NOT required modes to avoid multiple # "Found" messages and prematurally failure. set (_Python_QUIETLY ${Python_FIND_QUIETLY}) @@ -399,7 +434,6 @@ else() set (Python_FIND_QUIETLY TRUE) set (Python_FIND_REQUIRED FALSE) - set (_Python_REQUIRED_VERSIONS 3 2) set (_Python_REQUIRED_VERSION_LAST 2) unset (_Python_INPUT_VARS) @@ -433,10 +467,21 @@ else() set (Python_FIND_REQUIRED ${_Python_REQUIRED}) if (Python_FIND_REQUIRED OR NOT Python_FIND_QUIETLY) # call again validation command to get "Found" or error message - find_package_handle_standard_args (Python HANDLE_COMPONENTS + find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE REQUIRED_VARS ${_Python_REQUIRED_VARS} VERSION_VAR Python_VERSION) endif() +else() + # supported versions not in the specified range. Call final check + if (NOT Python_FIND_COMPONENTS) + set (Python_FIND_COMPONENTS Interpreter) + set (Python_FIND_REQUIRED_Interpreter TRUE) + endif() + + include (${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE + VERSION_VAR Python_VERSION + REASON_FAILURE_MESSAGE "Version range specified \"${Python_FIND_VERSION_RANGE}\" does not include supported versions") endif() if (COMMAND __Python_add_library) @@ -446,3 +491,5 @@ if (COMMAND __Python_add_library) endif() unset (_PYTHON_PREFIX) + +cmake_policy(POP) diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 3732463d0..028ce082e 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -22,7 +22,7 @@ if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) message (FATAL_ERROR "FindPython: INTERNAL ERROR") endif() if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3") - set(_${_PYTHON_PREFIX}_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) + set(_${_PYTHON_PREFIX}_VERSIONS 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "2") set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) else() @@ -31,6 +31,7 @@ endif() get_property(_${_PYTHON_PREFIX}_CMAKE_ROLE GLOBAL PROPERTY CMAKE_ROLE) +include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake) # # helper commands @@ -452,11 +453,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (REMOVE_DUPLICATES _values) elseif (NAME STREQUAL "SOABI") # clean-up: remove prefix character and suffix - if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$") - set(_values "") - else() - string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") - endif() + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") endif() endif() endif() @@ -508,11 +505,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) endforeach() if (_values) # clean-up: remove prefix character and suffix - if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$") - set(_values "") - else() - string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") - endif() + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") endif() endif() else() @@ -682,12 +675,7 @@ function (_PYTHON_VALIDATE_INTERPRETER) return() endif() - cmake_parse_arguments (PARSE_ARGV 0 _PVI "EXACT;CHECK_EXISTS" "" "") - if (_PVI_UNPARSED_ARGUMENTS) - set (expected_version "${_PVI_UNPARSED_ARGUMENTS}") - else() - unset (expected_version) - endif() + cmake_parse_arguments (PARSE_ARGV 0 _PVI "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "") if (_PVI_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_EXECUTABLE}") # interpreter does not exist anymore @@ -718,50 +706,69 @@ function (_PYTHON_VALIDATE_INTERPRETER) endif() endif() - get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME) + if (_PVI_IN_RANGE OR _PVI_VERSION) + # retrieve full version + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))" + RESULT_VARIABLE result + OUTPUT_VARIABLE version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (result) + # interpreter is not usable + set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") + return() + endif() - if (expected_version) - if (NOT python_name STREQUAL "python${expected_version}${abi}${CMAKE_EXECUTABLE_SUFFIX}") - # compute number of components for version - string (REGEX REPLACE "[^.]" "" dots "${expected_version}") - # add one dot because there is one dot less than there are components + if (_PVI_VERSION) + # check against specified version + ## compute number of components for version + string (REGEX REPLACE "[^.]" "" dots "${_PVI_VERSION}") + ## add one dot because there is one dot less than there are components string (LENGTH "${dots}." count) if (count GREATER 3) set (count 3) endif() + set (version_regex "^[0-9]+") + if (count EQUAL 3) + string (APPEND version_regex "\\.[0-9]+\\.[0-9]+") + elseif (count EQUAL 2) + string (APPEND version_regex "\\.[0-9]+") + endif() + # extract needed range + string (REGEX MATCH "${version_regex}" version "${version}") - # executable found must have a specific version - execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c - "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:${count}]]))" - RESULT_VARIABLE result - OUTPUT_VARIABLE version - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if (result) - # interpreter is not usable - set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) + if (_PVI_EXACT AND NOT version VERSION_EQUAL _PVI_VERSION) + # interpreter has wrong version + set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") + return() else() - if (_PVI_EXACT AND NOT version VERSION_EQUAL expected_version) - # interpreter has wrong version + # check that version is OK + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}") + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${_PVI_VERSION}") + if (NOT major_version VERSION_EQUAL expected_major_version + OR NOT version VERSION_GREATER_EQUAL _PVI_VERSION) set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") - else() - # check that version is OK - string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}") - string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${expected_version}") - if (NOT major_version VERSION_EQUAL expected_major_version - OR NOT version VERSION_GREATER_EQUAL expected_version) - set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) - set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") - endif() + return() endif() endif() - if (NOT _${_PYTHON_PREFIX}_EXECUTABLE) + endif() + + if (_PVI_IN_RANGE) + # check if version is in the requested range + find_package_check_version ("${version}" in_range HANDLE_VERSION_RANGE) + if (NOT in_range) + # interpreter has invalid version + set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") return() endif() endif() else() + get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME) if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}") # executable found do not have version in name # ensure major version is OK @@ -813,15 +820,7 @@ function (_PYTHON_VALIDATE_COMPILER) return() endif() - cmake_parse_arguments (PARSE_ARGV 0 _PVC "EXACT;CHECK_EXISTS" "" "") - if (_PVC_UNPARSED_ARGUMENTS) - set (major_version FALSE) - set (expected_version "${_PVC_UNPARSED_ARGUMENTS}") - else() - set (major_version TRUE) - set (expected_version "${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}") - set (_PVC_EXACT TRUE) - endif() + cmake_parse_arguments (PARSE_ARGV 0 _PVC "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "") if (_PVC_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_COMPILER}") # Compiler does not exist anymore @@ -834,19 +833,7 @@ function (_PYTHON_VALIDATE_COMPILER) # retrieve python environment version from compiler set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") - if (major_version) - # check only major version - file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write(str(sys.version_info[0]))") - else() - # compute number of components for version - string (REGEX REPLACE "[^.]" "" dots "${expected_version}") - # add one dot because there is one dot less than there are components - string (LENGTH "${dots}." count) - if (count GREATER 3) - set (count 3) - endif() - file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:${count}]]))\n") - endif() + file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n") execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_COMPILER}" ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} /target:exe /embed "${working_dir}/version.py" @@ -866,11 +853,64 @@ function (_PYTHON_VALIDATE_COMPILER) # compiler is not usable set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Cannot use the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") - elseif ((_PVC_EXACT AND NOT version VERSION_EQUAL expected_version) - OR NOT version VERSION_GREATER_EQUAL expected_version) - # Compiler has wrong version - set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) - set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") + return() + endif() + + if (_PVC_VERSION OR _PVC_IN_RANGE) + if (_PVC_VERSION) + # check against specified version + ## compute number of components for version + string (REGEX REPLACE "[^.]" "" dots "${_PVC_VERSION}") + ## add one dot because there is one dot less than there are components + string (LENGTH "${dots}." count) + if (count GREATER 3) + set (count 3) + endif() + set (version_regex "^[0-9]+") + if (count EQUAL 3) + string (APPEND version_regex "\\.[0-9]+\\.[0-9]+") + elseif (count EQUAL 2) + string (APPEND version_regex "\\.[0-9]+") + endif() + # extract needed range + string (REGEX MATCH "${version_regex}" version "${version}") + + if (_PVC_EXACT AND NOT version VERSION_EQUAL _PVC_VERSION) + # interpreter has wrong version + set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") + return() + else() + # check that version is OK + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}") + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${_PVC_VERSION}") + if (NOT major_version VERSION_EQUAL expected_major_version + OR NOT version VERSION_GREATER_EQUAL _PVC_VERSION) + set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") + return() + endif() + endif() + endif() + + if (_PVC_IN_RANGE) + # check if version is in the requested range + find_package_check_version ("${version}" in_range HANDLE_VERSION_RANGE) + if (NOT in_range) + # interpreter has invalid version + set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") + return() + endif() + endif() + else() + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}") + if (NOT major_version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) + # Compiler has wrong major version + set (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE "Wrong major version for the compiler \"${_${_PYTHON_PREFIX}_COMPILER}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_COMPILER PROPERTY VALUE "${_PYTHON_PREFIX}_COMPILER-NOTFOUND") + return() + endif() endif() endfunction() @@ -881,12 +921,7 @@ function (_PYTHON_VALIDATE_LIBRARY) return() endif() - cmake_parse_arguments (PARSE_ARGV 0 _PVL "EXACT;CHECK_EXISTS" "" "") - if (_PVL_UNPARSED_ARGUMENTS) - set (expected_version ${_PVL_UNPARSED_ARGUMENTS}) - else() - unset (expected_version) - endif() + cmake_parse_arguments (PARSE_ARGV 0 _PVL "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "") if (_PVL_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}") # library does not exist anymore @@ -907,13 +942,25 @@ function (_PYTHON_VALIDATE_LIBRARY) set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong ABI for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") else() - if (expected_version) - # library have only major.minor information - string (REGEX MATCH "[0-9](\\.[0-9]+)?" version "${expected_version}") - if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL version) OR (lib_VERSION VERSION_LESS version)) - # library has wrong version - set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE) - set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") + if (_PVL_VERSION OR _PVL_IN_RANGE) + if (_PVL_VERSION) + # library have only major.minor information + string (REGEX MATCH "[0-9](\\.[0-9]+)?" version "${_PVL_VERSION}") + if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL version) OR (lib_VERSION VERSION_LESS version)) + # library has wrong version + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") + endif() + endif() + + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND _PVL_IN_RANGE) + # check if library version is in the requested range + find_package_check_version ("${lib_VERSION}" in_range HANDLE_VERSION_RANGE) + if (NOT in_range) + # library has wrong version + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") + endif() endif() else() if (NOT lib_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) @@ -940,12 +987,7 @@ function (_PYTHON_VALIDATE_INCLUDE_DIR) return() endif() - cmake_parse_arguments (PARSE_ARGV 0 _PVID "EXACT;CHECK_EXISTS" "" "") - if (_PVID_UNPARSED_ARGUMENTS) - set (expected_version ${_PVID_UNPARSED_ARGUMENTS}) - else() - unset (expected_version) - endif() + cmake_parse_arguments (PARSE_ARGV 0 _PVID "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "") if (_PVID_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}") # include file does not exist anymore @@ -962,11 +1004,23 @@ function (_PYTHON_VALIDATE_INCLUDE_DIR) set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong ABI for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") else() - if (expected_version) - if ((_PVID_EXACT AND NOT inc_VERSION VERSION_EQUAL expected_version) OR (inc_VERSION VERSION_LESS expected_version)) - # include dir has wrong version - set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE) - set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") + if (_PVID_VERSION OR _PVID_IN_RANGE) + if (_PVID_VERSION) + if ((_PVID_EXACT AND NOT inc_VERSION VERSION_EQUAL expected_version) OR (inc_VERSION VERSION_LESS expected_version)) + # include dir has wrong version + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") + endif() + endif() + + if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND PVID_IN_RANGE) + # check if include dir is in the request range + find_package_check_version ("${inc_VERSION}" in_range HANDLE_VERSION_RANGE) + if (NOT in_range) + # include dir has wrong version + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") + endif() endif() else() if (NOT inc_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) @@ -1028,13 +1082,27 @@ function (_PYTHON_SET_DEVELOPMENT_MODULE_FOUND module) endfunction() -# If major version is specified, it must be the same as internal major version -if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR - AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) - _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong major version specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}\", but expected major version is \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"") +if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + # range must include internal major version + if (${_PYTHON_PREFIX}_FIND_VERSION_MIN_MAJOR VERSION_GREATER _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR + OR ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" + AND ${_PYTHON_PREFIX}_FIND_VERSION_MAX VERSION_LESS _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) + OR (${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" + AND ${_PYTHON_PREFIX}_FIND_VERSION_MAX VERSION_LESS_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR))) + _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong version range specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_RANGE}\", but expected version range must include major version \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"") - cmake_policy(POP) - return() + cmake_policy(POP) + return() + endif() +else() + if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR + AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) + # If major version is specified, it must be the same as internal major version + _python_display_failure ("Could NOT find ${_PYTHON_PREFIX}: Wrong major version specified is \"${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}\", but expected major version is \"${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}\"") + + cmake_policy(POP) + return() + endif() endif() @@ -1078,18 +1146,32 @@ list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSIONS}) unset (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT) -if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT) - if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) - set (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT "EXACT") - set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}) - else() - unset (_${_PYTHON_PREFIX}_FIND_VERSIONS) - # add all compatible versions - foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS) - if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL "${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}") - list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION}) - endif() - endforeach() +if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + unset (_${_PYTHON_PREFIX}_FIND_VERSIONS) + foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS) + if ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" + AND _${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION_MIN) + AND ((${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" + AND _${_PYTHON_PREFIX}_VERSION VERSION_LESS_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION_MAX) + OR (${_PYTHON_PREFIX}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" + AND _${_PYTHON_PREFIX}_VERSION VERSION_LESS ${_PYTHON_PREFIX}_FIND_VERSION_MAX))) + list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION}) + endif() + endforeach() +else() + if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1) + if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) + set (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT "EXACT") + set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}) + else() + unset (_${_PYTHON_PREFIX}_FIND_VERSIONS) + # add all compatible versions + foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS) + if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL "${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}") + list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION}) + endif() + endforeach() + endif() endif() endif() @@ -1308,14 +1390,26 @@ function (_PYTHON_CHECK_DEVELOPMENT_SIGNATURE module) string (MD5 signature "${signature}") if (signature STREQUAL _${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE) if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) - _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} - ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT} - CHECK_EXISTS) + if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) + _python_validate_library (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + _python_validate_library (IN_RANGE CHECK_EXISTS) + elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION) + _python_validate_library (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) + else() + _python_validate_library (CHECK_EXISTS) + endif() endif() if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) - _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} - ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT} - CHECK_EXISTS) + if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) + _python_validate_include_dir (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + _python_validate_include_dir (IN_RANGE CHECK_EXISTS) + elseif (${_PYTHON_PREFIX}_FIND_VERSION) + _python_validate_include_dir (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) + else() + _python_validate_include_dir (CHECK_EXISTS) + endif() endif() else() if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) @@ -1392,9 +1486,13 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE) # check version validity if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + _python_validate_interpreter (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + _python_validate_interpreter (IN_RANGE CHECK_EXISTS) + elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION) + _python_validate_interpreter (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) else() - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) + _python_validate_interpreter (CHECK_EXISTS) endif() else() unset (_${_PYTHON_PREFIX}_EXECUTABLE CACHE) @@ -1418,6 +1516,13 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # Registry Paths _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) + set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE) + elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION) + list (APPEND VERSION ${${_PYTHON_PREFIX}_FIND_VERSION}) + endif() + while (TRUE) # Virtual environments handling if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") @@ -1432,7 +1537,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1453,7 +1558,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1468,7 +1573,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1482,7 +1587,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1491,7 +1596,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES ${_${_PYTHON_PREFIX}_NAMES} NAMES_PER_DIR PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1504,7 +1609,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1517,7 +1622,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1527,6 +1632,11 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endwhile() else() # look-up for various versions and locations + set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS EXACT) + if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE) + endif() + foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX INTERPRETER) _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INTERPRETER) @@ -1546,7 +1656,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1581,7 +1691,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_SYSTEM_PATH) endif() - _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1594,7 +1704,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1607,7 +1717,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) - _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1632,7 +1742,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_DEFAULT_PATH) endif() - _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_interpreter (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1833,9 +1943,13 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (__${_PYTHON_PREFIX}_COMPILER_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_COMPILER_SIGNATURE) # check version validity if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + _python_validate_compiler (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) + elseif (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + _python_validate_compiler (IN_RANGE CHECK_EXISTS) + elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION) + _python_validate_compiler (VERSION ${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) else() - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) + _python_validate_compiler (CHECK_EXISTS) endif() else() unset (_${_PYTHON_PREFIX}_COMPILER CACHE) @@ -1870,6 +1984,13 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) IMPLEMENTATIONS IronPython VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) + set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE) + elseif (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION) + list (APPEND VERSION ${${_PYTHON_PREFIX}_FIND_VERSION}) + endif() + while (TRUE) # Apple frameworks handling if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") @@ -1883,7 +2004,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1898,7 +2019,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1912,7 +2033,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1922,7 +2043,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} NAMES_PER_DIR PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1935,7 +2056,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1948,6 +2069,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -1957,6 +2079,11 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endwhile() else() # try using root dir and registry + set (_${_PYTHON_PREFIX}_VALIDATE_OPTIONS EXACT) + if (${_PYTHON_PREFIX}_FIND_VERSION_RANGE) + list (APPEND _${_PYTHON_PREFIX}_VALIDATE_OPTIONS IN_RANGE) + endif() + foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES IMPLEMENTATIONS IronPython @@ -1987,7 +2114,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -2002,7 +2129,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -2016,7 +2143,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -2029,7 +2156,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -2042,7 +2169,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + _python_validate_compiler (VERSION ${_${_PYTHON_PREFIX}_VERSION} ${_${_PYTHON_PREFIX}_VALIDATE_OPTIONS}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() @@ -2062,6 +2189,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) + _python_validate_compiler () endif() endif() @@ -2762,7 +2890,6 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS if (_${_PYTHON_PREFIX}_INCLUDE_DIR) # retrieve version from header file _python_get_version (INCLUDE PREFIX _${_PYTHON_PREFIX}_INC_) - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) if ("${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL _${_PYTHON_PREFIX}_VERSION) @@ -2863,6 +2990,28 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS ${_PYTHON_PREFIX}_PyPy_VERSION "${${_PYTHON_PREFIX}_PyPy_VERSION}") endif() + unset(${_PYTHON_PREFIX}_LINK_OPTIONS) + if (${_PYTHON_PREFIX}_Development.Embed_FOUND AND APPLE + AND ${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$") + # rpath must be specified if python is part of a framework + unset(_${_PYTHON_PREFIX}_is_prefix) + foreach (_${_PYTHON_PREFIX}_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + foreach (_${_PYTHON_PREFIX}_framework IN LISTS _${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_implementation}_FRAMEWORKS) + if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "^${_${_PYTHON_PREFIX}_framework}") + get_filename_component (_${_PYTHON_PREFIX}_framework "${_${_PYTHON_PREFIX}_framework}" DIRECTORY) + set (${_PYTHON_PREFIX}_LINK_OPTIONS "LINKER:-rpath,${_${_PYTHON_PREFIX}_framework}") + break() + endif() + endforeach() + if (_${_PYTHON_PREFIX}_is_prefix) + break() + endif() + endforeach() + unset(_${_PYTHON_PREFIX}_implementation) + unset(_${_PYTHON_PREFIX}_framework) + unset(_${_PYTHON_PREFIX}_is_prefix) + endif() + if (NOT DEFINED ${_PYTHON_PREFIX}_SOABI) _python_get_config_var (${_PYTHON_PREFIX}_SOABI SOABI) endif() @@ -2988,10 +3137,10 @@ foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development endif() endforeach() -include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args (${_PYTHON_PREFIX} REQUIRED_VARS ${_${_PYTHON_PREFIX}_REQUIRED_VARS} VERSION_VAR ${_PYTHON_PREFIX}_VERSION + HANDLE_VERSION_RANGE HANDLE_COMPONENTS REASON_FAILURE_MESSAGE "${_${_PYTHON_PREFIX}_REASON_FAILURE}") @@ -3075,6 +3224,11 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") PROPERTY INTERFACE_LINK_LIBRARIES ${_${_PYTHON_PREFIX}_LINK_LIBRARIES}) endif() endif() + + if (${_PYTHON_PREFIX}_LINK_OPTIONS + AND _${_PYTHON_PREFIX}_LIBRARY_TYPE STREQUAL "SHARED") + set_property (TARGET ${__name} PROPERTY INTERFACE_LINK_OPTIONS "${${_PYTHON_PREFIX}_LINK_OPTIONS}") + endif() endmacro() if (${_PYTHON_PREFIX}_Development.Embed_FOUND) diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index 84c0c73b6..9cd22e174 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -5,9 +5,15 @@ FindPython2 ----------- +.. versionadded:: 3.12 + Find Python 2 interpreter, compiler and development environment (include directories and libraries). +When a version is requested, it can be specified as a simple value or as a +range. For a detailed description of version range usage and capabilities, +refer to the :command:`find_package` command. + The following components are supported: * ``Interpreter``: search for Python 2 interpreter @@ -45,7 +51,7 @@ for you. If components ``Interpreter`` and ``Development`` (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by ``CMake`` - configuration. This contraint does not apply if only ``Interpreter`` + configuration. This constraint does not apply if only ``Interpreter`` component is specified. Imported Targets @@ -128,6 +134,9 @@ This module will set the following variables in your project System has the Python 2 development artifacts for Python embedding. ``Python2_INCLUDE_DIRS`` The Python 2 include directories. +``Python2_LINK_OPTIONS`` + The Python 2 link options. Some configurations require specific link options + for a correct build and execution. ``Python2_LIBRARIES`` The Python 2 libraries. ``Python2_LIBRARY_DIRS`` @@ -147,7 +156,7 @@ This module will set the following variables in your project ``Python2_NumPy_FOUND`` System has the NumPy. ``Python2_NumPy_INCLUDE_DIRS`` - The NumPy include directries. + The NumPy include directories. ``Python2_NumPy_VERSION`` The NumPy version. @@ -273,7 +282,7 @@ setting the following variables: ``Python2_LIBRARY`` The path to the library. It will be used to compute the - variables ``Python2_LIBRARIES``, ``Python2_LIBRAY_DIRS`` and + variables ``Python2_LIBRARIES``, ``Python2_LIBRARY_DIRS`` and ``Python2_RUNTIME_LIBRARY_DIRS``. ``Python2_INCLUDE_DIR`` @@ -294,7 +303,7 @@ setting the following variables: When an artifact is specified, all ``HINTS`` will be ignored and no search will be performed for this artifact. - If more than one artifact is specified, it is the user's responsability to + If more than one artifact is specified, it is the user's responsibility to ensure the consistency of the various artifacts. By default, this module supports multiple calls in different directories of a @@ -302,7 +311,7 @@ project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, ``CMake`` cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior -can be controled with the following variable: +can be controlled with the following variable: ``Python2_ARTIFACTS_INTERACTIVE`` Selects the behavior of the module. This is a boolean variable: diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index f142c07ee..c79d482dd 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -5,9 +5,15 @@ FindPython3 ----------- +.. versionadded:: 3.12 + Find Python 3 interpreter, compiler and development environment (include directories and libraries). +When a version is requested, it can be specified as a simple value or as a +range. For a detailed description of version range usage and capabilities, +refer to the :command:`find_package` command. + The following components are supported: * ``Interpreter``: search for Python 3 interpreter @@ -45,7 +51,7 @@ for you. If components ``Interpreter`` and ``Development`` (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by ``CMake`` - configuration. This contraint does not apply if only ``Interpreter`` + configuration. This constraint does not apply if only ``Interpreter`` component is specified. Imported Targets @@ -137,6 +143,9 @@ This module will set the following variables in your project System has the Python 3 development artifacts for Python embedding. ``Python3_INCLUDE_DIRS`` The Python 3 include directories. +``Python3_LINK_OPTIONS`` + The Python 3 link options. Some configurations require specific link options + for a correct build and execution. ``Python3_LIBRARIES`` The Python 3 libraries. ``Python3_LIBRARY_DIRS`` @@ -156,7 +165,7 @@ This module will set the following variables in your project ``Python3_NumPy_FOUND`` System has the NumPy. ``Python3_NumPy_INCLUDE_DIRS`` - The NumPy include directries. + The NumPy include directories. ``Python3_NumPy_VERSION`` The NumPy version. @@ -186,7 +195,7 @@ Hints * ``ON``: Corresponding flag is selected. * ``OFF``: Corresponding flag is not selected. - * ``ANY``: The two posibilties (``ON`` and ``OFF``) will be searched. + * ``ANY``: The two possibilities (``ON`` and ``OFF``) will be searched. From this 3-tuple, various ABIs will be searched starting from the most specialized to the most general. Moreover, ``debug`` versions will be @@ -323,7 +332,7 @@ setting the following variables: ``Python3_LIBRARY`` The path to the library. It will be used to compute the - variables ``Python3_LIBRARIES``, ``Python3_LIBRAY_DIRS`` and + variables ``Python3_LIBRARIES``, ``Python3_LIBRARY_DIRS`` and ``Python3_RUNTIME_LIBRARY_DIRS``. ``Python3_INCLUDE_DIR`` @@ -344,7 +353,7 @@ setting the following variables: When an artifact is specified, all ``HINTS`` will be ignored and no search will be performed for this artifact. - If more than one artifact is specified, it is the user's responsability to + If more than one artifact is specified, it is the user's responsibility to ensure the consistency of the various artifacts. By default, this module supports multiple calls in different directories of a @@ -352,7 +361,7 @@ project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, ``CMake`` cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior -can be controled with the following variable: +can be controlled with the following variable: ``Python3_ARTIFACTS_INTERACTIVE`` Selects the behavior of the module. This is a boolean variable: diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake index 1e01a99cb..efe0f1190 100644 --- a/Modules/FindPythonInterp.cmake +++ b/Modules/FindPythonInterp.cmake @@ -54,7 +54,7 @@ unset(_Python_NAMES) set(_PYTHON1_VERSIONS 1.6 1.5) set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) -set(_PYTHON3_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) +set(_PYTHON3_VERSIONS 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) if(PythonInterp_FIND_VERSION) if(PythonInterp_FIND_VERSION_COUNT GREATER 1) diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index d3ec7beec..396f0d2ed 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -79,7 +79,7 @@ set(CMAKE_FIND_FRAMEWORK LAST) set(_PYTHON1_VERSIONS 1.6 1.5) set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) -set(_PYTHON3_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) +set(_PYTHON3_VERSIONS 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) if(PythonLibs_FIND_VERSION) if(PythonLibs_FIND_VERSION_COUNT GREATER 1) diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake index 2e3da746b..ec0f4536c 100644 --- a/Modules/FindQt4.cmake +++ b/Modules/FindQt4.cmake @@ -147,7 +147,7 @@ more-manual way. Several macros are available to add targets for such uses. in: directories sources ts_files options: flags to pass to lupdate, such as -extensions to specify extensions for a directory scan. - generates commands to create .ts (vie lupdate) and .qm + generates commands to create .ts (via lupdate) and .qm (via lrelease) - files from directories and/or sources. The ts files are created and/or updated in the source tree (unless given with full paths). The qm files are generated in the build tree. diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index a0cdf3b03..d12f8255d 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -401,6 +401,7 @@ if(Ruby_VERSION_MAJOR) set(_Ruby_VERSION_SHORT "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}") set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}") set(_Ruby_NODOT_VERSION "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}") + set(_Ruby_NODOT_VERSION_ZERO_PATCH "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}0") endif() # FIXME: Currently we require both the interpreter and development components to be found @@ -433,22 +434,27 @@ endif() set(_Ruby_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_Ruby_VERSION_SHORT} ruby${_Ruby_VERSION_SHORT_NODOT} ruby-${_Ruby_VERSION_SHORT} ruby-${Ruby_VERSION}) if(WIN32) + set(_Ruby_POSSIBLE_MSVC_RUNTIMES "msvcrt;vcruntime140;vcruntime140_1") if(MSVC_TOOLSET_VERSION) - set(_Ruby_MSVC_RUNTIME "${MSVC_TOOLSET_VERSION}") + list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr${MSVC_TOOLSET_VERSION}") else() - set(_Ruby_MSVC_RUNTIME "") + list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr") endif() + set(_Ruby_POSSIBLE_VERSION_SUFFICES "${_Ruby_NODOT_VERSION};${_Ruby_NODOT_VERSION_ZERO_PATCH}") + set(_Ruby_ARCH_PREFIX "") if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(_Ruby_ARCH_PREFIX "x64-") endif() - list(APPEND _Ruby_POSSIBLE_LIB_NAMES - "${_Ruby_ARCH_PREFIX}msvcr${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_NODOT_VERSION}" - "${_Ruby_ARCH_PREFIX}msvcr${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_NODOT_VERSION}-static" - "${_Ruby_ARCH_PREFIX}msvcrt-ruby${_Ruby_NODOT_VERSION}" - "${_Ruby_ARCH_PREFIX}msvcrt-ruby${_Ruby_NODOT_VERSION}-static" ) + foreach(_Ruby_MSVC_RUNTIME ${_Ruby_POSSIBLE_MSVC_RUNTIMES}) + foreach(_Ruby_VERSION_SUFFIX ${_Ruby_POSSIBLE_VERSION_SUFFICES}) + list(APPEND _Ruby_POSSIBLE_LIB_NAMES + "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}" + "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}-static") + endforeach() + endforeach() endif() find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${Ruby_POSSIBLE_LIB_DIR} ) diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake index 8d793a975..59eddbbc9 100644 --- a/Modules/FindSDL.cmake +++ b/Modules/FindSDL.cmake @@ -5,24 +5,54 @@ FindSDL ------- -Locate SDL library +Locate the SDL library -This module defines -:: +Imported targets +^^^^^^^^^^^^^^^^ - SDL_LIBRARY, the name of the library to link against - SDL_FOUND, if false, do not try to link to SDL - SDL_INCLUDE_DIR, where to find SDL.h - SDL_VERSION_STRING, human-readable string containing the version of SDL +This module defines the following :prop_tgt:`IMPORTED` target: +``SDL::SDL`` + The SDL library, if found +Result variables +^^^^^^^^^^^^^^^^ -This module responds to the flag: +This module will set the following variables in your project: + +``SDL_INCLUDE_DIRS`` + where to find SDL.h +``SDL_LIBRARIES`` + the name of the library to link against +``SDL_FOUND`` + if false, do not try to link to SDL +``SDL_VERSION`` + the human-readable string containing the version of SDL if found +``SDL_VERSION_MAJOR`` + SDL major version +``SDL_VERSION_MINOR`` + SDL minor version +``SDL_VERSION_PATCH`` + SDL patch version + +Cache variables +^^^^^^^^^^^^^^^ + +These variables may optionally be set to help this module find the correct files: -:: +``SDL_INCLUDE_DIR`` + where to find SDL.h +``SDL_LIBRARY`` + the name of the library to link against + + +Variables for locating SDL +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This module responds to the flag: - SDL_BUILDING_LIBRARY +``SDL_BUILDING_LIBRARY`` If this is defined, then no SDL_main will be linked in because only applications need main(). Otherwise, it is assumed you are building an application and this @@ -30,6 +60,15 @@ This module responds to the flag: as part of the returned SDL_LIBRARY variable. +Obsolete variables +^^^^^^^^^^^^^^^^^^ + +These variables are obsolete and provided for backwards compatibility: + +``SDL_VERSION_STRING`` + the human-readable string containing the version of SDL if found. + Identical to SDL_VERSION + Don't forget to include SDLmain.h and SDLmain.m your project for the OS X framework based version. (Other versions link to -lSDLmain which @@ -52,15 +91,6 @@ does not get created. $SDLDIR is an environment variable that would correspond to the ./configure --prefix=$SDLDIR used in building SDL. l.e.galup 9-20-02 -Modified by Eric Wing. Added code to assist with automated building -by using environmental variables and providing a more -controlled/consistent search behavior. Added new modifications to -recognize OS X frameworks and additional Unix paths (FreeBSD, etc). -Also corrected the header search path to follow "proper" SDL -guidelines. Added a search for SDLmain which is needed by some -platforms. Added a search for threads which is needed by some -platforms. Added needed compile switches for MinGW. - On OSX, this will prefer the Framework version (if found) over others. People will have to manually change the cache values of SDL_LIBRARY to override this selection or set the CMake environment @@ -174,13 +204,11 @@ if(SDL_INCLUDE_DIR AND EXISTS "${SDL_INCLUDE_DIR}/SDL_version.h") string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}") - set(SDL_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH}) unset(SDL_VERSION_MAJOR_LINE) unset(SDL_VERSION_MINOR_LINE) unset(SDL_VERSION_PATCH_LINE) - unset(SDL_VERSION_MAJOR) - unset(SDL_VERSION_MINOR) - unset(SDL_VERSION_PATCH) + set(SDL_VERSION ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH}) + set(SDL_VERSION_STRING ${SDL_VERSION}) endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) @@ -188,3 +216,14 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR VERSION_VAR SDL_VERSION_STRING) + +if(SDL_FOUND) + set(SDL_LIBRARIES ${SDL_LIBRARY}) + set(SDL_INCLUDE_DIRS ${SDL_INCLUDE_DIR}) + if(NOT TARGET SDL::SDL) + add_library(SDL::SDL INTERFACE IMPORTED) + set_target_properties(SDL::SDL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${SDL_LIBRARY}") + endif() +endif() diff --git a/Modules/FindSQLite3.cmake b/Modules/FindSQLite3.cmake index 374d7af6c..88c7dd209 100644 --- a/Modules/FindSQLite3.cmake +++ b/Modules/FindSQLite3.cmake @@ -5,6 +5,8 @@ FindSQLite3 ----------- +.. versionadded:: 3.14 + Find the SQLite libraries, v3 IMPORTED targets diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake index 2fded4985..87a389463 100644 --- a/Modules/FindSWIG.cmake +++ b/Modules/FindSWIG.cmake @@ -7,11 +7,16 @@ FindSWIG Find the Simplified Wrapper and Interface Generator (SWIG_) executable. - This module finds an installed SWIG and determines its version. If a -``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to ``find_package``, -it will also determine supported target languages. The module sents the -following variables: +``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to the +:command:`find_package` command, it will also determine supported target +languages. + +When a version is requested, it can be specified as a simple value or as a +range. For a detailed description of version range usage and capabilities, +refer to the :command:`find_package` command. + +The module defines the following variables: ``SWIG_FOUND`` Whether SWIG and any required components were found on the system. @@ -50,7 +55,35 @@ optional Fortran support: #]=======================================================================] -find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig) +# compute list of possible names +unset (_SWIG_NAMES) +if (SWIG_FIND_VERSION_RANGE) + foreach (_SWIG_MAJOR IN ITEMS 4 3 2) + if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MIN_MAJOR + AND ((SWIG_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _SWIG_MAJOR VERSION_LESS_EQUAL SWIG_FIND_VERSION_MAX) + OR (SWIG_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND _SWIG_MAJOR VERSION_LESS SWIG_FIND_VERSION_MAX))) + list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0) + endif() + endforeach() +elseif(SWIG_FIND_VERSION) + if (SWIG_FIND_VERSION_EXACT) + set(_SWIG_NAMES swig${SWIG_FIND_VERSION_MAJOR}.0) + else() + foreach (_SWIG_MAJOR IN ITEMS 4 3 2) + if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MAJOR) + list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0) + endif() + endforeach() + endif() +else() + set (_SWIG_NAMES swig4.0 swig3.0 swig2.0) +endif() +if (NOT _SWIG_NAMES) + # try to find any version + set (_SWIG_NAMES swig4.0 swig3.0 swig2.0) +endif() + +find_program(SWIG_EXECUTABLE NAMES ${_SWIG_NAMES} swig) if(SWIG_EXECUTABLE) execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib @@ -105,6 +138,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args( SWIG HANDLE_COMPONENTS REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR - VERSION_VAR SWIG_VERSION) + VERSION_VAR SWIG_VERSION + HANDLE_VERSION_RANGE) mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE) diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake index 00a3a415a..3b74c94f0 100644 --- a/Modules/FindTIFF.cmake +++ b/Modules/FindTIFF.cmake @@ -5,7 +5,14 @@ FindTIFF -------- -Find the TIFF library (``libtiff``). +Find the TIFF library (``libtiff``, https://libtiff.gitlab.io/libtiff/). + +Optional COMPONENTS +^^^^^^^^^^^^^^^^^^^ + +This module supports the optional component `CXX`, for use with the COMPONENTS +argument of the :command:`find_package` command. This component has an associated +imported target, as described below. Imported targets ^^^^^^^^^^^^^^^^ @@ -15,6 +22,11 @@ This module defines the following :prop_tgt:`IMPORTED` targets: ``TIFF::TIFF`` The TIFF library, if found. +``TIFF::CXX`` + The C++ wrapper libtiffxx, if requested by the `COMPONENTS CXX` option, + if the compiler is not MSVC (which includes the C++ wrapper in libtiff), + and if found. + Result variables ^^^^^^^^^^^^^^^^ @@ -36,10 +48,19 @@ The following cache variables may also be set: ``TIFF_INCLUDE_DIR`` the directory containing the TIFF headers -``TIFF_LIBRARY`` - the path to the TIFF library +``TIFF_LIBRARY_RELEASE`` + the path to the TIFF library for release configurations +``TIFF_LIBRARY_DEBUG`` + the path to the TIFF library for debug configurations +``TIFFXX_LIBRARY_RELEASE`` + the path to the TIFFXX library for release configurations +``TIFFXX_LIBRARY_DEBUG`` + the path to the TIFFXX library for debug configurations #]=======================================================================] +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) + find_path(TIFF_INCLUDE_DIR tiff.h) set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3) @@ -54,8 +75,6 @@ if(NOT TIFF_LIBRARY) select_library_configurations(TIFF) mark_as_advanced(TIFF_LIBRARY_RELEASE TIFF_LIBRARY_DEBUG) endif() -unset(TIFF_NAMES) -unset(TIFF_NAMES_DEBUG) if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str @@ -66,13 +85,46 @@ if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") unset(tiff_version_str) endif() +foreach(_comp IN LISTS TIFF_FIND_COMPONENTS) + if(_comp STREQUAL "CXX") + if(MSVC) + # C++ bindings are built into the main tiff library. + set(TIFF_CXX_FOUND 1) + else() + foreach(name ${TIFF_NAMES}) + list(APPEND TIFFXX_NAMES "${name}xx") + list(APPEND TIFFXX_NAMES_DEBUG "${name}xxd") + endforeach() + find_library(TIFFXX_LIBRARY_RELEASE NAMES ${TIFFXX_NAMES}) + find_library(TIFFXX_LIBRARY_DEBUG NAMES ${TIFFXX_NAMES_DEBUG}) + include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + select_library_configurations(TIFFXX) + mark_as_advanced(TIFFXX_LIBRARY_RELEASE TIFFXX_LIBRARY_DEBUG) + unset(TIFFXX_NAMES) + unset(TIFFXX_NAMES_DEBUG) + if(TIFFXX_LIBRARY) + set(TIFF_CXX_FOUND 1) + endif() + endif() + endif() +endforeach() +unset(_comp) + +unset(TIFF_NAMES) +unset(TIFF_NAMES_DEBUG) + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF + HANDLE_COMPONENTS REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR VERSION_VAR TIFF_VERSION_STRING) if(TIFF_FOUND) set(TIFF_LIBRARIES ${TIFF_LIBRARY}) + if("CXX" IN_LIST TIFF_FIND_COMPONENTS AND NOT MSVC) + list(APPEND TIFF_LIBRARIES ${TIFFXX_LIBRARY}) + endif() + set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}") if(NOT TARGET TIFF::TIFF) @@ -101,6 +153,41 @@ if(TIFF_FOUND) IMPORTED_LOCATION_DEBUG "${TIFF_LIBRARY_DEBUG}") endif() endif() + + if(NOT TARGET TIFF::CXX) + if(MSVC) + add_library(TIFF::CXX INTERFACE IMPORTED) + set_property(TARGET TIFF::CXX PROPERTY INTERFACE_LINK_LIBRARIES TIFF::TIFF) + else() + add_library(TIFF::CXX UNKNOWN IMPORTED) + set_property(TARGET TIFF::CXX PROPERTY INTERFACE_LINK_LIBRARIES TIFF::TIFF) + if(TIFF_INCLUDE_DIRS) + set_target_properties(TIFF::CXX PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}") + endif() + if(EXISTS "${TIFFXX_LIBRARY}") + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${TIFFXX_LIBRARY}") + endif() + if(EXISTS "${TIFFXX_LIBRARY_RELEASE}") + set_property(TARGET TIFF::CXX APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" + IMPORTED_LOCATION_RELEASE "${TIFFXX_LIBRARY_RELEASE}") + endif() + if(EXISTS "${TIFFXX_LIBRARY_DEBUG}") + set_property(TARGET TIFF::CXX APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" + IMPORTED_LOCATION_DEBUG "${TIFFXX_LIBRARY_DEBUG}") + endif() + endif() + endif() + endif() -mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY) +mark_as_advanced(TIFF_INCLUDE_DIR) +cmake_policy(POP) diff --git a/Modules/FindTclsh.cmake b/Modules/FindTclsh.cmake index 5555d5960..594d0ec81 100644 --- a/Modules/FindTclsh.cmake +++ b/Modules/FindTclsh.cmake @@ -15,15 +15,8 @@ library is. This code sets the following variables: TCLSH_FOUND = TRUE if tclsh has been found TCL_TCLSH = the path to the tclsh executable - -In cygwin, look for the cygwin version first. Don't look for it later -to avoid finding the cygwin version on a Win32 build. #]=======================================================================] -if(CYGWIN) - find_program(TCL_TCLSH NAMES cygtclsh83 cygtclsh80) -endif() - get_filename_component(TK_WISH_PATH "${TK_WISH}" PATH) get_filename_component(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH) string(REGEX REPLACE diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index ee498670f..e3e6591a3 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -66,7 +66,7 @@ endif() set(PTHREAD_C_CXX_TEST_SOURCE [====[ #include <pthread.h> -void* test_func(void* data) +static void* test_func(void* data) { return data; } diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 4b999b62a..0ec60133c 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -5,6 +5,8 @@ FindVulkan ---------- +.. versionadded:: 3.7 + Find Vulkan, which is a low-overhead, cross-platform 3D graphics and computing API. @@ -14,6 +16,9 @@ IMPORTED Targets This module defines :prop_tgt:`IMPORTED` target ``Vulkan::Vulkan``, if Vulkan has been found. +This module defines :prop_tgt:`IMPORTED` target ``Vulkan::glslc``, if +Vulkan and the GLSLC SPIR-V compiler has been found. + Result Variables ^^^^^^^^^^^^^^^^ @@ -23,10 +28,11 @@ This module defines the following variables:: Vulkan_INCLUDE_DIRS - include directories for Vulkan Vulkan_LIBRARIES - link against this library to use Vulkan -The module will also define two cache variables:: +The module will also define three cache variables:: - Vulkan_INCLUDE_DIR - the Vulkan include directory - Vulkan_LIBRARY - the path to the Vulkan library + Vulkan_INCLUDE_DIR - the Vulkan include directory + Vulkan_LIBRARY - the path to the Vulkan library + Vulkan_GLSLC_EXECUTABLE - the path to the GLSL SPIR-V compiler Hints ^^^^^ @@ -53,6 +59,11 @@ if(WIN32) "$ENV{VULKAN_SDK}/Lib" "$ENV{VULKAN_SDK}/Bin" ) + find_program(Vulkan_GLSLC_EXECUTABLE + NAMES glslc + HINTS + "$ENV{VULKAN_SDK}/Bin" + ) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) find_library(Vulkan_LIBRARY NAMES vulkan-1 @@ -60,6 +71,11 @@ if(WIN32) "$ENV{VULKAN_SDK}/Lib32" "$ENV{VULKAN_SDK}/Bin32" ) + find_program(Vulkan_GLSLC_EXECUTABLE + NAMES glslc + HINTS + "$ENV{VULKAN_SDK}/Bin32" + ) endif() else() find_path(Vulkan_INCLUDE_DIR @@ -68,6 +84,9 @@ else() find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib") + find_program(Vulkan_GLSLC_EXECUTABLE + NAMES glslc + HINTS "$ENV{VULKAN_SDK}/bin") endif() set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) @@ -78,7 +97,7 @@ find_package_handle_standard_args(Vulkan DEFAULT_MSG Vulkan_LIBRARY Vulkan_INCLUDE_DIR) -mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY) +mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY Vulkan_GLSLC_EXECUTABLE) if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan) add_library(Vulkan::Vulkan UNKNOWN IMPORTED) @@ -86,3 +105,8 @@ if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan) IMPORTED_LOCATION "${Vulkan_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}") endif() + +if(Vulkan_FOUND AND Vulkan_GLSLC_EXECUTABLE AND NOT TARGET Vulkan::glslc) + add_executable(Vulkan::glslc IMPORTED) + set_property(TARGET Vulkan::glslc PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLC_EXECUTABLE}") +endif() diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake index ccd025266..a865597af 100644 --- a/Modules/FindX11.cmake +++ b/Modules/FindX11.cmake @@ -28,6 +28,8 @@ and also the following more fine grained variables and targets: X11_xcb_INCLUDE_PATH, X11_xcb_LIB, X11_xcb_FOUND, X11::xcb X11_X11_xcb_INCLUDE_PATH, X11_X11_xcb_LIB, X11_X11_xcb_FOUND, X11::X11_xcb X11_xcb_icccm_INCLUDE_PATH, X11_xcb_icccm_LIB, X11_xcb_icccm_FOUND, X11::xcb_icccm + X11_xcb_util_INCLUDE_PATH, X11_xcb_util_LIB, X11_xcb_util_FOUND, X11::xcb_util + X11_xcb_xfixes_INCLUDE_PATH, X11_xcb_xfixes_LIB, X11_xcb_xfixes_FOUND, X11::xcb_xfixes X11_xcb_xkb_INCLUDE_PATH, X11_xcb_xkb_LIB, X11_xcb_xkb_FOUND, X11::xcb_xkb X11_Xcomposite_INCLUDE_PATH, X11_Xcomposite_LIB, X11_Xcomposite_FOUND, X11::Xcomposite X11_Xcursor_INCLUDE_PATH, X11_Xcursor_LIB, X11_Xcursor_FOUND, X11::Xcursor @@ -59,6 +61,7 @@ and also the following more fine grained variables and targets: X11_XShm_INCLUDE_PATH, (in X11_Xext_LIB), X11_XShm_FOUND X11_Xshape_INCLUDE_PATH, (in X11_Xext_LIB), X11_Xshape_FOUND X11_XSync_INCLUDE_PATH, (in X11_Xext_LIB), X11_XSync_FOUND + X11_Xaw_INCLUDE_PATH, X11_Xaw_LIB X11_Xaw_FOUND X11::Xaw #]=======================================================================] if (UNIX) @@ -100,9 +103,12 @@ if (UNIX) find_path(X11_Xaccessrules_INCLUDE_PATH X11/extensions/XKBrules.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xaccessstr_INCLUDE_PATH X11/extensions/XKBstr.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xau_INCLUDE_PATH X11/Xauth.h ${X11_INC_SEARCH_PATH}) + find_path(X11_Xaw_INCLUDE_PATH X11/Xaw/Intrinsic.h ${X11_INC_SEARCH_PATH}) find_path(X11_xcb_INCLUDE_PATH xcb/xcb.h ${X11_INC_SEARCH_PATH}) find_path(X11_X11_xcb_INCLUDE_PATH X11/Xlib-xcb.h ${X11_INC_SEARCH_PATH}) find_path(X11_xcb_icccm_INCLUDE_PATH xcb/xcb_icccm.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xcb_util_INCLUDE_PATH xcb/xcb_aux.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xcb_xfixes_INCLUDE_PATH xcb/xfixes.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xcomposite_INCLUDE_PATH X11/extensions/Xcomposite.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xcursor_INCLUDE_PATH X11/Xcursor/Xcursor.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xdamage_INCLUDE_PATH X11/extensions/Xdamage.h ${X11_INC_SEARCH_PATH}) @@ -134,6 +140,8 @@ if (UNIX) find_path(X11_Xv_INCLUDE_PATH X11/extensions/Xvlib.h ${X11_INC_SEARCH_PATH}) find_path(X11_XSync_INCLUDE_PATH X11/extensions/sync.h ${X11_INC_SEARCH_PATH}) + + # Backwards compatibility. set(X11_Xinput_INCLUDE_PATH "${X11_Xi_INCLUDE_PATH}") set(X11_xf86misc_INCLUDE_PATH "${X11_Xxf86misc_INCLUDE_PATH}") @@ -148,9 +156,12 @@ if (UNIX) find_library(X11_ICE_LIB ICE ${X11_LIB_SEARCH_PATH}) find_library(X11_SM_LIB SM ${X11_LIB_SEARCH_PATH}) find_library(X11_Xau_LIB Xau ${X11_LIB_SEARCH_PATH}) + find_library(X11_Xaw_LIB Xaw ${X11_LIB_SEARCH_PATH}) find_library(X11_xcb_LIB xcb ${X11_LIB_SEARCH_PATH}) find_library(X11_X11_xcb_LIB X11-xcb ${X11_LIB_SEARCH_PATH}) find_library(X11_xcb_icccm_LIB xcb-icccm ${X11_LIB_SEARCH_PATH}) + find_library(X11_xcb_util_LIB xcb-util ${X11_LIB_SEARCH_PATH}) + find_library(X11_xcb_xfixes_LIB xcb-xfixes ${X11_LIB_SEARCH_PATH}) find_library(X11_xcb_xkb_LIB xcb-xkb ${X11_LIB_SEARCH_PATH}) find_library(X11_Xcomposite_LIB Xcomposite ${X11_LIB_SEARCH_PATH}) find_library(X11_Xcursor_LIB Xcursor ${X11_LIB_SEARCH_PATH}) @@ -250,6 +261,14 @@ if (UNIX) set(X11_xcb_icccm_FOUND TRUE) endif () + if (X11_xcb_util_LIB AND X11_xcb_util_INCLUDE_PATH) + set(X11_xcb_util_FOUND TRUE) + endif () + + if (X11_xcb_xfixes_LIB) + set(X11_xcb_xfixes_FOUND TRUE) + endif () + if (X11_xcb_xkb_LIB) set(X11_xcb_xkb_FOUND TRUE) endif () @@ -392,6 +411,10 @@ if (UNIX) set(X11_SM_FOUND TRUE) endif() + if(X11_Xaw_LIB AND X11_Xaw_INCLUDE_PATH) + set(X11_Xaw_FOUND TRUE) + endif() + # Most of the X11 headers will be in the same directories, avoid # creating a huge list of duplicates. if (X11_INCLUDE_DIR) @@ -527,6 +550,14 @@ if (UNIX) INTERFACE_INCLUDE_DIRECTORIES "${X11_Xau_INCLUDE_PATH}") endif () + if (X11_Xaw_FOUND AND NOT TARGET X11::Xaw) + add_library(X11::Xaw UNKNOWN IMPORTED) + set_target_properties(X11::Xaw PROPERTIES + IMPORTED_LOCATION "${X11_Xaw_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${X11_Xaw_INCLUDE_PATH}" + INTERFACE_LINK_LIBRARIES "X11::Xext;X11::Xmu;X11::Xt;X11::Xpm;X11::X11") + endif () + if (X11_xcb_FOUND AND NOT TARGET X11::xcb) add_library(X11::xcb UNKNOWN IMPORTED) set_target_properties(X11::xcb PROPERTIES @@ -549,6 +580,20 @@ if (UNIX) INTERFACE_LINK_LIBRARIES "X11::xcb") endif () + if (X11_xcb_util_FOUND AND NOT TARGET X11::xcb_util) + add_library(X11::xcb_util UNKNOWN IMPORTED) + set_target_properties(X11::xcb_util PROPERTIES + IMPORTED_LOCATION "${X11_xcb_util_LIB}" + INTERFACE_LINK_LIBRARIES "X11::xcb") + endif () + + if (X11_xcb_xfixes_FOUND AND NOT TARGET X11::xcb_xfixes) + add_library(X11::xcb_xfixes UNKNOWN IMPORTED) + set_target_properties(X11::xcb_xfixes PROPERTIES + IMPORTED_LOCATION "${X11_xcb_xfixes_LIB}" + INTERFACE_LINK_LIBRARIES "X11::xcb") + endif () + if (X11_xcb_xkb_FOUND AND NOT TARGET X11::xcb_xkb) add_library(X11::xcb_xkb UNKNOWN IMPORTED) set_target_properties(X11::xcb_xkb PROPERTIES @@ -825,6 +870,8 @@ if (UNIX) X11_SM_LIB X11_SM_INCLUDE_PATH X11_XSync_INCLUDE_PATH + X11_Xaw_LIB + X11_Xaw_INCLUDE_PATH ) set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_SAVE}) set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) diff --git a/Modules/FindXCTest.cmake b/Modules/FindXCTest.cmake index 15721e184..1f6e82513 100644 --- a/Modules/FindXCTest.cmake +++ b/Modules/FindXCTest.cmake @@ -5,6 +5,8 @@ FindXCTest ---------- +.. versionadded:: 3.3 + Functions to help creating and executing XCTest bundles. An XCTest bundle is a CFBundle with a special product-type diff --git a/Modules/FindXalanC.cmake b/Modules/FindXalanC.cmake index 54783e394..a7fb766ca 100644 --- a/Modules/FindXalanC.cmake +++ b/Modules/FindXalanC.cmake @@ -5,6 +5,8 @@ FindXalanC ----------- +.. versionadded:: 3.5 + Find the Apache Xalan-C++ XSL transform processor headers and libraries. Imported targets diff --git a/Modules/FindXercesC.cmake b/Modules/FindXercesC.cmake index db78b61bd..abe18c057 100644 --- a/Modules/FindXercesC.cmake +++ b/Modules/FindXercesC.cmake @@ -5,6 +5,8 @@ FindXercesC ----------- +.. versionadded:: 3.1 + Find the Apache Xerces-C++ validating XML parser headers and libraries. Imported targets diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake index 93ac51dee..eab09f157 100644 --- a/Modules/FindwxWidgets.cmake +++ b/Modules/FindwxWidgets.cmake @@ -760,8 +760,16 @@ else() # UNIX: Start actual work. #----------------------------------------------------------------- # Support cross-compiling, only search in the target platform. + # + # Look for wx-config -- this can be set in the environment, + # or try versioned and toolchain-versioned variants of the -config + # executable as well. find_program(wxWidgets_CONFIG_EXECUTABLE - NAMES $ENV{WX_CONFIG} wx-config wx-config-3.1 wx-config-3.0 wx-config-2.9 wx-config-2.8 + NAMES + $ENV{WX_CONFIG} + wx-config + wx-config-3.1 wx-config-3.0 wx-config-2.9 wx-config-2.8 + wxgtk3u-3.1-config wxgtk3u-3.0-config wxgtk2u-2.8-config DOC "Location of wxWidgets library configuration provider binary (wx-config)." ONLY_CMAKE_FIND_ROOT_PATH ) diff --git a/Modules/FindwxWindows.cmake b/Modules/FindwxWindows.cmake index 35840f5f9..07fbc1bff 100644 --- a/Modules/FindwxWindows.cmake +++ b/Modules/FindwxWindows.cmake @@ -307,7 +307,7 @@ if(WIN32_STYLE_FIND) else () ## WX is built as multiple small pieces libraries instead of monolithic - ## DEPECATED (jw) replaced by more general WXWINDOWS_USE_MONOLITHIC ON/OFF + ## DEPRECATED (jw) replaced by more general WXWINDOWS_USE_MONOLITHIC ON/OFF # option(WXWINDOWS_SEPARATE_LIBS_BUILD "Is wxWindows build with separate libs?" OFF) ## HACK: This is very dirty. diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index 9ef22b936..13d067a2d 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -167,8 +167,6 @@ _GNUInstallDirs_cache_path(CMAKE_INSTALL_BINDIR "bin" "User executables (bin)") _GNUInstallDirs_cache_path(CMAKE_INSTALL_SBINDIR "sbin" "System admin executables (sbin)") -_GNUInstallDirs_cache_path(CMAKE_INSTALL_LIBEXECDIR "libexec" - "Program executables (libexec)") _GNUInstallDirs_cache_path(CMAKE_INSTALL_SYSCONFDIR "etc" "Read-only single-machine data (etc)") _GNUInstallDirs_cache_path(CMAKE_INSTALL_SHAREDSTATEDIR "com" @@ -262,6 +260,19 @@ set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE IN unset(_libdir_set) unset(__LAST_LIBDIR_DEFAULT) +if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$" + AND NOT CMAKE_CROSSCOMPILING + AND NOT EXISTS "/etc/arch-release" + AND EXISTS "/etc/debian_version" # is this a debian system ? + AND "${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$") + # see https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#usrlibexec + # and https://www.debian.org/doc/debian-policy/ch-opersys#file-system-structure (section 9.1.1 bullet point 4) + _GNUInstallDirs_cache_path(CMAKE_INSTALL_LIBEXECDIR "${CMAKE_INSTALL_LIBDIR}" + "Program executables (${CMAKE_INSTALL_LIBDIR})") +else() + _GNUInstallDirs_cache_path(CMAKE_INSTALL_LIBEXECDIR "libexec" + "Program executables (libexec)") +endif() _GNUInstallDirs_cache_path(CMAKE_INSTALL_INCLUDEDIR "include" "C header files (include)") _GNUInstallDirs_cache_path(CMAKE_INSTALL_OLDINCLUDEDIR "/usr/include" diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index 5c8c19671..c99c7725a 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -61,7 +61,7 @@ is the name of a CMake variable to contain the results. exclude "system" prerequisites. If <recurse> is set to 1 all prerequisites will be found recursively, if set to 0 only direct prerequisites are listed. <exepath> is the path to the top level -executable used for @executable_path replacment on the Mac. <dirs> is +executable used for @executable_path replacement on the Mac. <dirs> is a list of paths where libraries might be found: these paths are searched first when a target without any path info is given. Then standard system locations are also searched: PATH, Framework diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index b210a7715..057b29d6d 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -5,6 +5,8 @@ GoogleTest ---------- +.. versionadded:: 3.9 + This module defines functions to help use the Google Test infrastructure. Two mechanisms for adding tests are provided. :command:`gtest_add_tests` has been around for some time, originally via ``find_package(GTest)``. @@ -493,7 +495,7 @@ function(gtest_discover_tests TARGET) string(CONCAT ctest_include_content "if(EXISTS \"$<TARGET_FILE:${TARGET}>\")" "\n" " if(\"$<TARGET_FILE:${TARGET}>\" IS_NEWER_THAN \"${ctest_tests_file}\")" "\n" - " include(GoogleTestAddTests)" "\n" + " include(\"${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}\")" "\n" " gtest_discover_tests_impl(" "\n" " TEST_EXECUTABLE" " [==[" "$<TARGET_FILE:${TARGET}>" "]==]" "\n" " TEST_EXECUTOR" " [==[" "${crosscompiling_emulator}" "]==]" "\n" diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index db35e3afb..431b074c9 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -547,8 +547,8 @@ function(cpack_deb_prepare_package_vars) message(FATAL_ERROR _description_failure_message) endif() - # Ok, description has set. According to the `Debian Policy Manual`_ the frist - # line is a pacakge summary. Try to get it as well... + # Ok, description has set. According to the `Debian Policy Manual`_ the first + # line is a package summary. Try to get it as well... # See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description elseif(CPACK_PACKAGE_DESCRIPTION_SUMMARY AND NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY STREQUAL CPACK_DEFAULT_PACKAGE_DESCRIPTION_SUMMARY) diff --git a/Modules/Internal/CPack/WIX.template.in b/Modules/Internal/CPack/WIX.template.in index c4fc83afa..c0bf9353d 100644 --- a/Modules/Internal/CPack/WIX.template.in +++ b/Modules/Internal/CPack/WIX.template.in @@ -2,7 +2,7 @@ <?include "cpack_variables.wxi"?> -<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" +<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" @CPACK_WIX_CUSTOM_XMLNS_EXPANDED@ RequiredVersion="3.6.3303.0"> <Product Id="$(var.CPACK_WIX_PRODUCT_GUID)" diff --git a/Modules/Internal/CheckCompilerFlag.cmake b/Modules/Internal/CheckCompilerFlag.cmake new file mode 100644 index 000000000..f790d875c --- /dev/null +++ b/Modules/Internal/CheckCompilerFlag.cmake @@ -0,0 +1,79 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +include_guard(GLOBAL) +include(Internal/CheckSourceCompiles) +include(CMakeCheckCompilerFlagCommonPatterns) + +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST + +function(CMAKE_CHECK_COMPILER_FLAG _lang _flag _var) + + if(_lang STREQUAL C) + set(_lang_src "int main(void) { return 0; }") + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C") + elseif(_lang STREQUAL CXX) + set(_lang_src "int main() { return 0; }") + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+") + elseif(_lang STREQUAL CUDA) + set(_lang_src "__host__ int main() { return 0; }") + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif(_lang STREQUAL Fortran) + set(_lang_src " program test\n stop\n end program") + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran") + elseif(_lang STREQUAL OBJC) + set(_lang_src [=[ +#ifndef __OBJC__ +# error "Not an Objective-C compiler" +#endif +int main(void) { return 0; }]=]) + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif(_lang STREQUAL OBJCXX) + set(_lang_src [=[ +#ifndef __OBJC__ +# error "Not an Objective-C++ compiler" +#endif +int main(void) { return 0; }]=]) + set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif(_lang STREQUAL ISPC) + set(_lang_src "float func(uniform int32, float a) { return a / 2.25; }") + else() + message (SEND_ERROR "check_compiler_flag: ${_lang}: unknown language.") + return() + endif() + + get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT _lang IN_LIST _supported_languages) + message (SEND_ERROR "check_compiler_flag: ${_lang}: needs to be enabled before use.") + return() + endif() + + set(CMAKE_REQUIRED_DEFINITIONS ${_flag}) + + # Normalize locale during test compilation. + set(_locale_vars LC_ALL LC_MESSAGES LANG) + foreach(v IN LISTS _locale_vars) + set(_locale_vars_saved_${v} "$ENV{${v}}") + set(ENV{${v}} C) + endforeach() + + check_compiler_flag_common_patterns(_common_patterns) + cmake_check_source_compiles(${_lang} + "${_lang_src}" + ${_var} + ${_lang_fail_regex} + ${_common_patterns} + ) + + foreach(v IN LISTS _locale_vars) + set(ENV{${v}} ${_locale_vars_saved_${v}}) + endforeach() + set(${_var} "${${_var}}" PARENT_SCOPE) +endfunction () + +cmake_policy(POP) diff --git a/Modules/Internal/CheckSourceCompiles.cmake b/Modules/Internal/CheckSourceCompiles.cmake new file mode 100644 index 000000000..91c89640f --- /dev/null +++ b/Modules/Internal/CheckSourceCompiles.cmake @@ -0,0 +1,127 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +include_guard(GLOBAL) + +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST + +function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var) + if(NOT DEFINED "${_var}") + + if(_lang STREQUAL C) + set(_lang_textual "C") + set(_lang_ext "c") + elseif(_lang STREQUAL CXX) + set(_lang_textual "C++") + set(_lang_ext "cxx") + elseif(_lang STREQUAL CUDA) + set(_lang_textual "CUDA") + set(_lang_ext "cu") + elseif(_lang STREQUAL Fortran) + set(_lang_textual "Fortran") + set(_lang_ext "F90") + elseif(_lang STREQUAL ISPC) + set(_lang_textual "ISPC") + set(_lang_ext "ispc") + elseif(_lang STREQUAL OBJC) + set(_lang_textual "Objective-C") + set(_lang_ext "m") + elseif(_lang STREQUAL OBJCXX) + set(_lang_textual "Objective-C++") + set(_lang_ext "mm") + else() + message (SEND_ERROR "check_source_compiles: ${_lang}: unknown language.") + return() + endif() + + get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT _lang IN_LIST _supported_languages) + message (SEND_ERROR "check_source_compiles: ${_lang}: needs to be enabled before use.") + return() + endif() + + set(_FAIL_REGEX) + set(_SRC_EXT) + set(_key) + foreach(arg ${ARGN}) + if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$") + set(_key "${arg}") + elseif(_key STREQUAL "FAIL_REGEX") + list(APPEND _FAIL_REGEX "${arg}") + elseif(_key STREQUAL "SRC_EXT") + set(_SRC_EXT "${arg}") + set(_key "") + else() + message(FATAL_ERROR "Unknown argument:\n ${arg}\n") + endif() + endforeach() + + if(NOT _SRC_EXT) + set(_SRC_EXT ${_lang_ext}) + endif() + + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() + if(CMAKE_REQUIRED_LIBRARIES) + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_LIBRARIES + LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + else() + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_LIBRARIES) + endif() + if(CMAKE_REQUIRED_INCLUDES) + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") + else() + set(CHECK_${LANG}_SOURCE_COMPILES_ADD_INCLUDES) + endif() + file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}" + "${_source}\n") + + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_START "Performing Test ${_var}") + endif() + try_compile(${_var} + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} + COMPILE_DEFINITIONS -D${_var} ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_${LANG}_SOURCE_COMPILES_ADD_LINK_OPTIONS} + ${CHECK_${LANG}_SOURCE_COMPILES_ADD_LIBRARIES} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} + "${CHECK_${LANG}_SOURCE_COMPILES_ADD_INCLUDES}" + OUTPUT_VARIABLE OUTPUT) + + foreach(_regex ${_FAIL_REGEX}) + if("${OUTPUT}" MATCHES "${_regex}") + set(${_var} 0) + endif() + endforeach() + + if(${_var}) + set(${_var} 1 CACHE INTERNAL "Test ${_var}") + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_PASS "Success") + endif() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Performing ${_lang_textual} SOURCE FILE Test ${_var} succeeded with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${_source}\n") + else() + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_FAIL "Failed") + endif() + set(${_var} "" CACHE INTERNAL "Test ${_var}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Performing ${_lang_textual} SOURCE FILE Test ${_var} failed with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${_source}\n") + endif() + endif() +endfunction() + +cmake_policy(POP) diff --git a/Modules/Internal/CheckSourceRuns.cmake b/Modules/Internal/CheckSourceRuns.cmake new file mode 100644 index 000000000..3a4b7583f --- /dev/null +++ b/Modules/Internal/CheckSourceRuns.cmake @@ -0,0 +1,142 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +include_guard(GLOBAL) + +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST + +function(CMAKE_CHECK_SOURCE_RUNS _lang _source _var) + if(NOT DEFINED "${_var}") + + if(_lang STREQUAL C) + set(_lang_textual "C") + set(_lang_ext "c") + elseif(_lang STREQUAL CXX) + set(_lang_textual "C++") + set(_lang_ext "cxx") + elseif(_lang STREQUAL CUDA) + set(_lang_textual "CUDA") + set(_lang_ext "cu") + elseif(_lang STREQUAL Fortran) + set(_lang_textual "Fortran") + set(_lang_ext "F90") + elseif(_lang STREQUAL OBJC) + set(_lang_textual "Objective-C") + set(_lang_ext "m") + elseif(_lang STREQUAL OBJCXX) + set(_lang_textual "Objective-C++") + set(_lang_ext "mm") + else() + message (SEND_ERROR "check_source_runs: ${_lang}: unknown language.") + return() + endif() + + get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT _lang IN_LIST _supported_languages) + message (SEND_ERROR "check_source_runs: ${_lang}: needs to be enabled before use.") + return() + endif() + + set(_FAIL_REGEX) + set(_SRC_EXT) + set(_key) + foreach(arg ${ARGN}) + if("${arg}" MATCHES "^(FAIL_REGEX|SRC_EXT)$") + set(_key "${arg}") + elseif(_key STREQUAL "FAIL_REGEX") + list(APPEND _FAIL_REGEX "${arg}") + elseif(_key STREQUAL "SRC_EXT") + set(_SRC_EXT "${arg}") + set(_key "") + else() + set(message_type FATAL_ERROR) + if (_CheckSourceRuns_old_signature) + set(message_type AUTHOR_WARNING) + endif () + message("${message_type}" "Unknown argument:\n ${arg}\n") + unset(message_type) + endif() + endforeach() + + if(NOT _SRC_EXT) + set(_SRC_EXT ${_lang_ext}) + endif() + + if(CMAKE_REQUIRED_LINK_OPTIONS) + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_LINK_OPTIONS + LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) + else() + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_LINK_OPTIONS) + endif() + if(CMAKE_REQUIRED_LIBRARIES) + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_LIBRARIES + LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + else() + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_LIBRARIES) + endif() + if(CMAKE_REQUIRED_INCLUDES) + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") + else() + set(CHECK_${_lang}_SOURCE_COMPILES_ADD_INCLUDES) + endif() + file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}" + "${_source}\n") + + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_START "Performing Test ${_var}") + endif() + try_run(${_var}_EXITCODE ${_var}_COMPILED + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} + COMPILE_DEFINITIONS -D${_var} ${CMAKE_REQUIRED_DEFINITIONS} + ${CHECK_${_lang}_SOURCE_COMPILES_ADD_LINK_OPTIONS} + ${CHECK_${_lang}_SOURCE_COMPILES_ADD_LIBRARIES} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} + -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} + "${CHECK_${_lang}_SOURCE_COMPILES_ADD_INCLUDES}" + COMPILE_OUTPUT_VARIABLE OUTPUT + RUN_OUTPUT_VARIABLE RUN_OUTPUT) + # if it did not compile make the return value fail code of 1 + if(NOT ${_var}_COMPILED) + set(${_var}_EXITCODE 1) + set(${_var}_EXITCODE 1 PARENT_SCOPE) + endif() + # if the return value was 0 then it worked + if("${${_var}_EXITCODE}" EQUAL 0) + set(${_var} 1 CACHE INTERNAL "Test ${_var}") + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_PASS "Success") + endif() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Performing ${_lang_textual} SOURCE FILE Test ${_var} succeeded with the following compile output:\n" + "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" + "Return value: ${${_var}}\n" + "Source file was:\n${_source}\n") + else() + if(CMAKE_CROSSCOMPILING AND "${${_var}_EXITCODE}" MATCHES "FAILED_TO_RUN") + set(${_var} "${${_var}_EXITCODE}" PARENT_SCOPE) + else() + set(${_var} "" CACHE INTERNAL "Test ${_var}") + endif() + + if(NOT CMAKE_REQUIRED_QUIET) + message(CHECK_FAIL "Failed") + endif() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Performing ${_lang_textual} SOURCE FILE Test ${_var} failed with the following compile output:\n" + "${OUTPUT}\n" + "...and run output:\n" + "${RUN_OUTPUT}\n" + "Return value: ${${_var}_EXITCODE}\n" + "Source file was:\n${_source}\n") + + endif() + endif() +endfunction() + +cmake_policy(POP) diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake index 759448b8e..160eadae0 100644 --- a/Modules/Platform/Android-Clang.cmake +++ b/Modules/Platform/Android-Clang.cmake @@ -53,4 +53,7 @@ macro(__android_compiler_clang lang) endif() list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}") endif() + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(_ANDROID_STL_NOSTDLIBXX 1) + endif() endmacro() diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index 2225897fa..bc66ba1df 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -7,8 +7,8 @@ # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with -# that functionality for now. Later we may try to integrate this. -if(CMAKE_GENERATOR MATCHES "Visual Studio") +# that functionality for now. +if(CMAKE_GENERATOR_PLATFORM STREQUAL "Tegra-Android") return() endif() @@ -27,6 +27,63 @@ endif() cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # if IN_LIST +# If using Android tools for Visual Studio, compile a sample project to get the +# sysroot. +if(CMAKE_GENERATOR MATCHES "Visual Studio") + if(NOT CMAKE_SYSROOT) + set(vcx_platform ${CMAKE_GENERATOR_PLATFORM}) + if(CMAKE_GENERATOR MATCHES "Visual Studio 1[45]") + set(vcx_sysroot_var "Sysroot") + else() + set(vcx_sysroot_var "SysrootLink") + endif() + if(CMAKE_GENERATOR MATCHES "Visual Studio 14") + set(vcx_revision "2.0") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + set(vcx_revision "3.0") + else() + set(vcx_revision "") + endif() + configure_file(${CMAKE_ROOT}/Modules/Platform/Android/VCXProjInspect.vcxproj.in + ${CMAKE_PLATFORM_INFO_DIR}/VCXProjInspect.vcxproj @ONLY) + execute_process( + COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" "VCXProjInspect.vcxproj" + "/p:Configuration=Debug" "/p:Platform=${vcx_platform}" + WORKING_DIRECTORY ${CMAKE_PLATFORM_INFO_DIR} + OUTPUT_VARIABLE VCXPROJ_INSPECT_OUTPUT + ERROR_VARIABLE VCXPROJ_INSPECT_OUTPUT + RESULT_VARIABLE VCXPROJ_INSPECT_RESULT + ) + if(NOT CMAKE_SYSROOT AND VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_SYSROOT=([^%\r\n]+)[\r\n]") + # Strip VS diagnostic output from the end of the line. + string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _sysroot "${CMAKE_MATCH_1}") + if(EXISTS "${_sysroot}") + file(TO_CMAKE_PATH "${_sysroot}" CMAKE_SYSROOT) + endif() + endif() + if(VCXPROJ_INSPECT_RESULT) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining the sysroot for the Android NDK failed. +The output was: +${VCXPROJ_INSPECT_RESULT} +${VCXPROJ_INSPECT_OUTPUT} + +") + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining the sysroot for the Android NDK succeeded. +The output was: +${VCXPROJ_INSPECT_RESULT} +${VCXPROJ_INSPECT_OUTPUT} + +") + endif() + endif() + if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION) + set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang") + endif() +endif() + # If the user provided CMAKE_SYSROOT for us, extract information from it. set(_ANDROID_SYSROOT_NDK "") set(_ANDROID_SYSROOT_API "") @@ -144,64 +201,15 @@ if(NOT CMAKE_ANDROID_NDK AND NOT CMAKE_ANDROID_STANDALONE_TOOLCHAIN) message(FATAL_ERROR "Android: Neither the NDK or a standalone toolchain was found.") endif() -# Select an API. -if(CMAKE_SYSTEM_VERSION) - set(_ANDROID_API_VAR CMAKE_SYSTEM_VERSION) -elseif(CMAKE_ANDROID_API) - set(CMAKE_SYSTEM_VERSION "${CMAKE_ANDROID_API}") - set(_ANDROID_API_VAR CMAKE_ANDROID_API) -elseif(_ANDROID_SYSROOT_API) - set(CMAKE_SYSTEM_VERSION "${_ANDROID_SYSROOT_API}") - set(_ANDROID_API_VAR CMAKE_SYSROOT) -elseif(_ANDROID_STANDALONE_TOOLCHAIN_API) - set(CMAKE_SYSTEM_VERSION "${_ANDROID_STANDALONE_TOOLCHAIN_API}") -endif() -if(CMAKE_SYSTEM_VERSION) - if(CMAKE_ANDROID_API AND NOT "x${CMAKE_ANDROID_API}" STREQUAL "x${CMAKE_SYSTEM_VERSION}") - message(FATAL_ERROR - "Android: The API specified by CMAKE_ANDROID_API='${CMAKE_ANDROID_API}' is not consistent with CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}'." - ) - endif() - if(_ANDROID_SYSROOT_API) - foreach(v CMAKE_ANDROID_API CMAKE_SYSTEM_VERSION) - if(${v} AND NOT "x${_ANDROID_SYSROOT_API}" STREQUAL "x${${v}}") - message(FATAL_ERROR - "Android: The API specified by ${v}='${${v}}' is not consistent with CMAKE_SYSROOT:\n" - " ${CMAKE_SYSROOT}" - ) - endif() - endforeach() - endif() - if(CMAKE_ANDROID_NDK AND NOT IS_DIRECTORY "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}") - message(FATAL_ERROR - "Android: The API specified by ${_ANDROID_API_VAR}='${${_ANDROID_API_VAR}}' does not exist in the NDK. " - "The directory:\n" - " ${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}\n" - "does not exist." - ) - endif() -elseif(CMAKE_ANDROID_NDK) - file(GLOB _ANDROID_APIS_1 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9]") - file(GLOB _ANDROID_APIS_2 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9][0-9]") - list(SORT _ANDROID_APIS_1) - list(SORT _ANDROID_APIS_2) - set(_ANDROID_APIS ${_ANDROID_APIS_1} ${_ANDROID_APIS_2}) - unset(_ANDROID_APIS_1) - unset(_ANDROID_APIS_2) - if(_ANDROID_APIS STREQUAL "") - message(FATAL_ERROR - "Android: No APIs found in the NDK. No\n" - " ${CMAKE_ANDROID_NDK}/platforms/android-*\n" - "directories exist." - ) - endif() - string(REPLACE "android-" "" _ANDROID_APIS "${_ANDROID_APIS}") - list(REVERSE _ANDROID_APIS) - list(GET _ANDROID_APIS 0 CMAKE_SYSTEM_VERSION) - unset(_ANDROID_APIS) -endif() -if(NOT CMAKE_SYSTEM_VERSION MATCHES "^[0-9]+$") - message(FATAL_ERROR "Android: The API specified by CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}' is not an integer.") +if(CMAKE_ANDROID_NDK) + # NDK >= 18 has platforms.cmake. It provides: + # NDK_MIN_PLATFORM_LEVEL + # NDK_MAX_PLATFORM_LEVEL + include("${CMAKE_ANDROID_NDK}/build/cmake/platforms.cmake" OPTIONAL RESULT_VARIABLE _INCLUDED_PLATFORMS) + # NDK >= 18 has abis.cmake. It provides: + # NDK_KNOWN_DEVICE_ABI32S + # NDK_KNOWN_DEVICE_ABI64S + include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake" OPTIONAL RESULT_VARIABLE _INCLUDED_ABIS) endif() if(CMAKE_ANDROID_NDK) @@ -238,6 +246,10 @@ else() set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED "") endif() +if(_INCLUDED_ABIS) + set(_ANDROID_KNOWN_ABIS ${NDK_KNOWN_DEVICE_ABI32S} ${NDK_KNOWN_DEVICE_ABI64S}) +endif() + # https://developer.android.com/ndk/guides/abis.html set(_ANDROID_ABI_arm64-v8a_PROC "aarch64") @@ -301,6 +313,19 @@ if(NOT CMAKE_ANDROID_ARCH_ABI) set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_PROC_${CMAKE_SYSTEM_PROCESSOR}_ARCH_ABI}") elseif(_ANDROID_SYSROOT_ARCH) set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI}") + elseif(_INCLUDED_ABIS) + # Default to the oldest ARM ABI. + foreach(abi armeabi armeabi-v7a arm64-v8a) + if("${abi}" IN_LIST _ANDROID_KNOWN_ABIS) + set(CMAKE_ANDROID_ARCH_ABI "${abi}") + break() + endif() + endforeach() + if(NOT CMAKE_ANDROID_ARCH_ABI) + message(FATAL_ERROR + "Android: Can not determine the default ABI. Please set CMAKE_ANDROID_ARCH_ABI." + ) + endif() else() # https://developer.android.com/ndk/guides/application_mk.html # Default is the oldest ARM ABI. @@ -323,15 +348,12 @@ if(NOT CMAKE_ANDROID_ARCH_ABI) # Choose the oldest among the available arm ABIs. if(_ANDROID_ABIS) list(REMOVE_DUPLICATES _ANDROID_ABIS) - cmake_policy(PUSH) - cmake_policy(SET CMP0057 NEW) foreach(abi armeabi armeabi-v7a arm64-v8a) if("${abi}" IN_LIST _ANDROID_ABIS) set(CMAKE_ANDROID_ARCH_ABI "${abi}") break() endif() endforeach() - cmake_policy(POP) endif() unset(_ANDROID_ABIS) @@ -340,6 +362,12 @@ if(NOT CMAKE_ANDROID_ARCH_ABI) endif() endif() endif() +if(_INCLUDED_ABIS AND NOT CMAKE_ANDROID_ARCH_ABI IN_LIST _ANDROID_KNOWN_ABIS) + message(FATAL_ERROR + "Android: ABI '${CMAKE_ANDROID_ARCH_ABI}' is not supported by the NDK.\n" + "Supported ABIS: ${_ANDROID_KNOWN_ABIS}." + ) +endif() set(CMAKE_ANDROID_ARCH "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}") if(_ANDROID_SYSROOT_ARCH AND NOT "x${_ANDROID_SYSROOT_ARCH}" STREQUAL "x${CMAKE_ANDROID_ARCH}") message(FATAL_ERROR @@ -360,6 +388,88 @@ if(NOT _ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC STREQUAL CMAKE_SYSTEM_PROCESS message(FATAL_ERROR "Android: The specified CMAKE_ANDROID_ARCH_ABI='${CMAKE_ANDROID_ARCH_ABI}' and CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}' is not a valid combination.") endif() +# Select an API. +if(CMAKE_SYSTEM_VERSION) + set(_ANDROID_API_VAR CMAKE_SYSTEM_VERSION) +elseif(CMAKE_ANDROID_API) + set(CMAKE_SYSTEM_VERSION "${CMAKE_ANDROID_API}") + set(_ANDROID_API_VAR CMAKE_ANDROID_API) +elseif(_ANDROID_SYSROOT_API) + set(CMAKE_SYSTEM_VERSION "${_ANDROID_SYSROOT_API}") + set(_ANDROID_API_VAR CMAKE_SYSROOT) +elseif(_ANDROID_STANDALONE_TOOLCHAIN_API) + set(CMAKE_SYSTEM_VERSION "${_ANDROID_STANDALONE_TOOLCHAIN_API}") +endif() +if(CMAKE_SYSTEM_VERSION) + if(CMAKE_ANDROID_API AND NOT "x${CMAKE_ANDROID_API}" STREQUAL "x${CMAKE_SYSTEM_VERSION}") + message(FATAL_ERROR + "Android: The API specified by CMAKE_ANDROID_API='${CMAKE_ANDROID_API}' is not consistent with CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}'." + ) + endif() + if(_ANDROID_SYSROOT_API) + foreach(v CMAKE_ANDROID_API CMAKE_SYSTEM_VERSION) + if(${v} AND NOT "x${_ANDROID_SYSROOT_API}" STREQUAL "x${${v}}") + message(FATAL_ERROR + "Android: The API specified by ${v}='${${v}}' is not consistent with CMAKE_SYSROOT:\n" + " ${CMAKE_SYSROOT}" + ) + endif() + endforeach() + endif() + if(CMAKE_ANDROID_NDK) + if (_INCLUDED_PLATFORMS) + if(CMAKE_SYSTEM_VERSION GREATER NDK_MAX_PLATFORM_LEVEL OR + CMAKE_SYSTEM_VERSION LESS NDK_MIN_PLATFORM_LEVEL) + message(FATAL_ERROR + "Android: The API level ${CMAKE_SYSTEM_VERSION} is not supported by the NDK.\n" + "Choose one in the range of [${NDK_MIN_PLATFORM_LEVEL}, ${NDK_MAX_PLATFORM_LEVEL}]." + ) + endif() + else() + if(NOT IS_DIRECTORY "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}") + message(FATAL_ERROR + "Android: The API specified by ${_ANDROID_API_VAR}='${${_ANDROID_API_VAR}}' does not exist in the NDK. " + "The directory:\n" + " ${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}\n" + "does not exist." + ) + endif() + endif() + endif() +elseif(CMAKE_ANDROID_NDK) + if (_INCLUDED_PLATFORMS) + set(CMAKE_SYSTEM_VERSION ${NDK_MIN_PLATFORM_LEVEL}) + # And for LP64 we need to pull up to 21. No diagnostic is provided here because + # minSdkVersion < 21 is valid for the project even though it may not be for this + # ABI. + if(CMAKE_ANDROID_ARCH_ABI MATCHES "64(-v8a)?$" AND CMAKE_SYSTEM_VERSION LESS 21) + set(CMAKE_SYSTEM_VERSION 21) + endif() + else() + file(GLOB _ANDROID_APIS_1 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9]") + file(GLOB _ANDROID_APIS_2 RELATIVE "${CMAKE_ANDROID_NDK}/platforms" "${CMAKE_ANDROID_NDK}/platforms/android-[0-9][0-9]") + list(SORT _ANDROID_APIS_1) + list(SORT _ANDROID_APIS_2) + set(_ANDROID_APIS ${_ANDROID_APIS_1} ${_ANDROID_APIS_2}) + unset(_ANDROID_APIS_1) + unset(_ANDROID_APIS_2) + if(_ANDROID_APIS STREQUAL "") + message(FATAL_ERROR + "Android: No APIs found in the NDK. No\n" + " ${CMAKE_ANDROID_NDK}/platforms/android-*\n" + "directories exist." + ) + endif() + string(REPLACE "android-" "" _ANDROID_APIS "${_ANDROID_APIS}") + list(REVERSE _ANDROID_APIS) + list(GET _ANDROID_APIS 0 CMAKE_SYSTEM_VERSION) + unset(_ANDROID_APIS) + endif() +endif() +if(NOT CMAKE_SYSTEM_VERSION MATCHES "^[0-9]+$") + message(FATAL_ERROR "Android: The API specified by CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}' is not an integer.") +endif() + if(CMAKE_ANDROID_NDK AND NOT DEFINED CMAKE_ANDROID_NDK_DEPRECATED_HEADERS) if(IS_DIRECTORY "${CMAKE_ANDROID_NDK}/sysroot/usr/include/${CMAKE_ANDROID_ARCH_TRIPLE}") # Unified headers exist so we use them by default. diff --git a/Modules/Platform/Android-Initialize.cmake b/Modules/Platform/Android-Initialize.cmake index b90dd7a56..5019c28bd 100644 --- a/Modules/Platform/Android-Initialize.cmake +++ b/Modules/Platform/Android-Initialize.cmake @@ -6,7 +6,7 @@ # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with -# that functionality for now. Later we may try to integrate this. +# that functionality for now. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") return() endif() diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake index f56e1d5e5..a4d67c438 100644 --- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -184,7 +184,7 @@ foreach(line IN LISTS _ANDROID_TOOL_SETUP) # We just matched the gcc toolchain name without version number. Save it for later. set(_ANDROID_TOOL_NAME_ONLY "${CMAKE_MATCH_1}") elseif(line MATCHES [[^TOOLCHAIN_PREFIX +:= +.*/bin/(\$\(TOOLCHAIN_NAME\)-) *$]]) - # We just matched the toolchain prefix with a name placholder, so substitute it. + # We just matched the toolchain prefix with a name placeholder, so substitute it. # The gcc toolchain name will have already been extracted without version number from a TOOLCHAIN_NAME line. string(REPLACE "$(TOOLCHAIN_NAME)" "${_ANDROID_TOOL_NAME_ONLY}" _ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") elseif(line MATCHES [[^LLVM_VERSION +:= +([0-9.]+)$]]) diff --git a/Modules/Platform/Android/VCXProjInspect.vcxproj.in b/Modules/Platform/Android/VCXProjInspect.vcxproj.in new file mode 100644 index 000000000..6919d2cd8 --- /dev/null +++ b/Modules/Platform/Android/VCXProjInspect.vcxproj.in @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|@vcx_platform@"> + <Configuration>Debug</Configuration> + <Platform>@vcx_platform@</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{14D44772-ECF7-47BD-9E29-BC62FAF940A5}</ProjectGuid> + <RootNamespace>VCXProjInspect</RootNamespace> + <Keyword>Android</Keyword> + <ApplicationType>Android</ApplicationType> + <ApplicationTypeRevision>@vcx_revision@</ApplicationTypeRevision> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <PropertyGroup> + <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'"> + <PostBuildEvent> + <Command>%40echo CMAKE_SYSROOT=$(@vcx_sysroot_var@)</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake index 80e9a4019..213f71b9c 100644 --- a/Modules/Platform/Darwin-Initialize.cmake +++ b/Modules/Platform/Darwin-Initialize.cmake @@ -20,6 +20,17 @@ execute_process(COMMAND sw_vers -productVersion set(CMAKE_OSX_ARCHITECTURES "$ENV{CMAKE_OSX_ARCHITECTURES}" CACHE STRING "Build architectures for OSX") +if(NOT CMAKE_CROSSCOMPILING AND + CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND + CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" AND + CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + # When building on Apple Silicon (arm64), we need to explicitly specify + # the architecture to the toolchain since it will otherwise guess the + # architecture based on that of the build system tool. + # Set an *internal variable* to tell the generators to do this. + set(_CMAKE_APPLE_ARCHS_DEFAULT "arm64") +endif() + # macOS, iOS, tvOS, and watchOS should lookup compilers from # Platform/Apple-${CMAKE_CXX_COMPILER_ID}-<LANG> set(CMAKE_EFFECTIVE_SYSTEM_NAME "Apple") @@ -62,45 +73,36 @@ elseif("${CMAKE_GENERATOR}" MATCHES Xcode # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory. set(_CMAKE_OSX_SDKS_DIR "") if(OSX_DEVELOPER_ROOT) - foreach(d Platforms/MacOSX.platform/Developer/SDKs SDKs) - file(GLOB _CMAKE_OSX_SDKS ${OSX_DEVELOPER_ROOT}/${d}/*) + foreach(_d Platforms/MacOSX.platform/Developer/SDKs SDKs) + file(GLOB _CMAKE_OSX_SDKS ${OSX_DEVELOPER_ROOT}/${_d}/*) if(_CMAKE_OSX_SDKS) - set(_CMAKE_OSX_SDKS_DIR ${OSX_DEVELOPER_ROOT}/${d}) + set(_CMAKE_OSX_SDKS_DIR ${OSX_DEVELOPER_ROOT}/${_d}) break() endif() endforeach() endif() if(_CMAKE_OSX_SDKS_DIR) - # Select SDK for current OSX version accounting for the known - # specially named SDKs. - set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.4 "u") - set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.3 ".9") - - # find the latest SDK + # Find the latest SDK as recommended by Apple (Technical Q&A QA1806) set(_CMAKE_OSX_LATEST_SDK_VERSION "0.0") file(GLOB _CMAKE_OSX_SDKS RELATIVE "${_CMAKE_OSX_SDKS_DIR}" "${_CMAKE_OSX_SDKS_DIR}/MacOSX*.sdk") foreach(_SDK ${_CMAKE_OSX_SDKS}) - if(_SDK MATCHES "MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk" AND CMAKE_MATCH_1 VERSION_GREATER ${_CMAKE_OSX_LATEST_SDK_VERSION}) + if(IS_DIRECTORY "${_CMAKE_OSX_SDKS_DIR}/${_SDK}" + AND _SDK MATCHES "MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk" + AND CMAKE_MATCH_1 VERSION_GREATER ${_CMAKE_OSX_LATEST_SDK_VERSION}) set(_CMAKE_OSX_LATEST_SDK_VERSION "${CMAKE_MATCH_1}") endif() endforeach() - # pick an SDK that works - set(_CMAKE_OSX_SYSROOT_DEFAULT) - foreach(ver ${CMAKE_OSX_DEPLOYMENT_TARGET} - ${_CURRENT_OSX_VERSION} - ${_CMAKE_OSX_LATEST_SDK_VERSION}) - set(_CMAKE_OSX_DEPLOYMENT_TARGET ${ver}) - set(_CMAKE_OSX_SDKS_VER ${_CMAKE_OSX_DEPLOYMENT_TARGET}${_CMAKE_OSX_SDKS_VER_SUFFIX_${_CMAKE_OSX_DEPLOYMENT_TARGET}}) - set(_CMAKE_OSX_SYSROOT_CHECK "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_SDKS_VER}.sdk") - if(IS_DIRECTORY "${_CMAKE_OSX_SYSROOT_CHECK}") - set(_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SYSROOT_CHECK}") - break() - endif() - endforeach() + if(NOT _CMAKE_OSX_LATEST_SDK_VERSION STREQUAL "0.0") + set(_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_LATEST_SDK_VERSION}.sdk") + else() + message(WARNING "Could not find any valid SDKs in ${_CMAKE_OSX_SDKS_DIR}") + endif() - if(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_OSX_DEPLOYMENT_TARGET AND _CURRENT_OSX_VERSION VERSION_LESS _CMAKE_OSX_DEPLOYMENT_TARGET) + if(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_OSX_DEPLOYMENT_TARGET + AND (_CURRENT_OSX_VERSION VERSION_LESS _CMAKE_OSX_LATEST_SDK_VERSION + OR _CMAKE_OSX_LATEST_SDK_VERSION STREQUAL "0.0")) set(CMAKE_OSX_DEPLOYMENT_TARGET ${_CURRENT_OSX_VERSION} CACHE STRING "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value." FORCE) endif() @@ -113,8 +115,8 @@ endif() # Set cache variable - end user may change this during ccmake or cmake-gui configure. # Choose the type based on the current value. set(_CMAKE_OSX_SYSROOT_TYPE STRING) -foreach(v CMAKE_OSX_SYSROOT _CMAKE_OSX_SYSROOT_DEFAULT) - if("x${${v}}" MATCHES "/") +foreach(_v CMAKE_OSX_SYSROOT _CMAKE_OSX_SYSROOT_DEFAULT) + if("x${${_v}}" MATCHES "/") set(_CMAKE_OSX_SYSROOT_TYPE PATH) break() endif() @@ -143,20 +145,26 @@ function(_apple_resolve_supported_archs_for_sdk_from_system_lib sdk_path ret ret # Newer SDKs ship text based dylib stub files which contain the architectures supported by the # library in text form. if(EXISTS "${system_lib_tbd_path}") - file(STRINGS "${system_lib_tbd_path}" tbd_lines REGEX "^archs: +\\[.+\\]") + file(STRINGS "${system_lib_tbd_path}" tbd_lines REGEX "^(archs|targets): +\\[.+\\]") if(NOT tbd_lines) set(${ret_failed} TRUE PARENT_SCOPE) return() endif() # The tbd architectures line looks like the following: - # archs: [ armv7, armv7s, arm64, arm64e ] + # archs: [ armv7, armv7s, arm64, arm64e ] + # or for version 4 TBD files: + # targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ] list(GET tbd_lines 0 first_arch_line) string(REGEX REPLACE - "archs: +\\[ (.+) \\]" "\\1" arches_comma_separated "${first_arch_line}") + "(archs|targets): +\\[ (.+) \\]" "\\2" arches_comma_separated "${first_arch_line}") string(STRIP "${arches_comma_separated}" arches_comma_separated) string(REPLACE "," ";" arch_list "${arches_comma_separated}") string(REPLACE " " "" arch_list "${arch_list}") + + # Remove -platform suffix from target (version 4 only) + string(REGEX REPLACE "-[a-z-]+" "" arch_list "${arch_list}") + if(NOT arch_list) set(${ret_failed} TRUE PARENT_SCOPE) return() diff --git a/Modules/Platform/HP-UX.cmake b/Modules/Platform/HP-UX.cmake index 9572a7ebb..425a13f45 100644 --- a/Modules/Platform/HP-UX.cmake +++ b/Modules/Platform/HP-UX.cmake @@ -22,7 +22,7 @@ set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1) # set flags for gcc support include(Platform/UnixPaths) -# Look in both 32-bit and 64-bit implict link directories, but tell +# Look in both 32-bit and 64-bit implicit link directories, but tell # CMake not to pass the paths to the linker. The linker will find the # library for the proper architecture. In the future we should detect # which path will be used by the linker. Since the pointer type size diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index a23d66450..2261c90d8 100644 --- a/Modules/Platform/Windows-Clang.cmake +++ b/Modules/Platform/Windows-Clang.cmake @@ -102,6 +102,27 @@ macro(__windows_compiler_clang_gnu lang) enable_language(RC) endmacro() +macro(__enable_llvm_rc_preprocessing clang_option_prefix) + # Feed the preprocessed rc file to llvm-rc + if(CMAKE_RC_COMPILER_INIT MATCHES "llvm-rc" OR CMAKE_RC_COMPILER MATCHES "llvm-rc") + if(DEFINED CMAKE_C_COMPILER_ID) + set(CMAKE_RC_PREPROCESSOR CMAKE_C_COMPILER) + elseif(DEFINED CMAKE_CXX_COMPILER_ID) + set(CMAKE_RC_PREPROCESSOR CMAKE_CXX_COMPILER) + endif() + if(DEFINED CMAKE_RC_PREPROCESSOR) + set(CMAKE_DEPFILE_FLAGS_RC "${clang_option_prefix}-MD ${clang_option_prefix}-MF ${clang_option_prefix}<DEPFILE>") + set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_COMMAND> -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> -E -- <SOURCE> ++ <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> /fo <OBJECT> <OBJECT>.pp") + if(CMAKE_GENERATOR MATCHES "Ninja") + set(CMAKE_NINJA_CMCLDEPS_RC 0) + set(CMAKE_NINJA_DEP_TYPE_RC gcc) + endif() + unset(CMAKE_RC_PREPROCESSOR) + endif() + endif() +endmacro() + + if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") @@ -129,7 +150,10 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" if(__RC_COMPILER_PATH) set(CMAKE_RC_COMPILER_INIT rc) else() - set(CMAKE_RC_COMPILER_INIT llvm-rc) + find_program(__RC_COMPILER_PATH NAMES llvm-rc) + if(__RC_COMPILER_PATH) + set(CMAKE_RC_COMPILER_INIT llvm-rc) + endif() endif() unset(__RC_COMPILER_PATH CACHE) @@ -137,26 +161,9 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" if ( "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" ) include(Platform/Windows-MSVC) - - # Feed the preprocessed rc file to llvm-rc - if(CMAKE_RC_COMPILER_INIT MATCHES "llvm-rc") - if(DEFINED CMAKE_C_COMPILER_ID) - set(CMAKE_RC_PREPROCESSOR CMAKE_C_COMPILER) - elseif(DEFINED CMAKE_CXX_COMPILER_ID) - set(CMAKE_RC_PREPROCESSOR CMAKE_CXX_COMPILER) - endif() - if(DEFINED CMAKE_RC_PREPROCESSOR) - set(CMAKE_DEPFILE_FLAGS_RC "-clang:-MD -clang:-MF -clang:<DEPFILE>") - set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_COMMAND> -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> -E <SOURCE> -- <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> /fo <OBJECT> <OBJECT>.pp") - if(CMAKE_GENERATOR STREQUAL "Ninja") - set(CMAKE_NINJA_CMCLDEPS_RC 0) - set(CMAKE_NINJA_DEP_TYPE_RC gcc) - endif() - unset(CMAKE_RC_PREPROCESSOR) - endif() - endif() - - macro(__windows_compiler_clang lang) + # Set the clang option forwarding prefix for clang-cl usage in the llvm-rc processing stage + __enable_llvm_rc_preprocessing("-clang:") + macro(__windows_compiler_clang_base lang) set(_COMPILE_${lang} "${_COMPILE_${lang}_MSVC}") __windows_compiler_msvc(${lang}) endmacro() @@ -171,14 +178,25 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" set(CMAKE_BUILD_TYPE_INIT Debug) - macro(__windows_compiler_clang lang) + __enable_llvm_rc_preprocessing("") + macro(__windows_compiler_clang_base lang) __windows_compiler_clang_gnu(${lang}) endmacro() endif() else() include(Platform/Windows-GNU) - macro(__windows_compiler_clang lang) + __enable_llvm_rc_preprocessing("") + macro(__windows_compiler_clang_base lang) __windows_compiler_gnu(${lang}) endmacro() endif() + +macro(__windows_compiler_clang lang) + if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0) + set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "-target ") + else() + set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=") + endif() + __windows_compiler_clang_base(${lang}) +endmacro() diff --git a/Modules/Platform/Windows-Intel-ISPC.cmake b/Modules/Platform/Windows-Intel-ISPC.cmake new file mode 100644 index 000000000..cd2630266 --- /dev/null +++ b/Modules/Platform/Windows-Intel-ISPC.cmake @@ -0,0 +1,8 @@ + +if(CMAKE_VERBOSE_MAKEFILE) + set(CMAKE_CL_NOLOGO) +else() + set(CMAKE_CL_NOLOGO "/nologo") +endif() + +set(CMAKE_ISPC_CREATE_STATIC_LIBRARY "<CMAKE_AR> ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 2476a338e..bd0871843 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -333,6 +333,14 @@ macro(__windows_compiler_msvc lang) set(CMAKE_LINK_PCH ON) if (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang") set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") + + # macOS paths usually start with /Users/*. Unfortunately, clang-cl interprets + # paths starting with /U as macro undefines, so we need to put a -- before the + # input file path to force it to be treated as a path. + string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_COMPILE_OBJECT "${CMAKE_${lang}_COMPILE_OBJECT}") + string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "${CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE}") + string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "${CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE}") + elseif(MSVC_VERSION GREATER_EQUAL 1913) # At least MSVC toolet 14.13 from VS 2017 15.6 set(CMAKE_PCH_PROLOGUE "#pragma system_header") diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index b47a8cb05..757e5392b 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -76,14 +76,14 @@ Defines the following command for use with ``SWIG``: ``OUTFILE_DIR`` Specify an output directory name where the generated source file will be - placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable - will be used. If neither is specified, ``OUTPUT_DIR`` or + placed (swig ``-o`` option). If not specified, the ``SWIG_OUTFILE_DIR`` + variable will be used. If neither is specified, ``OUTPUT_DIR`` or ``CMAKE_SWIG_OUTDIR`` is used instead. ``SOURCES`` List of sources for the library. Files with extension ``.i`` will be identified as sources for the ``SWIG`` tool. Other files will be handled in - the standard way. This behavior can be overriden by specifying the variable + the standard way. This behavior can be overridden by specifying the variable ``SWIG_SOURCE_FILE_EXTENSIONS``. .. note:: @@ -156,6 +156,19 @@ ensure generated files will receive the required settings. If policy :policy:`CMP0086` is set to ``NEW``, ``-module <module_name>`` is passed to ``SWIG`` compiler. +``OUTPUT_DIR`` + Specify where to write the language specific files (swig ``-outdir`` option) + for the considered source file. If not specified, the other ways to define + the output directory applies (see ``OUTPUT_DIR`` option of + ``swig_add_library()`` command). + +``OUTFILE_DIR`` + Specify an output directory where the generated source file will be placed + (swig ``-o`` option) for the considered source file. If not specified, + ``OUTPUT_DIR`` source property will be used. If neither are specified, the + other ways to define output file directory applies (see ``OUTFILE_DIR`` + option of ``swig_add_library()`` command). + Target library properties can be set to apply same configuration to all SWIG input files. @@ -209,6 +222,11 @@ information about support files generated by ``SWIG`` interface compilation. This output property specifies the directory where support files will be generated. + .. note:: + + When source property ``OUTPUT_DIR`` is defined, multiple directories can be + specified as part of ``SWIG_SUPPORT_FILES_DIRECTORY``. + Some variables can be set to customize the behavior of ``swig_add_library`` as well as ``SWIG``: @@ -375,15 +393,24 @@ endfunction() function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) get_filename_component(swig_source_file_name_we "${infile}" NAME_WE) get_source_file_property(swig_source_file_cplusplus "${infile}" CPLUSPLUS) - - # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir - if(CMAKE_SWIG_OUTDIR) + get_source_file_property(swig_source_file_outdir "${infile}" OUTPUT_DIR) + get_source_file_property(swig_source_file_outfiledir "${infile}" OUTFILE_DIR) + + if (swig_source_file_outdir) + # use source file property + set(outdir "${swig_source_file_outdir}") + if (NOT swig_source_file_outfiledir) + set (swig_source_file_outfiledir "${outdir}") + endif() + elseif(CMAKE_SWIG_OUTDIR) set(outdir ${CMAKE_SWIG_OUTDIR}) else() set(outdir ${CMAKE_CURRENT_BINARY_DIR}) endif() - if(SWIG_OUTFILE_DIR) + if (swig_source_file_outfiledir) + set (outfiledir "${swig_source_file_outfiledir}") + elseif(SWIG_OUTFILE_DIR) set(outfiledir ${SWIG_OUTFILE_DIR}) else() set(outfiledir ${outdir}) @@ -725,6 +752,7 @@ function(SWIG_ADD_LIBRARY name) set(swig_generated_sources) set(swig_generated_timestamps) + set(swig_generated_outdirs "${outputdir}") list(LENGTH swig_dot_i_sources swig_sources_count) if (swig_sources_count GREATER "1") # option -interface cannot be used @@ -740,11 +768,16 @@ function(SWIG_ADD_LIBRARY name) "${workingdir}" swig_timestamp) list (APPEND swig_generated_timestamps "${swig_timestamp}") endif() + get_source_file_property(swig_source_file_outdir "${swig_it}" OUTPUT_DIR) + if (swig_source_file_outdir) + list (APPEND swig_generated_outdirs "${swig_source_file_outdir}") + endif() endforeach() + list(REMOVE_DUPLICATES swig_generated_outdirs) set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps}) if (UseSWIG_MODULE_VERSION VERSION_GREATER 1) - set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${outputdir}") + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${swig_generated_outdirs}) endif() add_library(${target_name} @@ -828,8 +861,8 @@ function(SWIG_ADD_LIBRARY name) set_target_properties (${target_name} PROPERTIES PREFIX "") endif () - # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files - set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}") + # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directories of support files + set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY ${swig_generated_outdirs}) # target property SWIG_SUPPORT_FILES lists principal proxy support files if (NOT SWIG_MODULE_${name}_NOPROXY) string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language) diff --git a/Modules/UseSWIG/ManageSupportFiles.cmake b/Modules/UseSWIG/ManageSupportFiles.cmake index 4a03900b7..6618fd512 100644 --- a/Modules/UseSWIG/ManageSupportFiles.cmake +++ b/Modules/UseSWIG/ManageSupportFiles.cmake @@ -4,7 +4,7 @@ if (ACTION STREQUAL "CLEAN") # Collect current list of generated files - file (GLOB files LIST_DIRECTORIES FALSE RELATIVE "${SUPPORT_FILES_WORKING_DIRECTORY}" "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + file (GLOB_RECURSE files LIST_DIRECTORIES TRUE RELATIVE "${SUPPORT_FILES_WORKING_DIRECTORY}" "${SUPPORT_FILES_WORKING_DIRECTORY}/*") if (files) # clean-up the output directory @@ -22,7 +22,7 @@ endif() if (ACTION STREQUAL "COPY") # Collect current list of generated files - file (GLOB files LIST_DIRECTORIES FALSE "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + file (GLOB files LIST_DIRECTORIES TRUE "${SUPPORT_FILES_WORKING_DIRECTORY}/*") if (files) # copy files to the output directory diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index 23d81b5fc..5100035b3 100644 --- a/Modules/WriteCompilerDetectionHeader.cmake +++ b/Modules/WriteCompilerDetectionHeader.cmake @@ -5,6 +5,8 @@ WriteCompilerDetectionHeader ---------------------------- +.. versionadded:: 3.1 + This module provides the function ``write_compiler_detection_header()``. This function can be used to generate a file suitable for preprocessor |