diff options
Diffstat (limited to 'Modules')
153 files changed, 3838 insertions, 2377 deletions
diff --git a/Modules/CMakeCUDACompilerABI.cu b/Modules/CMakeCUDACompilerABI.cu index 8463e86..b04d0ec 100644 --- a/Modules/CMakeCUDACompilerABI.cu +++ b/Modules/CMakeCUDACompilerABI.cu @@ -2,11 +2,8 @@ # error "A C or C++ compiler has been selected for CUDA" #endif -#include <cstdio> - -#include <cuda_runtime.h> - #include "CMakeCompilerABI.h" +#include "CMakeCompilerCUDAArch.h" int main(int argc, char* argv[]) { @@ -19,25 +16,7 @@ int main(int argc, char* argv[]) #endif static_cast<void>(argv); - int count = 0; - if (cudaGetDeviceCount(&count) != cudaSuccess || count == 0) { - std::fprintf(stderr, "No CUDA devices found.\n"); - return -1; - } - - int found = 0; - const char* sep = ""; - for (int device = 0; device < count; ++device) { - cudaDeviceProp prop; - if (cudaGetDeviceProperties(&prop, device) == cudaSuccess) { - std::printf("%s%d%d", sep, prop.major, prop.minor); - sep = ";"; - found = 1; - } - } - - if (!found) { - std::fprintf(stderr, "No CUDA architecture detected from any devices.\n"); + if (!cmakeCompilerCUDAArch()) { // Convince the compiler that the non-zero return value depends // on the info strings so they are not optimized out. return require ? -1 : 1; diff --git a/Modules/CMakeCompilerCUDAArch.h b/Modules/CMakeCompilerCUDAArch.h new file mode 100644 index 0000000..dcb030f --- /dev/null +++ b/Modules/CMakeCompilerCUDAArch.h @@ -0,0 +1,29 @@ +#include <cstdio> + +#include <cuda_runtime.h> + +static bool cmakeCompilerCUDAArch() +{ + int count = 0; + if (cudaGetDeviceCount(&count) != cudaSuccess || count == 0) { + std::fprintf(stderr, "No CUDA devices found.\n"); + return -1; + } + + bool found = false; + const char* sep = ""; + for (int device = 0; device < count; ++device) { + cudaDeviceProp prop; + if (cudaGetDeviceProperties(&prop, device) == cudaSuccess) { + std::printf("%s%d%d", sep, prop.major, prop.minor); + sep = ";"; + found = true; + } + } + + if (!found) { + std::fprintf(stderr, "No CUDA architecture detected from any devices.\n"); + } + + return found; +} diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 75d33e8..7eb93e2 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -65,12 +65,14 @@ function(compiler_id_detection outvar lang) VisualAge NVHPC PGI + CrayClang Cray TI FujitsuClang Fujitsu GHS Tasking + OrangeC ) if ("x${lang}" STREQUAL "xC") list(APPEND ordered_compilers @@ -102,6 +104,10 @@ function(compiler_id_detection outvar lang) set(ordered_compilers NVIDIA Clang) endif() + if("x${lang}" STREQUAL "xHIP") + set(ordered_compilers NVIDIA Clang) + endif() + if(CID_ID_DEFINE) foreach(Id ${ordered_compilers}) string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n") diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index 8ec6c66..6d7d17e 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -70,6 +70,10 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMClang "--version") set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMClang "armclang") + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS OrangeC ) + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_OrangeC "--version") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_OrangeC "occ \\(OrangeC\\) Version") + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP ) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V") set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C") diff --git a/Modules/CMakeDetermineCSharpCompiler.cmake b/Modules/CMakeDetermineCSharpCompiler.cmake index fe98469..652eb63 100644 --- a/Modules/CMakeDetermineCSharpCompiler.cmake +++ b/Modules/CMakeDetermineCSharpCompiler.cmake @@ -3,7 +3,7 @@ if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])") message(FATAL_ERROR - "C# is currently only supported for Microsoft Visual Studio 11 2012 and later.") + "C# is currently only supported for Microsoft Visual Studio 12 2013 and later.") endif() include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 53c5f78..6ac4dad 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -4,13 +4,13 @@ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) -if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR - ("${CMAKE_GENERATOR}" MATCHES "Ninja") OR - ("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[9][0-9])") ) ) +if(NOT ((CMAKE_GENERATOR MATCHES "Make") OR + (CMAKE_GENERATOR MATCHES "Ninja") OR + (CMAKE_GENERATOR MATCHES "Visual Studio (1|[9][0-9])"))) message(FATAL_ERROR "CUDA language not currently supported by \"${CMAKE_GENERATOR}\" generator") endif() -if(${CMAKE_GENERATOR} MATCHES "Visual Studio") +if(CMAKE_GENERATOR MATCHES "Visual Studio") if(DEFINED ENV{CUDAHOSTCXX} OR DEFINED CMAKE_CUDA_HOST_COMPILER) message(WARNING "Visual Studio does not support specifying CUDAHOSTCXX or CMAKE_CUDA_HOST_COMPILER. Using the C++ compiler provided by Visual Studio.") endif() @@ -62,7 +62,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) - if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + if(CMAKE_GENERATOR MATCHES "Visual Studio") # We will not know CMAKE_CUDA_COMPILER until the main compiler id step # below extracts it, but we do know that the compiler id will be NVIDIA. set(CMAKE_CUDA_COMPILER_ID "NVIDIA") @@ -78,176 +78,18 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) message(FATAL_ERROR "Clang with CUDA is not yet supported on Windows. See CMake issue #20776.") endif() - # Find the CUDA toolkit. We store the CMAKE_CUDA_COMPILER_TOOLKIT_ROOT, CMAKE_CUDA_COMPILER_TOOLKIT_VERSION and - # CMAKE_CUDA_COMPILER_LIBRARY_ROOT in CMakeCUDACompiler.cmake so FindCUDAToolkit can avoid searching on future - # runs and the toolkit is the same. - # This is very similar to FindCUDAToolkit, but somewhat simplified since we can issue fatal errors - # if we fail and we don't need to account for searching the libraries. - - # For NVCC we can easily deduce the SDK binary directory from the compiler path. - if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") - set(_CUDA_NVCC_EXECUTABLE "${CMAKE_CUDA_COMPILER}") - else() - # Search using CUDAToolkit_ROOT and then CUDA_PATH for equivalence with FindCUDAToolkit. - # In FindCUDAToolkit CUDAToolkit_ROOT is searched automatically due to being in a find_package(). - # First we search candidate non-default paths to give them priority. - find_program(_CUDA_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${CUDAToolkit_ROOT} - ENV CUDAToolkit_ROOT - ENV CUDA_PATH - PATH_SUFFIXES bin - NO_DEFAULT_PATH - ) - - # If we didn't find NVCC, then try the default paths. - find_program(_CUDA_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATH_SUFFIXES bin - ) - - # If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error. - if(NOT _CUDA_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) - set(fail_base "Could not find nvcc executable in path specified by") - - if(DEFINED CUDAToolkit_ROOT) - message(FATAL_ERROR "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}") - elseif(DEFINED ENV{CUDAToolkit_ROOT}) - message(FATAL_ERROR "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}") - endif() - endif() - - # CUDAToolkit_ROOT cmake/env variable not specified, try platform defaults. - # - # - Linux: /usr/local/cuda-X.Y - # - macOS: /Developer/NVIDIA/CUDA-X.Y - # - Windows: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y - # - # 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 _CUDA_NVCC_EXECUTABLE) - if(UNIX) - if(NOT APPLE) - set(platform_base "/usr/local/cuda-") - else() - set(platform_base "/Developer/NVIDIA/CUDA-") - endif() - else() - set(platform_base "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v") - endif() - - # Build out a descending list of possible cuda installations, e.g. - file(GLOB possible_paths "${platform_base}*") - # Iterate the glob results and create a descending list. - set(versions) - foreach(p ${possible_paths}) - # Extract version number from end of string - string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p}) - if(IS_DIRECTORY ${p} AND p_version) - list(APPEND versions ${p_version}) - endif() - endforeach() - - # Sort numerically in descending order, so we try the newest versions first. - list(SORT versions COMPARE NATURAL ORDER DESCENDING) - - # With a descending list of versions, populate possible paths to search. - set(search_paths) - foreach(v ${versions}) - list(APPEND search_paths "${platform_base}${v}") - endforeach() - - # Force the global default /usr/local/cuda to the front on Unix. - if(UNIX) - list(INSERT search_paths 0 "/usr/local/cuda") - endif() - - # Now search for nvcc again using the platform default search paths. - find_program(_CUDA_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${search_paths} - PATH_SUFFIXES bin - ) - - # We are done with these variables now, cleanup. - unset(platform_base) - unset(possible_paths) - unset(versions) - unset(search_paths) - - if(NOT _CUDA_NVCC_EXECUTABLE) - message(FATAL_ERROR "Failed to find nvcc.\nCompiler ${CMAKE_CUDA_COMPILER_ID} requires the CUDA toolkit. Please set the CUDAToolkit_ROOT variable.") - endif() - endif() - endif() - - # Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) - # each of which has a different layout, we need to extract the CUDA toolkit root from the compiler - # itself, allowing us to support numerous different scattered toolkit layouts - execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" - OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) - if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)") - get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}" ABSOLUTE) - else() - get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) - get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) - endif() - - if(_CUDA_NVCC_OUT MATCHES "\\#\\$ NVVMIR_LIBRARY_DIR=([^\r\n]*)") - get_filename_component(_CUDA_NVVMIR_LIBRARY_DIR "${CMAKE_MATCH_1}" ABSOLUTE) - - #We require the path to end in `/nvvm/libdevice' - if(_CUDA_NVVMIR_LIBRARY_DIR MATCHES "nvvm/libdevice$") - get_filename_component(_CUDA_NVVMIR_LIBRARY_DIR "${_CUDA_NVVMIR_LIBRARY_DIR}/../.." ABSOLUTE) - set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR "${_CUDA_NVVMIR_LIBRARY_DIR}") - endif() - - unset(_CUDA_NVVMIR_LIBRARY_DIR) - unset(_cuda_nvvmir_dir_name) - endif() - unset(_CUDA_NVCC_OUT) + # Find the CUDA toolkit to get: + # - CMAKE_CUDA_COMPILER_TOOLKIT_VERSION + # - CMAKE_CUDA_COMPILER_TOOLKIT_ROOT + # - CMAKE_CUDA_COMPILER_LIBRARY_ROOT + # We save them in CMakeCUDACompiler.cmake so FindCUDAToolkit can + # avoid searching on future runs and the toolkit is the same. + # Match arguments with cmake_cuda_architectures_all call. + include(Internal/CMakeCUDAFindToolkit) + cmake_cuda_find_toolkit(CUDA CMAKE_CUDA_COMPILER_) set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/nvlink${CMAKE_EXECUTABLE_SUFFIX}") set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") - - # 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. - if(DEFINED CMAKE_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR) - set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR}") - elseif(EXISTS "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/nvvm/libdevice") - set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}") - elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/nvvm/libdevice") - set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_SYSROOT_LINK}/usr/lib/cuda") - elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/nvvm/libdevice") - set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/cuda") - else() - message(FATAL_ERROR "Couldn't find CUDA library root.") - endif() - unset(CMAKE_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR) - - # 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() - - # For regular nvcc we the toolkit version is the same as the compiler version and we can parse it from the vendor test output. - # For Clang we need to invoke nvcc to get version output. - if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") - if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") - execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE CMAKE_CUDA_COMPILER_ID_OUTPUT) - endif() - - if(CMAKE_CUDA_COMPILER_ID_OUTPUT MATCHES [=[V([0-9]+\.[0-9]+\.[0-9]+)]=]) - set(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION "${CMAKE_MATCH_1}") - endif() endif() set(CMAKE_CUDA_COMPILER_ID_FLAGS_ALWAYS "-v") @@ -269,23 +111,9 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() endif() - # Rest of the code treats an empty value as equivalent to "use the defaults". - # Error out early to prevent confusing errors as a result of this. - # Note that this also catches invalid non-numerical values such as "a". - if(DEFINED CMAKE_CUDA_ARCHITECTURES) - if(CMAKE_CUDA_ARCHITECTURES STREQUAL "") - message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES must be non-empty if set.") - elseif(CMAKE_CUDA_ARCHITECTURES AND NOT CMAKE_CUDA_ARCHITECTURES MATCHES "^([0-9]+a?(-real|-virtual)?(;[0-9]+a?(-real|-virtual)?|;)*|all|all-major|native)$") - message(FATAL_ERROR - "CMAKE_CUDA_ARCHITECTURES:\n" - " ${CMAKE_CUDA_ARCHITECTURES}\n" - "is not one of the following:\n" - " * a semicolon-separated list of integers, each optionally\n" - " followed by '-real' or '-virtual'\n" - " * a special value: all, all-major, native\n" - ) - endif() - endif() + # If the user set CMAKE_CUDA_ARCHITECTURES, validate its value. + include(Internal/CMakeCUDAArchitecturesValidate) + cmake_cuda_architectures_validate(CUDA) if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") # Clang doesn't automatically select an architecture supported by the SDK. @@ -306,7 +134,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) CMAKE_DETERMINE_COMPILER_ID(CUDA CUDAFLAGS CMakeCUDACompilerId.cu) - if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + if(CMAKE_GENERATOR MATCHES "Visual Studio") # Now that we have the path to nvcc, we can compute the toolkit root. get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER}" DIRECTORY) get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) @@ -316,7 +144,12 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) set(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION ${CMAKE_CUDA_COMPILER_VERSION}) endif() - include(${CMAKE_ROOT}/Modules/CUDA/architectures.cmake) + include(Internal/CMakeCUDAArchitecturesAll) + # From CMAKE_CUDA_COMPILER_TOOLKIT_VERSION and CMAKE_CUDA_COMPILER_{ID,VERSION}, get: + # - CMAKE_CUDA_ARCHITECTURES_ALL + # - CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR + # Match arguments with cmake_cuda_find_toolkit call. + cmake_cuda_architectures_all(CUDA CMAKE_CUDA_COMPILER_) _cmake_find_compiler_sysroot(CUDA) endif() @@ -331,31 +164,13 @@ if(MSVC_CUDA_ARCHITECTURE_ID) "set(MSVC_CUDA_ARCHITECTURE_ID ${MSVC_CUDA_ARCHITECTURE_ID})") endif() -if(${CMAKE_GENERATOR} MATCHES "Visual Studio") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_LINKER}") - set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "") - set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "") - set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") - - # We do not currently detect CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES but we - # do need to detect CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT from the compiler by - # looking at which cudart library exists in the implicit link libraries passed - # to the host linker. - if(CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT MATCHES "link\\.exe [^\n]*cudart_static\\.lib") - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC") - elseif(CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT MATCHES "link\\.exe [^\n]*cudart\\.lib") - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED") - else() - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "NONE") - endif() - set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT - "set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")") -elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") - string(REGEX MATCHALL "-target-cpu sm_([0-9]+)" target_cpus "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") +if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") + string(REGEX MATCHALL "-target-cpu sm_([0-9]+)" _clang_target_cpus "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") - foreach(cpu ${target_cpus}) - string(REGEX MATCH "-target-cpu sm_([0-9]+)" dont_care "${cpu}") - list(APPEND architectures_detected "${CMAKE_MATCH_1}") + foreach(_clang_target_cpu ${_clang_target_cpus}) + if(_clang_target_cpu MATCHES "-target-cpu sm_([0-9]+)") + list(APPEND CMAKE_CUDA_ARCHITECTURES_DEFAULT "${CMAKE_MATCH_1}") + endif() endforeach() # Find target directory when crosscompiling. @@ -411,141 +226,32 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "${_CUDA_LIBRARY_DIR}") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") -elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") - set(_nvcc_log "") - string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") - if(_nvcc_output_orig MATCHES "#\\\$ +PATH= *([^\n]*)\n") - set(_nvcc_path "${CMAKE_MATCH_1}") - string(APPEND _nvcc_log " found 'PATH=' string: [${_nvcc_path}]\n") - string(REPLACE ":" ";" _nvcc_path "${_nvcc_path}") - else() - set(_nvcc_path "") - string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") - string(APPEND _nvcc_log " no 'PATH=' string found in nvcc output:${_nvcc_output_log}\n") - endif() - if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n") - set(_nvcc_libraries "${CMAKE_MATCH_1}") - string(APPEND _nvcc_log " found 'LIBRARIES=' string: [${_nvcc_libraries}]\n") - else() - set(_nvcc_libraries "") - string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") - string(APPEND _nvcc_log " no 'LIBRARIES=' string found in nvcc output:${_nvcc_output_log}\n") - endif() - - set(_nvcc_link_line "") - if(_nvcc_libraries) - # Remove variable assignments. - string(REGEX REPLACE "#\\\$ *[^= ]+=[^\n]*\n" "" _nvcc_output "${_nvcc_output_orig}") - # Encode [] characters that break list expansion. - string(REPLACE "[" "{==={" _nvcc_output "${_nvcc_output}") - string(REPLACE "]" "}===}" _nvcc_output "${_nvcc_output}") - # Split lines. - string(REGEX REPLACE "\n+(#\\\$ )?" ";" _nvcc_output "${_nvcc_output}") - foreach(line IN LISTS _nvcc_output) - set(_nvcc_output_line "${line}") - string(REPLACE "{==={" "[" _nvcc_output_line "${_nvcc_output_line}") - string(REPLACE "}===}" "]" _nvcc_output_line "${_nvcc_output_line}") - string(APPEND _nvcc_log " considering line: [${_nvcc_output_line}]\n") - if("${_nvcc_output_line}" MATCHES "^ *nvlink") - string(APPEND _nvcc_log " ignoring nvlink line\n") - elseif(_nvcc_libraries) - if("${_nvcc_output_line}" MATCHES "(@\"?((tmp/)?a\\.exe\\.res)\"?)") - set(_nvcc_link_res_arg "${CMAKE_MATCH_1}") - set(_nvcc_link_res_file "${CMAKE_MATCH_2}") - set(_nvcc_link_res "${CMAKE_PLATFORM_INFO_DIR}/CompilerIdCUDA/${_nvcc_link_res_file}") - if(EXISTS "${_nvcc_link_res}") - file(READ "${_nvcc_link_res}" _nvcc_link_res_content) - string(REPLACE "${_nvcc_link_res_arg}" "${_nvcc_link_res_content}" _nvcc_output_line "${_nvcc_output_line}") - endif() - endif() - string(FIND "${_nvcc_output_line}" "${_nvcc_libraries}" _nvcc_libraries_pos) - if(NOT _nvcc_libraries_pos EQUAL -1) - set(_nvcc_link_line "${_nvcc_output_line}") - string(APPEND _nvcc_log " extracted link line: [${_nvcc_link_line}]\n") - endif() - endif() - endforeach() - endif() - - if(_nvcc_link_line) - if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_LINKER}") - else() - #extract the compiler that is being used for linking - separate_arguments(_nvcc_link_line_args UNIX_COMMAND "${_nvcc_link_line}") - list(GET _nvcc_link_line_args 0 _nvcc_host_link_launcher) - if(IS_ABSOLUTE "${_nvcc_host_link_launcher}") - string(APPEND _nvcc_log " extracted link launcher absolute path: [${_nvcc_host_link_launcher}]\n") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}") - else() - string(APPEND _nvcc_log " extracted link launcher name: [${_nvcc_host_link_launcher}]\n") - find_program(_nvcc_find_host_link_launcher - NAMES ${_nvcc_host_link_launcher} - PATHS ${_nvcc_path} NO_DEFAULT_PATH) - find_program(_nvcc_find_host_link_launcher - NAMES ${_nvcc_host_link_launcher}) - if(_nvcc_find_host_link_launcher) - string(APPEND _nvcc_log " found link launcher absolute path: [${_nvcc_find_host_link_launcher}]\n") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_find_host_link_launcher}") - else() - string(APPEND _nvcc_log " could not find link launcher absolute path\n") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}") - endif() - unset(_nvcc_find_host_link_launcher CACHE) - endif() - endif() - #prefix the line with cuda-fake-ld so that implicit link info believes it is - #a link line - set(_nvcc_link_line "cuda-fake-ld ${_nvcc_link_line}") - CMAKE_PARSE_IMPLICIT_LINK_INFO("${_nvcc_link_line}" - CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES - CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES - CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES - log - "${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}" - LANGUAGE CUDA) - - # Detect CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT from the compiler by looking at which - # cudart library exists in the implicit link libraries passed to the host linker. - # This is required when a project sets the cuda runtime library as part of the - # initial flags. - if(";${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart_static(\.lib)?;]]) - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC") - elseif(";${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart(\.lib)?;]]) - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED") - else() - set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "NONE") - endif() - set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT - "set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")") + # Don't leak variables unnecessarily to user code. + unset(_CUDA_INCLUDE_DIR) + unset(_CUDA_LIBRARY_DIR) + unset(_CUDA_TARGET_DIR) + unset(_CUDA_TARGET_NAME) +elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + include(Internal/CMakeNVCCParseImplicitInfo) + # Parse CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT to get: + # - CMAKE_CUDA_ARCHITECTURES_DEFAULT + # - CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES + # - CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES + # - CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES + # - CMAKE_CUDA_HOST_LINK_LAUNCHER + # - CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT + # - CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES + # Match arguments with cmake_nvcc_filter_implicit_info call in CMakeTestCUDACompiler. + cmake_nvcc_parse_implicit_info(CUDA CMAKE_CUDA_) - message(CONFIGURE_LOG - "Parsed CUDA nvcc implicit link information:\n${_nvcc_log}\n${log}\n\n") - else() - message(CONFIGURE_LOG - "Failed to parse CUDA nvcc implicit link information:\n${_nvcc_log}\n\n") - message(FATAL_ERROR "Failed to extract nvcc implicit link line.") - endif() + set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT + "set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")") endif() -# CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES is detected above as the list of -# libraries that the CUDA compiler implicitly passes to the host linker. -# CMake invokes the host linker directly and so needs to pass these libraries. -# We filter out those that should not be passed unconditionally both here -# and from CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES in CMakeTestCUDACompiler. -set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE - # The CUDA runtime libraries are controlled by CMAKE_CUDA_RUNTIME_LIBRARY. - cudart cudart.lib - cudart_static cudart_static.lib - cudadevrt cudadevrt.lib - - # Dependencies of the CUDA static runtime library on Linux hosts. - rt - pthread - dl - ) -list(REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) +include(Internal/CMakeCUDAFilterImplicitLibs) +# Filter out implicit link libraries that should not be passed unconditionally. +cmake_cuda_filter_implicit_libs(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES) if(CMAKE_CUDA_COMPILER_SYSROOT) string(CONCAT _SET_CMAKE_CUDA_COMPILER_SYSROOT @@ -555,55 +261,17 @@ else() set(_SET_CMAKE_CUDA_COMPILER_SYSROOT "") endif() -# Determine CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES -if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") - set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) - string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") - if(_nvcc_output_orig MATCHES "#\\\$ +INCLUDES= *([^\n]*)\n") - set(_nvcc_includes "${CMAKE_MATCH_1}") - string(APPEND _nvcc_log " found 'INCLUDES=' string: [${_nvcc_includes}]\n") - else() - set(_nvcc_includes "") - string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") - string(APPEND _nvcc_log " no 'INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n") - endif() - if(_nvcc_includes) - # across all operating system each include directory is prefixed with -I - separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_includes}") - foreach(line IN LISTS _nvcc_output) - string(REGEX REPLACE "^-I" "" line "${line}") - get_filename_component(line "${line}" ABSOLUTE) - list(APPEND CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "${line}") - endforeach() - - message(CONFIGURE_LOG - "Parsed CUDA nvcc include information:\n${_nvcc_log}\n${log}\n\n") - else() - message(CONFIGURE_LOG - "Failed to detect CUDA nvcc include information:\n${_nvcc_log}\n\n") - endif() - - string(REGEX MATCHALL "-arch compute_([0-9]+)" target_cpus "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") - - foreach(cpu ${target_cpus}) - string(REGEX MATCH "-arch compute_([0-9]+)" dont_care "${cpu}") - list(APPEND architectures_detected "${CMAKE_MATCH_1}") - endforeach() -endif() - -# If the user didn't set the architectures, then set them to a default. -# If the user did, then make sure those architectures worked. +# If the user did not set CMAKE_CUDA_ARCHITECTURES, use the compiler's default. if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "") cmake_policy(GET CMP0104 _CUDA_CMP0104) - if(NOT CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" OR _CUDA_CMP0104 STREQUAL "NEW") - set(CMAKE_CUDA_ARCHITECTURES "${architectures_detected}" CACHE STRING "CUDA architectures") - + set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES_DEFAULT}" CACHE STRING "CUDA architectures") if(NOT CMAKE_CUDA_ARCHITECTURES) message(FATAL_ERROR "Failed to detect a default CUDA architecture.\n\nCompiler output:\n${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") endif() endif() endif() +unset(CMAKE_CUDA_ARCHITECTURES_DEFAULT) # configure all variables set in this file configure_file(${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in @@ -611,14 +279,5 @@ configure_file(${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in @ONLY ) -# Don't leak variables unnecessarily to user code. -unset(_CUDA_INCLUDE_DIR CACHE) -unset(_CUDA_NVCC_EXECUTABLE CACHE) -unset(_CUDA_LIBRARY_DIR) -unset(_CUDA_TARGET_DIR) -unset(_CUDA_TARGET_NAME) - -unset(architectures_detected) - set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX") set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX") diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 13bfeec..efc18f9 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -26,13 +26,13 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) if(DEFINED CMAKE_${lang}_VERBOSE_COMPILE_FLAG) set(COMPILE_DEFINITIONS "${CMAKE_${lang}_VERBOSE_COMPILE_FLAG}") endif() - if(lang STREQUAL "CUDA") - if(CMAKE_CUDA_ARCHITECTURES STREQUAL "native") + if(lang MATCHES "^(CUDA|HIP)$") + if(CMAKE_${lang}_ARCHITECTURES STREQUAL "native") # We are about to detect the native architectures, so we do # not yet know them. Use all architectures during detection. - set(CMAKE_CUDA_ARCHITECTURES "all") + set(CMAKE_${lang}_ARCHITECTURES "all") endif() - set(CMAKE_CUDA_RUNTIME_LIBRARY "Static") + set(CMAKE_${lang}_RUNTIME_LIBRARY "Static") endif() if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC") # Avoid adding our own platform standard libraries for compilers @@ -139,38 +139,46 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) endif() set(CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES "${_CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT}" PARENT_SCOPE) - # Parse implicit linker information for this language, if available. - set(implicit_dirs "") - set(implicit_objs "") - set(implicit_libs "") - set(implicit_fwks "") - if(CMAKE_${lang}_VERBOSE_FLAG) - CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log - "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}" - COMPUTE_IMPLICIT_OBJECTS implicit_objs - LANGUAGE ${lang}) - message(CONFIGURE_LOG - "Parsed ${lang} implicit link information:\n${log}\n\n") - endif() - # for VS IDE Intel Fortran we have to figure out the - # implicit link path for the fortran run time using - # a try-compile - if("${lang}" MATCHES "Fortran" - AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio") - message(CHECK_START "Determine Intel Fortran Compiler Implicit Link Path") - # Build a sample project which reports symbols. - try_compile(IFORT_LIB_PATH_COMPILED - PROJECT IntelFortranImplicit - SOURCE_DIR ${CMAKE_ROOT}/Modules/IntelVSImplicitPath - BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath - CMAKE_FLAGS - "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}" - OUTPUT_VARIABLE _output) - file(WRITE - "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt" - "${_output}") - include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL) - message(CHECK_PASS "done") + if(_CMAKE_${lang}_IMPLICIT_LINK_INFORMATION_DETERMINED_EARLY) + # Use implicit linker information detected during compiler id step. + set(implicit_dirs "${CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES}") + set(implicit_objs "") + set(implicit_libs "${CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES}") + set(implicit_fwks "${CMAKE_${lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}") + else() + # Parse implicit linker information for this language, if available. + set(implicit_dirs "") + set(implicit_objs "") + set(implicit_libs "") + set(implicit_fwks "") + if(CMAKE_${lang}_VERBOSE_FLAG) + CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log + "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}" + COMPUTE_IMPLICIT_OBJECTS implicit_objs + LANGUAGE ${lang}) + message(CONFIGURE_LOG + "Parsed ${lang} implicit link information:\n${log}\n\n") + endif() + # for VS IDE Intel Fortran we have to figure out the + # implicit link path for the fortran run time using + # a try-compile + if("${lang}" MATCHES "Fortran" + AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio") + message(CHECK_START "Determine Intel Fortran Compiler Implicit Link Path") + # Build a sample project which reports symbols. + try_compile(IFORT_LIB_PATH_COMPILED + PROJECT IntelFortranImplicit + SOURCE_DIR ${CMAKE_ROOT}/Modules/IntelVSImplicitPath + BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath + CMAKE_FLAGS + "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}" + OUTPUT_VARIABLE _output) + file(WRITE + "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt" + "${_output}") + include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL) + message(CHECK_PASS "done") + endif() endif() # Implicit link libraries cannot be used explicitly for multiple diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 2cf9853..4f1eaba 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -174,6 +174,32 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() + # FIXME(LLVMFlang): It does not provide predefines identifying the MSVC ABI or architecture. + # It should be taught to define _MSC_VER and its _M_* architecture flags. + if("x${lang}" STREQUAL "xFortran" AND "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xLLVMFlang") + # Parse the target triple to detect information we should later be able + # to get during preprocessing above, once LLVMFlang provides it. + if(COMPILER_${lang}_PRODUCED_OUTPUT MATCHES "-triple ([0-9a-z_]*)-.*windows-msvc([0-9]+)\\.([0-9]+)") + set(CMAKE_${lang}_SIMULATE_ID "MSVC") + set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") + set(arch ${CMAKE_MATCH_1}) + if(arch STREQUAL "x86_64") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "x64") + elseif(arch STREQUAL "aarch64") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64") + elseif(arch STREQUAL "arm64ec") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64EC") + elseif(arch MATCHES "^i[3-9]86$") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "X86") + else() + message(FATAL_ERROR "LLVMFlang target architecture unrecognized: ${arch}") + endif() + set(MSVC_${lang}_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}") + elseif(COMPILER_${lang}_PRODUCED_OUTPUT MATCHES "-triple ([0-9a-z_]*)-.*windows-gnu") + set(CMAKE_${lang}_SIMULATE_ID "GNU") + endif() + endif() + if (COMPILER_QNXNTO AND (CMAKE_${lang}_COMPILER_ID STREQUAL "GNU" OR CMAKE_${lang}_COMPILER_ID STREQUAL "LCC")) execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" @@ -605,6 +631,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} if(CMAKE_OSX_SYSROOT) set(id_sdkroot "SDKROOT = \"${CMAKE_OSX_SYSROOT}\";") if(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ii][Pp][Hh][Oo][Nn][Ee]" OR + CMAKE_OSX_SYSROOT MATCHES "(^|/)[Xx][Rr]" OR CMAKE_OSX_SYSROOT MATCHES "(^|/)[Aa][Pp][Pp][Ll][Ee][Tt][Vv]") set(id_product_type "com.apple.product-type.bundle.unit-test") elseif(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ww][Aa][Tt][Cc][Hh]") diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 8cbaf70..392f0f1 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -98,6 +98,9 @@ else() set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST # Get verbose output to help distinguish compilers. "-v" + + # Try compiling to an object file only, with verbose output. + "-v -c" ) set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. @@ -108,6 +111,10 @@ else() ) endif() +if(CMAKE_Fortran_COMPILER_TARGET) + set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST "-v -c --target=${CMAKE_Fortran_COMPILER_TARGET}") +endif() + # Build a small source file to identify the compiler. if(NOT CMAKE_Fortran_COMPILER_ID_RUN) set(CMAKE_Fortran_COMPILER_ID_RUN 1) @@ -227,6 +234,49 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN) endif() endif() +if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "LLVMFlang;MSVC") + # With LLVMFlang targeting the MSVC ABI we link using lld-link. + # Detect the implicit link information from the compiler driver + # so we can explicitly pass it to the linker. + include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) + set(_LLVMFlang_COMMAND "${CMAKE_Fortran_COMPILER}" "-###" ${CMAKE_CURRENT_LIST_DIR}/CMakeFortranCompilerABI.F) + if(CMAKE_Fortran_COMPILER_TARGET) + list(APPEND _LLVMFlang_COMMAND --target=${CMAKE_Fortran_COMPILER_TARGET}) + endif() + execute_process(COMMAND ${_LLVMFlang_COMMAND} + OUTPUT_VARIABLE _LLVMFlang_OUTPUT + ERROR_VARIABLE _LLVMFlang_OUTPUT + RESULT_VARIABLE _LLVMFlang_RESULT) + string(JOIN "\" \"" _LLVMFlang_COMMAND ${_LLVMFlang_COMMAND}) + message(CONFIGURE_LOG + "Running the Fortran compiler: \"${_LLVMFlang_COMMAND}\"\n" + "${_LLVMFlang_OUTPUT}" + ) + if(_LLVMFlang_RESULT EQUAL 0) + cmake_parse_implicit_link_info("${_LLVMFlang_OUTPUT}" + CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES + CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES + CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES + log + "${CMAKE_Fortran_IMPLICIT_OBJECT_REGEX}" + LANGUAGE Fortran) + message(CONFIGURE_LOG + "Parsed Fortran implicit link information:\n" + "${log}\n" + ) + set(_CMAKE_Fortran_IMPLICIT_LINK_INFORMATION_DETERMINED_EARLY 1) + if("x${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID}" STREQUAL "xARM64") + # FIXME(LLVMFlang): It does not add `-defaultlib:` fields to object + # files to specify link dependencies on its runtime libraries. + # For now, we add them ourselves. + list(APPEND CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "clang_rt.builtins-aarch64.lib") + endif() + endif() + unset(_LLVMFlang_COMMAND) + unset(_LLVMFlang_OUTPUT) + unset(_LLVMFlang_RESULT) +endif() + if (NOT _CMAKE_TOOLCHAIN_LOCATION) get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Fortran_COMPILER}" PATH) endif () diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index 9a40e82..e667099 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -5,11 +5,29 @@ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake) -if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR - ("${CMAKE_GENERATOR}" MATCHES "Ninja") ) ) +if(NOT ((CMAKE_GENERATOR MATCHES "Make") OR + (CMAKE_GENERATOR MATCHES "Ninja"))) message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator") endif() +if(NOT CMAKE_HIP_PLATFORM) + execute_process(COMMAND hipconfig --platform + OUTPUT_VARIABLE _CMAKE_HIPCONFIG_PLATFORM OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT + ) + if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND _CMAKE_HIPCONFIG_PLATFORM MATCHES "^(nvidia|nvcc)$") + set(CMAKE_HIP_PLATFORM "nvidia" CACHE STRING "HIP platform" FORCE) + else() + set(CMAKE_HIP_PLATFORM "amd" CACHE STRING "HIP platform" FORCE) + endif() +endif() +if(NOT CMAKE_HIP_PLATFORM MATCHES "^(amd|nvidia)$") + message(FATAL_ERROR + "The CMAKE_HIP_PLATFORM has unsupported value:\n" + " '${CMAKE_HIP_PLATFORM}'\n" + "It must be 'amd' or 'nvidia'." + ) +endif() if(NOT CMAKE_HIP_COMPILER) set(CMAKE_HIP_COMPILER_INIT NOTFOUND) @@ -34,15 +52,19 @@ if(NOT CMAKE_HIP_COMPILER) # finally list compilers to try if(NOT CMAKE_HIP_COMPILER_INIT) - set(CMAKE_HIP_COMPILER_LIST clang++) + if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") + set(CMAKE_HIP_COMPILER_LIST nvcc) + elseif(CMAKE_HIP_PLATFORM STREQUAL "amd") + set(CMAKE_HIP_COMPILER_LIST clang++) - # Look for the Clang coming with ROCm to support HIP. - execute_process(COMMAND hipconfig --hipclangpath - OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH - RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT - ) - if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}") - set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}") + # Look for the Clang coming with ROCm to support HIP. + execute_process(COMMAND hipconfig --hipclangpath + OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH + RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT + ) + if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}") + set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}") + endif() endif() endif() @@ -63,17 +85,65 @@ mark_as_advanced(CMAKE_HIP_COMPILER) if(NOT CMAKE_HIP_COMPILER_ID_RUN) set(CMAKE_HIP_COMPILER_ID_RUN 1) - # Try to identify the compiler. + include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) + + # We determine the vendor to use the right flags for detection right away. + # The main compiler identification is still needed below to extract other information. + list(APPEND CMAKE_HIP_COMPILER_ID_VENDORS NVIDIA Clang) + set(CMAKE_HIP_COMPILER_ID_VENDOR_REGEX_NVIDIA "nvcc: NVIDIA \\(R\\) Cuda compiler driver") + set(CMAKE_HIP_COMPILER_ID_VENDOR_REGEX_Clang "(clang version)") + CMAKE_DETERMINE_COMPILER_ID_VENDOR(HIP "--version") + + if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + # Find the CUDA toolkit to get: + # - CMAKE_HIP_COMPILER_CUDA_TOOLKIT_VERSION + # - CMAKE_HIP_COMPILER_CUDA_TOOLKIT_ROOT + # - CMAKE_HIP_COMPILER_CUDA_LIBRARY_ROOT + # We save them in CMakeHIPCompiler.cmake. + # Match arguments with cmake_cuda_architectures_all call. + include(Internal/CMakeCUDAFindToolkit) + cmake_cuda_find_toolkit(HIP CMAKE_HIP_COMPILER_CUDA_) + + # If the user set CMAKE_HIP_ARCHITECTURES, validate its value. + include(Internal/CMakeCUDAArchitecturesValidate) + cmake_cuda_architectures_validate(HIP) + + if(NOT CMAKE_HIP_HOST_COMPILER AND NOT $ENV{HIPHOSTCXX} STREQUAL "") + get_filename_component(CMAKE_HIP_HOST_COMPILER $ENV{HIPHOSTCXX} PROGRAM) + if(NOT EXISTS "${CMAKE_HIP_HOST_COMPILER}") + message(FATAL_ERROR "Could not find compiler set in environment variable HIPHOSTCXX:\n$ENV{HIPHOSTCXX}.\n${CMAKE_HIP_HOST_COMPILER}") + endif() + endif() + endif() + + if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang") + list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-v") + elseif(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + # Tell nvcc to treat .hip files as CUDA sources. + list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-x cu -v") + if(CMAKE_HIP_HOST_COMPILER) + string(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST " -ccbin=\"${CMAKE_HIP_HOST_COMPILER}\"") + endif() + endif() + + # We perform compiler identification for a second time to extract implicit linking info. + # We need to unset the compiler ID otherwise CMAKE_DETERMINE_COMPILER_ID() doesn't work. set(CMAKE_HIP_COMPILER_ID) set(CMAKE_HIP_PLATFORM_ID) file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in CMAKE_HIP_COMPILER_ID_PLATFORM_CONTENT) - list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-v") - - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(HIP HIPFLAGS CMakeHIPCompilerId.hip) + if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + include(Internal/CMakeCUDAArchitecturesAll) + # From CMAKE_HIP_COMPILER_CUDA_TOOLKIT_VERSION and CMAKE_HIP_COMPILER_{ID,VERSION}, get: + # - CMAKE_HIP_ARCHITECTURES_ALL + # - CMAKE_HIP_ARCHITECTURES_ALL_MAJOR + # Match arguments with cmake_cuda_find_toolkit call. + cmake_cuda_architectures_all(HIP CMAKE_HIP_COMPILER_CUDA_) + endif() + _cmake_find_compiler_sysroot(HIP) endif() @@ -104,56 +174,61 @@ if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT) message(FATAL_ERROR "Failed to find ROCm root directory.") endif() -# Normally implicit link information is not detected until -cmake_parse_implicit_link_info("${CMAKE_HIP_COMPILER_PRODUCED_OUTPUT}" - _CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS - _CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS - _CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS - _CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG - "" LANGUAGE HIP) -message(CONFIGURE_LOG - "Parsed HIP implicit link information from compiler id output:\n${_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG}\n\n") -cmake_parse_library_architecture(HIP "${_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS}" "" CMAKE_HIP_LIBRARY_ARCHITECTURE) -if(CMAKE_HIP_LIBRARY_ARCHITECTURE) +if(CMAKE_HIP_PLATFORM STREQUAL "amd") + # For this platform we need the hip-lang cmake package. + + # Normally implicit link information is not detected until ABI detection, + # but we need to populate CMAKE_HIP_LIBRARY_ARCHITECTURE to find hip-lang. + cmake_parse_implicit_link_info("${CMAKE_HIP_COMPILER_PRODUCED_OUTPUT}" + _CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS + _CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS + _CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS + _CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG + "" LANGUAGE HIP) message(CONFIGURE_LOG - "Parsed HIP library architecture from compiler id output: ${CMAKE_HIP_LIBRARY_ARCHITECTURE}\n") -endif() -unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS) -unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS) -unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS) -unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG) - -if(NOT CMAKE_HIP_COMPILER_ROCM_LIB) - set(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS - "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib" - "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib64" - ) + "Parsed HIP implicit link information from compiler id output:\n${_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG}\n\n") + cmake_parse_library_architecture(HIP "${_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS}" "" CMAKE_HIP_LIBRARY_ARCHITECTURE) if(CMAKE_HIP_LIBRARY_ARCHITECTURE) - list(APPEND _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/${CMAKE_HIP_LIBRARY_ARCHITECTURE}") + message(CONFIGURE_LOG + "Parsed HIP library architecture from compiler id output: ${CMAKE_HIP_LIBRARY_ARCHITECTURE}\n") endif() - foreach(dir IN LISTS _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS) - if(EXISTS "${dir}/cmake/hip-lang/hip-lang-config.cmake") - set(CMAKE_HIP_COMPILER_ROCM_LIB "${dir}") - break() - endif() - endforeach() + unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS) + unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS) + unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS) + unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG) + if(NOT CMAKE_HIP_COMPILER_ROCM_LIB) - list(TRANSFORM _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS APPEND "/cmake/hip-lang/hip-lang-config.cmake") - string(REPLACE ";" "\n " _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}") - message(FATAL_ERROR - "The ROCm root directory:\n" - " ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n" - "does not contain the HIP runtime CMake package, expected at one of:\n" - " ${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}\n" + set(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS + "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib" + "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib64" ) + if(CMAKE_HIP_LIBRARY_ARCHITECTURE) + list(APPEND _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/${CMAKE_HIP_LIBRARY_ARCHITECTURE}") + endif() + foreach(dir IN LISTS _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS) + if(EXISTS "${dir}/cmake/hip-lang/hip-lang-config.cmake") + set(CMAKE_HIP_COMPILER_ROCM_LIB "${dir}") + break() + endif() + endforeach() + if(NOT CMAKE_HIP_COMPILER_ROCM_LIB) + list(TRANSFORM _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS APPEND "/cmake/hip-lang/hip-lang-config.cmake") + string(REPLACE ";" "\n " _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}") + message(FATAL_ERROR + "The ROCm root directory:\n" + " ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n" + "does not contain the HIP runtime CMake package, expected at one of:\n" + " ${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}\n" + ) + endif() + unset(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS) + endif() + if(CMAKE_HIP_COMPILER_ROCM_LIB MATCHES "/lib64$" AND NOT DEFINED CMAKE_SIZEOF_VOID_P) + # We have not yet determined the target ABI but we need 'find_package' to + # search lib64 directories to find hip-lang CMake package dependencies. + # This will be replaced by ABI detection later. + set(CMAKE_HIP_SIZEOF_DATA_PTR 8) endif() - unset(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS) -endif() -if(CMAKE_HIP_COMPILER_ROCM_LIB MATCHES "/lib64$" AND NOT DEFINED CMAKE_SIZEOF_VOID_P) - # We have not yet determined the target ABI but we need 'find_package' to - # search lib64 directories to find hip-lang CMake package dependencies. - # This will be replaced by ABI detection later. - set(CMAKE_HIP_SIZEOF_DATA_PTR 8) endif() if (NOT _CMAKE_TOOLCHAIN_LOCATION) @@ -165,6 +240,26 @@ include(CMakeFindBinUtils) include(Compiler/${CMAKE_HIP_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang") + set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED") +elseif(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + include(Internal/CMakeNVCCParseImplicitInfo) + # Parse CMAKE_HIP_COMPILER_PRODUCED_OUTPUT to get: + # - CMAKE_HIP_ARCHITECTURES_DEFAULT + # - CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES + # - CMAKE_HIP_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES + # - CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES + # - CMAKE_HIP_HOST_LINK_LAUNCHER + # - CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT + # - CMAKE_HIP_CUDA_TOOLKIT_INCLUDE_DIRECTORIES + # Match arguments with cmake_nvcc_filter_implicit_info call in CMakeTestHIPCompiler. + cmake_nvcc_parse_implicit_info(HIP CMAKE_HIP_CUDA_) + + include(Internal/CMakeCUDAFilterImplicitLibs) + # Filter out implicit link libraries that should not be passed unconditionally. + cmake_cuda_filter_implicit_libs(CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES) +endif() + if(CMAKE_HIP_COMPILER_SYSROOT) string(CONCAT _SET_CMAKE_HIP_COMPILER_SYSROOT "set(CMAKE_HIP_COMPILER_SYSROOT \"${CMAKE_HIP_COMPILER_SYSROOT}\")\n" @@ -185,7 +280,20 @@ if(MSVC_HIP_ARCHITECTURE_ID) "set(MSVC_HIP_ARCHITECTURE_ID ${MSVC_HIP_ARCHITECTURE_ID})") endif() -if(NOT DEFINED CMAKE_HIP_ARCHITECTURES) +if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + if(NOT "$ENV{CUDAARCHS}" STREQUAL "") + set(CMAKE_HIP_ARCHITECTURES "$ENV{CUDAARCHS}" CACHE STRING "CUDA architectures") + endif() + + # If the user did not set CMAKE_HIP_ARCHITECTURES, use the compiler's default. + if("${CMAKE_HIP_ARCHITECTURES}" STREQUAL "") + set(CMAKE_HIP_ARCHITECTURES "${CMAKE_HIP_ARCHITECTURES_DEFAULT}" CACHE STRING "HIP architectures" FORCE) + if(NOT CMAKE_HIP_ARCHITECTURES) + message(FATAL_ERROR "Failed to detect a default HIP architecture.\n\nCompiler output:\n${CMAKE_HIP_COMPILER_PRODUCED_OUTPUT}") + endif() + endif() + unset(CMAKE_HIP_ARCHITECTURES_DEFAULT) +elseif(NOT DEFINED CMAKE_HIP_ARCHITECTURES) # Use 'rocm_agent_enumerator' to get the current GPU architecture. set(_CMAKE_HIP_ARCHITECTURES) find_program(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake index 386be73..fff4e9d 100644 --- a/Modules/CMakeDetermineSystem.cmake +++ b/Modules/CMakeDetermineSystem.cmake @@ -47,6 +47,28 @@ if(CMAKE_HOST_UNIX) set(CMAKE_HOST_SYSTEM_VERSION "${_CMAKE_HOST_SYSTEM_MAJOR_VERSION}.${_CMAKE_HOST_SYSTEM_MINOR_VERSION}") unset(_CMAKE_HOST_SYSTEM_MAJOR_VERSION) unset(_CMAKE_HOST_SYSTEM_MINOR_VERSION) + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android") + execute_process(COMMAND getprop ro.build.version.sdk + OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + + if(NOT DEFINED CMAKE_SYSTEM_VERSION) + set(_ANDROID_API_LEVEL_H $ENV{PREFIX}/include/android/api-level.h) + set(_ANDROID_API_REGEX "#define __ANDROID_API__ ([0-9]+)") + file(READ ${_ANDROID_API_LEVEL_H} _ANDROID_API_LEVEL_H_CONTENT) + string(REGEX MATCH ${_ANDROID_API_REGEX} _ANDROID_API_LINE "${_ANDROID_API_LEVEL_H_CONTENT}") + string(REGEX REPLACE ${_ANDROID_API_REGEX} "\\1" _ANDROID_API "${_ANDROID_API_LINE}") + if(_ANDROID_API) + set(CMAKE_SYSTEM_VERSION "${_ANDROID_API}") + endif() + + unset(_ANDROID_API_LEVEL_H) + unset(_ANDROID_API_LEVEL_H_CONTENT) + unset(_ANDROID_API_REGEX) + unset(_ANDROID_API_LINE) + unset(_ANDROID_API) + endif() else() execute_process(COMMAND ${CMAKE_UNAME} -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index f778891..e12b175 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -79,10 +79,10 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND set(_CMAKE_MT_NAMES "mt") # Prepend toolchain-specific names. - if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang") + if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^x(Clang|LLVMFlang)$") set(_CMAKE_NM_NAMES "llvm-nm" "nm") list(PREPEND _CMAKE_AR_NAMES "llvm-lib") - # llvm-mt does not support all flags we need in vs_link_exe + # llvm-mt is not ready to be used as a replacement for mt.exe # list(PREPEND _CMAKE_MT_NAMES "llvm-mt") list(PREPEND _CMAKE_LINKER_NAMES "lld-link") list(APPEND _CMAKE_TOOL_VARS NM) diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 6a2be28..89a00ab 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -14,8 +14,9 @@ set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@") set(CMAKE_RANLIB "@CMAKE_RANLIB@") -set(CMAKE_TAPI "@CMAKE_TAPI@") +set(CMAKE_LINKER "@CMAKE_LINKER@") set(CMAKE_Fortran_COMPILER_RANLIB "@CMAKE_Fortran_COMPILER_RANLIB@") +set(CMAKE_TAPI "@CMAKE_TAPI@") set(CMAKE_COMPILER_IS_GNUG77 @CMAKE_COMPILER_IS_GNUG77@) set(CMAKE_Fortran_COMPILER_LOADED 1) set(CMAKE_Fortran_COMPILER_WORKS @CMAKE_Fortran_COMPILER_WORKS@) diff --git a/Modules/CMakeHIPCompiler.cmake.in b/Modules/CMakeHIPCompiler.cmake.in index 0fa5bf0..6d5e62a 100644 --- a/Modules/CMakeHIPCompiler.cmake.in +++ b/Modules/CMakeHIPCompiler.cmake.in @@ -1,4 +1,6 @@ set(CMAKE_HIP_COMPILER "@CMAKE_HIP_COMPILER@") +set(CMAKE_HIP_HOST_COMPILER "@CMAKE_HIP_HOST_COMPILER@") +set(CMAKE_HIP_HOST_LINK_LAUNCHER "@CMAKE_HIP_HOST_LINK_LAUNCHER@") set(CMAKE_HIP_COMPILER_ID "@CMAKE_HIP_COMPILER_ID@") set(CMAKE_HIP_COMPILER_VERSION "@CMAKE_HIP_COMPILER_VERSION@") set(CMAKE_HIP_STANDARD_COMPUTED_DEFAULT "@CMAKE_HIP_STANDARD_COMPUTED_DEFAULT@") @@ -45,14 +47,27 @@ if(CMAKE_HIP_LIBRARY_ARCHITECTURE) set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_HIP_LIBRARY_ARCHITECTURE@") endif() -set(CMAKE_HIP_TOOLKIT_INCLUDE_DIRECTORIES "@CMAKE_HIP_TOOLKIT_INCLUDE_DIRECTORIES@") +set(CMAKE_HIP_COMPILER_CUDA_TOOLKIT_ROOT "@CMAKE_HIP_COMPILER_CUDA_TOOLKIT_ROOT@") +set(CMAKE_HIP_COMPILER_CUDA_TOOLKIT_LIBRARY_ROOT "@CMAKE_HIP_COMPILER_CUDA_TOOLKIT_LIBRARY_ROOT@") +set(CMAKE_HIP_COMPILER_CUDA_TOOLKIT_VERSION "@CMAKE_HIP_COMPILER_CUDA_TOOLKIT_VERSION@") +set(CMAKE_HIP_COMPILER_CUDA_LIBRARY_ROOT "@CMAKE_HIP_COMPILER_CUDA_LIBRARY_ROOT@") + +set(CMAKE_HIP_ARCHITECTURES_ALL "@CMAKE_HIP_ARCHITECTURES_ALL@") +set(CMAKE_HIP_ARCHITECTURES_ALL_MAJOR "@CMAKE_HIP_ARCHITECTURES_ALL_MAJOR@") +set(CMAKE_HIP_ARCHITECTURES_NATIVE "@CMAKE_HIP_ARCHITECTURES_NATIVE@") + +set(CMAKE_HIP_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "@CMAKE_HIP_CUDA_TOOLKIT_INCLUDE_DIRECTORIES@") + +set(CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES "@CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES@") +set(CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES "@CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES@") +set(CMAKE_HIP_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_HIP_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@") set(CMAKE_HIP_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_HIP_IMPLICIT_INCLUDE_DIRECTORIES@") set(CMAKE_HIP_IMPLICIT_LINK_LIBRARIES "@CMAKE_HIP_IMPLICIT_LINK_LIBRARIES@") set(CMAKE_HIP_IMPLICIT_LINK_DIRECTORIES "@CMAKE_HIP_IMPLICIT_LINK_DIRECTORIES@") set(CMAKE_HIP_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_HIP_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@") -set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED") +set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "@CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT@") set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_HIP_COMPILER_AR "@CMAKE_HIP_COMPILER_AR@") diff --git a/Modules/CMakeHIPCompilerABI.hip b/Modules/CMakeHIPCompilerABI.hip index 6c912bd..7d8b815 100644 --- a/Modules/CMakeHIPCompilerABI.hip +++ b/Modules/CMakeHIPCompilerABI.hip @@ -1,9 +1,13 @@ -#ifndef __HIP__ +#if !defined(__HIP__) && !defined(__NVCC__) # error "A C or C++ compiler has been selected for HIP" #endif #include "CMakeCompilerABI.h" +#if defined(__NVCC__) +# include "CMakeCompilerCUDAArch.h" +#endif + int main(int argc, char* argv[]) { int require = 0; @@ -11,6 +15,16 @@ int main(int argc, char* argv[]) #if defined(ABI_ID) require += info_abi[argc]; #endif - (void)argv; + static_cast<void>(argv); + +#if defined(__NVCC__) + if (!cmakeCompilerCUDAArch()) { + // Convince the compiler that the non-zero return value depends + // on the info strings so they are not optimized out. + return require ? -1 : 1; + } + return 0; +#else return require; +#endif } diff --git a/Modules/CMakeHIPCompilerId.hip.in b/Modules/CMakeHIPCompilerId.hip.in index 3c4a1d4..4ac0f30 100644 --- a/Modules/CMakeHIPCompilerId.hip.in +++ b/Modules/CMakeHIPCompilerId.hip.in @@ -1,4 +1,4 @@ -#ifndef __HIP__ +#if !defined(__HIP__) && !defined(__NVCC__) # error "A C or C++ compiler has been selected for HIP" #endif diff --git a/Modules/CMakeHIPInformation.cmake b/Modules/CMakeHIPInformation.cmake index 41a98db..3995c36 100644 --- a/Modules/CMakeHIPInformation.cmake +++ b/Modules/CMakeHIPInformation.cmake @@ -8,6 +8,19 @@ else() endif() set(CMAKE_INCLUDE_FLAG_HIP "-I") +# Set implicit links early so compiler-specific modules can use them. +set(__IMPLICIT_LINKS) +foreach(dir ${CMAKE_HIP_HOST_IMPLICIT_LINK_DIRECTORIES}) + string(APPEND __IMPLICIT_LINKS " -L\"${dir}\"") +endforeach() +foreach(lib ${CMAKE_HIP_HOST_IMPLICIT_LINK_LIBRARIES}) + if(${lib} MATCHES "/") + string(APPEND __IMPLICIT_LINKS " \"${lib}\"") + else() + string(APPEND __IMPLICIT_LINKS " -l${lib}") + endif() +endforeach() + # Load compiler-specific information. if(CMAKE_HIP_COMPILER_ID) include(Compiler/${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL) @@ -129,7 +142,7 @@ endif() # compile a HIP file into an object file if(NOT CMAKE_HIP_COMPILE_OBJECT) set(CMAKE_HIP_COMPILE_OBJECT - "<CMAKE_HIP_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> ${_CMAKE_COMPILE_AS_HIP_FLAG} -c <SOURCE>") + "<CMAKE_HIP_COMPILER> ${_CMAKE_HIP_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> ${_CMAKE_COMPILE_AS_HIP_FLAG} -c <SOURCE>") endif() # compile a cu file into an executable diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake index 1773dc4..cbdb915 100644 --- a/Modules/CMakeParseImplicitLinkInfo.cmake +++ b/Modules/CMakeParseImplicitLinkInfo.cmake @@ -26,12 +26,22 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj set(multiValueArgs ) cmake_parse_arguments(EXTRA_PARSE "${keywordArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(is_msvc 0) + if(EXTRA_PARSE_LANGUAGE AND + ("x${CMAKE_${EXTRA_PARSE_LANGUAGE}_ID}" STREQUAL "xMSVC" OR + "x${CMAKE_${EXTRA_PARSE_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC")) + set(is_msvc 1) + endif() + # Parse implicit linker arguments. set(linker "CMAKE_LINKER-NOTFOUND") if(CMAKE_LINKER) get_filename_component(linker ${CMAKE_LINKER} NAME) string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" linker "${linker}") endif() + if(is_msvc) + string(APPEND linker "|link\\.exe|lld-link") + endif() set(startfile "CMAKE_LINK_STARTFILE-NOTFOUND") if(CMAKE_LINK_STARTFILE) set(startfile "${CMAKE_LINK_STARTFILE}") @@ -75,12 +85,6 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj endif() endif() endif() - set(is_msvc 0) - if(EXTRA_PARSE_LANGUAGE AND - ("x${CMAKE_${EXTRA_PARSE_LANGUAGE}_ID}" STREQUAL "xMSVC" OR - "x${CMAKE_${EXTRA_PARSE_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC")) - set(is_msvc 1) - endif() set(search_static 0) if("${cmd}" MATCHES "${linker_regex}") string(APPEND log " link line: [${line}]\n") @@ -102,6 +106,8 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj string(APPEND log " arg [${arg}] ==> dir [${dir}]\n") elseif(is_msvc AND "${arg}" STREQUAL "-link") string(APPEND log " arg [${arg}] ==> ignore MSVC cl option\n") + elseif(is_msvc AND "${arg}" MATCHES "^[-/][Ii][Mm][Pp][Ll][Ii][Bb]:") + string(APPEND log " arg [${arg}] ==> ignore MSVC link option\n") elseif(is_msvc AND "${arg}" MATCHES "^(.*\\.[Ll][Ii][Bb])$") set(lib "${CMAKE_MATCH_1}") list(APPEND implicit_libs_tmp ${lib}) diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 777c680..1c6f0df 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -21,7 +21,8 @@ set(CMAKE_INCLUDE_FLAG_Swift "-I ") # FIXME: Move compiler- and platform-specific flags to the above-included modules. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" - OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") + OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "visionOS" + OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -install_name -Xlinker ") elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -soname -Xlinker ") @@ -30,7 +31,8 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" - OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") + OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "visionOS" + OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG_SEP "") set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP "") else() diff --git a/Modules/CMakeSystemSpecificInitialize.cmake b/Modules/CMakeSystemSpecificInitialize.cmake index e87d868..ee8cb86 100644 --- a/Modules/CMakeSystemSpecificInitialize.cmake +++ b/Modules/CMakeSystemSpecificInitialize.cmake @@ -25,7 +25,7 @@ unset(LINUX) # It is useful to share the same aforementioned configuration files and # avoids duplicating them in case of tightly related platforms. # -# An example are the platforms supported by Xcode (macOS, iOS, tvOS, +# An example are the platforms supported by Xcode (macOS, iOS, tvOS, visionOS # and watchOS). For all of those the CMAKE_EFFECTIVE_SYSTEM_NAME is # set to Apple which results in using # Platform/Apple-AppleClang-CXX.cmake for the Apple C++ compiler. diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake index 5779e4b..3057fe9 100644 --- a/Modules/CMakeTestCUDACompiler.cmake +++ b/Modules/CMakeTestCUDACompiler.cmake @@ -22,51 +22,10 @@ if(CMAKE_CUDA_ABI_COMPILED) set(CMAKE_CUDA_COMPILER_WORKS TRUE) message(STATUS "Check for working CUDA compiler: ${CMAKE_CUDA_COMPILER} - skipped") - # Run the test binary to detect the native architectures. - execute_process(COMMAND "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_CUDA.bin" - RESULT_VARIABLE _CUDA_ARCHS_RESULT - OUTPUT_VARIABLE _CUDA_ARCHS_OUTPUT - ERROR_VARIABLE _CUDA_ARCHS_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(_CUDA_ARCHS_RESULT EQUAL 0) - if("$ENV{CMAKE_CUDA_ARCHITECTURES_NATIVE_CLAMP}") - # Undocumented hook used by CMake's CI. - # Clamp native architecture to version range supported by this CUDA. - list(GET CMAKE_CUDA_ARCHITECTURES_ALL 0 _CUDA_ARCH_MIN) - list(GET CMAKE_CUDA_ARCHITECTURES_ALL -1 _CUDA_ARCH_MAX) - set(CMAKE_CUDA_ARCHITECTURES_NATIVE "") - foreach(_CUDA_ARCH IN LISTS _CUDA_ARCHS_OUTPUT) - if(_CUDA_ARCH LESS _CUDA_ARCH_MIN) - set(_CUDA_ARCH "${_CUDA_ARCH_MIN}") - endif() - if(_CUDA_ARCH GREATER _CUDA_ARCH_MAX) - set(_CUDA_ARCH "${_CUDA_ARCH_MAX}") - endif() - list(APPEND CMAKE_CUDA_ARCHITECTURES_NATIVE ${_CUDA_ARCH}) - endforeach() - unset(_CUDA_ARCH) - unset(_CUDA_ARCH_MIN) - unset(_CUDA_ARCH_MAX) - else() - set(CMAKE_CUDA_ARCHITECTURES_NATIVE "${_CUDA_ARCHS_OUTPUT}") - endif() - list(REMOVE_DUPLICATES CMAKE_CUDA_ARCHITECTURES_NATIVE) - list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_NATIVE APPEND "-real") - else() - if(NOT _CUDA_ARCHS_RESULT MATCHES "[0-9]+") - set(_CUDA_ARCHS_STATUS " (${_CUDA_ARCHS_RESULT})") - else() - set(_CUDA_ARCHS_STATUS "") - endif() - string(REPLACE "\n" "\n " _CUDA_ARCHS_OUTPUT " ${_CUDA_ARCHS_OUTPUT}") - message(CONFIGURE_LOG - "Detecting the CUDA native architecture(s) failed with " - "the following output:\n${_CUDA_ARCHS_OUTPUT}\n\n") - endif() - unset(_CUDA_ARCHS_EXE) - unset(_CUDA_ARCHS_RESULT) - unset(_CUDA_ARCHS_OUTPUT) + include(Internal/CMakeCUDAArchitecturesNative) + # Run the test binary to get: + # - CMAKE_CUDA_ARCHITECTURES_NATIVE + cmake_cuda_architectures_native(CUDA) endif() # This file is used by EnableLanguage in cmGlobalGenerator to @@ -114,22 +73,14 @@ if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}") endif() +include(Internal/CMakeCUDAFilterImplicitLibs) # Filter out implicit link libraries that should not be passed unconditionally. -# See CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE in CMakeDetermineCUDACompiler. -list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) +cmake_cuda_filter_implicit_libs(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES) if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") - # Remove the CUDA Toolkit include directories from the set of - # implicit system include directories. - # This resolves the issue that NVCC doesn't specify these - # includes as SYSTEM includes when compiling device code, and sometimes - # they contain headers that generate warnings, so let users mark them - # as SYSTEM explicitly - if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) - list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES - ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} - ) - endif() + include(Internal/CMakeNVCCFilterImplicitInfo) + # Match arguments with cmake_nvcc_parse_implicit_info call in CMakeDetermineCUDACompiler. + cmake_nvcc_filter_implicit_info(CUDA CMAKE_CUDA_) endif() # Re-configure to save learned information. diff --git a/Modules/CMakeTestHIPCompiler.cmake b/Modules/CMakeTestHIPCompiler.cmake index 686f055..ec54d80 100644 --- a/Modules/CMakeTestHIPCompiler.cmake +++ b/Modules/CMakeTestHIPCompiler.cmake @@ -10,7 +10,10 @@ if(CMAKE_HIP_COMPILER_FORCED) endif() set(__CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS}") -string(APPEND CMAKE_HIP_FLAGS " --cuda-host-only") + +if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang") + string(APPEND CMAKE_HIP_FLAGS " --cuda-host-only") +endif() include(CMakeTestCompilerCommon) @@ -31,6 +34,13 @@ if(CMAKE_HIP_ABI_COMPILED) # The compiler worked so skip dedicated test below. set(CMAKE_HIP_COMPILER_WORKS TRUE) message(STATUS "Check for working HIP compiler: ${CMAKE_HIP_COMPILER} - skipped") + + if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + include(Internal/CMakeCUDAArchitecturesNative) + # Run the test binary to get: + # - CMAKE_HIP_ARCHITECTURES_NATIVE + cmake_cuda_architectures_native(HIP) + endif() endif() # This file is used by EnableLanguage in cmGlobalGenerator to @@ -42,7 +52,7 @@ if(NOT CMAKE_HIP_COMPILER_WORKS) PrintTestCompilerStatus("HIP") __TestCompiler_setTryCompileTargetType() string(CONCAT __TestCompiler_testHIPCompilerSource - "#ifndef __HIP__\n" + "#if !defined(__HIP__) && !defined(__NVCC__)\n" "# error \"The CMAKE_HIP_COMPILER is set to a C/CXX compiler\"\n" "#endif\n" "int main(){return 0;}\n") @@ -76,6 +86,16 @@ unset(__CMAKE_HIP_FLAGS) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) CMAKE_DETERMINE_COMPILE_FEATURES(HIP) +if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA") + include(Internal/CMakeNVCCFilterImplicitInfo) + # Match arguments with cmake_nvcc_parse_implicit_info call in CMakeDetermineHIPCompiler. + cmake_nvcc_filter_implicit_info(HIP CMAKE_HIP_CUDA_) + + include(Internal/CMakeCUDAFilterImplicitLibs) + # Filter out implicit link libraries that should not be passed unconditionally. + cmake_cuda_filter_implicit_libs(CMAKE_HIP_IMPLICIT_LINK_LIBRARIES) +endif() + # Re-configure to save learned information. configure_file( ${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in diff --git a/Modules/CUDA/architectures.cmake b/Modules/CUDA/architectures.cmake deleted file mode 100644 index 7d6a6e0..0000000 --- a/Modules/CUDA/architectures.cmake +++ /dev/null @@ -1,69 +0,0 @@ -# See supported GPUs on Wikipedia -# https://en.wikipedia.org/wiki/CUDA#GPUs_supported - -# Initial set based on CUDA 7.0. -set(CMAKE_CUDA_ARCHITECTURES_ALL 20 21 30 35 37 50 52 53) -set(CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 20 30 35 50) - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 8.0) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 60 61 62) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 60) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 9.0) - if(NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang" OR CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 70 72) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 70) - endif() - - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 20 21) - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 20) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 10.0 - AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang" OR CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 75) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.0) - if(NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang" OR CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 80) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 80) - endif() - - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 30) - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 30) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.1 - AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang" OR CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 86) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.4 - AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 87) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.8 - AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 89 90) - list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 90) -endif() - -if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 12.0 - AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")) - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 35 37) - list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 35) -endif() - -# only generate jit code for the newest arch for all/all-major -list(POP_BACK CMAKE_CUDA_ARCHITECTURES_ALL _latest_arch) -list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_ALL APPEND "-real") -list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL ${_latest_arch}) - -list(POP_BACK CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR _latest_arch) -list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR APPEND "-real") -list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR ${_latest_arch}) - -unset(_latest_arch) diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index 12b0976..27b7ae8 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -22,7 +22,7 @@ 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. 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 +by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index ce4719a..79aca93 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -23,7 +23,7 @@ Check if given C source compiles and links into an executable. expressions. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake index d5a8fda..e06bcca 100644 --- a/Modules/CheckCSourceRuns.cmake +++ b/Modules/CheckCSourceRuns.cmake @@ -22,7 +22,7 @@ subsequently be run. false (e.g. an empty string or an error message). 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake index 4b33aa8..7531236 100644 --- a/Modules/CheckCXXSourceCompiles.cmake +++ b/Modules/CheckCXXSourceCompiles.cmake @@ -23,7 +23,7 @@ Check if given C++ source compiles and links into an executable. expressions. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index 3402715..eb643eb 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -22,7 +22,7 @@ subsequently be run. false (e.g. an empty string or an error message). 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckCXXSymbolExists.cmake b/Modules/CheckCXXSymbolExists.cmake index 569dafd..d807c17 100644 --- a/Modules/CheckCXXSymbolExists.cmake +++ b/Modules/CheckCXXSymbolExists.cmake @@ -33,7 +33,7 @@ Check if a symbol exists as a function, variable, or macro in ``C++``. function. Since there is no reliable way to predict whether a given function in the system environment may be defined as an overloaded function or may be an overloaded function on other systems or will become so in the future, it - is generally advised to use the :module:`CheckCXXSourceCompiles` module for + is generally advised to use the :module:`CheckSourceCompiles` module for checking any function symbol (unless somehow you surely know the checked function is not overloaded on other systems or will not be so in the future). diff --git a/Modules/CheckCompilerFlag.cmake b/Modules/CheckCompilerFlag.cmake index a18435b..0f2ec4c 100644 --- a/Modules/CheckCompilerFlag.cmake +++ b/Modules/CheckCompilerFlag.cmake @@ -23,7 +23,7 @@ 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. 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 +by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckFortranCompilerFlag.cmake b/Modules/CheckFortranCompilerFlag.cmake index 9164565..81a2345 100644 --- a/Modules/CheckFortranCompilerFlag.cmake +++ b/Modules/CheckFortranCompilerFlag.cmake @@ -24,7 +24,7 @@ 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. 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 +by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index 5158b7e..ed374ef 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -48,7 +48,7 @@ Check if given Fortran source compiles and links into an executable. ``.F90`` is a typical choice. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckFortranSourceRuns.cmake b/Modules/CheckFortranSourceRuns.cmake index f996749..9bf9fb2 100644 --- a/Modules/CheckFortranSourceRuns.cmake +++ b/Modules/CheckFortranSourceRuns.cmake @@ -44,7 +44,7 @@ subsequently be run. ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index 69913a3..94948b9 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -5,26 +5,45 @@ CheckLanguage ------------- -Check if a language can be enabled +Check whether a language can be enabled by the :command:`enable_language` +or :command:`project` commands: -Usage: +.. command:: check_language -:: + .. code-block:: cmake - check_language(<lang>) + check_language(<lang>) -where ``<lang>`` is a language that may be passed to :command:`enable_language` -such as ``Fortran``. If :variable:`CMAKE_<LANG>_COMPILER` is already defined -the check does nothing. Otherwise it tries enabling the language in a -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 (and cleared if it was not). + Try enabling language ``<lang>`` in a test project and record results + in the cache: -Example: + :variable:`CMAKE_<LANG>_COMPILER` + If the language can be enabled, this variable is set to the compiler + that was found. If the language cannot be enabled, this variable is + set to ``NOTFOUND``. -:: + If this variable is already set, either explicitly or cached by + a previous call, the check is skipped. + + :variable:`CMAKE_<LANG>_HOST_COMPILER` + This variable is set when ``<lang>`` is ``CUDA`` or ``HIP``. + + If the check detects an explicit host compiler that is required for + compilation, this variable will be set to that compiler. + If the check detects that no explicit host compiler is needed, + this variable will be cleared. + + If this variable is already set, its value is preserved only if + :variable:`CMAKE_<LANG>_COMPILER` is also set. + Otherwise, the check runs and overwrites + :variable:`CMAKE_<LANG>_HOST_COMPILER` with a new result. + Note that :variable:`CMAKE_<LANG>_HOST_COMPILER` documents it should + not be set without also setting + :variable:`CMAKE_<LANG>_COMPILER` to a NVCC compiler. + +For example: + +.. code-block:: cmake check_language(Fortran) if(CMAKE_Fortran_COMPILER) @@ -46,7 +65,7 @@ macro(check_language lang) file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}) set(extra_compiler_variables) - if(${lang} STREQUAL CUDA AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") + if("${lang}" MATCHES "^(CUDA|HIP)$" AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")") endif() diff --git a/Modules/CheckOBJCCompilerFlag.cmake b/Modules/CheckOBJCCompilerFlag.cmake index 24bf0db..f6d259e 100644 --- a/Modules/CheckOBJCCompilerFlag.cmake +++ b/Modules/CheckOBJCCompilerFlag.cmake @@ -24,7 +24,7 @@ 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. 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 +by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckOBJCSourceCompiles.cmake b/Modules/CheckOBJCSourceCompiles.cmake index 7663054..bc0cac1 100644 --- a/Modules/CheckOBJCSourceCompiles.cmake +++ b/Modules/CheckOBJCSourceCompiles.cmake @@ -25,7 +25,7 @@ Check if given Objective-C source compiles and links into an executable. expressions. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckOBJCSourceRuns.cmake b/Modules/CheckOBJCSourceRuns.cmake index a23a0c7..511cac6 100644 --- a/Modules/CheckOBJCSourceRuns.cmake +++ b/Modules/CheckOBJCSourceRuns.cmake @@ -24,7 +24,7 @@ subsequently be run. false (e.g. an empty string or an error message). 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckOBJCXXCompilerFlag.cmake b/Modules/CheckOBJCXXCompilerFlag.cmake index ae2d907..32d50c9 100644 --- a/Modules/CheckOBJCXXCompilerFlag.cmake +++ b/Modules/CheckOBJCXXCompilerFlag.cmake @@ -24,7 +24,7 @@ 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. 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 +by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckOBJCXXSourceCompiles.cmake b/Modules/CheckOBJCXXSourceCompiles.cmake index cfbda3a..366d7d5 100644 --- a/Modules/CheckOBJCXXSourceCompiles.cmake +++ b/Modules/CheckOBJCXXSourceCompiles.cmake @@ -25,7 +25,7 @@ Check if given Objective-C++ source compiles and links into an executable. expressions. 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckOBJCXXSourceRuns.cmake b/Modules/CheckOBJCXXSourceRuns.cmake index b2831b6..49db3cb 100644 --- a/Modules/CheckOBJCXXSourceRuns.cmake +++ b/Modules/CheckOBJCXXSourceRuns.cmake @@ -24,7 +24,7 @@ subsequently be run. false (e.g. an empty string or an error message). 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckSourceCompiles.cmake b/Modules/CheckSourceCompiles.cmake index 041b59c..af905a4 100644 --- a/Modules/CheckSourceCompiles.cmake +++ b/Modules/CheckSourceCompiles.cmake @@ -48,7 +48,7 @@ Check if given source compiles and links into an executable. HAVE_ERROR_STOP) 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 + named by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/CheckSourceRuns.cmake b/Modules/CheckSourceRuns.cmake index 822ee07..75636f4 100644 --- a/Modules/CheckSourceRuns.cmake +++ b/Modules/CheckSourceRuns.cmake @@ -48,7 +48,7 @@ subsequently be run. HAVE_COARRAY) 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 + by ``<resultVar>``. Every subsequent CMake run will reuse 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. diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake index a74e90b..a1ce6a1 100644 --- a/Modules/Compiler/Clang-CXX.cmake +++ b/Modules/Compiler/Clang-CXX.cmake @@ -32,7 +32,14 @@ endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") - string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE + if (CMAKE_HOST_WIN32) + # `rename` doesn't overwrite and doesn't retry in case of "target file is + # busy". + set(_clang_scan_deps_mv "\"${CMAKE_COMMAND}\" -E rename") + else () + set(_clang_scan_deps_mv "mv") + endif () + string(CONCAT CMAKE_CXX_SCANDEP_SOURCE "\"${CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS}\"" " -format=p1689" " --" @@ -40,8 +47,17 @@ if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) " -x c++ <SOURCE> -c -o <OBJECT>" " -MT <DYNDEP_FILE>" " -MD -MF <DEP_FILE>" - " > <DYNDEP_FILE>") - set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "clang") - set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>") + # Write to a temporary file. If the scan fails, we do not want to update + # the actual output file as `ninja` (at least) assumes that failed + # commands either delete or leave output files alone. See Issue#25419. + " > <DYNDEP_FILE>.tmp" + # We cannot use `copy_if_different` as the rule does not have a feature + # analogous to `ninja`'s `restat = 1`. It would also leave behind the + # `.tmp` file. + " && ${_clang_scan_deps_mv} <DYNDEP_FILE>.tmp <DYNDEP_FILE>") + unset(_clang_scan_deps_mv) + set(CMAKE_CXX_MODULE_MAP_FORMAT "clang") + set(CMAKE_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>") + set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG "--precompile") endif() endif() diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index e5683c2..4c033ca 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -117,8 +117,14 @@ else() # '-fcolor-diagnostics' introduced since Clang 2.6 if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 2.6) - set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS "-fcolor-diagnostics") - set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF "-fno-color-diagnostics") + # -fansi-escape-codes mentioned at https://releases.llvm.org/3.7.0/tools/clang/docs/UsersManual.html + if (CMAKE_HOST_WIN32 AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 3.7) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -fansi-escape-codes -fcolor-diagnostics) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -fno-ansi-escape-codes -fno-color-diagnostics) + else() + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -fcolor-diagnostics) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -fno-color-diagnostics) + endif() endif() endmacro() endif() diff --git a/Modules/Compiler/CrayClang-C.cmake b/Modules/Compiler/CrayClang-C.cmake new file mode 100644 index 0000000..bf878fc --- /dev/null +++ b/Modules/Compiler/CrayClang-C.cmake @@ -0,0 +1,30 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +include(Compiler/CrayClang) +__compiler_cray_clang(C) + +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + +string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG") +string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG") + +set(CMAKE_C90_STANDARD_COMPILE_OPTION -std=c90) +set(CMAKE_C90_EXTENSION_COMPILE_OPTION -std=gnu90) +set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_C99_STANDARD_COMPILE_OPTION -std=c99) +set(CMAKE_C99_EXTENSION_COMPILE_OPTION -std=gnu99) +set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_C11_STANDARD_COMPILE_OPTION -std=c11) +set(CMAKE_C11_EXTENSION_COMPILE_OPTION -std=gnu11) +set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_C17_STANDARD_COMPILE_OPTION -std=c17) +set(CMAKE_C17_EXTENSION_COMPILE_OPTION -std=gnu17) + +set(CMAKE_C23_STANDARD_COMPILE_OPTION -std=c2x) +set(CMAKE_C23_EXTENSION_COMPILE_OPTION -std=gnu2x) + +__compiler_check_default_language_standard(C 15.0.0 17) diff --git a/Modules/Compiler/CrayClang-CXX.cmake b/Modules/Compiler/CrayClang-CXX.cmake new file mode 100644 index 0000000..de6a53c --- /dev/null +++ b/Modules/Compiler/CrayClang-CXX.cmake @@ -0,0 +1,35 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +include(Compiler/CrayClang) +__compiler_cray_clang(CXX) + + +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) +set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") + +string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG") +string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG") + +set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -std=c++98) +set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -std=gnu++98) +set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_CXX11_STANDARD_COMPILE_OPTION -std=c++11) +set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -std=gnu++11) +set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_CXX14_STANDARD_COMPILE_OPTION -std=c++14) +set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -std=gnu++14) +set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_CXX17_STANDARD_COMPILE_OPTION -std=c++17) +set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION -std=gnu++17) + +set(CMAKE_CXX20_STANDARD_COMPILE_OPTION -std=c++20) +set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION -std=gnu++20) + +set(CMAKE_CXX23_STANDARD_COMPILE_OPTION -std=c++2b) +set(CMAKE_CXX23_EXTENSION_COMPILE_OPTION -std=gnu++2b) + +__compiler_check_default_language_standard(CXX 15.0.0 14) diff --git a/Modules/Compiler/CrayClang-DetermineCompiler.cmake b/Modules/Compiler/CrayClang-DetermineCompiler.cmake new file mode 100644 index 0000000..1828444 --- /dev/null +++ b/Modules/Compiler/CrayClang-DetermineCompiler.cmake @@ -0,0 +1,8 @@ +set(_compiler_id_pp_test "defined(__clang__) && defined(__cray__)") + +set(_compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__cray_major__) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__cray_minor__) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__cray_patchlevel__) +# define @PREFIX@COMPILER_VERSION_INTERNAL_STR __clang_version__ +") diff --git a/Modules/Compiler/CrayClang.cmake b/Modules/Compiler/CrayClang.cmake new file mode 100644 index 0000000..d2db9dd --- /dev/null +++ b/Modules/Compiler/CrayClang.cmake @@ -0,0 +1,17 @@ +# 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_CRAYCLANG) + return() +endif() +set(__COMPILER_CRAYCLANG 1) + +include(Compiler/Clang) + +macro (__compiler_cray_clang lang) + set(__crayclang_ver "${CMAKE_${lang}_COMPILER_VERSION}") + set("CMAKE_${lang}_COMPILER_VERSION" "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}") + __compiler_clang(${lang}) + set("CMAKE_${lang}_COMPILER_VERSION" "${__crayclang_ver}") +endmacro () diff --git a/Modules/Compiler/GNU-CXX-FeatureTests.cmake b/Modules/Compiler/GNU-CXX-FeatureTests.cmake index 45c5470..a9663d6 100644 --- a/Modules/Compiler/GNU-CXX-FeatureTests.cmake +++ b/Modules/Compiler/GNU-CXX-FeatureTests.cmake @@ -54,7 +54,7 @@ set(_cmake_feature_test_cxx_user_literals "${GNU47_CXX11}") # NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor # release following that (March 2012), and the first minor release to # support -std=c++11. Prior to that, support for C++11 features is technically -# experiemental and possibly incomplete (see for example the note below about +# experimental and possibly incomplete (see for example the note below about # cxx_variadic_template_template_parameters) # GNU does not define __cplusplus correctly before version 4.7. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake index b35f254..2e1b4ad 100644 --- a/Modules/Compiler/GNU-CXX.cmake +++ b/Modules/Compiler/GNU-CXX.cmake @@ -72,3 +72,24 @@ elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) endif() __compiler_check_default_language_standard(CXX 3.4 98 6.0 14 11.1 17) + +if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0) + string(CONCAT CMAKE_CXX_SCANDEP_SOURCE + "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E -x c++ <SOURCE>" + " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>" + " -fmodules-ts -fdeps-file=<DYNDEP_FILE> -fdeps-target=<OBJECT> -fdeps-format=p1689r5" + " -o <PREPROCESSED_SOURCE>") + set(CMAKE_CXX_MODULE_MAP_FORMAT "gcc") + string(CONCAT CMAKE_CXX_MODULE_MAP_FLAG + # Turn on modules. + "-fmodules-ts" + # Read the module mapper file. + " -fmodule-mapper=<MODULE_MAP_FILE>" + # Make sure dependency tracking is enabled (missing from `try_*`). + " -MD" + # Suppress `CXX_MODULES +=` from generated depfile snippets. + " -fdeps-format=p1689r5" + # Force C++ as a language. + " -x c++") + set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG "-fmodule-only") +endif() diff --git a/Modules/Compiler/IBMClang-CXX.cmake b/Modules/Compiler/IBMClang-CXX.cmake index 5431b17..be9b525 100644 --- a/Modules/Compiler/IBMClang-CXX.cmake +++ b/Modules/Compiler/IBMClang-CXX.cmake @@ -31,6 +31,8 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.1.0) set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17") set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++20") set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++20") + set(CMAKE_CXX23_STANDARD_COMPILE_OPTION "-std=c++2b") + set(CMAKE_CXX23_EXTENSION_COMPILE_OPTION "-std=gnu++2b") endif() __compiler_check_default_language_standard(CXX 17.1.0 17) diff --git a/Modules/Compiler/IntelLLVM.cmake b/Modules/Compiler/IntelLLVM.cmake index e256c8f..f3c0bf4 100644 --- a/Modules/Compiler/IntelLLVM.cmake +++ b/Modules/Compiler/IntelLLVM.cmake @@ -44,6 +44,13 @@ else() string(APPEND CMAKE_${lang}_FLAGS_INIT " ") string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") + if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 2023.0.0) + if("x${lang}" STREQUAL "xFortran") + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -diag-disable:10440") + else() + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -Rno-debug-disables-optimization") + endif() + endif() string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os") string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3") string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") diff --git a/Modules/Compiler/LCC-CXX-FeatureTests.cmake b/Modules/Compiler/LCC-CXX-FeatureTests.cmake index 45c5470..a9663d6 100644 --- a/Modules/Compiler/LCC-CXX-FeatureTests.cmake +++ b/Modules/Compiler/LCC-CXX-FeatureTests.cmake @@ -54,7 +54,7 @@ set(_cmake_feature_test_cxx_user_literals "${GNU47_CXX11}") # NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor # release following that (March 2012), and the first minor release to # support -std=c++11. Prior to that, support for C++11 features is technically -# experiemental and possibly incomplete (see for example the note below about +# experimental and possibly incomplete (see for example the note below about # cxx_variadic_template_template_parameters) # GNU does not define __cplusplus correctly before version 4.7. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 diff --git a/Modules/Compiler/LLVMFlang-Fortran.cmake b/Modules/Compiler/LLVMFlang-Fortran.cmake index 291413e..d27f094 100644 --- a/Modules/Compiler/LLVMFlang-Fortran.cmake +++ b/Modules/Compiler/LLVMFlang-Fortran.cmake @@ -1,5 +1,3 @@ -set(CMAKE_Fortran_VERBOSE_FLAG "-v") - set(CMAKE_Fortran_SUBMODULE_SEP "-") set(CMAKE_Fortran_SUBMODULE_EXT ".mod") @@ -15,6 +13,12 @@ set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72") -string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -O0 -g") -string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") -string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") +set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=") + +if(NOT "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_Fortran_VERBOSE_FLAG "-v") + + string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -O0 -g") + string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") + string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") +endif() diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake index 10a9073..79cd2e0 100644 --- a/Modules/Compiler/MSVC-CXX.cmake +++ b/Modules/Compiler/MSVC-CXX.cmake @@ -79,12 +79,13 @@ elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) endif() if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.34") - string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE + string(CONCAT CMAKE_CXX_SCANDEP_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE> -nologo -TP" " -showIncludes" " -scanDependencies <DYNDEP_FILE>" " -Fo<OBJECT>") - set(CMAKE_EXPERIMENTAL_CXX_SCANDEP_DEPFILE_FORMAT "msvc") - set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "msvc") - set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>") + set(CMAKE_CXX_SCANDEP_DEPFILE_FORMAT "msvc") + set(CMAKE_CXX_MODULE_MAP_FORMAT "msvc") + set(CMAKE_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>") + set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG "-ifcOnly;-ifcOutput;<OBJECT>") endif () diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index c839d1c..93ad182 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -1,10 +1,9 @@ -include(Compiler/CMakeCommonCompilerMacros) +include(Compiler/NVIDIA) +__compiler_nvidia_cxx_standards(CUDA) +__compiler_nvidia_cuda_flags(CUDA) set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE True) -set(CMAKE_CUDA_VERBOSE_FLAG "-v") -set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v") -set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cu") set(_CMAKE_CUDA_WHOLE_FLAG "-c") set(_CMAKE_CUDA_RDC_FLAG "-rdc=true") set(_CMAKE_CUDA_PTX_FLAG "-ptx") @@ -14,162 +13,11 @@ if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.7.0") set(_CMAKE_CUDA_OPTIX_FLAG "-optix-ir") endif() -if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) - # The -forward-unknown-to-host-compiler flag was only - # added to nvcc in 10.2 so before that we had no good - # way to invoke the CUDA compiler and propagate unknown - # flags such as -pthread to the host compiler - set(_CMAKE_CUDA_EXTRA_FLAGS "-forward-unknown-to-host-compiler") -else() - set(_CMAKE_CUDA_EXTRA_FLAGS "") -endif() - -if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0") - set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "-Wno-deprecated-gpu-targets") -else() - set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "") -endif() - -if(CMAKE_CUDA_HOST_COMPILER AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") - string(APPEND _CMAKE_CUDA_EXTRA_FLAGS " -ccbin=<CMAKE_CUDA_HOST_COMPILER>") -endif() - -if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) - # Starting in 10.2, nvcc supported treating all warnings as errors - set(CMAKE_CUDA_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror" "all-warnings") -endif() - -if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) - # The -MD flag was only added to nvcc in 10.2 so - # before that we had to invoke the compiler twice - # to get header dependency information - set(CMAKE_DEPFILE_FLAGS_CUDA "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") -else() - set(CMAKE_CUDA_DEPENDS_EXTRA_COMMANDS "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M <SOURCE> -MT <OBJECT> -o <DEP_FILE>") -endif() -set(CMAKE_CUDA_DEPFILE_FORMAT gcc) -if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) - AND CMAKE_GENERATOR MATCHES "Makefiles|WMake") - set(CMAKE_CUDA_DEPENDS_USE_COMPILER TRUE) -endif() - if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.2) - set(_CMAKE_CUDA_IPO_SUPPORTED_BY_CMAKE YES) - set(_CMAKE_CUDA_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) - set(CMAKE_CUDA_DEVICE_LINK_OPTIONS_IPO " -dlto") endif() -if(NOT "x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") - set(CMAKE_CUDA_COMPILE_OPTIONS_PIE -Xcompiler=-fPIE) - set(CMAKE_CUDA_COMPILE_OPTIONS_PIC -Xcompiler=-fPIC) - set(CMAKE_CUDA_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=) - # CMAKE_SHARED_LIBRARY_CUDA_FLAGS is sent to the host linker so we - # don't need to forward it through nvcc. - set(CMAKE_SHARED_LIBRARY_CUDA_FLAGS -fPIC) - string(APPEND CMAKE_CUDA_FLAGS_INIT " ") - string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -g") - string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") - string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -O1 -DNDEBUG") - string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") -endif() - -set(CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS -shared) -set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA "-isystem ") - -if (CMAKE_CUDA_SIMULATE_ID STREQUAL "GNU") - set(CMAKE_CUDA_LINKER_WRAPPER_FLAG "-Wl,") - set(CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP ",") -elseif(CMAKE_CUDA_SIMULATE_ID STREQUAL "Clang") - set(CMAKE_CUDA_LINKER_WRAPPER_FLAG "-Xlinker" " ") - set(CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP) -endif() - set(CMAKE_CUDA_DEVICE_COMPILER_WRAPPER_FLAG "-Xcompiler=") set(CMAKE_CUDA_DEVICE_COMPILER_WRAPPER_FLAG_SEP ",") set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG "-Xlinker=") set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG_SEP ",") - -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 AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX")) - list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") -endif() - -if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") - # MSVC requires c++14 as the minimum level - set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "") - set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "") - - # MSVC requires c++14 as the minimum level - set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "") - set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "") - - if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0) - 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) - 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() - - if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 12.0) - if(CMAKE_CUDA_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.11.25505) - set(CMAKE_CUDA20_STANDARD_COMPILE_OPTION "-std=c++20") - set(CMAKE_CUDA20_EXTENSION_COMPILE_OPTION "-std=c++20") - endif() - endif() - -else() - set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "") - set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "") - - set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11") - - if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0) - set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03") - set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03") - set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14") - 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") - endif() - - if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 12.0) - set(CMAKE_CUDA20_STANDARD_COMPILE_OPTION "-std=c++20") - set(CMAKE_CUDA20_EXTENSION_COMPILE_OPTION "-std=c++20") - endif() - -endif() - -if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0") - set(CMAKE_CUDA_RESPONSE_FILE_DEVICE_LINK_FLAG "--options-file ") - set(CMAKE_CUDA_RESPONSE_FILE_FLAG "--options-file ") -endif() - -if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0") - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 1) - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 1) - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 1) -else() - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0) - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0) - set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0) -endif() - -__compiler_check_default_language_standard(CUDA 6.0 03) diff --git a/Modules/Compiler/NVIDIA-HIP.cmake b/Modules/Compiler/NVIDIA-HIP.cmake new file mode 100644 index 0000000..c888bc7 --- /dev/null +++ b/Modules/Compiler/NVIDIA-HIP.cmake @@ -0,0 +1,14 @@ +include(Compiler/NVIDIA) +__compiler_nvidia_cxx_standards(HIP) +__compiler_nvidia_cuda_flags(HIP) + +# The ROCm hip-lang cmake package's device runtime library is not needed for NVIDIA GPUs. +set(_CMAKE_HIP_DEVICE_RUNTIME_TARGET "") + +set(CMAKE_HIP_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_HIP_COMPILER_ROCM_ROOT}/include") + +set(CMAKE_HIP_LINK_EXECUTABLE + "<CMAKE_HIP_HOST_LINK_LAUNCHER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICIT_LINKS}") +set(CMAKE_HIP_CREATE_SHARED_LIBRARY + "<CMAKE_HIP_HOST_LINK_LAUNCHER> <CMAKE_SHARED_LIBRARY_HIP_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>${__IMPLICIT_LINKS}") +set(CMAKE_HIP_CREATE_SHARED_MODULE "${CMAKE_HIP_CREATE_SHARED_LIBRARY}") diff --git a/Modules/Compiler/NVIDIA.cmake b/Modules/Compiler/NVIDIA.cmake new file mode 100644 index 0000000..a126c57 --- /dev/null +++ b/Modules/Compiler/NVIDIA.cmake @@ -0,0 +1,168 @@ + +# This module is shared by multiple languages; use include blocker. +if(__COMPILER_NVIDIA) + return() +endif() +set(__COMPILER_NVIDIA 1) + +include(Compiler/CMakeCommonCompilerMacros) + +macro(__compiler_nvidia_cxx_standards lang) + if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") + # MSVC requires c++14 as the minimum level + set(CMAKE_${lang}03_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}03_EXTENSION_COMPILE_OPTION "") + + # MSVC requires c++14 as the minimum level + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "") + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 9.0) + if(CMAKE_${lang}_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.10.25017) + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "-std=c++14") + else() + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "") + endif() + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0) + if(CMAKE_${lang}_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.11.25505) + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std=c++17") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std=c++17") + endif() + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0) + if(CMAKE_${lang}_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.11.25505) + set(CMAKE_${lang}20_STANDARD_COMPILE_OPTION "-std=c++20") + set(CMAKE_${lang}20_EXTENSION_COMPILE_OPTION "-std=c++20") + endif() + endif() + else() + set(CMAKE_${lang}03_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}03_EXTENSION_COMPILE_OPTION "") + + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "-std=c++11") + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 9.0) + set(CMAKE_${lang}03_STANDARD_COMPILE_OPTION "-std=c++03") + set(CMAKE_${lang}03_EXTENSION_COMPILE_OPTION "-std=c++03") + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "-std=c++14") + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0) + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std=c++17") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std=c++17") + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0) + set(CMAKE_${lang}20_STANDARD_COMPILE_OPTION "-std=c++20") + set(CMAKE_${lang}20_EXTENSION_COMPILE_OPTION "-std=c++20") + endif() + endif() + + __compiler_check_default_language_standard(${lang} 6.0 03) +endmacro() + +macro(__compiler_nvidia_cuda_flags lang) + set(CMAKE_${lang}_VERBOSE_FLAG "-v") + set(CMAKE_${lang}_VERBOSE_COMPILE_FLAG "-Xcompiler=-v") + set(_CMAKE_COMPILE_AS_${lang}_FLAG "-x cu") + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) + # The -forward-unknown-to-host-compiler flag was only + # added to nvcc in 10.2 so before that we had no good + # way to invoke the NVCC compiler and propagate unknown + # flags such as -pthread to the host compiler + set(_CMAKE_${lang}_EXTRA_FLAGS "-forward-unknown-to-host-compiler") + else() + set(_CMAKE_${lang}_EXTRA_FLAGS "") + endif() + + if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0") + set(_CMAKE_${lang}_EXTRA_DEVICE_LINK_FLAGS "-Wno-deprecated-gpu-targets") + else() + set(_CMAKE_${lang}_EXTRA_DEVICE_LINK_FLAGS "") + endif() + + if(CMAKE_${lang}_HOST_COMPILER AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") + string(APPEND _CMAKE_${lang}_EXTRA_FLAGS " -ccbin=<CMAKE_${lang}_HOST_COMPILER>") + endif() + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) + # Starting in 10.2, nvcc supported treating all warnings as errors + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror" "all-warnings") + endif() + + set(CMAKE_${lang}_DEPFILE_FORMAT gcc) + if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake") + set(CMAKE_${lang}_DEPENDS_USE_COMPILER TRUE) + endif() + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89) + # The -MD flag was only added to nvcc in 10.2 so + # before that we had to invoke the compiler twice + # to get header dependency information + set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") + else() + set(CMAKE_${lang}_DEPENDS_EXTRA_COMMANDS "<CMAKE_${lang}_COMPILER> ${_CMAKE_${lang}_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_${lang}_FLAG} -M <SOURCE> -MT <OBJECT> -o <DEP_FILE>") + endif() + + if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 11.2) + set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) + set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) + endif() + + if(NOT "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -Xcompiler=-fPIE) + set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -Xcompiler=-fPIC) + set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=) + # CMAKE_SHARED_LIBRARY_${lang}_FLAGS is sent to the host linker so we + # don't need to forward it through nvcc. + set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS -fPIC) + string(APPEND CMAKE_${lang}_FLAGS_INIT " ") + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O1 -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") + endif() + + set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS -shared) + set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") + + if (CMAKE_${lang}_SIMULATE_ID STREQUAL "GNU") + set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,") + set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",") + elseif(CMAKE_${lang}_SIMULATE_ID STREQUAL "Clang") + set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ") + set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP) + endif() + + set(CMAKE_${lang}_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "cudadevrt;cudart_static") + set(CMAKE_${lang}_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "cudadevrt;cudart") + set(CMAKE_${lang}_RUNTIME_LIBRARY_LINK_OPTIONS_NONE "") + + if(UNIX AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX")) + list(APPEND CMAKE_${lang}_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") + endif() + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0") + set(CMAKE_${lang}_RESPONSE_FILE_DEVICE_LINK_FLAG "--options-file ") + set(CMAKE_${lang}_RESPONSE_FILE_FLAG "--options-file ") + endif() + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0") + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1) + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1) + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1) + else() + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 0) + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 0) + set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 0) + endif() +endmacro() diff --git a/Modules/Compiler/OrangeC-ASM.cmake b/Modules/Compiler/OrangeC-ASM.cmake new file mode 100644 index 0000000..fe78911 --- /dev/null +++ b/Modules/Compiler/OrangeC-ASM.cmake @@ -0,0 +1,7 @@ +include(Compiler/OrangeC) +__compiler_orangec(ASM) + +set(CMAKE_ASM_OUTPUT_EXTENSION ".o") +set(CMAKE_ASM_VERBOSE_FLAG "-yyyyy") + +set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm;nas) diff --git a/Modules/Compiler/OrangeC-C.cmake b/Modules/Compiler/OrangeC-C.cmake new file mode 100644 index 0000000..15a6476 --- /dev/null +++ b/Modules/Compiler/OrangeC-C.cmake @@ -0,0 +1,20 @@ +include(Compiler/OrangeC) +include(Compiler/CMakeCommonCompilerMacros) + +set(CMAKE_C_OUTPUT_EXTENSION ".o") +set(CMAKE_C_VERBOSE_FLAG "-yyyyy") +set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c) + +set(CMAKE_C90_STANDARD_COMPILE_OPTION -std=c89) +set(CMAKE_C90_EXTENSION_COMPILE_OPTION -std=c89) +set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON) +set(CMAKE_C99_STANDARD_COMPILE_OPTION -std=c99) +set(CMAKE_C99_EXTENSION_COMPILE_OPTION -std=c99) +set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON) +set(CMAKE_C11_STANDARD_COMPILE_OPTION -std=c11) +set(CMAKE_C11_EXTENSION_COMPILE_OPTION -std=c11) +set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON) + +__compiler_orangec(C) +#- 6.38 is the earliest version which version info is available in the preprocessor +__compiler_check_default_language_standard(C 6.38 11) diff --git a/Modules/Compiler/OrangeC-CXX.cmake b/Modules/Compiler/OrangeC-CXX.cmake new file mode 100644 index 0000000..3f9d59c --- /dev/null +++ b/Modules/Compiler/OrangeC-CXX.cmake @@ -0,0 +1,25 @@ +include(Compiler/OrangeC) +include(Compiler/CMakeCommonCompilerMacros) + +set(_ORANGEC_COMPILE_CXX " -x c++") +set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++) + +set(CMAKE_CXX_OUTPUT_EXTENSION ".o") +set(CMAKE_CXX_VERBOSE_FLAG "-yyyyy") + + + +#- OrangeC is a little lax when accepting compiler version specifications. +# Usually changing the version only changes the value of __cplusplus. +# Also we don't support CXX98 +set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") +set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11") +set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON) + +set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") +set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++14") +set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) + +__compiler_orangec(CXX) +#- 6.38 is the earliest version which version info is available in the preprocessor +__compiler_check_default_language_standard(CXX 6.38 14) diff --git a/Modules/Compiler/OrangeC-DetermineCompiler.cmake b/Modules/Compiler/OrangeC-DetermineCompiler.cmake new file mode 100644 index 0000000..2ecc140 --- /dev/null +++ b/Modules/Compiler/OrangeC-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__ORANGEC__)") + +set(_compiler_id_version_compute " +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__ORANGEC_MAJOR__) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__ORANGEC_MINOR__) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__ORANGEC_PATCHLEVEL__)") diff --git a/Modules/Compiler/OrangeC.cmake b/Modules/Compiler/OrangeC.cmake new file mode 100644 index 0000000..fbb245b --- /dev/null +++ b/Modules/Compiler/OrangeC.cmake @@ -0,0 +1,33 @@ +include_guard() + +macro(__compiler_orangec lang) + if ("x${lang}" MATCHES "^x(C|CXX)$") + set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${_ORANGEC_COMPILE_${lang}} -! <SOURCE> <DEFINES> <INCLUDES> <FLAGS> +i -o <PREPROCESSED_SOURCE>") + set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${_ORANGEC_COMPILE_${lang}} -! <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -S -o <ASSEMBLY_SOURCE>") + endif() + set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${_ORANGEC_COMPILE_${lang}} -! -c <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") + unset(_ORANGEC_COMPILE_${lang}) + + set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") + set(CMAKE_${lang}_DEPFILE_FORMAT gcc) + set(CMAKE_${lang}_DEPENDS_USE_COMPILER TRUE) + + string(APPEND CMAKE_${lang}_FLAGS_INIT " ") + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O2 -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O1 -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") + + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY + "<CMAKE_${lang}_COMPILER> -! -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ") + set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> -! <FLAGS> -o <TARGET> --out-implib <TARGET_IMPLIB> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") + set(CMAKE_${lang}_CREATE_SHARED_LIBRARY + "<CMAKE_${lang}_COMPILER> -! <FLAGS> -o <TARGET> --out-implib <TARGET_IMPLIB> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <OBJECTS> <LINK_LIBRARIES>") + set(CMAKE_${lang}_CREATE_SHARED_MODULE "${CMAKE_${lang}_CREATE_SHARED_LIBRARY}") + + set(CMAKE_LIBRARY_PATH_FLAG "-L") + set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-! -shared") + + set(CMAKE_${lang}_RESPONSE_FILE_FLAG "@") + set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@") +endmacro() diff --git a/Modules/Compiler/PGI.cmake b/Modules/Compiler/PGI.cmake index d111be9..b037fbc 100644 --- a/Modules/Compiler/PGI.cmake +++ b/Modules/Compiler/PGI.cmake @@ -29,7 +29,7 @@ macro(__compiler_pgi lang) set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",") set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) - if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le AND (NOT CMAKE_HOST_WIN32 OR CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 16.3)) + if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le AND (NOT CMAKE_HOST_WIN32 OR CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 16.3) AND CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 23.3) set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-Mipa=fast,inline") else() diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 605908d..3ec0557 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -11,11 +11,8 @@ ExternalProject .. contents:: -Commands -^^^^^^^^ - External Project Definition -""""""""""""""""""""""""""" +^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. command:: ExternalProject_Add @@ -34,866 +31,908 @@ External Project Definition customized. The function supports a large number of options which can be used to tailor the external project behavior. - **Directory Options:** - Most of the time, the default directory layout is sufficient. It is largely - an implementation detail that the main project usually doesn't need to - change. In some circumstances, however, control over the directory layout - can be useful or necessary. The directory options are potentially more - useful from the point of view that the main build can use the - :command:`ExternalProject_Get_Property` command to retrieve their values, - thereby allowing the main project to refer to build artifacts of the - external project. - - ``PREFIX <dir>`` - Root directory for the external project. Unless otherwise noted below, - all other directories associated with the external project will be - created under here. - - ``TMP_DIR <dir>`` - Directory in which to store temporary files. - - ``STAMP_DIR <dir>`` - Directory in which to store the timestamps of each step. Log files from - individual steps are also created in here unless overridden by LOG_DIR - (see *Logging Options* below). - - ``LOG_DIR <dir>`` - .. versionadded:: 3.14 - - Directory in which to store the logs of each step. - - ``DOWNLOAD_DIR <dir>`` - Directory in which to store downloaded files before unpacking them. This - directory is only used by the URL download method, all other download - methods use ``SOURCE_DIR`` directly instead. - - ``SOURCE_DIR <dir>`` - Source directory into which downloaded contents will be unpacked, or for - non-URL download methods, the directory in which the repository should be - checked out, cloned, etc. If no download method is specified, this must - point to an existing directory where the external project has already - been unpacked or cloned/checked out. - - .. note:: - If a download method is specified, any existing contents of the source - directory may be deleted. Only the URL download method checks whether - this directory is either missing or empty before initiating the - download, stopping with an error if it is not empty. All other - download methods silently discard any previous contents of the source - directory. - - ``BINARY_DIR <dir>`` - Specify the build directory location. This option is ignored if - ``BUILD_IN_SOURCE`` is enabled. - - ``INSTALL_DIR <dir>`` - Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder. - This does not actually configure the external project to install to - the given prefix. That must be done by passing appropriate arguments - to the external project configuration step, e.g. using ``<INSTALL_DIR>``. - - If any of the above ``..._DIR`` options are not specified, their defaults - are computed as follows. If the ``PREFIX`` option is given or the - ``EP_PREFIX`` directory property is set, then an external project is built - and installed under the specified prefix:: - - TMP_DIR = <prefix>/tmp - STAMP_DIR = <prefix>/src/<name>-stamp - DOWNLOAD_DIR = <prefix>/src - SOURCE_DIR = <prefix>/src/<name> - BINARY_DIR = <prefix>/src/<name>-build - INSTALL_DIR = <prefix> - LOG_DIR = <STAMP_DIR> - - Otherwise, if the ``EP_BASE`` directory property is set then components - of an external project are stored under the specified base:: - - TMP_DIR = <base>/tmp/<name> - STAMP_DIR = <base>/Stamp/<name> - DOWNLOAD_DIR = <base>/Download/<name> - SOURCE_DIR = <base>/Source/<name> - BINARY_DIR = <base>/Build/<name> - INSTALL_DIR = <base>/Install/<name> - LOG_DIR = <STAMP_DIR> - - If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified, then the - default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are - interpreted with respect to :variable:`CMAKE_CURRENT_BINARY_DIR` at the - point where ``ExternalProject_Add()`` is called. - - **Download Step Options:** - A download method can be omitted if the ``SOURCE_DIR`` option is used to - point to an existing non-empty directory. Otherwise, one of the download - methods below must be specified (multiple download methods should not be - given) or a custom ``DOWNLOAD_COMMAND`` provided. - - ``DOWNLOAD_COMMAND <cmd>...`` - Overrides the command used for the download step - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). If this option is specified, all other download options will - be ignored. Providing an empty string for ``<cmd>`` effectively disables - the download step. - - *URL Download* - ``URL <url1> [<url2>...]`` - List of paths and/or URL(s) of the external project's source. When more - than one URL is given, they are tried in turn until one succeeds. A URL - may be an ordinary path in the local file system (in which case it - must be the only URL provided) or any downloadable URL supported by the - :command:`file(DOWNLOAD)` command. A local filesystem path may refer to - either an existing directory or to an archive file, whereas a URL is - expected to point to a file which can be treated as an archive. When an - archive is used, it will be unpacked automatically unless the - ``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type - is determined by inspecting the actual content rather than using logic - based on the file extension. - - .. versionchanged:: 3.7 - Multiple URLs are allowed. - - ``URL_HASH <algo>=<hashValue>`` - Hash of the archive file to be downloaded. The argument should be of - the form ``<algo>=<hashValue>`` where ``algo`` can be any of the hashing - algorithms supported by the :command:`file()` command. Specifying this - option is strongly recommended for URL downloads, as it ensures the - integrity of the downloaded content. It is also used as a check for a - previously downloaded file, allowing connection to the remote location - to be avoided altogether if the local directory already has a file from - an earlier download that matches the specified hash. - - ``URL_MD5 <md5>`` - Equivalent to ``URL_HASH MD5=<md5>``. - - ``DOWNLOAD_NAME <fname>`` - File name to use for the downloaded file. If not given, the end of the - URL is used to determine the file name. This option is rarely needed, - the default name is generally suitable and is not normally used outside - of code internal to the ``ExternalProject`` module. - - ``DOWNLOAD_EXTRACT_TIMESTAMP <bool>`` - .. versionadded:: 3.24 - - When specified with a true value, the timestamps of the extracted - files will match those in the archive. When false, the timestamps of - the extracted files will reflect the time at which the extraction - was performed. If the download URL changes, timestamps based off - those in the archive can result in dependent targets not being rebuilt - when they potentially should have been. Therefore, unless the file - timestamps are significant to the project in some way, use a false - value for this option. If ``DOWNLOAD_EXTRACT_TIMESTAMP`` is not given, - the default is false. See policy :policy:`CMP0135`. - - ``DOWNLOAD_NO_EXTRACT <bool>`` - .. versionadded:: 3.6 - - Allows the extraction part of the download step to be disabled by - passing a boolean true value for this option. If this option is not - given, the downloaded contents will be unpacked automatically if - required. If extraction has been disabled, the full path to the - downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent - steps or as the property ``DOWNLOADED_FILE`` with the - :command:`ExternalProject_Get_Property` command. - - ``DOWNLOAD_NO_PROGRESS <bool>`` - Can be used to disable logging the download progress. If this option is - not given, download progress messages will be logged. - - ``TIMEOUT <seconds>`` - Maximum time allowed for file download operations. - - ``INACTIVITY_TIMEOUT <seconds>`` - .. versionadded:: 3.19 - - Terminate the operation after a period of inactivity. - - ``HTTP_USERNAME <username>`` - .. versionadded:: 3.7 - - Username for the download operation if authentication is required. - - ``HTTP_PASSWORD <password>`` - .. versionadded:: 3.7 - - Password for the download operation if authentication is required. - - ``HTTP_HEADER <header1> [<header2>...]`` - .. versionadded:: 3.7 - - Provides an arbitrary list of HTTP headers for the download operation. - This can be useful for accessing content in systems like AWS, etc. - - ``TLS_VERIFY <bool>`` - Specifies whether certificate verification should be performed for - https URLs. If this option is not provided, the default behavior is - determined by the :variable:`CMAKE_TLS_VERIFY` variable (see - :command:`file(DOWNLOAD)`). If that is also not set, certificate - verification will not be performed. In situations where ``URL_HASH`` - cannot be provided, this option can be an alternative verification - measure. - - .. versionchanged:: 3.6 - This option also applies to ``git clone`` invocations, although the - default behavior is different. If ``TLS_VERIFY`` is not given and - :variable:`CMAKE_TLS_VERIFY` is not set, the behavior will be - determined by git's defaults. Normally, the ``sslVerify`` git - config setting defaults to true, but the user may have overridden - this at a global level. - - ``TLS_CAINFO <file>`` - Specify a custom certificate authority file to use if ``TLS_VERIFY`` - is enabled. If this option is not specified, the value of the - :variable:`CMAKE_TLS_CAINFO` variable will be used instead (see - :command:`file(DOWNLOAD)`) - - ``NETRC <level>`` - .. versionadded:: 3.11 - - Specify whether the ``.netrc`` file is to be used for operation. - If this option is not specified, the value of the - :variable:`CMAKE_NETRC` variable will be used instead - (see :command:`file(DOWNLOAD)`). Valid levels are: - - ``IGNORED`` - The ``.netrc`` file is ignored. - This is the default. - ``OPTIONAL`` - The ``.netrc`` file is optional, and information in the URL - is preferred. The file will be scanned to find which ever - information is not specified in the URL. - ``REQUIRED`` - The ``.netrc`` file is required, and information in the URL - is ignored. - - ``NETRC_FILE <file>`` - .. versionadded:: 3.11 - - Specify an alternative ``.netrc`` file to the one in your home directory - if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option - is not specified, the value of the :variable:`CMAKE_NETRC_FILE` variable - will be used instead (see :command:`file(DOWNLOAD)`) - - .. versionadded:: 3.1 - Added support for `tbz2`, `.tar.xz`, `.txz`, and `.7z` extensions. - - *Git* - NOTE: A git version of 1.6.5 or later is required if this download method - is used. - - ``GIT_REPOSITORY <url>`` - URL of the git repository. Any URL understood by the ``git`` command - may be used. - - .. versionchanged:: 3.27 - A relative URL will be resolved based on the parent project's - remote, subject to :policy:`CMP0150`. See the policy documentation - for how the remote is selected, including conditions where the - remote selection can fail. Local filesystem remotes should - always use absolute paths. - - ``GIT_TAG <tag>`` - Git branch name, tag or commit hash. Note that branch names and tags - should generally be specified as remote names (i.e. ``origin/myBranch`` - rather than simply ``myBranch``). This ensures that if the remote end - has its tag moved or branch rebased or history rewritten, the local - clone will still be updated correctly. In general, however, specifying - a commit hash should be preferred for a number of reasons: - - - If the local clone already has the commit corresponding to the hash, - no ``git fetch`` needs to be performed to check for changes each time - CMake is re-run. This can result in a significant speed up if many - external projects are being used. - - Using a specific git hash ensures that the main project's own history - is fully traceable to a specific point in the external project's - evolution. If a branch or tag name is used instead, then checking out - a specific commit of the main project doesn't necessarily pin the - whole build to a specific point in the life of the external project. - The lack of such deterministic behavior makes the main project lose - traceability and repeatability. - - If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with - branch names and tags. A commit hash is not allowed. - - Note that if not provided, ``GIT_TAG`` defaults to ``master``, not the - default Git branch name. - - ``GIT_REMOTE_NAME <name>`` - The optional name of the remote. If this option is not specified, it - defaults to ``origin``. - - ``GIT_SUBMODULES <module>...`` - Specific git submodules that should also be updated. If this option is - not provided, all git submodules will be updated. - - .. versionchanged:: 3.16 - When :policy:`CMP0097` is set to ``NEW``, if this value is set - to an empty string then no submodules are initialized or updated. - - ``GIT_SUBMODULES_RECURSE <bool>`` - .. versionadded:: 3.17 - - Specify whether git submodules (if any) should update recursively by - passing the ``--recursive`` flag to ``git submodule update``. - If not specified, the default is on. - - ``GIT_SHALLOW <bool>`` - .. versionadded:: 3.6 - - When this option is enabled, the ``git clone`` operation will be given - the ``--depth 1`` option. This performs a shallow clone, which avoids - downloading the whole history and instead retrieves just the commit - denoted by the ``GIT_TAG`` option. - - ``GIT_PROGRESS <bool>`` - .. versionadded:: 3.8 - - When enabled, this option instructs the ``git clone`` operation to - report its progress by passing it the ``--progress`` option. Without - this option, the clone step for large projects may appear to make the - build stall, since nothing will be logged until the clone operation - finishes. While this option can be used to provide progress to prevent - the appearance of the build having stalled, it may also make the build - overly noisy if lots of external projects are used. - - ``GIT_CONFIG <option1> [<option2>...]`` - .. versionadded:: 3.8 - - Specify a list of config options to pass to ``git clone``. Each option - listed will be transformed into its own ``--config <option>`` on the - ``git clone`` command line, with each option required to be in the - form ``key=value``. - - ``GIT_REMOTE_UPDATE_STRATEGY <strategy>`` - .. versionadded:: 3.18 - - When ``GIT_TAG`` refers to a remote branch, this option can be used to - specify how the update step behaves. The ``<strategy>`` must be one of - the following: - - ``CHECKOUT`` - Ignore the local branch and always checkout the branch specified by - ``GIT_TAG``. - - ``REBASE`` - Try to rebase the current branch to the one specified by ``GIT_TAG``. - If there are local uncommitted changes, they will be stashed first - and popped again after rebasing. If rebasing or popping stashed - changes fail, abort the rebase and halt with an error. - When ``GIT_REMOTE_UPDATE_STRATEGY`` is not present, this is the - default strategy unless the default has been overridden with - ``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` (see below). - Note that if the branch specified in ``GIT_TAG`` is different to - the upstream branch currently being tracked, it is not safe to - perform a rebase. In that situation, ``REBASE`` will silently be - treated as ``CHECKOUT`` instead. - - ``REBASE_CHECKOUT`` - Same as ``REBASE`` except if the rebase fails, an annotated tag will - be created at the original ``HEAD`` position from before the rebase - and then checkout ``GIT_TAG`` just like the ``CHECKOUT`` strategy. - The message stored on the annotated tag will give information about - what was attempted and the tag name will include a timestamp so that - each failed run will add a new tag. This strategy ensures no changes - will be lost, but updates should always succeed if ``GIT_TAG`` refers - to a valid ref unless there are uncommitted changes that cannot be - popped successfully. - - The variable ``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` can be set to - override the default strategy. This variable should not be set by a - project, it is intended for the user to set. It is primarily intended - for use in continuous integration scripts to ensure that when history - is rewritten on a remote branch, the build doesn't end up with - unintended changes or failed builds resulting from conflicts during - rebase operations. - - *Subversion* - ``SVN_REPOSITORY <url>`` - URL of the Subversion repository. - - ``SVN_REVISION -r<rev>`` - Revision to checkout from the Subversion repository. - - ``SVN_USERNAME <username>`` - Username for the Subversion checkout and update. - - ``SVN_PASSWORD <password>`` - Password for the Subversion checkout and update. - - ``SVN_TRUST_CERT <bool>`` - Specifies whether to trust the Subversion server site certificate. If - enabled, the ``--trust-server-cert`` option is passed to the ``svn`` - checkout and update commands. - - *Mercurial* - ``HG_REPOSITORY <url>`` - URL of the mercurial repository. - - ``HG_TAG <tag>`` - Mercurial branch name, tag or commit id. - - *CVS* - ``CVS_REPOSITORY <cvsroot>`` - CVSROOT of the CVS repository. - - ``CVS_MODULE <mod>`` - Module to checkout from the CVS repository. - - ``CVS_TAG <tag>`` - Tag to checkout from the CVS repository. - - **Update Step Options:** - Whenever CMake is re-run, by default the external project's sources will be - updated if the download method supports updates (e.g. a git repository - would be checked if the ``GIT_TAG`` does not refer to a specific commit). - - ``UPDATE_COMMAND <cmd>...`` - Overrides the download method's update step with a custom command. - The command may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - - ``UPDATE_DISCONNECTED <bool>`` - .. versionadded:: 3.2 - - When enabled, this option causes the update step to be skipped (but see - below for changed behavior where this is not the case). It does not - prevent the download step. The update step can still be - added as a step target (see :command:`ExternalProject_Add_StepTargets`) - and called manually. This is useful if you want to allow developers to - build the project when disconnected from the network (the network may - still be needed for the download step though). - - .. versionchanged:: 3.27 - - When ``UPDATE_DISCONNECTED`` is true, the update step will be executed - if any details about the update or download step are changed. - Furthermore, if using the git download/update method, the update - logic will be modified to skip attempts to contact the remote. - If the ``GIT_TAG`` mentions a ref that is not known locally, the - update step will halt with a fatal error. - - When this option is present, it is generally advisable to make the value - a cache variable under the developer's control rather than hard-coding - it. If this option is not present, the default value is taken from the - ``EP_UPDATE_DISCONNECTED`` directory property. If that is also not - defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED`` - directory property is intended as a convenience for controlling the - ``UPDATE_DISCONNECTED`` behavior for an entire section of a project's - directory hierarchy and may be a more convenient method of giving - developers control over whether or not to perform updates (assuming the - 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 Step Options:** - ``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 - to define an appropriate patch command that performs robustly, especially - for download methods such as git where changing the ``GIT_TAG`` will not - discard changes from a previous patch, but the patch command will be - called again after updating to the new tag. - - **Configure Step Options:** - The configure step is run after the download and update steps. By default, - the external project is assumed to be a CMake project, but this can be - overridden if required. - - ``CONFIGURE_COMMAND <cmd>...`` - The default configure command runs CMake with a few options based on - the main project. The options added are typically only those needed to - use the same generator as the main project, but the ``CMAKE_GENERATOR`` - option can be given to override this. The project is responsible for - adding any toolchain details, flags or other settings it wants to - re-use from the main project or otherwise specify (see ``CMAKE_ARGS``, - ``CMAKE_CACHE_ARGS`` and ``CMAKE_CACHE_DEFAULT_ARGS`` below). - - For non-CMake external projects, the ``CONFIGURE_COMMAND`` option must - be used to override the default configure command - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). For projects that require no configure step, specify this - option with an empty string as the command to execute. - - ``CMAKE_COMMAND /.../cmake`` - Specify an alternative cmake executable for the configure step (use an - absolute path). This is generally not recommended, since it is - usually desirable to use the same CMake version throughout the whole - build. This option is ignored if a custom configure command has been - specified with ``CONFIGURE_COMMAND``. - - ``CMAKE_GENERATOR <gen>`` - Override the CMake generator used for the configure step. Without this - option, the same generator as the main build will be used. This option is - ignored if a custom configure command has been specified with the - ``CONFIGURE_COMMAND`` option. - - ``CMAKE_GENERATOR_PLATFORM <platform>`` - .. versionadded:: 3.1 - - Pass a generator-specific platform name to the CMake command (see - :variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this - option without the ``CMAKE_GENERATOR`` option. - - ``CMAKE_GENERATOR_TOOLSET <toolset>`` - Pass a generator-specific toolset name to the CMake command (see - :variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this - option without the ``CMAKE_GENERATOR`` option. - - ``CMAKE_GENERATOR_INSTANCE <instance>`` - .. versionadded:: 3.11 - - Pass a generator-specific instance selection to the CMake command (see - :variable:`CMAKE_GENERATOR_INSTANCE`). It is an error to provide this - option without the ``CMAKE_GENERATOR`` option. - - ``CMAKE_ARGS <arg>...`` - The specified arguments are passed to the :program:`cmake` command line. - They can be any argument the :program:`cmake` command understands, not just - cache values defined by ``-D...`` arguments (see also - :manual:`CMake Options <cmake(1)>`). - - .. versionadded:: 3.3 - Arguments may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - - ``CMAKE_CACHE_ARGS <arg>...`` - This is an alternate way of specifying cache variables where command line - length issues may become a problem. The arguments are expected to be in - the form ``-Dvar:STRING=value``, which are then transformed into - CMake :command:`set` commands with the ``FORCE`` option used. These - ``set()`` commands are written to a pre-load script which is then applied - using the :manual:`cmake -C <cmake(1)>` command line option. - - .. versionadded:: 3.3 - Arguments may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - - ``CMAKE_CACHE_DEFAULT_ARGS <arg>...`` - .. versionadded:: 3.2 - - This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()`` - commands do not include the ``FORCE`` keyword. This means the values act - as initial defaults only and will not override any variables already set - from a previous run. Use this option with care, as it can lead to - different behavior depending on whether the build starts from a fresh - build directory or re-uses previous build contents. - - .. versionadded:: 3.15 - If the CMake generator is the ``Green Hills MULTI`` and not overridden, - the original project's settings for the GHS toolset and target system - customization cache variables are propagated into the external project. - - ``SOURCE_SUBDIR <dir>`` - .. versionadded:: 3.7 - - When no ``CONFIGURE_COMMAND`` option is specified, the configure step - assumes the external project has a ``CMakeLists.txt`` file at the top of - its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option - can be used to point to an alternative directory within the source tree - to use as the top of the CMake source tree instead. This must be a - relative path and it will be interpreted as being relative to - ``SOURCE_DIR``. - - .. versionadded:: 3.14 - When ``BUILD_IN_SOURCE`` option is enabled, the ``BUILD_COMMAND`` - is used to point to an alternative directory within the source tree. - - ``CONFIGURE_HANDLED_BY_BUILD <bool>`` - .. versionadded:: 3.20 - - Enabling this option relaxes the dependencies of the configure step on - other external projects to order-only. This means the configure step will - be executed after its external project dependencies are built but it will - not be marked dirty when one of its external project dependencies is - rebuilt. This option can be enabled when the build step is smart enough - to figure out if the configure step needs to be rerun. CMake and Meson are - examples of build systems whose build step is smart enough to know if the - configure step needs to be rerun. - - **Build Step Options:** - If the configure step assumed the external project uses CMake as its build - system, the build step will also. Otherwise, the build step will assume a - Makefile-based build and simply run ``make`` with no arguments as the - default build step. This can be overridden with custom build commands if - required. - - If both the main project and the external project use make as their build - tool, the build step of the external project is invoked as a recursive - make using ``$(MAKE)``. This will communicate some build tool settings - from the main project to the external project. If either the main project - or external project is not using make, no build tool settings will be - passed to the external project other than those established by the - configure step (i.e. running ``ninja -v`` in the main project will not - pass ``-v`` to the external project's build step, even if it also uses - ``ninja`` as its build tool). - - ``BUILD_COMMAND <cmd>...`` - Overrides the default build command - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). If this option is not given, the default build command will - be chosen to integrate with the main build in the most appropriate way - (e.g. using recursive ``make`` for Makefile generators or - :option:`cmake --build` if the project uses a CMake build). This option - can be specified with an empty string as the command to make the build - step do nothing. - - ``BUILD_IN_SOURCE <bool>`` - When this option is enabled, the build will be done directly within the - external project's source tree. This should generally be avoided, the use - of a separate build directory is usually preferred, but it can be useful - when the external project assumes an in-source build. The ``BINARY_DIR`` - option should not be specified if building in-source. - - ``BUILD_ALWAYS <bool>`` - Enabling this option forces the build step to always be run. This can be - the easiest way to robustly ensure that the external project's own build - dependencies are evaluated rather than relying on the default - success timestamp-based method. This option is not normally needed unless - developers are expected to modify something the external project's build - depends on in a way that is not detectable via the step target - dependencies (e.g. ``SOURCE_DIR`` is used without a download method and - developers might modify the sources in ``SOURCE_DIR``). - - ``BUILD_BYPRODUCTS <file>...`` - .. versionadded:: 3.2 - - Specifies files that will be generated by the build command but which - might or might not have their modification time updated by subsequent - builds. This may also be required to explicitly declare dependencies - when using the :generator:`Ninja` generator. - These ultimately get passed through as ``BYPRODUCTS`` to the - build step's own underlying call to :command:`add_custom_command`, which - has additional documentation. - - **Install Step Options:** - If the configure step assumed the external project uses CMake as its build - system, the install step will also. Otherwise, the install step will assume - a Makefile-based build and simply run ``make install`` as the default build - step. This can be overridden with custom install commands if required. - - ``INSTALL_COMMAND <cmd>...`` - The external project's own install step is invoked as part of the main - project's *build*. It is done after the external project's build step - and may be before or after the external project's test step (see the - ``TEST_BEFORE_INSTALL`` option below). The external project's install - rules are not part of the main project's install rules, so if anything - from the external project should be installed as part of the main build, - these need to be specified in the main build as additional - :command:`install` commands. The default install step builds the - ``install`` target of the external project, but this can be overridden - with a custom command using this option - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). Passing an empty string as the ``<cmd>`` makes the install - step do nothing. - - ``INSTALL_BYPRODUCTS <file>...`` - .. versionadded:: 3.26 - - Specifies files that will be generated by the install command but which - might or might not have their modification time updated by subsequent - installs. This may also be required to explicitly declare dependencies - when using the :generator:`Ninja` generator. - These ultimately get passed through as ``BYPRODUCTS`` to the - install step's own underlying call to :command:`add_custom_command`, which - has additional documentation. - - .. note:: - If the :envvar:`CMAKE_INSTALL_MODE` environment variable is set when the - main project is built, it will only have an effect if the following - conditions are met: - - * The main project's configure step assumed the external project uses - CMake as its build system. - * The external project's install command actually runs. Note that due - to the way ``ExternalProject`` may use timestamps internally, if - nothing the install step depends on needs to be re-executed, the - install command might also not need to run. - - Note also that ``ExternalProject`` does not check whether the - :envvar:`CMAKE_INSTALL_MODE` environment variable changes from one run - to another. - - **Test Step Options:** - The test step is only defined if at least one of the following ``TEST_...`` - options are provided. - - ``TEST_COMMAND <cmd>...`` - Overrides the default test command - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). If this option is not given, the default behavior of the test - step is to build the external project's own ``test`` target. This option - can be specified with ``<cmd>`` as an empty string, which allows the test - step to still be defined, but it will do nothing. Do not specify any of - the other ``TEST_...`` options if providing an empty string as the test - command, but prefer to omit all ``TEST_...`` options altogether if the - test step target is not needed. - - ``TEST_BEFORE_INSTALL <bool>`` - When this option is enabled, the test step will be executed before the - install step. The default behavior is for the test step to run after the - install step. - - ``TEST_AFTER_INSTALL <bool>`` - This option is mainly useful as a way to indicate that the test step is - desired but all default behavior is sufficient. Specifying this option - with a boolean true value ensures the test step is defined and that it - comes after the install step. If both ``TEST_BEFORE_INSTALL`` and - ``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored. - - ``TEST_EXCLUDE_FROM_MAIN <bool>`` - .. versionadded:: 3.2 - - 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 - step in a script to capture its output to files. The log files will be - created in ``LOG_DIR`` if supplied or otherwise the ``STAMP_DIR`` - directory with step-specific file names. - - ``LOG_DOWNLOAD <bool>`` - When enabled, the output of the download step is logged to files. - - ``LOG_UPDATE <bool>`` - When enabled, the output of the update step is logged to files. - - ``LOG_PATCH <bool>`` - .. versionadded:: 3.14 - - When enabled, the output of the patch step is logged to files. - - ``LOG_CONFIGURE <bool>`` - When enabled, the output of the configure step is logged to files. - - ``LOG_BUILD <bool>`` - When enabled, the output of the build step is logged to files. - - ``LOG_INSTALL <bool>`` - When enabled, the output of the install step is logged to files. - - ``LOG_TEST <bool>`` - When enabled, the output of the test step is logged to files. - - ``LOG_MERGED_STDOUTERR <bool>`` - .. versionadded:: 3.14 - - When enabled, stdout and stderr will be merged for any step whose - output is being logged to files. - - ``LOG_OUTPUT_ON_FAILURE <bool>`` - .. versionadded:: 3.14 - - This option only has an effect if at least one of the other ``LOG_<step>`` - options is enabled. If an error occurs for a step which has logging to - file enabled, that step's output will be printed to the console if - ``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount - of output is recorded, just the end of that output may be printed to the - console. - - **Terminal Access Options:** - .. versionadded:: 3.4 - - Steps can be given direct access to the terminal in some cases. Giving a - step access to the terminal may allow it to receive terminal input if - required, such as for authentication details not provided by other options. - With the :generator:`Ninja` generator, these options place the steps in the - ``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access - to the terminal individually via the following options: - - ``USES_TERMINAL_DOWNLOAD <bool>`` - Give the download step access to the terminal. - - ``USES_TERMINAL_UPDATE <bool>`` - Give the update step access to the terminal. - - ``USES_TERMINAL_PATCH <bool>`` - .. versionadded:: 3.23 - - Give the patch step access to the terminal. - - ``USES_TERMINAL_CONFIGURE <bool>`` - Give the configure step access to the terminal. - - ``USES_TERMINAL_BUILD <bool>`` - Give the build step access to the terminal. - - ``USES_TERMINAL_INSTALL <bool>`` - Give the install step access to the terminal. - - ``USES_TERMINAL_TEST <bool>`` - Give the test step access to the terminal. - - **Target Options:** - ``DEPENDS <targets>...`` - Specify other targets on which the external project depends. The other - targets will be brought up to date before any of the external project's - steps are executed. Because the external project uses additional custom - targets internally for each step, the ``DEPENDS`` option is the most - convenient way to ensure all of those steps depend on the other targets. - Simply doing - :command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will - not make any of the steps dependent on ``<targets>``. - - ``EXCLUDE_FROM_ALL <bool>`` - When enabled, this option excludes the external project from the default - ALL target of the main build. - - ``STEP_TARGETS <step-target>...`` - Generate custom targets for the specified steps. This is required if the - 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_StepTargets` below for further - discussion of the effects of this option. - - ``INDEPENDENT_STEP_TARGETS <step-target>...`` - .. deprecated:: 3.19 - 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_StepTargets` below for further discussion - of the effects of this option. - - **Miscellaneous Options:** - ``LIST_SEPARATOR <sep>`` - For any of the various ``..._COMMAND`` options, and ``CMAKE_ARGS``, - replace ``;`` with ``<sep>`` in the specified command lines. - This can be useful where list variables may be given in commands where - they should end up as space-separated arguments (``<sep>`` would be a - single space character string in this case). - - ``COMMAND <cmd>...`` - Any of the other ``..._COMMAND`` options can have additional commands - appended to them by following them with as many ``COMMAND ...`` options - as needed - (:manual:`generator expressions <cmake-generator-expressions(7)>` are - supported). For example: - - .. code-block:: cmake - - ExternalProject_Add(example - ... # Download options, etc. - BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build" - COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> - COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete" - ) +Directory Options +""""""""""""""""" + +Most of the time, the default directory layout is sufficient. It is largely +an implementation detail that the main project usually doesn't need to +change. In some circumstances, however, control over the directory layout +can be useful or necessary. The directory options are potentially more +useful from the point of view that the main build can use the +:command:`ExternalProject_Get_Property` command to retrieve their values, +thereby allowing the main project to refer to build artifacts of the +external project. + +``PREFIX <dir>`` + Root directory for the external project. Unless otherwise noted below, + all other directories associated with the external project will be + created under here. + +``TMP_DIR <dir>`` + Directory in which to store temporary files. + +``STAMP_DIR <dir>`` + Directory in which to store the timestamps of each step. Log files from + individual steps are also created in here unless overridden by LOG_DIR + (see *Logging Options* below). + +``LOG_DIR <dir>`` + .. versionadded:: 3.14 + + Directory in which to store the logs of each step. + +``DOWNLOAD_DIR <dir>`` + Directory in which to store downloaded files before unpacking them. This + directory is only used by the URL download method, all other download + methods use ``SOURCE_DIR`` directly instead. + +``SOURCE_DIR <dir>`` + Source directory into which downloaded contents will be unpacked, or for + non-URL download methods, the directory in which the repository should be + checked out, cloned, etc. If no download method is specified, this must + point to an existing directory where the external project has already + been unpacked or cloned/checked out. + + .. note:: + If a download method is specified, any existing contents of the source + directory may be deleted. Only the URL download method checks whether + this directory is either missing or empty before initiating the + download, stopping with an error if it is not empty. All other + download methods silently discard any previous contents of the source + directory. + +``BINARY_DIR <dir>`` + Specify the build directory location. This option is ignored if + ``BUILD_IN_SOURCE`` is enabled. + +``INSTALL_DIR <dir>`` + Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder. + This does not actually configure the external project to install to + the given prefix. That must be done by passing appropriate arguments + to the external project configuration step, e.g. using ``<INSTALL_DIR>``. + +If any of the above ``..._DIR`` options are not specified, their defaults +are computed as follows. If the ``PREFIX`` option is given or the +``EP_PREFIX`` directory property is set, then an external project is built +and installed under the specified prefix:: + + TMP_DIR = <prefix>/tmp + STAMP_DIR = <prefix>/src/<name>-stamp + DOWNLOAD_DIR = <prefix>/src + SOURCE_DIR = <prefix>/src/<name> + BINARY_DIR = <prefix>/src/<name>-build + INSTALL_DIR = <prefix> + LOG_DIR = <STAMP_DIR> + +Otherwise, if the ``EP_BASE`` directory property is set then components +of an external project are stored under the specified base:: + + TMP_DIR = <base>/tmp/<name> + STAMP_DIR = <base>/Stamp/<name> + DOWNLOAD_DIR = <base>/Download/<name> + SOURCE_DIR = <base>/Source/<name> + BINARY_DIR = <base>/Build/<name> + INSTALL_DIR = <base>/Install/<name> + LOG_DIR = <STAMP_DIR> + +If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified, then the +default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are +interpreted with respect to :variable:`CMAKE_CURRENT_BINARY_DIR` at the +point where ``ExternalProject_Add()`` is called. + +Download Step Options +""""""""""""""""""""" + +A download method can be omitted if the ``SOURCE_DIR`` option is used to +point to an existing non-empty directory. Otherwise, one of the download +methods below must be specified (multiple download methods should not be +given) or a custom ``DOWNLOAD_COMMAND`` provided. + +``DOWNLOAD_COMMAND <cmd>...`` + Overrides the command used for the download step + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is specified, all other download options will + be ignored. Providing an empty string for ``<cmd>`` effectively disables + the download step. + +URL +~~~ + +``URL <url1> [<url2>...]`` + List of paths and/or URL(s) of the external project's source. When more + than one URL is given, they are tried in turn until one succeeds. A URL + may be an ordinary path in the local file system (in which case it + must be the only URL provided) or any downloadable URL supported by the + :command:`file(DOWNLOAD)` command. A local filesystem path may refer to + either an existing directory or to an archive file, whereas a URL is + expected to point to a file which can be treated as an archive. When an + archive is used, it will be unpacked automatically unless the + ``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type + is determined by inspecting the actual content rather than using logic + based on the file extension. + + .. versionchanged:: 3.7 + Multiple URLs are allowed. + +``URL_HASH <algo>=<hashValue>`` + Hash of the archive file to be downloaded. The argument should be of + the form ``<algo>=<hashValue>`` where ``algo`` can be any of the hashing + algorithms supported by the :command:`file()` command. Specifying this + option is strongly recommended for URL downloads, as it ensures the + integrity of the downloaded content. It is also used as a check for a + previously downloaded file, allowing connection to the remote location + to be avoided altogether if the local directory already has a file from + an earlier download that matches the specified hash. + +``URL_MD5 <md5>`` + Equivalent to ``URL_HASH MD5=<md5>``. + +``DOWNLOAD_NAME <fname>`` + File name to use for the downloaded file. If not given, the end of the + URL is used to determine the file name. This option is rarely needed, + the default name is generally suitable and is not normally used outside + of code internal to the ``ExternalProject`` module. + +``DOWNLOAD_EXTRACT_TIMESTAMP <bool>`` + .. versionadded:: 3.24 + + When specified with a true value, the timestamps of the extracted + files will match those in the archive. When false, the timestamps of + the extracted files will reflect the time at which the extraction + was performed. If the download URL changes, timestamps based off + those in the archive can result in dependent targets not being rebuilt + when they potentially should have been. Therefore, unless the file + timestamps are significant to the project in some way, use a false + value for this option. If ``DOWNLOAD_EXTRACT_TIMESTAMP`` is not given, + the default is false. See policy :policy:`CMP0135`. + +``DOWNLOAD_NO_EXTRACT <bool>`` + .. versionadded:: 3.6 + + Allows the extraction part of the download step to be disabled by + passing a boolean true value for this option. If this option is not + given, the downloaded contents will be unpacked automatically if + required. If extraction has been disabled, the full path to the + downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent + steps or as the property ``DOWNLOADED_FILE`` with the + :command:`ExternalProject_Get_Property` command. + +``DOWNLOAD_NO_PROGRESS <bool>`` + Can be used to disable logging the download progress. If this option is + not given, download progress messages will be logged. + +``TIMEOUT <seconds>`` + Maximum time allowed for file download operations. + +``INACTIVITY_TIMEOUT <seconds>`` + .. versionadded:: 3.19 + + Terminate the operation after a period of inactivity. + +``HTTP_USERNAME <username>`` + .. versionadded:: 3.7 + + Username for the download operation if authentication is required. + +``HTTP_PASSWORD <password>`` + .. versionadded:: 3.7 + + Password for the download operation if authentication is required. + +``HTTP_HEADER <header1> [<header2>...]`` + .. versionadded:: 3.7 + + Provides an arbitrary list of HTTP headers for the download operation. + This can be useful for accessing content in systems like AWS, etc. + +``TLS_VERIFY <bool>`` + Specifies whether certificate verification should be performed for + https URLs. If this option is not provided, the default behavior is + determined by the :variable:`CMAKE_TLS_VERIFY` variable (see + :command:`file(DOWNLOAD)`). If that is also not set, certificate + verification will not be performed. In situations where ``URL_HASH`` + cannot be provided, this option can be an alternative verification + measure. + + .. versionchanged:: 3.6 + This option also applies to ``git clone`` invocations, although the + default behavior is different. If ``TLS_VERIFY`` is not given and + :variable:`CMAKE_TLS_VERIFY` is not set, the behavior will be + determined by git's defaults. Normally, the ``sslVerify`` git + config setting defaults to true, but the user may have overridden + this at a global level. + +``TLS_CAINFO <file>`` + Specify a custom certificate authority file to use if ``TLS_VERIFY`` + is enabled. If this option is not specified, the value of the + :variable:`CMAKE_TLS_CAINFO` variable will be used instead (see + :command:`file(DOWNLOAD)`) + +``NETRC <level>`` + .. versionadded:: 3.11 + + Specify whether the ``.netrc`` file is to be used for operation. + If this option is not specified, the value of the + :variable:`CMAKE_NETRC` variable will be used instead + (see :command:`file(DOWNLOAD)`). Valid levels are: + + ``IGNORED`` + The ``.netrc`` file is ignored. + This is the default. + ``OPTIONAL`` + The ``.netrc`` file is optional, and information in the URL + is preferred. The file will be scanned to find which ever + information is not specified in the URL. + ``REQUIRED`` + The ``.netrc`` file is required, and information in the URL + is ignored. + +``NETRC_FILE <file>`` + .. versionadded:: 3.11 + + Specify an alternative ``.netrc`` file to the one in your home directory + if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option + is not specified, the value of the :variable:`CMAKE_NETRC_FILE` variable + will be used instead (see :command:`file(DOWNLOAD)`) + +.. versionadded:: 3.1 + Added support for `tbz2`, `.tar.xz`, `.txz`, and `.7z` extensions. + +Git +~~~ + +NOTE: A git version of 1.6.5 or later is required if this download method +is used. + +``GIT_REPOSITORY <url>`` + URL of the git repository. Any URL understood by the ``git`` command + may be used. + + .. versionchanged:: 3.27 + A relative URL will be resolved based on the parent project's + remote, subject to :policy:`CMP0150`. See the policy documentation + for how the remote is selected, including conditions where the + remote selection can fail. Local filesystem remotes should + always use absolute paths. + +``GIT_TAG <tag>`` + Git branch name, tag or commit hash. Note that branch names and tags + should generally be specified as remote names (i.e. ``origin/myBranch`` + rather than simply ``myBranch``). This ensures that if the remote end + has its tag moved or branch rebased or history rewritten, the local + clone will still be updated correctly. In general, however, specifying + a commit hash should be preferred for a number of reasons: + + - If the local clone already has the commit corresponding to the hash, + no ``git fetch`` needs to be performed to check for changes each time + CMake is re-run. This can result in a significant speed up if many + external projects are being used. + - Using a specific git hash ensures that the main project's own history + is fully traceable to a specific point in the external project's + evolution. If a branch or tag name is used instead, then checking out + a specific commit of the main project doesn't necessarily pin the + whole build to a specific point in the life of the external project. + The lack of such deterministic behavior makes the main project lose + traceability and repeatability. + + If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with + branch names and tags. A commit hash is not allowed. + + Note that if not provided, ``GIT_TAG`` defaults to ``master``, not the + default Git branch name. + +``GIT_REMOTE_NAME <name>`` + The optional name of the remote. If this option is not specified, it + defaults to ``origin``. + +``GIT_SUBMODULES <module>...`` + Specific git submodules that should also be updated. If this option is + not provided, all git submodules will be updated. + + .. versionchanged:: 3.16 + When :policy:`CMP0097` is set to ``NEW``, if this value is set + to an empty string then no submodules are initialized or updated. + +``GIT_SUBMODULES_RECURSE <bool>`` + .. versionadded:: 3.17 + + Specify whether git submodules (if any) should update recursively by + passing the ``--recursive`` flag to ``git submodule update``. + If not specified, the default is on. + +``GIT_SHALLOW <bool>`` + .. versionadded:: 3.6 + + When this option is enabled, the ``git clone`` operation will be given + the ``--depth 1`` option. This performs a shallow clone, which avoids + downloading the whole history and instead retrieves just the commit + denoted by the ``GIT_TAG`` option. + +``GIT_PROGRESS <bool>`` + .. versionadded:: 3.8 + + When enabled, this option instructs the ``git clone`` operation to + report its progress by passing it the ``--progress`` option. Without + this option, the clone step for large projects may appear to make the + build stall, since nothing will be logged until the clone operation + finishes. While this option can be used to provide progress to prevent + the appearance of the build having stalled, it may also make the build + overly noisy if lots of external projects are used. + +``GIT_CONFIG <option1> [<option2>...]`` + .. versionadded:: 3.8 + + Specify a list of config options to pass to ``git clone``. Each option + listed will be transformed into its own ``--config <option>`` on the + ``git clone`` command line, with each option required to be in the + form ``key=value``. + +``GIT_REMOTE_UPDATE_STRATEGY <strategy>`` + .. versionadded:: 3.18 + + When ``GIT_TAG`` refers to a remote branch, this option can be used to + specify how the update step behaves. The ``<strategy>`` must be one of + the following: + + ``CHECKOUT`` + Ignore the local branch and always checkout the branch specified by + ``GIT_TAG``. + + ``REBASE`` + Try to rebase the current branch to the one specified by ``GIT_TAG``. + If there are local uncommitted changes, they will be stashed first + and popped again after rebasing. If rebasing or popping stashed + changes fail, abort the rebase and halt with an error. + When ``GIT_REMOTE_UPDATE_STRATEGY`` is not present, this is the + default strategy unless the default has been overridden with + ``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` (see below). + Note that if the branch specified in ``GIT_TAG`` is different to + the upstream branch currently being tracked, it is not safe to + perform a rebase. In that situation, ``REBASE`` will silently be + treated as ``CHECKOUT`` instead. + + ``REBASE_CHECKOUT`` + Same as ``REBASE`` except if the rebase fails, an annotated tag will + be created at the original ``HEAD`` position from before the rebase + and then checkout ``GIT_TAG`` just like the ``CHECKOUT`` strategy. + The message stored on the annotated tag will give information about + what was attempted and the tag name will include a timestamp so that + each failed run will add a new tag. This strategy ensures no changes + will be lost, but updates should always succeed if ``GIT_TAG`` refers + to a valid ref unless there are uncommitted changes that cannot be + popped successfully. + + The variable ``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` can be set to + override the default strategy. This variable should not be set by a + project, it is intended for the user to set. It is primarily intended + for use in continuous integration scripts to ensure that when history + is rewritten on a remote branch, the build doesn't end up with + unintended changes or failed builds resulting from conflicts during + rebase operations. + +Subversion +~~~~~~~~~~ + +``SVN_REPOSITORY <url>`` + URL of the Subversion repository. + +``SVN_REVISION -r<rev>`` + Revision to checkout from the Subversion repository. + +``SVN_USERNAME <username>`` + Username for the Subversion checkout and update. + +``SVN_PASSWORD <password>`` + Password for the Subversion checkout and update. + +``SVN_TRUST_CERT <bool>`` + Specifies whether to trust the Subversion server site certificate. If + enabled, the ``--trust-server-cert`` option is passed to the ``svn`` + checkout and update commands. + +Mercurial +~~~~~~~~~ + +``HG_REPOSITORY <url>`` + URL of the mercurial repository. + +``HG_TAG <tag>`` + Mercurial branch name, tag or commit id. + +CVS +~~~ + +``CVS_REPOSITORY <cvsroot>`` + CVSROOT of the CVS repository. + +``CVS_MODULE <mod>`` + Module to checkout from the CVS repository. + +``CVS_TAG <tag>`` + Tag to checkout from the CVS repository. + +Update Step Options +""""""""""""""""""" + +Whenever CMake is re-run, by default the external project's sources will be +updated if the download method supports updates (e.g. a git repository +would be checked if the ``GIT_TAG`` does not refer to a specific commit). + +``UPDATE_COMMAND <cmd>...`` + Overrides the download method's update step with a custom command. + The command may use + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +``UPDATE_DISCONNECTED <bool>`` + .. versionadded:: 3.2 + + When enabled, this option causes the update step to be skipped (but see + below for changed behavior where this is not the case). It does not + prevent the download step. The update step can still be + added as a step target (see :command:`ExternalProject_Add_StepTargets`) + and called manually. This is useful if you want to allow developers to + build the project when disconnected from the network (the network may + still be needed for the download step though). + + .. versionchanged:: 3.27 + + When ``UPDATE_DISCONNECTED`` is true, the update step will be executed + if any details about the update or download step are changed. + Furthermore, if using the git download/update method, the update + logic will be modified to skip attempts to contact the remote. + If the ``GIT_TAG`` mentions a ref that is not known locally, the + update step will halt with a fatal error. + + When this option is present, it is generally advisable to make the value + a cache variable under the developer's control rather than hard-coding + it. If this option is not present, the default value is taken from the + ``EP_UPDATE_DISCONNECTED`` directory property. If that is also not + defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED`` + directory property is intended as a convenience for controlling the + ``UPDATE_DISCONNECTED`` behavior for an entire section of a project's + directory hierarchy and may be a more convenient method of giving + developers control over whether or not to perform updates (assuming the + 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 Step Options +"""""""""""""""""" + +``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 + to define an appropriate patch command that performs robustly, especially + for download methods such as git where changing the ``GIT_TAG`` will not + discard changes from a previous patch, but the patch command will be + called again after updating to the new tag. + +Configure Step Options +"""""""""""""""""""""" + +The configure step is run after the download and update steps. By default, +the external project is assumed to be a CMake project, but this can be +overridden if required. + +``CONFIGURE_COMMAND <cmd>...`` + The default configure command runs CMake with a few options based on + the main project. The options added are typically only those needed to + use the same generator as the main project, but the ``CMAKE_GENERATOR`` + option can be given to override this. The project is responsible for + adding any toolchain details, flags or other settings it wants to + reuse from the main project or otherwise specify (see ``CMAKE_ARGS``, + ``CMAKE_CACHE_ARGS`` and ``CMAKE_CACHE_DEFAULT_ARGS`` below). + + For non-CMake external projects, the ``CONFIGURE_COMMAND`` option must + be used to override the default configure command + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). For projects that require no configure step, specify this + option with an empty string as the command to execute. + +``CMAKE_COMMAND /.../cmake`` + Specify an alternative cmake executable for the configure step (use an + absolute path). This is generally not recommended, since it is + usually desirable to use the same CMake version throughout the whole + build. This option is ignored if a custom configure command has been + specified with ``CONFIGURE_COMMAND``. + +``CMAKE_GENERATOR <gen>`` + Override the CMake generator used for the configure step. Without this + option, the same generator as the main build will be used. This option is + ignored if a custom configure command has been specified with the + ``CONFIGURE_COMMAND`` option. + +``CMAKE_GENERATOR_PLATFORM <platform>`` + .. versionadded:: 3.1 + + Pass a generator-specific platform name to the CMake command (see + :variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this + option without the ``CMAKE_GENERATOR`` option. + +``CMAKE_GENERATOR_TOOLSET <toolset>`` + Pass a generator-specific toolset name to the CMake command (see + :variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this + option without the ``CMAKE_GENERATOR`` option. + +``CMAKE_GENERATOR_INSTANCE <instance>`` + .. versionadded:: 3.11 + + Pass a generator-specific instance selection to the CMake command (see + :variable:`CMAKE_GENERATOR_INSTANCE`). It is an error to provide this + option without the ``CMAKE_GENERATOR`` option. + +``CMAKE_ARGS <arg>...`` + The specified arguments are passed to the :program:`cmake` command line. + They can be any argument the :program:`cmake` command understands, not just + cache values defined by ``-D...`` arguments (see also + :manual:`CMake Options <cmake(1)>`). + + .. versionadded:: 3.3 + Arguments may use + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +``CMAKE_CACHE_ARGS <arg>...`` + This is an alternate way of specifying cache variables where command line + length issues may become a problem. The arguments are expected to be in + the form ``-Dvar:STRING=value``, which are then transformed into + CMake :command:`set` commands with the ``FORCE`` option used. These + ``set()`` commands are written to a pre-load script which is then applied + using the :manual:`cmake -C <cmake(1)>` command line option. + + .. versionadded:: 3.3 + Arguments may use + :manual:`generator expressions <cmake-generator-expressions(7)>`. + +``CMAKE_CACHE_DEFAULT_ARGS <arg>...`` + .. versionadded:: 3.2 + + This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()`` + commands do not include the ``FORCE`` keyword. This means the values act + as initial defaults only and will not override any variables already set + from a previous run. Use this option with care, as it can lead to + different behavior depending on whether the build starts from a fresh + build directory or reuses previous build contents. + + .. versionadded:: 3.15 + If the CMake generator is the ``Green Hills MULTI`` and not overridden, + the original project's settings for the GHS toolset and target system + customization cache variables are propagated into the external project. + +``SOURCE_SUBDIR <dir>`` + .. versionadded:: 3.7 + + When no ``CONFIGURE_COMMAND`` option is specified, the configure step + assumes the external project has a ``CMakeLists.txt`` file at the top of + its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option + can be used to point to an alternative directory within the source tree + to use as the top of the CMake source tree instead. This must be a + relative path and it will be interpreted as being relative to + ``SOURCE_DIR``. + + .. versionadded:: 3.14 + When ``BUILD_IN_SOURCE`` option is enabled, the ``BUILD_COMMAND`` + is used to point to an alternative directory within the source tree. + +``CONFIGURE_HANDLED_BY_BUILD <bool>`` + .. versionadded:: 3.20 + + Enabling this option relaxes the dependencies of the configure step on + other external projects to order-only. This means the configure step will + be executed after its external project dependencies are built but it will + not be marked dirty when one of its external project dependencies is + rebuilt. This option can be enabled when the build step is smart enough + to figure out if the configure step needs to be rerun. CMake and Meson are + examples of build systems whose build step is smart enough to know if the + configure step needs to be rerun. + +Build Step Options +"""""""""""""""""" + +If the configure step assumed the external project uses CMake as its build +system, the build step will also. Otherwise, the build step will assume a +Makefile-based build and simply run ``make`` with no arguments as the +default build step. This can be overridden with custom build commands if +required. + +If both the main project and the external project use make as their build +tool, the build step of the external project is invoked as a recursive +make using ``$(MAKE)``. This will communicate some build tool settings +from the main project to the external project. If either the main project +or external project is not using make, no build tool settings will be +passed to the external project other than those established by the +configure step (i.e. running ``ninja -v`` in the main project will not +pass ``-v`` to the external project's build step, even if it also uses +``ninja`` as its build tool). + +``BUILD_COMMAND <cmd>...`` + Overrides the default build command + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is not given, the default build command will + be chosen to integrate with the main build in the most appropriate way + (e.g. using recursive ``make`` for Makefile generators or + :option:`cmake --build` if the project uses a CMake build). This option + can be specified with an empty string as the command to make the build + step do nothing. + +``BUILD_IN_SOURCE <bool>`` + When this option is enabled, the build will be done directly within the + external project's source tree. This should generally be avoided, the use + of a separate build directory is usually preferred, but it can be useful + when the external project assumes an in-source build. The ``BINARY_DIR`` + option should not be specified if building in-source. + +``BUILD_ALWAYS <bool>`` + Enabling this option forces the build step to always be run. This can be + the easiest way to robustly ensure that the external project's own build + dependencies are evaluated rather than relying on the default + success timestamp-based method. This option is not normally needed unless + developers are expected to modify something the external project's build + depends on in a way that is not detectable via the step target + dependencies (e.g. ``SOURCE_DIR`` is used without a download method and + developers might modify the sources in ``SOURCE_DIR``). + +``BUILD_BYPRODUCTS <file>...`` + .. versionadded:: 3.2 + + Specifies files that will be generated by the build command but which + might or might not have their modification time updated by subsequent + builds. This may also be required to explicitly declare dependencies + when using the :generator:`Ninja` generator. + These ultimately get passed through as ``BYPRODUCTS`` to the + build step's own underlying call to :command:`add_custom_command`, which + has additional documentation. + +``BUILD_JOB_SERVER_AWARE <bool>`` + .. versionadded:: 3.28 + + Specifies that the build step is aware of the GNU Make job server. + See the :command:`add_custom_command` documentation of its + ``JOB_SERVER_AWARE`` option for details. This option is relevant + only when an explicit ``BUILD_COMMAND`` is specified. + +Install Step Options +"""""""""""""""""""" + +If the configure step assumed the external project uses CMake as its build +system, the install step will also. Otherwise, the install step will assume +a Makefile-based build and simply run ``make install`` as the default build +step. This can be overridden with custom install commands if required. + +``INSTALL_COMMAND <cmd>...`` + The external project's own install step is invoked as part of the main + project's *build*. It is done after the external project's build step + and may be before or after the external project's test step (see the + ``TEST_BEFORE_INSTALL`` option below). The external project's install + rules are not part of the main project's install rules, so if anything + from the external project should be installed as part of the main build, + these need to be specified in the main build as additional + :command:`install` commands. The default install step builds the + ``install`` target of the external project, but this can be overridden + with a custom command using this option + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). Passing an empty string as the ``<cmd>`` makes the install + step do nothing. + +``INSTALL_BYPRODUCTS <file>...`` + .. versionadded:: 3.26 + + Specifies files that will be generated by the install command but which + might or might not have their modification time updated by subsequent + installs. This may also be required to explicitly declare dependencies + when using the :generator:`Ninja` generator. + These ultimately get passed through as ``BYPRODUCTS`` to the + install step's own underlying call to :command:`add_custom_command`, which + has additional documentation. + +.. note:: + If the :envvar:`CMAKE_INSTALL_MODE` environment variable is set when the + main project is built, it will only have an effect if the following + conditions are met: + + * The main project's configure step assumed the external project uses + CMake as its build system. + * The external project's install command actually runs. Note that due + to the way ``ExternalProject`` may use timestamps internally, if + nothing the install step depends on needs to be re-executed, the + install command might also not need to run. + + Note also that ``ExternalProject`` does not check whether the + :envvar:`CMAKE_INSTALL_MODE` environment variable changes from one run + to another. + +Test Step Options +""""""""""""""""" + +The test step is only defined if at least one of the following ``TEST_...`` +options are provided. + +``TEST_COMMAND <cmd>...`` + Overrides the default test command + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is not given, the default behavior of the test + step is to build the external project's own ``test`` target. This option + can be specified with ``<cmd>`` as an empty string, which allows the test + step to still be defined, but it will do nothing. Do not specify any of + the other ``TEST_...`` options if providing an empty string as the test + command, but prefer to omit all ``TEST_...`` options altogether if the + test step target is not needed. + +``TEST_BEFORE_INSTALL <bool>`` + When this option is enabled, the test step will be executed before the + install step. The default behavior is for the test step to run after the + install step. + +``TEST_AFTER_INSTALL <bool>`` + This option is mainly useful as a way to indicate that the test step is + desired but all default behavior is sufficient. Specifying this option + with a boolean true value ensures the test step is defined and that it + comes after the install step. If both ``TEST_BEFORE_INSTALL`` and + ``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored. + +``TEST_EXCLUDE_FROM_MAIN <bool>`` + .. versionadded:: 3.2 + + 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 +step in a script to capture its output to files. The log files will be +created in ``LOG_DIR`` if supplied or otherwise the ``STAMP_DIR`` +directory with step-specific file names. + +``LOG_DOWNLOAD <bool>`` + When enabled, the output of the download step is logged to files. + +``LOG_UPDATE <bool>`` + When enabled, the output of the update step is logged to files. + +``LOG_PATCH <bool>`` + .. versionadded:: 3.14 + + When enabled, the output of the patch step is logged to files. - It should also be noted that each build step is created via a call to - :command:`ExternalProject_Add_Step`. See that command's documentation for the - automatic substitutions that are supported for some options. +``LOG_CONFIGURE <bool>`` + When enabled, the output of the configure step is logged to files. + +``LOG_BUILD <bool>`` + When enabled, the output of the build step is logged to files. + +``LOG_INSTALL <bool>`` + When enabled, the output of the install step is logged to files. + +``LOG_TEST <bool>`` + When enabled, the output of the test step is logged to files. + +``LOG_MERGED_STDOUTERR <bool>`` + .. versionadded:: 3.14 + + When enabled, stdout and stderr will be merged for any step whose + output is being logged to files. + +``LOG_OUTPUT_ON_FAILURE <bool>`` + .. versionadded:: 3.14 + + This option only has an effect if at least one of the other ``LOG_<step>`` + options is enabled. If an error occurs for a step which has logging to + file enabled, that step's output will be printed to the console if + ``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount + of output is recorded, just the end of that output may be printed to the + console. + +Terminal Access Options +""""""""""""""""""""""" + +.. versionadded:: 3.4 + +Steps can be given direct access to the terminal in some cases. Giving a +step access to the terminal may allow it to receive terminal input if +required, such as for authentication details not provided by other options. +With the :generator:`Ninja` generator, these options place the steps in the +``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access +to the terminal individually via the following options: + +``USES_TERMINAL_DOWNLOAD <bool>`` + Give the download step access to the terminal. + +``USES_TERMINAL_UPDATE <bool>`` + Give the update step access to the terminal. + +``USES_TERMINAL_PATCH <bool>`` + .. versionadded:: 3.23 + + Give the patch step access to the terminal. + +``USES_TERMINAL_CONFIGURE <bool>`` + Give the configure step access to the terminal. + +``USES_TERMINAL_BUILD <bool>`` + Give the build step access to the terminal. + +``USES_TERMINAL_INSTALL <bool>`` + Give the install step access to the terminal. + +``USES_TERMINAL_TEST <bool>`` + Give the test step access to the terminal. + +Target Options +"""""""""""""" + +``DEPENDS <targets>...`` + Specify other targets on which the external project depends. The other + targets will be brought up to date before any of the external project's + steps are executed. Because the external project uses additional custom + targets internally for each step, the ``DEPENDS`` option is the most + convenient way to ensure all of those steps depend on the other targets. + Simply doing + :command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will + not make any of the steps dependent on ``<targets>``. + +``EXCLUDE_FROM_ALL <bool>`` + When enabled, this option excludes the external project from the default + ALL target of the main build. + +``STEP_TARGETS <step-target>...`` + Generate custom targets for the specified steps. This is required if the + 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_StepTargets` below for further + discussion of the effects of this option. + +``INDEPENDENT_STEP_TARGETS <step-target>...`` + .. deprecated:: 3.19 + 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_StepTargets` below for further discussion + of the effects of this option. + +Miscellaneous Options +""""""""""""""""""""" + +``LIST_SEPARATOR <sep>`` + For any of the various ``..._COMMAND`` options, and ``CMAKE_ARGS``, + replace ``;`` with ``<sep>`` in the specified command lines. + This can be useful where list variables may be given in commands where + they should end up as space-separated arguments (``<sep>`` would be a + single space character string in this case). + +``COMMAND <cmd>...`` + Any of the other ``..._COMMAND`` options can have additional commands + appended to them by following them with as many ``COMMAND ...`` options + as needed + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). For example: + + .. code-block:: cmake + + ExternalProject_Add(example + ... # Download options, etc. + BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build" + COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> + COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete" + ) + +It should also be noted that each build step is created via a call to +:command:`ExternalProject_Add_Step`. See that command's documentation for the +automatic substitutions that are supported for some options. Obtaining Project Properties -"""""""""""""""""""""""""""" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. command:: ExternalProject_Get_Property @@ -914,7 +953,7 @@ Obtaining Project Properties message("Source dir of myExtProj = ${SOURCE_DIR}") Explicit Step Management -"""""""""""""""""""""""" +^^^^^^^^^^^^^^^^^^^^^^^^ The ``ExternalProject_Add()`` function on its own is often sufficient for incorporating an external project into the main build. Certain scenarios @@ -990,6 +1029,13 @@ control needed to implement such step-level capabilities. When enabled, this option specifies that the custom step should always be run (i.e. that it is always considered out of date). + ``JOB_SERVER_AWARE <bool>`` + .. versionadded:: 3.28 + + Specifies that the custom step is aware of the GNU Make job server. + See the :command:`add_custom_command` documentation of its + ``JOB_SERVER_AWARE`` option for details. + ``EXCLUDE_FROM_MAIN <bool>`` When enabled, this option specifies that the external project's main target does not depend on the custom step. @@ -2335,6 +2381,7 @@ function(ExternalProject_Add_Step name step) INDEPENDENT BYPRODUCTS ALWAYS + JOB_SERVER_AWARE EXCLUDE_FROM_MAIN WORKING_DIRECTORY LOG @@ -2514,6 +2561,16 @@ function(ExternalProject_Add_Step name step) set(maybe_COMMAND_touch "COMMAND \${CMAKE_COMMAND} -E touch \${stamp_file}") endif() + get_property(job_server_aware + TARGET ${name} + PROPERTY _EP_${step}_JOB_SERVER_AWARE + ) + if(job_server_aware) + set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1") + else() + set(maybe_JOB_SERVER_AWARE "") + endif() + # Wrap with log script? get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG) if(command AND log) @@ -2540,6 +2597,7 @@ function(ExternalProject_Add_Step name step) COMMENT \${comment} COMMAND ${__cmdQuoted} ${maybe_COMMAND_touch} + ${maybe_JOB_SERVER_AWARE} DEPENDS \${depends} WORKING_DIRECTORY \${work_dir} VERBATIM @@ -2767,6 +2825,7 @@ function(_ep_add_download_command name) set(comment) set(work_dir) set(extra_repo_info) + set(byproduct_file) if(cmd_set) set(work_dir ${download_dir}) @@ -2811,7 +2870,8 @@ function(_ep_add_download_command name) TARGET ${name} PROPERTY _EP_USES_TERMINAL_DOWNLOAD ) - if(uses_terminal) + # The --trust-server-cert option requires --non-interactive + if(uses_terminal AND NOT svn_trust_cert) set(svn_interactive_args "") else() set(svn_interactive_args "--non-interactive") @@ -3046,14 +3106,16 @@ hash=${hash} get_filename_component(fname "${fname}" NAME) else() # Fall back to a default file name. The actual file name does not - # matter because it is used only internally and our extraction tool - # inspects the file content directly. If it turns out the wrong URL - # was given that will be revealed during the build which is an easier - # place for users to diagnose than an error here anyway. - set(fname "archive.tar") + # matter as long as it doesn't conflict with other projects because + # it is used only internally and our extraction tool inspects the + # file content directly. If it turns out the wrong URL was given + # that will be revealed during the build which is an easier place for + # users to diagnose than an error here anyway. + set(fname "${name}-archive.tar") endif() string(REPLACE ";" "-" fname "${fname}") set(file ${download_dir}/${fname}) + set(byproduct_file "${download_dir}/${fname}") get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT) get_property(inactivity_timeout TARGET ${name} @@ -3230,6 +3292,7 @@ hash=${hash} COMMAND ${__cmdQuoted} WORKING_DIRECTORY \${work_dir} DEPENDS \${depends} + BYPRODUCTS \${byproduct_file} DEPENDEES mkdir ${log} ${uses_terminal} @@ -3299,7 +3362,8 @@ function(_ep_add_update_command name) get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD) get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT) get_property(uses_terminal TARGET ${name} PROPERTY _EP_USES_TERMINAL_UPDATE) - if(uses_terminal) + # The --trust-server-cert option requires --non-interactive + if(uses_terminal AND NOT svn_trust_cert) set(svn_interactive_args "") else() set(svn_interactive_args "--non-interactive") @@ -3914,6 +3978,17 @@ function(_ep_add_build_command name) PROPERTY _EP_BUILD_BYPRODUCTS ) + get_property(build_job_server_aware + TARGET ${name} + PROPERTY _EP_BUILD_JOB_SERVER_AWARE + ) + if(build_job_server_aware) + set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1") + else() + set(maybe_JOB_SERVER_AWARE "") + endif() + + set(__cmdQuoted) foreach(__item IN LISTS cmd) string(APPEND __cmdQuoted " [==[${__item}]==]") @@ -3927,6 +4002,7 @@ function(_ep_add_build_command name) DEPENDEES configure DEPENDS \${file_deps} ALWAYS \${always} + ${maybe_JOB_SERVER_AWARE} ${log} ${uses_terminal} )" @@ -4221,6 +4297,7 @@ function(ExternalProject_Add name) BUILD_IN_SOURCE BUILD_ALWAYS BUILD_BYPRODUCTS + BUILD_JOB_SERVER_AWARE # # Install step options # diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 4ff43ed..f10684c 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -111,6 +111,7 @@ Commands FetchContent_Declare( <name> <contentOptions>... + [EXCLUDE_FROM_ALL] [SYSTEM] [OVERRIDE_FIND_PACKAGE | FIND_PACKAGE_ARGS args...] @@ -240,6 +241,15 @@ Commands See the :prop_tgt:`SYSTEM` target property documentation for a more detailed discussion of the effects. + .. versionadded:: 3.28 + + ``EXCLUDE_FROM_ALL`` + If the ``EXCLUDE_FROM_ALL`` argument is provided, then targets in the + subdirectory added by :command:`FetchContent_MakeAvailable` will not be + included in the ``ALL`` target by default, and may be excluded from IDE + project files. See the `:command:`add_subdirectory` `EXCLUDE_FROM_ALL`` + argument documentation for a more detailed discussion of the effects. + .. command:: FetchContent_MakeAvailable .. versionadded:: 3.14 @@ -358,6 +368,11 @@ Commands :command:`FetchContent_Declare`, the ``SYSTEM`` keyword will be added to the :command:`add_subdirectory` command as well. + .. versionadded:: 3.28 + If the ``EXCLUDE_FROM_ALL`` keyword was included in the call to + :command:`FetchContent_Declare`, the ``EXCLUDE_FROM_ALL`` keyword will + be added to the :command:`add_subdirectory` command as well. + Projects should aim to declare the details of all dependencies they might use before they call ``FetchContent_MakeAvailable()`` for any of them. This ensures that if any of the dependencies are also sub-dependencies of @@ -1466,8 +1481,10 @@ function(__FetchContent_directPopulate contentName) set(options QUIET - # SYSTEM has no meaning for ExternalProject, it is only used by us in - # FetchContent_MakeAvailable(). We need to parse and discard it here. + # EXCLUDE_FROM_ALL and SYSTEM have no meaning for ExternalProject, they + # are only used by us in FetchContent_MakeAvailable(). We need to parse + # and discard them here. + EXCLUDE_FROM_ALL SYSTEM ) set(oneValueArgs @@ -2030,22 +2047,28 @@ macro(FetchContent_MakeAvailable) if("${__cmake_contentDetails}" STREQUAL "") message(FATAL_ERROR "No details have been set for content: ${__cmake_contentName}") endif() - cmake_parse_arguments(__cmake_arg "SYSTEM" "SOURCE_SUBDIR" "" ${__cmake_contentDetails}) + cmake_parse_arguments(__cmake_arg "EXCLUDE_FROM_ALL;SYSTEM" "SOURCE_SUBDIR" "" ${__cmake_contentDetails}) if(NOT "${__cmake_arg_SOURCE_SUBDIR}" STREQUAL "") string(APPEND __cmake_srcdir "/${__cmake_arg_SOURCE_SUBDIR}") endif() if(EXISTS ${__cmake_srcdir}/CMakeLists.txt) - if (__cmake_arg_SYSTEM) - add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR} SYSTEM) - else() - add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR}) + set(__cmake_add_subdirectory_args ${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR}) + if(__cmake_arg_EXCLUDE_FROM_ALL) + list(APPEND __cmake_add_subdirectory_args EXCLUDE_FROM_ALL) + endif() + if(__cmake_arg_SYSTEM) + list(APPEND __cmake_add_subdirectory_args SYSTEM) endif() + add_subdirectory(${__cmake_add_subdirectory_args}) endif() unset(__cmake_srcdir) unset(__cmake_contentDetails) + unset(__cmake_arg_EXCLUDE_FROM_ALL) + unset(__cmake_arg_SYSTEM) unset(__cmake_arg_SOURCE_SUBDIR) + unset(__cmake_add_subdirectory_args) endif() endforeach() diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 0d7f1a4..203a473 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -1423,7 +1423,7 @@ function(CUDA_COMPUTE_BUILD_PATH path build_path) # Only deal with CMake style paths from here on out file(TO_CMAKE_PATH "${path}" bpath) if (IS_ABSOLUTE "${bpath}") - # Absolute paths are generally unnessary, especially if something like + # Absolute paths are generally unnecessary, especially if something like # file(GLOB_RECURSE) is used to pick up the files. string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos) diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index c2627e7..0a22e63 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -514,7 +514,7 @@ Result variables executable ``nvcc``. ``CUDAToolkit_INCLUDE_DIRS`` - The path to the CUDA Toolkit ``include`` folder containing the header files + List of paths to all the CUDA Toolkit folders containing header files required to compile a project linking against CUDA. ``CUDAToolkit_LIBRARY_DIR`` @@ -579,13 +579,28 @@ Result variables # ############################################################################### +function(_CUDAToolkit_build_include_dirs result_variable default_paths_variable) + set(content "${${default_paths_variable}}") + set(${result_variable} "${content}" PARENT_SCOPE) +endfunction() + +function(_CUDAToolkit_build_library_dirs result_variable default_paths_variable) + set(content "${${default_paths_variable}}") + set(${result_variable} "${content}" PARENT_SCOPE) +endfunction() + # The toolkit is located during compiler detection for CUDA and stored in CMakeCUDACompiler.cmake as -# CMAKE_CUDA_COMPILER_TOOLKIT_ROOT and CMAKE_CUDA_COMPILER_LIBRARY_ROOT. +# - CMAKE_CUDA_COMPILER_TOOLKIT_ROOT +# - CMAKE_CUDA_COMPILER_LIBRARY_ROOT +# - CMAKE_CUDA_COMPILER_LIBRARY_DIRECTORIES_FROM_IMPLICIT_LIBRARIES +# - CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES # We compute the rest based on those here to avoid re-searching and to avoid finding a possibly # different installation. if(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT) set(CUDAToolkit_ROOT_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}") set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_LIBRARY_ROOT}") + _CUDAToolkit_build_library_dirs(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES) + _CUDAToolkit_build_include_dirs(CUDAToolkit_INCLUDE_DIRECTORIES CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES) set(CUDAToolkit_BIN_DIR "${CUDAToolkit_ROOT_DIR}/bin") set(CUDAToolkit_NVCC_EXECUTABLE "${CUDAToolkit_BIN_DIR}/nvcc${CMAKE_EXECUTABLE_SUFFIX}") set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_TOOLKIT_VERSION}") @@ -622,11 +637,45 @@ else() # NVIDIA HPC SDK, and distro's splayed layouts execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) + message(CONFIGURE_LOG + "Executed nvcc to extract CUDAToolkit information:\n${_CUDA_NVCC_OUT}\n\n") if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)") get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE) + message(CONFIGURE_LOG + "Parsed CUDAToolkit nvcc location:\n${CUDAToolkit_BIN_DIR}\n\n") else() get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) endif() + if(_CUDA_NVCC_OUT MATCHES "\\#\\$ INCLUDES=([^\r\n]*)") + separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}") + foreach(line IN LISTS _nvcc_output) + string(REGEX REPLACE "^-I" "" line "${line}") + get_filename_component(line "${line}" ABSOLUTE) + list(APPEND _cmake_CUDAToolkit_include_directories "${line}") + endforeach() + message(CONFIGURE_LOG + "Parsed CUDAToolkit nvcc implicit include information:\n${_cmake_CUDAToolkit_include_directories}\n\n") + + set(_cmake_CUDAToolkit_include_directories "${_cmake_CUDAToolkit_include_directories}" CACHE INTERNAL "CUDAToolkit internal list of include directories") + endif() + if(_CUDA_NVCC_OUT MATCHES "\\#\\$ LIBRARIES=([^\r\n]*)") + include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) + set(_nvcc_link_line "cuda-fake-ld ${CMAKE_MATCH_1}") + CMAKE_PARSE_IMPLICIT_LINK_INFO("${_nvcc_link_line}" + _cmake_CUDAToolkit_implicit_link_libs + _cmake_CUDAToolkit_implicit_link_directories + _cmake_CUDAToolkit_implicit_frameworks + _nvcc_log + "${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}" + LANGUAGE CUDA) + message(CONFIGURE_LOG + "Parsed CUDAToolkit nvcc implicit link information:\n${_nvcc_log}\n${_cmake_CUDAToolkit_implicit_link_directories}\n\n") + unset(_nvcc_link_line) + unset(_cmake_CUDAToolkit_implicit_link_libs) + unset(_cmake_CUDAToolkit_implicit_frameworks) + + set(_cmake_CUDAToolkit_implicit_link_directories "${_cmake_CUDAToolkit_implicit_link_directories}" CACHE INTERNAL "CUDAToolkit internal list of implicit link directories") + endif() unset(_CUDA_NVCC_OUT) set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) @@ -642,6 +691,15 @@ else() endif() endif() + if(DEFINED _cmake_CUDAToolkit_include_directories) + _CUDAToolkit_build_include_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_include_directories) + set(CUDAToolkit_INCLUDE_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE) + endif() + if(DEFINED _cmake_CUDAToolkit_implicit_link_directories) + _CUDAToolkit_build_library_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_implicit_link_directories) + set(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE) + 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) @@ -885,18 +943,27 @@ if(NOT CUDAToolkit_TARGET_DIR) set(_CUDAToolkit_Pop_Prefix True) endif() -# CUDAToolkit_TARGET_DIR always points to the directory containing the include directory. -# On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux. -if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h") - set(CUDAToolkit_INCLUDE_DIR "${CUDAToolkit_TARGET_DIR}/include") -elseif(NOT CUDAToolkit_FIND_QUIETLY) - message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIR.") + +# We don't need to verify the cuda_runtime header when we are using `nvcc` include paths +# as the compiler being enabled means the header was found +if(NOT CUDAToolkit_INCLUDE_DIRECTORIES) + # Otherwise use CUDAToolkit_TARGET_DIR to guess where the `cuda_runtime.h` is located + # On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux. + if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h") + set(CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_TARGET_DIR}/include") + else() + message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIRECTORIES.") + endif() endif() # The NVHPC layout moves math library headers and libraries to a sibling directory and it could be nested under # the version of the CUDA toolchain # Create a separate variable so this directory can be selectively added to math targets. -if(NOT EXISTS "${CUDAToolkit_INCLUDE_DIR}/cublas_v2.h") +find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS + "${CUDAToolkit_INCLUDE_DIRECTORIES}" + NO_DEFAULT_PATH) + +if(NOT CUDAToolkit_CUBLAS_INCLUDE_DIR) file(REAL_PATH "${CUDAToolkit_TARGET_DIR}" CUDAToolkit_MATH_INCLUDE_DIR) cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "../../math_libs/") if(EXISTS "${CUDAToolkit_MATH_INCLUDE_DIR}/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/") @@ -905,22 +972,26 @@ if(NOT EXISTS "${CUDAToolkit_INCLUDE_DIR}/cublas_v2.h") cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "include") cmake_path(NORMAL_PATH CUDAToolkit_MATH_INCLUDE_DIR) - if(NOT EXISTS "${CUDAToolkit_MATH_INCLUDE_DIR}/cublas_v2.h") - if(NOT CUDAToolkit_FIND_QUIETLY) - message(STATUS "Unable to find cublas_v2.h in either \"${CUDAToolkit_INCLUDE_DIR}\" or \"${CUDAToolkit_MATH_INCLUDE_DIR}\"") - endif() - unset(CUDAToolkit_MATH_INCLUDE_DIR) + find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS + "${CUDAToolkit_INCLUDE_DIRECTORIES}" + ) + if(CUDAToolkit_CUBLAS_INCLUDE_DIR) + list(APPEND CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_CUBLAS_INCLUDE_DIR}") endif() endif() +unset(CUDAToolkit_CUBLAS_INCLUDE_DIR CACHE) +unset(CUDAToolkit_CUBLAS_INCLUDE_DIR) # Find the CUDA Runtime Library libcudart find_library(CUDA_CUDART NAMES cudart + PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES} PATH_SUFFIXES lib64 lib/x64 ) find_library(CUDA_CUDART NAMES cudart - PATH_SUFFIXES lib64/stubs lib/x64/stubs + PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES} + PATH_SUFFIXES lib64/stubs lib/x64/stubs lib/stubs stubs ) if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY) @@ -937,7 +1008,7 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(CUDAToolkit REQUIRED_VARS - CUDAToolkit_INCLUDE_DIR + CUDAToolkit_INCLUDE_DIRECTORIES CUDA_CUDART CUDAToolkit_BIN_DIR VERSION_VAR @@ -946,7 +1017,6 @@ find_package_handle_standard_args(CUDAToolkit unset(CUDAToolkit_ROOT_DIR) mark_as_advanced(CUDA_CUDART - CUDAToolkit_INCLUDE_DIR CUDAToolkit_NVCC_EXECUTABLE CUDAToolkit_SENTINEL_FILE ) @@ -954,7 +1024,7 @@ mark_as_advanced(CUDA_CUDART #----------------------------------------------------------------------------- # Construct result variables if(CUDAToolkit_FOUND) - set(CUDAToolkit_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIR}) + set(CUDAToolkit_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRECTORIES}") get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE) # Build search paths without any symlinks @@ -965,12 +1035,19 @@ if(CUDAToolkit_FOUND) # search paths without symlinks if(CUDAToolkit_LIBRARY_DIR MATCHES ".*/cuda/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64$") # Search location for math_libs/ - file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../" _cmake_search_dir) - list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}") + block(SCOPE_FOR POLICIES) + cmake_policy(SET CMP0152 NEW) + file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../../../" _cmake_search_dir) + list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}") + + # Search location for extras like cupti + file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../" _cmake_search_dir) + list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}") + endblock() + endif() - # Search location for extras like cupti - file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../" _cmake_search_dir) - list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}") + if(DEFINED CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES) + list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}") endif() # If no `CUDAToolkit_LIBRARY_ROOT` exists set it based on CUDAToolkit_LIBRARY_DIR @@ -986,7 +1063,8 @@ if(CUDAToolkit_FOUND) unset(CUDAToolkit_possible_lib_root) endif() endif() - +unset(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES) +unset(CUDAToolkit_INCLUDE_DIRECTORIES) #----------------------------------------------------------------------------- # Construct import targets @@ -1009,17 +1087,26 @@ if(CUDAToolkit_FOUND) ) # Don't try any stub directories until we have exhausted all other # search locations. - find_library(CUDA_${lib_name}_LIBRARY - NAMES ${search_names} - HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS} - ENV CUDA_PATH - PATH_SUFFIXES lib64/stubs lib/x64/stubs lib/stubs stubs - ) + set(CUDA_IMPORT_PROPERTY IMPORTED_LOCATION) + set(CUDA_IMPORT_TYPE UNKNOWN) + if(NOT CUDA_${lib_name}_LIBRARY) + find_library(CUDA_${lib_name}_LIBRARY + NAMES ${search_names} + HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS} + ENV CUDA_PATH + PATH_SUFFIXES lib64/stubs lib/x64/stubs lib/stubs stubs + ) + if(CUDA_${lib_name}_LIBRARY AND NOT WIN32) + # Use `IMPORTED_IMPLIB` so that we don't add a `-rpath` entry for stub directories + set(CUDA_IMPORT_PROPERTY IMPORTED_IMPLIB) + set(CUDA_IMPORT_TYPE SHARED) + endif() + endif() mark_as_advanced(CUDA_${lib_name}_LIBRARY) if (NOT TARGET CUDA::${lib_name} AND CUDA_${lib_name}_LIBRARY) - add_library(CUDA::${lib_name} UNKNOWN IMPORTED) + add_library(CUDA::${lib_name} ${CUDA_IMPORT_TYPE} IMPORTED) target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}") if(DEFINED CUDAToolkit_MATH_INCLUDE_DIR) string(FIND ${CUDA_${lib_name}_LIBRARY} "math_libs" math_libs) @@ -1027,7 +1114,7 @@ if(CUDAToolkit_FOUND) target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_MATH_INCLUDE_DIR}") endif() endif() - set_property(TARGET CUDA::${lib_name} PROPERTY IMPORTED_LOCATION "${CUDA_${lib_name}_LIBRARY}") + set_property(TARGET CUDA::${lib_name} PROPERTY ${CUDA_IMPORT_PROPERTY} "${CUDA_${lib_name}_LIBRARY}") foreach(dep ${arg_DEPS}) if(TARGET CUDA::${dep}) target_link_libraries(CUDA::${lib_name} INTERFACE CUDA::${dep}) @@ -1105,11 +1192,11 @@ if(CUDAToolkit_FOUND) endif() if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.4) - _CUDAToolkit_find_and_add_import_lib(cuFile DEPS culibos) - _CUDAToolkit_find_and_add_import_lib(cuFile_static DEPS culibos) + _CUDAToolkit_find_and_add_import_lib(cuFile ALT cufile DEPS culibos) + _CUDAToolkit_find_and_add_import_lib(cuFile_static ALT cufile_static DEPS culibos) - _CUDAToolkit_find_and_add_import_lib(cuFile_rdma DEPS cuFile culibos) - _CUDAToolkit_find_and_add_import_lib(cuFile_rdma_static DEPS cuFile_static culibos) + _CUDAToolkit_find_and_add_import_lib(cuFile_rdma ALT cufile_rdma DEPS cuFile culibos) + _CUDAToolkit_find_and_add_import_lib(cuFile_rdma_static ALT cufile_rdma_static DEPS cuFile_static culibos) endif() if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.6) diff --git a/Modules/FindCURL.cmake b/Modules/FindCURL.cmake index acb87dc..2f33dac 100644 --- a/Modules/FindCURL.cmake +++ b/Modules/FindCURL.cmake @@ -58,6 +58,18 @@ returns its results with no further action. Set ``CURL_NO_CURL_CMAKE`` to ``ON`` to disable this search. +Hints +^^^^^ + +``CURL_USE_STATIC_LIBS`` + + .. versionadded:: 3.28 + + Set to ``TRUE`` to use static libraries. + + This is meaningful only when CURL is not found via its + CMake Package Configuration file. + #]=======================================================================] include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) @@ -193,6 +205,11 @@ if(CURL_FOUND) set_target_properties(CURL::libcurl PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}") + if(CURL_USE_STATIC_LIBS) + set_property(TARGET CURL::libcurl APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB") + endif() + if(EXISTS "${CURL_LIBRARY}") set_target_properties(CURL::libcurl PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" @@ -212,5 +229,11 @@ if(CURL_FOUND) IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}") endif() + + if(CURL_USE_STATIC_LIBS AND MSVC) + set_target_properties(CURL::libcurl PROPERTIES + INTERFACE_LINK_LIBRARIES "normaliz.lib;ws2_32.lib;wldap32.lib") + endif() + endif() endif() diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake index 76f4759..9903e37 100644 --- a/Modules/FindDoxygen.cmake +++ b/Modules/FindDoxygen.cmake @@ -463,10 +463,6 @@ function(_Doxygen_version_validator version_match doxy_path) else() _Doxygen_get_version(candidate_version version_result "${doxy_path}") - if(version_result) - message(DEBUG "Unable to determine candidate doxygen version at ${doxy_path}: ${version_result}") - endif() - find_package_check_version("${candidate_version}" valid_doxy_version HANDLE_VERSION_RANGE ) @@ -494,15 +490,18 @@ macro(_Doxygen_find_doxygen) _Doxygen_get_version(DOXYGEN_VERSION _Doxygen_version_result "${DOXYGEN_EXECUTABLE}") if(_Doxygen_version_result) - message(WARNING "Unable to determine doxygen version: ${_Doxygen_version_result}") - endif() - - # Create an imported target for Doxygen - if(NOT TARGET Doxygen::doxygen) - add_executable(Doxygen::doxygen IMPORTED GLOBAL) - set_target_properties(Doxygen::doxygen PROPERTIES - IMPORTED_LOCATION "${DOXYGEN_EXECUTABLE}" - ) + if(NOT Doxygen_FIND_QUIETLY) + message(WARNING "Doxygen executable failed unexpected while determining version (exit status: ${_Doxygen_version_result}). Disabling Doxygen.") + endif() + set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}-FAILED_EXECUTION-NOTFOUND") + else() + # Create an imported target for Doxygen + if(NOT TARGET Doxygen::doxygen) + add_executable(Doxygen::doxygen IMPORTED GLOBAL) + set_target_properties(Doxygen::doxygen PROPERTIES + IMPORTED_LOCATION "${DOXYGEN_EXECUTABLE}" + ) + endif() endif() endif() endmacro() diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake index 3bedc73..762931e 100644 --- a/Modules/FindEXPAT.cmake +++ b/Modules/FindEXPAT.cmake @@ -30,6 +30,15 @@ This module will set the following variables in your project: ``EXPAT_FOUND`` true if the Expat headers and libraries were found. +Hints +^^^^^ + +``EXPAT_USE_STATIC_LIBS`` + + .. versionadded:: 3.28 + + Set to ``TRUE`` to use static libraries. + #]=======================================================================] find_package(PkgConfig QUIET) @@ -43,8 +52,13 @@ set(EXPAT_NAMES expat expatw) set(EXPAT_NAMES_DEBUG expatd expatwd) if(WIN32) - list(APPEND EXPAT_NAMES expatMT expatMD expatwMT expatwMD) - list(APPEND EXPAT_NAMES_DEBUG expatdMT expatdMD expatwdMT expatwdMD) + if(EXPAT_USE_STATIC_LIBS) + list(APPEND EXPAT_NAMES expatMT expatwMT) + list(APPEND EXPAT_NAMES_DEBUG expatdMT expatwdMT) + else() + list(APPEND EXPAT_NAMES expatMT expatMD expatwMT expatwMD) + list(APPEND EXPAT_NAMES_DEBUG expatdMT expatdMD expatwdMT expatwdMD) + endif() endif() # Allow EXPAT_LIBRARY to be set manually, as the location of the expat library @@ -115,6 +129,11 @@ if(EXPAT_FOUND) IMPORTED_LINK_INTERFACE_LANGUAGES "C" INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}") + if(EXPAT_USE_STATIC_LIBS) + set_property(TARGET EXPAT::EXPAT APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS "XML_STATIC") + endif() + if(EXPAT_LIBRARY_RELEASE) set_property(TARGET EXPAT::EXPAT APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) diff --git a/Modules/FindEnvModules.cmake b/Modules/FindEnvModules.cmake index dab97ac..5337e4f 100644 --- a/Modules/FindEnvModules.cmake +++ b/Modules/FindEnvModules.cmake @@ -81,7 +81,7 @@ modules: .. command:: env_module - Execute an aribitrary module command: + Execute an arbitrary module command: .. code-block:: cmake diff --git a/Modules/FindFLTK.cmake b/Modules/FindFLTK.cmake index d54d2f6..a245c6c 100644 --- a/Modules/FindFLTK.cmake +++ b/Modules/FindFLTK.cmake @@ -232,7 +232,7 @@ else() find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR}) if(FLTK_CONFIG_SCRIPT) if(NOT FLTK_INCLUDE_DIR) - exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS) + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS) if(FLTK_CXXFLAGS) string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS}) string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}") @@ -256,7 +256,7 @@ else() # Try to find FLTK library if(UNIX) if(FLTK_CONFIG_SCRIPT) - exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS) + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS) if(_FLTK_POSSIBLE_LIBS) get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH) endif() @@ -292,12 +292,12 @@ else() # Find the extra libraries needed for the fltk_images library. if(UNIX) if(FLTK_CONFIG_SCRIPT) - exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --use-images --ldflags OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS) set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*") if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}") string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${CMAKE_MATCH_1}") - # The EXEC_PROGRAM will not be inherited into subdirectories from + # The execute_process() will not be inherited into subdirectories from # the file that originally included this module. Save the answer. set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL "Extra libraries for fltk_images library.") diff --git a/Modules/FindFLTK2.cmake b/Modules/FindFLTK2.cmake index a43f7a4..2f6e41d 100644 --- a/Modules/FindFLTK2.cmake +++ b/Modules/FindFLTK2.cmake @@ -191,12 +191,12 @@ if(FLTK2_DIR) if(UNIX) find_program(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR}) if(FLTK2_CONFIG_SCRIPT) - exec_program(${FLTK2_CONFIG_SCRIPT} ARGS --use-images --ldflags + execute_process(COMMAND ${FLTK2_CONFIG_SCRIPT} --use-images --ldflags OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS) set(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*") if("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}") string(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${CMAKE_MATCH_1}") - # The EXEC_PROGRAM will not be inherited into subdirectories from + # The execute_process() will not be inherited into subdirectories from # the file that originally included this module. Save the answer. set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL "Extra libraries for fltk_images library.") diff --git a/Modules/FindFreetype.cmake b/Modules/FindFreetype.cmake index 82885cb..583d056 100644 --- a/Modules/FindFreetype.cmake +++ b/Modules/FindFreetype.cmake @@ -65,6 +65,94 @@ directory of a Freetype installation. # I'm going to attempt to cut out the middleman and hope # everything still works. +set(_Freetype_args) +if (Freetype_FIND_QUIETLY) + list(APPEND _Freetype_args + QUIET) +endif () +if (Freetype_FIND_VERSION) + list(APPEND _Freetype_args + "${Freetype_FIND_VERSION}") + if (Freetype_FIND_VERSION_EXACT) + list(APPEND _Freetype_args + EXACT) + endif () +endif () +set(_Freetype_component_req) +set(_Freetype_component_opt) +foreach (_Freetype_component IN LISTS Freetype_FIND_COMPONENTS) + if (Freetype_FIND_REQUIRE_${_Freetype_component}) + list(APPEND _Freetype_component_req + "${_Freetype_component}") + else () + list(APPEND _Freetype_component_opt + "${_Freetype_component}") + endif () +endforeach () +unset(_Freetype_component) +if (_Freetype_component_req) + list(APPEND _Freetype_args + COMPONENTS "${_Freetype_component_req}") +endif () +unset(_Freetype_component_req) +if (_Freetype_component_opt) + list(APPEND _Freetype_args + OPTIONAL_COMPONENTS "${_Freetype_component_opt}") +endif () +unset(_Freetype_component_opt) +find_package(freetype CONFIG ${_Freetype_args}) +unset(_Freetype_args) +if (freetype_FOUND) + if (NOT TARGET Freetype::Freetype) + add_library(Freetype::Freetype IMPORTED INTERFACE) + set_target_properties(Freetype::Freetype PROPERTIES + INTERFACE_LINK_LIBRARIES freetype) + endif () + get_property(FREETYPE_INCLUDE_DIRS TARGET freetype PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + get_property(FREETYPE_LIBRARIES TARGET freetype PROPERTY INTERFACE_LINK_LIBRARIES) + get_property(_Freetype_location TARGET freetype PROPERTY IMPORTED_IMPLIB) + if (NOT _Freetype_location) + get_property(_Freetype_location_release TARGET freetype PROPERTY IMPORTED_IMPLIB_RELEASE) + get_property(_Freetype_location_debug TARGET freetype PROPERTY IMPORTED_IMPLIB_DEBUG) + if (_Freetype_location_release AND _Freetype_location_debug) + set(_Freetype_location + optimized "${_Freetype_location_release}" + debug "${_Freetype_location_debug}") + elseif (_Freetype_location_release) + set(_Freetype_location "${_Freetype_location_release}") + elseif (_Freetype_location_debug) + set(_Freetype_location "${_Freetype_location_debug}") + else () + get_property(_Freetype_location_release TARGET freetype PROPERTY LOCATION_RELEASE) + get_property(_Freetype_location_debug TARGET freetype PROPERTY LOCATION_DEBUG) + if (_Freetype_location_release AND _Freetype_location_debug) + set(_Freetype_location + optimized "${_Freetype_location_release}" + debug "${_Freetype_location_debug}") + elseif (_Freetype_location_release) + set(_Freetype_location "${_Freetype_location_release}") + elseif (_Freetype_location_debug) + set(_Freetype_location "${_Freetype_location_debug}") + else () + get_property(_Freetype_location TARGET freetype PROPERTY LOCATION) + endif () + endif () + unset(_Freetype_location_release) + unset(_Freetype_location_debug) + endif () + list(INSERT FREETYPE_LIBRARIES 0 + "${_Freetype_location}") + unset(_Freetype_location) + set(Freetype_FOUND 1) + set(FREETYPE_FOUND 1) + set(FREETYPE_VERSION_STRING "${freetype_VERSION}") + foreach (_Freetype_component IN LISTS Freetype_FIND_COMPONENTS) + set(Freetype_${_Freetype_component}_FOUND "${freetype_${_Freetype_component}_FOUND}") + endforeach () + unset(_Freetype_component) + return () +endif () + set(FREETYPE_FIND_ARGS HINTS ENV FREETYPE_DIR diff --git a/Modules/FindGLEW.cmake b/Modules/FindGLEW.cmake index bfde40b..dff53e1 100644 --- a/Modules/FindGLEW.cmake +++ b/Modules/FindGLEW.cmake @@ -126,6 +126,10 @@ function(__glew_set_find_library_suffix shared_or_static) set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib;.so" PARENT_SCOPE) elseif(APPLE AND "${shared_or_static}" MATCHES "STATIC") set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE) + elseif(WIN32 AND MINGW AND "${shared_or_static}" MATCHES "SHARED") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" PARENT_SCOPE) + elseif(WIN32 AND MINGW AND "${shared_or_static}" MATCHES "STATIC") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE) elseif(WIN32 AND "${shared_or_static}" MATCHES "SHARED") set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" PARENT_SCOPE) elseif(WIN32 AND "${shared_or_static}" MATCHES "STATIC") diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index 09403bc..613d315 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -107,18 +107,8 @@ elseif(APPLE) if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) add_library(GLUT::Cocoa UNKNOWN IMPORTED) - # Cocoa should always be a Framework, but we check to make sure. - if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$") - set(_glut_cocoa "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}") - if(EXISTS "${_glut_cocoa}.tbd") - string(APPEND _glut_cocoa ".tbd") - endif() - set_target_properties(GLUT::Cocoa PROPERTIES - IMPORTED_LOCATION "${_glut_cocoa}") - else() - set_target_properties(GLUT::Cocoa PROPERTIES - IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") - endif() + set_target_properties(GLUT::Cocoa PROPERTIES + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") endif() else() if(BEOS) @@ -196,32 +186,23 @@ if (GLUT_FOUND) add_library(GLUT::GLUT UNKNOWN IMPORTED) set_target_properties(GLUT::GLUT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIRS}") - if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$") - set(_glut_glut "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") - if(EXISTS "${_glut_glut}.tbd") - string(APPEND _glut_glut ".tbd") - endif() + if(GLUT_glut_LIBRARY_RELEASE) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}") + endif() + + if(GLUT_glut_LIBRARY_DEBUG) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION "${_glut_glut}") - else() - if(GLUT_glut_LIBRARY_RELEASE) - set_property(TARGET GLUT::GLUT APPEND PROPERTY - IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}") - endif() - - if(GLUT_glut_LIBRARY_DEBUG) - set_property(TARGET GLUT::GLUT APPEND PROPERTY - IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(GLUT::GLUT PROPERTIES - IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}") - endif() - - if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG) - set_property(TARGET GLUT::GLUT APPEND PROPERTY - IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") - endif() + IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}") + endif() + + if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG) + set_property(TARGET GLUT::GLUT APPEND PROPERTY + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") endif() if(TARGET GLUT::Xmu) diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake index e7050a3..abc76cf 100644 --- a/Modules/FindJNI.cmake +++ b/Modules/FindJNI.cmake @@ -136,76 +136,76 @@ endif() # Expand {libarch} occurrences to java_libarch subdirectory(-ies) and set ${_var} macro(java_append_library_directories _var) - # Determine java arch-specific library subdir - # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk - # 1.6.0_18 + icedtea patches. However, it would be much better to base the - # guess on the first part of the GNU config.guess platform triplet. - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") - if(CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnux32") - set(_java_libarch "x32" "amd64" "i386") - else() - set(_java_libarch "amd64" "i386") - endif() - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") - set(_java_libarch "i386") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") - set(_java_libarch "arm64" "aarch64") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha") - set(_java_libarch "alpha") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") - # Subdir is "arm" for both big-endian (arm) and little-endian (armel). - set(_java_libarch "arm" "aarch32") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") - # mips* machines are bi-endian mostly so processor does not tell - # endianness of the underlying system. - set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" - "mips" "mipsel" "mipseb" "mipsr6" "mipsr6el" - "mips64" "mips64el" "mips64r6" "mips64r6el" - "mipsn32" "mipsn32el" "mipsn32r6" "mipsn32r6el") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le") - set(_java_libarch "ppc64" "ppc64le") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64") - set(_java_libarch "ppc64" "ppc") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") - set(_java_libarch "ppc" "ppc64") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc") - # Both flavors can run on the same processor - set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)") - set(_java_libarch "parisc" "parisc64") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390") - # s390 binaries can run on s390x machines - set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh") - set(_java_libarch "sh") + # Determine java arch-specific library subdir + # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk + # 1.6.0_18 + icedtea patches. However, it would be much better to base the + # guess on the first part of the GNU config.guess platform triplet. + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + if(CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnux32") + set(_java_libarch "x32" "amd64" "i386") else() - set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}") + set(_java_libarch "amd64" "i386") endif() + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") + set(_java_libarch "i386") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + set(_java_libarch "arm64" "aarch64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha") + set(_java_libarch "alpha") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + # Subdir is "arm" for both big-endian (arm) and little-endian (armel). + set(_java_libarch "arm" "aarch32") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + # mips* machines are bi-endian mostly so processor does not tell + # endianness of the underlying system. + set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" + "mips" "mipsel" "mipseb" "mipsr6" "mipsr6el" + "mips64" "mips64el" "mips64r6" "mips64r6el" + "mipsn32" "mipsn32el" "mipsn32r6" "mipsn32r6el") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le") + set(_java_libarch "ppc64" "ppc64le") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64") + set(_java_libarch "ppc64" "ppc") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + set(_java_libarch "ppc" "ppc64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc") + # Both flavors can run on the same processor + set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)") + set(_java_libarch "parisc" "parisc64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390") + # s390 binaries can run on s390x machines + set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh") + set(_java_libarch "sh") + else() + set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}") + endif() - # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or - # system is non-Linux (where the code above has not been well tested) - if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux")) - list(APPEND _java_libarch "i386" "amd64" "ppc") - endif() + # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or + # system is non-Linux (where the code above has not been well tested) + if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux")) + list(APPEND _java_libarch "i386" "amd64" "ppc") + endif() - # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer - # current value to a hardcoded list. Remove possible duplicates. - list(REMOVE_DUPLICATES _java_libarch) - - foreach(_path ${ARGN}) - if(_path MATCHES "{libarch}") - foreach(_libarch ${_java_libarch}) - string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}") - if(EXISTS ${_newpath}) - list(APPEND ${_var} "${_newpath}") - endif() - endforeach() - else() - if(EXISTS ${_path}) - list(APPEND ${_var} "${_path}") - endif() + # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer + # current value to a hardcoded list. Remove possible duplicates. + list(REMOVE_DUPLICATES _java_libarch) + + foreach(_path ${ARGN}) + if(_path MATCHES "{libarch}") + foreach(_libarch IN LISTS _java_libarch) + string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}") + if(EXISTS ${_newpath}) + list(APPEND ${_var} "${_newpath}") endif() - endforeach() + endforeach() + else() + if(EXISTS ${_path}) + list(APPEND ${_var} "${_path}") + endif() + endif() + endforeach() endmacro() include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake) @@ -235,13 +235,12 @@ endif() if (WIN32) set (_JNI_HINTS) macro (_JNI_GET_INSTALLED_VERSIONS _KIND) - execute_process(COMMAND REG QUERY "HKLM\\SOFTWARE\\JavaSoft\\${_KIND}" - RESULT_VARIABLE _JAVA_RESULT - OUTPUT_VARIABLE _JAVA_VERSIONS - ERROR_QUIET) - if (NOT _JAVA_RESULT) - string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9._]+" _JNI_VERSIONS "${_JAVA_VERSIONS}") - string (REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\([0-9._]+)" "\\1" _JNI_VERSIONS "${_JNI_VERSIONS}") + cmake_host_system_information(RESULT _JNI_VERSIONS + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/JavaSoft/${_KIND}" + SUBKEYS) + if (_JNI_VERSIONS) + string (REGEX MATCHALL "[0-9._]+" _JNI_VERSIONS "${_JNI_VERSIONS}") + string (REGEX REPLACE "([0-9._]+)" "\\1" _JNI_VERSIONS "${_JNI_VERSIONS}") if (_JNI_VERSIONS) # sort versions. Most recent first list (SORT _JNI_VERSIONS COMPARE NATURAL ORDER DESCENDING) @@ -340,7 +339,7 @@ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES ) set(JAVA_JVM_LIBRARY_DIRECTORIES) -foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES}) +foreach(dir IN LISTS JAVA_AWT_LIBRARY_DIRECTORIES) list(APPEND JAVA_JVM_LIBRARY_DIRECTORIES "${dir}" "${dir}/client" @@ -365,14 +364,14 @@ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_INCLUDE_DIRECTORIES ${_JNI_JAVA_INCLUDE_TRIES} ) -foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}") +foreach(JAVA_PROG IN ITEMS "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}") get_filename_component(jpath "${JAVA_PROG}" PATH) - foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include) + foreach(JAVA_INC_PATH IN ITEMS ../include ../java/include ../share/java/include) if(EXISTS ${jpath}/${JAVA_INC_PATH}) list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${jpath}/${JAVA_INC_PATH}") endif() endforeach() - foreach(JAVA_LIB_PATH + foreach(JAVA_LIB_PATH IN ITEMS ../lib ../jre/lib ../jre/lib/i386 ../java/lib ../java/jre/lib ../java/jre/lib/i386 ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386) @@ -429,7 +428,7 @@ set(_JNI_NORMAL_JAWT PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES} ) -foreach(search ${_JNI_SEARCHES}) +foreach(search IN LISTS _JNI_SEARCHES) if(JVM IN_LIST JNI_FIND_COMPONENTS) find_library(JAVA_JVM_LIBRARY ${_JNI_${search}_JVM} DOC "Java Virtual Machine library" diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake index e8fb120..74e424b 100644 --- a/Modules/FindJava.cmake +++ b/Modules/FindJava.cmake @@ -90,13 +90,12 @@ if(_JAVA_HOME) endif() if (WIN32) macro (_JAVA_GET_INSTALLED_VERSIONS _KIND) - execute_process(COMMAND REG QUERY "HKLM\\SOFTWARE\\JavaSoft\\${_KIND}" - RESULT_VARIABLE _JAVA_RESULT - OUTPUT_VARIABLE _JAVA_VERSIONS - ERROR_QUIET) - if (NOT _JAVA_RESULT) - string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9._]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}") - string (REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\([0-9._]+)" "\\1" _JAVA_VERSIONS "${_JAVA_VERSIONS}") + cmake_host_system_information(RESULT _JAVA_VERSIONS + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/JavaSoft/${_KIND}" + SUBKEYS) + if (_JAVA_VERSIONS) + string (REGEX MATCHALL "[0-9._]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}") + string (REGEX REPLACE "([0-9._]+)" "\\1" _JAVA_VERSIONS "${_JAVA_VERSIONS}") if (_JAVA_VERSIONS) # sort versions. Most recent first list (SORT _JAVA_VERSIONS COMPARE NATURAL ORDER DESCENDING) @@ -221,7 +220,7 @@ if(Java_JAVA_EXECUTABLE) unset(_java_var) set(Java_VERSION "${Java_VERSION_MAJOR}") if(NOT "x${Java_VERSION}" STREQUAL "x") - foreach(_java_c MINOR PATCH TWEAK) + foreach(_java_c IN ITEMS "MINOR" "PATCH" "TWEAK") if(NOT "x${Java_VERSION_${_java_c}}" STREQUAL "x") string(APPEND Java_VERSION ".${Java_VERSION_${_java_c}}") else() @@ -274,7 +273,7 @@ find_program(Java_JARSIGNER_EXECUTABLE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) if(Java_FIND_COMPONENTS) set(_JAVA_REQUIRED_VARS) - foreach(component ${Java_FIND_COMPONENTS}) + foreach(component IN LISTS Java_FIND_COMPONENTS) # User just want to execute some Java byte-compiled If(component STREQUAL "Runtime") list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE) @@ -316,7 +315,7 @@ if(Java_FIND_COMPONENTS) VERSION_VAR Java_VERSION ) if(Java_FOUND) - foreach(component ${Java_FIND_COMPONENTS}) + foreach(component IN LISTS Java_FIND_COMPONENTS) set(Java_${component}_FOUND TRUE) endforeach() endif() diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake index 97943d6..a9920ee 100644 --- a/Modules/FindLibXslt.cmake +++ b/Modules/FindLibXslt.cmake @@ -110,7 +110,8 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXslt VERSION_VAR LIBXSLT_VERSION_STRING) mark_as_advanced(LIBXSLT_INCLUDE_DIR - LIBXSLT_LIBRARIES + LIBXSLT_LIBRARY + LIBXSLT_EXSLT_INCLUDE_DIR LIBXSLT_EXSLT_LIBRARY LIBXSLT_XSLTPROC_EXECUTABLE) diff --git a/Modules/FindLua50.cmake b/Modules/FindLua50.cmake index 0575caa..6ba9008 100644 --- a/Modules/FindLua50.cmake +++ b/Modules/FindLua50.cmake @@ -5,28 +5,19 @@ FindLua50 --------- - - Locate Lua library. -This module defines:: -:: +This module defines:: LUA50_FOUND, if false, do not try to link to Lua LUA_LIBRARIES, both lua and lualib LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h) - - -Note that the expected include convention is - -:: +Note that the expected include convention is:: #include "lua.h" -and not - -:: +and not:: #include <lua/lua.h> diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake index 283a3eb..405a7a7 100644 --- a/Modules/FindLua51.cmake +++ b/Modules/FindLua51.cmake @@ -5,29 +5,20 @@ FindLua51 --------- - - Locate Lua library. This module defines:: -:: - LUA51_FOUND, if false, do not try to link to Lua LUA_LIBRARIES LUA_INCLUDE_DIR, where to find lua.h LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) - -Note that the expected include convention is - -:: +Note that the expected include convention is:: #include "lua.h" -and not - -:: +and not:: #include <lua/lua.h> diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index e3246c6..a25f113 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -436,7 +436,7 @@ function (_MPI_interrogate_compiler LANG) # a particular MPICH derivate might check compiler interoperability. # Intel MPI in particular does this with I_MPI_CHECK_COMPILER. file(TO_NATIVE_PATH "${CMAKE_${LANG}_COMPILER}" _MPI_UNDERLAYING_COMPILER) - # On Windows, the Intel MPI batch scripts can only work with filnames - Full paths will break them. + # On Windows, the Intel MPI batch scripts can only work with filenames - Full paths will break them. # Due to the lack of other MPICH-based wrappers for Visual C++, we may treat this as default. if(MSVC) get_filename_component(_MPI_UNDERLAYING_COMPILER "${_MPI_UNDERLAYING_COMPILER}" NAME) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 3ab6bc1..639cc5f 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -46,7 +46,7 @@ The module supports the following components: The version given to the :command:`find_package` directive is the Matlab **version**, which should not be confused with the Matlab *release* name - (eg. `R2014`). + (e.g. `R2023b`). The :command:`matlab_get_version_from_release_name` and :command:`matlab_get_release_name_from_version` provide a mapping between the release name and the version. @@ -57,7 +57,7 @@ specific: * Windows: The installed versions of Matlab/MCR are retrieved from the Windows registry -* OS X: The installed versions of Matlab/MCR are given by the MATLAB +* macOS: The installed versions of Matlab/MCR are given by the MATLAB default installation paths in ``/Application``. If no such application is found, it falls back to the one that might be accessible from the ``PATH``. * Unix: The desired Matlab should be accessible from the ``PATH``. This does @@ -140,8 +140,8 @@ Result variables ``Matlab_VERSION`` .. versionadded:: 3.27 - the numerical version (e.g. 9.13) of Matlab found. Not to be confused with - Matlab release name (e.g. R2022b) that can be obtained with + the numerical version (e.g. 23.2.0) of Matlab found. Not to be confused with + Matlab release name (e.g. R2023b) that can be obtained with :command:`matlab_get_release_name_from_version`. ``Matlab_ROOT_DIR`` the final root of the Matlab installation determined by the FindMatlab @@ -302,6 +302,7 @@ if(NOT MATLAB_ADDITIONAL_VERSIONS) endif() set(MATLAB_VERSIONS_MAPPING + "R2023b=23.2" "R2023a=9.14" "R2022b=9.13" "R2022a=9.12" @@ -336,9 +337,7 @@ set(MATLAB_VERSIONS_MAPPING # temporary folder for all Matlab runs set(_matlab_temporary_folder ${CMAKE_BINARY_DIR}/Matlab) -if(NOT EXISTS "${_matlab_temporary_folder}") - file(MAKE_DIRECTORY "${_matlab_temporary_folder}") -endif() +file(MAKE_DIRECTORY "${_matlab_temporary_folder}") #[=======================================================================[.rst: .. command:: matlab_get_version_from_release_name @@ -347,14 +346,14 @@ endif() matlab_get_version_from_release_name(release version) - * Input: ``release`` is the release name (R2022b) - * Output: ``version`` is the version of Matlab (9.13) + * Input: ``release`` is the release name (e.g. R2023b) + * Output: ``version`` is the version of Matlab (e.g. 23.2.0) Returns the version of Matlab from a release name #]=======================================================================] macro(matlab_get_version_from_release_name release_name version_name) - string(REGEX MATCHALL "${release_name}=([0-9]+\\.?[0-9]*)" _matched ${MATLAB_VERSIONS_MAPPING}) + string(REGEX MATCHALL "${release_name}=([0-9]+\\.[0-9]+)" _matched ${MATLAB_VERSIONS_MAPPING}) set(${version_name} "") if(NOT _matched STREQUAL "") @@ -374,16 +373,24 @@ endmacro() matlab_get_release_name_from_version(version release_name) - * Input: ``version`` is the version of Matlab (9.13) - * Output: ``release_name`` is the release name (R2022b) + * Input: ``version`` is the version of Matlab (e.g. 23.2.0) + * Output: ``release_name`` is the release name (R2023b) Returns the release name from the version of Matlab #]=======================================================================] macro(matlab_get_release_name_from_version version release_name) + # only the major.minor version is used + string(REGEX MATCH "([0-9]+\\.[0-9]+)" _match ${version}) + if(CMAKE_MATCH_1) + set(short_version ${CMAKE_MATCH_1}) + else() + set(short_version ${version}) + endif() + set(${release_name} "") foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING) - string(REGEX MATCHALL "(.+)=${version}" _matched ${_var}) + string(REGEX MATCHALL "(.+)=${short_version}" _matched ${_var}) if(NOT _matched STREQUAL "") set(${release_name} ${CMAKE_MATCH_1}) break() @@ -393,7 +400,7 @@ macro(matlab_get_release_name_from_version version release_name) unset(_var) unset(_matched) if(${release_name} STREQUAL "") - message(WARNING "[MATLAB] The version ${version} is not registered") + message(WARNING "[MATLAB] The version ${short_version} is not registered") endif() endmacro() @@ -404,7 +411,7 @@ endmacro() macro(matlab_get_supported_releases list_releases) set(${list_releases}) foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING) - string(REGEX MATCHALL "(.+)=([0-9]+\\.?[0-9]*)" _matched ${_var}) + string(REGEX MATCHALL "(.+)=([0-9]+\\.[0-9]+)" _matched ${_var}) if(NOT _matched STREQUAL "") list(APPEND ${list_releases} ${CMAKE_MATCH_1}) endif() @@ -421,7 +428,7 @@ endmacro() macro(matlab_get_supported_versions list_versions) set(${list_versions}) foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING) - string(REGEX MATCHALL "(.+)=([0-9]+\\.?[0-9]*)" _matched ${_var}) + string(REGEX MATCHALL "(.+)=([0-9]+\\.[0-9]+)" _matched ${_var}) if(NOT _matched STREQUAL "") list(APPEND ${list_versions} ${CMAKE_MATCH_2}) endif() @@ -459,50 +466,44 @@ endmacro() function(matlab_extract_all_installed_versions_from_registry win64 matlab_versions) if(NOT CMAKE_HOST_WIN32) - message(FATAL_ERROR "[MATLAB] This macro can only be called by a windows host (call to reg.exe)") + message(FATAL_ERROR "[MATLAB] This macro can only be called by a Windows host") endif() if(${win64} AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "64") - set(APPEND_REG "/reg:64") + set(_view "64") else() - set(APPEND_REG "/reg:32") + set(_view "32") endif() set(matlabs_from_registry) foreach(_installation_type IN ITEMS "MATLAB" "MATLAB Runtime" "MATLAB Compiler Runtime") - # /reg:64 should be added on 64 bits capable OSs in order to enable the - # redirection of 64 bits applications - execute_process( - COMMAND reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\${_installation_type}" /f * /k ${APPEND_REG} - RESULT_VARIABLE resultMatlab - OUTPUT_VARIABLE varMatlab - ERROR_VARIABLE errMatlab - INPUT_FILE NUL - ) + cmake_host_system_information(RESULT _reg + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/${_installation_type}" + SUBKEYS VIEW ${_view} + ) + if(_reg) - if(resultMatlab EQUAL 0) + string(REGEX MATCHALL "([0-9]+\\.[0-9]+)" _versions_regex ${_reg}) - string( - REGEX MATCHALL "${_installation_type}\\\\([0-9]+(\\.[0-9]+)?)" - matlab_versions_regex ${varMatlab}) - - foreach(match IN LISTS matlab_versions_regex) - string( - REGEX MATCH "${_installation_type}\\\\(([0-9]+)(\\.([0-9]+))?)" - current_match ${match}) - - set(_matlab_current_version ${CMAKE_MATCH_1}) - set(current_matlab_version_major ${CMAKE_MATCH_2}) - set(current_matlab_version_minor ${CMAKE_MATCH_4}) - if(NOT current_matlab_version_minor) - set(current_matlab_version_minor "0") + foreach(match IN LISTS _versions_regex) + string(REGEX MATCH "([0-9]+\\.[0-9]+)" current_match ${match}) + + if(NOT CMAKE_MATCH_1) + continue() endif() - list(APPEND matlabs_from_registry ${_matlab_current_version}) - unset(_matlab_current_version) + cmake_host_system_information(RESULT _reg + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/${_installation_type}/${CMAKE_MATCH_1}" + VALUE "MATLABROOT" + ) + + _Matlab_VersionInfoXML(${_reg} _matlab_version_tmp) + if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") + list(APPEND matlabs_from_registry ${_matlab_version_tmp}) + endif() endforeach() endif() @@ -510,8 +511,7 @@ function(matlab_extract_all_installed_versions_from_registry win64 matlab_versio if(matlabs_from_registry) list(REMOVE_DUPLICATES matlabs_from_registry) - list(SORT matlabs_from_registry COMPARE NATURAL) - list(REVERSE matlabs_from_registry) + list(SORT matlabs_from_registry COMPARE NATURAL ORDER DESCENDING) endif() set(${matlab_versions} ${matlabs_from_registry} PARENT_SCOPE) @@ -529,8 +529,7 @@ macro(extract_matlab_versions_from_registry_brute_force matlab_versions) # we order from more recent to older if(matlab_supported_versions) list(REMOVE_DUPLICATES matlab_supported_versions) - list(SORT matlab_supported_versions COMPARE NATURAL) - list(REVERSE matlab_supported_versions) + list(SORT matlab_supported_versions COMPARE NATURAL ORDER DESCENDING) endif() set(${matlab_versions} ${matlab_supported_versions}) @@ -567,7 +566,7 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\${_matlab_current_version};MATLABROOT]" ABSOLUTE) - if(EXISTS "${current_MATLAB_ROOT}") + if(IS_DIRECTORY "${current_MATLAB_ROOT}") list(APPEND _matlab_roots_list "MATLAB" ${_matlab_current_version} ${current_MATLAB_ROOT}) endif() @@ -583,7 +582,7 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ # remove the dot string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") - if(EXISTS "${current_MATLAB_ROOT}") + if(IS_DIRECTORY "${current_MATLAB_ROOT}") list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") endif() @@ -599,7 +598,7 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ # remove the dot string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") - if(EXISTS "${current_MATLAB_ROOT}") + if(IS_DIRECTORY "${current_MATLAB_ROOT}") list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") endif() @@ -842,7 +841,7 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve string(SUBSTRING "${_matlab_version_from_cmd}" ${index} -1 substring_ans) string( - REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*'?([0-9]+(\\.[0-9]+)?)" + REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*'?([0-9]+(\\.[0-9]+)+)" matlab_versions_regex ${substring_ans}) foreach(match IN LISTS matlab_versions_regex) @@ -1281,7 +1280,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve if(NOT matlab_known_version STREQUAL "NOTFOUND") # the version is known, we just return it set(${matlab_final_version} ${matlab_known_version} PARENT_SCOPE) - set(Matlab_VERSION_STRING_INTERNAL ${matlab_known_version} CACHE INTERNAL "Matlab version (automatically determined)" FORCE) + set(Matlab_VERSION_STRING_INTERNAL ${matlab_known_version} CACHE INTERNAL "Matlab version (automatically determined)") return() endif() @@ -1292,7 +1291,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve if(EXISTS "${matlab_root}/appdata/version.xml") # we inspect the application version.xml file that contains the product information - file(STRINGS "${matlab_root}/appdata/version.xml" productinfo_string NEWLINE_CONSUME) + file(READ "${matlab_root}/appdata/version.xml" productinfo_string) string(REGEX MATCH "<installedProductData.*displayedString=\"([a-zA-Z ]+)\".*/>" product_reg_match ${productinfo_string} @@ -1325,7 +1324,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve if(NOT _matlab_current_program) set(_find_matlab_options) - if(matlab_root AND EXISTS ${matlab_root}) + if(IS_DIRECTORY "${matlab_root}") set(_find_matlab_options PATHS ${matlab_root} ${matlab_root}/bin NO_DEFAULT_PATH) endif() @@ -1337,13 +1336,13 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve ) endif() - if(NOT _matlab_current_program OR NOT EXISTS ${_matlab_current_program}) + if(NOT _matlab_current_program) # if not found, clear the dependent variables if(MATLAB_FIND_DEBUG) message(WARNING "[MATLAB] Cannot find the main matlab program under ${matlab_root}") endif() - set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE) - set(Matlab_VERSION_STRING_INTERNAL "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE) + set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version") + set(Matlab_VERSION_STRING_INTERNAL "" CACHE INTERNAL "internal matlab location for the discovered version") unset(_matlab_current_program) unset(_matlab_current_program CACHE) return() @@ -1363,10 +1362,16 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve # update the location of the program set(Matlab_PROG_VERSION_STRING_AUTO_DETECT ${_matlab_main_real_path_tmp} - CACHE INTERNAL "internal matlab location for the discovered version" FORCE) + CACHE INTERNAL "internal matlab location for the discovered version") - set(matlab_list_of_all_versions) - matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions) + _Matlab_VersionInfoXML(${matlab_root} _matlab_version_tmp) + if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") + # at least back to R2016 VersionInfo.xml exists + set(matlab_list_of_all_versions ${_matlab_version_tmp}) + else() + # time consuming, less stable way to find Matlab version by running Matlab + matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions) + endif() list(LENGTH matlab_list_of_all_versions list_of_all_versions_length) if(list_of_all_versions_length GREATER 0) @@ -1376,40 +1381,54 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve endif() # set the version into the cache - set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE) + set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)") # warning, just in case several versions found (should not happen) if((list_of_all_versions_length GREATER 1) AND MATLAB_FIND_DEBUG) message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${matlab_list_of_all_versions})") endif() - # return the updated value - set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE) - elseif(EXISTS "${matlab_root}/VersionInfo.xml") + else() # MCR # we cannot run anything in order to extract the version. We assume that the file # VersionInfo.xml exists under the MatlabRoot, we look for it and extract the version from there - set(_matlab_version_tmp "unknown") - file(STRINGS "${matlab_root}/VersionInfo.xml" versioninfo_string NEWLINE_CONSUME) - - if(versioninfo_string) - # parses "<version>9.2.0.538062</version>" - string(REGEX MATCH "<version>(.*)</version>" - version_reg_match - ${versioninfo_string} - ) - - if(CMAKE_MATCH_1 MATCHES "(([0-9]+)\\.([0-9]+))[\\.0-9]*") - set(_matlab_version_tmp "${CMAKE_MATCH_1}") - endif() + _Matlab_VersionInfoXML(${matlab_root} _matlab_version_tmp) + if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") + set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)") endif() - set(${matlab_final_version} "${_matlab_version_tmp}" PARENT_SCOPE) - set(Matlab_VERSION_STRING_INTERNAL - "${_matlab_version_tmp}" - CACHE INTERNAL "Matlab (MCR) version (automatically determined)" - FORCE) endif() # Matlab or MCR + # return the updated value + set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE) + +endfunction() + + +function(_Matlab_VersionInfoXML matlab_root _version) + + set(_ver "unknown") + + set(_XMLfile ${matlab_root}/VersionInfo.xml) + if(NOT EXISTS ${_XMLfile}) + return() + endif() + + file(READ ${_XMLfile} versioninfo_string) + + if(versioninfo_string) + # parses "<version>23.2.0.2365128</version>" + string(REGEX MATCH "<version>([0-9]+(\\.[0-9]+)+)</version>" + version_reg_match + ${versioninfo_string} + ) + + if(CMAKE_MATCH_1) + set(_ver "${CMAKE_MATCH_1}") + endif() + endif() + + set(${_version} ${_ver} PARENT_SCOPE) + endfunction() @@ -1444,8 +1463,8 @@ function(_Matlab_find_instances_win32 matlab_roots) endfunction() -# Utility function for finding Matlab or MCR on OSX -function(_Matlab_find_instances_osx matlab_roots) +# Utility function for finding Matlab or MCR on macOS +function(_Matlab_find_instances_macos matlab_roots) set(_matlab_possible_roots) # on mac, we look for the /Application paths @@ -1462,8 +1481,13 @@ function(_Matlab_find_instances_osx matlab_roots) string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") set(_matlab_base_path "/Applications/MATLAB_${_matlab_current_release}.app") + _Matlab_VersionInfoXML(${_matlab_base_path} _matlab_version_tmp) + if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") + set(_matlab_current_version ${_matlab_version_tmp}) + endif() + # Check Matlab, has precedence over MCR - if(EXISTS ${_matlab_base_path}) + if(IS_DIRECTORY "${_matlab_base_path}") if(MATLAB_FIND_DEBUG) message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_base_path}") endif() @@ -1472,7 +1496,7 @@ function(_Matlab_find_instances_osx matlab_roots) # Checks MCR set(_mcr_path "/Applications/MATLAB/MATLAB_Runtime/v${_matlab_current_version_without_dot}") - if(EXISTS "${_mcr_path}") + if(IS_DIRECTORY "${_mcr_path}") if(MATLAB_FIND_DEBUG) message(STATUS "[MATLAB] Found MCR version ${_matlab_current_release} (${_matlab_current_version}) in ${_mcr_path}") endif() @@ -1565,7 +1589,7 @@ endif() if(Matlab_ROOT_DIR) # if the user specifies a possible root, we keep this one - if(NOT EXISTS "${Matlab_ROOT_DIR}") + if(NOT IS_DIRECTORY "${Matlab_ROOT_DIR}") # if Matlab_ROOT_DIR specified but erroneous if(MATLAB_FIND_DEBUG) message(WARNING "[MATLAB] the specified path for Matlab_ROOT_DIR does not exist (${Matlab_ROOT_DIR})") @@ -1587,8 +1611,8 @@ else() _Matlab_find_instances_win32(_matlab_possible_roots_win32) list(APPEND _matlab_possible_roots ${_matlab_possible_roots_win32}) elseif(APPLE) - _Matlab_find_instances_osx(_matlab_possible_roots_osx) - list(APPEND _matlab_possible_roots ${_matlab_possible_roots_osx}) + _Matlab_find_instances_macos(_matlab_possible_roots_macos) + list(APPEND _matlab_possible_roots ${_matlab_possible_roots_macos}) endif() endif() @@ -1604,10 +1628,6 @@ if(MATLAB_FIND_DEBUG) message(STATUS "[MATLAB] Matlab root folders are ${_matlab_possible_roots}") endif() - - - - # take the first possible Matlab root list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots) set(Matlab_VERSION_STRING "NOTFOUND") @@ -1799,7 +1819,7 @@ endif() # This small stub around find_library is to prevent any pollution of CMAKE_FIND_LIBRARY_PREFIXES in the global scope. # This is the function to be used below instead of the find_library directives. function(_Matlab_find_library _matlab_library_prefix) - set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} ${_matlab_library_prefix}) + list(APPEND CMAKE_FIND_LIBRARY_PREFIXES ${_matlab_library_prefix}) find_library(${ARGN}) endfunction() diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake index 3d58569..c8e295b 100644 --- a/Modules/FindOpenAL.cmake +++ b/Modules/FindOpenAL.cmake @@ -106,15 +106,9 @@ find_package_handle_standard_args( mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR) if(OPENAL_FOUND AND NOT TARGET OpenAL::OpenAL) - if(OPENAL_LIBRARY MATCHES "/([^/]+)\\.framework$") - add_library(OpenAL::OpenAL INTERFACE IMPORTED) - set_target_properties(OpenAL::OpenAL PROPERTIES - INTERFACE_LINK_LIBRARIES "${OPENAL_LIBRARY}") - else() - add_library(OpenAL::OpenAL UNKNOWN IMPORTED) - set_target_properties(OpenAL::OpenAL PROPERTIES - IMPORTED_LOCATION "${OPENAL_LIBRARY}") - endif() + add_library(OpenAL::OpenAL UNKNOWN IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LOCATION "${OPENAL_LIBRARY}") set_target_properties(OpenAL::OpenAL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}") endif() diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake index 843f787..1527c31 100644 --- a/Modules/FindOpenGL.cmake +++ b/Modules/FindOpenGL.cmake @@ -655,17 +655,8 @@ if(OPENGL_FOUND) # A legacy GL library is available, so use it for the legacy GL target. if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}") add_library(OpenGL::GL UNKNOWN IMPORTED) - if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$") - set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}") - if(EXISTS "${_gl_fw}.tbd") - string(APPEND _gl_fw ".tbd") - endif() - set_target_properties(OpenGL::GL PROPERTIES - IMPORTED_LOCATION "${_gl_fw}") - else() - set_target_properties(OpenGL::GL PROPERTIES - IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}") - endif() + set_target_properties(OpenGL::GL PROPERTIES + IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}") else() add_library(OpenGL::GL INTERFACE IMPORTED) set_target_properties(OpenGL::GL PROPERTIES @@ -709,17 +700,8 @@ if(OPENGL_FOUND) if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU) if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}") add_library(OpenGL::GLU UNKNOWN IMPORTED) - if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$") - set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}") - if(EXISTS "${_glu_fw}.tbd") - string(APPEND _glu_fw ".tbd") - endif() - set_target_properties(OpenGL::GLU PROPERTIES - IMPORTED_LOCATION "${_glu_fw}") - else() - set_target_properties(OpenGL::GLU PROPERTIES - IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}") - endif() + set_target_properties(OpenGL::GLU PROPERTIES + IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}") else() add_library(OpenGL::GLU INTERFACE IMPORTED) set_target_properties(OpenGL::GLU PROPERTIES diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 1d0f34b..69099f7 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -298,8 +298,9 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR) set("${OPENMP_LIB_NAMES_VAR}" "" PARENT_SCOPE) endif() break() - elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "AppleClang" - AND CMAKE_${LANG}_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0") + elseif((CMAKE_${LANG}_COMPILER_ID STREQUAL "AppleClang" + AND CMAKE_${LANG}_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0") OR + (CMAKE_${LANG}_COMPILER_ID STREQUAL "Clang" AND APPLE)) # Check for separate OpenMP library on AppleClang 7+ find_library(OpenMP_libomp_LIBRARY diff --git a/Modules/FindPhysFS.cmake b/Modules/FindPhysFS.cmake index a32f83a..19e5ba9 100644 --- a/Modules/FindPhysFS.cmake +++ b/Modules/FindPhysFS.cmake @@ -5,16 +5,20 @@ FindPhysFS ---------- +Locate PhysFS library This module defines: +``PHYSFS_LIBRARY`` + the name of the library to link against +``PHYSFS_FOUND`` + if false, do not try to link to PHYSFS +``PHYSFS_INCLUDE_DIR`` + where to find physfs.h -Locate PhysFS library This module defines PHYSFS_LIBRARY, the name of -the library to link against PHYSFS_FOUND, if false, do not try to link -to PHYSFS PHYSFS_INCLUDE_DIR, where to find physfs.h +``$PHYSFSDIR`` is an environment variable that would correspond to:: -$PHYSFSDIR is an environment variable that would correspond to the -./configure --prefix=$PHYSFSDIR used in building PHYSFS. + ./configure --prefix=$PHYSFSDIR -Created by Eric Wing. +used in building PHYSFS. #]=======================================================================] find_path(PHYSFS_INCLUDE_DIR physfs.h diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 02f7fb4..27d25fb 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -425,13 +425,19 @@ macro(_pkg_set_path_internal) unset(_pkgconfig_path) endif() - # Tell pkg-config not to strip any -L paths so we can search them all. + # Tell pkg-config not to strip any -I or -L paths so we can search them all. if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}) set(_pkgconfig_allow_system_libs_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}") else() unset(_pkgconfig_allow_system_libs_old) endif() set(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} 1) + if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) + set(_pkgconfig_allow_system_cflags_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}") + else() + unset(_pkgconfig_allow_system_cflags_old) + endif() + set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1) endmacro() macro(_pkg_restore_path_internal) @@ -445,6 +451,12 @@ macro(_pkg_restore_path_internal) else() unset(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}) endif() + if(DEFINED _pkgconfig_allow_system_cflags_old) + set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} "${_pkgconfig_allow_system_cflags_old}") + unset(_pkgconfig_allow_system_cflags_old) + else() + unset(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) + endif() unset(_extra_paths) unset(_pkgconfig_path_old) @@ -543,7 +555,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma endif() set(_pkg_check_modules_packages) - set(_pkg_check_modules_failed) + set(_pkg_check_modules_failed "") _pkg_set_path_internal() @@ -551,8 +563,8 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma foreach (_pkg_check_modules_pkg ${_pkg_check_modules_list}) set(_pkg_check_modules_exist_query) - # check whether version is given - if (_pkg_check_modules_pkg MATCHES "(.*[^><])(=|[><]=?)(.*)") + # check whether version is given while ignoring whitespace + if (_pkg_check_modules_pkg MATCHES "(.*[^>< \t])[ \t]*(=|[><]=?)[ \t]*(.*)") set(_pkg_check_modules_pkg_name "${CMAKE_MATCH_1}") set(_pkg_check_modules_pkg_op "${CMAKE_MATCH_2}") set(_pkg_check_modules_pkg_ver "${CMAKE_MATCH_3}") @@ -597,14 +609,14 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma message(STATUS " ${_pkgconfig_error}") endif() - set(_pkg_check_modules_failed 1) + string(APPEND _pkg_check_modules_failed " - ${_pkg_check_modules_pkg}\n") endif() endforeach() if(_pkg_check_modules_failed) # fail when requested if (${_is_required}) - message(FATAL_ERROR "A required package was not found") + message(FATAL_ERROR "The following required packages were not found:\n${_pkg_check_modules_failed}") endif () else() # when we are here, we checked whether requested modules @@ -911,11 +923,20 @@ endmacro() .. code-block:: cmake - pkg_get_variable(<resultVar> <moduleName> <varName>) + pkg_get_variable(<resultVar> <moduleName> <varName> + [DEFINE_VARIABLES <key>=<value>...]) If ``pkg-config`` returns multiple values for the specified variable, ``resultVar`` will contain a :ref:`;-list <CMake Language Lists>`. + Options: + + ``DEFINE_VARIABLES <key>=<value>...`` + .. versionadded:: 3.28 + + Specify key-value pairs to redefine variables affecting the variable + retrieved with ``pkg-config``. + For example: .. code-block:: cmake @@ -923,8 +944,20 @@ endmacro() pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir) #]========================================] function (pkg_get_variable result pkg variable) + set(_multiValueArgs DEFINE_VARIABLES) + + CMAKE_PARSE_ARGUMENTS(_parsedArguments "" "" "${_multiValueArgs}" ${ARGN}) + set(defined_variables ) + foreach(_def_var ${_parsedArguments_DEFINE_VARIABLES}) + if(NOT _def_var MATCHES "^.+=.*$") + message(FATAL_ERROR "DEFINE_VARIABLES should contain arguments in the form of key=value") + endif() + + list(APPEND defined_variables "--define-variable=${_def_var}") + endforeach() + _pkg_set_path_internal() - _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}") + _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}" ${defined_variables}) set("${result}" "${prefix_result}" PARENT_SCOPE) diff --git a/Modules/FindProducer.cmake b/Modules/FindProducer.cmake index 65495b5..8a16e8a 100644 --- a/Modules/FindProducer.cmake +++ b/Modules/FindProducer.cmake @@ -5,8 +5,6 @@ FindProducer ------------ - - Though Producer isn't directly part of OpenSceneGraph, its primary user is OSG so I consider this part of the Findosg* suite used to find OpenSceneGraph components. You'll notice that I accept OSGDIR as an @@ -17,19 +15,25 @@ must also opt into OpenGL (and OpenThreads?) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular module (perhaps because the default -FindOpenGL.cmake module doesn't work with your system as an example). +:module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, -use the FindOpenSceneGraph.cmake instead of the Findosg*.cmake +use the :module:`FindOpenSceneGraph` instead of the Findosg*.cmake modules. -Locate Producer This module defines PRODUCER_LIBRARY PRODUCER_FOUND, -if false, do not try to link to Producer PRODUCER_INCLUDE_DIR, where -to find the headers +Locate Producer This module defines: + +``PRODUCER_LIBRARY`` + +``PRODUCER_FOUND`` + if false, do not try to link to Producer +``PRODUCER_INCLUDE_DIR`` + where to find the headers + +``$PRODUCER_DIR`` is an environment variable that would correspond to:: -$PRODUCER_DIR is an environment variable that would correspond to the -./configure --prefix=$PRODUCER_DIR used in building osg. + ./configure --prefix=$PRODUCER_DIR -Created by Eric Wing. +used in building osg. #]=======================================================================] # Header files are presumed to be included like diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index a92fb52..a7ee0c4 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -136,15 +136,95 @@ Example: Variable to define with autogenerated Python files ``ARGN`` ``.proto`` files + +.. command:: protobuf_generate + + .. versionadded:: 3.13 + + Automatically generate source files from ``.proto`` schema files at build time:: + + protobuf_generate ( + TARGET <target> + [LANGUAGE <lang>] + [OUT_VAR <out_var>] + [EXPORT_MACRO <macro>] + [PROTOC_OUT_DIR <dir>] + [PLUGIN <plugin>] + [PLUGIN_OPTIONS <plugin_options>] + [DEPENDENCIES <depends] + [PROTOS <protobuf_files>] + [IMPORT_DIRS <dirs>] + [GENERATE_EXTENSIONS <extensions>] + [PROTOC_OPTIONS <protoc_options>] + [APPEND_PATH]) + + ``APPEND_PATH`` + A flag that causes the base path of all proto schema files to be added to + ``IMPORT_DIRS``. + ``LANGUAGE`` + A single value: cpp or python. Determines what kind of source files are + being generated. Defaults to cpp. + ``OUT_VAR`` + Name of a CMake variable that will be filled with the paths to the generated + source files. + ``EXPORT_MACRO`` + Name of a macro that is applied to all generated Protobuf message classes + and extern variables. It can, for example, be used to declare DLL exports. + ``PROTOC_OUT_DIR`` + Output directory of generated source files. Defaults to ``CMAKE_CURRENT_BINARY_DIR``. + ``PLUGIN`` + .. versionadded:: 3.21 + + An optional plugin executable. This could, for example, be the path to + ``grpc_cpp_plugin``. + ``PLUGIN_OPTIONS`` + .. versionadded:: 3.28 + + Additional options provided to the plugin, such as ``generate_mock_code=true`` + for the gRPC cpp plugin. + ``DEPENDENCIES`` + .. versionadded:: 3.28 + + Arguments forwarded to the ``DEPENDS`` of the underlying ``add_custom_command`` + invocation. + ``TARGET`` + CMake target that will have the generated files added as sources. + ``PROTOS`` + List of proto schema files. If omitted, then every source file ending in *proto* of ``TARGET`` will be used. + ``IMPORT_DIRS`` + A common parent directory for the schema files. For example, if the schema file is + ``proto/helloworld/helloworld.proto`` and the import directory ``proto/`` then the + generated files are ``${PROTOC_OUT_DIR}/helloworld/helloworld.pb.h`` and + ``${PROTOC_OUT_DIR}/helloworld/helloworld.pb.cc``. + ``GENERATE_EXTENSIONS`` + If LANGUAGE is omitted then this must be set to the extensions that protoc generates. + ``PROTOC_OPTIONS`` + .. versionadded:: 3.28 + + Additional arguments that are forwarded to protoc. + + Example:: + + find_package(gRPC CONFIG REQUIRED) + find_package(Protobuf REQUIRED) + add_library(ProtoTest Test.proto) + target_link_libraries(ProtoTest PUBLIC gRPC::grpc++) + protobuf_generate(TARGET ProtoTest) + protobuf_generate( + TARGET ProtoTest + LANGUAGE grpc + PLUGIN protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin> + PLUGIN_OPTIONS generate_mock_code=true + GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc) #]=======================================================================] function(protobuf_generate) set(_options APPEND_PATH DESCRIPTORS) - set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN) + set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS DEPENDENCIES) if(COMMAND target_sources) list(APPEND _singleargs TARGET) endif() - set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS) + set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS PROTOC_OPTIONS) cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") @@ -168,9 +248,18 @@ function(protobuf_generate) endif() if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) - set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:") + set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}") endif() + foreach(_option ${_dll_export_decl} ${protobuf_generate_PLUGIN_OPTIONS}) + # append comma - not using CMake lists and string replacement as users + # might have semicolons in options + if(_plugin_options) + set( _plugin_options "${_plugin_options},") + endif() + set(_plugin_options "${_plugin_options}${_option}") + endforeach() + if(protobuf_generate_PLUGIN) set(_plugin "--plugin=${protobuf_generate_PLUGIN}") endif() @@ -204,10 +293,10 @@ function(protobuf_generate) # Create an include path for each file specified foreach(_file ${protobuf_generate_PROTOS}) get_filename_component(_abs_file ${_file} ABSOLUTE) - get_filename_component(_abs_path ${_abs_file} PATH) - list(FIND _protobuf_include_path ${_abs_path} _contains_already) + get_filename_component(_abs_dir ${_abs_file} DIRECTORY) + list(FIND _protobuf_include_path ${_abs_dir} _contains_already) if(${_contains_already} EQUAL -1) - list(APPEND _protobuf_include_path -I ${_abs_path}) + list(APPEND _protobuf_include_path -I ${_abs_dir}) endif() endforeach() else() @@ -246,12 +335,20 @@ function(protobuf_generate) endif() list(APPEND _generated_srcs_all ${_generated_srcs}) + set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}") + if(protobuf_generate_PROTOC_OPTIONS) + set(_comment "${_comment}, protoc-options: ${protobuf_generate_PROTOC_OPTIONS}") + endif() + if(_plugin_options) + set(_comment "${_comment}, plugin-options: ${_plugin_options}") + endif() + add_custom_command( OUTPUT ${_generated_srcs} - COMMAND protobuf::protoc - ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file} - DEPENDS ${_abs_file} protobuf::protoc - COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}" + COMMAND protobuf::protoc + ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file} + DEPENDS ${_abs_file} protobuf::protoc ${protobuf_generate_DEPENDENCIES} + COMMENT ${_comment} VERBATIM ) endforeach() diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index d483d7f..08ab9c0 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -474,7 +474,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) set (config_flag "--${NAME}") endif() string (TOLOWER "${config_flag}" config_flag) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" ${config_flag} + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} ${config_flag} RESULT_VARIABLE _result OUTPUT_VARIABLE _values ERROR_QUIET @@ -752,12 +752,43 @@ function (_PYTHON_GET_VERSION) endfunction() function (_PYTHON_GET_LAUNCHER _PYTHON_PGL_NAME) - cmake_parse_arguments (PARSE_ARGV 1 _PGL "INTERPRETER;COMPILER" "" "") + cmake_parse_arguments (PARSE_ARGV 1 _PGL "INTERPRETER;COMPILER" "CONFIG" "") unset (${_PYTHON_PGL_NAME} PARENT_SCOPE) if ((_PGL_INTERPRETER AND NOT _${_PYTHON_PREFIX}_EXECUTABLE) - OR (_PGL_COMPILER AND NOT _${_PYTHON_PREFIX}_COMPILER)) + OR (_PGL_COMPILER AND NOT _${_PYTHON_PREFIX}_COMPILER) + OR (_PGL_CONFIG AND NOT _${_PYTHON_PREFIX}_CONFIG)) + return() + endif() + + if (_PGL_CONFIG) + # default config script can be launched directly + set (${_PYTHON_PGL_NAME} "${_${_PYTHON_PREFIX}_CONFIG}" PARENT_SCOPE) + + if (NOT MINGW) + return() + endif() + # on MINGW environment, python-config script may require bash to be launched + execute_process (COMMAND cygpath.exe -u "${_${_PYTHON_PREFIX}_CONFIG}" + RESULT_VARIABLE _result + OUTPUT_VARIABLE _config + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (_result) + # impossible to convert path, keep default config + return() + endif() + execute_process (COMMAND bash.exe "${_config}" --prefix + RESULT_VARIABLE _result + OUTPUT_QUIET + ERROR_QUIET) + if (_result) + # fail to execute through bash, keep default config + return() + endif() + + set(${_PYTHON_PGL_NAME} bash.exe "${_config}" PARENT_SCOPE) return() endif() @@ -770,7 +801,7 @@ function (_PYTHON_GET_LAUNCHER _PYTHON_PGL_NAME) AND ext STREQUAL ".exe") set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE) endif() - else() + elseif (_PGL_COMPILER) get_filename_component (name "${_${_PYTHON_PREFIX}_COMPILER}" NAME) get_filename_component (ext "${_${_PYTHON_PREFIX}_COMPILER}" LAST_EXT) if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES @@ -981,7 +1012,7 @@ function (_PYTHON_VALIDATE_COMPILER) # retrieve python environment version from compiler set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") - file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n") + file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]])); sys.stdout.flush()\n") execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_COMPILER}" ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} /target:exe /embed "${working_dir}/version.py" @@ -2520,7 +2551,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # retrieve python environment version from compiler _python_get_launcher (_${_PYTHON_PREFIX}_COMPILER_LAUNCHER COMPILER) set (_${_PYTHON_PREFIX}_VERSION_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") - file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n") + file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]])); sys.stdout.flush()\n") execute_process (COMMAND ${_${_PYTHON_PREFIX}_COMPILER_LAUNCHER} "${_${_PYTHON_PREFIX}_COMPILER}" ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" @@ -2731,20 +2762,23 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS NO_DEFAULT_PATH) endif() + _python_get_launcher (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER CONFIG "${_${_PYTHON_PREFIX}_CONFIG}") + if (_${_PYTHON_PREFIX}_CONFIG) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --prefix RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP - ERROR_QUIET + ERROR_VARIABLE __${_PYTHON_PREFIX}_HELP OUTPUT_STRIP_TRAILING_WHITESPACE) if (_${_PYTHON_PREFIX}_RESULT) # assume config tool is not usable unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) endif() endif() if (_${_PYTHON_PREFIX}_CONFIG) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --abiflags RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS ERROR_QUIET @@ -2756,22 +2790,25 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS) # Wrong ABI unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) endif() endif() if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) # check that config tool match library architecture - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --configdir RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (_${_PYTHON_PREFIX}_RESULT) unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) else() string(FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT) if (_${_PYTHON_PREFIX}_RESULT EQUAL -1) unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) endif() endif() endif() @@ -2817,8 +2854,10 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS unset (_${_PYTHON_PREFIX}_CONFIG_NAMES) + _python_get_launcher (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER CONFIG "${_${_PYTHON_PREFIX}_CONFIG}") + if (_${_PYTHON_PREFIX}_CONFIG) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --help + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --prefix RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE __${_PYTHON_PREFIX}_HELP ERROR_QUIET @@ -2826,6 +2865,7 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS if (_${_PYTHON_PREFIX}_RESULT) # assume config tool is not usable unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) endif() endif() @@ -2833,7 +2873,7 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS continue() endif() - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --abiflags + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --abiflags RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE __${_PYTHON_PREFIX}_ABIFLAGS ERROR_QUIET @@ -2845,23 +2885,26 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND NOT __${_PYTHON_PREFIX}_ABIFLAGS IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS) # Wrong ABI unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) continue() endif() if (_${_PYTHON_PREFIX}_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) # check that config tool match library architecture - execute_process (COMMAND "${_${_PYTHON_PREFIX}_CONFIG}" --configdir + execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} --configdir RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE _${_PYTHON_PREFIX}_CONFIGDIR ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (_${_PYTHON_PREFIX}_RESULT) unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) continue() endif() string (FIND "${_${_PYTHON_PREFIX}_CONFIGDIR}" "${CMAKE_LIBRARY_ARCHITECTURE}" _${_PYTHON_PREFIX}_RESULT) if (_${_PYTHON_PREFIX}_RESULT EQUAL -1) unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_CONFIG_LAUNCHER) continue() endif() endif() diff --git a/Modules/FindQt.cmake b/Modules/FindQt.cmake index 44a1f41..604f8e3 100644 --- a/Modules/FindQt.cmake +++ b/Modules/FindQt.cmake @@ -91,7 +91,7 @@ endif () # now find qmake find_program(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin") if(QT_QMAKE_EXECUTABLE_FINDQT) - exec_program(${QT_QMAKE_EXECUTABLE_FINDQT} ARGS "-query QT_VERSION" + execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT} -query QT_VERSION OUTPUT_VARIABLE QTVERSION) if(QTVERSION MATCHES "4") set(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt4 qmake program.") @@ -103,8 +103,8 @@ if(QT_QMAKE_EXECUTABLE_FINDQT) endif() if(QT_QMAKE_EXECUTABLE_FINDQT) - exec_program( ${QT_QMAKE_EXECUTABLE_FINDQT} - ARGS "-query QT_INSTALL_HEADERS" + execute_process(COMMAND ${QT_QMAKE_EXECUTABLE_FINDQT} + -query QT_INSTALL_HEADERS OUTPUT_VARIABLE qt_headers ) endif() diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake index 3154ad3..9174bee 100644 --- a/Modules/FindQt4.cmake +++ b/Modules/FindQt4.cmake @@ -36,7 +36,7 @@ Qt Build Tools ^^^^^^^^^^^^^^ Qt relies on some bundled tools for code generation, such as ``moc`` for -meta-object code generation,``uic`` for widget layout and population, +meta-object code generation, ``uic`` for widget layout and population, and ``rcc`` for virtual filesystem content generation. These tools may be automatically invoked by :manual:`cmake(1)` if the appropriate conditions are met. See :manual:`cmake-qt(7)` for more. diff --git a/Modules/FindQuickTime.cmake b/Modules/FindQuickTime.cmake index 107486d..89be2a6 100644 --- a/Modules/FindQuickTime.cmake +++ b/Modules/FindQuickTime.cmake @@ -5,16 +5,18 @@ FindQuickTime ------------- +Locate QuickTime This module defines: +``QUICKTIME_LIBRARY`` -Locate QuickTime This module defines QUICKTIME_LIBRARY -QUICKTIME_FOUND, if false, do not try to link to gdal -QUICKTIME_INCLUDE_DIR, where to find the headers +``QUICKTIME_FOUND`` + if false, do not try to link to gdal +``QUICKTIME_INCLUDE_DIR`` + where to find the headers -$QUICKTIME_DIR is an environment variable that would correspond to the -./configure --prefix=$QUICKTIME_DIR +``$QUICKTIME_DIR`` is an environment variable that would correspond to:: -Created by Eric Wing. + ./configure --prefix=$QUICKTIME_DIR #]=======================================================================] find_path(QUICKTIME_INCLUDE_DIR QuickTime/QuickTime.h QuickTime.h diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index d82f41d..4fe8bd5 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -8,7 +8,7 @@ FindRuby Find Ruby This module finds if Ruby is installed and determines where the -include files and libraries are. Ruby 1.8 through 3.1 are +include files and libraries are. Ruby 1.8 through 3.2 are supported. The minimum required version of Ruby can be specified using the @@ -136,13 +136,13 @@ set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION # Set name of possible executables, ignoring the minor # Eg: -# 2.1.1 => from ruby31 to ruby21 included -# 2.1 => from ruby31 to ruby21 included -# 2 => from ruby31 to ruby20 included -# empty => from ruby31 to ruby18 included +# 2.1.1 => from ruby32 to ruby21 included +# 2.1 => from ruby32 to ruby21 included +# 2 => from ruby32 to ruby20 included +# empty => from ruby32 to ruby18 included if(NOT Ruby_FIND_VERSION_EXACT) - foreach(_ruby_version RANGE 31 18 -1) + foreach(_ruby_version RANGE 32 18 -1) string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version) string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version) diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake index c68e18d..7691eb7 100644 --- a/Modules/FindSDL.cmake +++ b/Modules/FindSDL.cmake @@ -181,7 +181,7 @@ if(SDL_LIBRARY_TEMP) # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa. # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there if I modify a pre-used variable. + # though it actually is there if I modify a preused variable. # I think it has something to do with the CACHE STRING. # So I use a temporary variable until the end so I can set the # "real" variable in one-shot. diff --git a/Modules/FindSDL_sound.cmake b/Modules/FindSDL_sound.cmake index d863e3c..3443959 100644 --- a/Modules/FindSDL_sound.cmake +++ b/Modules/FindSDL_sound.cmake @@ -196,7 +196,7 @@ if(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY) # I expect that MPGLIB, VOC, WAV, AIFF, and SHN are compiled in statically. # I think Timidity is also compiled in statically. - # I've never had to explcitly link against Quicktime, so I'll skip that for now. + # I've never had to explicitly link against Quicktime, so I'll skip that for now. set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARY}) diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake index ed2657c..4a93c04 100644 --- a/Modules/FindTIFF.cmake +++ b/Modules/FindTIFF.cmake @@ -65,6 +65,79 @@ The following cache variables may also be set: Debug and Release variants are found separately. #]=======================================================================] +set(_TIFF_args) +if (TIFF_FIND_QUIETLY) + list(APPEND _TIFF_args + QUIET) +endif () +if (TIFF_FIND_VERSION) + list(APPEND _TIFF_args + "${TIFF_FIND_VERSION}") + if (TIFF_FIND_VERSION_EXACT) + list(APPEND _TIFF_args + EXACT) + endif () +endif () +set(_TIFF_component_req) +set(_TIFF_component_opt) +foreach (_TIFF_component IN LISTS TIFF_FIND_COMPONENTS) + if (TIFF_FIND_REQUIRE_${_TIFF_component}) + list(APPEND _TIFF_component_req + "${_TIFF_component}") + else () + list(APPEND _TIFF_component_opt + "${_TIFF_component}") + endif () +endforeach () +unset(_TIFF_component) +if (_TIFF_component_req) + list(APPEND _TIFF_args + COMPONENTS "${_TIFF_component_req}") +endif () +unset(_TIFF_component_req) +if (_TIFF_component_opt) + list(APPEND _TIFF_args + OPTIONAL_COMPONENTS "${_TIFF_component_opt}") +endif () +unset(_TIFF_component_opt) +find_package(tiff CONFIG ${_TIFF_args}) +unset(_TIFF_args) +if (tiff_FOUND) + if (NOT TARGET TIFF::TIFF) + add_library(TIFF::TIFF IMPORTED INTERFACE) + set_target_properties(TIFF::TIFF PROPERTIES + INTERFACE_LINK_LIBRARIES TIFF::tiff) + endif () + get_property(TIFF_INCLUDE_DIRS TARGET TIFF::tiff PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + get_property(TIFF_LIBRARIES TARGET TIFF::tiff PROPERTY INTERFACE_LINK_LIBRARIES) + get_property(_TIFF_location TARGET TIFF::tiff PROPERTY LOCATION) + list(APPEND TIFF_LIBRARIES + "${_TIFF_location}") + unset(_TIFF_location) + set(TIFF_FOUND 1) + if("CXX" IN_LIST TIFF_FIND_COMPONENTS) + if (TARGET TIFF::CXX) + get_property(_TIFF_CXX_location TARGET TIFF::CXX PROPERTY LOCATION) + list(APPEND TIFF_LIBRARIES ${_TIFF_CXX_location}) + unset(_TIFF_CXX_location) + set(TIFF_CXX_FOUND 1) + else () + set(TIFF_CXX_FOUND 0) + if (TIFF_FIND_REQUIRED_CXX) + set(TIFF_FOUND 0) + list(APPEND TIFF_NOT_FOUND_REASON + "No C++ bindings target found") + endif () + endif () + endif () + set(TIFF_VERSION_STRING "${tiff_VERSION}") + foreach (_TIFF_component IN LISTS TIFF_FIND_COMPONENTS) + set(TIFF_${_TIFF_component}_FOUND "${tiff_${_TIFF_component}_FOUND}") + endforeach () + unset(_TIFF_component) + return () +endif () + cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) diff --git a/Modules/FindXCTest.cmake b/Modules/FindXCTest.cmake index 40e767b..a01c010 100644 --- a/Modules/FindXCTest.cmake +++ b/Modules/FindXCTest.cmake @@ -74,7 +74,7 @@ if(CMAKE_EFFECTIVE_SYSTEM_NAME STREQUAL "Apple" # platform directory which is not added to the CMAKE_FIND_ROOT_PATH # (only to CMAKE_SYSTEM_FRAMEWORK_PATH) and therefore not searched. # - # Until this is properly addressed, temporaily add the platform + # Until this is properly addressed, temporarily add the platform # directory to CMAKE_FIND_ROOT_PATH. list(APPEND CMAKE_FIND_ROOT_PATH "${_CMAKE_OSX_SYSROOT_PATH}/../..") endif() diff --git a/Modules/Findosg.cmake b/Modules/Findosg.cmake index 027f315..9e952c9 100644 --- a/Modules/Findosg.cmake +++ b/Modules/Findosg.cmake @@ -7,32 +7,40 @@ Findosg -NOTE: It is highly recommended that you use the new -FindOpenSceneGraph.cmake introduced in CMake 2.6.3 and not use this -Find module directly. +.. note:: + It is highly recommended that you use the new + :module:`FindOpenSceneGraph` introduced in CMake 2.6.3 and not use this + Find module directly. -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osg This module defines +Locate osg This module defines: -OSG_FOUND - Was the Osg found? OSG_INCLUDE_DIR - Where to find the -headers OSG_LIBRARIES - The libraries to link against for the OSG (use -this) +``OSG_FOUND`` + Was the Osg found? +``OSG_INCLUDE_DIR`` + Where to find theheaders +``OSG_LIBRARIES`` + The libraries to link against for the OSG (use this) +``OSG_LIBRARY`` + The OSG library +``OSG_LIBRARY_DEBUG`` + The OSG debug library -OSG_LIBRARY - The OSG library OSG_LIBRARY_DEBUG - The OSG debug -library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgAnimation.cmake b/Modules/FindosgAnimation.cmake index 65e3016..e31987e 100644 --- a/Modules/FindosgAnimation.cmake +++ b/Modules/FindosgAnimation.cmake @@ -7,29 +7,35 @@ FindosgAnimation -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgAnimation This module defines +Locate osgAnimation This module defines: -OSGANIMATION_FOUND - Was osgAnimation found? OSGANIMATION_INCLUDE_DIR -- Where to find the headers OSGANIMATION_LIBRARIES - The libraries to -link against for the OSG (use this) +``OSGANIMATION_FOUND`` + Was osgAnimation found? +``OSGANIMATION_INCLUDE_DIR`` + Where to find the headers +``OSGANIMATION_LIBRARIES`` + The libraries to link against for the OSG (use this) +``OSGANIMATION_LIBRARY`` + The OSG library +``OSGANIMATION_LIBRARY_DEBUG`` + The OSG debug library -OSGANIMATION_LIBRARY - The OSG library OSGANIMATION_LIBRARY_DEBUG - -The OSG debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgDB.cmake b/Modules/FindosgDB.cmake index a28f650..9366d21 100644 --- a/Modules/FindosgDB.cmake +++ b/Modules/FindosgDB.cmake @@ -37,7 +37,9 @@ Locate osgDB This module defines: ``$OSGDIR`` is an environment variable that would correspond to:: - ./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. #]=======================================================================] diff --git a/Modules/FindosgFX.cmake b/Modules/FindosgFX.cmake index 438fab7..79362ef 100644 --- a/Modules/FindosgFX.cmake +++ b/Modules/FindosgFX.cmake @@ -7,28 +7,35 @@ FindosgFX -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgFX This module defines +Locate osgFX This module defines: -OSGFX_FOUND - Was osgFX found? OSGFX_INCLUDE_DIR - Where to find the -headers OSGFX_LIBRARIES - The libraries to link against for the osgFX -(use this) +``OSGFX_FOUND`` + Was osgFX found? +``OSGFX_INCLUDE_DIR`` + Where to find the headers +``OSGFX_LIBRARIES`` + The libraries to link against for the osgFX (use this) +``OSGFX_LIBRARY`` + The osgFX library +``OSGFX_LIBRARY_DEBUG`` + The osgFX debug library -OSGFX_LIBRARY - The osgFX library OSGFX_LIBRARY_DEBUG - The osgFX -debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgGA.cmake b/Modules/FindosgGA.cmake index 7b6ef30..7ebcce8 100644 --- a/Modules/FindosgGA.cmake +++ b/Modules/FindosgGA.cmake @@ -7,28 +7,35 @@ FindosgGA -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgGA This module defines +Locate osgGA This module defines: -OSGGA_FOUND - Was osgGA found? OSGGA_INCLUDE_DIR - Where to find the -headers OSGGA_LIBRARIES - The libraries to link against for the osgGA -(use this) +``OSGGA_FOUND`` + Was osgGA found? +``OSGGA_INCLUDE_DIR`` + Where to find the headers +``OSGGA_LIBRARIES`` + The libraries to link against for the osgGA (use this) +``OSGGA_LIBRARY`` + The osgGA library +``OSGGA_LIBRARY_DEBUG`` + The osgGA debug library -OSGGA_LIBRARY - The osgGA library OSGGA_LIBRARY_DEBUG - The osgGA -debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgIntrospection.cmake b/Modules/FindosgIntrospection.cmake index 625e4c2..c0c28f2 100644 --- a/Modules/FindosgIntrospection.cmake +++ b/Modules/FindosgIntrospection.cmake @@ -7,29 +7,35 @@ FindosgIntrospection -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgINTROSPECTION This module defines +Locate osgINTROSPECTION This module defines: -OSGINTROSPECTION_FOUND - Was osgIntrospection found? -OSGINTROSPECTION_INCLUDE_DIR - Where to find the headers -OSGINTROSPECTION_LIBRARIES - The libraries to link for -osgIntrospection (use this) +``OSGINTROSPECTION_FOUND`` + Was osgIntrospection found? +``OSGINTROSPECTION_INCLUDE_DIR`` + Where to find the headers +``OSGINTROSPECTION_LIBRARIES`` + The libraries to link for osgIntrospection (use this) +``OSGINTROSPECTION_LIBRARY`` + The osgIntrospection library +``OSGINTROSPECTION_LIBRARY_DEBUG`` + The osgIntrospection debug library -OSGINTROSPECTION_LIBRARY - The osgIntrospection library -OSGINTROSPECTION_LIBRARY_DEBUG - The osgIntrospection debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgManipulator.cmake b/Modules/FindosgManipulator.cmake index 857ff5d..47c74f6 100644 --- a/Modules/FindosgManipulator.cmake +++ b/Modules/FindosgManipulator.cmake @@ -7,29 +7,35 @@ FindosgManipulator -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgManipulator This module defines +Locate osgManipulator This module defines: -OSGMANIPULATOR_FOUND - Was osgManipulator found? -OSGMANIPULATOR_INCLUDE_DIR - Where to find the headers -OSGMANIPULATOR_LIBRARIES - The libraries to link for osgManipulator -(use this) +``OSGMANIPULATOR_FOUND`` + Was osgManipulator found? +``OSGMANIPULATOR_INCLUDE_DIR`` + Where to find the headers +``OSGMANIPULATOR_LIBRARIES`` + The libraries to link for osgManipulator (use this) +``OSGMANIPULATOR_LIBRARY`` + The osgManipulator library +``OSGMANIPULATOR_LIBRARY_DEBUG`` + The osgManipulator debug library -OSGMANIPULATOR_LIBRARY - The osgManipulator library -OSGMANIPULATOR_LIBRARY_DEBUG - The osgManipulator debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgParticle.cmake b/Modules/FindosgParticle.cmake index 91a30dc..cbe033d 100644 --- a/Modules/FindosgParticle.cmake +++ b/Modules/FindosgParticle.cmake @@ -7,28 +7,35 @@ FindosgParticle -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgParticle This module defines +Locate osgParticle This module defines: -OSGPARTICLE_FOUND - Was osgParticle found? OSGPARTICLE_INCLUDE_DIR - -Where to find the headers OSGPARTICLE_LIBRARIES - The libraries to -link for osgParticle (use this) +``OSGPARTICLE_FOUND`` + Was osgParticle found? +``OSGPARTICLE_INCLUDE_DIR`` + Where to find the headers +``OSGPARTICLE_LIBRARIES`` + The libraries to link for osgParticle (use this) +``OSGPARTICLE_LIBRARY`` + The osgParticle library +``OSGPARTICLE_LIBRARY_DEBUG`` + The osgParticle debug library -OSGPARTICLE_LIBRARY - The osgParticle library -OSGPARTICLE_LIBRARY_DEBUG - The osgParticle debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgPresentation.cmake b/Modules/FindosgPresentation.cmake index eae75d6..e8c8b4f 100644 --- a/Modules/FindosgPresentation.cmake +++ b/Modules/FindosgPresentation.cmake @@ -7,30 +7,35 @@ FindosgPresentation -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgPresentation This module defines +Locate osgPresentation This module defines: -OSGPRESENTATION_FOUND - Was osgPresentation found? -OSGPRESENTATION_INCLUDE_DIR - Where to find the headers -OSGPRESENTATION_LIBRARIES - The libraries to link for osgPresentation -(use this) +``OSGPRESENTATION_FOUND`` + Was osgPresentation found? +``OSGPRESENTATION_INCLUDE_DIR`` + Where to find the headers +``OSGPRESENTATION_LIBRARIES`` + The libraries to link for osgPresentation (use this) +``OSGPRESENTATION_LIBRARY`` + The osgPresentation library +``OSGPRESENTATION_LIBRARY_DEBUG`` + The osgPresentation debug library -OSGPRESENTATION_LIBRARY - The osgPresentation library -OSGPRESENTATION_LIBRARY_DEBUG - The osgPresentation debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR +used in building osg. Created by Eric Wing. Modified to work with osgPresentation by Robert Osfield, January 2012. #]=======================================================================] diff --git a/Modules/FindosgProducer.cmake b/Modules/FindosgProducer.cmake index 33b9f73..92f0d20 100644 --- a/Modules/FindosgProducer.cmake +++ b/Modules/FindosgProducer.cmake @@ -7,28 +7,35 @@ FindosgProducer -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgProducer This module defines +Locate osgProducer This module defines: -OSGPRODUCER_FOUND - Was osgProducer found? OSGPRODUCER_INCLUDE_DIR - -Where to find the headers OSGPRODUCER_LIBRARIES - The libraries to -link for osgProducer (use this) +``OSGPRODUCER_FOUND`` + Was osgProducer found? +``OSGPRODUCER_INCLUDE_DIR`` + Where to find the headers +``OSGPRODUCER_LIBRARIES`` + The libraries to link for osgProducer (use this) +``OSGPRODUCER_LIBRARY`` + The osgProducer library +``OSGPRODUCER_LIBRARY_DEBUG`` + The osgProducer debug library -OSGPRODUCER_LIBRARY - The osgProducer library -OSGPRODUCER_LIBRARY_DEBUG - The osgProducer debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgQt.cmake b/Modules/FindosgQt.cmake index cf35630..2ad7174 100644 --- a/Modules/FindosgQt.cmake +++ b/Modules/FindosgQt.cmake @@ -7,27 +7,35 @@ FindosgQt -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgQt This module defines +Locate osgQt This module defines: -OSGQT_FOUND - Was osgQt found? OSGQT_INCLUDE_DIR - Where to find the -headers OSGQT_LIBRARIES - The libraries to link for osgQt (use this) +``OSGQT_FOUND`` + Was osgQt found? +``OSGQT_INCLUDE_DIR`` + Where to find the headers +``OSGQT_LIBRARIES`` + The libraries to link for osgQt (use this) +``OSGQT_LIBRARY`` + The osgQt library +``OSGQT_LIBRARY_DEBUG`` + The osgQt debug library -OSGQT_LIBRARY - The osgQt library OSGQT_LIBRARY_DEBUG - The osgQt -debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. Modified to work with osgQt by Robert Osfield, January 2012. diff --git a/Modules/FindosgShadow.cmake b/Modules/FindosgShadow.cmake index 0049c4e..12eb9da 100644 --- a/Modules/FindosgShadow.cmake +++ b/Modules/FindosgShadow.cmake @@ -7,28 +7,35 @@ FindosgShadow -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgShadow This module defines +Locate osgShadow This module defines: -OSGSHADOW_FOUND - Was osgShadow found? OSGSHADOW_INCLUDE_DIR - Where -to find the headers OSGSHADOW_LIBRARIES - The libraries to link for -osgShadow (use this) +``OSGSHADOW_FOUND`` + Was osgShadow found? +``OSGSHADOW_INCLUDE_DIR`` + Where to find the headers +``OSGSHADOW_LIBRARIES`` + The libraries to link for osgShadow (use this) +``OSGSHADOW_LIBRARY`` + The osgShadow library +``OSGSHADOW_LIBRARY_DEBUG`` + The osgShadow debug library -OSGSHADOW_LIBRARY - The osgShadow library OSGSHADOW_LIBRARY_DEBUG - -The osgShadow debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgSim.cmake b/Modules/FindosgSim.cmake index 43ba542..37ef03c 100644 --- a/Modules/FindosgSim.cmake +++ b/Modules/FindosgSim.cmake @@ -7,28 +7,35 @@ FindosgSim -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgSim This module defines +Locate osgSim This module defines: -OSGSIM_FOUND - Was osgSim found? OSGSIM_INCLUDE_DIR - Where to find -the headers OSGSIM_LIBRARIES - The libraries to link for osgSim (use -this) +``OSGSIM_FOUND`` + Was osgSim found? +``OSGSIM_INCLUDE_DIR`` + Where to find the headers +``OSGSIM_LIBRARIES`` + The libraries to link for osgSim (use this) +``OSGSIM_LIBRARY`` + The osgSim library +``OSGSIM_LIBRARY_DEBUG`` + The osgSim debug library -OSGSIM_LIBRARY - The osgSim library OSGSIM_LIBRARY_DEBUG - The osgSim -debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgTerrain.cmake b/Modules/FindosgTerrain.cmake index c6f5b69..a2de4ea 100644 --- a/Modules/FindosgTerrain.cmake +++ b/Modules/FindosgTerrain.cmake @@ -7,28 +7,35 @@ FindosgTerrain -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgTerrain This module defines +Locate osgTerrain This module defines: -OSGTERRAIN_FOUND - Was osgTerrain found? OSGTERRAIN_INCLUDE_DIR - -Where to find the headers OSGTERRAIN_LIBRARIES - The libraries to link -for osgTerrain (use this) +``OSGTERRAIN_FOUND`` + Was osgTerrain found? +``OSGTERRAIN_INCLUDE_DIR`` + Where to find the headers +``OSGTERRAIN_LIBRARIES`` + The libraries to link for osgTerrain (use this) +``OSGTERRAIN_LIBRARY`` + The osgTerrain library +``OSGTERRAIN_LIBRARY_DEBUG`` + The osgTerrain debug library -OSGTERRAIN_LIBRARY - The osgTerrain library OSGTERRAIN_LIBRARY_DEBUG - -The osgTerrain debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgText.cmake b/Modules/FindosgText.cmake index fd3c232..7646ad0 100644 --- a/Modules/FindosgText.cmake +++ b/Modules/FindosgText.cmake @@ -7,28 +7,35 @@ FindosgText -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgText This module defines +Locate osgText This module defines: -OSGTEXT_FOUND - Was osgText found? OSGTEXT_INCLUDE_DIR - Where to find -the headers OSGTEXT_LIBRARIES - The libraries to link for osgText (use -this) +``OSGTEXT_FOUND`` + Was osgText found? +``OSGTEXT_INCLUDE_DIR`` + Where to find the headers +``OSGTEXT_LIBRARIES`` + The libraries to link for osgText (use this) +``OSGTEXT_LIBRARY`` + The osgText library +``OSGTEXT_LIBRARY_DEBUG`` + The osgText debug library -OSGTEXT_LIBRARY - The osgText library OSGTEXT_LIBRARY_DEBUG - The -osgText debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgUtil.cmake b/Modules/FindosgUtil.cmake index e84727a..a34fea0 100644 --- a/Modules/FindosgUtil.cmake +++ b/Modules/FindosgUtil.cmake @@ -7,28 +7,35 @@ FindosgUtil -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgUtil This module defines +Locate osgUtil This module defines: -OSGUTIL_FOUND - Was osgUtil found? OSGUTIL_INCLUDE_DIR - Where to find -the headers OSGUTIL_LIBRARIES - The libraries to link for osgUtil (use -this) +``OSGUTIL_FOUND`` + Was osgUtil found? +``OSGUTIL_INCLUDE_DIR`` + Where to find the headers +``OSGUTIL_LIBRARIES`` + The libraries to link for osgUtil (use this) +``OSGUTIL_LIBRARY`` + The osgUtil library +``OSGUTIL_LIBRARY_DEBUG`` + The osgUtil debug library -OSGUTIL_LIBRARY - The osgUtil library OSGUTIL_LIBRARY_DEBUG - The -osgUtil debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgViewer.cmake b/Modules/FindosgViewer.cmake index 2174357..c3834e8 100644 --- a/Modules/FindosgViewer.cmake +++ b/Modules/FindosgViewer.cmake @@ -7,28 +7,35 @@ FindosgViewer -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgViewer This module defines +Locate osgViewer This module defines: -OSGVIEWER_FOUND - Was osgViewer found? OSGVIEWER_INCLUDE_DIR - Where -to find the headers OSGVIEWER_LIBRARIES - The libraries to link for -osgViewer (use this) +``OSGVIEWER_FOUND`` + Was osgViewer found? +``OSGVIEWER_INCLUDE_DIR`` + Where to find the headers +``OSGVIEWER_LIBRARIES`` + The libraries to link for osgViewer (use this) +``OSGVIEWER_LIBRARY`` + The osgViewer library +``OSGVIEWER_LIBRARY_DEBUG`` + The osgViewer debug library -OSGVIEWER_LIBRARY - The osgViewer library OSGVIEWER_LIBRARY_DEBUG - -The osgViewer debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgVolume.cmake b/Modules/FindosgVolume.cmake index 35defef..58d9f7a 100644 --- a/Modules/FindosgVolume.cmake +++ b/Modules/FindosgVolume.cmake @@ -7,28 +7,35 @@ FindosgVolume -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgVolume This module defines +Locate osgVolume This module defines: -OSGVOLUME_FOUND - Was osgVolume found? OSGVOLUME_INCLUDE_DIR - Where -to find the headers OSGVOLUME_LIBRARIES - The libraries to link for -osgVolume (use this) +``OSGVOLUME_FOUND`` + Was osgVolume found? +``OSGVOLUME_INCLUDE_DIR`` + Where to find the headers +``OSGVOLUME_LIBRARIES`` + The libraries to link for osgVolume (use this) +``OSGVOLUME_LIBRARY`` + The osgVolume library +``OSGVOLUME_LIBRARY_DEBUG`` + The osgVolume debug library -OSGVOLUME_LIBRARY - The osgVolume library OSGVOLUME_LIBRARY_DEBUG - -The osgVolume debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. Created by Eric Wing. #]=======================================================================] diff --git a/Modules/FindosgWidget.cmake b/Modules/FindosgWidget.cmake index c7aae44..4049fad 100644 --- a/Modules/FindosgWidget.cmake +++ b/Modules/FindosgWidget.cmake @@ -7,28 +7,35 @@ FindosgWidget -This is part of the Findosg* suite used to find OpenSceneGraph +This is part of the ``Findosg*`` suite used to find OpenSceneGraph components. Each component is separate and you must opt in to each module. You must also opt into OpenGL and OpenThreads (and Producer if needed) as these modules won't do it for you. This is to allow you control over your own system piece by piece in case you need to opt out of certain components or change the Find behavior for a particular -module (perhaps because the default FindOpenGL.cmake module doesn't +module (perhaps because the default :module:`FindOpenGL` module doesn't work with your system as an example). If you want to use a more convenient module that includes everything, use the -FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +:module:`FindOpenSceneGraph` instead of the ``Findosg*.cmake`` modules. -Locate osgWidget This module defines +Locate osgWidget This module defines: -OSGWIDGET_FOUND - Was osgWidget found? OSGWIDGET_INCLUDE_DIR - Where -to find the headers OSGWIDGET_LIBRARIES - The libraries to link for -osgWidget (use this) +``OSGWIDGET_FOUND`` + Was osgWidget found? +``OSGWIDGET_INCLUDE_DIR`` + Where to find the headers +``OSGWIDGET_LIBRARIES`` + The libraries to link for osgWidget (use this) +``OSGWIDGET_LIBRARY`` + The osgWidget library +``OSGWIDGET_LIBRARY_DEBUG`` + The osgWidget debug library -OSGWIDGET_LIBRARY - The osgWidget library OSGWIDGET_LIBRARY_DEBUG - -The osgWidget debug library +``$OSGDIR`` is an environment variable that would correspond to:: -$OSGDIR is an environment variable that would correspond to the -./configure --prefix=$OSGDIR used in building osg. + ./configure --prefix=$OSGDIR + +used in building osg. FindosgWidget.cmake tweaked from Findosg* suite as created by Eric Wing. diff --git a/Modules/Findosg_functions.cmake b/Modules/Findosg_functions.cmake index 563b6bd..5226102 100644 --- a/Modules/Findosg_functions.cmake +++ b/Modules/Findosg_functions.cmake @@ -10,7 +10,7 @@ Findosg_functions This CMake file contains two macros to assist with searching for OSG -libraries and nodekits. Please see FindOpenSceneGraph.cmake for full +libraries and nodekits. Please see :module:`FindOpenSceneGraph` for full documentation. #]=======================================================================] diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake index cc76b35..78fa481 100644 --- a/Modules/FindwxWidgets.cmake +++ b/Modules/FindwxWidgets.cmake @@ -848,7 +848,8 @@ if(wxWidgets_FIND_STYLE STREQUAL "unix") DBG_MSG_V("wxWidgets required components : ${_cmp_req}") DBG_MSG_V("wxWidgets optional components : ${_cmp_opt}") if(DEFINED _cmp_opt) - string(REPLACE ";" "," _cmp_opt "--optional-libs ${_cmp_opt}") + string(REPLACE ";" "," _cmp_opt "${_cmp_opt}") + set(_cmp_opt "--optional-libs" ${_cmp_opt}) endif() string(REPLACE ";" "," _cmp_req "${_cmp_req}") execute_process( diff --git a/Modules/FindwxWindows.cmake b/Modules/FindwxWindows.cmake index 6e4be91..d1b25e1 100644 --- a/Modules/FindwxWindows.cmake +++ b/Modules/FindwxWindows.cmake @@ -635,14 +635,14 @@ else() # remember: always link shared to use systems GL etc. libs (no static # linking, just link *against* static .a libs) if(WXWINDOWS_USE_SHARED_LIBS) - set(WX_CONFIG_ARGS_LIBS "--libs") + set(WX_CONFIG_ARGS_LIBS --libs) else() - set(WX_CONFIG_ARGS_LIBS "--static --libs") + set(WX_CONFIG_ARGS_LIBS --static --libs) endif() # do we need additionial wx GL stuff like GLCanvas ? if(WXWINDOWS_USE_GL) - string(APPEND WX_CONFIG_ARGS_LIBS " --gl-libs" ) + list(APPEND WX_CONFIG_ARGS_LIBS --gl-libs) endif() ##message("DBG: WX_CONFIG_ARGS_LIBS=${WX_CONFIG_ARGS_LIBS}===") @@ -662,14 +662,15 @@ else() ##CMAKE_WXWINDOWS_CXX_FLAGS=${CMAKE_WXWINDOWS_CXX_FLAGS}===") # keep the back-quoted string for clarity - set(WXWINDOWS_LIBRARIES "`${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} ${WX_CONFIG_ARGS_LIBS}`") + string(REPLACE ";" " " _wx_config_args_libs "${WX_CONFIG_ARGS_LIBS}") + set(WXWINDOWS_LIBRARIES "`${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} ${_wx_config_args_libs}`") ##message("DBG2: for linking: ##WXWINDOWS_LIBRARIES=${WXWINDOWS_LIBRARIES}===") # evaluate wx-config output to separate linker flags and linkdirs for # rpath: - exec_program(${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} - ARGS ${WX_CONFIG_ARGS_LIBS} + execute_process(COMMAND ${CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE} + ${WX_CONFIG_ARGS_LIBS} OUTPUT_VARIABLE WX_CONFIG_LIBS ) ## extract linkdirs (-L) for rpath diff --git a/Modules/Internal/CMakeCUDAArchitecturesAll.cmake b/Modules/Internal/CMakeCUDAArchitecturesAll.cmake new file mode 100644 index 0000000..873400a --- /dev/null +++ b/Modules/Internal/CMakeCUDAArchitecturesAll.cmake @@ -0,0 +1,88 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# See supported GPUs on Wikipedia +# https://en.wikipedia.org/wiki/CUDA#GPUs_supported + +function(cmake_cuda_architectures_all lang lang_var_) + # Initial set based on CUDA 7.0. + set(CMAKE_CUDA_ARCHITECTURES_ALL 20 21 30 35 37 50 52 53) + set(CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 20 30 35 50) + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 8.0) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 60 61 62) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 60) + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 9.0) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA" + OR (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang" AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) + ) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 70 72) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 70) + endif() + + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 20 21) + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 20) + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 10.0) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA" + OR (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang" AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + ) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 75) + endif() + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.0) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA" + OR (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang" AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0) + ) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 80) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 80) + endif() + + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 30) + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 30) + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.1) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA" + OR (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang" AND CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0) + ) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 86) + endif() + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.4) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA") + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 87) + endif() + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.8) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA") + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 89 90) + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 90) + endif() + endif() + + if(${lang_var_}TOOLKIT_VERSION VERSION_GREATER_EQUAL 12.0) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA") + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL 35 37) + list(REMOVE_ITEM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR 35) + endif() + endif() + + # only generate jit code for the newest arch for all/all-major + list(POP_BACK CMAKE_CUDA_ARCHITECTURES_ALL _latest_arch) + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_ALL APPEND "-real") + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL ${_latest_arch}) + + list(POP_BACK CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR _latest_arch) + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR APPEND "-real") + list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR ${_latest_arch}) + + set(CMAKE_${lang}_ARCHITECTURES_ALL "${CMAKE_CUDA_ARCHITECTURES_ALL}" PARENT_SCOPE) + set(CMAKE_${lang}_ARCHITECTURES_ALL_MAJOR "${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}" PARENT_SCOPE) +endfunction() diff --git a/Modules/Internal/CMakeCUDAArchitecturesNative.cmake b/Modules/Internal/CMakeCUDAArchitecturesNative.cmake new file mode 100644 index 0000000..4185eda --- /dev/null +++ b/Modules/Internal/CMakeCUDAArchitecturesNative.cmake @@ -0,0 +1,49 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +function(cmake_cuda_architectures_native lang) + # Run the test binary to detect the native architectures. + execute_process(COMMAND "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin" + RESULT_VARIABLE archs_result + OUTPUT_VARIABLE archs_output + ERROR_VARIABLE archs_output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(archs_result EQUAL 0) + if("$ENV{CMAKE_CUDA_ARCHITECTURES_NATIVE_CLAMP}") + # Undocumented hook used by CMake's CI. + # Clamp native architecture to version range supported by this CUDA. + list(GET CMAKE_${lang}_ARCHITECTURES_ALL 0 arch_min) + list(GET CMAKE_${lang}_ARCHITECTURES_ALL -1 arch_max) + set(CMAKE_CUDA_ARCHITECTURES_NATIVE "") + foreach(arch IN LISTS archs_output) + if(arch LESS arch_min) + set(arch "${arch_min}") + endif() + if(arch GREATER arch_max) + set(arch "${arch_max}") + endif() + list(APPEND CMAKE_CUDA_ARCHITECTURES_NATIVE ${arch}) + endforeach() + unset(arch) + unset(arch_min) + unset(arch_max) + else() + set(CMAKE_CUDA_ARCHITECTURES_NATIVE "${archs_output}") + endif() + list(REMOVE_DUPLICATES CMAKE_CUDA_ARCHITECTURES_NATIVE) + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_NATIVE APPEND "-real") + else() + if(NOT archs_result MATCHES "[0-9]+") + set(archs_status " (${archs_result})") + else() + set(archs_status "") + endif() + string(REPLACE "\n" "\n " archs_output " ${archs_output}") + message(CONFIGURE_LOG + "Detecting the CUDA native architecture(s) failed with " + "the following output${archs_status}:\n${archs_output}\n\n") + endif() + + set(CMAKE_${lang}_ARCHITECTURES_NATIVE "${CMAKE_CUDA_ARCHITECTURES_NATIVE}" PARENT_SCOPE) +endfunction() diff --git a/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake b/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake new file mode 100644 index 0000000..b6997d2 --- /dev/null +++ b/Modules/Internal/CMakeCUDAArchitecturesValidate.cmake @@ -0,0 +1,19 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +function(cmake_cuda_architectures_validate lang) + if(DEFINED CMAKE_${lang}_ARCHITECTURES) + if(CMAKE_${lang}_ARCHITECTURES STREQUAL "") + message(FATAL_ERROR "CMAKE_${lang}_ARCHITECTURES must be non-empty if set.") + elseif(CMAKE_${lang}_ARCHITECTURES AND NOT CMAKE_${lang}_ARCHITECTURES MATCHES "^([0-9]+a?(-real|-virtual)?(;[0-9]+a?(-real|-virtual)?|;)*|all|all-major|native)$") + message(FATAL_ERROR + "CMAKE_${lang}_ARCHITECTURES:\n" + " ${CMAKE_${lang}_ARCHITECTURES}\n" + "is not one of the following:\n" + " * a semicolon-separated list of integers, each optionally\n" + " followed by '-real' or '-virtual'\n" + " * a special value: all, all-major, native\n" + ) + endif() + endif() +endfunction() diff --git a/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake b/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake new file mode 100644 index 0000000..60287af --- /dev/null +++ b/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake @@ -0,0 +1,20 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# In CMakeDetermineCUDACompiler and CMakeTestCUDACompiler we detect +# libraries that the CUDA compiler implicitly passes to the host linker. +# CMake invokes the host linker directly and so needs to pass these libraries. +# Filter out implicit link libraries that should not be passed unconditionally. +macro(cmake_cuda_filter_implicit_libs _var_CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES) + list(REMOVE_ITEM "${_var_CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES}" + # The CUDA runtime libraries are controlled by CMAKE_CUDA_RUNTIME_LIBRARY. + cudart cudart.lib + cudart_static cudart_static.lib + cudadevrt cudadevrt.lib + + # Dependencies of the CUDA static runtime library on Linux hosts. + rt + pthread + dl + ) +endmacro() diff --git a/Modules/Internal/CMakeCUDAFindToolkit.cmake b/Modules/Internal/CMakeCUDAFindToolkit.cmake new file mode 100644 index 0000000..58d1e55 --- /dev/null +++ b/Modules/Internal/CMakeCUDAFindToolkit.cmake @@ -0,0 +1,173 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +macro(cmake_cuda_find_toolkit lang lang_var_) + # This is very similar to FindCUDAToolkit, but somewhat simplified since we can issue fatal errors + # if we fail and we don't need to account for searching the libraries. + + # For NVCC we can easily deduce the SDK binary directory from the compiler path. + if(CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA") + set(_CUDA_NVCC_EXECUTABLE "${CMAKE_${lang}_COMPILER}") + else() + # Search using CUDAToolkit_ROOT and then CUDA_PATH for equivalence with FindCUDAToolkit. + # In FindCUDAToolkit CUDAToolkit_ROOT is searched automatically due to being in a find_package(). + # First we search candidate non-default paths to give them priority. + find_program(_CUDA_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ${CUDAToolkit_ROOT} + ENV CUDAToolkit_ROOT + ENV CUDA_PATH + PATH_SUFFIXES bin + NO_DEFAULT_PATH + NO_CACHE + ) + + # If we didn't find NVCC, then try the default paths. + find_program(_CUDA_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATH_SUFFIXES bin + NO_CACHE + ) + + # If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error. + if(NOT _CUDA_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) + set(fail_base "Could not find nvcc executable in path specified by") + + if(DEFINED CUDAToolkit_ROOT) + message(FATAL_ERROR "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}") + elseif(DEFINED ENV{CUDAToolkit_ROOT}) + message(FATAL_ERROR "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}") + endif() + endif() + + # CUDAToolkit_ROOT cmake/env variable not specified, try platform defaults. + # + # - Linux: /usr/local/cuda-X.Y + # - macOS: /Developer/NVIDIA/CUDA-X.Y + # - Windows: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y + # + # 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 _CUDA_NVCC_EXECUTABLE) + if(UNIX) + if(NOT APPLE) + set(platform_base "/usr/local/cuda-") + else() + set(platform_base "/Developer/NVIDIA/CUDA-") + endif() + else() + set(platform_base "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v") + endif() + + # Build out a descending list of possible cuda installations, e.g. + file(GLOB possible_paths "${platform_base}*") + # Iterate the glob results and create a descending list. + set(versions) + foreach(p ${possible_paths}) + # Extract version number from end of string + string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p}) + if(IS_DIRECTORY ${p} AND p_version) + list(APPEND versions ${p_version}) + endif() + endforeach() + + # Sort numerically in descending order, so we try the newest versions first. + list(SORT versions COMPARE NATURAL ORDER DESCENDING) + + # With a descending list of versions, populate possible paths to search. + set(search_paths) + foreach(v ${versions}) + list(APPEND search_paths "${platform_base}${v}") + endforeach() + + # Force the global default /usr/local/cuda to the front on Unix. + if(UNIX) + list(INSERT search_paths 0 "/usr/local/cuda") + endif() + + # Now search for nvcc again using the platform default search paths. + find_program(_CUDA_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ${search_paths} + PATH_SUFFIXES bin + NO_CACHE + ) + + # We are done with these variables now, cleanup. + unset(platform_base) + unset(possible_paths) + unset(versions) + unset(search_paths) + + if(NOT _CUDA_NVCC_EXECUTABLE) + message(FATAL_ERROR "Failed to find nvcc.\nCompiler ${CMAKE_${lang}_COMPILER_ID} requires the CUDA toolkit. Please set the CUDAToolkit_ROOT variable.") + endif() + endif() + endif() + + # Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) + # each of which has a different layout, we need to extract the CUDA toolkit root from the compiler + # itself, allowing us to support numerous different scattered toolkit layouts + execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" + OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) + if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)") + get_filename_component(${lang_var_}TOOLKIT_ROOT "${CMAKE_MATCH_1}" ABSOLUTE) + else() + get_filename_component(${lang_var_}TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) + get_filename_component(${lang_var_}TOOLKIT_ROOT "${${lang_var_}TOOLKIT_ROOT}" DIRECTORY) + endif() + + if(_CUDA_NVCC_OUT MATCHES "\\#\\$ NVVMIR_LIBRARY_DIR=([^\r\n]*)") + get_filename_component(_CUDA_NVVMIR_LIBRARY_DIR "${CMAKE_MATCH_1}" ABSOLUTE) + + #We require the path to end in `/nvvm/libdevice' + if(_CUDA_NVVMIR_LIBRARY_DIR MATCHES "nvvm/libdevice$") + get_filename_component(_CUDA_NVVMIR_LIBRARY_DIR "${_CUDA_NVVMIR_LIBRARY_DIR}/../.." ABSOLUTE) + set(_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR "${_CUDA_NVVMIR_LIBRARY_DIR}") + endif() + + unset(_CUDA_NVVMIR_LIBRARY_DIR) + unset(_cuda_nvvmir_dir_name) + endif() + unset(_CUDA_NVCC_OUT) + + # In a non-scattered installation the following are equivalent to ${lang_var_}TOOLKIT_ROOT. + # We first check for a non-scattered installation to prefer it over a scattered installation. + + # ${lang_var_}LIBRARY_ROOT contains the device library. + if(DEFINED _CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR) + set(${lang_var_}LIBRARY_ROOT "${_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR}") + elseif(EXISTS "${${lang_var_}TOOLKIT_ROOT}/nvvm/libdevice") + set(${lang_var_}LIBRARY_ROOT "${${lang_var_}TOOLKIT_ROOT}") + elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/nvvm/libdevice") + set(${lang_var_}LIBRARY_ROOT "${CMAKE_SYSROOT_LINK}/usr/lib/cuda") + elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/nvvm/libdevice") + set(${lang_var_}LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/cuda") + else() + message(FATAL_ERROR "Couldn't find CUDA library root.") + endif() + unset(_CUDA_COMPILER_LIBRARY_ROOT_FROM_NVVMIR_LIBRARY_DIR) + + # ${lang_var_}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(${lang_var_}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(${lang_var_}TOOLKIT_LIBRARY_ROOT "${CMAKE_SYSROOT}/usr/lib/nvidia-cuda-toolkit") + else() + set(${lang_var_}TOOLKIT_LIBRARY_ROOT "${${lang_var_}TOOLKIT_ROOT}") + endif() + + # For regular nvcc we the toolkit version is the same as the compiler version and we can parse it from the vendor test output. + # For Clang we need to invoke nvcc to get version output. + if(CMAKE_${lang}_COMPILER_ID STREQUAL "Clang") + execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT) + endif() + + if(CMAKE_${lang}_COMPILER_ID_OUTPUT MATCHES [=[V([0-9]+\.[0-9]+\.[0-9]+)]=]) + set(${lang_var_}TOOLKIT_VERSION "${CMAKE_MATCH_1}") + endif() + + # Don't leak variables unnecessarily to user code. + unset(_CUDA_NVCC_EXECUTABLE) +endmacro() diff --git a/Modules/Internal/CMakeNVCCFilterImplicitInfo.cmake b/Modules/Internal/CMakeNVCCFilterImplicitInfo.cmake new file mode 100644 index 0000000..dee7580 --- /dev/null +++ b/Modules/Internal/CMakeNVCCFilterImplicitInfo.cmake @@ -0,0 +1,16 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +macro(cmake_nvcc_filter_implicit_info lang lang_var_) + # Remove the CUDA Toolkit include directories from the set of + # implicit system include directories. + # This resolves the issue that NVCC doesn't specify these + # includes as SYSTEM includes when compiling device code, and sometimes + # they contain headers that generate warnings, so let users mark them + # as SYSTEM explicitly + if(${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES) + list(REMOVE_ITEM CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES + ${${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES} + ) + endif() +endmacro() diff --git a/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake b/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake new file mode 100644 index 0000000..3aa10a2 --- /dev/null +++ b/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake @@ -0,0 +1,152 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +macro(cmake_nvcc_parse_implicit_info lang lang_var_) + set(_nvcc_log "") + string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_${lang}_COMPILER_PRODUCED_OUTPUT}") + if(_nvcc_output_orig MATCHES "#\\\$ +PATH= *([^\n]*)\n") + set(_nvcc_path "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " found 'PATH=' string: [${_nvcc_path}]\n") + string(REPLACE ":" ";" _nvcc_path "${_nvcc_path}") + else() + set(_nvcc_path "") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") + string(APPEND _nvcc_log " no 'PATH=' string found in nvcc output:${_nvcc_output_log}\n") + endif() + if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n") + set(_nvcc_libraries "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " found 'LIBRARIES=' string: [${_nvcc_libraries}]\n") + else() + set(_nvcc_libraries "") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") + string(APPEND _nvcc_log " no 'LIBRARIES=' string found in nvcc output:${_nvcc_output_log}\n") + endif() + if(_nvcc_output_orig MATCHES "#\\\$ +INCLUDES= *([^\n]*)\n") + set(_nvcc_includes "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " found 'INCLUDES=' string: [${_nvcc_includes}]\n") + else() + set(_nvcc_includes "") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") + string(APPEND _nvcc_log " no 'INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n") + endif() + string(REGEX MATCHALL "-arch compute_([0-9]+)" _nvcc_target_cpus "${_nvcc_output_orig}") + foreach(_nvcc_target_cpu ${_nvcc_target_cpus}) + if(_nvcc_target_cpu MATCHES "-arch compute_([0-9]+)") + list(APPEND CMAKE_${lang}_ARCHITECTURES_DEFAULT "${CMAKE_MATCH_1}") + endif() + endforeach() + + set(_nvcc_link_line "") + if(_nvcc_libraries) + # Remove variable assignments. + string(REGEX REPLACE "#\\\$ *[^= ]+=[^\n]*\n" "" _nvcc_output "${_nvcc_output_orig}") + # Encode [] characters that break list expansion. + string(REPLACE "[" "{==={" _nvcc_output "${_nvcc_output}") + string(REPLACE "]" "}===}" _nvcc_output "${_nvcc_output}") + # Split lines. + string(REGEX REPLACE "\n+(#\\\$ )?" ";" _nvcc_output "${_nvcc_output}") + foreach(line IN LISTS _nvcc_output) + set(_nvcc_output_line "${line}") + string(REPLACE "{==={" "[" _nvcc_output_line "${_nvcc_output_line}") + string(REPLACE "}===}" "]" _nvcc_output_line "${_nvcc_output_line}") + string(APPEND _nvcc_log " considering line: [${_nvcc_output_line}]\n") + if("${_nvcc_output_line}" MATCHES "^ *nvlink") + string(APPEND _nvcc_log " ignoring nvlink line\n") + elseif("${_nvcc_output_line}" MATCHES "(link\\.exe .*CompilerId${lang}\\.exe.*)$") + set(_nvcc_link_line "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " extracted link line: [${_nvcc_link_line}]\n") + elseif(_nvcc_libraries) + if("${_nvcc_output_line}" MATCHES "(@\"?((tmp/)?a\\.exe\\.res)\"?)") + set(_nvcc_link_res_arg "${CMAKE_MATCH_1}") + set(_nvcc_link_res_file "${CMAKE_MATCH_2}") + set(_nvcc_link_res "${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang}/${_nvcc_link_res_file}") + if(EXISTS "${_nvcc_link_res}") + file(READ "${_nvcc_link_res}" _nvcc_link_res_content) + string(REPLACE "${_nvcc_link_res_arg}" "${_nvcc_link_res_content}" _nvcc_output_line "${_nvcc_output_line}") + endif() + endif() + string(FIND "${_nvcc_output_line}" "${_nvcc_libraries}" _nvcc_libraries_pos) + if(NOT _nvcc_libraries_pos EQUAL -1) + set(_nvcc_link_line "${_nvcc_output_line}") + string(APPEND _nvcc_log " extracted link line: [${_nvcc_link_line}]\n") + endif() + endif() + endforeach() + endif() + + if(_nvcc_link_line) + if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_${lang}_HOST_LINK_LAUNCHER "${CMAKE_LINKER}") + else() + #extract the compiler that is being used for linking + separate_arguments(_nvcc_link_line_args UNIX_COMMAND "${_nvcc_link_line}") + list(GET _nvcc_link_line_args 0 _nvcc_host_link_launcher) + if(IS_ABSOLUTE "${_nvcc_host_link_launcher}") + string(APPEND _nvcc_log " extracted link launcher absolute path: [${_nvcc_host_link_launcher}]\n") + set(CMAKE_${lang}_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}") + else() + string(APPEND _nvcc_log " extracted link launcher name: [${_nvcc_host_link_launcher}]\n") + find_program(_nvcc_find_host_link_launcher + NAMES ${_nvcc_host_link_launcher} + PATHS ${_nvcc_path} NO_DEFAULT_PATH) + find_program(_nvcc_find_host_link_launcher + NAMES ${_nvcc_host_link_launcher}) + if(_nvcc_find_host_link_launcher) + string(APPEND _nvcc_log " found link launcher absolute path: [${_nvcc_find_host_link_launcher}]\n") + set(CMAKE_${lang}_HOST_LINK_LAUNCHER "${_nvcc_find_host_link_launcher}") + else() + string(APPEND _nvcc_log " could not find link launcher absolute path\n") + set(CMAKE_${lang}_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}") + endif() + unset(_nvcc_find_host_link_launcher CACHE) + endif() + endif() + + #prefix the line with cuda-fake-ld so that implicit link info believes it is + #a link line + set(_nvcc_link_line "cuda-fake-ld ${_nvcc_link_line}") + CMAKE_PARSE_IMPLICIT_LINK_INFO("${_nvcc_link_line}" + CMAKE_${lang}_HOST_IMPLICIT_LINK_LIBRARIES + CMAKE_${lang}_HOST_IMPLICIT_LINK_DIRECTORIES + CMAKE_${lang}_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES + log + "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}" + LANGUAGE ${lang}) + + # Detect CMAKE_${lang}_RUNTIME_LIBRARY_DEFAULT from the compiler by looking at which + # cudart library exists in the implicit link libraries passed to the host linker. + # This is required when a project sets the cuda runtime library as part of the + # initial flags. + if(";${CMAKE_${lang}_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart_static(\.lib)?;]]) + set(CMAKE_${lang}_RUNTIME_LIBRARY_DEFAULT "STATIC") + elseif(";${CMAKE_${lang}_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart(\.lib)?;]]) + set(CMAKE_${lang}_RUNTIME_LIBRARY_DEFAULT "SHARED") + else() + set(CMAKE_${lang}_RUNTIME_LIBRARY_DEFAULT "NONE") + endif() + + message(CONFIGURE_LOG + "Parsed ${lang} nvcc implicit link information:\n${_nvcc_log}\n${log}\n\n") + else() + message(CONFIGURE_LOG + "Failed to parse ${lang} nvcc implicit link information:\n${_nvcc_log}\n\n") + message(FATAL_ERROR "Failed to extract nvcc implicit link line.") + endif() + + set(${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES) + if(_nvcc_includes) + # across all operating system each include directory is prefixed with -I + separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_includes}") + foreach(line IN LISTS _nvcc_output) + string(REGEX REPLACE "^-I" "" line "${line}") + get_filename_component(line "${line}" ABSOLUTE) + list(APPEND ${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES "${line}") + endforeach() + + message(CONFIGURE_LOG + "Parsed CUDA nvcc include information:\n${_nvcc_log}\n${log}\n\n") + else() + message(CONFIGURE_LOG + "Failed to detect CUDA nvcc include information:\n${_nvcc_log}\n\n") + endif() +endmacro() diff --git a/Modules/Internal/CPack/CPackFreeBSD.cmake b/Modules/Internal/CPack/CPackFreeBSD.cmake index c35089c..46a7bf7 100644 --- a/Modules/Internal/CPack/CPackFreeBSD.cmake +++ b/Modules/Internal/CPack/CPackFreeBSD.cmake @@ -66,7 +66,7 @@ _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION" ) # There's really only one homepage for a project, so -# re-use the Debian setting if it's there. +# reuse the Debian setting if it's there. _cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_WWW" "CPACK_PACKAGE_HOMEPAGE_URL" "CPACK_DEBIAN_PACKAGE_HOMEPAGE" diff --git a/Modules/Internal/CPack/NSIS.template.in b/Modules/Internal/CPack/NSIS.template.in index 21753af..6349f9d 100644 --- a/Modules/Internal/CPack/NSIS.template.in +++ b/Modules/Internal/CPack/NSIS.template.in @@ -981,7 +981,7 @@ inst: ;MessageBox MB_OK 'User "$0" is in the Admin group' StrCpy $SV_ALLUSERS "AllUsers" Goto done - StrCmp $1 "Power" 0 +4 + StrCmp $1 "Power" 0 +3 SetShellVarContext all ;MessageBox MB_OK 'User "$0" is in the Power Users group' StrCpy $SV_ALLUSERS "AllUsers" diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake index 1a8a27e..c2bd14f 100644 --- a/Modules/Internal/FeatureTesting.cmake +++ b/Modules/Internal/FeatureTesting.cmake @@ -37,6 +37,7 @@ macro(_record_compiler_features lang compile_flags feature_list) LINK_LIBRARIES "${compile_flags_for_link}" COPY_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin" COPY_FILE_ERROR _copy_error + __CMAKE_INTERNAL FEATURE_TESTING ) if(NOT CMAKE_${lang}_FEATURE_TEST) set(_result 255) diff --git a/Modules/Platform/Apple-Clang.cmake b/Modules/Platform/Apple-Clang.cmake index 0681bfb..57b3910 100644 --- a/Modules/Platform/Apple-Clang.cmake +++ b/Modules/Platform/Apple-Clang.cmake @@ -14,6 +14,10 @@ macro(__apple_compiler_clang lang) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.2) set(CMAKE_${lang}_SYSTEM_FRAMEWORK_SEARCH_FLAG "-iframework ") endif() + + set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK "-framework <LIBRARY>") + set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK_SUPPORTED TRUE) + if(_CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhoneOS") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-miphoneos-version-min=") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhoneSimulator") @@ -22,6 +26,10 @@ macro(__apple_compiler_clang lang) set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtvos-version-min=") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/AppleTVSimulator") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtvos-simulator-version-min=") + elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XROS") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros") + elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XRSimulator") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/WatchOS") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mwatchos-version-min=") elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/WatchSimulator") diff --git a/Modules/Platform/Apple-GNU.cmake b/Modules/Platform/Apple-GNU.cmake index 9572736..823c790 100644 --- a/Modules/Platform/Apple-GNU.cmake +++ b/Modules/Platform/Apple-GNU.cmake @@ -14,6 +14,9 @@ macro(__apple_compiler_gnu lang) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.3) set(CMAKE_${lang}_SYSTEM_FRAMEWORK_SEARCH_FLAG "-iframework ") endif() + + set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK "-framework <LIBRARY>") + set(CMAKE_${lang}_LINK_LIBRARY_USING_FRAMEWORK_SUPPORTED TRUE) endmacro() macro(cmake_gnu_set_sysroot_flag lang) diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake index e253392..8d5bf8c 100644 --- a/Modules/Platform/Darwin-Initialize.cmake +++ b/Modules/Platform/Darwin-Initialize.cmake @@ -43,7 +43,7 @@ if(NOT CMAKE_CROSSCOMPILING AND unset(_sysctl_stdout) endif() -# macOS, iOS, tvOS, and watchOS should lookup compilers from +# macOS, iOS, tvOS, visionOS, and watchOS should lookup compilers from # Platform/Apple-${CMAKE_CXX_COMPILER_ID}-<LANG> set(CMAKE_EFFECTIVE_SYSTEM_NAME "Apple") @@ -76,6 +76,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) set(_CMAKE_OSX_SYSROOT_DEFAULT "iphoneos") elseif(CMAKE_SYSTEM_NAME STREQUAL tvOS) set(_CMAKE_OSX_SYSROOT_DEFAULT "appletvos") +elseif(CMAKE_SYSTEM_NAME STREQUAL visionOS) + set(_CMAKE_OSX_SYSROOT_DEFAULT "xros") elseif(CMAKE_SYSTEM_NAME STREQUAL watchOS) set(_CMAKE_OSX_SYSROOT_DEFAULT "watchos") elseif("${CMAKE_GENERATOR}" MATCHES Xcode diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 48a9065..d614182 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -1,4 +1,4 @@ -if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "visionOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") if(NOT DEFINED CMAKE_MACOSX_BUNDLE) set(CMAKE_MACOSX_BUNDLE ON) endif() diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake index 088b238..412af6b 100644 --- a/Modules/Platform/Windows-GNU.cmake +++ b/Modules/Platform/Windows-GNU.cmake @@ -10,6 +10,25 @@ set(__WINDOWS_GNU 1) set(MINGW 1) +# On Windows hosts, in MSYSTEM environments, search standard prefixes. +if(CMAKE_HOST_WIN32) + # Bootstrap CMake does not have cmake_host_system_information. + if(COMMAND cmake_host_system_information) + cmake_host_system_information(RESULT _MSYSTEM_PREFIX QUERY MSYSTEM_PREFIX) + elseif(IS_DIRECTORY "$ENV{MSYSTEM_PREFIX}") + set(_MSYSTEM_PREFIX "$ENV{MSYSTEM_PREFIX}") + endif() + + # Search this MSYSTEM environment's equivalent to /usr/local and /usr. + if(_MSYSTEM_PREFIX) + list(PREPEND CMAKE_SYSTEM_PREFIX_PATH "${_MSYSTEM_PREFIX}") + if(IS_DIRECTORY "${_MSYSTEM_PREFIX}/local") + list(PREPEND CMAKE_SYSTEM_PREFIX_PATH "${_MSYSTEM_PREFIX}/local") + endif() + endif() + unset(_MSYSTEM_PREFIX) +endif() + set(CMAKE_IMPORT_LIBRARY_PREFIX "lib") set(CMAKE_SHARED_LIBRARY_PREFIX "lib") set(CMAKE_SHARED_MODULE_PREFIX "lib") diff --git a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake index 64dc0da..3e22a6e 100644 --- a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake +++ b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake @@ -1,3 +1,58 @@ -include(Platform/Windows-GNU) -__windows_compiler_gnu(Fortran) -# TODO: MSVC ABI Support +if("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xGNU") + include(Platform/Windows-GNU) + __windows_compiler_gnu(Fortran) +elseif("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC") + include(Platform/Windows-MSVC) + __windows_compiler_msvc(Fortran) + + # FIXME(LLVMFlang): It does not provides MSVC runtime library selection flags. + # It should be given a flag like classic Flang's `-Xclang --dependent-lib=`, or a + # dedicated flag to select among multiple `Fortran*.lib` runtime library variants + # that each depend on a different MSVC runtime library. For now, LLVMFlang's + # `Fortran*.lib` runtime libraries hard-code use of msvcrt (MultiThreadedDLL), + # so we link to it ourselves. + set(_LLVMFlang_LINK_RUNTIME "-defaultlib:msvcrt") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") + + # FIXME(LLVMFlang): It does not provide all debug information format flags or predefines. + # It should be given a flag to enable Embedded debug information like MSVC -Z7. + #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded) # not supported by LLVMFlang + #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_EditAndContinue) # not supported by LLVMFlang + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_ProgramDatabase "-g") + + set(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") + + if(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT) + set(_g "") + else() + set(_g " -g") + endif() + string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT "${_g}") + string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT "") + string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "${_g}") + string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "") + unset(_g) + + # We link with lld-link.exe instead of the compiler driver, so explicitly + # pass implicit link information previously detected from the compiler. + set(_LLVMFlang_LINK_DIRS "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}") + list(TRANSFORM _LLVMFlang_LINK_DIRS PREPEND "-libpath:\"") + list(TRANSFORM _LLVMFlang_LINK_DIRS APPEND "\"") + string(JOIN " " _LLVMFlang_LINK_DIRS ${_LLVMFlang_LINK_DIRS}) + string(JOIN " " _LLVMFlang_LINK_LIBS ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) + foreach(v IN ITEMS + CMAKE_Fortran_LINK_EXECUTABLE + CMAKE_Fortran_CREATE_SHARED_LIBRARY + CMAKE_Fortran_CREATE_SHARED_MODULE + ) + string(APPEND "${v}" " ${_LLVMFlang_LINK_DIRS} ${_LLVMFlang_LINK_LIBS} ${_LLVMFlang_LINK_RUNTIME}") + endforeach() + unset(_LLVMFlang_LINK_DIRS) + unset(_LLVMFlang_LINK_LIBS) + unset(_LLVMFlang_LINK_RUNTIME) +else() + message(FATAL_ERROR "LLVMFlang target ABI unrecognized: ${CMAKE_Fortran_SIMULATE_ID}") +endif() diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 8e96bf4..829ab9b 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -28,6 +28,8 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL "WindowsCE") set(_PLATFORM_LINK_FLAGS " /subsystem:windowsce") +elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(_PLATFORM_LINK_FLAGS " -subsystem:native -kernel -MANIFEST:NO") else() set(_PLATFORM_LINK_FLAGS "") endif() @@ -223,6 +225,18 @@ elseif(WINDOWS_PHONE OR WINDOWS_STORE) else() set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "") + set(_FLAGS_C " -kernel") + set(_FLAGS_CXX " -kernel") + foreach(t EXE SHARED MODULE) + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " -NODEFAULTLIB") + endforeach() + if((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "x64") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "x64")) + set(_PLATFORM_DEFINES "${_PLATFORM_DEFINES} -D_AMD64_ -DAMD64") + elseif((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64")) + set(_PLATFORM_DEFINES "${_PLATFORM_DEFINES} -D_ARM64_ -DARM64") + endif() else() set(_PLATFORM_DEFINES "/DWIN32") if((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64EC") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64EC")) @@ -294,7 +308,7 @@ endif() # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype # on versions that support it set( MSVC_INCREMENTAL_YES_FLAG "") -if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE) +if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") if(NOT MSVC_INCREMENTAL_DEFAULT) set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES") else() @@ -353,8 +367,14 @@ macro(__windows_compiler_msvc lang) set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ") set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ") endif() + if(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(_DLL_DRIVER "-driver") + else() + set(_DLL_DRIVER "/dll") + endif() set(CMAKE_${lang}_CREATE_SHARED_LIBRARY - "${_CMAKE_VS_LINK_DLL}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") + "${_CMAKE_VS_LINK_DLL}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> ${_DLL_DRIVER} /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") + unset(_DLL_DRIVER) set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY}) set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") diff --git a/Modules/Platform/Windows-OrangeC-C.cmake b/Modules/Platform/Windows-OrangeC-C.cmake new file mode 100644 index 0000000..6b7e6b5 --- /dev/null +++ b/Modules/Platform/Windows-OrangeC-C.cmake @@ -0,0 +1,2 @@ +include(Platform/Windows-OrangeC) +__windows_compiler_orangec(C) diff --git a/Modules/Platform/Windows-OrangeC-CXX.cmake b/Modules/Platform/Windows-OrangeC-CXX.cmake new file mode 100644 index 0000000..7de6716 --- /dev/null +++ b/Modules/Platform/Windows-OrangeC-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/Windows-OrangeC) +__windows_compiler_orangec(CXX) diff --git a/Modules/Platform/Windows-OrangeC.cmake b/Modules/Platform/Windows-OrangeC.cmake new file mode 100644 index 0000000..4f66e0e --- /dev/null +++ b/Modules/Platform/Windows-OrangeC.cmake @@ -0,0 +1,10 @@ +set(CMAKE_LINK_LIBRARY_SUFFIX "") +set(CMAKE_STATIC_LIBRARY_SUFFIX ".l") +set(CMAKE_IMPORT_LIBRARY_SUFFIX ".l") +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".l") + +macro(__windows_compiler_orangec lang) + set(CMAKE_${lang}_CREATE_WIN32_EXE "-Wg") + set(CMAKE_${lang}_CREATE_CONSOLE_EXE "-Wc") +endmacro() diff --git a/Modules/Platform/Windows.cmake b/Modules/Platform/Windows.cmake index 8697e7a..1bf39cf 100644 --- a/Modules/Platform/Windows.cmake +++ b/Modules/Platform/Windows.cmake @@ -1,7 +1,11 @@ set(CMAKE_STATIC_LIBRARY_PREFIX "") set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib -set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so +if(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(CMAKE_SHARED_LIBRARY_SUFFIX ".sys") # .so +else() + set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so +endif() set(CMAKE_IMPORT_LIBRARY_PREFIX "") set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") set(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe diff --git a/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake new file mode 100644 index 0000000..6f0ef33 --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake @@ -0,0 +1,11 @@ +# undocumented, do not use outside of CMake +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED "WindowsKernelModeDriver" _cmake_windows_kernel_mode_driver_enabled) +if(NOT _cmake_windows_kernel_mode_driver_enabled) + message(FATAL_ERROR "Windows kernel-mode driver experimental support is not enabled.") +endif() + +if(CMAKE_GENERATOR MATCHES "Visual Studio") + message(FATAL_ERROR "Visual Studio generators do not yet support CMAKE_SYSTEM_NAME=WindowsKernelModeDriver.") +endif() + +set(_CMAKE_FEATURE_DETECTION_TARGET_TYPE STATIC_LIBRARY) diff --git a/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake b/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake new file mode 100644 index 0000000..ce8060b --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-C) diff --git a/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake b/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake new file mode 100644 index 0000000..281eadc --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-CXX) diff --git a/Modules/Platform/WindowsKernelModeDriver.cmake b/Modules/Platform/WindowsKernelModeDriver.cmake new file mode 100644 index 0000000..65b2eae --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver.cmake @@ -0,0 +1 @@ +include(Platform/Windows) diff --git a/Modules/Platform/visionOS-Determine-CXX.cmake b/Modules/Platform/visionOS-Determine-CXX.cmake new file mode 100644 index 0000000..ac80fa6 --- /dev/null +++ b/Modules/Platform/visionOS-Determine-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Darwin-Determine-CXX) diff --git a/Modules/Platform/visionOS-Initialize.cmake b/Modules/Platform/visionOS-Initialize.cmake new file mode 100644 index 0000000..e8431bc --- /dev/null +++ b/Modules/Platform/visionOS-Initialize.cmake @@ -0,0 +1,7 @@ +include(Platform/Darwin-Initialize) + +if(NOT _CMAKE_OSX_SYSROOT_PATH MATCHES "/XR(OS|Simulator)") + message(FATAL_ERROR "${CMAKE_OSX_SYSROOT} is not an visionOS SDK") +endif() + +set(_CMAKE_FEATURE_DETECTION_TARGET_TYPE STATIC_LIBRARY) diff --git a/Modules/Platform/visionOS.cmake b/Modules/Platform/visionOS.cmake new file mode 100644 index 0000000..850ddc2 --- /dev/null +++ b/Modules/Platform/visionOS.cmake @@ -0,0 +1 @@ +include(Platform/Darwin) diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index 99fd617..1724c3a 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -1521,7 +1521,7 @@ function (create_javah) "CLASSES;CLASSPATH;DEPENDS" ${ARGN}) - # ckeck parameters + # check parameters if (NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES) message (FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified.") endif() diff --git a/Modules/UsePkgConfig.cmake b/Modules/UsePkgConfig.cmake index 32d228d..b020259 100644 --- a/Modules/UsePkgConfig.cmake +++ b/Modules/UsePkgConfig.cmake @@ -35,25 +35,25 @@ macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags) # if pkg-config has been found if(PKGCONFIG_EXECUTABLE) - exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull ) + execute_process(COMMAND ${PKGCONFIG_EXECUTABLE} ${_package} --exists RESULT_VARIABLE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull ) # and if the package of interest also exists for pkg-config, then get the information if(NOT _return_VALUE) - exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir + execute_process(COMMAND ${PKGCONFIG_EXECUTABLE} ${_package} --variable=includedir OUTPUT_VARIABLE ${_include_DIR} ) string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}") - exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir + execute_process(COMMAND ${PKGCONFIG_EXECUTABLE} ${_package} --variable=libdir OUTPUT_VARIABLE ${_link_DIR} ) string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}") - exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs + execute_process(COMMAND ${PKGCONFIG_EXECUTABLE} ${_package} --libs OUTPUT_VARIABLE ${_link_FLAGS} ) string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}") - exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags + execute_process(COMMAND ${PKGCONFIG_EXECUTABLE} ${_package} --cflags OUTPUT_VARIABLE ${_cflags} ) string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}") diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index ca16bc2..cece973 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -189,7 +189,7 @@ ensure generated files will receive the required settings. :ref:`Makefile <Makefile Generators>`, :ref:`Ninja <Ninja Generators>`, :generator:`Xcode`, and :ref:`Visual Studio <Visual Studio Generators>` - (:generator:`Visual Studio 11 2012` and above) generators. Default value is + (:generator:`Visual Studio 12 2013` and above) generators. Default value is ``FALSE``. .. versionadded:: 3.21 @@ -353,7 +353,7 @@ as well as ``SWIG``: :ref:`Makefile <Makefile Generators>`, :ref:`Ninja <Ninja Generators>`, :generator:`Xcode`, and :ref:`Visual Studio <Visual Studio Generators>` - (:generator:`Visual Studio 11 2012` and above) generators. Default value is + (:generator:`Visual Studio 12 2013` and above) generators. Default value is ``FALSE``. Source file property ``USE_SWIG_DEPENDENCIES``, if not defined, will be |