diff options
Diffstat (limited to 'Modules')
149 files changed, 5516 insertions, 2758 deletions
diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in index b8e09fe..3953b30 100644 --- a/Modules/CMakeASMCompiler.cmake.in +++ b/Modules/CMakeASMCompiler.cmake.in @@ -10,7 +10,9 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LOADED 1) set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ID "@_CMAKE_ASM_COMPILER_ID@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_VERSION "@_CMAKE_ASM_COMPILER_VERSION@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@") +@_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH@ @_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_ASM_COMPILER_SYSROOT@ set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0) diff --git a/Modules/CMakeASMInformation.cmake b/Modules/CMakeASMInformation.cmake index 6b73730..03195cc 100644 --- a/Modules/CMakeASMInformation.cmake +++ b/Modules/CMakeASMInformation.cmake @@ -76,12 +76,12 @@ endif() if(NOT CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY) set(CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> " - "<CMAKE_RANLIB> <TARGET> ") + "<CMAKE_RANLIB> <TARGET>") endif() if(NOT CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE) set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE - "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() if(NOT CMAKE_EXECUTABLE_RUNTIME_ASM${ASM_DIALECT}_FLAG) diff --git a/Modules/CMakeASM_MASMInformation.cmake b/Modules/CMakeASM_MASMInformation.cmake index 9f7e934..6d1e174 100644 --- a/Modules/CMakeASM_MASMInformation.cmake +++ b/Modules/CMakeASM_MASMInformation.cmake @@ -8,7 +8,7 @@ set(ASM_DIALECT "_MASM") set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS asm) -set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> /c /Fo <OBJECT> <SOURCE>") +set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> /c /Fo <OBJECT> <SOURCE>") # The ASM_MASM compiler id for this compiler is "MSVC", so fill out the runtime library table. set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") diff --git a/Modules/CMakeASM_NASMInformation.cmake b/Modules/CMakeASM_NASMInformation.cmake index cb793e7..97cb488 100644 --- a/Modules/CMakeASM_NASMInformation.cmake +++ b/Modules/CMakeASM_NASMInformation.cmake @@ -8,19 +8,25 @@ set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS nasm asm) if(NOT CMAKE_ASM_NASM_OBJECT_FORMAT) if(WIN32) - if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + if(DEFINED CMAKE_C_SIZEOF_DATA_PTR AND CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + set(CMAKE_ASM_NASM_OBJECT_FORMAT win64) + elseif(DEFINED CMAKE_CXX_SIZEOF_DATA_PTR AND CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) set(CMAKE_ASM_NASM_OBJECT_FORMAT win64) else() set(CMAKE_ASM_NASM_OBJECT_FORMAT win32) endif() elseif(APPLE) - if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + if(DEFINED CMAKE_C_SIZEOF_DATA_PTR AND CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + set(CMAKE_ASM_NASM_OBJECT_FORMAT macho64) + elseif(DEFINED CMAKE_CXX_SIZEOF_DATA_PTR AND CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) set(CMAKE_ASM_NASM_OBJECT_FORMAT macho64) else() set(CMAKE_ASM_NASM_OBJECT_FORMAT macho) endif() else() - if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + if(DEFINED CMAKE_C_SIZEOF_DATA_PTR AND CMAKE_C_SIZEOF_DATA_PTR EQUAL 8) + set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64) + elseif(DEFINED CMAKE_CXX_SIZEOF_DATA_PTR AND CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64) else() set(CMAKE_ASM_NASM_OBJECT_FORMAT elf) diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 9b8d423..eea3f5d 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -15,6 +15,7 @@ set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@") set(CMAKE_C_COMPILER_FRONTEND_VARIANT "@CMAKE_C_COMPILER_FRONTEND_VARIANT@") set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@") @_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_C_COMPILER_SYSROOT@ @SET_MSVC_C_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_ARCHS@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake index 1e08bb7..f6d620f 100644 --- a/Modules/CMakeCInformation.cmake +++ b/Modules/CMakeCInformation.cmake @@ -161,7 +161,7 @@ if(NOT DEFINED CMAKE_C_ARCHIVE_CREATE) set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_C_ARCHIVE_APPEND) - set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_C_ARCHIVE_FINISH) set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -170,12 +170,12 @@ endif() # compile a C file into an object file if(NOT CMAKE_C_COMPILE_OBJECT) set(CMAKE_C_COMPILE_OBJECT - "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") + "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") endif() if(NOT CMAKE_C_LINK_EXECUTABLE) set(CMAKE_C_LINK_EXECUTABLE - "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() if(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG) diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in index 4a615a3..64fb469 100644 --- a/Modules/CMakeCUDACompiler.cmake.in +++ b/Modules/CMakeCUDACompiler.cmake.in @@ -16,6 +16,7 @@ set(CMAKE_CUDA_SIMULATE_ID "@CMAKE_CUDA_SIMULATE_ID@") set(CMAKE_CUDA_COMPILER_FRONTEND_VARIANT "@CMAKE_CUDA_COMPILER_FRONTEND_VARIANT@") set(CMAKE_CUDA_SIMULATE_VERSION "@CMAKE_CUDA_SIMULATE_VERSION@") @SET_MSVC_CUDA_ARCHITECTURE_ID@ +@_SET_CMAKE_CUDA_COMPILER_SYSROOT@ set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX") set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX") @@ -53,5 +54,8 @@ set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "@CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES@") set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES@") set(CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@") +@_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT@ + set(CMAKE_LINKER "@CMAKE_LINKER@") +set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_MT "@CMAKE_MT@") diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 974f5fa..f9f7574 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -8,6 +8,19 @@ else() endif() set(CMAKE_INCLUDE_FLAG_CUDA "-I") +# Set implicit links early so compiler-specific modules can use them. +set(__IMPLICT_LINKS ) +foreach(dir ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) + string(APPEND __IMPLICT_LINKS " -L\"${dir}\"") +endforeach() +foreach(lib ${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}) + if(${lib} MATCHES "/") + string(APPEND __IMPLICT_LINKS " \"${lib}\"") + else() + string(APPEND __IMPLICT_LINKS " -l${lib}") + endif() +endforeach() + # Load compiler-specific information. if(CMAKE_CUDA_COMPILER_ID) include(Compiler/${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL) @@ -97,22 +110,10 @@ include(CMakeCommonLanguageInclude) # CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION # CMAKE_CUDA_LINK_EXECUTABLE -if(CMAKE_CUDA_HOST_COMPILER) +if(CMAKE_CUDA_HOST_COMPILER AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") string(APPEND _CMAKE_CUDA_EXTRA_FLAGS " -ccbin=<CMAKE_CUDA_HOST_COMPILER>") endif() -set(__IMPLICT_LINKS ) -foreach(dir ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) - string(APPEND __IMPLICT_LINKS " -L\"${dir}\"") -endforeach() -foreach(lib ${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}) - if(${lib} MATCHES "/") - string(APPEND __IMPLICT_LINKS " \"${lib}\"") - else() - string(APPEND __IMPLICT_LINKS " -l${lib}") - endif() -endforeach() - # create a shared library if(NOT CMAKE_CUDA_CREATE_SHARED_LIBRARY) set(CMAKE_CUDA_CREATE_SHARED_LIBRARY @@ -129,7 +130,7 @@ if(NOT DEFINED CMAKE_CUDA_ARCHIVE_CREATE) set(CMAKE_CUDA_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_CUDA_ARCHIVE_APPEND) - set(CMAKE_CUDA_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CUDA_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_CUDA_ARCHIVE_FINISH) set(CMAKE_CUDA_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -138,24 +139,24 @@ endif() #Specify how to compile when ptx has been requested if(NOT CMAKE_CUDA_COMPILE_PTX_COMPILATION) set(CMAKE_CUDA_COMPILE_PTX_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -ptx <SOURCE> -o <OBJECT>") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} ${_CMAKE_CUDA_PTX_FLAG} <SOURCE> -o <OBJECT>") endif() #Specify how to compile when separable compilation has been requested if(NOT CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION) set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -dc <SOURCE> -o <OBJECT>") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -dc <SOURCE> -o <OBJECT>") endif() #Specify how to compile when whole compilation has been requested if(NOT CMAKE_CUDA_COMPILE_WHOLE_COMPILATION) set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -c <SOURCE> -o <OBJECT>") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c <SOURCE> -o <OBJECT>") endif() -if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_DEPFILE_FLAGS_CUDA ) +if(CMAKE_GENERATOR STREQUAL "Ninja" AND NOT CMAKE_DEPFILE_FLAGS_CUDA) set(CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -M <SOURCE> -MT <OBJECT> -o $DEP_FILE") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M <SOURCE> -MT <OBJECT> -o $DEP_FILE") #The Ninja generator uses the make file dependency files to determine what #files need to be recompiled. Unfortunately, nvcc < 10.2 doesn't support building #a source file and generating the dependencies of said file in a single @@ -192,14 +193,13 @@ unset(__IMPLICT_DLINK_DIRS) #These are used when linking relocatable (dc) cuda code if(NOT CMAKE_CUDA_DEVICE_LINK_LIBRARY) set(CMAKE_CUDA_DEVICE_LINK_LIBRARY - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") endif() if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE) set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}") endif() -unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS) unset(__IMPLICT_DLINK_FLAGS) set(CMAKE_CUDA_INFORMATION_LOADED 1) diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index efb8abf..09bdc23 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -17,6 +17,7 @@ set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@") set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "@CMAKE_CXX_COMPILER_FRONTEND_VARIANT@") set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@") @_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_CXX_COMPILER_SYSROOT@ @SET_MSVC_CXX_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_ARCHS@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake index da7440a..dbb4366 100644 --- a/Modules/CMakeCXXInformation.cmake +++ b/Modules/CMakeCXXInformation.cmake @@ -258,7 +258,7 @@ if(NOT DEFINED CMAKE_CXX_ARCHIVE_CREATE) set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_CXX_ARCHIVE_APPEND) - set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_CXX_ARCHIVE_FINISH) set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -267,12 +267,12 @@ endif() # compile a C++ file into an object file if(NOT CMAKE_CXX_COMPILE_OBJECT) set(CMAKE_CXX_COMPILE_OBJECT - "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") + "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") endif() if(NOT CMAKE_CXX_LINK_EXECUTABLE) set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() mark_as_advanced( diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index bb573b7..acd15df 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -89,9 +89,8 @@ function(compiler_id_detection outvar lang) ) endif() - #Currently the only CUDA compilers are NVIDIA if(lang STREQUAL CUDA) - set(ordered_compilers NVIDIA) + set(ordered_compilers NVIDIA Clang) endif() if(CID_ID_DEFINE) diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index e47f3a4..bc8b86b 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -134,6 +134,9 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) list(GET _all_compileid_matches "-1" CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID) endif() endif() + + _cmake_find_compiler_sysroot(ASM${ASM_DIALECT}) + unset(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT) unset(_all_compileid_matches) unset(_compileid) @@ -211,6 +214,21 @@ foreach(_var set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}") endforeach() +if(CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_ASM_COMPILER_SYSROOT + "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT \"${CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_ASM${ASM_DIALECT}_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_ASM_COMPILER_SYSROOT "") +endif() + +if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH) + set(_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH + "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH [==[${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH}]==])") +else() + set(_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH "") +endif() + if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 037c33b..86683d1 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -99,7 +99,7 @@ if(NOT CMAKE_C_COMPILER_ID_RUN) CMAKE_C_COMPILER_ID_PLATFORM_CONTENT) # The IAR compiler produces weird output. - # See https://gitlab.kitware.com/cmake/cmake/issues/10176#note_153591 + # See https://gitlab.kitware.com/cmake/cmake/-/issues/10176#note_153591 list(APPEND CMAKE_C_COMPILER_ID_VENDORS IAR) set(CMAKE_C_COMPILER_ID_VENDOR_FLAGS_IAR ) set(CMAKE_C_COMPILER_ID_VENDOR_REGEX_IAR "IAR .+ Compiler") @@ -115,6 +115,8 @@ if(NOT CMAKE_C_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c) + _cmake_find_compiler_sysroot(C) + # Set old compiler and platform id variables. if(CMAKE_C_COMPILER_ID STREQUAL "GNU") set(CMAKE_COMPILER_IS_GNUCC 1) @@ -153,7 +155,7 @@ endif () # NAME_WE cannot be used since then this test will fail for names like # "arm-unknown-nto-qnx6.3.0-gcc.exe", where BASENAME would be # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-" -if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) +if (NOT _CMAKE_TOOLCHAIN_PREFIX) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME) @@ -191,6 +193,14 @@ include(CMakeFindBinUtils) include(Compiler/${CMAKE_C_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_C_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_C_COMPILER_SYSROOT + "set(CMAKE_C_COMPILER_SYSROOT \"${CMAKE_C_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_C_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_C_COMPILER_SYSROOT "") +endif() + if(CMAKE_C_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID "set(CMAKE_C_COMPILER_ARCHITECTURE_ID ${CMAKE_C_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 7d7fb9a..ed37d28 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -2,7 +2,7 @@ # file Copyright.txt or https://cmake.org/licensing for details. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) -include(${CMAKE_ROOT}/Modules//CMakeParseImplicitLinkInfo.cmake) +include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR ("${CMAKE_GENERATOR}" MATCHES "Ninja") OR @@ -57,23 +57,60 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in CMAKE_CUDA_COMPILER_ID_PLATFORM_CONTENT) - list(APPEND CMAKE_CUDA_COMPILER_ID_MATCH_VENDORS NVIDIA) - set(CMAKE_CUDA_COMPILER_ID_MATCH_VENDOR_REGEX_NVIDIA "nvcc: NVIDIA \(R\) Cuda compiler driver") + list(APPEND CMAKE_CUDA_COMPILER_ID_VENDORS NVIDIA Clang) + set(CMAKE_CUDA_COMPILER_ID_VENDOR_REGEX_NVIDIA "nvcc: NVIDIA \\(R\\) Cuda compiler driver") + set(CMAKE_CUDA_COMPILER_ID_VENDOR_REGEX_Clang "(clang version)") set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCUDA/(\\./)?(CompilerIdCUDA.xctest/)?CompilerIdCUDA[ \t\n\\\"]") set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_INDEX 2) + set(CMAKE_CUDA_COMPILER_ID_FLAGS_ALWAYS "-v") - set(CMAKE_CUDA_COMPILER_ID_FLAGS_ALWAYS -v --keep --keep-dir tmp) + # nvcc + set(nvcc_test_flags "--keep --keep-dir tmp") if(CMAKE_CUDA_HOST_COMPILER) - list(APPEND CMAKE_CUDA_COMPILER_ID_FLAGS_ALWAYS "-ccbin=${CMAKE_CUDA_HOST_COMPILER}") + string(APPEND nvcc_test_flags " -ccbin=${CMAKE_CUDA_HOST_COMPILER}") endif() + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST ${nvcc_test_flags}) + + # Clang + if(CMAKE_CROSSCOMPILING) + # Need to pass the host target and include directories if we're crosscompiling. + set(clang_test_flags "--sysroot=\"${CMAKE_SYSROOT}\" --target=${CMAKE_CUDA_COMPILER_TARGET}") + else() + set(clang_test_flags) + endif() + + # First try with the user-specified architectures. + if(CMAKE_CUDA_ARCHITECTURES) + set(clang_archs "${clang_test_flags}") + + foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) + # Strip specifiers as PTX vs binary doesn't matter. + string(REGEX MATCH "[0-9]+" arch_name "${arch}") + string(APPEND clang_archs " --cuda-gpu-arch=sm_${arch_name}") + endforeach() + + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_archs}") + endif() + + # Clang doesn't automatically select an architecture supported by the SDK. + # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups). + foreach(arch "20" "30" "52") + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}") + endforeach() + + # Finally also try the default. + list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}") include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(CUDA CUDAFLAGS CMakeCUDACompilerId.cu) + + _cmake_find_compiler_sysroot(CUDA) endif() set(_CMAKE_PROCESSING_LANGUAGE "CUDA") include(CMakeFindBinUtils) +include(Compiler/${CMAKE_CUDA_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) if(MSVC_CUDA_ARCHITECTURE_ID) @@ -86,7 +123,56 @@ if(${CMAKE_GENERATOR} MATCHES "Visual Studio") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "") set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") -elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA) + + # 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") + if(NOT CMAKE_CUDA_ARCHITECTURES) + # Find the architecture that we successfully compiled using and set it as the default. + string(REGEX MATCH "-target-cpu sm_([0-9]+)" dont_care "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") + set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_MATCH_1}" CACHE STRING "CUDA architectures") + + if(NOT CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR "Failed to find a working CUDA architecture.") + endif() + else() + string(REGEX MATCHALL "-target-cpu sm_([0-9]+)" 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 "${CMAKE_MATCH_1}") + endforeach() + + if(NOT "${architectures}" STREQUAL "${CMAKE_CUDA_ARCHITECTURES}") + message(FATAL_ERROR + "The CMAKE_CUDA_ARCHITECTURES:\n" + " ${CMAKE_CUDA_ARCHITECTURES}\n" + "do not all work with this compiler. Try:\n" + " ${architectures}\n" + "instead.") + endif() + endif() + + # Clang does not add any CUDA SDK libraries or directories when invoking the host linker. + # Add the CUDA toolkit library directory ourselves so that linking works. + # The CUDA runtime libraries are handled elsewhere by CMAKE_CUDA_RUNTIME_LIBRARY. + include(Internal/CUDAToolkit) + set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "${CUDAToolkit_INCLUDE_DIR}") + set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "${CUDAToolkit_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") @@ -179,6 +265,20 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA) log "${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}") + # 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}\")") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Parsed CUDA nvcc implicit link information from above output:\n${_nvcc_log}\n${log}\n\n") else() @@ -188,30 +288,70 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA) endif() endif() -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") +# 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}) + +if(CMAKE_CUDA_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_CUDA_COMPILER_SYSROOT + "set(CMAKE_CUDA_COMPILER_SYSROOT \"${CMAKE_CUDA_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_CUDA_COMPILER_SYSROOT}\")") 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") + set(_SET_CMAKE_CUDA_COMPILER_SYSROOT "") 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() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Parsed CUDA nvcc include information from above output:\n${_nvcc_log}\n${log}\n\n") -else() - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Failed to detect CUDA nvcc include information:\n${_nvcc_log}\n\n") +# 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() + + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Parsed CUDA nvcc include information from above output:\n${_nvcc_log}\n${log}\n\n") + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Failed to detect CUDA nvcc include information:\n${_nvcc_log}\n\n") + endif() + + # Parse default CUDA architecture. + cmake_policy(GET CMP0104 _CUDA_CMP0104) + if(NOT CMAKE_CUDA_ARCHITECTURES AND _CUDA_CMP0104 STREQUAL "NEW") + string(REGEX MATCH "arch[ =]compute_([0-9]+)" dont_care "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") + set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_MATCH_1}" CACHE STRING "CUDA architectures") + + if(NOT CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR "Failed to find default CUDA architecture.") + endif() + endif() endif() # configure all variables set in this file diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 7274eec..662b831 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -94,7 +94,7 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN) CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT) # The IAR compiler produces weird output. - # See https://gitlab.kitware.com/cmake/cmake/issues/10176#note_153591 + # See https://gitlab.kitware.com/cmake/cmake/-/issues/10176#note_153591 list(APPEND CMAKE_CXX_COMPILER_ID_VENDORS IAR) set(CMAKE_CXX_COMPILER_ID_VENDOR_FLAGS_IAR ) set(CMAKE_CXX_COMPILER_ID_VENDOR_REGEX_IAR "IAR .+ Compiler") @@ -110,6 +110,8 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp) + _cmake_find_compiler_sysroot(CXX) + # Set old compiler and platform id variables. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_COMPILER_IS_GNUCXX 1) @@ -150,7 +152,7 @@ endif () # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-" -if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) +if (NOT _CMAKE_TOOLCHAIN_PREFIX) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME) @@ -189,6 +191,14 @@ include(CMakeFindBinUtils) include(Compiler/${CMAKE_CXX_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_CXX_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_CXX_COMPILER_SYSROOT + "set(CMAKE_CXX_COMPILER_SYSROOT \"${CMAKE_CXX_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_CXX_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_CXX_COMPILER_SYSROOT "") +endif() + if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID "set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index c37adae..7cd7c47 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -53,6 +53,20 @@ macro(_cmake_find_compiler lang) NO_DEFAULT_PATH DOC "${lang} compiler") endif() + if(CMAKE_HOST_WIN32 AND CMAKE_GENERATOR MATCHES "Ninja") + # On Windows command-line builds, the Makefile generators each imply + # a preferred compiler tool. The Ninja generator does not imply a + # compiler tool, so use the compiler that occurs first in PATH. + find_program(CMAKE_${lang}_COMPILER + NAMES ${CMAKE_${lang}_COMPILER_LIST} + NAMES_PER_DIR + DOC "${lang} compiler" + NO_PACKAGE_ROOT_PATH + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + ) + endif() find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler") if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER) set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${CMAKE_${lang}_COMPILER_INIT}") @@ -118,3 +132,19 @@ macro(_cmake_find_compiler_path lang) endif() endif() endmacro() + +function(_cmake_find_compiler_sysroot lang) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -print-sysroot + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE _cmake_sysroot_run_out + ERROR_VARIABLE _cmake_sysroot_run_err) + + if(_cmake_sysroot_run_out AND NOT _cmake_sysroot_run_err AND IS_DIRECTORY "${_cmake_sysroot_run_out}/usr") + file(TO_CMAKE_PATH "${_cmake_sysroot_run_out}/usr" _cmake_sysroot_run_out_usr) + set(CMAKE_${lang}_COMPILER_SYSROOT "${_cmake_sysroot_run_out_usr}" PARENT_SCOPE) + else() + set(CMAKE_${lang}_COMPILER_SYSROOT "" PARENT_SCOPE) + endif() + endif() +endfunction() diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index e1b3c52..50d5cd1 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -65,10 +65,13 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) # Move result from cache to normal variable. set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED}) unset(CMAKE_${lang}_ABI_COMPILED CACHE) + if(CMAKE_${lang}_ABI_COMPILED AND _copy_error) + set(CMAKE_${lang}_ABI_COMPILED 0) + endif() set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED} PARENT_SCOPE) # Load the resulting information strings. - if(CMAKE_${lang}_ABI_COMPILED AND NOT _copy_error) + if(CMAKE_${lang}_ABI_COMPILED) message(CHECK_PASS "done") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n") diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index d3ed45b..df48fa5 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -381,7 +381,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) set(id_ItemDefinitionGroup_entry "<CudaCompile><TargetMachinePlatform>64</TargetMachinePlatform><AdditionalOptions>%(AdditionalOptions)-v</AdditionalOptions></CudaCompile>") endif() - set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart.lib</AdditionalDependencies>") + if(CMAKE_CUDA_FLAGS MATCHES "(^| )-cudart +shared( |$)") + set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart.lib</AdditionalDependencies>") + else() + set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart_static.lib</AdditionalDependencies>") + endif() endif() configure_file(${CMAKE_ROOT}/Modules/CompilerId/VS-${v}.${ext}.in ${id_dir}/CompilerId${lang}.${ext} @ONLY) @@ -870,6 +874,14 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags) file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}) endif() + # Save the current LC_ALL, LC_MESSAGES, and LANG environment variables + # and set them to "C" so we get the expected output to match. + set(_orig_lc_all $ENV{LC_ALL}) + set(_orig_lc_messages $ENV{LC_MESSAGES}) + set(_orig_lang $ENV{LANG}) + set(ENV{LC_ALL} C) + set(ENV{LC_MESSAGES} C) + set(ENV{LANG} C) foreach(vendor ${CMAKE_${lang}_COMPILER_ID_VENDORS}) set(flags ${CMAKE_${lang}_COMPILER_ID_VENDOR_FLAGS_${vendor}}) @@ -891,6 +903,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags) "matched \"${regex}\":\n${output}") set(CMAKE_${lang}_COMPILER_ID "${vendor}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_ID_OUTPUT "${output}" PARENT_SCOPE) + set(CMAKE_${lang}_COMPILER_ID_VENDOR_MATCH "${CMAKE_MATCH_1}" PARENT_SCOPE) break() else() if("${result}" MATCHES "timeout") @@ -904,6 +917,11 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags) endif() endif() endforeach() + + # Restore original LC_ALL, LC_MESSAGES, and LANG + set(ENV{LC_ALL} ${_orig_lc_all}) + set(ENV{LC_MESSAGES} ${_orig_lc_messages}) + set(ENV{LANG} ${_orig_lang}) endfunction() function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang userflags) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index e850541..5f5a70a 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -186,6 +186,8 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F) + _cmake_find_compiler_sysroot(Fortran) + # Fall back to old is-GNU test. if(NOT CMAKE_Fortran_COMPILER_ID) execute_process(COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "${CMAKE_ROOT}/Modules/CMakeTestGNU.c" @@ -249,7 +251,7 @@ endif () # NAME_WE cannot be used since then this test will fail for names like # "arm-unknown-nto-qnx6.3.0-gcc.exe", where BASENAME would be # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-" -if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) +if (NOT _CMAKE_TOOLCHAIN_PREFIX) if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") get_filename_component(COMPILER_BASENAME "${CMAKE_Fortran_COMPILER}" NAME) @@ -276,6 +278,14 @@ if(CMAKE_Fortran_XL_CPP) "set(CMAKE_Fortran_XL_CPP \"${CMAKE_Fortran_XL_CPP}\")") endif() +if(CMAKE_Fortran_COMPILER_SYSROOT) + string(CONCAT _SET_CMAKE_Fortran_COMPILER_SYSROOT + "set(CMAKE_Fortran_COMPILER_SYSROOT \"${CMAKE_Fortran_COMPILER_SYSROOT}\")\n" + "set(CMAKE_COMPILER_SYSROOT \"${CMAKE_Fortran_COMPILER_SYSROOT}\")") +else() + set(_SET_CMAKE_Fortran_COMPILER_SYSROOT "") +endif() + if(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID) set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID "set(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID ${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineOBJCCompiler.cmake b/Modules/CMakeDetermineOBJCCompiler.cmake index ad13eab..11b47fd 100644 --- a/Modules/CMakeDetermineOBJCCompiler.cmake +++ b/Modules/CMakeDetermineOBJCCompiler.cmake @@ -34,16 +34,19 @@ else() if(NOT CMAKE_OBJC_COMPILER) set(CMAKE_OBJC_COMPILER_INIT NOTFOUND) - # prefer the environment variable OBJC - if($ENV{OBJC} MATCHES ".+") - get_filename_component(CMAKE_OBJC_COMPILER_INIT $ENV{OBJC} PROGRAM PROGRAM_ARGS CMAKE_OBJC_FLAGS_ENV_INIT) - if(CMAKE_OBJC_FLAGS_ENV_INIT) - set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C compiler") + # prefer the environment variable OBJC or CC + foreach(var OBJC CC) + if($ENV{${var}} MATCHES ".+") + get_filename_component(CMAKE_OBJC_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJC_FLAGS_ENV_INIT) + if(CMAKE_OBJC_FLAGS_ENV_INIT) + set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C compiler") + endif() + if(NOT EXISTS ${CMAKE_OBJC_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") + endif() + break() endif() - if(NOT EXISTS ${CMAKE_OBJC_COMPILER_INIT}) - message(FATAL_ERROR "Could not find compiler set in environment variable OBJC:\n$ENV{OBJC}.") - endif() - endif() + endforeach() # next try prefer the compiler specified by the generator if(CMAKE_GENERATOR_OBJC) diff --git a/Modules/CMakeDetermineOBJCXXCompiler.cmake b/Modules/CMakeDetermineOBJCXXCompiler.cmake index 60fcbb3..99ad6c3 100644 --- a/Modules/CMakeDetermineOBJCXXCompiler.cmake +++ b/Modules/CMakeDetermineOBJCXXCompiler.cmake @@ -36,16 +36,19 @@ else() if(NOT CMAKE_OBJCXX_COMPILER) set(CMAKE_OBJCXX_COMPILER_INIT NOTFOUND) - # prefer the environment variable OBJCXX - if($ENV{OBJCXX} MATCHES ".+") - get_filename_component(CMAKE_OBJCXX_COMPILER_INIT $ENV{OBJCXX} PROGRAM PROGRAM_ARGS CMAKE_OBJCXX_FLAGS_ENV_INIT) - if(CMAKE_OBJCXX_FLAGS_ENV_INIT) - set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C++ compiler") + # prefer the environment variable OBJCXX or CXX + foreach(var OBJCXX CXX) + if($ENV{${var}} MATCHES ".+") + get_filename_component(CMAKE_OBJCXX_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJCXX_FLAGS_ENV_INIT) + if(CMAKE_OBJCXX_FLAGS_ENV_INIT) + set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C++ compiler") + endif() + if(NOT EXISTS ${CMAKE_OBJCXX_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") + endif() + break() endif() - if(NOT EXISTS ${CMAKE_OBJCXX_COMPILER_INIT}) - message(FATAL_ERROR "Could not find compiler set in environment variable OBJCXX:\n$ENV{OBJCXX}.\n${CMAKE_OBJCXX_COMPILER_INIT}") - endif() - endif() + endforeach() # next prefer the generator specified compiler if(CMAKE_GENERATOR_OBJCXX) @@ -145,7 +148,7 @@ endif () # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-" -if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) +if (NOT _CMAKE_TOOLCHAIN_PREFIX) if("${CMAKE_OBJCXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC") get_filename_component(COMPILER_BASENAME "${CMAKE_OBJCXX_COMPILER}" NAME) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index c23e447..de9ef9a 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -75,6 +75,7 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND endif() find_program(CMAKE_LINKER NAMES ${_CMAKE_ADDITIONAL_LINKER_NAMES} link HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + find_program(CMAKE_AR NAMES lib HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) list(APPEND _CMAKE_TOOL_VARS LINKER MT) diff --git a/Modules/CMakeFindEclipseCDT4.cmake b/Modules/CMakeFindEclipseCDT4.cmake index 199005d..e563a12 100644 --- a/Modules/CMakeFindEclipseCDT4.cmake +++ b/Modules/CMakeFindEclipseCDT4.cmake @@ -25,7 +25,7 @@ function(_FIND_ECLIPSE_VERSION) if(NOT DEFINED CMAKE_ECLIPSE_VERSION) if(CMAKE_ECLIPSE_EXECUTABLE) - # use REALPATH to resolve symlinks (https://gitlab.kitware.com/cmake/cmake/issues/13036) + # use REALPATH to resolve symlinks (https://gitlab.kitware.com/cmake/cmake/-/issues/13036) get_filename_component(_REALPATH_CMAKE_ECLIPSE_EXECUTABLE "${CMAKE_ECLIPSE_EXECUTABLE}" REALPATH) get_filename_component(_ECLIPSE_DIR "${_REALPATH_CMAKE_ECLIPSE_EXECUTABLE}" PATH) file(GLOB _ECLIPSE_FEATURE_DIR "${_ECLIPSE_DIR}/features/org.eclipse.platform*") diff --git a/Modules/CMakeFindFrameworks.cmake b/Modules/CMakeFindFrameworks.cmake index 06c05fb..8906f48 100644 --- a/Modules/CMakeFindFrameworks.cmake +++ b/Modules/CMakeFindFrameworks.cmake @@ -17,13 +17,25 @@ if(NOT CMAKE_FIND_FRAMEWORKS_INCLUDED) macro(CMAKE_FIND_FRAMEWORKS fwk) set(${fwk}_FRAMEWORKS) if(APPLE) - foreach(dir - ~/Library/Frameworks/${fwk}.framework - /usr/local/Frameworks/${fwk}.framework - /Library/Frameworks/${fwk}.framework - /System/Library/Frameworks/${fwk}.framework - /Network/Library/Frameworks/${fwk}.framework - ${CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS}) + file(TO_CMAKE_PATH "$ENV{CMAKE_FRAMEWORK_PATH}" _cmff_CMAKE_FRAMEWORK_PATH) + set(_cmff_search_paths + ${CMAKE_FRAMEWORK_PATH} + ${_cmff_CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /usr/local/Frameworks + /Library/Frameworks + /System/Library/Frameworks + /Network/Library/Frameworks + ${CMAKE_SYSTEM_FRAMEWORK_PATH}) + + # For backwards compatibility reasons, + # CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS includes ${fwk}.framework + list(TRANSFORM _cmff_search_paths APPEND /${fwk}.framework) + list(APPEND _cmff_search_paths ${CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS}) + + list(REMOVE_DUPLICATES _cmff_search_paths) + + foreach(dir IN LISTS _cmff_search_paths) if(EXISTS ${dir}) set(${fwk}_FRAMEWORKS ${${fwk}_FRAMEWORKS} ${dir}) endif() diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 34f44aa..06ee528 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -8,6 +8,7 @@ set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@") set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") @_SET_CMAKE_Fortran_XL_CPP@ @_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID@ +@_SET_CMAKE_Fortran_COMPILER_SYSROOT@ @SET_MSVC_Fortran_ARCHITECTURE_ID@ set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@") diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index e80716b..9a4ce63 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -193,7 +193,7 @@ if(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE) set(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND) - set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH) set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -209,7 +209,7 @@ endif() # link a fortran program if(NOT CMAKE_Fortran_LINK_EXECUTABLE) set(CMAKE_Fortran_LINK_EXECUTABLE - "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT) diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index f539b46..000fba1 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -50,15 +50,9 @@ if(CMAKE_GENERATOR MATCHES "Make") if(DEFINED CMAKE_TARGET_MESSAGES) set_property(GLOBAL PROPERTY TARGET_MESSAGES ${CMAKE_TARGET_MESSAGES}) endif() - if(CMAKE_GENERATOR MATCHES "Unix Makefiles") - set(CMAKE_EXPORT_COMPILE_COMMANDS "$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}" - CACHE BOOL "Enable/Disable output of compile commands during generation." - ) - mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS) - endif() endif() -if(CMAKE_GENERATOR MATCHES "Ninja") +if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS AND CMAKE_GENERATOR MATCHES "Ninja|Unix Makefiles") set(CMAKE_EXPORT_COMPILE_COMMANDS "$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}" CACHE BOOL "Enable/Disable output of compile commands during generation." ) diff --git a/Modules/CMakeOBJCInformation.cmake b/Modules/CMakeOBJCInformation.cmake index 15a3311..b3da82d 100644 --- a/Modules/CMakeOBJCInformation.cmake +++ b/Modules/CMakeOBJCInformation.cmake @@ -161,7 +161,7 @@ if(NOT DEFINED CMAKE_OBJC_ARCHIVE_CREATE) set(CMAKE_OBJC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_OBJC_ARCHIVE_APPEND) - set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_OBJC_ARCHIVE_FINISH) set(CMAKE_OBJC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -170,12 +170,12 @@ endif() # compile an Objective-C file into an object file if(NOT CMAKE_OBJC_COMPILE_OBJECT) set(CMAKE_OBJC_COMPILE_OBJECT - "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c -o <OBJECT> -c <SOURCE>") + "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c -o <OBJECT> -c <SOURCE>") endif() if(NOT CMAKE_OBJC_LINK_EXECUTABLE) set(CMAKE_OBJC_LINK_EXECUTABLE - "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG) diff --git a/Modules/CMakeOBJCXXInformation.cmake b/Modules/CMakeOBJCXXInformation.cmake index cb349d7..71beb7f 100644 --- a/Modules/CMakeOBJCXXInformation.cmake +++ b/Modules/CMakeOBJCXXInformation.cmake @@ -254,7 +254,7 @@ if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_CREATE) set(CMAKE_OBJCXX_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_APPEND) - set(CMAKE_OBJCXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_OBJCXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") endif() if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_FINISH) set(CMAKE_OBJCXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") @@ -263,12 +263,12 @@ endif() # compile an Objective-C++ file into an object file if(NOT CMAKE_OBJCXX_COMPILE_OBJECT) set(CMAKE_OBJCXX_COMPILE_OBJECT - "<CMAKE_OBJCXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c++ -o <OBJECT> -c <SOURCE>") + "<CMAKE_OBJCXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c++ -o <OBJECT> -c <SOURCE>") endif() if(NOT CMAKE_OBJCXX_LINK_EXECUTABLE) set(CMAKE_OBJCXX_LINK_EXECUTABLE - "<CMAKE_OBJCXX_COMPILER> <FLAGS> <CMAKE_OBJCXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_OBJCXX_COMPILER> <FLAGS> <CMAKE_OBJCXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() mark_as_advanced( diff --git a/Modules/CMakePrintSystemInformation.cmake b/Modules/CMakePrintSystemInformation.cmake index 8d5cf5c..d44e933 100644 --- a/Modules/CMakePrintSystemInformation.cmake +++ b/Modules/CMakePrintSystemInformation.cmake @@ -11,7 +11,7 @@ This module serves diagnostic purposes. Just include it in a project to see various internal CMake variables. #]=======================================================================] -message("CMAKE_SYSTEM is ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}") +message("CMAKE_SYSTEM is ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR}") message("CMAKE_SYSTEM file is ${CMAKE_SYSTEM_INFO_FILE}") message("CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}") message("CMAKE_CXX_COMPILER is ${CMAKE_CXX_COMPILER}") diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake index eadea89..3734ec4 100644 --- a/Modules/CMakeTestCCompiler.cmake +++ b/Modules/CMakeTestCCompiler.cmake @@ -21,6 +21,15 @@ endif() # We now store this in CMakeCCompiler.cmake. unset(CMAKE_C_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeCCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c) +if(CMAKE_C_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_C_COMPILER_WORKS TRUE) + message(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that that selected C compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -47,49 +56,41 @@ if(NOT CMAKE_C_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS}) unset(CMAKE_C_COMPILER_WORKS CACHE) - set(C_TEST_WAS_RUN 1) __TestCompiler_restoreTryCompileTargetType() -endif() - -if(NOT CMAKE_C_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the C compiler works failed with " - "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${__CMAKE_C_COMPILER_OUTPUT}") - message(FATAL_ERROR "The C compiler\n \"${CMAKE_C_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(C_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the C compiler works passed with " + if(NOT CMAKE_C_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the C compiler works failed with " "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${__CMAKE_C_COMPILER_OUTPUT}") + message(FATAL_ERROR "The C compiler\n \"${CMAKE_C_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the C compiler works passed with " + "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeCCompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c) - # Try to identify the compiler features - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) - CMAKE_DETERMINE_COMPILE_FEATURES(C) +# Try to identify the compiler features +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) +CMAKE_DETERMINE_COMPILE_FEATURES(C) - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake) +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake) - if(CMAKE_C_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_C_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_C_ABI_FILES) - endif() +if(CMAKE_C_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_C_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_C_ABI_FILES) endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake index 05811a8..a18947b 100644 --- a/Modules/CMakeTestCUDACompiler.cmake +++ b/Modules/CMakeTestCUDACompiler.cmake @@ -14,6 +14,15 @@ include(CMakeTestCompilerCommon) # We now store this in CMakeCUDACompiler.cmake. unset(CMAKE_CUDA_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeCUDACompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu) +if(CMAKE_CUDA_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_CUDA_COMPILER_WORKS TRUE) + message(STATUS "Check for working CUDA compiler: ${CMAKE_CUDA_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that the selected cuda compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -34,50 +43,37 @@ if(NOT CMAKE_CUDA_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_CUDA_COMPILER_WORKS ${CMAKE_CUDA_COMPILER_WORKS}) unset(CMAKE_CUDA_COMPILER_WORKS CACHE) - set(CUDA_TEST_WAS_RUN 1) -endif() - -if(NOT CMAKE_CUDA_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the CUDA compiler works failed with " - "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${__CMAKE_CUDA_COMPILER_OUTPUT}") - message(FATAL_ERROR "The CUDA compiler\n \"${CMAKE_CUDA_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(CUDA_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the CUDA compiler works passed with " + if(NOT CMAKE_CUDA_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the CUDA compiler works failed with " "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${__CMAKE_CUDA_COMPILER_OUTPUT}") + message(FATAL_ERROR "The CUDA compiler\n \"${CMAKE_CUDA_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the CUDA compiler works passed with " + "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeCUDACompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu) - # Try to identify the compiler features - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) - CMAKE_DETERMINE_COMPILE_FEATURES(CUDA) +# Try to identify the compiler features +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) +CMAKE_DETERMINE_COMPILE_FEATURES(CUDA) - if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") - set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}") - set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}") - endif() +if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}") + set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}") +endif() - # Remove the following libraries from CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES and - # CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES - # - # - cudart - # - cudart_static - # - cudadevrt - # - # These are controlled by CMAKE_CUDA_RUNTIME_LIBRARY - list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES cudart cudart_static cudadevrt) - list(REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES cudart cudart_static cudadevrt) +# 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}) +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 @@ -89,15 +85,14 @@ else() ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} ) endif() - - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake) endif() +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake) unset(__CMAKE_CUDA_COMPILER_OUTPUT) diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake index bd42153..b9cb1dd 100644 --- a/Modules/CMakeTestCXXCompiler.cmake +++ b/Modules/CMakeTestCXXCompiler.cmake @@ -21,6 +21,15 @@ endif() # We now store this in CMakeCXXCompiler.cmake. unset(CMAKE_CXX_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeCXXCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp) +if(CMAKE_CXX_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_CXX_COMPILER_WORKS TRUE) + message(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that the selected C++ compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -40,49 +49,41 @@ if(NOT CMAKE_CXX_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS}) unset(CMAKE_CXX_COMPILER_WORKS CACHE) - set(CXX_TEST_WAS_RUN 1) __TestCompiler_restoreTryCompileTargetType() -endif() - -if(NOT CMAKE_CXX_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the CXX compiler works failed with " - "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}") - message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(CXX_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the CXX compiler works passed with " + if(NOT CMAKE_CXX_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the CXX compiler works failed with " "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}") + message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the CXX compiler works passed with " + "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp) - # Try to identify the compiler features - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) - CMAKE_DETERMINE_COMPILE_FEATURES(CXX) +# Try to identify the compiler features +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) +CMAKE_DETERMINE_COMPILE_FEATURES(CXX) - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake) +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake) - if(CMAKE_CXX_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_CXX_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_CXX_ABI_FILES) - endif() +if(CMAKE_CXX_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_CXX_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_CXX_ABI_FILES) endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) diff --git a/Modules/CMakeTestFortranCompiler.cmake b/Modules/CMakeTestFortranCompiler.cmake index 7461f9c..10fb0a7 100644 --- a/Modules/CMakeTestFortranCompiler.cmake +++ b/Modules/CMakeTestFortranCompiler.cmake @@ -15,6 +15,15 @@ include(CMakeTestCompilerCommon) # We now store this in CMakeFortranCompiler.cmake. unset(CMAKE_Fortran_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeFortranCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F) +if(CMAKE_Fortran_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_Fortran_COMPILER_WORKS TRUE) + message(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that the selected Fortran compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -33,70 +42,61 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS}) unset(CMAKE_Fortran_COMPILER_WORKS CACHE) - set(FORTRAN_TEST_WAS_RUN 1) -endif() - -if(NOT CMAKE_Fortran_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the Fortran compiler works failed with " - "the following output:\n${OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${OUTPUT}") - message(FATAL_ERROR "The Fortran compiler\n \"${CMAKE_Fortran_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(FORTRAN_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the Fortran compiler works passed with " + if(NOT CMAKE_Fortran_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Fortran compiler works failed with " "the following output:\n${OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${OUTPUT}") + message(FATAL_ERROR "The Fortran compiler\n \"${CMAKE_Fortran_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Fortran compiler works passed with " + "the following output:\n${OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F) - - # Test for Fortran 90 support by using an f90-specific construct. - if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90) - message(CHECK_START "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90") - file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 " - PROGRAM TESTFortran90 - integer stop ; stop = 1 ; do while ( stop .eq. 0 ) ; end do - END PROGRAM TESTFortran90 +# Test for Fortran 90 support by using an f90-specific construct. +if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90) + message(CHECK_START "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90") + file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 " + PROGRAM TESTFortran90 + integer stop ; stop = 1 ; do while ( stop .eq. 0 ) ; end do + END PROGRAM TESTFortran90 ") - try_compile(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 - OUTPUT_VARIABLE OUTPUT) - if(CMAKE_Fortran_COMPILER_SUPPORTS_F90) - message(CHECK_PASS "yes") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the Fortran compiler supports Fortran 90 passed with " - "the following output:\n${OUTPUT}\n\n") - set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) - else() - message(CHECK_FAIL "no") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the Fortran compiler supports Fortran 90 failed with " - "the following output:\n${OUTPUT}\n\n") - set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0) - endif() - unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE) + try_compile(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 + OUTPUT_VARIABLE OUTPUT) + if(CMAKE_Fortran_COMPILER_SUPPORTS_F90) + message(CHECK_PASS "yes") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Fortran compiler supports Fortran 90 passed with " + "the following output:\n${OUTPUT}\n\n") + set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) + else() + message(CHECK_FAIL "no") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Fortran compiler supports Fortran 90 failed with " + "the following output:\n${OUTPUT}\n\n") + set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0) endif() + unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE) +endif() - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake) +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake) - if(CMAKE_Fortran_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_Fortran_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_Fortran_ABI_FILES) - endif() +if(CMAKE_Fortran_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_Fortran_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_Fortran_ABI_FILES) endif() diff --git a/Modules/CMakeTestOBJCCompiler.cmake b/Modules/CMakeTestOBJCCompiler.cmake index bcc6fae..0e333c0 100644 --- a/Modules/CMakeTestOBJCCompiler.cmake +++ b/Modules/CMakeTestOBJCCompiler.cmake @@ -21,6 +21,15 @@ endif() # We now store this in CMakeCCompiler.cmake. unset(CMAKE_OBJC_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m) +if(CMAKE_OBJC_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_OBJC_COMPILER_WORKS TRUE) + message(STATUS "Check for working OBJC compiler: ${CMAKE_OBJC_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that that selected Objective-C compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -44,49 +53,41 @@ if(NOT CMAKE_OBJC_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_OBJC_COMPILER_WORKS ${CMAKE_OBJC_COMPILER_WORKS}) unset(CMAKE_OBJC_COMPILER_WORKS CACHE) - set(OBJC_TEST_WAS_RUN 1) __TestCompiler_restoreTryCompileTargetType() -endif() - -if(NOT CMAKE_OBJC_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the Objective-C compiler works failed with " - "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${__CMAKE_OBJC_COMPILER_OUTPUT}") - message(FATAL_ERROR "The Objective-C compiler\n \"${CMAKE_OBJC_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(OBJC_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the Objective-C compiler works passed with " + if(NOT CMAKE_OBJC_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Objective-C compiler works failed with " "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${__CMAKE_OBJC_COMPILER_OUTPUT}") + message(FATAL_ERROR "The Objective-C compiler\n \"${CMAKE_OBJC_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Objective-C compiler works passed with " + "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m) - # Try to identify the compiler features - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) - CMAKE_DETERMINE_COMPILE_FEATURES(OBJC) +# Try to identify the compiler features +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) +CMAKE_DETERMINE_COMPILE_FEATURES(OBJC) - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeOBJCCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake) +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeOBJCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake) - if(CMAKE_OBJC_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_OBJC_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_OBJC_ABI_FILES) - endif() +if(CMAKE_OBJC_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_OBJC_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_OBJC_ABI_FILES) endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) diff --git a/Modules/CMakeTestOBJCXXCompiler.cmake b/Modules/CMakeTestOBJCXXCompiler.cmake index 83227d5..dc153a7 100644 --- a/Modules/CMakeTestOBJCXXCompiler.cmake +++ b/Modules/CMakeTestOBJCXXCompiler.cmake @@ -21,6 +21,15 @@ endif() # We now store this in CMakeOBJCXXCompiler.cmake. unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE) +# Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) +CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm) +if(CMAKE_OBJCXX_ABI_COMPILED) + # The compiler worked so skip dedicated test below. + set(CMAKE_OBJCXX_COMPILER_WORKS TRUE) + message(STATUS "Check for working OBJCXX compiler: ${CMAKE_OBJCXX_COMPILER} - skipped") +endif() + # This file is used by EnableLanguage in cmGlobalGenerator to # determine that the selected Objective-C++ compiler can actually compile # and link the most basic of programs. If not, a fatal error @@ -43,49 +52,41 @@ if(NOT CMAKE_OBJCXX_COMPILER_WORKS) # Move result from cache to normal variable. set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS}) unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE) - set(OBJCXX_TEST_WAS_RUN 1) __TestCompiler_restoreTryCompileTargetType() -endif() - -if(NOT CMAKE_OBJCXX_COMPILER_WORKS) - PrintTestCompilerResult(CHECK_FAIL "broken") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the Objective-C++ compiler works failed with " - "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n") - string(REPLACE "\n" "\n " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}") - message(FATAL_ERROR "The Objective-C++ compiler\n \"${CMAKE_OBJCXX_COMPILER}\"\n" - "is not able to compile a simple test program.\nIt fails " - "with the following output:\n ${_output}\n\n" - "CMake will not be able to correctly generate this project.") -else() - if(OBJCXX_TEST_WAS_RUN) - PrintTestCompilerResult(CHECK_PASS "works") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the Objective-C++ compiler works passed with " + if(NOT CMAKE_OBJCXX_COMPILER_WORKS) + PrintTestCompilerResult(CHECK_FAIL "broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Objective-C++ compiler works failed with " "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n") + string(REPLACE "\n" "\n " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}") + message(FATAL_ERROR "The Objective-C++ compiler\n \"${CMAKE_OBJCXX_COMPILER}\"\n" + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${_output}\n\n" + "CMake will not be able to correctly generate this project.") endif() + PrintTestCompilerResult(CHECK_PASS "works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Objective-C++ compiler works passed with " + "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n") +endif() - # Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) - CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm) - # Try to identify the compiler features - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) - CMAKE_DETERMINE_COMPILE_FEATURES(OBJCXX) +# Try to identify the compiler features +include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) +CMAKE_DETERMINE_COMPILE_FEATURES(OBJCXX) - # Re-configure to save learned information. - configure_file( - ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake - @ONLY - ) - include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake) +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake + @ONLY + ) +include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake) - if(CMAKE_OBJCXX_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_OBJCXX_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_OBJCXX_ABI_FILES) - endif() +if(CMAKE_OBJCXX_SIZEOF_DATA_PTR) + foreach(f ${CMAKE_OBJCXX_ABI_FILES}) + include(${f}) + endforeach() + unset(CMAKE_OBJCXX_ABI_FILES) endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index baf7e47..6234b9d 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -5,7 +5,7 @@ CPack ----- -Configure the binary and source package installers. +Configure generators for binary installers and source packages. Introduction ^^^^^^^^^^^^ @@ -19,13 +19,17 @@ Depending on the CMake generator, the CPack module may also add two new build targets, ``package`` and ``package_source``. See the `packaging targets`_ section below for details. -The generated binary installers contain everything installed via CMake's -:command:`install` command (and the deprecated commands :command:`install_files`, -:command:`install_programs`, and :command:`install_targets`). -For certain kinds of binary installers (including the graphical -installers on macOS and Windows), CPack generates installers that -allow users to select individual application components to install. -See :module:`CPackComponent` module for further details. +The generated binary installers will contain all files that have been installed +via CMake's :command:`install` command (and the deprecated commands +:command:`install_files`, :command:`install_programs`, and +:command:`install_targets`). Certain kinds of binary installers can be +configured such that users can select individual application components to +install. See the :module:`CPackComponent` module for further details. + +Source packages (configured through ``CPackSourceConfig.cmake`` and generated +by the :cpack_gen:`CPack Archive Generator`) will contain all source files in +the project directory except those specified in +:variable:`CPACK_SOURCE_IGNORE_FILES`. CPack Generators ^^^^^^^^^^^^^^^^ @@ -38,10 +42,6 @@ generator. In a :variable:`CPACK_PROJECT_CONFIG_FILE`, :variable:`CPACK_GENERATOR` is a *string naming a single generator*. If you need per-cpack-generator logic to control *other* cpack settings, then you need a :variable:`CPACK_PROJECT_CONFIG_FILE`. - -The CMake source tree itself contains a :variable:`CPACK_PROJECT_CONFIG_FILE`. -See the top level file ``CMakeCPackOptions.cmake.in`` for an example. - If set, the :variable:`CPACK_PROJECT_CONFIG_FILE` is included automatically on a per-generator basis. It only need contain overrides. diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake index 211d767..1f8c38c 100644 --- a/Modules/CPackComponent.cmake +++ b/Modules/CPackComponent.cmake @@ -5,29 +5,34 @@ CPackComponent -------------- -Build binary and source package installers +Configure components for binary installers and source packages. -Variables concerning CPack Components -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. only:: html -The CPackComponent module is the module which handles the component -part of CPack. See CPack module for general information about CPack. + .. contents:: -For certain kinds of binary installers (including the graphical -installers on macOS and Windows), CPack generates installers that -allow users to select individual application components to install. -The contents of each of the components are identified by the COMPONENT -argument of CMake's INSTALL command. These components can be +Introduction +^^^^^^^^^^^^ + +This module is automatically included by :module:`CPack`. + +Certain binary installers (especially the graphical installers) generated +by CPack allow users to select individual application *components* to install. +This module allows developers to configure the packaging of such components. + +Contents is assigned to components by the ``COMPONENT`` +argument of CMake's :command:`install` command. Components can be annotated with user-friendly names and descriptions, inter-component dependencies, etc., and grouped in various ways to customize the -resulting installer. See the cpack_add_* commands, described below, -for more information about component-specific installations. +resulting installer, using the commands described below. + +To specify different groupings for different CPack generators use +a CPACK_PROJECT_CONFIG_FILE. -Component-specific installation allows users to select specific sets -of components to install during the install process. Installation -components are identified by the COMPONENT argument of CMake's INSTALL -commands, and should be further described by the following CPack -commands: +Variables +^^^^^^^^^ + +The following variables influence the component-specific packaging: .. variable:: CPACK_COMPONENTS_ALL @@ -61,16 +66,14 @@ commands: Specify how components are grouped for multi-package component-aware CPack generators. - Some generators like RPM or ARCHIVE family (TGZ, ZIP, ...) generates - several packages files when asked for component packaging. They group - the component differently depending on the value of this variable: - - * ONE_PER_GROUP (default): creates one package file per component group - * ALL_COMPONENTS_IN_ONE : creates a single package with all (requested) components - * IGNORE : creates one package per component, i.e. IGNORE component group + Some generators like RPM or ARCHIVE (TGZ, ZIP, ...) may generate + several packages files when there are components, depending + on the value of this variable: - One can specify different grouping for different CPack generator by - using a CPACK_PROJECT_CONFIG_FILE. + * ONE_PER_GROUP (default): create one package per component group + * IGNORE : create one package per component (ignore the groups) + * ALL_COMPONENTS_IN_ONE : create a single package with all requested + components .. variable:: CPACK_COMPONENT_<compName>_DISPLAY_NAME @@ -100,10 +103,15 @@ commands: True if this component is not selected to be installed by default. +Commands +^^^^^^^^ + +Add component +""""""""""""" + .. command:: cpack_add_component -Describes a CPack installation -component named by the COMPONENT argument to a CMake INSTALL command. +Describe an installation component. :: @@ -118,13 +126,11 @@ component named by the COMPONENT argument to a CMake INSTALL command. [ARCHIVE_FILE filename] [PLIST filename]) - - -The cmake_add_component command describes an installation component, -which the user can opt to install or remove as part of the graphical -installation process. compname is the name of the component, as -provided to the COMPONENT argument of one or more CMake INSTALL -commands. +``compname`` is the name of an installation component, as defined by the +``COMPONENT`` argument of one or more CMake :command:`install` commands. +With the ``cpack_add_component`` command one can set a name, a description, +and other attributes of an installation component. +One can also assign a component to a component group. DISPLAY_NAME is the displayed name of the component, used in graphical installers to display the component name. This value can be any @@ -177,6 +183,9 @@ the component. See cpack_configure_downloads for more information. PLIST gives a filename that is passed to pkgbuild with the ``--component-plist`` argument when using the productbuild generator. +Add component group +""""""""""""""""""" + .. command:: cpack_add_component_group Describes a group of related CPack installation components. @@ -225,6 +234,9 @@ single entry. BOLD_TITLE indicates that the group title should appear in bold, to call the user's attention to the group. +Add installation type +""""""""""""""""""""" + .. command:: cpack_add_install_type Add a new installation type containing @@ -249,6 +261,9 @@ DISPLAY_NAME is the displayed name of the install type, which will typically show up in a drop-down box within a graphical installer. This value can be any string. +Configure downloads +""""""""""""""""""" + .. command:: cpack_configure_downloads Configure CPack to download @@ -281,8 +296,6 @@ requires the ZipDLL plug-in for NSIS, available at: http://nsis.sourceforge.net/ZipDLL_plug-in - - On macOS, installers that download components on-the-fly can only be built and installed on system using macOS 10.5 or later. diff --git a/Modules/CTestCoverageCollectGCOV.cmake b/Modules/CTestCoverageCollectGCOV.cmake index ff48cc2..b1268be 100644 --- a/Modules/CTestCoverageCollectGCOV.cmake +++ b/Modules/CTestCoverageCollectGCOV.cmake @@ -37,6 +37,17 @@ After generating this tar file, it can be sent to CDash for display with the upload to CDash. Relative paths will be interpreted with respect to the top-level build directory. + ``TARBALL_COMPRESSION <option>`` Specify a compression algorithm for the + ``TARBALL`` data file. Using this option reduces the size of the data file + before it is submitted to CDash. ``<option>`` must be one of ``GZIP``, + ``BZIP2``, ``XZ``, ``ZSTD``, ``FROM_EXT``, or an expression that CMake + evaluates as ``FALSE``. The default value is ``BZIP2``. + + If ``FROM_EXT`` is specified, the resulting file will be compressed based on + the file extension of the ``<tarfile>`` (i.e. ``.tar.gz`` will use ``GZIP`` + compression). File extensions that will produce compressed output include + ``.tar.gz``, ``.tgz``, ``.tar.bzip2``, ``.tbz``, ``.tar.xz``, and ``.txz``. + ``SOURCE <source_dir>`` Specify the top-level source directory for the build. Default is the value of :variable:`CTEST_SOURCE_DIRECTORY`. @@ -68,7 +79,7 @@ After generating this tar file, it can be sent to CDash for display with the function(ctest_coverage_collect_gcov) set(options QUIET GLOB DELETE) - set(oneValueArgs TARBALL SOURCE BUILD GCOV_COMMAND) + set(oneValueArgs TARBALL SOURCE BUILD GCOV_COMMAND TARBALL_COMPRESSION) set(multiValueArgs GCOV_OPTIONS) cmake_parse_arguments(GCOV "${options}" "${oneValueArgs}" "${multiValueArgs}" "" ${ARGN} ) @@ -91,6 +102,13 @@ function(ctest_coverage_collect_gcov) else() set(gcov_command "${GCOV_GCOV_COMMAND}") endif() + if(NOT DEFINED GCOV_TARBALL_COMPRESSION) + set(GCOV_TARBALL_COMPRESSION "BZIP2") + elseif( GCOV_TARBALL_COMPRESSION AND + NOT GCOV_TARBALL_COMPRESSION MATCHES "^(GZIP|BZIP2|XZ|ZSTD|FROM_EXT)$") + message(FATAL_ERROR "TARBALL_COMPRESSION must be one of OFF, GZIP, " + "BZIP2, XZ, ZSTD, or FROM_EXT for ctest_coverage_collect_gcov") + endif() # run gcov on each gcda file in the binary tree set(gcda_files) set(label_files) @@ -137,11 +155,23 @@ function(ctest_coverage_collect_gcov) if(NOT DEFINED GCOV_GCOV_OPTIONS) set(GCOV_GCOV_OPTIONS -b -x) endif() + if (GCOV_QUIET) + set(coverage_out_opts + OUTPUT_QUIET + ERROR_QUIET + ) + else() + set(coverage_out_opts + OUTPUT_FILE "${coverage_dir}/gcov.log" + ERROR_FILE "${coverage_dir}/gcov.log" + ) + endif() execute_process(COMMAND ${gcov_command} ${GCOV_GCOV_OPTIONS} ${gcda_files} - OUTPUT_VARIABLE out RESULT_VARIABLE res - WORKING_DIRECTORY ${coverage_dir}) + WORKING_DIRECTORY ${coverage_dir} + ${coverage_out_opts} + ) if (GCOV_DELETE) file(REMOVE ${gcda_files}) @@ -149,7 +179,7 @@ function(ctest_coverage_collect_gcov) if(NOT "${res}" EQUAL 0) if (NOT GCOV_QUIET) - message(STATUS "Error running gcov: ${res} ${out}") + message(STATUS "Error running gcov: ${res}, see\n ${coverage_dir}/gcov.log") endif() endif() # create json file with project information @@ -258,14 +288,38 @@ ${label_files} ${uncovered_files_for_tar} ") - if (GCOV_QUIET) - set(tar_opts "cfj") - else() - set(tar_opts "cvfj") + # Prepare tar command line arguments + + set(tar_opts "") + # Select data compression mode + if( GCOV_TARBALL_COMPRESSION STREQUAL "FROM_EXT") + if( GCOV_TARBALL MATCHES [[\.(tgz|tar.gz)$]] ) + string(APPEND tar_opts "z") + elseif( GCOV_TARBALL MATCHES [[\.(txz|tar.xz)$]] ) + string(APPEND tar_opts "J") + elseif( GCOV_TARBALL MATCHES [[\.(tbz|tar.bz)$]] ) + string(APPEND tar_opts "j") + endif() + elseif(GCOV_TARBALL_COMPRESSION STREQUAL "GZIP") + string(APPEND tar_opts "z") + elseif(GCOV_TARBALL_COMPRESSION STREQUAL "XZ") + string(APPEND tar_opts "J") + elseif(GCOV_TARBALL_COMPRESSION STREQUAL "BZIP2") + string(APPEND tar_opts "j") + elseif(GCOV_TARBALL_COMPRESSION STREQUAL "ZSTD") + set(zstd_tar_opt "--zstd") + endif() + # Verbosity options + if(NOT GCOV_QUIET AND NOT tar_opts MATCHES v) + string(APPEND tar_opts "v") endif() + # Prepend option 'c' specifying 'create' + string(PREPEND tar_opts "c") + # Append option 'f' so that the next argument is the filename + string(APPEND tar_opts "f") execute_process(COMMAND - ${CMAKE_COMMAND} -E tar ${tar_opts} ${GCOV_TARBALL} + ${CMAKE_COMMAND} -E tar ${tar_opts} ${GCOV_TARBALL} ${zstd_tar_opt} "--mtime=1970-01-01 0:0:0 UTC" "--format=gnutar" --files-from=${coverage_dir}/coverage_file_list.txt diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index f0fde8d..3354bfb 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -103,8 +103,6 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) if(NOT _SRC_EXT) set(_SRC_EXT F) endif() - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") if(CMAKE_REQUIRED_LINK_OPTIONS) set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) @@ -132,10 +130,10 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) try_compile(${VAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + COMPILE_DEFINITIONS -D${VAR} ${CMAKE_REQUIRED_DEFINITIONS} ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" OUTPUT_VARIABLE OUTPUT) diff --git a/Modules/CheckFortranSourceRuns.cmake b/Modules/CheckFortranSourceRuns.cmake index a3e5d5d..f858b84 100644 --- a/Modules/CheckFortranSourceRuns.cmake +++ b/Modules/CheckFortranSourceRuns.cmake @@ -98,8 +98,6 @@ macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) if(NOT _SRC_EXT) set(_SRC_EXT F90) endif() - set(MACRO_CHECK_FUNCTION_DEFINITIONS - "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") if(CMAKE_REQUIRED_LINK_OPTIONS) set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}) @@ -127,10 +125,10 @@ macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR) try_run(${VAR}_EXITCODE ${VAR}_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT} - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + COMPILE_DEFINITIONS -D${VAR} ${CMAKE_REQUIRED_DEFINITIONS} ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS} ${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" COMPILE_OUTPUT_VARIABLE OUTPUT diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index 997cc8d..d67d8d3 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -43,11 +43,11 @@ macro(check_language lang) file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}) set(extra_compiler_variables) - if(lang STREQUAL CUDA) + if(${lang} STREQUAL CUDA) set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")") endif() - set(content + set(_cl_content "cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(Check${lang} ${lang}) file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" @@ -57,7 +57,7 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" ) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt" - "${content}") + "${_cl_content}") if(CMAKE_GENERATOR_INSTANCE) set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}") else() @@ -75,22 +75,22 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" -T "${CMAKE_GENERATOR_TOOLSET}" ${_D_CMAKE_GENERATOR_INSTANCE} ${_D_CMAKE_MAKE_PROGRAM} - OUTPUT_VARIABLE output - ERROR_VARIABLE output - RESULT_VARIABLE result + OUTPUT_VARIABLE _cl_output + ERROR_VARIABLE _cl_output + RESULT_VARIABLE _cl_result ) include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL) - if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0") + if(CMAKE_${lang}_COMPILER AND "${_cl_result}" STREQUAL "0") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "${_desc} passed with the following output:\n" - "${output}\n") + "${_cl_output}\n") set(_CHECK_COMPILER_STATUS CHECK_PASS) else() set(CMAKE_${lang}_COMPILER NOTFOUND) set(_CHECK_COMPILER_STATUS CHECK_FAIL) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${_desc} failed with the following output:\n" - "${output}\n") + "${_cl_output}\n") endif() message(${_CHECK_COMPILER_STATUS} "${CMAKE_${lang}_COMPILER}") set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler") diff --git a/Modules/CheckLinkerFlag.cmake b/Modules/CheckLinkerFlag.cmake new file mode 100644 index 0000000..beda5fe --- /dev/null +++ b/Modules/CheckLinkerFlag.cmake @@ -0,0 +1,81 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +CheckLinkerFlag +--------------- + +Check whether the compiler supports a given link flag. + +.. command:: check_linker_flag + + .. code-block:: cmake + + check_linker_flag(<lang> <flag> <var>) + +Check that the link ``<flag>`` is accepted by the ``<lang>`` compiler without +a diagnostic. Stores the result in an internal cache entry named ``<var>``. + +This command temporarily sets the ``CMAKE_REQUIRED_LINK_OPTIONS`` variable +and calls the ``check_<lang>_source_compiles`` macro from the +``Check<lang>SourceCompiles`` module (:module:`CheckCSourceCompiles`, +:module:`CheckCSourceCompiles`, :module:`CheckCXXSourceCompiles`, +:module:`CheckOBJCSourceCompiles`, :module:`CheckOBJCXXSourceCompiles` or +:module:`CheckFortranSourceCompiles`). See documentation of these +modules for a listing of variables that can otherwise modify the build. + +The underlying implementation rely on :prop_tgt:`LINK_OPTIONS` property to +check the specified flag. The ``LINKER:`` prefix, as described in +:command:`target_link_options` command, can be used as well. + +A positive result from this check indicates only that the compiler did not +issue a diagnostic message when given the link flag. Whether the flag has any +effect or even a specific one is beyond the scope of this module. + +.. note:: + Since the :command:`try_compile` command forwards flags from variables + like :variable:`CMAKE_<LANG>_FLAGS`, unknown flags in such variables may + cause a false negative for this check. +#]=======================================================================] + +include_guard(GLOBAL) + +include(CMakeCheckCompilerFlagCommonPatterns) + +function(CHECK_LINKER_FLAG _lang _flag _var) + get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT _lang IN_LIST _supported_languages) + message (SEND_ERROR "check_linker_flag: ${_lang}: unknown language.") + return() + endif() + + include (Check${_lang}SourceCompiles) + + set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}") + + # Normalize locale during test compilation. + set(_locale_vars LC_ALL LC_MESSAGES LANG) + foreach(v IN LISTS _locale_vars) + set(_locale_vars_saved_${v} "$ENV{${v}}") + set(ENV{${v}} C) + endforeach() + + if (_lang MATCHES "^(C|CXX)$") + set (_source "int main() { return 0; }") + elseif (_lang STREQUAL "Fortran") + set (_source " program test\n stop\n end program") + elseif (_lang MATCHES "^(OBJC|OBJCXX)$") + set (_source "#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }") + else() + message (SEND_ERROR "check_linker_flag: ${_lang}: unsupported language.") + return() + endif() + check_compiler_flag_common_patterns(_common_patterns) + + cmake_language (CALL check_${_lang}_source_compiles "${_source}" ${_var} ${_common_patterns}) + + foreach(v IN LISTS _locale_vars) + set(ENV{${v}} ${_locale_vars_saved_${v}}) + endforeach() + set(${_var} "${${_var}}" PARENT_SCOPE) +endfunction() diff --git a/Modules/CheckTypeSize.c.in b/Modules/CheckTypeSize.c.in index 82035a3..fb93073 100644 --- a/Modules/CheckTypeSize.c.in +++ b/Modules/CheckTypeSize.c.in @@ -5,10 +5,14 @@ # define KEY '_','_','i','3','8','6' #elif defined(__x86_64) # define KEY '_','_','x','8','6','_','6','4' -#elif defined(__ppc__) -# define KEY '_','_','p','p','c','_','_' +#elif defined(__PPC64__) +# define KEY '_','_','P','P','C','6','4','_','_' #elif defined(__ppc64__) # define KEY '_','_','p','p','c','6','4','_','_' +#elif defined(__PPC__) +# define KEY '_','_','P','P','C','_','_' +#elif defined(__ppc__) +# define KEY '_','_','p','p','c','_','_' #elif defined(__aarch64__) # define KEY '_','_','a','a','r','c','h','6','4','_','_' #elif defined(__ARM_ARCH_7A__) diff --git a/Modules/Compiler/Absoft-Fortran.cmake b/Modules/Compiler/Absoft-Fortran.cmake index 76502dc..8724f85 100644 --- a/Modules/Compiler/Absoft-Fortran.cmake +++ b/Modules/Compiler/Absoft-Fortran.cmake @@ -9,3 +9,5 @@ set(CMAKE_Fortran_VERBOSE_FLAG "-v") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree") set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-X") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-no-cpp") diff --git a/Modules/Compiler/Clang-CUDA.cmake b/Modules/Compiler/Clang-CUDA.cmake new file mode 100644 index 0000000..a970985 --- /dev/null +++ b/Modules/Compiler/Clang-CUDA.cmake @@ -0,0 +1,25 @@ +include(Compiler/Clang) +__compiler_clang(CUDA) + +# C++03 isn't supported for CXX, but is for CUDA, so we need to set these manually. +# Do this before __compiler_clang_cxx_standards() since that adds the feature. +set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03") +set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=gnu++03") +__compiler_clang_cxx_standards(CUDA) + +set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE TRUE) +set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cuda") +set(_CMAKE_CUDA_PTX_FLAG "--cuda-device-only -S") + +# RulePlaceholderExpander expands crosscompile variables like sysroot and target only for CMAKE_<LANG>_COMPILER. Override the default. +set(CMAKE_CUDA_LINK_EXECUTABLE "<CMAKE_CUDA_COMPILER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}") +set(CMAKE_CUDA_CREATE_SHARED_LIBRARY "<CMAKE_CUDA_COMPILER> <CMAKE_SHARED_LIBRARY_CUDA_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>${__IMPLICT_LINKS}") + +set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC") +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) + list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") +endif() diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake index cb240f9..789e991 100644 --- a/Modules/Compiler/Clang-CXX.cmake +++ b/Modules/Compiler/Clang-CXX.cmake @@ -1,5 +1,6 @@ include(Compiler/Clang) __compiler_clang(CXX) +__compiler_clang_cxx_standards(CXX) if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") @@ -13,121 +14,3 @@ endif() if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl") endif() - -if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") - endif() - - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1) - 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) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") - endif() - - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) - 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) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") - set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON) - endif() - - set(_clang_version_std17 5.0) - if(CMAKE_SYSTEM_NAME STREQUAL "Android") - set(_clang_version_std17 6.0) - endif() - - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") - endif() - - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") - set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a") - set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a") - endif() - - unset(_clang_version_std17) - - if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") - # The MSVC standard library requires C++14, and MSVC itself has no - # notion of operating in a mode not aware of at least that standard. - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++14") - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++14") - - # This clang++ is missing some features because of MSVC compatibility. - unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT) - unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT) - unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT) - unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT) - endif() - - __compiler_check_default_language_standard(CXX 2.1 98) -elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9 - AND CMAKE_CXX_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0) - # This version of clang-cl and the MSVC version it simulates have - # support for -std: flags. - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std:c++14") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std:c++14") - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++17") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++17") - set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest") - set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std:c++latest") - else() - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++latest") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++latest") - endif() - - __compiler_check_default_language_standard(CXX 3.9 14) -else() - # This version of clang-cl, or the MSVC version it simulates, does not have - # language standards. Set these options as empty strings so the feature - # test infrastructure can at least check to see if they are defined. - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "") - set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "") - set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "") - - # There is no meaningful default for this - set(CMAKE_CXX_STANDARD_DEFAULT "") - - # There are no compiler modes so we only need to test features once. - # Override the default macro for this special case. Pretend that - # all language standards are available so that at least compilation - # can be attempted. - macro(cmake_record_cxx_compile_features) - list(APPEND CMAKE_CXX_COMPILE_FEATURES - cxx_std_98 - cxx_std_11 - cxx_std_14 - cxx_std_17 - cxx_std_20 - ) - _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES) - endmacro() -endif() diff --git a/Modules/Compiler/Clang-OBJCXX.cmake b/Modules/Compiler/Clang-OBJCXX.cmake index b01ce64..453b5fd 100644 --- a/Modules/Compiler/Clang-OBJCXX.cmake +++ b/Modules/Compiler/Clang-OBJCXX.cmake @@ -1,70 +1,3 @@ include(Compiler/Clang) __compiler_clang(OBJCXX) - -if("x${CMAKE_OBJCXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") - if(NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_OBJCXX98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_OBJCXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") - endif() - - if(NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 3.1) - set(CMAKE_OBJCXX98_STANDARD__HAS_FULL_SUPPORT ON) - set(CMAKE_OBJCXX11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_OBJCXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") - set(CMAKE_OBJCXX11_STANDARD__HAS_FULL_SUPPORT ON) - elseif(NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_OBJCXX11_STANDARD_COMPILE_OPTION "-std=c++0x") - set(CMAKE_OBJCXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") - endif() - - if(NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 3.5) - set(CMAKE_OBJCXX14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_OBJCXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14") - set(CMAKE_OBJCXX14_STANDARD__HAS_FULL_SUPPORT ON) - elseif(NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 3.4) - set(CMAKE_OBJCXX14_STANDARD_COMPILE_OPTION "-std=c++1y") - set(CMAKE_OBJCXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") - set(CMAKE_OBJCXX14_STANDARD__HAS_FULL_SUPPORT ON) - endif() - - set(_clang_version_std17 5.0) - - if (NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") - set(CMAKE_OBJCXX17_STANDARD_COMPILE_OPTION "-std=c++17") - set(CMAKE_OBJCXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17") - elseif (NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS 3.5) - set(CMAKE_OBJCXX17_STANDARD_COMPILE_OPTION "-std=c++1z") - set(CMAKE_OBJCXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") - endif() - - if (NOT CMAKE_OBJCXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") - set(CMAKE_OBJCXX20_STANDARD_COMPILE_OPTION "-std=c++2a") - set(CMAKE_OBJCXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a") - endif() - - unset(_clang_version_std17) - - __compiler_check_default_language_standard(OBJCXX 2.1 98) -elseif(CMAKE_OBJCXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9 - AND CMAKE_OBJCXX_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0) - # This version of clang-cl and the MSVC version it simulates have - # support for -std: flags. - set(CMAKE_OBJCXX98_STANDARD_COMPILE_OPTION "") - set(CMAKE_OBJCXX98_EXTENSION_COMPILE_OPTION "") - set(CMAKE_OBJCXX98_STANDARD__HAS_FULL_SUPPORT ON) - set(CMAKE_OBJCXX11_STANDARD_COMPILE_OPTION "") - set(CMAKE_OBJCXX11_EXTENSION_COMPILE_OPTION "") - set(CMAKE_OBJCXX14_STANDARD_COMPILE_OPTION "-std:c++14") - set(CMAKE_OBJCXX14_EXTENSION_COMPILE_OPTION "-std:c++14") - if (CMAKE_OBJCXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) - set(CMAKE_OBJCXX17_STANDARD_COMPILE_OPTION "-std:c++17") - set(CMAKE_OBJCXX17_EXTENSION_COMPILE_OPTION "-std:c++17") - set(CMAKE_OBJCXX20_STANDARD_COMPILE_OPTION "-std:c++latest") - set(CMAKE_OBJCXX20_EXTENSION_COMPILE_OPTION "-std:c++latest") - else() - set(CMAKE_OBJCXX17_STANDARD_COMPILE_OPTION "-std:c++latest") - set(CMAKE_OBJCXX17_EXTENSION_COMPILE_OPTION "-std:c++latest") - endif() - - __compiler_check_default_language_standard(OBJCXX 3.9 14) -endif() +__compiler_clang_cxx_standards(OBJCXX) diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index f65916f..cd47aa6 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -105,3 +105,123 @@ else() set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER>) endmacro() endif() + +macro(__compiler_clang_cxx_standards lang) + if("x${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 2.1) + set(CMAKE_${lang}98_STANDARD_COMPILE_OPTION "-std=c++98") + set(CMAKE_${lang}98_EXTENSION_COMPILE_OPTION "-std=gnu++98") + endif() + + if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.1) + set(CMAKE_${lang}98_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "-std=gnu++11") + set(CMAKE_${lang}11_STANDARD__HAS_FULL_SUPPORT ON) + elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 2.1) + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "-std=c++0x") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") + endif() + + if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.5) + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "-std=gnu++14") + set(CMAKE_${lang}14_STANDARD__HAS_FULL_SUPPORT ON) + elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4) + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "-std=c++1y") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") + set(CMAKE_${lang}14_STANDARD__HAS_FULL_SUPPORT ON) + endif() + + set(_clang_version_std17 5.0) + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(_clang_version_std17 6.0) + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std=c++17") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std=gnu++17") + elseif (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.5) + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std=c++1z") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") + endif() + + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}") + set(CMAKE_${lang}20_STANDARD_COMPILE_OPTION "-std=c++2a") + set(CMAKE_${lang}20_EXTENSION_COMPILE_OPTION "-std=gnu++2a") + endif() + + unset(_clang_version_std17) + + if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") + # The MSVC standard library requires C++14, and MSVC itself has no + # notion of operating in a mode not aware of at least that standard. + set(CMAKE_${lang}98_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_${lang}98_EXTENSION_COMPILE_OPTION "-std=gnu++14") + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "-std=gnu++14") + + # This clang++ is missing some features because of MSVC compatibility. + unset(CMAKE_${lang}11_STANDARD__HAS_FULL_SUPPORT) + unset(CMAKE_${lang}14_STANDARD__HAS_FULL_SUPPORT) + unset(CMAKE_${lang}17_STANDARD__HAS_FULL_SUPPORT) + unset(CMAKE_${lang}20_STANDARD__HAS_FULL_SUPPORT) + endif() + + __compiler_check_default_language_standard(${lang} 2.1 98) + elseif(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9 + AND CMAKE_${lang}_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0) + # This version of clang-cl and the MSVC version it simulates have + # support for -std: flags. + set(CMAKE_${lang}98_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}98_STANDARD__HAS_FULL_SUPPORT ON) + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "-std:c++14") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "-std:c++14") + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std:c++17") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std:c++17") + set(CMAKE_${lang}20_STANDARD_COMPILE_OPTION "-std:c++latest") + set(CMAKE_${lang}20_EXTENSION_COMPILE_OPTION "-std:c++latest") + else() + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "-std:c++latest") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "-std:c++latest") + endif() + + __compiler_check_default_language_standard(${lang} 3.9 14) + else() + # This version of clang-cl, or the MSVC version it simulates, does not have + # language standards. Set these options as empty strings so the feature + # test infrastructure can at least check to see if they are defined. + set(CMAKE_${lang}98_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}11_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}11_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}14_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}14_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}17_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}17_EXTENSION_COMPILE_OPTION "") + set(CMAKE_${lang}20_STANDARD_COMPILE_OPTION "") + set(CMAKE_${lang}20_EXTENSION_COMPILE_OPTION "") + + # There is no meaningful default for this + set(CMAKE_${lang}_STANDARD_DEFAULT "") + + # There are no compiler modes so we only need to test features once. + # Override the default macro for this special case. Pretend that + # all language standards are available so that at least compilation + # can be attempted. + macro(cmake_record_${lang}_compile_features) + list(APPEND CMAKE_${lang}_COMPILE_FEATURES + ${lang}_std_98 + ${lang}_std_11 + ${lang}_std_14 + ${lang}_std_17 + ${lang}_std_20 + ) + _record_compiler_features(${lang} "" CMAKE_${lang}_COMPILE_FEATURES) + endmacro() + endif() +endmacro() diff --git a/Modules/Compiler/Cray-Fortran.cmake b/Modules/Compiler/Cray-Fortran.cmake index ccb7c2e..696ae76 100644 --- a/Modules/Compiler/Cray-Fortran.cmake +++ b/Modules/Compiler/Cray-Fortran.cmake @@ -11,3 +11,11 @@ set(CMAKE_Fortran_MODDIR_FLAG -J) set(CMAKE_Fortran_MODDIR_DEFAULT .) set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-f fixed") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-f free") + +if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.5) + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-eT") + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-dT") +else() + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-eZ") + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-dZ") +endif() diff --git a/Modules/Compiler/Flang-Fortran.cmake b/Modules/Compiler/Flang-Fortran.cmake index f0e61d8..de0484e 100644 --- a/Modules/Compiler/Flang-Fortran.cmake +++ b/Modules/Compiler/Flang-Fortran.cmake @@ -11,3 +11,6 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") set(CMAKE_Fortran_MODDIR_FLAG "-J") + +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") diff --git a/Modules/Compiler/G95-Fortran.cmake b/Modules/Compiler/G95-Fortran.cmake index 03b7e08..5dba04e 100644 --- a/Modules/Compiler/G95-Fortran.cmake +++ b/Modules/Compiler/G95-Fortran.cmake @@ -9,3 +9,5 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,") set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-no-cpp") diff --git a/Modules/Compiler/GNU-ASM.cmake b/Modules/Compiler/GNU-ASM.cmake index e07401d..3daa57d 100644 --- a/Modules/Compiler/GNU-ASM.cmake +++ b/Modules/Compiler/GNU-ASM.cmake @@ -4,3 +4,9 @@ include(Compiler/GNU) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm) __compiler_gnu(ASM) + +if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_MATCH STREQUAL "GNU assembler") + set(CMAKE_DEPFILE_FLAGS_ASM${ASM_DIALECT} "--MD <DEPFILE>") + set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE + "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") +endif() diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake index 6413769..5dfb03e 100644 --- a/Modules/Compiler/GNU-Fortran.cmake +++ b/Modules/Compiler/GNU-Fortran.cmake @@ -10,6 +10,11 @@ set(CMAKE_Fortran_PREPROCESS_SOURCE set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") +if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 4.4) + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") +endif() + set(CMAKE_Fortran_POSTPROCESS_FLAG "-fpreprocessed") # No -DNDEBUG for Fortran. diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 1c050a2..df6d6b8 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -44,7 +44,8 @@ macro(__compiler_gnu lang) # tests to always succeed. Work around this by disabling dependency tracking # in try_compile mode. get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE) - if(NOT _IN_TC OR CMAKE_FORCE_DEPFILES) + if(CMAKE_${lang}_COMPILER_ID STREQUAL "GNU" AND _IN_TC AND NOT CMAKE_FORCE_DEPFILES) + else() # distcc does not transform -o to -MT when invoking the preprocessor # internally, as it ought to. Work around this bug by setting -MT here # even though it isn't strictly necessary. @@ -114,6 +115,7 @@ macro(__compiler_gnu lang) if (NOT CMAKE_GENERATOR MATCHES "Xcode") set(CMAKE_PCH_PROLOGUE "#pragma GCC system_header") endif() - set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Winvalid-pch -include <PCH_HEADER>) - set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Winvalid-pch -x ${__pch_header_${lang}} -include <PCH_HEADER>) + set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch) + set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -include <PCH_HEADER>) + set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -x ${__pch_header_${lang}} -include <PCH_HEADER>) endmacro() diff --git a/Modules/Compiler/HP-Fortran.cmake b/Modules/Compiler/HP-Fortran.cmake index 63a0331..d3e2a30 100644 --- a/Modules/Compiler/HP-Fortran.cmake +++ b/Modules/Compiler/HP-Fortran.cmake @@ -7,3 +7,6 @@ set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,") set(CMAKE_Fortran_LINKER_WRAPPER_FLAG ",") + +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "+cpp=yes") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "+cpp=no") diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake index 8e75caa..296e2fd 100644 --- a/Modules/Compiler/IAR.cmake +++ b/Modules/Compiler/IAR.cmake @@ -1,6 +1,6 @@ # This file is processed when the IAR compiler is used for a C or C++ file # Documentation can be downloaded here: http://www.iar.com/website1/1.0.1.0/675/1/ -# The initial feature request is here: https://gitlab.kitware.com/cmake/cmake/issues/10176 +# The initial feature request is here: https://gitlab.kitware.com/cmake/cmake/-/issues/10176 # It also contains additional links and information. # See USER GUIDES -> C/C++ Development Guide and ReleaseNotes for EWARM: # version 6.30.8: http://supp.iar.com/FilesPublic/UPDINFO/006607/arm/doc/infocenter/index.ENU.html diff --git a/Modules/Compiler/Intel-Fortran.cmake b/Modules/Compiler/Intel-Fortran.cmake index 156b533..71f25f4 100644 --- a/Modules/Compiler/Intel-Fortran.cmake +++ b/Modules/Compiler/Intel-Fortran.cmake @@ -15,3 +15,5 @@ set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <IN set(CMAKE_Fortran_PREPROCESS_SOURCE "<CMAKE_Fortran_COMPILER> -fpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nofpp") diff --git a/Modules/Compiler/Intel.cmake b/Modules/Compiler/Intel.cmake index d895ed0..63a20af 100644 --- a/Modules/Compiler/Intel.cmake +++ b/Modules/Compiler/Intel.cmake @@ -37,7 +37,8 @@ else() set(CMAKE_PCH_EXTENSION .pchi) set(CMAKE_LINK_PCH ON) set(CMAKE_PCH_EPILOGUE "#pragma hdrstop") - set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Winvalid-pch -Wno-pch-messages -pch-use <PCH_FILE> -include <PCH_HEADER>) - set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Winvalid-pch -Wno-pch-messages -pch-create <PCH_FILE> -include <PCH_HEADER>) + set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch) + set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Wno-pch-messages -pch-use <PCH_FILE> -include <PCH_HEADER>) + set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Wno-pch-messages -pch-create <PCH_FILE> -include <PCH_HEADER>) endmacro() endif() diff --git a/Modules/Compiler/NAG-Fortran.cmake b/Modules/Compiler/NAG-Fortran.cmake index 2111c65..ffce97e 100644 --- a/Modules/Compiler/NAG-Fortran.cmake +++ b/Modules/Compiler/NAG-Fortran.cmake @@ -37,3 +37,4 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free") set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC") set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "-PIC") set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-Wl,@") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp") diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index 1f4d54d..87607e2 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -4,6 +4,9 @@ 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_PTX_FLAG "-ptx") + 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 @@ -43,11 +46,27 @@ endif() set(CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS -shared) set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA -isystem=) -set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC") +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) + list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") +endif() + if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC") set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "") set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "") diff --git a/Modules/Compiler/NVIDIA-DetermineCompiler.cmake b/Modules/Compiler/NVIDIA-DetermineCompiler.cmake index bf9111a..4f6ddc2 100644 --- a/Modules/Compiler/NVIDIA-DetermineCompiler.cmake +++ b/Modules/Compiler/NVIDIA-DetermineCompiler.cmake @@ -11,9 +11,19 @@ set(_compiler_id_version_compute " /* _MSC_VER = VVRR */ # define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100) # define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(_MSC_VER % 100) +# elif defined(__clang__) +# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__clang_major__) +# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(__clang_minor__) +# elif defined(__GNUC__) +# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__GNUC__) +# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(__GNUC_MINOR__) # endif") set(_compiler_id_simulate " # if defined(_MSC_VER) # define @PREFIX@SIMULATE_ID \"MSVC\" +# elif defined(__clang__) +# define @PREFIX@SIMULATE_ID \"Clang\" +# elif defined(__GNUC__) +# define @PREFIX@SIMULATE_ID \"GNU\" # endif") diff --git a/Modules/Compiler/OpenWatcom-C.cmake b/Modules/Compiler/OpenWatcom-C.cmake new file mode 100644 index 0000000..19e3359 --- /dev/null +++ b/Modules/Compiler/OpenWatcom-C.cmake @@ -0,0 +1 @@ +include(Compiler/OpenWatcom) diff --git a/Modules/Compiler/OpenWatcom-CXX.cmake b/Modules/Compiler/OpenWatcom-CXX.cmake new file mode 100644 index 0000000..19e3359 --- /dev/null +++ b/Modules/Compiler/OpenWatcom-CXX.cmake @@ -0,0 +1 @@ +include(Compiler/OpenWatcom) diff --git a/Modules/Compiler/OpenWatcom.cmake b/Modules/Compiler/OpenWatcom.cmake new file mode 100644 index 0000000..9efbfc2 --- /dev/null +++ b/Modules/Compiler/OpenWatcom.cmake @@ -0,0 +1,118 @@ +# 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. +include_guard() + +set(CMAKE_LIBRARY_PATH_FLAG "libpath ") +set(CMAKE_LINK_LIBRARY_FLAG "library ") +set(CMAKE_LINK_LIBRARY_FILE_FLAG "library ") + +if(CMAKE_VERBOSE_MAKEFILE) + set(CMAKE_WCL_QUIET) + set(CMAKE_WLINK_QUIET) + set(CMAKE_LIB_QUIET) +else() + set(CMAKE_WCL_QUIET "-zq") + set(CMAKE_WLINK_QUIET "option quiet") + set(CMAKE_LIB_QUIET "-q") +endif() + +foreach(type CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE) + set(CMAKE_C_${type}_USE_WATCOM_QUOTE 1) + set(CMAKE_CXX_${type}_USE_WATCOM_QUOTE 1) +endforeach() + +foreach(type SHARED MODULE EXE) + # linker map file creation directives + string(APPEND CMAKE_${type}_LINKER_FLAGS_INIT " opt map") + # linker debug directives + string(APPEND CMAKE_${type}_LINKER_FLAGS_DEBUG_INIT " debug all") + string(APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO_INIT " debug all") +endforeach() + +foreach(lang C CXX) + # warning level + string(APPEND CMAKE_${lang}_FLAGS_INIT " -w3") + # debug options + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -d2") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -s -os -d0 -dNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -s -ot -d0 -dNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -s -ot -d1 -dNDEBUG") +endforeach() + +# C create import library +set(CMAKE_C_CREATE_IMPORT_LIBRARY + "wlib -c -q -n -b <TARGET_IMPLIB> +<TARGET_QUOTED>") +# C++ create import library +set(CMAKE_CXX_CREATE_IMPORT_LIBRARY ${CMAKE_C_CREATE_IMPORT_LIBRARY}) + +# C link a object files into an executable file +set(CMAKE_C_LINK_EXECUTABLE + "wlink ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> file {<OBJECTS>} <LINK_LIBRARIES>") +# C++ link a object files into an executable file +set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE}) + +# C compile a file into an object file +set(CMAKE_C_COMPILE_OBJECT + "<CMAKE_C_COMPILER> ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<OBJECT> -c -cc <SOURCE>") +# C++ compile a file into an object file +set(CMAKE_CXX_COMPILE_OBJECT + "<CMAKE_CXX_COMPILER> ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<OBJECT> -c -cc++ <SOURCE>") + +# C preprocess a source file +set(CMAKE_C_CREATE_PREPROCESSED_SOURCE + "<CMAKE_C_COMPILER> ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<PREPROCESSED_SOURCE> -pl -cc <SOURCE>") +# C++ preprocess a source file +set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE + "<CMAKE_CXX_COMPILER> ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<PREPROCESSED_SOURCE> -pl -cc++ <SOURCE>") + +# C create a shared library +set(CMAKE_C_CREATE_SHARED_LIBRARY + "wlink ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> option implib=<TARGET_IMPLIB> file {<OBJECTS>} <LINK_LIBRARIES>") +# C++ create a shared library +set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY}) + +# C create a shared module +set(CMAKE_C_CREATE_SHARED_MODULE + "wlink ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> file {<OBJECTS>} <LINK_LIBRARIES>") +# C++ create a shared module +set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_MODULE}) + +# C create a static library +set(CMAKE_C_CREATE_STATIC_LIBRARY + "wlib ${CMAKE_LIB_QUIET} -c -n -b <TARGET_QUOTED> <LINK_FLAGS> <OBJECTS> ") +# C++ create a static library +set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY}) + + +# old CMake internaly used OpenWatcom version macros +# for backward compatibility +if(NOT _CMAKE_WATCOM_VERSION) + set(_CMAKE_WATCOM_VERSION 1) + if(CMAKE_C_COMPILER_VERSION) + set(_compiler_version ${CMAKE_C_COMPILER_VERSION}) + set(_compiler_id ${CMAKE_C_COMPILER_ID}) + else() + set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION}) + set(_compiler_id ${CMAKE_CXX_COMPILER_ID}) + endif() + set(WATCOM16) + set(WATCOM17) + set(WATCOM18) + set(WATCOM19) + if("${_compiler_id}" STREQUAL "OpenWatcom") + if("${_compiler_version}" VERSION_LESS 1.7) + set(WATCOM16 1) + endif() + if("${_compiler_version}" VERSION_EQUAL 1.7) + set(WATCOM17 1) + endif() + if("${_compiler_version}" VERSION_EQUAL 1.8) + set(WATCOM18 1) + endif() + if("${_compiler_version}" VERSION_EQUAL 1.9) + set(WATCOM19 1) + endif() + endif() +endif() diff --git a/Modules/Compiler/PGI-Fortran.cmake b/Modules/Compiler/PGI-Fortran.cmake index 3daf798..ff87577 100644 --- a/Modules/Compiler/PGI-Fortran.cmake +++ b/Modules/Compiler/PGI-Fortran.cmake @@ -6,6 +6,7 @@ set(CMAKE_Fortran_SUBMODULE_EXT ".mod") set(CMAKE_Fortran_PREPROCESS_SOURCE "<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-Mpreprocess") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-Mnofreeform") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-Mfreeform") diff --git a/Modules/Compiler/PathScale-Fortran.cmake b/Modules/Compiler/PathScale-Fortran.cmake index d903621..891d93e 100644 --- a/Modules/Compiler/PathScale-Fortran.cmake +++ b/Modules/Compiler/PathScale-Fortran.cmake @@ -4,3 +4,6 @@ __compiler_pathscale(Fortran) set(CMAKE_Fortran_MODDIR_FLAG "-module ") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixedform") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-freeform") + +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") diff --git a/Modules/Compiler/QCC-CXX.cmake b/Modules/Compiler/QCC-CXX.cmake index 0e7314a..42303f4 100644 --- a/Modules/Compiler/QCC-CXX.cmake +++ b/Modules/Compiler/QCC-CXX.cmake @@ -10,6 +10,6 @@ set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -lang-c++ <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_CXX_COMPILER> -lang-c++ <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CXX_COMPILER> -lang-c++ <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake index 0c93c94..0ba5015 100644 --- a/Modules/Compiler/SunPro-Fortran.cmake +++ b/Modules/Compiler/SunPro-Fortran.cmake @@ -30,3 +30,5 @@ set(CMAKE_Fortran_PREPROCESS_SOURCE set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -F -fpp <SOURCE> -o <PREPROCESSED_SOURCE>") set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>") + +set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp") diff --git a/Modules/Compiler/TI-C.cmake b/Modules/Compiler/TI-C.cmake index 1c0f4bc..b060ee9 100644 --- a/Modules/Compiler/TI-C.cmake +++ b/Modules/Compiler/TI-C.cmake @@ -14,5 +14,9 @@ set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> --compile_only --skip_ass set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> --preproc_only --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>") set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> --compile_only --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") -set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>") -set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") +set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>") +set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>") +set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET_NAME>.map <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") +set(CMAKE_ASM_RESPONSE_FILE_FLAG "--cmd_file=") +set(CMAKE_C_RESPONSE_FILE_FLAG "--cmd_file=") +set(CMAKE_C_RESPONSE_FILE_LINK_FLAG " ") diff --git a/Modules/Compiler/TI-CXX.cmake b/Modules/Compiler/TI-CXX.cmake index 4c6af06..7836543 100644 --- a/Modules/Compiler/TI-CXX.cmake +++ b/Modules/Compiler/TI-CXX.cmake @@ -8,5 +8,8 @@ set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> --compile_only --skip set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> --preproc_only --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>") set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> --compile_only --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<OBJECT>") -set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -r <TARGET> <OBJECTS>") -set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>") +set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>") +set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>") +set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET_NAME>.map <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") +set(CMAKE_CXX_RESPONSE_FILE_FLAG "--cmd_file=") +set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG " ") diff --git a/Modules/Compiler/XL-Fortran.cmake b/Modules/Compiler/XL-Fortran.cmake index 1683dff..cc15e65 100644 --- a/Modules/Compiler/XL-Fortran.cmake +++ b/Modules/Compiler/XL-Fortran.cmake @@ -8,6 +8,7 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-qfixed") # [=<right_margin>] set(CMAKE_Fortran_FORMAT_FREE_FLAG "-qfree") # [=f90|ibm] set(CMAKE_Fortran_MODDIR_FLAG "-qmoddir=") +set(CMAKE_Fortran_MODDIR_INCLUDE_FLAG "-I") # -qmoddir= does not affect search path set(CMAKE_Fortran_DEFINE_FLAG "-WF,-D") @@ -22,3 +23,8 @@ set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE) set(CMAKE_Fortran_PREPROCESS_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -qpreprocess -qnoobject -qsuppress=1517-020 -tF -B \"${CMAKE_CURRENT_LIST_DIR}/XL-Fortran/\" -WF,--cpp,\"${CMAKE_Fortran_XL_CPP}\",--out,<PREPROCESSED_SOURCE> <SOURCE>" ) + +if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 15.1.6) + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-qpreprocess") + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-qnopreprocess") +endif() diff --git a/Modules/Documentation.cmake b/Modules/Documentation.cmake index aaf24f6..c297231 100644 --- a/Modules/Documentation.cmake +++ b/Modules/Documentation.cmake @@ -9,6 +9,30 @@ This module provides support for the VTK documentation framework. It relies on several tools (Doxygen, Perl, etc). #]=======================================================================] +cmake_policy(GET CMP0106 _Documentation_policy) + +if (_Documentation_policy STREQUAL "NEW") + message(FATAL_ERROR + "Documentation.cmake is VTK-specific code and should not be used in " + "non-VTK projects. This logic in this module is best shipped with the " + "project using it rather than with CMake. This is now an error according " + "to policy CMP0106.") +else () + +if (_Documentation_policy STREQUAL "") + # Ignore the warning if the project is detected as VTK itself. + if (NOT CMAKE_PROJECT_NAME STREQUAL "VTK" AND + NOT PROJECT_NAME STREQUAL "VTK") + cmake_policy(GET_WARNING CMP0106 _Documentation_policy_warning) + message(AUTHOR_WARNING + "${_Documentation_policy_warning}\n" + "Documentation.cmake is VTK-specific code and should not be used in " + "non-VTK projects. This logic in this module is best shipped with the " + "project using it rather than with CMake.") + endif () + unset(_Documentation_policy_warning) +endif () + # # Build the documentation ? # @@ -44,3 +68,7 @@ if (BUILD_DOCUMENTATION) # endif () + +endif () + +unset(_Documentation_policy) diff --git a/Modules/ExternalProject-gitupdate.cmake.in b/Modules/ExternalProject-gitupdate.cmake.in new file mode 100644 index 0000000..e993c3c --- /dev/null +++ b/Modules/ExternalProject-gitupdate.cmake.in @@ -0,0 +1,205 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +cmake_minimum_required(VERSION 3.5) + +execute_process( + COMMAND "@git_EXECUTABLE@" rev-list --max-count=1 HEAD + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + OUTPUT_VARIABLE head_sha + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +if(error_code) + message(FATAL_ERROR "Failed to get the hash for HEAD") +endif() + +execute_process( + COMMAND "@git_EXECUTABLE@" show-ref "@git_tag@" + WORKING_DIRECTORY "@work_dir@" + OUTPUT_VARIABLE show_ref_output + ) +# If a remote ref is asked for, which can possibly move around, +# we must always do a fetch and checkout. +if("${show_ref_output}" MATCHES "remotes") + set(is_remote_ref 1) +else() + set(is_remote_ref 0) +endif() + +# Tag is in the form <remote>/<tag> (i.e. origin/master) we must strip +# the remote from the tag. +if("${show_ref_output}" MATCHES "refs/remotes/@git_tag@") + string(REGEX MATCH "^([^/]+)/(.+)$" _unused "@git_tag@") + set(git_remote "${CMAKE_MATCH_1}") + set(git_tag "${CMAKE_MATCH_2}") +else() + set(git_remote "@git_remote_name@") + set(git_tag "@git_tag@") +endif() + +# This will fail if the tag does not exist (it probably has not been fetched +# yet). +execute_process( + COMMAND "@git_EXECUTABLE@" rev-list --max-count=1 "${git_tag}" + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + OUTPUT_VARIABLE tag_sha + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +# Is the hash checkout out that we want? +if(error_code OR is_remote_ref OR NOT ("${tag_sha}" STREQUAL "${head_sha}")) + execute_process( + COMMAND "@git_EXECUTABLE@" fetch + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Failed to fetch repository '@git_repository@'") + endif() + + if(is_remote_ref AND NOT "@git_update_strategy@" STREQUAL "CHECKOUT") + # Check if stash is needed + execute_process( + COMMAND "@git_EXECUTABLE@" status --porcelain + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + OUTPUT_VARIABLE repo_status + ) + if(error_code) + message(FATAL_ERROR "Failed to get the status") + endif() + string(LENGTH "${repo_status}" need_stash) + + # If not in clean state, stash changes in order to be able to be able to + # perform git pull --rebase + if(need_stash) + execute_process( + COMMAND "@git_EXECUTABLE@" stash save @git_stash_save_options@ + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Failed to stash changes") + endif() + endif() + + # Pull changes from the remote branch + execute_process( + COMMAND "@git_EXECUTABLE@" rebase "${git_remote}/${git_tag}" + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + OUTPUT_VARIABLE rebase_output + ERROR_VARIABLE rebase_output + ) + if(error_code) + # Rebase failed, undo the rebase attempt before continuing + execute_process( + COMMAND "@git_EXECUTABLE@" rebase --abort + WORKING_DIRECTORY "@work_dir@" + ) + + if(NOT "@git_update_strategy@" STREQUAL "REBASE_CHECKOUT") + # Not allowed to do a checkout as a fallback, so cannot proceed + if(need_stash) + execute_process( + COMMAND "@git_EXECUTABLE@" stash pop --index --quiet + WORKING_DIRECTORY "@work_dir@" + ) + endif() + message(FATAL_ERROR "\nFailed to rebase in: '@work_dir@'." + "\nOutput from the attempted rebase follows:" + "\n${rebase_output}" + "\n\nYou will have to resolve the conflicts manually") + endif() + + # Fall back to checkout. We create an annotated tag so that the user + # can manually inspect the situation and revert if required. + # We can't log the failed rebase output because MSVC sees it and + # intervenes, causing the build to fail even though it completes. + # Write it to a file instead. + string(TIMESTAMP tag_timestamp "%Y%m%dT%H%M%S" UTC) + set(tag_name _cmake_ExternalProject_moved_from_here_${tag_timestamp}Z) + set(error_log_file ${CMAKE_CURRENT_LIST_DIR}/rebase_error_${tag_timestamp}Z.log) + file(WRITE ${error_log_file} "${rebase_output}") + message(WARNING "Rebase failed, output has been saved to ${error_log_file}" + "\nFalling back to checkout, previous commit tagged as ${tag_name}") + execute_process( + COMMAND "@git_EXECUTABLE@" tag -a + -m "ExternalProject attempting to move from here to ${git_remote}/${git_tag}" + ${tag_name} + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Failed to add marker tag") + endif() + + execute_process( + COMMAND "@git_EXECUTABLE@" checkout ${git_remote}/${git_tag} + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Failed to checkout : '${git_remote}/${git_tag}'") + endif() + + endif() + + if(need_stash) + execute_process( + COMMAND "@git_EXECUTABLE@" stash pop --index --quiet + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + # Stash pop --index failed: Try again dropping the index + execute_process( + COMMAND "@git_EXECUTABLE@" reset --hard --quiet + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + execute_process( + COMMAND "@git_EXECUTABLE@" stash pop --quiet + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + # Stash pop failed: Restore previous state. + execute_process( + COMMAND "@git_EXECUTABLE@" reset --hard --quiet ${head_sha} + WORKING_DIRECTORY "@work_dir@" + ) + execute_process( + COMMAND "@git_EXECUTABLE@" stash pop --index --quiet + WORKING_DIRECTORY "@work_dir@" + ) + message(FATAL_ERROR "\nFailed to unstash changes in: '@work_dir@'." + "\nYou will have to resolve the conflicts manually") + endif() + endif() + endif() + else() + execute_process( + COMMAND "@git_EXECUTABLE@" checkout "${git_tag}" + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Failed to checkout tag: '${git_tag}'") + endif() + endif() + + set(init_submodules "@init_submodules@") + if(init_submodules) + execute_process( + COMMAND "@git_EXECUTABLE@" submodule update @git_submodules_recurse@ --init @git_submodules@ + WORKING_DIRECTORY "@work_dir@" + RESULT_VARIABLE error_code + ) + endif() + if(error_code) + message(FATAL_ERROR "Failed to update submodules in: '@work_dir@'") + endif() +endif() diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index a9448e5..3a47090 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -9,8 +9,11 @@ ExternalProject .. contents:: +Commands +^^^^^^^^ + External Project Definition -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +""""""""""""""""""""""""""" .. command:: ExternalProject_Add @@ -291,6 +294,42 @@ External Project Definition ``git clone`` command line, with each option required to be in the form ``key=value``. + ``GIT_REMOTE_UPDATE_STRATEGY <strategy>`` + 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). + + ``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. @@ -665,7 +704,7 @@ External Project Definition automatic substitutions that are supported for some options. Obtaining Project Properties -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +"""""""""""""""""""""""""""" .. command:: ExternalProject_Get_Property @@ -686,7 +725,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 @@ -935,6 +974,7 @@ The custom step could then be triggered from the main build like so:: cmake_policy(PUSH) cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST # Pre-compute a regex to match documented keywords for each command. math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 4") @@ -1239,7 +1279,7 @@ endif() endfunction() -function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name init_submodules git_submodules_recurse git_submodules git_repository work_dir) +function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name init_submodules git_submodules_recurse git_submodules git_repository work_dir git_update_strategy) if("${git_tag}" STREQUAL "") message(FATAL_ERROR "Tag for git checkout should not be empty.") endif() @@ -1248,171 +1288,13 @@ function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_r else() set(git_stash_save_options --quiet) endif() - file(WRITE ${script_filename} -" -execute_process( - COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 HEAD - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - OUTPUT_VARIABLE head_sha - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -if(error_code) - message(FATAL_ERROR \"Failed to get the hash for HEAD\") -endif() - -execute_process( - COMMAND \"${git_EXECUTABLE}\" show-ref ${git_tag} - WORKING_DIRECTORY \"${work_dir}\" - OUTPUT_VARIABLE show_ref_output - ) -# If a remote ref is asked for, which can possibly move around, -# we must always do a fetch and checkout. -if(\"\${show_ref_output}\" MATCHES \"remotes\") - set(is_remote_ref 1) -else() - set(is_remote_ref 0) -endif() -# Tag is in the form <remote>/<tag> (i.e. origin/master) we must strip -# the remote from the tag. -if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\") - string(REGEX MATCH \"^([^/]+)/(.+)$\" _unused \"${git_tag}\") - set(git_remote \"\${CMAKE_MATCH_1}\") - set(git_tag \"\${CMAKE_MATCH_2}\") -else() - set(git_remote \"${git_remote_name}\") - set(git_tag \"${git_tag}\") -endif() - -# This will fail if the tag does not exist (it probably has not been fetched -# yet). -execute_process( - COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 ${git_tag} - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - OUTPUT_VARIABLE tag_sha - OUTPUT_STRIP_TRAILING_WHITESPACE + configure_file( + "${_ExternalProject_SELF_DIR}/ExternalProject-gitupdate.cmake.in" + "${script_filename}" + @ONLY ) - -# Is the hash checkout out that we want? -if(error_code OR is_remote_ref OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\")) - execute_process( - COMMAND \"${git_EXECUTABLE}\" fetch - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - message(FATAL_ERROR \"Failed to fetch repository '${git_repository}'\") - endif() - - if(is_remote_ref) - # Check if stash is needed - execute_process( - COMMAND \"${git_EXECUTABLE}\" status --porcelain - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - OUTPUT_VARIABLE repo_status - ) - if(error_code) - message(FATAL_ERROR \"Failed to get the status\") - endif() - string(LENGTH \"\${repo_status}\" need_stash) - - # If not in clean state, stash changes in order to be able to be able to - # perform git pull --rebase - if(need_stash) - execute_process( - COMMAND \"${git_EXECUTABLE}\" stash save ${git_stash_save_options} - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - message(FATAL_ERROR \"Failed to stash changes\") - endif() - endif() - - # Pull changes from the remote branch - execute_process( - COMMAND \"${git_EXECUTABLE}\" rebase \${git_remote}/\${git_tag} - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - # Rebase failed: Restore previous state. - execute_process( - COMMAND \"${git_EXECUTABLE}\" rebase --abort - WORKING_DIRECTORY \"${work_dir}\" - ) - if(need_stash) - execute_process( - COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet - WORKING_DIRECTORY \"${work_dir}\" - ) - endif() - message(FATAL_ERROR \"\\nFailed to rebase in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\") - endif() - - if(need_stash) - execute_process( - COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - # Stash pop --index failed: Try again dropping the index - execute_process( - COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - execute_process( - COMMAND \"${git_EXECUTABLE}\" stash pop --quiet - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - # Stash pop failed: Restore previous state. - execute_process( - COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet \${head_sha} - WORKING_DIRECTORY \"${work_dir}\" - ) - execute_process( - COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet - WORKING_DIRECTORY \"${work_dir}\" - ) - message(FATAL_ERROR \"\\nFailed to unstash changes in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\") - endif() - endif() - endif() - else() - execute_process( - COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag} - WORKING_DIRECTORY \"${work_dir}\" - RESULT_VARIABLE error_code - ) - if(error_code) - message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\") - endif() - endif() - - set(init_submodules ${init_submodules}) - if(init_submodules) - execute_process( - COMMAND \"${git_EXECUTABLE}\" submodule update ${git_submodules_recurse} --init ${git_submodules} - WORKING_DIRECTORY \"${work_dir}/${src_name}\" - RESULT_VARIABLE error_code - ) - endif() - if(error_code) - message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\") - endif() -endif() - -" -) - -endfunction(_ep_write_gitupdate_script) +endfunction() function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file) if(timeout) @@ -1905,7 +1787,11 @@ function(_ep_get_build_command name step cmd_var) get_target_property(args ${name} _EP_${step}_ARGS) endif() - list(APPEND cmd ${args}) + if(NOT "${args}" STREQUAL "") + # args could have empty items, so we must quote it to prevent them + # from being silently removed + list(APPEND cmd "${args}") + endif() set(${cmd_var} "${cmd}" PARENT_SCOPE) endfunction() @@ -2221,17 +2107,23 @@ function(ExternalProject_Add_Step name step) set(command ${CMAKE_COMMAND} -E echo_append) endif() - add_custom_command( - OUTPUT ${stamp_file} - BYPRODUCTS ${byproducts} - COMMENT ${comment} - COMMAND ${command} - COMMAND ${touch} - DEPENDS ${depends} - WORKING_DIRECTORY ${work_dir} - VERBATIM - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS command) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + add_custom_command( + OUTPUT \${stamp_file} + BYPRODUCTS \${byproducts} + COMMENT \${comment} + COMMAND ${__cmdQuoted} + COMMAND \${touch} + DEPENDS \${depends} + WORKING_DIRECTORY \${work_dir} + VERBATIM + ${uses_terminal} + )" + ) set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step}) # Add custom "step target"? @@ -2279,7 +2171,7 @@ function(ExternalProject_Add_StepDependencies name step) get_property(steps TARGET ${name} PROPERTY _EP_STEPS) list(FIND steps ${step} is_step) - if(NOT is_step) + if(is_step LESS 0) message(FATAL_ERROR "External project \"${name}\" does not have a step \"${step}\".") endif() @@ -2686,17 +2578,32 @@ function(_ep_add_download_command name) set(uses_terminal "") endif() - ExternalProject_Add_Step(${name} download - COMMENT ${comment} - COMMAND ${cmd} - WORKING_DIRECTORY ${work_dir} - DEPENDS ${depends} - DEPENDEES mkdir - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(\${name} download + COMMENT \${comment} + COMMAND ${__cmdQuoted} + WORKING_DIRECTORY \${work_dir} + DEPENDS \${depends} + DEPENDEES mkdir + ${log} + ${uses_terminal} + )" + ) endfunction() +function(_ep_get_update_disconnected var name) + get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET) + if(update_disconnected_set) + get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED) + else() + get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED) + endif() + set(${var} "${update_disconnected}" PARENT_SCOPE) +endfunction() function(_ep_add_update_command name) ExternalProject_Get_Property(${name} source_dir tmp_dir) @@ -2707,12 +2614,8 @@ function(_ep_add_update_command name) get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY) get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY) get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY ) - get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET) - if(update_disconnected_set) - get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED) - else() - get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED) - endif() + + _ep_get_update_disconnected(update_disconnected ${name}) set(work_dir) set(comment) @@ -2781,10 +2684,22 @@ function(_ep_add_update_command name) endif() endif() + get_property(git_update_strategy TARGET ${name} PROPERTY _EP_GIT_REMOTE_UPDATE_STRATEGY) + if(NOT git_update_strategy) + set(git_update_strategy "${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}") + endif() + if(NOT git_update_strategy) + set(git_update_strategy REBASE) + endif() + set(strategies CHECKOUT REBASE REBASE_CHECKOUT) + if(NOT git_update_strategy IN_LIST strategies) + message(FATAL_ERROR "'${git_update_strategy}' is not one of the supported strategies: ${strategies}") + endif() + _ep_get_git_submodules_recurse(git_submodules_recurse) _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake - ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} ${git_init_submodules} "${git_submodules_recurse}" "${git_submodules}" ${git_repository} ${work_dir} + ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} ${git_init_submodules} "${git_submodules_recurse}" "${git_submodules}" ${git_repository} ${work_dir} ${git_update_strategy} ) set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake) set(always 1) @@ -2826,16 +2741,22 @@ Update to Mercurial >= 2.1.1. set(uses_terminal "") endif() - ExternalProject_Add_Step(${name} update - COMMENT ${comment} - COMMAND ${cmd} - ALWAYS ${always} - EXCLUDE_FROM_MAIN ${update_disconnected} - WORKING_DIRECTORY ${work_dir} - DEPENDEES download - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} update + COMMENT \${comment} + COMMAND ${__cmdQuoted} + ALWAYS \${always} + EXCLUDE_FROM_MAIN \${update_disconnected} + WORKING_DIRECTORY \${work_dir} + DEPENDEES download + ${log} + ${uses_terminal} + )" + ) if(update_disconnected) _ep_get_step_stampfile(${name} skip-update skip-update_stamp_file) @@ -2874,12 +2795,25 @@ function(_ep_add_patch_command name) set(log "") endif() - ExternalProject_Add_Step(${name} patch - COMMAND ${cmd} - WORKING_DIRECTORY ${work_dir} - DEPENDEES download - ${log} - ) + _ep_get_update_disconnected(update_disconnected ${name}) + if(update_disconnected) + set(update_dep skip-update) + else() + set(update_dep update) + endif() + + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} patch + COMMAND ${__cmdQuoted} + WORKING_DIRECTORY \${work_dir} + DEPENDEES download \${update_dep} + ${log} + )" + ) endfunction() @@ -2974,6 +2908,10 @@ function(_ep_extract_configure_command var name) endif() _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}") list(APPEND cmd "-C${_ep_cache_args_script}") + _ep_replace_location_tags(${name} _ep_cache_args_script) + set(_ep_cache_args_script + "${_ep_cache_args_script}" + PARENT_SCOPE) endif() list(APPEND cmd "<SOURCE_DIR><SOURCE_SUBDIR>") @@ -3004,7 +2942,7 @@ function(_ep_add_configure_command name) # If anything about the configure command changes, (command itself, cmake # used, cmake args or cmake generator) then re-run the configure step. - # Fixes issue https://gitlab.kitware.com/cmake/cmake/issues/10258 + # Fixes issue https://gitlab.kitware.com/cmake/cmake/-/issues/10258 # if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in) file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n") @@ -3028,26 +2966,27 @@ function(_ep_add_configure_command name) set(uses_terminal "") endif() - get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET) - if(update_disconnected_set) - get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED) - else() - get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED) - endif() + _ep_get_update_disconnected(update_disconnected ${name}) if(update_disconnected) set(update_dep skip-update) else() set(update_dep update) endif() - ExternalProject_Add_Step(${name} configure - COMMAND ${cmd} - WORKING_DIRECTORY ${binary_dir} - DEPENDEES ${update_dep} patch - DEPENDS ${file_deps} - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} configure + COMMAND ${__cmdQuoted} + WORKING_DIRECTORY \${binary_dir} + DEPENDEES \${update_dep} patch + DEPENDS \${file_deps} + ${log} + ${uses_terminal} + )" + ) endfunction() @@ -3085,15 +3024,21 @@ function(_ep_add_build_command name) get_property(build_byproducts TARGET ${name} PROPERTY _EP_BUILD_BYPRODUCTS) - ExternalProject_Add_Step(${name} build - COMMAND ${cmd} - BYPRODUCTS ${build_byproducts} - WORKING_DIRECTORY ${binary_dir} - DEPENDEES configure - ALWAYS ${always} - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} build + COMMAND ${__cmdQuoted} + BYPRODUCTS \${build_byproducts} + WORKING_DIRECTORY \${binary_dir} + DEPENDEES configure + ALWAYS \${always} + ${log} + ${uses_terminal} + )" + ) endfunction() @@ -3122,13 +3067,19 @@ function(_ep_add_install_command name) set(uses_terminal "") endif() - ExternalProject_Add_Step(${name} install - COMMAND ${cmd} - WORKING_DIRECTORY ${binary_dir} - DEPENDEES build - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} install + COMMAND ${__cmdQuoted} + WORKING_DIRECTORY \${binary_dir} + DEPENDEES build + ${log} + ${uses_terminal} + )" + ) endfunction() @@ -3183,15 +3134,21 @@ function(_ep_add_test_command name) set(uses_terminal "") endif() - ExternalProject_Add_Step(${name} test - COMMAND ${cmd} - WORKING_DIRECTORY ${binary_dir} - ${dependees_args} - ${dependers_args} - ${exclude_args} - ${log} - ${uses_terminal} - ) + set(__cmdQuoted) + foreach(__item IN LISTS cmd) + string(APPEND __cmdQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + ExternalProject_Add_Step(${name} test + COMMAND ${__cmdQuoted} + WORKING_DIRECTORY \${binary_dir} + ${dependees_args} + ${dependers_args} + ${exclude_args} + ${log} + ${uses_terminal} + )" + ) endif() endfunction() diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index f3e1b51..69f2513 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -76,8 +76,11 @@ sometimes useful as part of implementing some higher level feature or to populate some content in CMake's script mode. +Commands +^^^^^^^^ + Declaring Content Details -^^^^^^^^^^^^^^^^^^^^^^^^^ +""""""""""""""""""""""""" .. command:: FetchContent_Declare @@ -105,9 +108,13 @@ Declaring Content Details The ``<contentOptions>`` can be any of the download or update/patch options that the :command:`ExternalProject_Add` command understands. The configure, build, install and test steps are explicitly disabled and therefore options - related to them will be ignored. In most cases, ``<contentOptions>`` will - just be a couple of options defining the download method and method-specific - details like a commit tag or archive hash. For example: + related to them will be ignored. The ``SOURCE_SUBDIR`` option is an + exception, see :command:`FetchContent_MakeAvailable` for details on how that + affects behavior. + + In most cases, ``<contentOptions>`` will just be a couple of options defining + the download method and method-specific details like a commit tag or archive + hash. For example: .. code-block:: cmake @@ -130,7 +137,7 @@ Declaring Content Details ) Populating The Content -^^^^^^^^^^^^^^^^^^^^^^ +"""""""""""""""""""""" For most common scenarios, population means making content available to the main build according to previously declared details for that dependency. @@ -161,8 +168,9 @@ approach. The former generally follows this canonical pattern: The above is such a common pattern that, where no custom steps are needed between the calls to :command:`FetchContent_Populate` and :command:`add_subdirectory`, equivalent logic can be obtained by calling -:command:`FetchContent_MakeAvailable` instead (and should be preferred where -it meets the needs of the project). +:command:`FetchContent_MakeAvailable` instead. Where it meets the needs of +the project, :command:`FetchContent_MakeAvailable` should be preferred, as it +is simpler and provides additional features over the pattern above. .. command:: FetchContent_Populate @@ -332,6 +340,8 @@ it meets the needs of the project). ``${CMAKE_CURRENT_BINARY_DIR}/<lcName>-subbuild`` and it would be unusual to need to override this default. If a relative path is specified, it will be interpreted as relative to :variable:`CMAKE_CURRENT_BINARY_DIR`. + This option should not be confused with the ``SOURCE_SUBDIR`` option which + only affects the :command:`FetchContent_MakeAvailable` command. ``SOURCE_DIR``, ``BINARY_DIR`` The ``SOURCE_DIR`` and ``BINARY_DIR`` arguments are supported by @@ -406,15 +416,22 @@ it meets the needs of the project). This command implements the common pattern typically needed for most dependencies. It iterates over each of the named dependencies in turn - and for each one it loosely follows the same + and for each one it loosely follows the :ref:`canonical pattern <fetch-content-canonical-pattern>` as - presented at the beginning of this section. One small difference to - that pattern is that it will only call :command:`add_subdirectory` on the + presented at the beginning of this section. An important difference is + that :command:`add_subdirectory` will only be called on the populated content if there is a ``CMakeLists.txt`` file in its top level source directory. This allows the command to be used for dependencies that make downloaded content available at a known location but which do not need or support being added directly to the build. + The ``SOURCE_SUBDIR`` option can be given in the declared details to + instruct ``FetchContent_MakeAvailable()`` to look for a ``CMakeLists.txt`` + file in a subdirectory below the top level (i.e. the same way that + ``SOURCE_SUBDIR`` is used by the :command:`ExternalProject_Add` command). + ``SOURCE_SUBDIR`` must always be a relative path. See the next section + for an example of this option. + .. _`fetch-content-examples`: @@ -442,6 +459,23 @@ frameworks are available to the main build: # Catch2 will be defined and available to the rest of the build FetchContent_MakeAvailable(googletest Catch2) +If the sub-project's ``CMakeLists.txt`` file is not at the top level of its +source tree, the ``SOURCE_SUBDIR`` option can be used to tell ``FetchContent`` +where to find it. The following example shows how to use that option and +it also sets a variable which is meaningful to the subproject before pulling +it into the main build: + +.. code-block:: cmake + + include(FetchContent) + FetchContent_Declare( + protobuf + GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git + GIT_TAG v3.12.0 + SOURCE_SUBDIR cmake + ) + set(protobuf_BUILD_TESTS OFF) + FetchContent_MakeAvailable(protobuf) In more complex project hierarchies, the dependency relationships can be more complicated. Consider a hierarchy where ``projA`` is the top level project and @@ -622,7 +656,12 @@ function(__FetchContent_declareDetails contentName) BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" ) - set_property(GLOBAL PROPERTY ${propertyName} ${ARGN}) + set(__cmdArgs) + foreach(__item IN LISTS ARGN) + string(APPEND __cmdArgs " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE + "set_property(GLOBAL PROPERTY ${propertyName} ${__cmdArgs})") endif() endfunction() @@ -655,7 +694,8 @@ function(FetchContent_Declare contentName) set(oneValueArgs SVN_REPOSITORY) set(multiValueArgs "") - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(PARSE_ARGV 1 ARG + "${options}" "${oneValueArgs}" "${multiValueArgs}") unset(srcDirSuffix) unset(svnRepoArgs) @@ -673,13 +713,20 @@ function(FetchContent_Declare contentName) endif() string(TOLOWER ${contentName} contentNameLower) - __FetchContent_declareDetails( - ${contentNameLower} - SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src${srcDirSuffix}" - BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build" - ${svnRepoArgs} - # List these last so they can override things we set above - ${ARG_UNPARSED_ARGUMENTS} + + set(__argsQuoted) + foreach(__item IN LISTS ARG_UNPARSED_ARGUMENTS) + string(APPEND __argsQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + __FetchContent_declareDetails( + ${contentNameLower} + SOURCE_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src${srcDirSuffix}\" + BINARY_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build\" + \${svnRepoArgs} + # List these last so they can override things we set above + ${__argsQuoted} + )" ) endfunction() @@ -793,6 +840,8 @@ function(__FetchContent_directPopulate contentName) SUBBUILD_DIR SOURCE_DIR BINARY_DIR + # We need special processing if DOWNLOAD_NO_EXTRACT is true + DOWNLOAD_NO_EXTRACT # Prevent the following from being passed through CONFIGURE_COMMAND BUILD_COMMAND @@ -808,7 +857,8 @@ function(__FetchContent_directPopulate contentName) ) set(multiValueArgs "") - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(PARSE_ARGV 1 ARG + "${options}" "${oneValueArgs}" "${multiValueArgs}") if(NOT ARG_SUBBUILD_DIR) message(FATAL_ERROR "Internal error: SUBBUILD_DIR not set") @@ -843,6 +893,26 @@ function(__FetchContent_directPopulate contentName) set(ARG_EXTRA "${ARG_EXTRA} \"${arg}\"") endforeach() + if(ARG_DOWNLOAD_NO_EXTRACT) + set(ARG_EXTRA "${ARG_EXTRA} DOWNLOAD_NO_EXTRACT YES") + set(__FETCHCONTENT_COPY_FILE +" +ExternalProject_Get_Property(${contentName}-populate DOWNLOADED_FILE) +get_filename_component(dlFileName \"\${DOWNLOADED_FILE}\" NAME) + +ExternalProject_Add_Step(${contentName}-populate copyfile + COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different + \"<DOWNLOADED_FILE>\" \"${ARG_SOURCE_DIR}\" + DEPENDEES patch + DEPENDERS configure + BYPRODUCTS \"${ARG_SOURCE_DIR}/\${dlFileName}\" + COMMENT \"Copying file to SOURCE_DIR\" +) +") + else() + unset(__FETCHCONTENT_COPY_FILE) + endif() + # Hide output if requested, but save it to a variable in case there's an # error so we can show the output upon failure. When not quiet, don't # capture the output to a variable because the user may want to see the @@ -1000,17 +1070,23 @@ function(FetchContent_Populate contentName) message(FATAL_ERROR "No details have been set for content: ${contentName}") endif() - __FetchContent_directPopulate( - ${contentNameLower} - ${quietFlag} - UPDATE_DISCONNECTED ${disconnectUpdates} - SUBBUILD_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-subbuild" - SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src" - BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build" - # Put the saved details last so they can override any of the - # the options we set above (this can include SOURCE_DIR or - # BUILD_DIR) - ${contentDetails} + set(__detailsQuoted) + foreach(__item IN LISTS contentDetails) + string(APPEND __detailsQuoted " [==[${__item}]==]") + endforeach() + cmake_language(EVAL CODE " + __FetchContent_directPopulate( + ${contentNameLower} + ${quietFlag} + UPDATE_DISCONNECTED ${disconnectUpdates} + SUBBUILD_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-subbuild\" + SOURCE_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src\" + BINARY_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build\" + # Put the saved details last so they can override any of the + # the options we set above (this can include SOURCE_DIR or + # BUILD_DIR) + ${__detailsQuoted} + )" ) endif() @@ -1047,11 +1123,26 @@ macro(FetchContent_MakeAvailable) # can be treated that way. Protecting the call with the check # allows this function to be used for projects that just want # to ensure the content exists, such as to provide content at - # a known location. - if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt) - add_subdirectory(${${contentNameLower}_SOURCE_DIR} - ${${contentNameLower}_BINARY_DIR}) + # a known location. We check the saved details for an optional + # SOURCE_SUBDIR which can be used in the same way as its meaning + # for ExternalProject. It won't matter if it was passed through + # to the ExternalProject sub-build, since it would have been + # ignored there. + set(__fc_srcdir "${${contentNameLower}_SOURCE_DIR}") + __FetchContent_getSavedDetails(${contentName} contentDetails) + if("${contentDetails}" STREQUAL "") + message(FATAL_ERROR "No details have been set for content: ${contentName}") + endif() + cmake_parse_arguments(__fc_arg "" "SOURCE_SUBDIR" "" ${contentDetails}) + if(NOT "${__fc_arg_SOURCE_SUBDIR}" STREQUAL "") + string(APPEND __fc_srcdir "/${__fc_arg_SOURCE_SUBDIR}") endif() + + if(EXISTS ${__fc_srcdir}/CMakeLists.txt) + add_subdirectory(${__fc_srcdir} ${${contentNameLower}_BINARY_DIR}) + endif() + + unset(__fc_srcdir) endif() endforeach() diff --git a/Modules/FetchContent/CMakeLists.cmake.in b/Modules/FetchContent/CMakeLists.cmake.in index 0095b11..45e4df0 100644 --- a/Modules/FetchContent/CMakeLists.cmake.in +++ b/Modules/FetchContent/CMakeLists.cmake.in @@ -21,3 +21,5 @@ ExternalProject_Add(${contentName}-populate USES_TERMINAL_DOWNLOAD YES USES_TERMINAL_UPDATE YES ) + +@__FETCHCONTENT_COPY_FILE@ diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake index c4e55ce..243b9e0 100644 --- a/Modules/FindArmadillo.cmake +++ b/Modules/FindArmadillo.cmake @@ -6,7 +6,7 @@ FindArmadillo ------------- Find the Armadillo C++ library. -Armadillo is library for linear algebra & scientific computing. +Armadillo is a library for linear algebra & scientific computing. Using Armadillo: @@ -31,19 +31,13 @@ This module sets the following variables: ARMADILLO_VERSION_NAME - name of the version (ex: "Antipodean Antileech") #]=======================================================================] -# UNIX paths are standard, no need to write. -find_library(ARMADILLO_LIBRARY - NAMES armadillo - PATHS "$ENV{ProgramFiles}/Armadillo/lib" "$ENV{ProgramFiles}/Armadillo/lib64" "$ENV{ProgramFiles}/Armadillo" - ) find_path(ARMADILLO_INCLUDE_DIR NAMES armadillo PATHS "$ENV{ProgramFiles}/Armadillo/include" ) - +mark_as_advanced(ARMADILLO_INCLUDE_DIR) if(ARMADILLO_INCLUDE_DIR) - # ------------------------------------------------------------------------ # Extract version information from <armadillo> # ------------------------------------------------------------------------ @@ -59,32 +53,79 @@ if(ARMADILLO_INCLUDE_DIR) if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp") # Read and parse armdillo version header file for version number - file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _armadillo_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ") - string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_armadillo_HEADER_CONTENTS}") - string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_armadillo_HEADER_CONTENTS}") - string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_armadillo_HEADER_CONTENTS}") + file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/arma_version.hpp" _ARMA_HEADER_CONTENTS REGEX "#define ARMA_VERSION_[A-Z]+ ") + string(REGEX REPLACE ".*#define ARMA_VERSION_MAJOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MAJOR "${_ARMA_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define ARMA_VERSION_MINOR ([0-9]+).*" "\\1" ARMADILLO_VERSION_MINOR "${_ARMA_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define ARMA_VERSION_PATCH ([0-9]+).*" "\\1" ARMADILLO_VERSION_PATCH "${_ARMA_HEADER_CONTENTS}") # WARNING: The number of spaces before the version name is not one. - string(REGEX REPLACE ".*#define ARMA_VERSION_NAME +\"([0-9a-zA-Z _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_armadillo_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define ARMA_VERSION_NAME\ +\"([0-9a-zA-Z\ _-]+)\".*" "\\1" ARMADILLO_VERSION_NAME "${_ARMA_HEADER_CONTENTS}") - unset(_armadillo_HEADER_CONTENTS) endif() set(ARMADILLO_VERSION_STRING "${ARMADILLO_VERSION_MAJOR}.${ARMADILLO_VERSION_MINOR}.${ARMADILLO_VERSION_PATCH}") endif () +if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp") + file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp" _ARMA_CONFIG_CONTENTS REGEX "^#define ARMA_USE_[A-Z]+") + string(REGEX MATCH "ARMA_USE_WRAPPER" _ARMA_USE_WRAPPER "${_ARMA_CONFIG_CONTENTS}") + string(REGEX MATCH "ARMA_USE_LAPACK" _ARMA_USE_LAPACK "${_ARMA_CONFIG_CONTENTS}") + string(REGEX MATCH "ARMA_USE_BLAS" _ARMA_USE_BLAS "${_ARMA_CONFIG_CONTENTS}") + string(REGEX MATCH "ARMA_USE_ARPACK" _ARMA_USE_ARPACK "${_ARMA_CONFIG_CONTENTS}") + string(REGEX MATCH "ARMA_USE_HDF5" _ARMA_USE_HDF5 "${_ARMA_CONFIG_CONTENTS}") +endif() + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + +# If _ARMA_USE_WRAPPER is set, then we just link to armadillo, but if it's not then we need support libraries instead +set(_ARMA_SUPPORT_LIBRARIES) + +if(_ARMA_USE_WRAPPER) + # Link to the armadillo wrapper library. + find_library(ARMADILLO_LIBRARY + NAMES armadillo + PATHS + "$ENV{ProgramFiles}/Armadillo/lib" + "$ENV{ProgramFiles}/Armadillo/lib64" + "$ENV{ProgramFiles}/Armadillo" + ) + mark_as_advanced(ARMADILLO_LIBRARY) + set(_ARMA_REQUIRED_VARS ARMADILLO_LIBRARY) +else() + # Link directly to individual components. + set(ARMADILLO_LIBRARY "") + foreach(pkg + LAPACK + BLAS + ARPACK + HDF5 + ) + if(_ARMA_USE_${pkg}) + find_package(${pkg} QUIET) + list(APPEND _ARMA_REQUIRED_VARS "${pkg}_FOUND") + if(${pkg}_FOUND) + list(APPEND _ARMA_SUPPORT_LIBRARIES ${${pkg}_LIBRARIES}) + endif() + endif() + endforeach() +endif() + find_package_handle_standard_args(Armadillo - REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR + REQUIRED_VARS ARMADILLO_INCLUDE_DIR ${_ARMA_REQUIRED_VARS} VERSION_VAR ARMADILLO_VERSION_STRING) -# version_var fails with cmake < 2.8.4. if (ARMADILLO_FOUND) set(ARMADILLO_INCLUDE_DIRS ${ARMADILLO_INCLUDE_DIR}) - set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY}) + set(ARMADILLO_LIBRARIES ${ARMADILLO_LIBRARY} ${_ARMA_SUPPORT_LIBRARIES}) endif () -# Hide internal variables -mark_as_advanced( - ARMADILLO_INCLUDE_DIR - ARMADILLO_LIBRARY) +# Clean up internal variables +unset(_ARMA_REQUIRED_VARS) +unset(_ARMA_SUPPORT_LIBRARIES) +unset(_ARMA_USE_WRAPPER) +unset(_ARMA_USE_LAPACK) +unset(_ARMA_USE_BLAS) +unset(_ARMA_USE_ARPACK) +unset(_ARMA_USE_HDF5) +unset(_ARMA_CONFIG_CONTENTS) +unset(_ARMA_HEADER_CONTENTS) diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 9b6d09c..4c569b3 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -48,6 +48,10 @@ The following variables may be set to influence this module's behavior: * ``ACML_GPU`` * ``Apple`` * ``NAS`` + * ``Arm`` + * ``Arm_mp`` + * ``Arm_ilp64`` + * ``Arm_ilp64_mp`` * ``Generic`` ``BLA_F95`` @@ -57,6 +61,15 @@ The following variables may be set to influence this module's behavior: if set ``pkg-config`` will be used to search for a BLAS library first and if one is found that is preferred +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``BLAS::BLAS`` + The libraries to use for BLAS, if found. + + Result Variables ^^^^^^^^^^^^^^^^ @@ -107,6 +120,17 @@ if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_CO endif() endif() +function(_add_blas_target) + if(NOT TARGET BLAS::BLAS) + add_library(BLAS::BLAS INTERFACE IMPORTED) + if(BLAS_LIBRARIES) + set_target_properties(BLAS::BLAS PROPERTIES + INTERFACE_LINK_LIBRARIES "${BLAS_LIBRARIES}" + ) + endif() + endif() +endfunction() + if(CMAKE_Fortran_COMPILER_LOADED) include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake) else() @@ -123,6 +147,7 @@ if(BLA_PREFER_PKGCONFIG) if(PKGC_BLAS_FOUND) set(BLAS_FOUND ${PKGC_BLAS_FOUND}) set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}") + _add_blas_target() return() endif() endif() @@ -550,6 +575,36 @@ if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All") endif() endif() +# ArmPL blas library? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries) +if(BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All") + + # Check for 64bit Integer support + if(BLA_VENDOR MATCHES "_ilp64") + set(BLAS_armpl_LIB "armpl_ilp64") + else() + set(BLAS_armpl_LIB "armpl_lp64") + endif() + + # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp + if(BLA_VENDOR MATCHES "_mp") + set(BLAS_armpl_LIB "${BLAS_armpl_LIB}_mp") + endif() + + if(NOT BLAS_LIBRARIES) + check_blas_libraries( + BLAS_LIBRARIES + BLAS + sgemm + "" + "${BLAS_armpl_LIB}" + "" + "" + "" + ) + endif() + +endif() + # FLAME's blis library? (https://github.com/flame/blis) if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All") if(NOT BLAS_LIBRARIES) @@ -892,11 +947,13 @@ if(NOT BLA_F95) find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES) endif() + # On compilers that implicitly link BLAS (such as ftn, cc, and CC on Cray HPC machines) # we used a placeholder for empty BLAS_LIBRARIES to get through our logic above. if(BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES") set(BLAS_LIBRARIES "") endif() +_add_blas_target() cmake_pop_check_state() set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 53fc4b7..13981d3 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -155,6 +155,10 @@ setting variables:: used if multiple compatible suffixes should be tested for, in decreasing order of preference. + Boost_LIB_PREFIX - Set to the platform-specific library name + prefix (e.g. "lib") used by Boost static libs. + This is needed only on platforms where CMake + does not know the prefix by default. Boost_ARCHITECTURE - Set to the architecture-specific library suffix (e.g. "-x64"). Default is auto-computed for the C++ compiler in use. @@ -750,7 +754,11 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret) set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34 else() _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION _boost_COMPILER_VERSION_MAJOR _boost_COMPILER_VERSION_MINOR) - set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") + if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.73 AND _boost_COMPILER_VERSION_MAJOR VERSION_GREATER_EQUAL 5) + set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION_MAJOR}") + else() + set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") + endif() endif() elseif (UNIX) _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION _boost_COMPILER_VERSION_MAJOR _boost_COMPILER_VERSION_MINOR) @@ -1449,7 +1457,7 @@ else() # _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_DEPENDENCIES. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69" + "1.73.0" "1.73" "1.72.0" "1.72" "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69" "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65" "1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60" "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55" @@ -1663,10 +1671,17 @@ endif() # Prefix initialization # ------------------------------------------------------------------------ -set(Boost_LIB_PREFIX "") -if ( (GHSMULTI AND Boost_USE_STATIC_LIBS) OR - (WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN) ) - set(Boost_LIB_PREFIX "lib") +if ( NOT DEFINED Boost_LIB_PREFIX ) + # Boost's static libraries use a "lib" prefix on DLL platforms + # to distinguish them from the DLL import libraries. + if (Boost_USE_STATIC_LIBS AND ( + (WIN32 AND NOT CYGWIN) + OR GHSMULTI + )) + set(Boost_LIB_PREFIX "lib") + else() + set(Boost_LIB_PREFIX "") + endif() endif() if ( NOT Boost_NAMESPACE ) diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index de7e785..b28892e 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -473,168 +473,8 @@ Result variables # ############################################################################### -if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR) - get_filename_component(cuda_dir "${CMAKE_CUDA_COMPILER}" DIRECTORY) - # use the already detected cuda compiler - set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "") - mark_as_advanced(CUDAToolkit_BIN_DIR) - unset(cuda_dir) -endif() - -# Try language- or user-provided path first. -if(CUDAToolkit_BIN_DIR) - find_program(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${CUDAToolkit_BIN_DIR} - NO_DEFAULT_PATH - ) -endif() - -# Search using CUDAToolkit_ROOT -find_program(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ENV CUDA_PATH - PATH_SUFFIXES bin -) - -# If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error. -if (NOT CUDAToolkit_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) - # Declare error messages now, print later depending on find_package args. - set(fail_base "Could not find nvcc executable in path specified by") - set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}") - set(env_cuda_root_fail "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}") - - if (CUDAToolkit_FIND_REQUIRED) - if (DEFINED CUDAToolkit_ROOT) - message(FATAL_ERROR ${cuda_root_fail}) - elseif (DEFINED ENV{CUDAToolkit_ROOT}) - message(FATAL_ERROR ${env_cuda_root_fail}) - endif() - else() - if (NOT CUDAToolkit_FIND_QUIETLY) - if (DEFINED CUDAToolkit_ROOT) - message(STATUS ${cuda_root_fail}) - elseif (DEFINED ENV{CUDAToolkit_ROOT}) - message(STATUS ${env_cuda_root_fail}) - endif() - endif() - set(CUDAToolkit_FOUND FALSE) - unset(fail_base) - unset(cuda_root_fail) - unset(env_cuda_root_fail) - return() - 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 CUDAToolkit_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(possible_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 possible_versions ${p_version}) - endif() - endforeach() - - # Cannot use list(SORT) because that is alphabetical, we need numerical. - # NOTE: this is not an efficient sorting strategy. But even if a user had - # every possible version of CUDA installed, this wouldn't create any - # significant overhead. - set(versions) - foreach (v ${possible_versions}) - list(LENGTH versions num_versions) - # First version, nothing to compare with so just append. - if (num_versions EQUAL 0) - list(APPEND versions ${v}) - else() - # Loop through list. Insert at an index when comparison is - # VERSION_GREATER since we want a descending list. Duplicates will not - # happen since this came from a glob list of directories. - set(i 0) - set(early_terminate FALSE) - while (i LESS num_versions) - list(GET versions ${i} curr) - if (v VERSION_GREATER curr) - list(INSERT versions ${i} ${v}) - set(early_terminate TRUE) - break() - endif() - math(EXPR i "${i} + 1") - endwhile() - # If it did not get inserted, place it at the end. - if (NOT early_terminate) - list(APPEND versions ${v}) - endif() - endif() - endforeach() - - # 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(CUDAToolkit_NVCC_EXECUTABLE - NAMES nvcc nvcc.exe - PATHS ${search_paths} - PATH_SUFFIXES bin - ) - - # We are done with these variables now, cleanup for caller. - unset(platform_base) - unset(possible_paths) - unset(possible_versions) - unset(versions) - unset(i) - unset(early_terminate) - unset(search_paths) - - if (NOT CUDAToolkit_NVCC_EXECUTABLE) - if (CUDAToolkit_FIND_REQUIRED) - message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.") - elseif(NOT CUDAToolkit_FIND_QUIETLY) - message(STATUS "Could not find nvcc, please set CUDAToolkit_ROOT.") - endif() - - set(CUDAToolkit_FOUND FALSE) - return() - endif() -endif() - -if(NOT CUDAToolkit_BIN_DIR AND CUDAToolkit_NVCC_EXECUTABLE) - get_filename_component(cuda_dir "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) - set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "" FORCE) - mark_as_advanced(CUDAToolkit_BIN_DIR) - unset(cuda_dir) -endif() +# Include shared CUDA toolkit location code. +include(Internal/CUDAToolkit) if(CUDAToolkit_NVCC_EXECUTABLE AND CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER) @@ -658,72 +498,22 @@ else() unset(NVCC_OUT) endif() - -get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE) - -# Handle cross compilation -if(CMAKE_CROSSCOMPILING) - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") - # Support for NVPACK - set (CUDAToolkit_TARGET_NAME "armv7-linux-androideabi") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") - # Support for arm cross compilation - set(CUDAToolkit_TARGET_NAME "armv7-linux-gnueabihf") - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") - # Support for aarch64 cross compilation - if (ANDROID_ARCH_NAME STREQUAL "arm64") - set(CUDAToolkit_TARGET_NAME "aarch64-linux-androideabi") - else() - set(CUDAToolkit_TARGET_NAME "aarch64-linux") - endif (ANDROID_ARCH_NAME STREQUAL "arm64") - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") - set(CUDAToolkit_TARGET_NAME "x86_64-linux") - endif() - - if (EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}") - set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}") - # add known CUDA target root path to the set of directories we search for programs, libraries and headers - list(PREPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}") - - # Mark that we need to pop the root search path changes after we have - # found all cuda libraries so that searches for our cross-compilation - # libraries work when another cuda sdk is in CMAKE_PREFIX_PATH or - # PATh - set(_CUDAToolkit_Pop_ROOT_PATH True) - endif() -else() - # Not cross compiling - set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}") - # Now that we have the real ROOT_DIR, find components inside it. - list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR}) - - # Mark that we need to pop the prefix path changes after we have - # found the cudart library. - set(_CUDAToolkit_Pop_Prefix True) +if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY) + message(STATUS "Unable to find cudart library.") endif() - -# Find the include/ directory -find_path(CUDAToolkit_INCLUDE_DIR - NAMES cuda_runtime.h -) - -# And find the CUDA Runtime Library libcudart +# Find the CUDA Runtime Library libcudart find_library(CUDA_CUDART NAMES cudart PATH_SUFFIXES lib64 lib/x64 ) -if (NOT CUDA_CUDART) +if(NOT CUDA_CUDART) find_library(CUDA_CUDART NAMES cudart PATH_SUFFIXES lib64/stubs lib/x64/stubs ) endif() -if (NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY) - message(STATUS "Unable to find cudart library.") -endif() - unset(CUDAToolkit_ROOT_DIR) if(_CUDAToolkit_Pop_Prefix) list(REMOVE_AT CMAKE_PREFIX_PATH -1) @@ -749,8 +539,8 @@ mark_as_advanced(CUDA_CUDART #----------------------------------------------------------------------------- # Construct result variables if(CUDAToolkit_FOUND) - set(CUDAToolkit_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIR}) - get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE) + set(CUDAToolkit_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIR}) + get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE) endif() #----------------------------------------------------------------------------- diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake index faa03f9..184a9a2 100644 --- a/Modules/FindDoxygen.cmake +++ b/Modules/FindDoxygen.cmake @@ -999,9 +999,11 @@ doxygen_add_docs() for target ${targetName}") foreach(_item IN LISTS DOXYGEN_INPUT) get_filename_component(_abs_item "${_item}" ABSOLUTE BASE_DIR "${_args_WORKING_DIRECTORY}") - if(EXISTS "${_abs_item}" AND - NOT IS_DIRECTORY "${_abs_item}" AND - NOT IS_SYMLINK "${_abs_item}") + get_source_file_property(_isGenerated "${_abs_item}" GENERATED) + if(_isGenerated OR + (EXISTS "${_abs_item}" AND + NOT IS_DIRECTORY "${_abs_item}" AND + NOT IS_SYMLINK "${_abs_item}")) list(APPEND _sources "${_abs_item}") elseif(_args_USE_STAMP_FILE) message(FATAL_ERROR "Source does not exist or is not a file:\n" diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake index 565763d..62f1614 100644 --- a/Modules/FindGTK2.cmake +++ b/Modules/FindGTK2.cmake @@ -695,11 +695,14 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS}) _GTK2_FIND_LIBRARY (CAIRO cairo false false) _GTK2_ADD_TARGET (CAIRO) + _GTK2_FIND_INCLUDE_DIR(HARFBUZZ hb.h) + _GTK2_FIND_LIBRARY (HARFBUZZ harfbuzz false false) + _GTK2_ADD_TARGET (HARFBUZZ) + _GTK2_FIND_INCLUDE_DIR(PANGO pango/pango.h) _GTK2_FIND_LIBRARY (PANGO pango false true) - _GTK2_ADD_TARGET (PANGO GTK2_DEPENDS gobject glib) - - _GTK2_FIND_INCLUDE_DIR(HARFBUZZ hb.h) + _GTK2_ADD_TARGET (PANGO GTK2_DEPENDS gobject glib + GTK2_OPTIONAL_DEPENDS harfbuzz) _GTK2_FIND_LIBRARY (PANGOCAIRO pangocairo false true) _GTK2_ADD_TARGET (PANGOCAIRO GTK2_DEPENDS pango cairo gobject glib) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index b488418..60a313d 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -19,9 +19,12 @@ The module will optionally accept the ``COMPONENTS`` argument. If no ``COMPONENTS`` are specified, then the find module will default to finding only the ``HDF5`` C library. If one or more ``COMPONENTS`` are specified, the module will attempt to find the language bindings for the specified -components. The only valid components are ``C``, ``CXX``, ``Fortran``, ``HL``, -and ``Fortran_HL``. If the ``COMPONENTS`` argument is not given, the module will +components. The valid components are ``C``, ``CXX``, ``Fortran``, ``HL``. +``HL`` refers to the "high-level" HDF5 functions for C and Fortran. +If the ``COMPONENTS`` argument is not given, the module will attempt to find only the C bindings. +For example, to use Fortran HDF5 and HDF5-HL functions, do: +``find_package(HDF5 COMPONENTS Fortran HL)``. This module will read the variable ``HDF5_USE_STATIC_LIBRARIES`` to determine whether or not to prefer a @@ -29,16 +32,11 @@ static link to a dynamic link for ``HDF5`` and all of it's dependencies. To use this feature, make sure that the ``HDF5_USE_STATIC_LIBRARIES`` variable is set before the call to find_package. -To provide the module with a hint about where to find your ``HDF5`` -installation, you can set the environment variable ``HDF5_ROOT``. The -Find module will then look in this path when searching for ``HDF5`` -executables, paths, and libraries. - Both the serial and parallel ``HDF5`` wrappers are considered and the first directory to contain either one will be used. In the event that both appear in the same directory the serial version is preferentially selected. This behavior can be reversed by setting the variable ``HDF5_PREFER_PARALLEL`` to -``True``. +``TRUE``. In addition to finding the includes and libraries required to compile an ``HDF5`` client application, this module also makes an effort to find @@ -115,10 +113,10 @@ also be defined. With all components enabled, the following variables will be d Hints ^^^^^ -The following variable can be set to guide the search for HDF5 libraries and includes: +The following variables can be set to guide the search for HDF5 libraries and includes: -``HDF5_ROOT`` - Specify the path to the HDF5 installation to use. +``HDF5_PREFER_PARALLEL`` + set ``true`` to prefer parallel HDF5 (by default, serial is preferred) ``HDF5_FIND_DEBUG`` Set ``true`` to get extra debugging output. @@ -141,28 +139,30 @@ if(NOT HDF5_FIND_COMPONENTS) else() set(HDF5_LANGUAGE_BINDINGS) # add the extra specified components, ensuring that they are valid. - set(FIND_HL OFF) - foreach(component IN LISTS HDF5_FIND_COMPONENTS) - list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${component} component_location) - if(NOT component_location EQUAL -1) - list(APPEND HDF5_LANGUAGE_BINDINGS ${component}) - elseif(component STREQUAL "HL") - set(FIND_HL ON) - elseif(component STREQUAL "Fortran_HL") # only for compatibility + set(HDF5_FIND_HL OFF) + foreach(_component IN LISTS HDF5_FIND_COMPONENTS) + list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) + if(NOT _component_location EQUAL -1) + list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) + elseif(_component STREQUAL "HL") + set(HDF5_FIND_HL ON) + elseif(_component STREQUAL "Fortran_HL") # only for compatibility list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) - set(FIND_HL ON) - set(HDF5_FIND_REQUIRED_Fortran_HL False) - set(HDF5_FIND_REQUIRED_Fortran True) - set(HDF5_FIND_REQUIRED_HL True) + set(HDF5_FIND_HL ON) + set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) + set(HDF5_FIND_REQUIRED_Fortran TRUE) + set(HDF5_FIND_REQUIRED_HL TRUE) else() - message(FATAL_ERROR "${component} is not a valid HDF5 component.") + message(FATAL_ERROR "${_component} is not a valid HDF5 component.") endif() endforeach() + unset(_component) + unset(_component_location) if(NOT HDF5_LANGUAGE_BINDINGS) - get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES) - foreach(__lang IN LISTS __langs) - if(__lang MATCHES "^(C|CXX|Fortran)$") - list(APPEND HDF5_LANGUAGE_BINDINGS ${__lang}) + get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(_lang IN LISTS _langs) + if(_lang MATCHES "^(C|CXX|Fortran)$") + list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) endif() endforeach() endif() @@ -328,97 +328,109 @@ endfunction() # Invoke the HDF5 wrapper compiler. The compiler return value is stored to the # return_value argument, the text output is stored to the output variable. -macro( _HDF5_invoke_compiler language output return_value version is_parallel) - set(${version}) - if(HDF5_USE_STATIC_LIBRARIES) - set(lib_type_args -noshlib) - else() - set(lib_type_args -shlib) - endif() - set(scratch_dir ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) - if("${language}" STREQUAL "C") - set(test_file ${scratch_dir}/cmake_hdf5_test.c) - elseif("${language}" STREQUAL "CXX") - set(test_file ${scratch_dir}/cmake_hdf5_test.cxx) - elseif("${language}" STREQUAL "Fortran") - set(test_file ${scratch_dir}/cmake_hdf5_test.f90) - endif() +function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) + set(is_parallel FALSE) + if(HDF5_USE_STATIC_LIBRARIES) + set(lib_type_args -noshlib) + else() + set(lib_type_args -shlib) + endif() + set(scratch_dir ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) + if("${language}" STREQUAL "C") + set(test_file ${scratch_dir}/cmake_hdf5_test.c) + elseif("${language}" STREQUAL "CXX") + set(test_file ${scratch_dir}/cmake_hdf5_test.cxx) + elseif("${language}" STREQUAL "Fortran") + set(test_file ${scratch_dir}/cmake_hdf5_test.f90) + endif() + # Verify that the compiler wrapper can actually compile: sometimes the compiler + # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} ${test_file} + RESULT_VARIABLE return_value + ) + if(return_value) + message(STATUS + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") + else() execute_process( COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} ${test_file} - OUTPUT_VARIABLE ${output} - ERROR_VARIABLE ${output} - RESULT_VARIABLE ${return_value} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE ) - if(NOT ${${return_value}} EQUAL 0) - message(STATUS - "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + if(return_value) + message(STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") endif() execute_process( COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig OUTPUT_VARIABLE config_output ERROR_VARIABLE config_output - RESULT_VARIABLE config_return + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE ) - if(NOT ${return_value} EQUAL 0) - message( STATUS - "Unable to determine HDF5 ${language} version from HDF5 wrapper.") + if(return_value) + message(STATUS + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") endif() - string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version_match "${config_output}") - if(version_match) - string(REPLACE "HDF5 Version: " "" ${version} "${version_match}") - string(REPLACE "-patch" "." ${version} "${${version}}") + string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") + if(version) + string(REPLACE "HDF5 Version: " "" version "${version}") + string(REPLACE "-patch" "." version "${version}") endif() if(config_output MATCHES "Parallel HDF5: yes") - set(${is_parallel} TRUE) - else() - set(${is_parallel} FALSE) + set(is_parallel TRUE) endif() -endmacro() + endif() + foreach(var output return_value version is_parallel) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() # Parse a compile line for definitions, includes, library paths, and libraries. -macro( _HDF5_parse_compile_line - compile_line_var - include_paths - definitions - library_paths - libraries - libraries_hl) - - separate_arguments(_HDF5_COMPILE_ARGS NATIVE_COMMAND "${${compile_line_var}}") - - foreach(arg IN LISTS _HDF5_COMPILE_ARGS) - if("${arg}" MATCHES "^-I(.*)$") +function(_HDF5_parse_compile_line compile_line_var include_paths definitions + library_paths libraries libraries_hl) + + separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") + + foreach(_arg IN LISTS _compile_args) + if("${_arg}" MATCHES "^-I(.*)$") # include directory - list(APPEND ${include_paths} "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-D(.*)$") + list(APPEND include_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-D(.*)$") # compile definition - list(APPEND ${definitions} "-D${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-L(.*)$") + list(APPEND definitions "-D${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-L(.*)$") # library search path - list(APPEND ${library_paths} "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-l(hdf5.*hl.*)$") + list(APPEND library_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") # library name (hl) - list(APPEND ${libraries_hl} "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-l(.*)$") + list(APPEND libraries_hl "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(.*)$") # library name - list(APPEND ${libraries} "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") + list(APPEND libraries "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") # library file - if(NOT EXISTS "${arg}") + if(NOT EXISTS "${_arg}") continue() endif() - get_filename_component(_HDF5_LPATH "${arg}" DIRECTORY) - get_filename_component(_HDF5_LNAME "${arg}" NAME_WE) - string(REGEX REPLACE "^lib" "" _HDF5_LNAME "${_HDF5_LNAME}") - list(APPEND ${library_paths} "${_HDF5_LPATH}") - if(_HDF5_LNAME MATCHES "hdf5.*hl") - list(APPEND ${libraries_hl} "${_HDF5_LNAME}") + get_filename_component(_lpath "${_arg}" DIRECTORY) + get_filename_component(_lname "${_arg}" NAME_WE) + string(REGEX REPLACE "^lib" "" _lname "${_lname}") + list(APPEND library_paths "${_lpath}") + if(_lname MATCHES "hdf5.*hl") + list(APPEND libraries_hl "${_lname}") else() - list(APPEND ${libraries} "${_HDF5_LNAME}") + list(APPEND libraries "${_lname}") endif() endif() endforeach() -endmacro() + foreach(var include_paths definitions library_paths libraries libraries_hl) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() # Select a preferred imported configuration from a target function(_HDF5_select_imported_config target imported_conf) @@ -528,10 +540,10 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) - set(HDF5_${_lang}_FOUND True) + set(HDF5_${_lang}_FOUND TRUE) endif() - if(FIND_HL) - get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if(HDF5_FIND_HL) + get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) if (NOT _hdf5_lang_hl_location) get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) if (NOT _hdf5_hl_lang_location) @@ -542,7 +554,7 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) - set(HDF5_HL_FOUND True) + set(HDF5_HL_FOUND TRUE) endif() unset(_hdf5_lang_hl_location) endif() @@ -553,172 +565,177 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) endif() if(NOT HDF5_FOUND) - set(_HDF5_NEED_TO_SEARCH False) - set(HDF5_COMPILER_NO_INTERROGATE True) + set(_HDF5_NEED_TO_SEARCH FALSE) + set(HDF5_COMPILER_NO_INTERROGATE TRUE) # Only search for languages we've enabled - foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) # First check to see if our regular compiler is one of wrappers - if(__lang STREQUAL "C") + if(_lang STREQUAL "C") _HDF5_test_regular_compiler_C( - HDF5_${__lang}_COMPILER_NO_INTERROGATE - HDF5_${__lang}_VERSION - HDF5_${__lang}_IS_PARALLEL) - elseif(__lang STREQUAL "CXX") + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "CXX") _HDF5_test_regular_compiler_CXX( - HDF5_${__lang}_COMPILER_NO_INTERROGATE - HDF5_${__lang}_VERSION - HDF5_${__lang}_IS_PARALLEL) - elseif(__lang STREQUAL "Fortran") + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "Fortran") _HDF5_test_regular_compiler_Fortran( - HDF5_${__lang}_COMPILER_NO_INTERROGATE - HDF5_${__lang}_IS_PARALLEL) + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_IS_PARALLEL) else() continue() endif() - if(HDF5_${__lang}_COMPILER_NO_INTERROGATE) - message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${__lang} compiling") - set(HDF5_${__lang}_FOUND True) - set(HDF5_${__lang}_COMPILER_EXECUTABLE_NO_INTERROGATE - "${CMAKE_${__lang}_COMPILER}" - CACHE FILEPATH "HDF5 ${__lang} compiler wrapper") - set(HDF5_${__lang}_DEFINITIONS) - set(HDF5_${__lang}_INCLUDE_DIRS) - set(HDF5_${__lang}_LIBRARIES) - set(HDF5_${__lang}_HL_LIBRARIES) - - mark_as_advanced(HDF5_${__lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) - - set(HDF5_${__lang}_FOUND True) - set(HDF5_HL_FOUND True) + if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") + endif() + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE + "${CMAKE_${_lang}_COMPILER}" + CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") + set(HDF5_${_lang}_DEFINITIONS) + set(HDF5_${_lang}_INCLUDE_DIRS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) + + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_HL_FOUND TRUE) else() - set(HDF5_COMPILER_NO_INTERROGATE False) + set(HDF5_COMPILER_NO_INTERROGATE FALSE) # If this language isn't using the wrapper, then try to seed the # search options with the wrapper - find_program(HDF5_${__lang}_COMPILER_EXECUTABLE - NAMES ${HDF5_${__lang}_COMPILER_NAMES} NAMES_PER_DIR + find_program(HDF5_${_lang}_COMPILER_EXECUTABLE + NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR HINTS ${HDF5_ROOT} PATH_SUFFIXES bin Bin - DOC "HDF5 ${__lang} Wrapper compiler. Used only to detect HDF5 compile flags." + DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." ${_HDF5_SEARCH_OPTS} ) - mark_as_advanced( HDF5_${__lang}_COMPILER_EXECUTABLE ) - unset(HDF5_${__lang}_COMPILER_NAMES) - - if(HDF5_${__lang}_COMPILER_EXECUTABLE) - _HDF5_invoke_compiler(${__lang} HDF5_${__lang}_COMPILE_LINE - HDF5_${__lang}_RETURN_VALUE HDF5_${__lang}_VERSION HDF5_${__lang}_IS_PARALLEL) - if(HDF5_${__lang}_RETURN_VALUE EQUAL 0) - message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${__lang} configuration") - _HDF5_parse_compile_line( HDF5_${__lang}_COMPILE_LINE - HDF5_${__lang}_INCLUDE_DIRS - HDF5_${__lang}_DEFINITIONS - HDF5_${__lang}_LIBRARY_DIRS - HDF5_${__lang}_LIBRARY_NAMES - HDF5_${__lang}_HL_LIBRARY_NAMES + mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) + unset(HDF5_${_lang}_COMPILER_NAMES) + + if(HDF5_${_lang}_COMPILER_EXECUTABLE) + _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) + if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") + endif() + _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_INCLUDE_DIRS + HDF5_${_lang}_DEFINITIONS + HDF5_${_lang}_LIBRARY_DIRS + HDF5_${_lang}_LIBRARY_NAMES + HDF5_${_lang}_HL_LIBRARY_NAMES ) - set(HDF5_${__lang}_LIBRARIES) + set(HDF5_${_lang}_LIBRARIES) - foreach(L IN LISTS HDF5_${__lang}_LIBRARY_NAMES) + foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) set(_HDF5_SEARCH_NAMES_LOCAL) - if("x${L}" MATCHES "hdf5") + if("x${_lib}" MATCHES "hdf5") # hdf5 library set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) if(HDF5_USE_STATIC_LIBRARIES) if(WIN32) - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) else() - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) endif() endif() else() # external library set(_HDF5_SEARCH_OPTS_LOCAL) endif() - find_library(HDF5_${__lang}_LIBRARY_${L} - NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR - HINTS ${HDF5_${__lang}_LIBRARY_DIRS} + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} ${HDF5_ROOT} ${_HDF5_SEARCH_OPTS_LOCAL} ) unset(_HDF5_SEARCH_OPTS_LOCAL) unset(_HDF5_SEARCH_NAMES_LOCAL) - if(HDF5_${__lang}_LIBRARY_${L}) - list(APPEND HDF5_${__lang}_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}}) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) else() - list(APPEND HDF5_${__lang}_LIBRARIES ${L}) + list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) endif() endforeach() - if(FIND_HL) - set(HDF5_${__lang}_HL_LIBRARIES) - foreach(L IN LISTS HDF5_${__lang}_HL_LIBRARY_NAMES) + if(HDF5_FIND_HL) + set(HDF5_${_lang}_HL_LIBRARIES) + foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) set(_HDF5_SEARCH_NAMES_LOCAL) - if("x${L}" MATCHES "hdf5") + if("x${_lib}" MATCHES "hdf5") # hdf5 library set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) if(HDF5_USE_STATIC_LIBRARIES) if(WIN32) - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) else() - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) endif() endif() else() # external library set(_HDF5_SEARCH_OPTS_LOCAL) endif() - find_library(HDF5_${__lang}_LIBRARY_${L} - NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR - HINTS ${HDF5_${__lang}_LIBRARY_DIRS} + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} ${HDF5_ROOT} ${_HDF5_SEARCH_OPTS_LOCAL} ) unset(_HDF5_SEARCH_OPTS_LOCAL) unset(_HDF5_SEARCH_NAMES_LOCAL) - if(HDF5_${__lang}_LIBRARY_${L}) - list(APPEND HDF5_${__lang}_HL_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}}) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) else() - list(APPEND HDF5_${__lang}_HL_LIBRARIES ${L}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) endif() endforeach() - set(HDF5_HL_FOUND True) + set(HDF5_HL_FOUND TRUE) endif() - set(HDF5_${__lang}_FOUND True) - _HDF5_remove_duplicates_from_beginning(HDF5_${__lang}_DEFINITIONS) - _HDF5_remove_duplicates_from_beginning(HDF5_${__lang}_INCLUDE_DIRS) - _HDF5_remove_duplicates_from_beginning(HDF5_${__lang}_LIBRARIES) - _HDF5_remove_duplicates_from_beginning(HDF5_${__lang}_HL_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) + _HDF5_remove_duplicates_from_beginning(HDF5_${_lang}_DEFINITIONS) + _HDF5_remove_duplicates_from_beginning(HDF5_${_lang}_INCLUDE_DIRS) + _HDF5_remove_duplicates_from_beginning(HDF5_${_lang}_LIBRARIES) + _HDF5_remove_duplicates_from_beginning(HDF5_${_lang}_HL_LIBRARIES) else() - set(_HDF5_NEED_TO_SEARCH True) + set(_HDF5_NEED_TO_SEARCH TRUE) endif() else() - set(_HDF5_NEED_TO_SEARCH True) + set(_HDF5_NEED_TO_SEARCH TRUE) endif() endif() - if(HDF5_${__lang}_VERSION) + if(HDF5_${_lang}_VERSION) if(NOT HDF5_VERSION) - set(HDF5_VERSION ${HDF5_${__lang}_VERSION}) - elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${__lang}_VERSION) - message(WARNING "HDF5 Version found for language ${__lang}, ${HDF5_${__lang}_VERSION} is different than previously found version ${HDF5_VERSION}") + set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) + elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) + message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") endif() endif() - if(DEFINED HDF5_${__lang}_IS_PARALLEL) + if(DEFINED HDF5_${_lang}_IS_PARALLEL) if(NOT DEFINED HDF5_IS_PARALLEL) - set(HDF5_IS_PARALLEL ${HDF5_${__lang}_IS_PARALLEL}) - elseif(NOT HDF5_IS_PARALLEL AND HDF5_${__lang}_IS_PARALLEL) - message(WARNING "HDF5 found for language ${__lang} is parallel but previously found language is not parallel.") - elseif(HDF5_IS_PARALLEL AND NOT HDF5_${__lang}_IS_PARALLEL) - message(WARNING "HDF5 found for language ${__lang} is not parallel but previously found language is parallel.") + set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) + elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") + elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") endif() endif() endforeach() + unset(_lib) else() - set(_HDF5_NEED_TO_SEARCH True) + set(_HDF5_NEED_TO_SEARCH TRUE) endif() if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) # No arguments necessary, all languages can use the compiler wrappers - set(HDF5_FOUND True) + set(HDF5_FOUND TRUE) set(HDF5_METHOD "Included by compiler wrappers") set(HDF5_REQUIRED_VARS HDF5_METHOD) elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) @@ -727,14 +744,14 @@ elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) set(HDF5_INCLUDE_DIRS) set(HDF5_LIBRARIES) set(HDF5_HL_LIBRARIES) - foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) - if(HDF5_${__lang}_FOUND) - if(NOT HDF5_${__lang}_COMPILER_NO_INTERROGATE) - list(APPEND HDF5_DEFINITIONS ${HDF5_${__lang}_DEFINITIONS}) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${__lang}_INCLUDE_DIRS}) - list(APPEND HDF5_LIBRARIES ${HDF5_${__lang}_LIBRARIES}) - if(FIND_HL) - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${__lang}_HL_LIBRARIES}) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if(HDF5_${_lang}_FOUND) + if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) + list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + if(HDF5_FIND_HL) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) endif() endif() endif() @@ -743,9 +760,9 @@ elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) _HDF5_remove_duplicates_from_beginning(HDF5_INCLUDE_DIRS) _HDF5_remove_duplicates_from_beginning(HDF5_LIBRARIES) _HDF5_remove_duplicates_from_beginning(HDF5_HL_LIBRARIES) - set(HDF5_FOUND True) + set(HDF5_FOUND TRUE) set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) - if(FIND_HL) + if(HDF5_FIND_HL) list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) endif() endif() @@ -769,33 +786,44 @@ if( NOT HDF5_FOUND ) set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) - foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) + # suffixes as seen on Linux, MSYS2, ... + set(_lib_suffixes hdf5) + if(NOT HDF5_PREFER_PARALLEL) + list(APPEND _lib_suffixes hdf5/serial) + endif() + if(HDF5_USE_STATIC_LIBRARIES) + set(_inc_suffixes include/static) + else() + set(_inc_suffixes include/shared) + endif() + + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) # find the HDF5 include directories - if("${__lang}" STREQUAL "Fortran") + if("${_lang}" STREQUAL "Fortran") set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) - elseif("${__lang}" STREQUAL "CXX") + elseif("${_lang}" STREQUAL "CXX") set(HDF5_INCLUDE_FILENAME H5Cpp.h) else() set(HDF5_INCLUDE_FILENAME hdf5.h) endif() - find_path(HDF5_${__lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} + find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} HINTS ${HDF5_ROOT} PATHS $ENV{HOME}/.local/include - PATH_SUFFIXES include Include + PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_HDF5_SEARCH_OPTS} ) - mark_as_advanced(HDF5_${__lang}_INCLUDE_DIR) + mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) # set the _DIRS variable as this is what the user will normally use - set(HDF5_${__lang}_INCLUDE_DIRS ${HDF5_${__lang}_INCLUDE_DIR}) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${__lang}_INCLUDE_DIR}) + set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) # find the HDF5 libraries - foreach(LIB IN LISTS HDF5_${__lang}_LIBRARY_NAMES) + foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) if(HDF5_USE_STATIC_LIBRARIES) # According to bug 1643 on the CMake bug tracker, this is the # preferred method for searching for a static library. - # See https://gitlab.kitware.com/cmake/cmake/issues/1643. We search + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search # first for the full static library name, but fall back to a # generic search on the name if the static search fails. set( THIS_LIBRARY_SEARCH_DEBUG @@ -811,31 +839,32 @@ if( NOT HDF5_FOUND ) endif() find_library(HDF5_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} ${_HDF5_SEARCH_OPTS} ) - find_library( HDF5_${LIB}_LIBRARY_RELEASE + find_library(HDF5_${LIB}_LIBRARY_RELEASE NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} ${_HDF5_SEARCH_OPTS} ) + select_library_configurations( HDF5_${LIB} ) - list(APPEND HDF5_${__lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) endforeach() - if(HDF5_${__lang}_LIBRARIES) - set(HDF5_${__lang}_FOUND True) + if(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) endif() # Append the libraries for this language binding to the list of all # required libraries. - list(APPEND HDF5_LIBRARIES ${HDF5_${__lang}_LIBRARIES}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) - if(FIND_HL) - foreach(LIB IN LISTS HDF5_${__lang}_HL_LIBRARY_NAMES) + if(HDF5_FIND_HL) + foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) if(HDF5_USE_STATIC_LIBRARIES) # According to bug 1643 on the CMake bug tracker, this is the # preferred method for searching for a static library. - # See https://gitlab.kitware.com/cmake/cmake/issues/1643. We search + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search # first for the full static library name, but fall back to a # generic search on the name if the static search fails. set( THIS_LIBRARY_SEARCH_DEBUG @@ -848,25 +877,26 @@ if( NOT HDF5_FOUND ) endif() find_library(HDF5_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} ${_HDF5_SEARCH_OPTS} ) - find_library( HDF5_${LIB}_LIBRARY_RELEASE + find_library(HDF5_${LIB}_LIBRARY_RELEASE NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} ${_HDF5_SEARCH_OPTS} ) + select_library_configurations( HDF5_${LIB} ) - list(APPEND HDF5_${__lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) endforeach() # Append the libraries for this language binding to the list of all # required libraries. - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${__lang}_HL_LIBRARIES}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) endif() endforeach() - if(FIND_HL AND HDF5_HL_LIBRARIES) - set(HDF5_HL_FOUND True) + if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) + set(HDF5_HL_FOUND TRUE) endif() _HDF5_remove_duplicates_from_beginning(HDF5_DEFINITIONS) @@ -903,12 +933,14 @@ if( NOT HDF5_FOUND ) endif() endforeach() endforeach() + unset(_hdr) + unset(_dir) set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL "HDF5 library compiled with parallel IO support" ) mark_as_advanced( HDF5_IS_PARALLEL ) set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) - if(FIND_HL) + if(HDF5_FIND_HL) list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) endif() endif() @@ -946,13 +978,15 @@ if (HDF5_FIND_DEBUG) message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") - foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) - message(STATUS "HDF5_${__lang}_DEFINITIONS: ${HDF5_${__lang}_DEFINITIONS}") - message(STATUS "HDF5_${__lang}_INCLUDE_DIR: ${HDF5_${__lang}_INCLUDE_DIR}") - message(STATUS "HDF5_${__lang}_INCLUDE_DIRS: ${HDF5_${__lang}_INCLUDE_DIRS}") - message(STATUS "HDF5_${__lang}_LIBRARY: ${HDF5_${__lang}_LIBRARY}") - message(STATUS "HDF5_${__lang}_LIBRARIES: ${HDF5_${__lang}_LIBRARIES}") - message(STATUS "HDF5_${__lang}_HL_LIBRARY: ${HDF5_${__lang}_HL_LIBRARY}") - message(STATUS "HDF5_${__lang}_HL_LIBRARIES: ${HDF5_${__lang}_HL_LIBRARIES}") + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") + message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") + message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") + message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") + message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") endforeach() endif() +unset(_lang) +unset(_HDF5_NEED_TO_SEARCH) diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake index c962976..e275946 100644 --- a/Modules/FindLAPACK.cmake +++ b/Modules/FindLAPACK.cmake @@ -38,11 +38,23 @@ The following variables may be set to influence this module's behavior: * ``ACML`` * ``Apple`` * ``NAS`` + * ``Arm`` + * ``Arm_mp`` + * ``Arm_ilp64`` + * ``Arm_ilp64_mp`` * ``Generic`` ``BLA_F95`` if ``ON`` tries to find the BLAS95/LAPACK95 interfaces +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``LAPACK::LAPACK`` + The libraries to use for LAPACK, if found. + Result Variables ^^^^^^^^^^^^^^^^ @@ -359,6 +371,36 @@ if(BLAS_FOUND) endif() endif() + # ArmPL? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries) + if(BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All") + + # Check for 64bit Integer support + if(BLA_VENDOR MATCHES "_ilp64") + set(LAPACK_armpl_LIB "armpl_ilp64") + else() + set(LAPACK_armpl_LIB "armpl_lp64") + endif() + + # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp + if(BLA_VENDOR MATCHES "_mp") + set(LAPACK_armpl_LIB "${LAPACK_armpl_LIB}_mp") + endif() + + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "${LAPACK_armpl_LIB}" + "" + "" + "" + "${BLAS_LIBRARIES}" + ) + endif() + endif() + # FLAME's blis library? (https://github.com/flame/blis) if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All") if(NOT LAPACK_LIBRARIES) @@ -492,5 +534,22 @@ if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES") set(LAPACK_LIBRARIES "") endif() +if(NOT TARGET LAPACK::LAPACK) + add_library(LAPACK::LAPACK INTERFACE IMPORTED) + set(_lapack_libs "${LAPACK_LIBRARIES}") + if(_lapack_libs AND TARGET BLAS::BLAS) + # remove the ${BLAS_LIBRARIES} from the interface and replace it + # with the BLAS::BLAS target + list(REMOVE_ITEM _lapack_libs "${BLAS_LIBRARIES}") + endif() + + if(_lapack_libs) + set_target_properties(LAPACK::LAPACK PROPERTIES + INTERFACE_LINK_LIBRARIES "${_lapack_libs}" + ) + endif() + unset(_lapack_libs) +endif() + cmake_pop_check_state() set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake index 01a9d8b..fc7adeb 100644 --- a/Modules/FindLibXslt.cmake +++ b/Modules/FindLibXslt.cmake @@ -8,9 +8,22 @@ FindLibXslt Find the XSL Transformations, Extensible Stylesheet Language Transformations (XSLT) library (LibXslt) -Once done this will define +IMPORTED Targets +^^^^^^^^^^^^^^^^ -:: +The following :prop_tgt:`IMPORTED` targets may be defined: + +``LibXslt::LibXslt`` + If the libxslt library has been found +``LibXslt::LibExslt`` + If the libexslt library has been found +``LibXslt::xsltproc`` + If the xsltproc command-line executable has been found + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: LIBXSLT_FOUND - system has LibXslt LIBXSLT_INCLUDE_DIR - the LibXslt include directory @@ -21,6 +34,8 @@ Once done this will define Additionally, the following two variables are set (but not required for using xslt): +``LIBXSLT_EXSLT_INCLUDE_DIR`` + The include directory for exslt. ``LIBXSLT_EXSLT_LIBRARIES`` Link to these if you need to link against the exslt library. ``LIBXSLT_XSLTPROC_EXECUTABLE`` @@ -39,16 +54,36 @@ find_path(LIBXSLT_INCLUDE_DIR NAMES libxslt/xslt.h ${PC_LIBXSLT_INCLUDE_DIRS} ) -find_library(LIBXSLT_LIBRARIES NAMES xslt libxslt +# CMake 3.17 and below used 'LIBXSLT_LIBRARIES' as the name of +# the cache entry storing the find_library result. Use the +# value if it was set by the project or user. +if(DEFINED LIBXSLT_LIBRARIES AND NOT DEFINED LIBXSLT_LIBRARY) + set(LIBXSLT_LIBRARY ${LIBXSLT_LIBRARIES}) +endif() + +find_library(LIBXSLT_LIBRARY NAMES xslt libxslt HINTS ${PC_LIBXSLT_LIBDIR} ${PC_LIBXSLT_LIBRARY_DIRS} ) +set(LIBXSLT_LIBRARIES ${LIBXSLT_LIBRARY}) + +PKG_CHECK_MODULES(PC_LIBXSLT_EXSLT QUIET libexslt) +set(LIBXSLT_EXSLT_DEFINITIONS ${PC_LIBXSLT_EXSLT_CFLAGS_OTHER}) + +find_path(LIBXSLT_EXSLT_INCLUDE_DIR NAMES libexslt/exslt.h + HINTS + ${PC_LIBXSLT_EXSLT_INCLUDEDIR} + ${PC_LIBXSLT_EXSLT_INCLUDE_DIRS} +) + find_library(LIBXSLT_EXSLT_LIBRARY NAMES exslt libexslt HINTS ${PC_LIBXSLT_LIBDIR} ${PC_LIBXSLT_LIBRARY_DIRS} + ${PC_LIBXSLT_EXSLT_LIBDIR} + ${PC_LIBXSLT_EXSLT_LIBRARY_DIRS} ) set(LIBXSLT_EXSLT_LIBRARIES ${LIBXSLT_EXSLT_LIBRARY} ) @@ -75,3 +110,22 @@ mark_as_advanced(LIBXSLT_INCLUDE_DIR LIBXSLT_LIBRARIES LIBXSLT_EXSLT_LIBRARY LIBXSLT_XSLTPROC_EXECUTABLE) + +if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibXslt) + add_library(LibXslt::LibXslt UNKNOWN IMPORTED) + set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_INCLUDE_DIR}") + set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_DEFINITIONS}") + set_property(TARGET LibXslt::LibXslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_LIBRARY}") +endif() + +if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibExslt) + add_library(LibXslt::LibExslt UNKNOWN IMPORTED) + set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_EXSLT_INCLUDE_DIR}") + set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_EXSLT_DEFINITIONS}") + set_property(TARGET LibXslt::LibExslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_EXSLT_LIBRARY}") +endif() + +if(LIBXSLT_XSLTPROC_EXECUTABLE AND NOT TARGET LibXslt::xsltproc) + add_executable(LibXslt::xsltproc IMPORTED) + set_target_properties(LibXslt::xsltproc PROPERTIES IMPORTED_LOCATION "${LIBXSLT_XSLTPROC_EXECUTABLE}") +endif() diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index cdbb927..786bcc8 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -867,11 +867,11 @@ function(_MPI_guess_settings LANG) # We first attempt to locate the msmpi.lib. Should be find it, we'll assume that the MPI present is indeed # Microsoft MPI. if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) - set(MPI_MSMPI_LIB_PATH "$ENV{MSMPI_LIB64}") - set(MPI_MSMPI_INC_PATH_EXTRA "$ENV{MSMPI_INC}/x64") + file(TO_CMAKE_PATH "$ENV{MSMPI_LIB64}" MPI_MSMPI_LIB_PATH) + file(TO_CMAKE_PATH "$ENV{MSMPI_INC}/x64" MPI_MSMPI_INC_PATH_EXTRA) else() - set(MPI_MSMPI_LIB_PATH "$ENV{MSMPI_LIB32}") - set(MPI_MSMPI_INC_PATH_EXTRA "$ENV{MSMPI_INC}/x86") + file(TO_CMAKE_PATH "$ENV{MSMPI_LIB32}" MPI_MSMPI_LIB_PATH) + file(TO_CMAKE_PATH "$ENV{MSMPI_INC}/x86" MPI_MSMPI_INC_PATH_EXTRA) endif() find_library(MPI_msmpi_LIBRARY @@ -1154,7 +1154,7 @@ macro(_MPI_create_imported_target LANG) endif() # When this is consumed for compiling CUDA, use '-Xcompiler' to wrap '-pthread'. - string(REPLACE "-pthread" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >-pthread" + string(REPLACE "-pthread" "$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:SHELL:-Xcompiler >-pthread" _MPI_${LANG}_COMPILE_OPTIONS "${MPI_${LANG}_COMPILE_OPTIONS}") set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_COMPILE_OPTIONS "${_MPI_${LANG}_COMPILE_OPTIONS}") unset(_MPI_${LANG}_COMPILE_OPTIONS) diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake index 27dcaf5..b5b92c5 100644 --- a/Modules/FindOpenAL.cmake +++ b/Modules/FindOpenAL.cmake @@ -5,27 +5,45 @@ FindOpenAL ---------- - Finds Open Audio Library (OpenAL). -This module defines ``OPENAL_LIBRARY OPENAL_FOUND``, if -false, do not try to link to OpenAL ``OPENAL_INCLUDE_DIR``, where to find -the headers. -``$OPENALDIR`` is an environment variable that would correspond to the -``./configure --prefix=$OPENALDIR`` used in building OpenAL. +Projects using this module should use ``#include "al.h"`` to include the OpenAL +header file, **not** ``#include <AL/al.h>``. The reason for this is that the +latter is not entirely portable. Windows/Creative Labs does not by default put +their headers in ``AL/`` and macOS uses the convention ``<OpenAL/al.h>``. + +Hints +^^^^^ + +Environment variable ``$OPENALDIR`` can be used to set the prefix of OpenAL +installation to be found. + +By default on macOS, system framework is search first. In other words, +OpenAL is searched in the following order: + +1. System framework: ``/System/Library/Frameworks``, whose priority can be + changed via setting the :variable:`CMAKE_FIND_FRAMEWORK` variable. +2. Environment variable ``$OPENALDIR``. +3. System paths. +4. User-compiled framework: ``~/Library/Frameworks``. +5. Manually compiled framework: ``/Library/Frameworks``. +6. Add-on package: ``/opt``. + +Result Variables +^^^^^^^^^^^^^^^^ -Created by Eric Wing. This was influenced by the ``FindSDL.cmake`` -module. +This module defines the following variables: + +``OPENAL_FOUND`` + If false, do not try to link to OpenAL +``OPENAL_INCLUDE_DIR`` + OpenAL include directory +``OPENAL_LIBRARY`` + Path to the OpenAL library +``OPENAL_VERSION_STRING`` + Human-readable string containing the version of OpenAL #]=======================================================================] -# This makes the presumption that you are include al.h like -# #include "al.h" -# and not -# #include <AL/al.h> -# The reason for this is that the latter is not entirely portable. -# Windows/Creative Labs does not by default put their headers in AL/ and -# OS X uses the convention <OpenAL/al.h>. -# # For Windows, Creative Labs seems to have added a registry key for their # OpenAL 1.1 installer. I have added that key to the list of search paths, # however, the key looks like it could be a little fragile depending on @@ -36,36 +54,17 @@ module. # platforms are introduced. # The OpenAL 1.0 installer doesn't seem to have a useful key I can use. # I do not know if the Nvidia OpenAL SDK has a registry key. -# -# For OS X, remember that OpenAL was added by Apple in 10.4 (Tiger). -# To support the framework, I originally wrote special framework detection -# code in this module which I have now removed with CMake's introduction -# of native support for frameworks. -# In addition, OpenAL is open source, and it is possible to compile on Panther. -# Furthermore, due to bugs in the initial OpenAL release, and the -# transition to OpenAL 1.1, it is common to need to override the built-in -# framework. -# Per my request, CMake should search for frameworks first in -# the following order: -# ~/Library/Frameworks/OpenAL.framework/Headers -# /Library/Frameworks/OpenAL.framework/Headers -# /System/Library/Frameworks/OpenAL.framework/Headers -# -# On OS X, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# OPENAL_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. find_path(OPENAL_INCLUDE_DIR al.h HINTS ENV OPENALDIR - PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL PATHS - ~/Library/Frameworks - /Library/Frameworks - /opt - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] -) + ~/Library/Frameworks + /Library/Frameworks + /opt + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] + PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL + ) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(_OpenAL_ARCH_DIR libs/Win64) @@ -77,17 +76,21 @@ find_library(OPENAL_LIBRARY NAMES OpenAL al openal OpenAL32 HINTS ENV OPENALDIR - PATH_SUFFIXES libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR} PATHS - ~/Library/Frameworks - /Library/Frameworks - /opt - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] -) + ~/Library/Frameworks + /Library/Frameworks + /opt + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] + PATH_SUFFIXES libx32 lib64 lib libs64 libs ${_OpenAL_ARCH_DIR} + ) unset(_OpenAL_ARCH_DIR) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR) +find_package_handle_standard_args( + OpenAL + REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR + VERSION_VAR OPENAL_VERSION_STRING + ) mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR) diff --git a/Modules/FindOpenCL.cmake b/Modules/FindOpenCL.cmake index 9891724..34a203e 100644 --- a/Modules/FindOpenCL.cmake +++ b/Modules/FindOpenCL.cmake @@ -78,6 +78,8 @@ find_path(OpenCL_INCLUDE_DIR ENV CUDA_PATH ENV ATISTREAMSDKROOT ENV OCL_ROOT + /usr/local/cuda + /opt/cuda PATH_SUFFIXES include OpenCL/common/inc @@ -126,6 +128,8 @@ else() PATHS ENV AMDAPPSDKROOT ENV CUDA_PATH + /usr/local/cuda + /opt/cuda PATH_SUFFIXES lib/x86 lib) @@ -135,6 +139,8 @@ else() PATHS ENV AMDAPPSDKROOT ENV CUDA_PATH + /usr/local/cuda + /opt/cuda PATH_SUFFIXES lib/x86_64 lib/x64 diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake index 45b641d..8ddd78e 100644 --- a/Modules/FindOpenSSL.cmake +++ b/Modules/FindOpenSSL.cmake @@ -22,6 +22,27 @@ This module defines the following :prop_tgt:`IMPORTED` targets: The OpenSSL ``ssl`` library, if found. ``OpenSSL::Crypto`` The OpenSSL ``crypto`` library, if found. +``OpenSSL::applink`` + The OpenSSL ``applink`` components that might be need to be compiled into + projects under MSVC. This target is available only if found OpenSSL version + is not less than 0.9.8. By linking this target the above OpenSSL targets can + be linked even if the project has different MSVC runtime configurations with + the above OpenSSL targets. This target has no effect on plaforms other than + MSVC. + +NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target, +unless you certainly know what you are doing, it is always prefered to link +``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is +linked at most once for the whole dependency graph of any library or +executable: + +.. code-block:: cmake + + target_link_libraries(myTarget PRIVATE OpenSSL::applink) + +Otherwise you would probably encounter unexpected random problems when building +and linking, as both the ISO C and the ISO C++ standard claims almost nothing +about what a link process should be. Result Variables ^^^^^^^^^^^^^^^^ @@ -45,6 +66,10 @@ This module will set the following variables in your project: All OpenSSL libraries and their dependencies. ``OPENSSL_VERSION`` This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``). +``OPENSSL_APPLINK_SOURCE`` + The sources in the target ``OpenSSL::applink`` that is mentioned above. This + variable shall always be undefined if found openssl version is less than + 0.9.8 or if platform is not MSVC. Hints ^^^^^ @@ -533,6 +558,28 @@ if(OPENSSL_FOUND) endif() _OpenSSL_target_add_dependencies(OpenSSL::SSL) endif() + + if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8") + if(MSVC) + if(EXISTS "${OPENSSL_INCLUDE_DIR}") + set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR}) + endif() + find_file(OPENSSL_APPLINK_SOURCE + NAMES + openssl/applink.c + ${_OPENSSL_applink_paths} + NO_DEFAULT_PATH) + if(OPENSSL_APPLINK_SOURCE) + set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE}) + endif() + endif() + if(NOT TARGET OpenSSL::applink) + add_library(OpenSSL::applink INTERFACE IMPORTED) + set_property(TARGET OpenSSL::applink APPEND + PROPERTY INTERFACE_SOURCES + ${_OPENSSL_applink_interface_srcs}) + endif() + endif() endif() # Restore the original find library ordering diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index a078049..4fb0825 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -57,7 +57,8 @@ valid filepaths. These may be named in the generated failure message asking the user to set the missing variable values. Therefore these should typically be cache entries such as ``FOO_LIBRARY`` and not output - variables like ``FOO_LIBRARIES``. + variables like ``FOO_LIBRARIES``. This option is mandatory if + ``HANDLE_COMPONENTS`` is not specified. ``VERSION_VAR <version-var>`` Specify the name of a variable that holds the version of the package @@ -257,7 +258,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(FPHSA_VERSION_VAR ${_NAME}_VERSION) endif() - if(NOT FPHSA_REQUIRED_VARS) + if(NOT FPHSA_REQUIRED_VARS AND NOT FPHSA_HANDLE_COMPONENTS) message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") endif() endif() @@ -283,7 +284,9 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") endif() - list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) + if (FPHSA_REQUIRED_VARS) + list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) + endif() string(TOUPPER ${_NAME} _NAME_UPPER) string(TOLOWER ${_NAME} _NAME_LOWER) @@ -440,7 +443,17 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) _FPHSA_HANDLE_FAILURE_CONFIG_MODE() else() if(NOT VERSION_OK) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") + set(RESULT_MSG) + if (_FIRST_REQUIRED_VAR) + string (APPEND RESULT_MSG "found ${${_FIRST_REQUIRED_VAR}}") + endif() + if (COMPONENT_MSG) + if (RESULT_MSG) + string (APPEND RESULT_MSG ", ") + endif() + string (APPEND RESULT_MSG "${FOUND_COMPONENTS_MSG}") + endif() + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (${RESULT_MSG})") else() _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing:${MISSING_VARS}) ${VERSION_MSG}") endif() diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index c79f20f..93827d8 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -34,16 +34,31 @@ endif() find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable") mark_as_advanced(PKG_CONFIG_EXECUTABLE) +set(_PKG_CONFIG_FAILURE_MESSAGE "") if (PKG_CONFIG_EXECUTABLE) execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --version - OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _PKG_CONFIG_VERSION_ERROR ERROR_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _PKG_CONFIG_VERSION_RESULT + ) + + if (NOT _PKG_CONFIG_VERSION_RESULT EQUAL 0) + string(REPLACE "\n" "\n " _PKG_CONFIG_VERSION_ERROR " ${_PKG_CONFIG_VERSION_ERROR}") + string(APPEND _PKG_CONFIG_FAILURE_MESSAGE + "The command\n" + " \"${PKG_CONFIG_EXECUTABLE}\" --version\n" + " failed with output\n${_PKG_CONFIG_VERSION_ERROR}" + ) + set(PKG_CONFIG_EXECUTABLE "") + unset(PKG_CONFIG_VERSION_STRING) + endif () + unset(_PKG_CONFIG_VERSION_RESULT) endif () include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(PkgConfig REQUIRED_VARS PKG_CONFIG_EXECUTABLE + REASON_FAILURE_MESSAGE "${_PKG_CONFIG_FAILURE_MESSAGE}" VERSION_VAR PKG_CONFIG_VERSION_STRING) # This is needed because the module name is "PkgConfig" but the name of @@ -197,7 +212,13 @@ function(_pkg_find_libs _prefix _no_cmake_path _no_cmake_environment_path) endif() unset(_search_paths) + unset(_next_is_framework) foreach (flag IN LISTS ${_prefix}_LDFLAGS) + if (_next_is_framework) + list(APPEND _libs "-framework ${flag}") + unset(_next_is_framework) + continue() + endif () if (flag MATCHES "^-L(.*)") list(APPEND _search_paths ${CMAKE_MATCH_1}) continue() @@ -205,6 +226,9 @@ function(_pkg_find_libs _prefix _no_cmake_path _no_cmake_environment_path) if (flag MATCHES "^-l(.*)") set(_pkg_search "${CMAKE_MATCH_1}") else() + if (flag STREQUAL "-framework") + set(_next_is_framework TRUE) + endif () continue() endif() @@ -364,6 +388,60 @@ macro(_pkg_restore_path_internal) unset(_pkgconfig_path_old) endmacro() +# pkg-config returns frameworks in --libs-only-other +# they need to be in ${_prefix}_LIBRARIES so "-framework a -framework b" does +# not incorrectly be combined to "-framework a b" +function(_pkgconfig_extract_frameworks _prefix) + set(ldflags "${${_prefix}_LDFLAGS_OTHER}") + list(FIND ldflags "-framework" FR_POS) + list(LENGTH ldflags LD_LENGTH) + + # reduce length by 1 as we need "-framework" and the next entry + math(EXPR LD_LENGTH "${LD_LENGTH} - 1") + while (FR_POS GREATER -1 AND LD_LENGTH GREATER FR_POS) + list(REMOVE_AT ldflags ${FR_POS}) + list(GET ldflags ${FR_POS} HEAD) + list(REMOVE_AT ldflags ${FR_POS}) + math(EXPR LD_LENGTH "${LD_LENGTH} - 2") + + list(APPEND LIBS "-framework ${HEAD}") + + list(FIND ldflags "-framework" FR_POS) + endwhile () + set(${_prefix}_LIBRARIES ${${_prefix}_LIBRARIES} ${LIBS} PARENT_SCOPE) + set(${_prefix}_LDFLAGS_OTHER "${ldflags}" PARENT_SCOPE) +endfunction() + +# pkg-config returns -isystem include directories in --cflags-only-other, +# depending on the version and if there is a space between -isystem and +# the actual path +function(_pkgconfig_extract_isystem _prefix) + set(cflags "${${_prefix}_CFLAGS_OTHER}") + set(outflags "") + set(incdirs "${${_prefix}_INCLUDE_DIRS}") + + set(next_is_isystem FALSE) + foreach (THING IN LISTS cflags) + # This may filter "-isystem -isystem". That would not work anyway, + # so let it happen. + if (THING STREQUAL "-isystem") + set(next_is_isystem TRUE) + continue() + endif () + if (next_is_isystem) + set(next_is_isystem FALSE) + list(APPEND incdirs "${THING}") + elseif (THING MATCHES "^-isystem") + string(SUBSTRING "${THING}" 8 -1 THING) + list(APPEND incdirs "${THING}") + else () + list(APPEND outflags "${THING}") + endif () + endforeach () + set(${_prefix}_CFLAGS_OTHER "${outflags}" PARENT_SCOPE) + set(${_prefix}_INCLUDE_DIRS "${incdirs}" PARENT_SCOPE) +endfunction() + ### macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global _prefix) _pkgconfig_unset(${_prefix}_FOUND) @@ -497,14 +575,22 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma endforeach() # set variables which are combined for multiple modules - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES "(^| )-l" --libs-only-l ) - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS "(^| )-L" --libs-only-L ) - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS "" --libs ) - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER "" --libs-only-other ) - - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS "(^| )-I" --cflags-only-I ) - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags ) - _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES "(^| )-l" --libs-only-l ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS "(^| )-L" --libs-only-L ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS "" --libs ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER "" --libs-only-other ) + + if (APPLE AND "-framework" IN_LIST ${_prefix}_LDFLAGS_OTHER) + _pkgconfig_extract_frameworks("${_prefix}") + endif() + + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS "(^| )(-I|-isystem ?)" --cflags-only-I ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other ) + + if (${_prefix}_CFLAGS_OTHER MATCHES "-isystem") + _pkgconfig_extract_isystem("${_prefix}") + endif () _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global}) endif() diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index 32ef120..01b82c4 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -13,13 +13,24 @@ The following components are supported: * ``Interpreter``: search for Python interpreter. * ``Compiler``: search for Python compiler. Only offered by IronPython. * ``Development``: search for development artifacts (include directories and - libraries). + libraries). This component includes two sub-components which can be specified + independently: + + * ``Development.Module``: search for artifacts for Python module + developments. + * ``Development.Embed``: search for artifacts for Python embedding + developments. + * ``NumPy``: search for NumPy include directories. If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed. +If component ``Development`` is specified, it implies sub-components +``Development.Module`` and ``Development.Embed``. + To ensure consistent versions between components ``Interpreter``, ``Compiler``, -``Development`` and ``NumPy``, specify all components at the same time:: +``Development`` (or one of its sub-components) and ``NumPy``, specify all +components at the same time:: find_package (Python COMPONENTS Interpreter Development) @@ -30,10 +41,11 @@ To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and .. note:: - If components ``Interpreter`` and ``Development`` are both specified, this - module search only for interpreter with same platform architecture as the one - defined by ``CMake`` configuration. This contraint does not apply if only - ``Interpreter`` component is specified. + If components ``Interpreter`` and ``Development`` (or one of its + sub-components) are both specified, this module search only for interpreter + with same platform architecture as the one defined by ``CMake`` + configuration. This contraint does not apply if only ``Interpreter`` + component is specified. Imported Targets ^^^^^^^^^^^^^^^^ @@ -45,12 +57,12 @@ This module defines the following :ref:`Imported Targets <Imported Targets>` Python interpreter. Target defined if component ``Interpreter`` is found. ``Python::Compiler`` Python compiler. Target defined if component ``Compiler`` is found. +``Python::Module`` + Python library for Python module. Target defined if component + ``Development.Module`` is found. ``Python::Python`` Python library for Python embedding. Target defined if component - ``Development`` is found. -``Python::Module`` - Python library for Python module. Target defined if component ``Development`` - is found. + ``Development.Embed`` is found. ``Python::NumPy`` NumPy Python library. Target defined if component ``NumPy`` is found. @@ -73,33 +85,40 @@ This module will set the following variables in your project * Anaconda * Canopy * IronPython + * PyPy ``Python_STDLIB`` Standard platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)`` + or else ``sysconfig.get_path('stdlib')``. ``Python_STDARCH`` Standard platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)`` + or else ``sysconfig.get_path('platstdlib')``. ``Python_SITELIB`` Third-party platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)`` + or else ``sysconfig.get_path('purelib')``. ``Python_SITEARCH`` Third-party platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)`` + or else ``sysconfig.get_path('platlib')``. ``Python_SOABI`` Extension suffix for modules. Information returned by - ``distutils.sysconfig.get_config_flag('SOABI')`` or computed from - ``distutils.sysconfig.get_config_flag('EXT_SUFFIX')`` or - ``python-config --extension-suffix``. + ``distutils.sysconfig.get_config_var('SOABI')`` or computed from + ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` or + ``python-config --extension-suffix``. If package ``distutils.sysconfig`` is + not available, ``sysconfig.get_config_var('SOABI')`` or + ``sysconfig.get_config_var('EXT_SUFFIX')`` are used. ``Python_Compiler_FOUND`` System has the Python compiler. ``Python_COMPILER`` @@ -107,8 +126,14 @@ This module will set the following variables in your project ``Python_COMPILER_ID`` A short string unique to the compiler. Possible values include: * IronPython +``Python_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. ``Python_Development_FOUND`` System has the Python development artifacts. +``Python_Development.Module_FOUND`` + System has the Python development artifacts for Python module. +``Python_Development.Embed_FOUND`` + System has the Python development artifacts for Python embedding. ``Python_INCLUDE_DIRS`` The Python include directories. ``Python_LIBRARIES`` @@ -125,6 +150,8 @@ This module will set the following variables in your project Python minor version. ``Python_VERSION_PATCH`` Python patch version. +``Python_PyPy_VERSION`` + Python PyPy version. ``Python_NumPy_FOUND`` System has the NumPy. ``Python_NumPy_INCLUDE_DIRS`` @@ -237,8 +264,9 @@ Hints * ``ONLY``: Only the virtual environment is used to look-up for the interpreter. * ``STANDARD``: The virtual environment is not used to look-up for the - interpreter. In this case, variable ``Python_FIND_REGISTRY`` (Windows) - or ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or + interpreter but environment variable ``PATH`` is always considered. + In this case, variable ``Python_FIND_REGISTRY`` (Windows) or + ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or ``NEVER`` to select preferably the interpreter from the virtual environment. @@ -248,6 +276,39 @@ Hints recommended to also include the component ``Interpreter`` to get expected result. +``Python_FIND_IMPLEMENTATIONS`` + This variable defines, in an ordered list, the different implementations + which will be searched. The ``Python_FIND_IMPLEMENTATIONS`` variable can + hold the following values: + + * ``CPython``: this is the standard implementation. Various products, like + ``Anaconda`` or ``ActivePython``, rely on this implementation. + * ``IronPython``: This implementation use the ``CSharp`` language for + ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``). + See `IronPython <http://ironpython.net>`_. + * ``PyPy``: This implementation use ``RPython`` language and + ``RPython translation toolchain`` to produce the python interpreter. + See `PyPy <https://www.pypy.org>`_. + + The default value is: + + * Windows platform: ``CPython``, ``IronPython`` + * Other platforms: ``CPython`` + + .. note:: + + This hint has the lowest priority of all hints, so even if, for example, + you specify ``IronPython`` first and ``CPython`` in second, a python + product based on ``CPython`` can be selected because, for example with + ``Python_FIND_STRATEGY=LOCATION``, each location will be search first for + ``IronPython`` and second for ``CPython``. + + .. note:: + + When ``IronPython`` is specified, on platforms other than ``Windows``, the + ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available + through the ``PATH`` variable. + Artifacts Specification ^^^^^^^^^^^^^^^^^^^^^^^ @@ -260,6 +321,9 @@ setting the following variables: ``Python_COMPILER`` The path to the compiler. +``Python_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. + ``Python_LIBRARY`` The path to the library. It will be used to compute the variables ``Python_LIBRARIES``, ``Python_LIBRAY_DIRS`` and @@ -286,6 +350,22 @@ setting the following variables: If more than one artifact is specified, it is the user's responsability to ensure the consistency of the various artifacts. +By default, this module supports multiple calls in different directories of a +project with different version/component requirements while providing correct +and consistent results for each call. To support this behavior, ``CMake`` cache +is not used in the traditional way which can be problematic for interactive +specification. So, to enable also interactive specification, module behavior +can be controled with the following variable: + +``Python_ARTIFACTS_INTERACTIVE`` + Selects the behavior of the module. This is a boolean variable: + + * If set to ``TRUE``: Create CMake cache entries for the above artifact + specification variables so that users can edit them interactively. + This disables support for multiple version/component requirements. + * If set to ``FALSE`` or undefined: Enable multiple version/component + requirements. + Commands ^^^^^^^^ diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 8789d7b..1be0625 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -22,9 +22,9 @@ endif() if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) message (FATAL_ERROR "FindPython: INTERNAL ERROR") endif() -if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 3) +if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3") set(_${_PYTHON_PREFIX}_VERSIONS 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) -elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL 2) +elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "2") set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) else() message (FATAL_ERROR "FindPython: INTERNAL ERROR") @@ -75,71 +75,135 @@ macro (_PYTHON_SELECT_LIBRARY_CONFIGURATIONS _PYTHON_BASENAME) (_PYTHON_isMultiConfig OR CMAKE_BUILD_TYPE)) # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for # single-config generators, set optimized and debug libraries - set (${_PYTHON_BASENAME}_LIBRARY "") - foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE ) - list( APPEND ${_PYTHON_BASENAME}_LIBRARY optimized "${_PYTHON_libname}" ) + set (${_PYTHON_BASENAME}_LIBRARIES "") + foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE) + list( APPEND ${_PYTHON_BASENAME}_LIBRARIES optimized "${_PYTHON_libname}") endforeach() - foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG ) - list( APPEND ${_PYTHON_BASENAME}_LIBRARY debug "${_PYTHON_libname}" ) + foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG) + list( APPEND ${_PYTHON_BASENAME}_LIBRARIES debug "${_PYTHON_libname}") endforeach() elseif (${_PYTHON_BASENAME}_LIBRARY_RELEASE) - set (${_PYTHON_BASENAME}_LIBRARY "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}") + set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}") elseif (${_PYTHON_BASENAME}_LIBRARY_DEBUG) - set (${_PYTHON_BASENAME}_LIBRARY "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}") + set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}") else() - set (${_PYTHON_BASENAME}_LIBRARY "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND") + set (${_PYTHON_BASENAME}_LIBRARIES "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND") endif() - - set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY}") endmacro() macro (_PYTHON_FIND_FRAMEWORKS) - set (${_PYTHON_PREFIX}_FRAMEWORKS) if (CMAKE_HOST_APPLE OR APPLE) file(TO_CMAKE_PATH "$ENV{CMAKE_FRAMEWORK_PATH}" _pff_CMAKE_FRAMEWORK_PATH) set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH} - ${_pff_CMAKE_FRAMEWORK_PATH} - ~/Library/Frameworks - /usr/local/Frameworks - ${CMAKE_SYSTEM_FRAMEWORK_PATH}) + ${_pff_CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /usr/local/Frameworks + ${CMAKE_SYSTEM_FRAMEWORK_PATH}) list (REMOVE_DUPLICATES _pff_frameworks) - foreach (_pff_framework IN LISTS _pff_frameworks) - if (EXISTS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework) - list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework) - endif() - if (EXISTS ${_pff_framework}/Python.framework) - list (APPEND ${_PYTHON_PREFIX}_FRAMEWORKS ${_pff_framework}/Python.framework) + foreach (_pff_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + unset (_${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS) + if (_pff_implementation STREQUAL "CPython") + foreach (_pff_framework IN LISTS _pff_frameworks) + if (EXISTS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework) + list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework) + endif() + if (EXISTS ${_pff_framework}/Python.framework) + list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python.framework) + endif() + endforeach() + elseif (_pff_implementation STREQUAL "IronPython") + foreach (_pff_framework IN LISTS _pff_frameworks) + if (EXISTS ${_pff_framework}/IronPython.framework) + list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/IronPython.framework) + endif() + endforeach() endif() endforeach() + unset (_pff_implementation) unset (_pff_frameworks) unset (_pff_framework) endif() endmacro() -function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS _PYTHON_VERSION) - set (_PYTHON_FRAMEWORK_PATHS) - foreach (_PYTHON_FRAMEWORK IN LISTS ${_PYTHON_PREFIX}_FRAMEWORKS) - list (APPEND _PYTHON_FRAMEWORK_PATHS - "${_PYTHON_FRAMEWORK}/Versions/${_PYTHON_VERSION}") +function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS) + cmake_parse_arguments (PARSE_ARGV 1 _PGF "" "" "IMPLEMENTATIONS;VERSION") + + if (NOT _PGF_IMPLEMENTATIONS) + set (_PGF_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}) + endif() + + set (framework_paths) + + foreach (implementation IN LISTS _PGF_IMPLEMENTATIONS) + if (implementation STREQUAL "CPython") + foreach (version IN LISTS _PGF_VERSION) + foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS) + if (EXISTS "${framework}/Versions/${version}") + list (APPEND framework_paths "${framework}/Versions/${version}") + endif() + endforeach() + endforeach() + elseif (implementation STREQUAL "IronPython") + foreach (version IN LISTS _PGF_VERSION) + foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS) + # pick-up all available versions + file (GLOB versions LIST_DIRECTORIES true RELATIVE "${framework}/Versions/" + "${framework}/Versions/${version}*") + list (SORT versions ORDER DESCENDING) + list (TRANSFORM versions PREPEND "${framework}/Versions/") + list (APPEND framework_paths ${versions}) + endforeach() + endforeach() + endif() endforeach() - set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${_PYTHON_FRAMEWORK_PATHS} PARENT_SCOPE) + + set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${framework_paths} PARENT_SCOPE) endfunction() -function (_PYTHON_GET_REGISTRIES _PYTHON_PGR_REGISTRY_PATHS _PYTHON_VERSION) - string (REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${_PYTHON_VERSION}) - set (${_PYTHON_PGR_REGISTRY_PATHS} - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_PYTHON_VERSION}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${_PYTHON_VERSION_NO_DOTS}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] - PARENT_SCOPE) +function (_PYTHON_GET_REGISTRIES _PYTHON_PGR_REGISTRY_PATHS) + cmake_parse_arguments (PARSE_ARGV 1 _PGR "" "" "IMPLEMENTATIONS;VERSION") + + if (NOT _PGR_IMPLEMENTATIONS) + set (_PGR_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}) + endif() + + set (registries) + + foreach (implementation IN LISTS _PGR_IMPLEMENTATIONS) + if (implementation STREQUAL "CPython") + foreach (version IN LISTS _PGR_VERSION) + string (REPLACE "." "" version_no_dots ${version}) + list (APPEND registries + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]) + if (version VERSION_GREATER_EQUAL "3.5") + get_filename_component (arch "[HKEY_CURRENT_USER\\Software\\Python\\PythonCore\\${version};SysArchitecture]" NAME) + if (arch MATCHES "(${_${_PYTHON_PREFIX}_ARCH}|${_${_PYTHON_PREFIX}_ARCH2})bit") + list (APPEND registries + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath]) + endif() + else() + list (APPEND registries + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath]) + endif() + list (APPEND registries + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${version}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH}\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\ContinuumAnalytics\\Anaconda${version_no_dots}-${_${_PYTHON_PREFIX}_ARCH2}\\InstallPath]) + endforeach() + elseif (implementation STREQUAL "IronPython") + foreach (version IN LISTS _PGR_VERSION) + list (APPEND registries [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${version}\\InstallPath]) + endforeach() + endif() + endforeach() + + set (${_PYTHON_PGR_REGISTRY_PATHS} "${registries}" PARENT_SCOPE) endfunction() @@ -187,7 +251,11 @@ function (_PYTHON_GET_ABIFLAGS _PGABIFLAGS) endfunction() function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES) - cmake_parse_arguments (PARSE_ARGV 1 _PGPS "LIBRARY;INCLUDE" "VERSION" "") + cmake_parse_arguments (PARSE_ARGV 1 _PGPS "INTERPRETER;COMPILER;LIBRARY;INCLUDE" "" "IMPLEMENTATIONS;VERSION") + + if (NOT _PGPS_IMPLEMENTATIONS) + set (_PGPS_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}) + endif() if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS) set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}") @@ -196,93 +264,163 @@ function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES) endif() set (path_suffixes) - if (_PGPS_LIBRARY) - if (CMAKE_LIBRARY_ARCHITECTURE) - list (APPEND path_suffixes lib/${CMAKE_LIBRARY_ARCHITECTURE}) - endif() - list (APPEND path_suffixes lib libs) - if (CMAKE_LIBRARY_ARCHITECTURE) - set (suffixes "${abi}") - if (suffixes) - list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") - list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}") + foreach (implementation IN LISTS _PGPS_IMPLEMENTATIONS) + if (implementation STREQUAL "CPython") + if (_PGPS_INTERPRETER) + list (APPEND path_suffixes bin Scripts) else() - set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}-${CMAKE_LIBRARY_ARCHITECTURE}") + foreach (version IN LISTS _PGPS_VERSION) + if (_PGPS_LIBRARY) + if (CMAKE_LIBRARY_ARCHITECTURE) + list (APPEND path_suffixes lib/${CMAKE_LIBRARY_ARCHITECTURE}) + endif() + list (APPEND path_suffixes lib libs) + + if (CMAKE_LIBRARY_ARCHITECTURE) + set (suffixes "${abi}") + if (suffixes) + list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}") + else() + set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}-${CMAKE_LIBRARY_ARCHITECTURE}") + endif() + list (APPEND path_suffixes ${suffixes}) + endif() + set (suffixes "${abi}") + if (suffixes) + list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + else() + set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + endif() + list (APPEND path_suffixes ${suffixes}) + elseif (_PGPS_INCLUDE) + set (suffixes "${abi}") + if (suffixes) + list (TRANSFORM suffixes PREPEND "include/python${_PGPS_VERSION}") + else() + set (suffixes "include/python${_PGPS_VERSION}") + endif() + list (APPEND path_suffixes ${suffixes} include) + endif() + endforeach() + endif() + elseif (implementation STREQUAL "IronPython") + if (_PGPS_INTERPRETER OR _PGPS_COMPILER) + foreach (version IN LISTS _PGPS_VERSION) + list (APPEND path_suffixes "share/ironpython${version}") + endforeach() + list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}) + endif() + elseif (implementation STREQUAL "PyPy") + if (_PGPS_INTERPRETER) + list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES}) + elseif (_PGPS_LIBRARY) + list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES}) + elseif (_PGPS_INCLUDE) + list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES}) endif() - list (APPEND path_suffixes ${suffixes}) - endif() - set (suffixes "${abi}") - if (suffixes) - list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") - else() - set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") - endif() - list (APPEND path_suffixes ${suffixes}) - elseif (_PGPS_INCLUDE) - set (suffixes "${abi}") - if (suffixes) - list (TRANSFORM suffixes PREPEND "include/python${_PGPS_VERSION}") - else() - set (suffixes "include/python${_PGPS_VERSION}") endif() - list (APPEND path_suffixes ${suffixes} include) - endif() + endforeach() + list (REMOVE_DUPLICATES path_suffixes) set (${_PYTHON_PGPS_PATH_SUFFIXES} ${path_suffixes} PARENT_SCOPE) endfunction() function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES) - cmake_parse_arguments (PARSE_ARGV 1 _PGN "POSIX;EXECUTABLE;CONFIG;LIBRARY;WIN32;DEBUG" "VERSION" "") + cmake_parse_arguments (PARSE_ARGV 1 _PGN "POSIX;INTERPRETER;COMPILER;CONFIG;LIBRARY;WIN32;DEBUG" "" "IMPLEMENTATIONS;VERSION") + + if (NOT _PGN_IMPLEMENTATIONS) + set (_PGN_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}) + endif() set (names) - if (_PGN_WIN32) - string (REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${_PGN_VERSION}) + foreach (implementation IN LISTS _PGN_IMPLEMENTATIONS) + if (implementation STREQUAL "CPython") + foreach (version IN LISTS _PGN_VERSION) + if (_PGN_WIN32) + string (REPLACE "." "" version_no_dots ${version}) - set (name python${_PYTHON_VERSION_NO_DOTS}) - if (_PGN_DEBUG) - string (APPEND name "_d") - endif() + set (name python${version_no_dots}) + if (_PGN_DEBUG) + string (APPEND name "_d") + endif() - list (APPEND names "${name}") - endif() + list (APPEND names "${name}") + endif() - if (_PGN_POSIX) - if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS) - set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}") - else() - if (_PGN_EXECUTABLE OR _PGN_CONFIG) - set (abi "") - else() - set (abi "mu" "m" "u" "") - endif() - endif() + if (_PGN_POSIX) + if (DEFINED _${_PYTHON_PREFIX}_ABIFLAGS) + set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}") + else() + if (_PGN_INTERPRETER OR _PGN_CONFIG) + set (abi "") + else() + set (abi "mu" "m" "u" "") + endif() + endif() - if (abi) - if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) - set (abinames "${abi}") - list (TRANSFORM abinames PREPEND "${CMAKE_LIBRARY_ARCHITECTURE}-python${_PGN_VERSION}") - list (TRANSFORM abinames APPEND "-config") - list (APPEND names ${abinames}) - endif() - set (abinames "${abi}") - list (TRANSFORM abinames PREPEND "python${_PGN_VERSION}") - if (_PGN_CONFIG) - list (TRANSFORM abinames APPEND "-config") + if (abi) + if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) + set (abinames "${abi}") + list (TRANSFORM abinames PREPEND "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}") + list (TRANSFORM abinames APPEND "-config") + list (APPEND names ${abinames}) + endif() + set (abinames "${abi}") + list (TRANSFORM abinames PREPEND "python${version}") + if (_PGN_CONFIG) + list (TRANSFORM abinames APPEND "-config") + endif() + list (APPEND names ${abinames}) + else() + unset (abinames) + if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) + set (abinames "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}") + endif() + list (APPEND abinames "python${version}") + if (_PGN_CONFIG) + list (TRANSFORM abinames APPEND "-config") + endif() + list (APPEND names ${abinames}) + endif() + endif() + endforeach() + if (_PGN_INTERPRETER) + list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python) endif() - list (APPEND names ${abinames}) - else() - if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE) - set (abinames "${CMAKE_LIBRARY_ARCHITECTURE}-python${_PGN_VERSION}") + elseif (implementation STREQUAL "IronPython") + if (_PGN_INTERPRETER) + if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Do not use wrapper script on Linux because it is buggy: -c interpreter option cannot be used + foreach (version IN LISTS _PGN_VERSION) + list (APPEND names "ipy${version}") + endforeach() + endif() + list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES}) + elseif (_PGN_COMPILER) + list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES}) endif() - list (APPEND abinames "python${_PGN_VERSION}") - if (_PGN_CONFIG) - list (TRANSFORM abinames APPEND "-config") + elseif (implementation STREQUAL "PyPy") + if (_PGN_INTERPRETER) + list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_NAMES}) + elseif (_PGN_LIBRARY) + if (_PGN_WIN32) + foreach (version IN LISTS _PGN_VERSION) + string (REPLACE "." "" version_no_dots ${version}) + + set (name "python${version_no_dots}") + if (_PGN_DEBUG) + string (APPEND name "_d") + endif() + list (APPEND names "${name}") + endforeach() + endif() + list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_LIB_NAMES}) endif() - list (APPEND names ${abinames}) endif() - endif() + endforeach() set (${_PYTHON_PGN_NAMES} ${names} PARENT_SCOPE) endfunction() @@ -323,7 +461,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) if (_${_PYTHON_PREFIX}_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING) if (NAME STREQUAL "PREFIX") - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(';'.join([sysconfig.PREFIX,sysconfig.EXEC_PREFIX,sysconfig.BASE_EXEC_PREFIX]))" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.PREFIX,sysconfig.EXEC_PREFIX,sysconfig.BASE_EXEC_PREFIX]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('base') or '', sysconfig.get_config_var('installed_base') or '']))" RESULT_VARIABLE _result OUTPUT_VARIABLE _values ERROR_QUIET @@ -334,16 +472,25 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (REMOVE_DUPLICATES _values) endif() elseif (NAME STREQUAL "INCLUDES") - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(';'.join([sysconfig.get_python_inc(plat_specific=True),sysconfig.get_python_inc(plat_specific=False)]))" + if (WIN32) + set (_scheme "nt") + else() + set (_scheme "posix_prefix") + endif() + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_python_inc(plat_specific=True),sysconfig.get_python_inc(plat_specific=False)]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_path('platinclude'),sysconfig.get_path('platinclude','${_scheme}'),sysconfig.get_path('include'),sysconfig.get_path('include','${_scheme}')]))" RESULT_VARIABLE _result OUTPUT_VARIABLE _values ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (_result) unset (_values) + else() + list (REMOVE_DUPLICATES _values) endif() elseif (NAME STREQUAL "SOABI") - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '']))" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '']))\nexcept Exception:\n import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '']))" RESULT_VARIABLE _result OUTPUT_VARIABLE _soabi ERROR_QUIET @@ -351,14 +498,15 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) if (_result) unset (_values) else() - list (GET _soabi 0 _values) - if (NOT _values) - # try to compute SOABI from EXT_SUFFIX - list (GET _soabi 1 _values) - if (_values) - # clean-up: remove prefix character and suffix - string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") + foreach (_item IN LISTS _soabi) + if (_item) + set (_values "${_item}") + break() endif() + endforeach() + if (_values) + # clean-up: remove prefix character and suffix + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") endif() endif() else() @@ -366,7 +514,8 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) if (NAME STREQUAL "CONFIGDIR") set (config_flag "LIBPL") endif() - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_config_var('${config_flag}'))" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))\nexcept Exception:\n import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))" RESULT_VARIABLE _result OUTPUT_VARIABLE _values ERROR_QUIET @@ -394,6 +543,10 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (REMOVE_DUPLICATES _values) endif() + if (WIN32 AND NAME MATCHES "^(PREFIX|CONFIGDIR|INCLUDES)$") + file (TO_CMAKE_PATH "${_values}" _values) + endif() + set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE) endfunction() @@ -420,6 +573,16 @@ function (_PYTHON_GET_VERSION) set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE) set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE) set (${_PGV_PREFIX}ABI "${CMAKE_MATCH_3}" PARENT_SCOPE) + elseif (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "pypy(3)?") + set (version "${CMAKE_MATCH_1}") + if (version EQUAL "3") + set (${_PGV_PREFIX}VERSION_MAJOR "3" PARENT_SCOPE) + set (${_PGV_PREFIX}VERSION "3" PARENT_SCOPE) + else() + set (${_PGV_PREFIX}VERSION_MAJOR "2" PARENT_SCOPE) + set (${_PGV_PREFIX}VERSION "2" PARENT_SCOPE) + endif() + set (${_PGV_PREFIX}ABI "" PARENT_SCOPE) endif() endif() else() @@ -434,7 +597,7 @@ function (_PYTHON_GET_VERSION) list (GET versions 1 version_minor) list (GET versions 2 version_patch) - set (${_PGV_PREFIX}VERSION "${version_major}.${version_minor}" PARENT_SCOPE) + set (${_PGV_PREFIX}VERSION "${version_major}.${version_minor}.${version_patch}" PARENT_SCOPE) set (${_PGV_PREFIX}VERSION_MAJOR ${version_major} PARENT_SCOPE) set (${_PGV_PREFIX}VERSION_MINOR ${version_minor} PARENT_SCOPE) set (${_PGV_PREFIX}VERSION_PATCH ${version_patch} PARENT_SCOPE) @@ -466,6 +629,36 @@ function (_PYTHON_GET_VERSION) endif() endfunction() +function (_PYTHON_GET_LAUNCHER _PYTHON_PGL_NAME) + cmake_parse_arguments (PARSE_ARGV 1 _PGL "INTERPRETER;COMPILER" "" "") + + unset ({_PYTHON_PGL_NAME} PARENT_SCOPE) + + if ((_PGL_INTERPRETER AND NOT _${_PYTHON_PREFIX}_EXECUTABLE) + OR (_PGL_COMPILER AND NOT _${_PYTHON_PREFIX}_COMPILER)) + return() + endif() + + if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS + AND NOT SYSTEM_NAME MATCHES "Windows|Linux") + if (_PGL_INTERPRETER) + get_filename_component (name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME) + get_filename_component (ext "${_${_PYTHON_PREFIX}_EXECUTABLE}" LAST_EXT) + if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES + AND ext STREQUAL ".exe") + set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE) + endif() + else() + 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 + AND ext STREQUAL ".exe") + set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + function (_PYTHON_VALIDATE_INTERPRETER) if (NOT _${_PYTHON_PREFIX}_EXECUTABLE) @@ -486,9 +679,11 @@ function (_PYTHON_VALIDATE_INTERPRETER) return() endif() + _python_get_launcher (launcher INTERPRETER) + # validate ABI compatibility if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.abiflags)" RESULT_VARIABLE result OUTPUT_VARIABLE abi @@ -508,42 +703,52 @@ function (_PYTHON_VALIDATE_INTERPRETER) get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME) - if (expected_version AND NOT python_name STREQUAL "python${expected_version}${abi}${CMAKE_EXECUTABLE_SUFFIX}") - # executable found must have a specific version - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c - "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))" - RESULT_VARIABLE result - OUTPUT_VARIABLE version - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if (result) - # interpreter is not usable - set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) - set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") - else() - if (_PVI_EXACT AND NOT version VERSION_EQUAL expected_version) - # interpreter has wrong version - set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) + if (expected_version) + if (NOT python_name STREQUAL "python${expected_version}${abi}${CMAKE_EXECUTABLE_SUFFIX}") + # compute number of components for version + string (REGEX REPLACE "[^.]" "" dots "${expected_version}") + # add one dot because there is one dot less than there are components + string (LENGTH "${dots}." count) + if (count GREATER 3) + set (count 3) + endif() + + # executable found must have a specific version + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:${count}]]))" + RESULT_VARIABLE result + OUTPUT_VARIABLE version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (result) + # interpreter is not usable + set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") else() - # check that version is OK - string(REGEX REPLACE "^([0-9]+)\\..*$" "\\1" major_version "${version}") - string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${expected_version}") - if (NOT major_version VERSION_EQUAL expected_major_version - OR NOT version VERSION_GREATER_EQUAL expected_version) + if (_PVI_EXACT AND NOT version VERSION_EQUAL expected_version) + # interpreter has wrong version set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") + else() + # check that version is OK + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}") + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${expected_version}") + if (NOT major_version VERSION_EQUAL expected_major_version + OR NOT version VERSION_GREATER_EQUAL expected_version) + set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"" PARENT_SCOPE) + set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") + endif() endif() endif() - endif() - if (NOT _${_PYTHON_PREFIX}_EXECUTABLE) - return() + if (NOT _${_PYTHON_PREFIX}_EXECUTABLE) + return() + endif() endif() else() if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}") # executable found do not have version in name # ensure major version is OK - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; sys.stdout.write(str(sys.version_info[0]))" RESULT_VARIABLE result OUTPUT_VARIABLE version @@ -562,10 +767,11 @@ function (_PYTHON_VALIDATE_INTERPRETER) endif() endif() - if (CMAKE_SIZEOF_VOID_P AND "Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + if (CMAKE_SIZEOF_VOID_P AND ("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + OR "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) AND NOT CMAKE_CROSSCOMPILING) # In this case, interpreter must have same architecture as environment - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys, struct; sys.stdout.write(str(struct.calcsize(\"P\")))" RESULT_VARIABLE result OUTPUT_VARIABLE size @@ -607,20 +813,33 @@ function (_PYTHON_VALIDATE_COMPILER) return() endif() + _python_get_launcher (launcher COMPILER) + # retrieve python environment version from compiler set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") if (major_version) # check only major version file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write(str(sys.version_info[0]))") else() - file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))\n") + # compute number of components for version + string (REGEX REPLACE "[^.]" "" dots "${expected_version}") + # add one dot because there is one dot less than there are components + string (LENGTH "${dots}." count) + if (count GREATER 3) + set (count 3) + endif() + file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:${count}]]))\n") endif() - execute_process (COMMAND "${_${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${working_dir}/version.py" + execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_COMPILER}" + ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} + /target:exe /embed "${working_dir}/version.py" WORKING_DIRECTORY "${working_dir}" OUTPUT_QUIET ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process (COMMAND "${working_dir}/version" + get_filename_component (ir_dir "${_${_PYTHON_PREFIX}_COMPILER}" DIRECTORY) + execute_process (COMMAND "${CMAKE_COMMAND}" -E env "MONO_PATH=${ir_dir}" + ${${_PYTHON_PREFIX}_DOTNET_LAUNCHER} "${working_dir}/version.exe" WORKING_DIRECTORY "${working_dir}" RESULT_VARIABLE result OUTPUT_VARIABLE version @@ -641,6 +860,7 @@ endfunction() function (_PYTHON_VALIDATE_LIBRARY) if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG) return() endif() @@ -671,7 +891,9 @@ function (_PYTHON_VALIDATE_LIBRARY) set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") else() if (expected_version) - if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL expected_version) OR (lib_VERSION VERSION_LESS expected_version)) + # library have only major.minor information + string (REGEX MATCH "[0-9](\\.[0-9]+)?" version "${expected_version}") + if ((_PVL_EXACT AND NOT lib_VERSION VERSION_EQUAL version) OR (lib_VERSION VERSION_LESS version)) # library has wrong version set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Wrong version for the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"" PARENT_SCOPE) set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") @@ -765,13 +987,30 @@ function (_PYTHON_SET_LIBRARY_DIRS _PYTHON_SLD_RESULT) list (APPEND _PYTHON_DIRS "${_PYTHON_DIR}") endif() endforeach() - if (_PYTHON_DIRS) - list (REMOVE_DUPLICATES _PYTHON_DIRS) - endif() + list (REMOVE_DUPLICATES _PYTHON_DIRS) set (${_PYTHON_SLD_RESULT} ${_PYTHON_DIRS} PARENT_SCOPE) endfunction() +function (_PYTHON_SET_DEVELOPMENT_MODULE_FOUND module) + if ("Development.${module}" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + string(TOUPPER "${module}" id) + set (module_found TRUE) + + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS + AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + set (module_found FALSE) + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS + AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) + set (module_found FALSE) + endif() + + set (${_PYTHON_PREFIX}_Development.${module}_FOUND ${module_found} PARENT_SCOPE) + endif() +endfunction() + + # If major version is specified, it must be the same as internal major version if (DEFINED ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR AND NOT ${_PYTHON_PREFIX}_FIND_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) @@ -785,26 +1024,49 @@ if (NOT ${_PYTHON_PREFIX}_FIND_COMPONENTS) set (${_PYTHON_PREFIX}_FIND_REQUIRED_Interpreter TRUE) endif() if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) - list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Interpreter" "Development") - list (REMOVE_DUPLICATES ${_PYTHON_PREFIX}_FIND_COMPONENTS) + list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Interpreter" "Development.Module") endif() -foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development NumPy) +if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + list (APPEND ${_PYTHON_PREFIX}_FIND_COMPONENTS "Development.Module" "Development.Embed") +endif() +list (REMOVE_DUPLICATES ${_PYTHON_PREFIX}_FIND_COMPONENTS) +foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development Development.Module Development.Embed NumPy) set (${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_FOUND FALSE) endforeach() -unset (_${_PYTHON_PREFIX}_FIND_VERSIONS) +if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development) + set (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Module TRUE) + set (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Embed TRUE) +endif() + +unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) +unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) +unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS) +if ("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$") + list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "LIBRARY") + endif() + list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "INCLUDE_DIR") +endif() +if ("Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS "LIBRARY" "INCLUDE_DIR") +endif() +set (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS ${_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS} ${_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS}) +list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) # Set versions to search ## default: search any version set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSIONS}) +unset (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT) -if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1) +if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT) if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) + set (_${_PYTHON_PREFIX}_FIND_VERSION_EXACT "EXACT") set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}) else() unset (_${_PYTHON_PREFIX}_FIND_VERSIONS) # add all compatible versions foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_VERSIONS) - if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL ${_PYTHON_PREFIX}_FIND_VERSION) + if (_${_PYTHON_PREFIX}_VERSION VERSION_GREATER_EQUAL "${${_PYTHON_PREFIX}_FIND_VERSION_MAJOR}.${${_PYTHON_PREFIX}_FIND_VERSION_MINOR}") list (APPEND _${_PYTHON_PREFIX}_FIND_VERSIONS ${_${_PYTHON_PREFIX}_VERSION}) endif() endforeach() @@ -861,15 +1123,75 @@ else() endif() # IronPython support +unset (_${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES) +unset (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES) +unset (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS) if (CMAKE_SIZEOF_VOID_P) - # In this case, search only for 64bit or 32bit - math (EXPR _${_PYTHON_PREFIX}_ARCH "${CMAKE_SIZEOF_VOID_P} * 8") - set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy${_${_PYTHON_PREFIX}_ARCH} ipy) + if (_${_PYTHON_PREFIX}_ARCH EQUAL "32") + set (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS "/platform:x86") + else() + set (_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS "/platform:x64") + endif() +endif() +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Do not use wrapper script on Linux because it is buggy: -c interpreter option cannot be used + list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES "ipy${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}" "ipy64" "ipy32" "ipy") + list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES "ipyc") +endif() +list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES "ipy.exe") +list (APPEND _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES "ipyc.exe") +set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40 bin) + +# PyPy support +if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3") + set (_${_PYTHON_PREFIX}_PYPY_NAMES pypy3) + set (_${_PYTHON_PREFIX}_PYPY_LIB_NAMES pypy3-c) + if (WIN32) + # special name for runtime part + list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy3-c) + endif() + set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy3) +else() + set (_${_PYTHON_PREFIX}_PYPY_NAMES pypy) + set (_${_PYTHON_PREFIX}_PYPY_LIB_NAMES pypy-c) + if (WIN32) + # special name for runtime part + list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy-c) + endif() + set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy) +endif() +set (_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES bin) +set (_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES lib libs bin) +list (APPEND _${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES include) + +# Python Implementations handling +unset (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) +if (DEFINED ${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + foreach (_${_PYTHON_PREFIX}_IMPLEMENTATION IN LISTS ${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + if (NOT _${_PYTHON_PREFIX}_IMPLEMENTATION MATCHES "^(CPython|IronPython|PyPy)$") + message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${_${_PYTHON_PREFIX}_IMPLEMENTATION}: invalid value for '${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS'. 'CPython', 'IronPython' or 'PyPy' expected. Value will be ignored.") + else() + list (APPEND _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_IMPLEMENTATION}) + endif() + endforeach() else() - # architecture unknown, search for natural interpreter - set (_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES ipy) + if (WIN32) + set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS CPython IronPython) + else() + set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS CPython) + endif() endif() -set (_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES net45 net40) + +# compute list of names for header file +unset (_${_PYTHON_PREFIX}_INCLUDE_NAMES) +foreach (_${_PYTHON_PREFIX}_IMPLEMENTATION IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + if (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "CPython") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "Python.h") + elseif (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "PyPy") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "PyPy.h") + endif() +endforeach() + # Apple frameworks handling _python_find_frameworks () @@ -941,7 +1263,7 @@ endif() # Compute search signature # This signature will be used to check validity of cached variables on new search -set (_${_PYTHON_PREFIX}_SIGNATURE "${${_PYTHON_PREFIX}_ROOT_DIR}:${_${_PYTHON_PREFIX}_FIND_STRATEGY}:${${_PYTHON_PREFIX}_FIND_VIRTUALENV}") +set (_${_PYTHON_PREFIX}_SIGNATURE "${${_PYTHON_PREFIX}_ROOT_DIR}:${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS}:${_${_PYTHON_PREFIX}_FIND_STRATEGY}:${${_PYTHON_PREFIX}_FIND_VIRTUALENV}") if (NOT WIN32) string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${${_PYTHON_PREFIX}_USE_STATIC_LIBS}:") endif() @@ -952,6 +1274,64 @@ if (CMAKE_HOST_WIN32) string (APPEND _${_PYTHON_PREFIX}_SIGNATURE ":${_${_PYTHON_PREFIX}_FIND_REGISTRY}") endif() +function (_PYTHON_CHECK_DEVELOPMENT_SIGNATURE module) + if ("Development.${module}" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + string (TOUPPER "${module}" id) + set (signature "${_${_PYTHON_PREFIX}_SIGNATURE}:") + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + list (APPEND signature "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:") + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + list (APPEND signature "${_${_PYTHON_PREFIX}_INCLUDE_DIR}:") + endif() + string (MD5 signature "${signature}") + if (signature STREQUAL _${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} + ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT} + CHECK_EXISTS) + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} + ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT} + CHECK_EXISTS) + endif() + else() + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + unset (_${_PYTHON_PREFIX}_LIBRARY_RELEASE CACHE) + unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE) + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE) + endif() + endif() + if (("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS + AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + OR ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS + AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR)) + unset (_${_PYTHON_PREFIX}_CONFIG CACHE) + unset (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE CACHE) + endif() + endif() +endfunction() + +function (_PYTHON_COMPUTE_DEVELOPMENT_SIGNATURE module) + string (TOUPPER "${module}" id) + if (${_PYTHON_PREFIX}_Development.${module}_FOUND) + set (signature "${_${_PYTHON_PREFIX}_SIGNATURE}:") + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + list (APPEND signature "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:") + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_${id}_ARTIFACTS) + list (APPEND signature "${_${_PYTHON_PREFIX}_INCLUDE_DIR}:") + endif() + string (MD5 signature "${signature}") + set (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE "${signature}" CACHE INTERNAL "") + else() + unset (_${_PYTHON_PREFIX}_DEVELOPMENT_${id}_SIGNATURE CACHE) + endif() +endfunction() + unset (_${_PYTHON_PREFIX}_REQUIRED_VARS) unset (_${_PYTHON_PREFIX}_CACHED_VARS) @@ -961,6 +1341,15 @@ unset (_${_PYTHON_PREFIX}_Development_REASON_FAILURE) unset (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE) +# preamble +## For IronPython on platforms other than Windows, search for the .Net interpreter +if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS + AND NOT WIN32) + find_program (${_PYTHON_PREFIX}_DOTNET_LAUNCHER + NAMES "mono") +endif() + + # first step, search for the interpreter if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_EXECUTABLE @@ -999,25 +1388,14 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION") - unset (_${_PYTHON_PREFIX}_NAMES) - unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS) - unset (_${_PYTHON_PREFIX}_REGISTRY_PATHS) + # build all executable names + _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} POSIX INTERPRETER) + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} INTERPRETER) - foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - # build all executable names - _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX EXECUTABLE) - list (APPEND _${_PYTHON_PREFIX}_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES}) - - # Framework Paths - _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS}) - - # Registry Paths - _python_get_registries (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS} - [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]) - endforeach() - list (APPEND _${_PYTHON_PREFIX}_NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python) + # Framework Paths + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) + # Registry Paths + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) while (TRUE) # Virtual environments handling @@ -1027,13 +1405,13 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX - PATH_SUFFIXES bin Scripts + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1049,12 +1427,12 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES bin + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1063,14 +1441,13 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1079,23 +1456,21 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # try using HINTS find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() # try using standard paths find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1106,9 +1481,9 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES ${_${_PYTHON_PREFIX}_NAMES} NAMES_PER_DIR PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES bin + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1117,12 +1492,11 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) - _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_interpreter (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() endif() @@ -1133,12 +1507,11 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) else() # look-up for various versions and locations foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX EXECUTABLE) - list (APPEND _${_PYTHON_PREFIX}_NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} - python) + _python_get_names (_${_PYTHON_PREFIX}_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX INTERPRETER) + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INTERPRETER) - _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION}) # Virtual environments handling if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") @@ -1147,7 +1520,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX - PATH_SUFFIXES bin Scripts + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH @@ -1168,7 +1541,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES bin + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH @@ -1179,12 +1552,10 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() @@ -1197,10 +1568,9 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # try using HINTS find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) @@ -1213,15 +1583,9 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # For example, typical systems have 'python' for version 2.* and 'python3' # for version 3.*. So looking for names per dir will find, potentially, # systematically 'python' (i.e. version 2) even if version 3 is searched. - if (CMAKE_HOST_WIN32) - find_program (_${_PYTHON_PREFIX}_EXECUTABLE - NAMES ${_${_PYTHON_PREFIX}_NAMES} - python - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}) - else() - find_program (_${_PYTHON_PREFIX}_EXECUTABLE - NAMES ${_${_PYTHON_PREFIX}_NAMES}) - endif() + find_program (_${_PYTHON_PREFIX}_EXECUTABLE + NAMES ${_${_PYTHON_PREFIX}_NAMES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) _python_validate_interpreter (${_${_PYTHON_PREFIX}_VERSION} EXACT) if (_${_PYTHON_PREFIX}_EXECUTABLE) break() @@ -1233,7 +1597,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES ${_${_PYTHON_PREFIX}_NAMES} NAMES_PER_DIR PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES bin + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) endif() @@ -1241,11 +1605,9 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") find_program (_${_PYTHON_PREFIX}_EXECUTABLE NAMES ${_${_PYTHON_PREFIX}_NAMES} - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) endif() @@ -1263,20 +1625,20 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # For example, typical systems have 'python' for version 2.* and 'python3' # for version 3.*. So looking for names per dir will find, potentially, # systematically 'python' (i.e. version 2) even if version 3 is searched. + _python_get_names (_${_PYTHON_PREFIX}_NAMES POSIX INTERPRETER) find_program (_${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} - python - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}) + NAMES ${_${_PYTHON_PREFIX}_NAMES}) _python_validate_interpreter () endif() endif() endif() set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}") + _python_get_launcher (_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER INTERPRETER) # retrieve exact version of executable found if (_${_PYTHON_PREFIX}_EXECUTABLE) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))" RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE ${_PYTHON_PREFIX}_VERSION @@ -1323,7 +1685,8 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # Use interpreter version and ABI for future searches to ensure consistency set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.abiflags)" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETR_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write(sys.abiflags)" RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE _${_PYTHON_PREFIX}_ABIFLAGS ERROR_QUIET @@ -1335,13 +1698,16 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() if (${_PYTHON_PREFIX}_Interpreter_FOUND) + unset (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE) + # compute and save interpreter signature string (MD5 __${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_EXECUTABLE}") set (_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE "${__${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}" CACHE INTERNAL "") if (NOT CMAKE_SIZEOF_VOID_P) # determine interpreter architecture - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.maxsize > 2**32)" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write(str(sys.maxsize > 2**32))" RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE ${_PYTHON_PREFIX}_IS64BIT ERROR_VARIABLE ${_PYTHON_PREFIX}_IS64BIT) @@ -1357,7 +1723,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() # retrieve interpreter identity - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -V + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -V RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID ERROR_VARIABLE ${_PYTHON_PREFIX}_INTERPRETER_ID) @@ -1366,11 +1732,15 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) set (${_PYTHON_PREFIX}_INTERPRETER_ID "Anaconda") elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "Enthought") set (${_PYTHON_PREFIX}_INTERPRETER_ID "Canopy") + elseif (${_PYTHON_PREFIX}_INTERPRETER_ID MATCHES "PyPy ([0-9.]+)") + set (${_PYTHON_PREFIX}_INTERPRETER_ID "PyPy") + set (${_PYTHON_PREFIX}_PyPy_VERSION "${CMAKE_MATCH_1}") else() string (REGEX REPLACE "^([^ ]+).*" "\\1" ${_PYTHON_PREFIX}_INTERPRETER_ID "${${_PYTHON_PREFIX}_INTERPRETER_ID}") if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "Python") # try to get a more precise ID - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; print(sys.copyright)" + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys; sys.stdout.write(sys.copyright)" RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE ${_PYTHON_PREFIX}_COPYRIGHT ERROR_QUIET) @@ -1384,10 +1754,11 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() # retrieve various package installation directories - execute_process (COMMAND "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys; from distutils import sysconfig;sys.stdout.write(';'.join([sysconfig.get_python_lib(plat_specific=False,standard_lib=True),sysconfig.get_python_lib(plat_specific=True,standard_lib=True),sysconfig.get_python_lib(plat_specific=False,standard_lib=False),sysconfig.get_python_lib(plat_specific=True,standard_lib=False)]))" - RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT - OUTPUT_VARIABLE _${_PYTHON_PREFIX}_LIBPATHS - ERROR_QUIET) + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_python_lib(plat_specific=False,standard_lib=True),sysconfig.get_python_lib(plat_specific=True,standard_lib=True),sysconfig.get_python_lib(plat_specific=False,standard_lib=False),sysconfig.get_python_lib(plat_specific=True,standard_lib=False)]))\nexcept Exception:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_path('stdlib'),sysconfig.get_path('platstdlib'),sysconfig.get_path('purelib'),sysconfig.get_path('platlib')]))" + RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT + OUTPUT_VARIABLE _${_PYTHON_PREFIX}_LIBPATHS + ERROR_QUIET) if (NOT _${_PYTHON_PREFIX}_RESULT) list (GET _${_PYTHON_PREFIX}_LIBPATHS 0 ${_PYTHON_PREFIX}_STDLIB) list (GET _${_PYTHON_PREFIX}_LIBPATHS 1 ${_PYTHON_PREFIX}_STDARCH) @@ -1414,6 +1785,10 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() endif() + if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE) + set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}" CACHE FILEPATH "${_PYTHON_PREFIX} Interpreter") + endif() + _python_mark_as_internal (_${_PYTHON_PREFIX}_EXECUTABLE _${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES _${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE) @@ -1427,7 +1802,10 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_COMPILER) endif() - if (DEFINED ${_PYTHON_PREFIX}_COMPILER + if (NOT "IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) + unset (_${_PYTHON_PREFIX}_COMPILER CACHE) + unset (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE CACHE) + elseif (DEFINED ${_PYTHON_PREFIX}_COMPILER AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_COMPILER}") set (_${_PYTHON_PREFIX}_COMPILER "${${_PYTHON_PREFIX}_COMPILER}" CACHE INTERNAL "") elseif (DEFINED _${_PYTHON_PREFIX}_COMPILER) @@ -1446,7 +1824,8 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() endif() - if (NOT _${_PYTHON_PREFIX}_COMPILER) + if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS + AND NOT _${_PYTHON_PREFIX}_COMPILER) # IronPython specific artifacts # If IronPython interpreter is found, use its path unset (_${_PYTHON_PREFIX}_IRON_ROOT) @@ -1455,46 +1834,104 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION") - set (_${_PYTHON_PREFIX}_REGISTRY_PATHS) - - foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - # Registry Paths - list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS - [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath]) - endforeach() + _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} + COMPILER) + + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} + COMPILER) + + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) while (TRUE) - if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + # Apple frameworks handling + if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_program (_${_PYTHON_PREFIX}_COMPILER + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() + endif() + # Windows registry + if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() endif() + # try using HINTS find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION}) + _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) if (_${_PYTHON_PREFIX}_COMPILER) break() endif() - if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + # try using standard paths + find_program (_${_PYTHON_PREFIX}_COMPILER + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) + _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() + + # Apple frameworks handling + if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + find_program (_${_PYTHON_PREFIX}_COMPILER + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_DEFAULT_PATH) + _python_validate_compiler (${${_PYTHON_PREFIX}_FIND_VERSION} ${_${_PYTHON_PREFIX}_FIND_VERSION_EXACT}) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() + endif() + # Windows registry + if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() endif() break() @@ -1502,12 +1939,48 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) else() # try using root dir and registry foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} + COMPILER) + + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSION} + COMPILER) + + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_VERSION}) + + # Apple frameworks handling + if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_program (_${_PYTHON_PREFIX}_COMPILER + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() + endif() + # Windows registry + if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) @@ -1516,10 +1989,12 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() endif() + # try using HINTS find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) @@ -1527,11 +2002,26 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) break() endif() - if (_${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + # Apple frameworks handling + if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + find_program (_${_PYTHON_PREFIX}_COMPILER + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_DEFAULT_PATH) + _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) + if (_${_PYTHON_PREFIX}_COMPILER) + break() + endif() + endif() + # Windows registry + if (CMAKE_HOST_WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\IronPython\\${_${_PYTHON_PREFIX}_VERSION}\\InstallPath] - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} + NAMES_PER_DIR + PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_DEFAULT_PATH) _python_validate_compiler (${_${_PYTHON_PREFIX}_VERSION} EXACT) if (_${_PYTHON_PREFIX}_COMPILER) @@ -1541,10 +2031,18 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endforeach() # no specific version found, re-try in standard paths + _python_get_names (_${_PYTHON_PREFIX}_COMPILER_NAMES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} + COMPILER) + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES + IMPLEMENTATIONS IronPython + VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} + COMPILER) find_program (_${_PYTHON_PREFIX}_COMPILER - NAMES ipyc + NAMES ${_${_PYTHON_PREFIX}_COMPILER_NAMES} HINTS ${_${_PYTHON_PREFIX}_IRON_ROOT} ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES}) + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) endif() endif() @@ -1552,13 +2050,18 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) if (_${_PYTHON_PREFIX}_COMPILER) # 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") - execute_process (COMMAND "${_${_PYTHON_PREFIX}_COMPILER}" /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" + 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" WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}" OUTPUT_QUIET ERROR_QUIET) - execute_process (COMMAND "${_${_PYTHON_PREFIX}_VERSION_DIR}/version" + get_filename_component (_${_PYTHON_PREFIX}_IR_DIR "${_${_PYTHON_PREFIX}_COMPILER}" DIRECTORY) + execute_process (COMMAND "${CMAKE_COMMAND}" -E env "MONO_PATH=${_${_PYTHON_PREFIX}_IR_DIR}" + ${${_PYTHON_PREFIX}_DOTNET_LAUNCHER} "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.exe" WORKING_DIRECTORY "${_${_PYTHON_PREFIX}_VERSION_DIR}" RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT OUTPUT_VARIABLE _${_PYTHON_PREFIX}_VERSION @@ -1593,12 +2096,14 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) endif() elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR) set (${_PYTHON_PREFIX}_Compiler_FOUND TRUE) - # Use compiler version for future searches to ensure consistency - set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}) + # Use compiler version for future searches to ensure consistency + set (_${_PYTHON_PREFIX}_FIND_VERSIONS ${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}) endif() endif() if (${_PYTHON_PREFIX}_Compiler_FOUND) + unset (_${_PYTHON_PREFIX}_Compiler_REASON_FAILURE) + # compute and save compiler signature string (MD5 __${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_COMPILER}") set (_${_PYTHON_PREFIX}_COMPILER_SIGNATURE "${__${_PYTHON_PREFIX}_COMPILER_SIGNATURE}" CACHE INTERNAL "") @@ -1609,54 +2114,61 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) unset (${_PYTHON_PREFIX}_COMPILER_ID) endif() + if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE) + set (${_PYTHON_PREFIX}_COMPILER "${_${_PYTHON_PREFIX}_COMPILER}" CACHE FILEPATH "${_PYTHON_PREFIX} Compiler") + endif() + _python_mark_as_internal (_${_PYTHON_PREFIX}_COMPILER _${_PYTHON_PREFIX}_COMPILER_SIGNATURE) endif() - # third step, search for the development artifacts +if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Module) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) + list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES) + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) + list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_INCLUDE_DIRS) + endif() +endif() +if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development.Embed) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS) + list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES) + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS) + list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_INCLUDE_DIRS) + endif() +endif() +list (REMOVE_DUPLICATES _${_PYTHON_PREFIX}_REQUIRED_VARS) ## Development environment is not compatible with IronPython interpreter -if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS - AND NOT ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython") +if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + OR "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) + AND ((${_PYTHON_PREFIX}_Interpreter_FOUND + AND NOT ${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "IronPython") + OR NOT ${_PYTHON_PREFIX}_Interpreter_FOUND)) + if (${_PYTHON_PREFIX}_Interpreter_FOUND) + # reduce possible implementations to the interpreter one + if (${_PYTHON_PREFIX}_INTERPRETER_ID STREQUAL "PyPy") + set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "PyPy") + else() + set (_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "CPython") + endif() + else() + list (REMOVE_ITEM _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS "IronPython") + endif() + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_LIBRARY_RELEASE _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE _${_PYTHON_PREFIX}_LIBRARY_DEBUG - _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG - _${_PYTHON_PREFIX}_INCLUDE_DIR) - if (${_PYTHON_PREFIX}_FIND_REQUIRED_Development) - list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_LIBRARIES - ${_PYTHON_PREFIX}_INCLUDE_DIRS) - endif() - - if (DEFINED _${_PYTHON_PREFIX}_LIBRARY_RELEASE OR DEFINED _${_PYTHON_PREFIX}_INCLUDE_DIR) - # compute development signature and check validity of definition - string (MD5 __${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:${_${_PYTHON_PREFIX}_INCLUDE_DIR}") - if (WIN32 AND NOT DEFINED _${_PYTHON_PREFIX}_LIBRARY_DEBUG) - set (_${_PYTHON_PREFIX}_LIBRARY_DEBUG "${_PYTHON_PREFIX}_LIBRARY_DEBUG-NOTFOUND" CACHE INTERNAL "") - endif() - if (NOT DEFINED _${_PYTHON_PREFIX}_INCLUDE_DIR) - set (_${_PYTHON_PREFIX}_INCLUDE_DIR "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND" CACHE INTERNAL "") - endif() - if (__${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE) - # check version validity - if (${_PYTHON_PREFIX}_FIND_VERSION_EXACT) - _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) - _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} EXACT CHECK_EXISTS) - else() - _python_validate_library (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) - _python_validate_include_dir (${${_PYTHON_PREFIX}_FIND_VERSION} CHECK_EXISTS) - endif() - else() - unset (_${_PYTHON_PREFIX}_LIBRARY_RELEASE CACHE) - unset (_${_PYTHON_PREFIX}_LIBRARY_DEBUG CACHE) - unset (_${_PYTHON_PREFIX}_INCLUDE_DIR CACHE) - endif() + _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG) endif() - if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE OR NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) - unset (_${_PYTHON_PREFIX}_CONFIG CACHE) - unset (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE CACHE) + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) + list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_INCLUDE_DIR) endif() + _python_check_development_signature (Module) + _python_check_development_signature (Embed) + if (DEFINED ${_PYTHON_PREFIX}_LIBRARY AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_LIBRARY}") set (_${_PYTHON_PREFIX}_LIBRARY_RELEASE "${${_PYTHON_PREFIX}_LIBRARY}" CACHE INTERNAL "") @@ -1683,25 +2195,18 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS # if python interpreter is found, use it to look-up for artifacts # to ensure consistency between interpreter and development environments. # If not, try to locate a compatible config tool - if (NOT ${_PYTHON_PREFIX}_Interpreter_FOUND OR CMAKE_CROSSCOMPILING) + if ((NOT ${_PYTHON_PREFIX}_Interpreter_FOUND OR CMAKE_CROSSCOMPILING) + AND "CPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS) set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS) if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX) endif() - unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS) if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION") - set (_${_PYTHON_PREFIX}_CONFIG_NAMES) - - foreach (_${_PYTHON_PREFIX}_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX CONFIG) - list (APPEND _${_PYTHON_PREFIX}_CONFIG_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES}) - + _python_get_names (_${_PYTHON_PREFIX}_CONFIG_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} POSIX CONFIG) # Framework Paths - _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS}) - endforeach() + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS}) # Apple frameworks handling if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") @@ -1785,7 +2290,7 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS _python_get_names (_${_PYTHON_PREFIX}_CONFIG_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} POSIX CONFIG) # Framework Paths - _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION}) # Apple frameworks handling if (CMAKE_HOST_APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") @@ -1878,140 +2383,61 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS endif() endif() - if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) - if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG) - # retrieve root install directory - _python_get_config_var (_${_PYTHON_PREFIX}_PREFIX PREFIX) - - # enforce current ABI - _python_get_config_var (_${_PYTHON_PREFIX}_ABIFLAGS ABIFLAGS) - - set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}") - - # retrieve library - ## compute some paths and artifact names - if (_${_PYTHON_PREFIX}_CONFIG) - string (REGEX REPLACE "^.+python([0-9.]+)[a-z]*-config" "\\1" _${_PYTHON_PREFIX}_VERSION "${_${_PYTHON_PREFIX}_CONFIG}") - else() - set (_${_PYTHON_PREFIX}_VERSION "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}") - endif() - _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} LIBRARY) - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY) - - _python_get_config_var (_${_PYTHON_PREFIX}_CONFIGDIR CONFIGDIR) - list (APPEND _${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_CONFIGDIR}") - - list (APPEND _${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - - find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} - NAMES_PER_DIR - HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) - endif() - - # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) - set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - - unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS) - if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") - set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX) - endif() - - if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION") - unset (_${_PYTHON_PREFIX}_LIB_NAMES) - unset (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG) - unset (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS) - unset (_${_PYTHON_PREFIX}_REGISTRY_PATHS) - unset (_${_PYTHON_PREFIX}_PATH_SUFFIXES) - - foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - # library names - _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY) - list (APPEND _${_PYTHON_PREFIX}_LIB_NAMES ${_${_PYTHON_PREFIX}_VERSION_NAMES}) - _python_get_names (_${_PYTHON_PREFIX}_VERSION_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG) - list (APPEND _${_PYTHON_PREFIX}_LIB_NAMES_DEBUG ${_${_PYTHON_PREFIX}_VERSION_NAMES}) - - # Framework Paths - _python_get_frameworks (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION}) - list (APPEND _${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS}) + if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG) + # retrieve root install directory + _python_get_config_var (_${_PYTHON_PREFIX}_PREFIX PREFIX) - # Registry Paths - _python_get_registries (_${_PYTHON_PREFIX}_VERSION_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION}) - list (APPEND _${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION_PATHS}) + # enforce current ABI + _python_get_config_var (_${_PYTHON_PREFIX}_ABIFLAGS ABIFLAGS) - # Paths suffixes - _python_get_path_suffixes (_${_PYTHON_PREFIX}_VERSION_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY) - list (APPEND _${_PYTHON_PREFIX}_PATH_SUFFIXES ${_${_PYTHON_PREFIX}_VERSION_PATHS}) - endforeach() + set (_${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_PREFIX}") - if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") - find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} - NAMES_PER_DIR - HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} - ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} - NO_CMAKE_PATH - NO_CMAKE_ENVIRONMENT_PATH - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) + # retrieve library + ## compute some paths and artifact names + if (_${_PYTHON_PREFIX}_CONFIG) + string (REGEX REPLACE "^.+python([0-9.]+)[a-z]*-config" "\\1" _${_PYTHON_PREFIX}_VERSION "${_${_PYTHON_PREFIX}_CONFIG}") + else() + set (_${_PYTHON_PREFIX}_VERSION "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}") endif() + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} LIBRARY) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY) - if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") - find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} - NAMES_PER_DIR - HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} - ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) - endif() + _python_get_config_var (_${_PYTHON_PREFIX}_CONFIGDIR CONFIGDIR) + list (APPEND _${_PYTHON_PREFIX}_HINTS "${_${_PYTHON_PREFIX}_CONFIGDIR}") + + list (APPEND _${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - # search in HINTS locations find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + endif() - if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) - endif() + # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts + if (NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) + unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS) + if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") + set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX) endif() - # search in all default paths - find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} - NAMES_PER_DIR - PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) - else() - foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY) - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG) - - _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION}) - _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_LIB_VERSION}) + if (_${_PYTHON_PREFIX}_FIND_STRATEGY STREQUAL "LOCATION") + # library names + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} WIN32 POSIX LIBRARY) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} WIN32 DEBUG) + # Paths suffixes + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} LIBRARY) - _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY) + # Framework Paths + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_FIND_VERSIONS}) + # Registry Paths + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_FIND_VERSIONS} ) if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE @@ -2049,184 +2475,288 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) - if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) - endif() + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + endif() - if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) - endif() + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) + endif() - # search in all default paths - find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE + # search in all default paths + find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} NAMES_PER_DIR PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) + else() + foreach (_${_PYTHON_PREFIX}_LIB_VERSION IN LISTS _${_PYTHON_PREFIX}_FIND_VERSIONS) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 POSIX LIBRARY) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} WIN32 DEBUG) + + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION}) + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION}) + + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_LIB_VERSION} LIBRARY) + + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} + ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) - break() - endif() - endforeach() + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} + ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + + # search in HINTS locations + find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} + NAMES_PER_DIR + HINTS ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + endif() + + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) + endif() + + # search in all default paths + find_library (_${_PYTHON_PREFIX}_LIBRARY_RELEASE + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} + NAMES_PER_DIR + PATHS ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES}) + + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) + break() + endif() + endforeach() + endif() endif() endif() - endif() - # finalize library version information - _python_get_version (LIBRARY PREFIX _${_PYTHON_PREFIX}_) + # finalize library version information + _python_get_version (LIBRARY PREFIX _${_PYTHON_PREFIX}_) + if (_${_PYTHON_PREFIX}_VERSION EQUAL "${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}") + # not able to extract full version from library name + if (${_PYTHON_PREFIX}_Interpreter_FOUND) + # update from interpreter + set (_${_PYTHON_PREFIX}_VERSION ${${_PYTHON_PREFIX}_VERSION}) + set (_${_PYTHON_PREFIX}_VERSION_MAJOR ${${_PYTHON_PREFIX}_VERSION_MAJOR}) + set (_${_PYTHON_PREFIX}_VERSION_MINOR ${${_PYTHON_PREFIX}_VERSION_MINOR}) + set (_${_PYTHON_PREFIX}_VERSION_PATCH ${${_PYTHON_PREFIX}_VERSION_PATCH}) + endif() + endif() - set (${_PYTHON_PREFIX}_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}") + set (${_PYTHON_PREFIX}_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}") - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}") - set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"") - set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") - endif() + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT EXISTS "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}") + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the library \"${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}\"") + set_property (CACHE _${_PYTHON_PREFIX}_LIBRARY_RELEASE PROPERTY VALUE "${_PYTHON_PREFIX}_LIBRARY_RELEASE-NOTFOUND") + endif() - set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - - if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE) - # search for debug library - # use release library location as a hint - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG) - get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) - find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG} - NAMES_PER_DIR - HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} - NO_DEFAULT_PATH) - endif() - - # retrieve runtime libraries - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY) - get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) - get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY) - _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} - NAMES_PER_DIR - HINTS "${_${_PYTHON_PREFIX}_PATH}" "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin) - endif() - if (_${_PYTHON_PREFIX}_LIBRARY_DEBUG) - _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG) - get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}" DIRECTORY) - get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY) - _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG - NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG} - NAMES_PER_DIR - HINTS "${_${_PYTHON_PREFIX}_PATH}" "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin) - endif() - - # Don't search for include dir if no library was founded - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) - if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG) - _python_get_config_var (_${_PYTHON_PREFIX}_INCLUDE_DIRS INCLUDES) + set (_${_PYTHON_PREFIX}_HINTS "${${_PYTHON_PREFIX}_ROOT_DIR}" ENV ${_PYTHON_PREFIX}_ROOT_DIR) - find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR - NAMES Python.h - HINTS ${_${_PYTHON_PREFIX}_INCLUDE_DIRS} - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) + if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + # search for debug library + # use release library location as a hint + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG) + get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) + find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG} + NAMES_PER_DIR + HINTS "${_${_PYTHON_PREFIX}_PATH}" ${_${_PYTHON_PREFIX}_HINTS} + NO_DEFAULT_PATH) + # second try including CMAKE variables to catch-up non conventional layouts + find_library (_${_PYTHON_PREFIX}_LIBRARY_DEBUG + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG} + NAMES_PER_DIR + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) endif() - # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts - if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) - unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS) - if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") - set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX) - endif() - unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS) - - # Use the library's install prefix as a hint - if (${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+/Frameworks/Python.framework/Versions/[0-9.]+)") - list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") - elseif (${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib(64|32)?/python[0-9.]+/config") - list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") - elseif (DEFINED CMAKE_LIBRARY_ARCHITECTURE AND ${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib/${CMAKE_LIBRARY_ARCHITECTURE}") - list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") - else() - # assume library is in a directory under root - get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) - get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_PREFIX}" DIRECTORY) - list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PREFIX}") + # retrieve runtime libraries + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 POSIX LIBRARY) + get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) + get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY) + _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES} + NAMES_PER_DIR + HINTS "${_${_PYTHON_PREFIX}_PATH}" + "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS} + PATH_SUFFIXES bin) + endif() + if (_${_PYTHON_PREFIX}_LIBRARY_DEBUG) + _python_get_names (_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG VERSION ${_${_PYTHON_PREFIX}_VERSION} WIN32 DEBUG) + get_filename_component (_${_PYTHON_PREFIX}_PATH "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}" DIRECTORY) + get_filename_component (_${_PYTHON_PREFIX}_PATH2 "${_${_PYTHON_PREFIX}_PATH}" DIRECTORY) + _python_find_runtime_library (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG + NAMES ${_${_PYTHON_PREFIX}_LIB_NAMES_DEBUG} + NAMES_PER_DIR + HINTS "${_${_PYTHON_PREFIX}_PATH}" + "${_${_PYTHON_PREFIX}_PATH2}" ${_${_PYTHON_PREFIX}_HINTS} + PATH_SUFFIXES bin) + endif() + endif() + + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) + while (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS + AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE) + # Don't search for include dir if no library was founded + break() endif() - _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_VERSION}) - _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INCLUDE) + if ((${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT CMAKE_CROSSCOMPILING) OR _${_PYTHON_PREFIX}_CONFIG) + _python_get_config_var (_${_PYTHON_PREFIX}_INCLUDE_DIRS INCLUDES) - if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR - NAMES Python.h - HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} - ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} - NO_CMAKE_PATH - NO_CMAKE_ENVIRONMENT_PATH + NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES} + HINTS ${_${_PYTHON_PREFIX}_INCLUDE_DIRS} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() - if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + # Rely on HINTS and standard paths if interpreter or config tool failed to locate artifacts + if (NOT _${_PYTHON_PREFIX}_INCLUDE_DIR) + unset (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS) + if (_${_PYTHON_PREFIX}_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") + set (_${_PYTHON_PREFIX}_VIRTUALENV_PATHS ENV VIRTUAL_ENV ENV CONDA_PREFIX) + endif() + unset (_${_PYTHON_PREFIX}_INCLUDE_HINTS) + + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) + # Use the library's install prefix as a hint + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "^(.+/Frameworks/Python.framework/Versions/[0-9.]+)") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") + elseif (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "^(.+)/lib(64|32)?/python[0-9.]+/config") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") + elseif (DEFINED CMAKE_LIBRARY_ARCHITECTURE AND ${_${_PYTHON_PREFIX}_LIBRARY_RELEASE} MATCHES "^(.+)/lib/${CMAKE_LIBRARY_ARCHITECTURE}") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${CMAKE_MATCH_1}") + else() + # assume library is in a directory under root + get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) + get_filename_component (_${_PYTHON_PREFIX}_PREFIX "${_${_PYTHON_PREFIX}_PREFIX}" DIRECTORY) + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_HINTS "${_${_PYTHON_PREFIX}_PREFIX}") + endif() + endif() + + _python_get_frameworks (_${_PYTHON_PREFIX}_FRAMEWORK_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_registries (_${_PYTHON_PREFIX}_REGISTRY_PATHS VERSION ${_${_PYTHON_PREFIX}_VERSION}) + _python_get_path_suffixes (_${_PYTHON_PREFIX}_PATH_SUFFIXES VERSION ${_${_PYTHON_PREFIX}_VERSION} INCLUDE) + + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "FIRST") + find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR + NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES} + HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} + ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "FIRST") + find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR + NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES} + HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} + PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} + ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + endif() + + if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) + endif() + + if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") + set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) + else() + unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) + endif() + find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR - NAMES Python.h + NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES} HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} - ${_${_PYTHON_PREFIX}_REGISTRY_PATHS} + ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} + ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() - if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS ${_${_PYTHON_PREFIX}_FRAMEWORK_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_FRAMEWORK_PATHS) - endif() - - if (WIN32 AND _${_PYTHON_PREFIX}_FIND_REGISTRY STREQUAL "LAST") - set (__${_PYTHON_PREFIX}_REGISTRY_PATHS ${_${_PYTHON_PREFIX}_REGISTRY_PATHS}) - else() - unset (__${_PYTHON_PREFIX}_REGISTRY_PATHS) - endif() - + # search header file in standard locations find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR - NAMES Python.h - HINTS ${_${_PYTHON_PREFIX}_INCLUDE_HINTS} ${_${_PYTHON_PREFIX}_HINTS} - PATHS ${_${_PYTHON_PREFIX}_VIRTUALENV_PATHS} - ${__${_PYTHON_PREFIX}_FRAMEWORK_PATHS} - ${__${_PYTHON_PREFIX}_REGISTRY_PATHS} - PATH_SUFFIXES ${_${_PYTHON_PREFIX}_PATH_SUFFIXES} - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH) - endif() + NAMES ${_${_PYTHON_PREFIX}_INCLUDE_NAMES}) - # search header file in standard locations - find_path (_${_PYTHON_PREFIX}_INCLUDE_DIR - NAMES Python.h) - endif() + break() + endwhile() - set (${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}") + set (${_PYTHON_PREFIX}_INCLUDE_DIRS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}") - if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}") - set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"") - set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") - endif() - - if (_${_PYTHON_PREFIX}_INCLUDE_DIR) - # retrieve version from header file - _python_get_version (INCLUDE PREFIX _${_PYTHON_PREFIX}_INC_) + if (_${_PYTHON_PREFIX}_INCLUDE_DIR AND NOT EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}") + set (_${_PYTHON_PREFIX}_Development_REASON_FAILURE "Cannot find the directory \"${_${_PYTHON_PREFIX}_INCLUDE_DIR}\"") + set_property (CACHE _${_PYTHON_PREFIX}_INCLUDE_DIR PROPERTY VALUE "${_PYTHON_PREFIX}_INCLUDE_DIR-NOTFOUND") + endif() - # update versioning - if (_${_PYTHON_PREFIX}_INC_VERSION VERSION_EQUAL _${_PYTHON_PREFIX}_VERSION) - set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH}) + if (_${_PYTHON_PREFIX}_INCLUDE_DIR) + # retrieve version from header file + _python_get_version (INCLUDE PREFIX _${_PYTHON_PREFIX}_INC_) + + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE) + if ("${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" + VERSION_EQUAL _${_PYTHON_PREFIX}_VERSION) + # update versioning + set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION}) + set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH}) + endif() + else() + set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION}) + set (_${_PYTHON_PREFIX}_VERSION_MAJOR ${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}) + set (_${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}) + set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH}) + endif() endif() endif() @@ -2239,88 +2769,125 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS endif() # define public variables - set (${_PYTHON_PREFIX}_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}") - _python_select_library_configurations (${_PYTHON_PREFIX}) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) + set (${_PYTHON_PREFIX}_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_LIBRARY_DEBUG}") + _python_select_library_configurations (${_PYTHON_PREFIX}) - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}") - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}") + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}") + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}") - if (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE) - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}") - elseif (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG) - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}") - else() - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_PYTHON_PREFIX}_RUNTIME_LIBRARY-NOTFOUND") - endif() - - _python_set_library_dirs (${_PYTHON_PREFIX}_LIBRARY_DIRS - _${_PYTHON_PREFIX}_LIBRARY_RELEASE _${_PYTHON_PREFIX}_LIBRARY_DEBUG) - if (UNIX) - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$") - set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS ${${_PYTHON_PREFIX}_LIBRARY_DIRS}) + if (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE) + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}") + elseif (_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG) + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG}") + else() + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY "${_PYTHON_PREFIX}_RUNTIME_LIBRARY-NOTFOUND") endif() - else() + + _python_set_library_dirs (${_PYTHON_PREFIX}_LIBRARY_DIRS + _${_PYTHON_PREFIX}_LIBRARY_RELEASE + _${_PYTHON_PREFIX}_LIBRARY_DEBUG) + if (UNIX) + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$") + set (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS ${${_PYTHON_PREFIX}_LIBRARY_DIRS}) + endif() + else() _python_set_library_dirs (${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DIRS - _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG) + _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE + _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG) + endif() endif() - if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE AND _${_PYTHON_PREFIX}_INCLUDE_DIR) + if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE OR _${_PYTHON_PREFIX}_INCLUDE_DIR) if (${_PYTHON_PREFIX}_Interpreter_FOUND OR ${_PYTHON_PREFIX}_Compiler_FOUND) # development environment must be compatible with interpreter/compiler if ("${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}" VERSION_EQUAL "${${_PYTHON_PREFIX}_VERSION_MAJOR}.${${_PYTHON_PREFIX}_VERSION_MINOR}" AND "${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL "${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}") - set (${_PYTHON_PREFIX}_Development_FOUND TRUE) + _python_set_development_module_found (Module) + _python_set_development_module_found (Embed) endif() elseif (${_PYTHON_PREFIX}_VERSION_MAJOR VERSION_EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR - AND "${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL "${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}") - set (${_PYTHON_PREFIX}_Development_FOUND TRUE) + AND "${_${_PYTHON_PREFIX}_INC_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}" VERSION_EQUAL "${_${_PYTHON_PREFIX}_VERSION_MAJOR}.${_${_PYTHON_PREFIX}_VERSION_MINOR}") + _python_set_development_module_found (Module) + _python_set_development_module_found (Embed) endif() if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI AND (NOT _${_PYTHON_PREFIX}_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS OR NOT _${_PYTHON_PREFIX}_INC_ABI IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)) - set (${_PYTHON_PREFIX}_Development_FOUND FALSE) + set (${_PYTHON_PREFIX}_Development.Module_FOUND FALSE) + set (${_PYTHON_PREFIX}_Development.Embed_FOUND FALSE) endif() endif() + if (( ${_PYTHON_PREFIX}_Development.Module_FOUND + AND ${_PYTHON_PREFIX}_Development.Embed_FOUND) + OR (NOT "Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + AND ${_PYTHON_PREFIX}_Development.Embed_FOUND) + OR (NOT "Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + AND ${_PYTHON_PREFIX}_Development.Module_FOUND)) + unset (_${_PYTHON_PREFIX}_Development_REASON_FAILURE) + endif() + + if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + AND ${_PYTHON_PREFIX}_Development.Module_FOUND + AND ${_PYTHON_PREFIX}_Development.Embed_FOUND) + set (${_PYTHON_PREFIX}_Development_FOUND TRUE) + endif() + + if ((${_PYTHON_PREFIX}_Development.Module_FOUND + OR ${_PYTHON_PREFIX}_Development.Embed_FOUND) + AND EXISTS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/PyPy.h") + # retrieve PyPy version + file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" ${_PYTHON_PREFIX}_PyPy_VERSION + REGEX "^#define[ \t]+PYPY_VERSION[ \t]+\"[^\"]+\"") + string (REGEX REPLACE "^#define[ \t]+PYPY_VERSION[ \t]+\"([^\"]+)\".*" "\\1" + ${_PYTHON_PREFIX}_PyPy_VERSION "${${_PYTHON_PREFIX}_PyPy_VERSION}") + endif() + if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR VERSION_GREATER_EQUAL "3" AND NOT DEFINED ${_PYTHON_PREFIX}_SOABI) _python_get_config_var (${_PYTHON_PREFIX}_SOABI SOABI) endif() - if (${_PYTHON_PREFIX}_Development_FOUND) - # compute and save development signature - string (MD5 __${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${_${_PYTHON_PREFIX}_SIGNATURE}:${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}:${_${_PYTHON_PREFIX}_INCLUDE_DIR}") - set (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE "${__${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}" CACHE INTERNAL "") - else() - unset (_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE CACHE) - endif() + _python_compute_development_signature (Module) + _python_compute_development_signature (Embed) # Restore the original find library ordering if (DEFINED _${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES) set (CMAKE_FIND_LIBRARY_SUFFIXES ${_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES}) endif() + if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) + set (${_PYTHON_PREFIX}_LIBRARY "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" CACHE FILEPATH "${_PYTHON_PREFIX} Library") + endif() + if ("INCLUDE_DIR" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS) + set (${_PYTHON_PREFIX}_INCLUDE_DIR "${_${_PYTHON_PREFIX}_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} Include Directory") + endif() + endif() + _python_mark_as_internal (_${_PYTHON_PREFIX}_LIBRARY_RELEASE _${_PYTHON_PREFIX}_LIBRARY_DEBUG _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE _${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG _${_PYTHON_PREFIX}_INCLUDE_DIR _${_PYTHON_PREFIX}_CONFIG - _${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE) + _${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE + _${_PYTHON_PREFIX}_DEVELOPMENT_EMBED_SIGNATURE) endif() +if (${_PYTHON_PREFIX}_FIND_REQUIRED_NumPy) + list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS) +endif() if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Interpreter_FOUND) list (APPEND _${_PYTHON_PREFIX}_CACHED_VARS _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR) - if (${_PYTHON_PREFIX}_FIND_REQUIRED_NumPy) - list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VARS ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIRS) - endif() if (DEFINED ${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR AND IS_ABSOLUTE "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}") set (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE INTERNAL "") elseif (DEFINED _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR) # compute numpy signature. Depends on interpreter and development signatures - string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}:${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}") + string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE}:${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}") if (NOT __${_PYTHON_PREFIX}_NUMPY_SIGNATURE STREQUAL _${_PYTHON_PREFIX}_NUMPY_SIGNATURE OR NOT EXISTS "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}") unset (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR CACHE) @@ -2329,13 +2896,12 @@ if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Inte endif() if (NOT _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR) - execute_process( - COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c - "from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n" - RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT - OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_PATH - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry: import numpy; sys.stdout.write(numpy.get_include())\nexcept:pass\n" + RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT + OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_PATH + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT _${_PYTHON_PREFIX}_RESULT) find_path (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR @@ -2353,31 +2919,36 @@ if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Inte endif() if (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR) - execute_process ( - COMMAND "${${_PYTHON_PREFIX}_EXECUTABLE}" -c - "from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n" - RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT - OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_VERSION) + execute_process (COMMAND ${${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry: import numpy; sys.stdout.write(numpy.__version__)\nexcept:pass\n" + RESULT_VARIABLE _${_PYTHON_PREFIX}_RESULT + OUTPUT_VARIABLE _${_PYTHON_PREFIX}_NumPy_VERSION) if (NOT _${_PYTHON_PREFIX}_RESULT) set (${_PYTHON_PREFIX}_NumPy_VERSION "${_${_PYTHON_PREFIX}_NumPy_VERSION}") else() unset (${_PYTHON_PREFIX}_NumPy_VERSION) endif() - # final step: set NumPy founded only if Development component is founded as well - set(${_PYTHON_PREFIX}_NumPy_FOUND ${${_PYTHON_PREFIX}_Development_FOUND}) + # final step: set NumPy founded only if Development.Module component is founded as well + set(${_PYTHON_PREFIX}_NumPy_FOUND ${${_PYTHON_PREFIX}_Development.Module_FOUND}) else() set (${_PYTHON_PREFIX}_NumPy_FOUND FALSE) endif() if (${_PYTHON_PREFIX}_NumPy_FOUND) + unset (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE) + # compute and save numpy signature - string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_SIGNATURE}:${${_PYTHON_PREFIX}_NumPyINCLUDE_DIR}") + string (MD5 __${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE}:${_${_PYTHON_PREFIX}_DEVELOPMENT_MODULE_SIGNATURE}:${${_PYTHON_PREFIX}_NumPyINCLUDE_DIR}") set (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE "${__${_PYTHON_PREFIX}_NUMPY_SIGNATURE}" CACHE INTERNAL "") else() unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE) endif() + if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE) + set (${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} NumPy Include Directory") + endif() + _python_mark_as_internal (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR _${_PYTHON_PREFIX}_NUMPY_SIGNATURE) endif() @@ -2390,11 +2961,10 @@ endif() unset (_${_PYTHON_PREFIX}_REASON_FAILURE) foreach (_${_PYTHON_PREFIX}_COMPONENT IN ITEMS Interpreter Compiler Development NumPy) - if (NOT ${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_FOUND - AND _${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE) + if (_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE) string (APPEND _${_PYTHON_PREFIX}_REASON_FAILURE "\n ${_${_PYTHON_PREFIX}_COMPONENT}: ${_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE}") + unset (_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE) endif() - unset (_${_PYTHON_PREFIX}_${_${_PYTHON_PREFIX}_COMPONENT}_REASON_FAILURE) endforeach() include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake) @@ -2422,8 +2992,10 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") PROPERTY IMPORTED_LOCATION "${${_PYTHON_PREFIX}_COMPILER}") endif() - if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS - AND ${_PYTHON_PREFIX}_Development_FOUND) + if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + AND ${_PYTHON_PREFIX}_Development.Module_FOUND) + OR ("Development.Embed" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS + AND ${_PYTHON_PREFIX}_Development.Embed_FOUND)) macro (__PYTHON_IMPORT_LIBRARY __name) if (${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$" @@ -2455,8 +3027,8 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") else() set_target_properties (${__name} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARY}" - IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY}") + IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARIES}" + IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}") endif() else() if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG) @@ -2470,7 +3042,7 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") else() set_target_properties (${__name} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY}") + IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}") endif() endif() @@ -2484,31 +3056,35 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") endif() endmacro() - __python_import_library (${_PYTHON_PREFIX}::Python) - - if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$") - # On Windows/CYGWIN/MSYS, Python::Module is the same as Python::Python - # but ALIAS cannot be used because the imported library is not GLOBAL. - __python_import_library (${_PYTHON_PREFIX}::Module) - else() - if (NOT TARGET ${_PYTHON_PREFIX}::Module ) - add_library (${_PYTHON_PREFIX}::Module INTERFACE IMPORTED) - endif() - set_property (TARGET ${_PYTHON_PREFIX}::Module - PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}") + if (${_PYTHON_PREFIX}_Development.Embed_FOUND) + __python_import_library (${_PYTHON_PREFIX}::Python) + endif() - # When available, enforce shared library generation with undefined symbols - if (APPLE) - set_property (TARGET ${_PYTHON_PREFIX}::Module - PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup") - endif() - if (CMAKE_SYSTEM_NAME STREQUAL "SunOS") - set_property (TARGET ${_PYTHON_PREFIX}::Module - PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-z,nodefs") - endif() - if (CMAKE_SYSTEM_NAME STREQUAL "AIX") + if (${_PYTHON_PREFIX}_Development.Module_FOUND) + if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) + # On Windows/CYGWIN/MSYS, Python::Module is the same as Python::Python + # but ALIAS cannot be used because the imported library is not GLOBAL. + __python_import_library (${_PYTHON_PREFIX}::Module) + else() + if (NOT TARGET ${_PYTHON_PREFIX}::Module) + add_library (${_PYTHON_PREFIX}::Module INTERFACE IMPORTED) + endif() set_property (TARGET ${_PYTHON_PREFIX}::Module - PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-b,erok") + PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}") + + # When available, enforce shared library generation with undefined symbols + if (APPLE) + set_property (TARGET ${_PYTHON_PREFIX}::Module + PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup") + endif() + if (CMAKE_SYSTEM_NAME STREQUAL "SunOS") + set_property (TARGET ${_PYTHON_PREFIX}::Module + PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-z,nodefs") + endif() + if (CMAKE_SYSTEM_NAME STREQUAL "AIX") + set_property (TARGET ${_PYTHON_PREFIX}::Module + PROPERTY INTERFACE_LINK_OPTIONS "LINKER:-b,erok") + endif() endif() endif() @@ -2517,8 +3093,7 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") # It is used to build modules for python. # function (__${_PYTHON_PREFIX}_ADD_LIBRARY prefix name) - cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY - "STATIC;SHARED;MODULE;WITH_SOABI" "" "") + cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY "STATIC;SHARED;MODULE;WITH_SOABI" "" "") if (prefix STREQUAL "Python2" AND PYTHON_ADD_LIBRARY_WITH_SOABI) message (AUTHOR_WARNING "FindPython2: Option `WITH_SOABI` is not supported for Python2 and will be ignored.") @@ -2532,6 +3107,16 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") else() set (type MODULE) endif() + + if (type STREQUAL "MODULE" AND NOT TARGET ${prefix}::Module) + message (SEND_ERROR "${prefix}_ADD_LIBRARY: dependent target '${prefix}::Module' is not defined.\n Did you miss to request COMPONENT 'Development.Module'?") + return() + endif() + if (NOT type STREQUAL "MODULE" AND NOT TARGET ${prefix}::Python) + message (SEND_ERROR "${prefix}_ADD_LIBRARY: dependent target '${prefix}::Python' is not defined.\n Did you miss to request COMPONENT 'Development.Embed'?") + return() + endif() + add_library (${name} ${type} ${PYTHON_ADD_LIBRARY_UNPARSED_ARGUMENTS}) get_property (type TARGET ${name} PROPERTY TYPE) diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index 3d0e6b9..84c0c73 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -13,13 +13,24 @@ The following components are supported: * ``Interpreter``: search for Python 2 interpreter * ``Compiler``: search for Python 2 compiler. Only offered by IronPython. * ``Development``: search for development artifacts (include directories and - libraries) + libraries). This component includes two sub-components which can be specified + independently: + + * ``Development.Module``: search for artifacts for Python 2 module + developments. + * ``Development.Embed``: search for artifacts for Python 2 embedding + developments. + * ``NumPy``: search for NumPy include directories. If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed. +If component ``Development`` is specified, it implies sub-components +``Development.Module`` and ``Development.Embed``. + To ensure consistent versions between components ``Interpreter``, ``Compiler``, -``Development`` and ``NumPy``, specify all components at the same time:: +``Development`` (or one of its sub-components) and ``NumPy``, specify all +components at the same time:: find_package (Python2 COMPONENTS Interpreter Development) @@ -31,10 +42,11 @@ for you. .. note:: - If components ``Interpreter`` and ``Development`` are both specified, this - module search only for interpreter with same platform architecture as the one - defined by ``CMake`` configuration. This contraint does not apply if only - ``Interpreter`` component is specified. + If components ``Interpreter`` and ``Development`` (or one of its + sub-components) are both specified, this module search only for interpreter + with same platform architecture as the one defined by ``CMake`` + configuration. This contraint does not apply if only ``Interpreter`` + component is specified. Imported Targets ^^^^^^^^^^^^^^^^ @@ -46,12 +58,12 @@ This module defines the following :ref:`Imported Targets <Imported Targets>` Python 2 interpreter. Target defined if component ``Interpreter`` is found. ``Python2::Compiler`` Python 2 compiler. Target defined if component ``Compiler`` is found. -``Python2::Python`` - Python 2 library for Python embedding. Target defined if component - ``Development`` is found. ``Python2::Module`` Python 2 library for Python module. Target defined if component - ``Development`` is found. + ``Development.Module`` is found. +``Python2::Python`` + Python 2 library for Python embedding. Target defined if component + ``Development.Embed`` is found. ``Python2::NumPy`` NumPy library for Python 2. Target defined if component ``NumPy`` is found. @@ -74,26 +86,31 @@ This module will set the following variables in your project * Anaconda * Canopy * IronPython + * PyPy ``Python2_STDLIB`` Standard platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)`` + or else ``sysconfig.get_path('stdlib')``. ``Python2_STDARCH`` Standard platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)`` + or else ``sysconfig.get_path('platstdlib')``. ``Python2_SITELIB`` Third-party platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)`` + or else ``sysconfig.get_path('purelib')``. ``Python2_SITEARCH`` Third-party platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)`` + or else ``sysconfig.get_path('platlib')``. ``Python2_Compiler_FOUND`` System has the Python 2 compiler. ``Python2_COMPILER`` @@ -101,8 +118,14 @@ This module will set the following variables in your project ``Python2_COMPILER_ID`` A short string unique to the compiler. Possible values include: * IronPython +``Python2_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. ``Python2_Development_FOUND`` System has the Python 2 development artifacts. +``Python2_Development.Module_FOUND`` + System has the Python 2 development artifacts for Python module. +``Python2_Development.Embed_FOUND`` + System has the Python 2 development artifacts for Python embedding. ``Python2_INCLUDE_DIRS`` The Python 2 include directories. ``Python2_LIBRARIES`` @@ -119,6 +142,8 @@ This module will set the following variables in your project Python 2 minor version. ``Python2_VERSION_PATCH`` Python 2 patch version. +``Python2_PyPy_VERSION`` + Python 2 PyPy version. ``Python2_NumPy_FOUND`` System has the NumPy. ``Python2_NumPy_INCLUDE_DIRS`` @@ -186,8 +211,9 @@ Hints * ``ONLY``: Only the virtual environment is used to look-up for the interpreter. * ``STANDARD``: The virtual environment is not used to look-up for the - interpreter. In this case, variable ``Python2_FIND_REGISTRY`` (Windows) - or ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or + interpreter but environment variable ``PATH`` is always considered. + In this case, variable ``Python2_FIND_REGISTRY`` (Windows) or + ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or ``NEVER`` to select preferably the interpreter from the virtual environment. @@ -197,6 +223,39 @@ Hints recommended to also include the component ``Interpreter`` to get expected result. +``Python2_FIND_IMPLEMENTATIONS`` + This variable defines, in an ordered list, the different implementations + which will be searched. The ``Python2_FIND_IMPLEMENTATIONS`` variable can + hold the following values: + + * ``CPython``: this is the standard implementation. Various products, like + ``Anaconda`` or ``ActivePython``, rely on this implementation. + * ``IronPython``: This implementation use the ``CSharp`` language for + ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``). + See `IronPython <http://ironpython.net>`_. + * ``PyPy``: This implementation use ``RPython`` language and + ``RPython translation toolchain`` to produce the python interpreter. + See `PyPy <https://www.pypy.org>`_. + + The default value is: + + * Windows platform: ``CPython``, ``IronPython`` + * Other platforms: ``CPython`` + + .. note:: + + This hint has the lowest priority of all hints, so even if, for example, + you specify ``IronPython`` first and ``CPython`` in second, a python + product based on ``CPython`` can be selected because, for example with + ``Python2_FIND_STRATEGY=LOCATION``, each location will be search first for + ``IronPython`` and second for ``CPython``. + + .. note:: + + When ``IronPython`` is specified, on platforms other than ``Windows``, the + ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available + through the ``PATH`` variable. + Artifacts Specification ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,6 +268,9 @@ setting the following variables: ``Python2_COMPILER`` The path to the compiler. +``Python2_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. + ``Python2_LIBRARY`` The path to the library. It will be used to compute the variables ``Python2_LIBRARIES``, ``Python2_LIBRAY_DIRS`` and @@ -235,6 +297,22 @@ setting the following variables: If more than one artifact is specified, it is the user's responsability to ensure the consistency of the various artifacts. +By default, this module supports multiple calls in different directories of a +project with different version/component requirements while providing correct +and consistent results for each call. To support this behavior, ``CMake`` cache +is not used in the traditional way which can be problematic for interactive +specification. So, to enable also interactive specification, module behavior +can be controled with the following variable: + +``Python2_ARTIFACTS_INTERACTIVE`` + Selects the behavior of the module. This is a boolean variable: + + * If set to ``TRUE``: Create CMake cache entries for the above artifact + specification variables so that users can edit them interactively. + This disables support for multiple version/component requirements. + * If set to ``FALSE`` or undefined: Enable multiple version/component + requirements. + Commands ^^^^^^^^ diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index c9a5d09..f142c07 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -13,13 +13,24 @@ The following components are supported: * ``Interpreter``: search for Python 3 interpreter * ``Compiler``: search for Python 3 compiler. Only offered by IronPython. * ``Development``: search for development artifacts (include directories and - libraries) + libraries). This component includes two sub-components which can be specified + independently: + + * ``Development.Module``: search for artifacts for Python 3 module + developments. + * ``Development.Embed``: search for artifacts for Python 3 embedding + developments. + * ``NumPy``: search for NumPy include directories. If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed. +If component ``Development`` is specified, it implies sub-components +``Development.Module`` and ``Development.Embed``. + To ensure consistent versions between components ``Interpreter``, ``Compiler``, -``Development`` and ``NumPy``, specify all components at the same time:: +``Development`` (or one of its sub-components) and ``NumPy``, specify all +components at the same time:: find_package (Python3 COMPONENTS Interpreter Development) @@ -31,10 +42,11 @@ for you. .. note:: - If components ``Interpreter`` and ``Development`` are both specified, this - module search only for interpreter with same platform architecture as the one - defined by ``CMake`` configuration. This contraint does not apply if only - ``Interpreter`` component is specified. + If components ``Interpreter`` and ``Development`` (or one of its + sub-components) are both specified, this module search only for interpreter + with same platform architecture as the one defined by ``CMake`` + configuration. This contraint does not apply if only ``Interpreter`` + component is specified. Imported Targets ^^^^^^^^^^^^^^^^ @@ -46,12 +58,12 @@ This module defines the following :ref:`Imported Targets <Imported Targets>` Python 3 interpreter. Target defined if component ``Interpreter`` is found. ``Python3::Compiler`` Python 3 compiler. Target defined if component ``Compiler`` is found. -``Python3::Python`` - Python 3 library for Python embedding. Target defined if component - ``Development`` is found. ``Python3::Module`` Python 3 library for Python module. Target defined if component - ``Development`` is found. + ``Development.Module`` is found. +``Python3::Python`` + Python 3 library for Python embedding. Target defined if component + ``Development.Embed`` is found. ``Python3::NumPy`` NumPy library for Python 3. Target defined if component ``NumPy`` is found. @@ -74,33 +86,40 @@ This module will set the following variables in your project * Anaconda * Canopy * IronPython + * PyPy ``Python3_STDLIB`` Standard platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)`` + or else ``sysconfig.get_path('stdlib')``. ``Python3_STDARCH`` Standard platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)`` + or else ``sysconfig.get_path('platstdlib')``. ``Python3_SITELIB`` Third-party platform independent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)`` + or else ``sysconfig.get_path('purelib')``. ``Python3_SITEARCH`` Third-party platform dependent installation directory. Information returned by - ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``. + ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)`` + or else ``sysconfig.get_path('platlib')``. ``Python3_SOABI`` Extension suffix for modules. Information returned by - ``distutils.sysconfig.get_config_flag('SOABI')`` or computed from - ``distutils.sysconfig.get_config_flag('EXT_SUFFIX')`` or - ``python3-config --extension-suffix``. + ``distutils.sysconfig.get_config_var('SOABI')`` or computed from + ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` or + ``python3-config --extension-suffix``. If package ``distutils.sysconfig`` is + not available, ``sysconfig.get_config_var('SOABI')`` or + ``sysconfig.get_config_var('EXT_SUFFIX')`` are used. ``Python3_Compiler_FOUND`` System has the Python 3 compiler. ``Python3_COMPILER`` @@ -108,8 +127,14 @@ This module will set the following variables in your project ``Python3_COMPILER_ID`` A short string unique to the compiler. Possible values include: * IronPython +``Python3_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. ``Python3_Development_FOUND`` System has the Python 3 development artifacts. +``Python3_Development.Module_FOUND`` + System has the Python 3 development artifacts for Python module. +``Python3_Development.Embed_FOUND`` + System has the Python 3 development artifacts for Python embedding. ``Python3_INCLUDE_DIRS`` The Python 3 include directories. ``Python3_LIBRARIES`` @@ -126,6 +151,8 @@ This module will set the following variables in your project Python 3 minor version. ``Python3_VERSION_PATCH`` Python 3 patch version. +``Python3_PyPy_VERSION`` + Python 3 PyPy version. ``Python3_NumPy_FOUND`` System has the NumPy. ``Python3_NumPy_INCLUDE_DIRS`` @@ -234,8 +261,9 @@ Hints * ``ONLY``: Only the virtual environment is used to look-up for the interpreter. * ``STANDARD``: The virtual environment is not used to look-up for the - interpreter. In this case, variable ``Python3_FIND_REGISTRY`` (Windows) - or ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or + interpreter but environment variable ``PATH`` is always considered. + In this case, variable ``Python3_FIND_REGISTRY`` (Windows) or + ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or ``NEVER`` to select preferably the interpreter from the virtual environment. @@ -245,6 +273,39 @@ Hints recommended to also include the component ``Interpreter`` to get expected result. +``Python3_FIND_IMPLEMENTATIONS`` + This variable defines, in an ordered list, the different implementations + which will be searched. The ``Python3_FIND_IMPLEMENTATIONS`` variable can + hold the following values: + + * ``CPython``: this is the standard implementation. Various products, like + ``Anaconda`` or ``ActivePython``, rely on this implementation. + * ``IronPython``: This implementation use the ``CSharp`` language for + ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``). + See `IronPython <http://ironpython.net>`_. + * ``PyPy``: This implementation use ``RPython`` language and + ``RPython translation toolchain`` to produce the python interpreter. + See `PyPy <https://www.pypy.org>`_. + + The default value is: + + * Windows platform: ``CPython``, ``IronPython`` + * Other platforms: ``CPython`` + + .. note:: + + This hint has the lowest priority of all hints, so even if, for example, + you specify ``IronPython`` first and ``CPython`` in second, a python + product based on ``CPython`` can be selected because, for example with + ``Python3_FIND_STRATEGY=LOCATION``, each location will be search first for + ``IronPython`` and second for ``CPython``. + + .. note:: + + When ``IronPython`` is specified, on platforms other than ``Windows``, the + ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available + through the ``PATH`` variable. + Artifacts Specification ^^^^^^^^^^^^^^^^^^^^^^^ @@ -257,6 +318,9 @@ setting the following variables: ``Python3_COMPILER`` The path to the compiler. +``Python3_DOTNET_LAUNCHER`` + The ``.Net`` interpreter. Only used by ``IronPython`` implementation. + ``Python3_LIBRARY`` The path to the library. It will be used to compute the variables ``Python3_LIBRARIES``, ``Python3_LIBRAY_DIRS`` and @@ -283,6 +347,22 @@ setting the following variables: If more than one artifact is specified, it is the user's responsability to ensure the consistency of the various artifacts. +By default, this module supports multiple calls in different directories of a +project with different version/component requirements while providing correct +and consistent results for each call. To support this behavior, ``CMake`` cache +is not used in the traditional way which can be problematic for interactive +specification. So, to enable also interactive specification, module behavior +can be controled with the following variable: + +``Python3_ARTIFACTS_INTERACTIVE`` + Selects the behavior of the module. This is a boolean variable: + + * If set to ``TRUE``: Create CMake cache entries for the above artifact + specification variables so that users can edit them interactively. + This disables support for multiple version/component requirements. + * If set to ``FALSE`` or undefined: Enable multiple version/component + requirements. + Commands ^^^^^^^^ diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index 7e01fbc..1bdee60 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -8,288 +8,505 @@ FindRuby Find Ruby This module finds if Ruby is installed and determines where the -include files and libraries are. Ruby 1.8, 1.9, 2.0 and 2.1 are +include files and libraries are. Ruby 1.8 through 2.7 are supported. The minimum required version of Ruby can be specified using the -standard syntax, e.g. find_package(Ruby 1.8) +standard syntax, e.g. -It also determines what the name of the library is. This code sets -the following variables: +.. code-block:: cmake -``RUBY_EXECUTABLE`` + find_package(Ruby 2.5.1 EXACT REQUIRED) + # OR + find_package(Ruby 2.4) + +It also determines what the name of the library is. + +Virtual environments such as RVM are handled as well, by passing +the argument ``Ruby_FIND_VIRTUALENV`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Ruby_FOUND`` + set to true if ruby was found successfully +``Ruby_EXECUTABLE`` full path to the ruby binary -``RUBY_INCLUDE_DIRS`` +``Ruby_INCLUDE_DIRS`` include dirs to be used when using the ruby library -``RUBY_LIBRARY`` - full path to the ruby library -``RUBY_VERSION`` +``Ruby_LIBRARIES`` + libraries needed to use ruby from C. +``Ruby_VERSION`` the version of ruby which was found, e.g. "1.8.7" -``RUBY_FOUND`` - set to true if ruby ws found successfully +``Ruby_VERSION_MAJOR`` + Ruby major version. +``Ruby_VERSION_MINOR`` + Ruby minor version. +``Ruby_VERSION_PATCH`` + Ruby patch version. + Also: -``RUBY_INCLUDE_PATH`` - same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it +``Ruby_INCLUDE_PATH`` + same as Ruby_INCLUDE_DIRS, only provided for compatibility reasons, don't use it + +Hints +^^^^^ + +``Ruby_ROOT_DIR`` + Define the root directory of a Ruby installation. + +``Ruby_FIND_VIRTUALENV`` + This variable defines the handling of virtual environments managed by + ``rvm``. It is meaningful only when a virtual environment + is active (i.e. the ``rvm`` script has been evaluated or at least the + ``MY_RUBY_HOME`` environment variable is set). + The ``Ruby_FIND_VIRTUALENV`` variable can be set to empty or + one of the following: + + * ``FIRST``: The virtual environment is used before any other standard + paths to look-up for the interpreter. This is the default. + * ``ONLY``: Only the virtual environment is used to look-up for the + interpreter. + * ``STANDARD``: The virtual environment is not used to look-up for the + interpreter (assuming it isn't still in the PATH...) + #]=======================================================================] -# RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'` -# RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'` -# RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'` -# RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'` -# RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'` +# Backwards compatibility +# Define camel case versions of input variables +foreach(UPPER + RUBY_EXECUTABLE + RUBY_LIBRARY + RUBY_INCLUDE_DIR + RUBY_CONFIG_INCLUDE_DIR + ) + if (DEFINED ${UPPER}) + string(REPLACE "RUBY_" "Ruby_" Camel ${UPPER}) + if (NOT DEFINED ${Camel}) + set(${Camel} ${${UPPER}}) + endif() + endif() +endforeach() + +# Ruby_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'` +# Ruby_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'` +# Ruby_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'` +# Ruby_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'` +# Ruby_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'` # uncomment the following line to get debug output for this file -# set(_RUBY_DEBUG_OUTPUT TRUE) +# set(_Ruby_DEBUG_OUTPUT TRUE) # Determine the list of possible names of the ruby executable depending # on which version of ruby is required -set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ruby) - -# if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8 -if(DEFINED Ruby_FIND_VERSION_MAJOR AND DEFINED Ruby_FIND_VERSION_MINOR) - set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}") - # we can't construct that if only major version is given - set(_RUBY_POSSIBLE_EXECUTABLE_NAMES - ruby${Ruby_FIND_VERSION_MAJOR}.${Ruby_FIND_VERSION_MINOR} - ruby${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR} - ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}) -else() - set(Ruby_FIND_VERSION_SHORT_NODOT "18") +set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby) + +# If not specified, allow everything as far back as 1.8.0 +if(NOT DEFINED Ruby_FIND_VERSION_MAJOR) + set(Ruby_FIND_VERSION "1.8.0") + set(Ruby_FIND_VERSION_MAJOR 1) + set(Ruby_FIND_VERSION_MINOR 8) + set(Ruby_FIND_VERSION_PATCH 0) +endif() + +if(_Ruby_DEBUG_OUTPUT) + message("Ruby_FIND_VERSION=${Ruby_FIND_VERSION}") + message("Ruby_FIND_VERSION_MAJOR=${Ruby_FIND_VERSION_MAJOR}") + message("Ruby_FIND_VERSION_MINOR=${Ruby_FIND_VERSION_MINOR}") + message("Ruby_FIND_VERSION_PATCH=${Ruby_FIND_VERSION_PATCH}") endif() +set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}") + +# Set name of possible executables, ignoring the minor +# Eg: +# 2.1.1 => from ruby27 to ruby21 included +# 2.1 => from ruby27 to ruby21 included +# 2 => from ruby26 to ruby20 included +# empty => from ruby27 to ruby18 included if(NOT Ruby_FIND_VERSION_EXACT) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.4 ruby24) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.3 ruby23) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.2 ruby22) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.1 ruby21) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.0 ruby20) - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.9 ruby19) - - # if we want a version below 1.9, also look for ruby 1.8 - if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19") - list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.8 ruby18) + + foreach(_ruby_version RANGE 27 18 -1) + string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version) + string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version) + + if(NOT "${_ruby_major_version}${_ruby_minor_version}" VERSION_LESS ${Ruby_FIND_VERSION_SHORT_NODOT}) + # Append both rubyX.Y and rubyXY (eg: ruby2.7 ruby27) + list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version}) + else() + break() + endif() + + endforeach() + + list(REMOVE_DUPLICATES _Ruby_POSSIBLE_EXECUTABLE_NAMES) +endif() + +# virtual environments handling (eg RVM) +if (DEFINED ENV{MY_RUBY_HOME}) + if(_Ruby_DEBUG_OUTPUT) + message("My ruby home is defined: $ENV{MY_RUBY_HOME}") + endif() + + if (DEFINED Ruby_FIND_VIRTUALENV) + if (NOT Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$") + message (AUTHOR_WARNING "FindRuby: ${Ruby_FIND_VIRTUALENV}: invalid value for 'Ruby_FIND_VIRTUALENV'. 'FIRST', 'ONLY' or 'STANDARD' expected. 'FIRST' will be used instead.") + set (_Ruby_FIND_VIRTUALENV "FIRST") + else() + set (_Ruby_FIND_VIRTUALENV ${Ruby_FIND_VIRTUALENV}) + endif() + else() + set (_Ruby_FIND_VIRTUALENV FIRST) endif() +else() + if (DEFINED Ruby_FIND_VIRTUALENV) + message("Environment variable MY_RUBY_HOME isn't set, defaulting back to Ruby_FIND_VIRTUALENV=STANDARD") + endif() + set (_Ruby_FIND_VIRTUALENV STANDARD) +endif() - list(REMOVE_DUPLICATES _RUBY_POSSIBLE_EXECUTABLE_NAMES) +if(_Ruby_DEBUG_OUTPUT) + message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}") + message("_Ruby_FIND_VIRTUALENV=${_Ruby_FIND_VIRTUALENV}") endif() -find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}) +function (_RUBY_VALIDATE_INTERPRETER) + if (NOT Ruby_EXECUTABLE) + return() + endif() -if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) + cmake_parse_arguments (PARSE_ARGV 0 _RVI "EXACT;CHECK_EXISTS" "" "") + if (_RVI_UNPARSED_ARGUMENTS) + set (expected_version ${_RVI_UNPARSED_ARGUMENTS}) + else() + unset (expected_version) + endif() + + if (_RVI_CHECK_EXISTS AND NOT EXISTS "${Ruby_EXECUTABLE}") + # interpreter does not exist anymore + set (_Ruby_Interpreter_REASON_FAILURE "Cannot find the interpreter \"${Ruby_EXECUTABLE}\"") + set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND") + return() + endif() + + # Check the version it returns + # executable found must have a specific version + execute_process (COMMAND "${Ruby_EXECUTABLE}" -e "puts RUBY_VERSION" + RESULT_VARIABLE result + OUTPUT_VARIABLE version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (result OR (_RVI_EXACT AND NOT version VERSION_EQUAL expected_version) OR (version VERSION_LESS expected_version)) + # interpreter not usable or has wrong major version + if (result) + set (_Ruby_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${Ruby_EXECUTABLE}\"") + else() + set (_Ruby_Interpreter_REASON_FAILURE "Wrong major version for the interpreter \"${Ruby_EXECUTABLE}\"") + endif() + set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND") + return() + endif() + +endfunction() + +while(1) + # Virtual environments handling + if(_Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") + if(_Ruby_DEBUG_OUTPUT) + message("Inside Matches") + endif() + find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR + PATHS ENV MY_RUBY_HOME + PATH_SUFFIXES bin Scripts + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + + if(_Ruby_DEBUG_OUTPUT) + message("Ruby_EXECUTABLE=${Ruby_EXECUTABLE}") + endif() + + _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}}) + if(Ruby_EXECUTABLE) + break() + endif() + if(NOT _Ruby_FIND_VIRTUALENV STREQUAL "ONLY") + break() + endif() + elseif(_Ruby_DEBUG_OUTPUT) + message("_Ruby_FIND_VIRTUALENV doesn't match: ${_Ruby_FIND_VIRTUALENV}") + endif() + + # try using standard paths + find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR) + _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}) + if (Ruby_EXECUTABLE) + break() + endif() + + break() +endwhile() + +if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) function(_RUBY_CONFIG_VAR RBVAR OUTVAR) - execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" - RESULT_VARIABLE _RUBY_SUCCESS - OUTPUT_VARIABLE _RUBY_OUTPUT + execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" + RESULT_VARIABLE _Ruby_SUCCESS + OUTPUT_VARIABLE _Ruby_OUTPUT ERROR_QUIET) - if(_RUBY_SUCCESS OR _RUBY_OUTPUT STREQUAL "") - execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']" - RESULT_VARIABLE _RUBY_SUCCESS - OUTPUT_VARIABLE _RUBY_OUTPUT + if(_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "") + execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']" + RESULT_VARIABLE _Ruby_SUCCESS + OUTPUT_VARIABLE _Ruby_OUTPUT ERROR_QUIET) endif() - set(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE) + set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE) endfunction() # query the ruby version - _RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR) - _RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR) - _RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH) + _RUBY_CONFIG_VAR("MAJOR" Ruby_VERSION_MAJOR) + _RUBY_CONFIG_VAR("MINOR" Ruby_VERSION_MINOR) + _RUBY_CONFIG_VAR("TEENY" Ruby_VERSION_PATCH) # query the different directories - _RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR) - _RUBY_CONFIG_VAR("arch" RUBY_ARCH) - _RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR) - _RUBY_CONFIG_VAR("rubyarchhdrdir" RUBY_ARCHHDR_DIR) - _RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR) - _RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR) + _RUBY_CONFIG_VAR("archdir" Ruby_ARCH_DIR) + _RUBY_CONFIG_VAR("arch" Ruby_ARCH) + _RUBY_CONFIG_VAR("rubyhdrdir" Ruby_HDR_DIR) + _RUBY_CONFIG_VAR("rubyarchhdrdir" Ruby_ARCHHDR_DIR) + _RUBY_CONFIG_VAR("libdir" Ruby_POSSIBLE_LIB_DIR) + _RUBY_CONFIG_VAR("rubylibdir" Ruby_RUBY_LIB_DIR) # site_ruby - _RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR) - _RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR) + _RUBY_CONFIG_VAR("sitearchdir" Ruby_SITEARCH_DIR) + _RUBY_CONFIG_VAR("sitelibdir" Ruby_SITELIB_DIR) # vendor_ruby available ? - execute_process(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'" - OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET) + execute_process(COMMAND ${Ruby_EXECUTABLE} -r vendor-specific -e "print 'true'" + OUTPUT_VARIABLE Ruby_HAS_VENDOR_RUBY ERROR_QUIET) - if(RUBY_HAS_VENDOR_RUBY) - _RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR) - _RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR) + if(Ruby_HAS_VENDOR_RUBY) + _RUBY_CONFIG_VAR("vendorlibdir" Ruby_VENDORLIB_DIR) + _RUBY_CONFIG_VAR("vendorarchdir" Ruby_VENDORARCH_DIR) endif() # save the results in the cache so we don't have to run ruby the next time again - set(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE) - set(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE) - set(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE) - set(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE) - set(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE) - set(RUBY_ARCHHDR_DIR ${RUBY_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE) - set(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE) - set(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE) - set(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE) - set(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE) - set(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE) - set(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE) - set(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE) + set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE) + set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE) + set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE) + set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE) + set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE) + set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE) + set(Ruby_POSSIBLE_LIB_DIR ${Ruby_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE) + set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE) + set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE) + set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE) + set(Ruby_HAS_VENDOR_RUBY ${Ruby_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE) + set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE) + set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE) mark_as_advanced( - RUBY_ARCH_DIR - RUBY_ARCH - RUBY_HDR_DIR - RUBY_ARCHHDR_DIR - RUBY_POSSIBLE_LIB_DIR - RUBY_RUBY_LIB_DIR - RUBY_SITEARCH_DIR - RUBY_SITELIB_DIR - RUBY_HAS_VENDOR_RUBY - RUBY_VENDORARCH_DIR - RUBY_VENDORLIB_DIR - RUBY_VERSION_MAJOR - RUBY_VERSION_MINOR - RUBY_VERSION_PATCH + Ruby_ARCH_DIR + Ruby_ARCH + Ruby_HDR_DIR + Ruby_ARCHHDR_DIR + Ruby_POSSIBLE_LIB_DIR + Ruby_RUBY_LIB_DIR + Ruby_SITEARCH_DIR + Ruby_SITELIB_DIR + Ruby_HAS_VENDOR_RUBY + Ruby_VENDORARCH_DIR + Ruby_VENDORLIB_DIR + Ruby_VERSION_MAJOR + Ruby_VERSION_MINOR + Ruby_VERSION_PATCH ) endif() -# In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling) +# In case Ruby_EXECUTABLE could not be executed (e.g. cross compiling) # try to detect which version we found. This is not too good. -if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) +if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) # by default assume 1.8.0 - set(RUBY_VERSION_MAJOR 1) - set(RUBY_VERSION_MINOR 8) - set(RUBY_VERSION_PATCH 0) + set(Ruby_VERSION_MAJOR 1) + set(Ruby_VERSION_MINOR 8) + set(Ruby_VERSION_PATCH 0) # check whether we found 1.9.x - if(${RUBY_EXECUTABLE} MATCHES "ruby1\\.?9") - set(RUBY_VERSION_MAJOR 1) - set(RUBY_VERSION_MINOR 9) + if(${Ruby_EXECUTABLE} MATCHES "ruby1\\.?9") + set(Ruby_VERSION_MAJOR 1) + set(Ruby_VERSION_MINOR 9) endif() # check whether we found 2.0.x - if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?0") - set(RUBY_VERSION_MAJOR 2) - set(RUBY_VERSION_MINOR 0) + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?0") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 0) endif() # check whether we found 2.1.x - if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?1") - set(RUBY_VERSION_MAJOR 2) - set(RUBY_VERSION_MINOR 1) + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?1") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 1) endif() # check whether we found 2.2.x - if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?2") - set(RUBY_VERSION_MAJOR 2) - set(RUBY_VERSION_MINOR 2) + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?2") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 2) endif() # check whether we found 2.3.x - if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?3") - set(RUBY_VERSION_MAJOR 2) - set(RUBY_VERSION_MINOR 3) + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?3") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 3) endif() # check whether we found 2.4.x - if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?4") - set(RUBY_VERSION_MAJOR 2) - set(RUBY_VERSION_MINOR 4) + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?4") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 4) + endif() + # check whether we found 2.5.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?5") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 5) + endif() + # check whether we found 2.6.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?6") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 6) + endif() + # check whether we found 2.7.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?7") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 7) endif() endif() -if(RUBY_VERSION_MAJOR) - set(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}") - set(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}") - set(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}") - set(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}") +if(Ruby_VERSION_MAJOR) + set(Ruby_VERSION "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}.${Ruby_VERSION_PATCH}") + set(_Ruby_VERSION_SHORT "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}") + set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}") + set(_Ruby_NODOT_VERSION "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}") endif() -find_path(RUBY_INCLUDE_DIR +# FIXME: Currently we require both the interpreter and development components to be found +# in order to use either. See issue #20474. +find_path(Ruby_INCLUDE_DIR NAMES ruby.h HINTS - ${RUBY_HDR_DIR} - ${RUBY_ARCH_DIR} - /usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ + ${Ruby_HDR_DIR} + ${Ruby_ARCH_DIR} + /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/ ) -set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} ) +set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR}) # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir -if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR) - find_path(RUBY_CONFIG_INCLUDE_DIR +if( Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR) + find_path(Ruby_CONFIG_INCLUDE_DIR NAMES ruby/config.h config.h HINTS - ${RUBY_HDR_DIR}/${RUBY_ARCH} - ${RUBY_ARCH_DIR} - ${RUBY_ARCHHDR_DIR} + ${Ruby_HDR_DIR}/${Ruby_ARCH} + ${Ruby_ARCH_DIR} + ${Ruby_ARCHHDR_DIR} ) - set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} ) + set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIRS} ${Ruby_CONFIG_INCLUDE_DIR} ) endif() # Determine the list of possible names for the ruby library -set(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ruby${_RUBY_VERSION_SHORT_NODOT} ruby-${_RUBY_VERSION_SHORT} ruby-${RUBY_VERSION}) +set(_Ruby_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_Ruby_VERSION_SHORT} ruby${_Ruby_VERSION_SHORT_NODOT} ruby-${_Ruby_VERSION_SHORT} ruby-${Ruby_VERSION}) if(WIN32) - set( _RUBY_MSVC_RUNTIME "" ) - if( MSVC_VERSION EQUAL 1200 ) - set( _RUBY_MSVC_RUNTIME "60" ) - endif() - if( MSVC_VERSION EQUAL 1300 ) - set( _RUBY_MSVC_RUNTIME "70" ) - endif() - if( MSVC_VERSION EQUAL 1310 ) - set( _RUBY_MSVC_RUNTIME "71" ) - endif() - if( MSVC_VERSION EQUAL 1400 ) - set( _RUBY_MSVC_RUNTIME "80" ) - endif() - if( MSVC_VERSION EQUAL 1500 ) - set( _RUBY_MSVC_RUNTIME "90" ) + if(MSVC_TOOLSET_VERSION) + set(_Ruby_MSVC_RUNTIME "${MSVC_TOOLSET_VERSION}") + else() + set(_Ruby_MSVC_RUNTIME "") endif() - set(_RUBY_ARCH_PREFIX "") + set(_Ruby_ARCH_PREFIX "") if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_RUBY_ARCH_PREFIX "x64-") + set(_Ruby_ARCH_PREFIX "x64-") endif() - list(APPEND _RUBY_POSSIBLE_LIB_NAMES - "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}" - "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static" - "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}" - "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}-static" ) + list(APPEND _Ruby_POSSIBLE_LIB_NAMES + "${_Ruby_ARCH_PREFIX}msvcr${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_NODOT_VERSION}" + "${_Ruby_ARCH_PREFIX}msvcr${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_NODOT_VERSION}-static" + "${_Ruby_ARCH_PREFIX}msvcrt-ruby${_Ruby_NODOT_VERSION}" + "${_Ruby_ARCH_PREFIX}msvcrt-ruby${_Ruby_NODOT_VERSION}-static" ) endif() -find_library(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} ) +find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${Ruby_POSSIBLE_LIB_DIR} ) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -set(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY) -if(_RUBY_VERSION_SHORT_NODOT GREATER 18) - list(APPEND _RUBY_REQUIRED_VARS RUBY_CONFIG_INCLUDE_DIR) +set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY) +if(_Ruby_VERSION_SHORT_NODOT GREATER 18) + list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR) endif() -if(_RUBY_DEBUG_OUTPUT) +if(_Ruby_DEBUG_OUTPUT) message(STATUS "--------FindRuby.cmake debug------------") - message(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}") - message(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}") - message(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}") - message(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}") - message(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}") - message(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"") - message(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}") - message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}") - message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}") - message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}") - message(STATUS "RUBY_CONFIG_INCLUDE_DIR: ${RUBY_CONFIG_INCLUDE_DIR}") + message(STATUS "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}") + message(STATUS "_Ruby_POSSIBLE_LIB_NAMES: ${_Ruby_POSSIBLE_LIB_NAMES}") + message(STATUS "Ruby_ARCH_DIR: ${Ruby_ARCH_DIR}") + message(STATUS "Ruby_HDR_DIR: ${Ruby_HDR_DIR}") + message(STATUS "Ruby_POSSIBLE_LIB_DIR: ${Ruby_POSSIBLE_LIB_DIR}") + message(STATUS "Found Ruby_VERSION: \"${Ruby_VERSION}\" , short: \"${_Ruby_VERSION_SHORT}\", nodot: \"${_Ruby_VERSION_SHORT_NODOT}\"") + message(STATUS "_Ruby_REQUIRED_VARS: ${_Ruby_REQUIRED_VARS}") + message(STATUS "Ruby_EXECUTABLE: ${Ruby_EXECUTABLE}") + message(STATUS "Ruby_LIBRARY: ${Ruby_LIBRARY}") + message(STATUS "Ruby_INCLUDE_DIR: ${Ruby_INCLUDE_DIR}") + message(STATUS "Ruby_CONFIG_INCLUDE_DIR: ${Ruby_CONFIG_INCLUDE_DIR}") message(STATUS "--------------------") endif() -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_RUBY_REQUIRED_VARS} - VERSION_VAR RUBY_VERSION ) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS} + VERSION_VAR Ruby_VERSION ) + +if(Ruby_FOUND) + set(Ruby_LIBRARIES ${Ruby_LIBRARY}) +endif() mark_as_advanced( - RUBY_EXECUTABLE - RUBY_LIBRARY - RUBY_INCLUDE_DIR - RUBY_CONFIG_INCLUDE_DIR + Ruby_EXECUTABLE + Ruby_LIBRARY + Ruby_INCLUDE_DIR + Ruby_CONFIG_INCLUDE_DIR ) -# Set some variables for compatibility with previous version of this file -set(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR}) -set(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR}) -set(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS}) +# Set some variables for compatibility with previous version of this file (no need to provide a CamelCase version of that...) +set(RUBY_POSSIBLE_LIB_PATH ${Ruby_POSSIBLE_LIB_DIR}) +set(RUBY_RUBY_LIB_PATH ${Ruby_RUBY_LIB_DIR}) +set(RUBY_INCLUDE_PATH ${Ruby_INCLUDE_DIRS}) + +# Backwards compatibility +# Define upper case versions of output variables +foreach(Camel + Ruby_EXECUTABLE + Ruby_INCLUDE_DIRS + Ruby_LIBRARY + Ruby_VERSION + Ruby_VERSION_MAJOR + Ruby_VERSION_MINOR + Ruby_VERSION_PATCH + Ruby_INCLUDE_PATH + + Ruby_ARCH_DIR + Ruby_ARCH + Ruby_HDR_DIR + Ruby_ARCHHDR_DIR + Ruby_POSSIBLE_LIB_DIR + Ruby_RUBY_LIB_DIR + Ruby_SITEARCH_DIR + Ruby_SITELIB_DIR + Ruby_HAS_VENDOR_RUBY + Ruby_VENDORARCH_DIR + + ) + string(TOUPPER ${Camel} UPPER) + set(${UPPER} ${${Camel}}) +endforeach() diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake index ae6ae56..2fded49 100644 --- a/Modules/FindSWIG.cmake +++ b/Modules/FindSWIG.cmake @@ -5,25 +5,49 @@ FindSWIG -------- -Find Simplified Wrapper and Interface Generator (SWIG) +Find the Simplified Wrapper and Interface Generator (SWIG_) executable. -This module finds an installed SWIG. It sets the following variables: - -:: - - SWIG_FOUND - set to "True" if SWIG is found - SWIG_DIR - the directory where swig is installed - SWIG_EXECUTABLE - the path to the swig executable - SWIG_VERSION - the version number of the swig executable +This module finds an installed SWIG and determines its version. If a +``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to ``find_package``, +it will also determine supported target languages. The module sents the +following variables: +``SWIG_FOUND`` + Whether SWIG and any required components were found on the system. +``SWIG_EXECUTABLE`` + Path to the SWIG executable. +``SWIG_DIR`` + Path to the installed SWIG ``Lib`` directory (result of ``swig -swiglib``). +``SWIG_VERSION`` + SWIG executable version (result of ``swig -version``). +``SWIG_<lang>_FOUND`` + If ``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` are requested, each available + target language ``<lang>`` (lowercase) will be set to TRUE. -The minimum required version of SWIG can be specified using the -standard syntax, e.g. :command:`find_package(SWIG 1.1)` +Any ``COMPONENTS`` given to ``find_package`` should be the names of supported +target languages as provided to the LANGUAGE argument of ``swig_add_library``, +such as ``python`` or ``perl5``. Language names *must* be lowercase. All information is collected from the ``SWIG_EXECUTABLE``, so the version to be found can be changed from the command line by means of setting -``SWIG_EXECUTABLE`` +``SWIG_EXECUTABLE``. + +Example usage requiring SWIG 4.0 or higher and Python language support, with +optional Fortran support: + +.. code-block:: cmake + + find_package(SWIG 4.0 COMPONENTS python OPTIONAL_COMPONENTS fortran) + if(SWIG_FOUND) + message("SWIG found: ${SWIG_EXECUTABLE}") + if(NOT SWIG_fortran_FOUND) + message(WARNING "SWIG Fortran bindings cannot be generated") + endif() + endif() + +.. _`SWIG`: http://swig.org + #]=======================================================================] find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig) @@ -58,10 +82,29 @@ if(SWIG_EXECUTABLE) endif() endif() endif() + + if(SWIG_FIND_COMPONENTS) + execute_process(COMMAND ${SWIG_EXECUTABLE} -help + OUTPUT_VARIABLE SWIG_swighelp_output + ERROR_VARIABLE SWIG_swighelp_error + RESULT_VARIABLE SWIG_swighelp_result) + if(SWIG_swighelp_result) + message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -help\" failed with output:\n${SWIG_swiglib_error}") + else() + string(REPLACE "\n" ";" SWIG_swighelp_output "${SWIG_swighelp_output}") + foreach(SWIG_line IN LISTS SWIG_swighelp_output) + if(SWIG_line MATCHES "-([A-Za-z0-9_]+) +- *Generate.*wrappers") + set(SWIG_${CMAKE_MATCH_1}_FOUND TRUE) + endif() + endforeach() + endif() + endif() endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR - VERSION_VAR SWIG_VERSION ) +find_package_handle_standard_args( + SWIG HANDLE_COMPONENTS + REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR + VERSION_VAR SWIG_VERSION) mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE) diff --git a/Modules/FindSquish.cmake b/Modules/FindSquish.cmake index 7d49505..91d1410 100644 --- a/Modules/FindSquish.cmake +++ b/Modules/FindSquish.cmake @@ -9,8 +9,7 @@ FindSquish -This module can be used to find Squish. Currently Squish versions 3 -and 4 are supported. +This module can be used to find Squish. :: @@ -39,12 +38,12 @@ and 4 are supported. -It provides the function squish_v4_add_test() for adding a squish test -to cmake using Squish 4.x: +It provides the function squish_add_test() for adding a squish test +to cmake using Squish >= 4.x: :: - squish_v4_add_test(cmakeTestName + squish_add_test(cmakeTestName AUT targetName SUITE suiteName TEST squishTestName [SETTINGSGROUP group] [PRE_COMMAND command] [POST_COMMAND command] ) @@ -66,8 +65,7 @@ The arguments have the following meaning: the name of the squish test, i.e. the name of the subdirectory of the test inside the suite directory. ``SETTINGSGROUP group`` - if specified, the given settings group will be used for executing the test. - If not specified, the groupname will be "CTest_<username>" + deprecated, this argument will be ignored. ``PRE_COMMAND command`` if specified, the given command will be executed before starting the squish test. ``POST_COMMAND command`` @@ -78,13 +76,12 @@ The arguments have the following meaning: :: enable_testing() - find_package(Squish 4.0) + find_package(Squish 6.5) if (SQUISH_FOUND) - squish_v4_add_test(myTestName + squish_add_test(myTestName AUT myApp SUITE ${CMAKE_SOURCE_DIR}/tests/mySuite TEST someSquishTest - SETTINGSGROUP myGroup ) endif () @@ -105,19 +102,12 @@ provided: :: enable_testing() - find_package(Squish) + find_package(Squish 3.0) if (SQUISH_FOUND) squish_v3_add_test(myTestName myApplication testCase envVars testWrapper) endif () - -macro SQUISH_ADD_TEST(testName applicationUnderTest testCase envVars -testWrapper) - -:: - - This is deprecated. Use SQUISH_V3_ADD_TEST() if you are using Squish 3.x instead. #]=======================================================================] set(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.") @@ -137,7 +127,8 @@ if(NOT SQUISH_INSTALL_DIR) string(REPLACE "//" "/" SQUISH_INSTALL_DIR_SEARCH "${SQUISH_INSTALL_DIR_SEARCH}") # Look for an installation - find_path(SQUISH_INSTALL_DIR bin/squishrunner + find_path(SQUISH_INSTALL_DIR + NAMES bin/squishrunner bin/squishrunner.exe HINTS # Look for an environment variable SQUISH_INSTALL_DIR. ENV SQUISH_INSTALL_DIR @@ -169,9 +160,9 @@ endif() set(SQUISH_VERSION) -set(SQUISH_VERSION_MAJOR ) -set(SQUISH_VERSION_MINOR ) -set(SQUISH_VERSION_PATCH ) +set(SQUISH_VERSION_MAJOR) +set(SQUISH_VERSION_MINOR) +set(SQUISH_VERSION_PATCH) # record if executables are set if(SQUISH_CLIENT_EXECUTABLE) @@ -203,8 +194,8 @@ find_package_handle_standard_args(Squish REQUIRED_VARS SQUISH_INSTALL_DIR SQUI set(_SQUISH_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}") -macro(SQUISH_V3_ADD_TEST testName testAUT testCase envVars testWraper) - if("${SQUISH_VERSION_MAJOR}" STREQUAL "4") +macro(squish_v3_add_test testName testAUT testCase envVars testWraper) + if("${SQUISH_VERSION_MAJOR}" STRGREATER "3") message(STATUS "Using squish_v3_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.") endif() @@ -227,16 +218,9 @@ macro(SQUISH_V3_ADD_TEST testName testAUT testCase envVars testWraper) endmacro() -macro(SQUISH_ADD_TEST) - message(STATUS "Using squish_add_test() is deprecated, use squish_v3_add_test() instead.") - squish_v3_add_test(${ARGV}) -endmacro() - - -function(SQUISH_V4_ADD_TEST testName) - - if(NOT "${SQUISH_VERSION_MAJOR}" STREQUAL "4") - message(STATUS "Using squish_v4_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.") +function(squish_v4_add_test testName) + if(NOT "${SQUISH_VERSION_MAJOR}" STRGREATER "3") + message(STATUS "Using squish_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.") endif() set(oneValueArgs AUT SUITE TEST SETTINGSGROUP PRE_COMMAND POST_COMMAND) @@ -259,10 +243,6 @@ function(SQUISH_V4_ADD_TEST testName) message(FATAL_ERROR "Required argument TEST not given for SQUISH_ADD_TEST()") endif() - get_target_property(testAUTLocation ${_SQUISH_AUT} LOCATION) - get_filename_component(testAUTDir ${testAUTLocation} PATH) - get_filename_component(testAUTName ${testAUTLocation} NAME) - get_filename_component(absTestSuite "${_SQUISH_SUITE}" ABSOLUTE) if(NOT EXISTS "${absTestSuite}") message(FATAL_ERROR "Could not find squish test suite ${_SQUISH_SUITE} (checked ${absTestSuite})") @@ -273,15 +253,15 @@ function(SQUISH_V4_ADD_TEST testName) message(FATAL_ERROR "Could not find squish testcase ${_SQUISH_TEST} (checked ${absTestCase})") endif() - if(NOT _SQUISH_SETTINGSGROUP) - set(_SQUISH_SETTINGSGROUP "CTest_$ENV{LOGNAME}") + if(_SQUISH_SETTINGSGROUP) + message("SETTINGSGROUP is deprecated and will be ignored.") endif() - add_test(${testName} - ${CMAKE_COMMAND} -V -VV + add_test(NAME ${testName} + COMMAND ${CMAKE_COMMAND} -V -VV "-Dsquish_version:STRING=4" - "-Dsquish_aut:STRING=${testAUTName}" - "-Dsquish_aut_dir:STRING=${testAUTDir}" + "-Dsquish_aut:STRING=$<TARGET_FILE_BASE_NAME:${_SQUISH_AUT}>" + "-Dsquish_aut_dir:STRING=$<TARGET_FILE_DIR:${_SQUISH_AUT}>" "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}" "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}" "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}" @@ -290,7 +270,6 @@ function(SQUISH_V4_ADD_TEST testName) "-Dsquish_env_vars:STRING=${envVars}" "-Dsquish_wrapper:STRING=${testWraper}" "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}" - "-Dsquish_settingsgroup:STRING=${_SQUISH_SETTINGSGROUP}" "-Dsquish_pre_command:STRING=${_SQUISH_PRE_COMMAND}" "-Dsquish_post_command:STRING=${_SQUISH_POST_COMMAND}" -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake" @@ -299,3 +278,11 @@ function(SQUISH_V4_ADD_TEST testName) PROPERTIES FAIL_REGULAR_EXPRESSION "FAIL;FAILED;ERROR;FATAL" ) endfunction() + +macro(squish_add_test) + if("${SQUISH_VERSION_MAJOR}" STRGREATER "3") + squish_v4_add_test(${ARGV}) + else() + squish_v3_add_test(${ARGV}) + endif() +endmacro() diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index f97e5c8..ee49867 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -238,8 +238,8 @@ if(THREADS_FOUND AND NOT TARGET Threads::Threads) if(THREADS_HAVE_PTHREAD_ARG) set_property(TARGET Threads::Threads - PROPERTY INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler -pthread>" - "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>") + PROPERTY INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:SHELL:-Xcompiler -pthread>" + "$<$<NOT:$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>>:-pthread>") endif() if(CMAKE_THREAD_LIBS_INIT) diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 55da55f..4b999b6 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -28,40 +28,46 @@ The module will also define two cache variables:: Vulkan_INCLUDE_DIR - the Vulkan include directory Vulkan_LIBRARY - the path to the Vulkan library +Hints +^^^^^ + +The ``VULKAN_SDK`` environment variable optionally specifies the +location of the Vulkan SDK root directory for the given +architecture. It is typically set by sourcing the toplevel +``setup-env.sh`` script of the Vulkan SDK directory into the shell +environment. + #]=======================================================================] if(WIN32) find_path(Vulkan_INCLUDE_DIR NAMES vulkan/vulkan.h - PATHS + HINTS "$ENV{VULKAN_SDK}/Include" ) if(CMAKE_SIZEOF_VOID_P EQUAL 8) find_library(Vulkan_LIBRARY NAMES vulkan-1 - PATHS + HINTS "$ENV{VULKAN_SDK}/Lib" "$ENV{VULKAN_SDK}/Bin" - ) + ) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) find_library(Vulkan_LIBRARY NAMES vulkan-1 - PATHS + HINTS "$ENV{VULKAN_SDK}/Lib32" "$ENV{VULKAN_SDK}/Bin32" - NO_SYSTEM_ENVIRONMENT_PATH - ) + ) endif() else() - find_path(Vulkan_INCLUDE_DIR - NAMES vulkan/vulkan.h - PATHS - "$ENV{VULKAN_SDK}/include") - find_library(Vulkan_LIBRARY - NAMES vulkan - PATHS - "$ENV{VULKAN_SDK}/lib") + find_path(Vulkan_INCLUDE_DIR + NAMES vulkan/vulkan.h + HINTS "$ENV{VULKAN_SDK}/include") + find_library(Vulkan_LIBRARY + NAMES vulkan + HINTS "$ENV{VULKAN_SDK}/lib") endif() set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake index b28dd12..aa83575 100644 --- a/Modules/FindX11.cmake +++ b/Modules/FindX11.cmake @@ -25,6 +25,10 @@ and also the following more fine grained variables and targets: X11_Xaccessrules_INCLUDE_PATH, X11_Xaccessstr_INCLUDE_PATH, X11_Xaccess_FOUND X11_Xau_INCLUDE_PATH, X11_Xau_LIB, X11_Xau_FOUND, X11::Xau + X11_xcb_INCLUDE_PATH, X11_xcb_LIB, X11_xcb_FOUND, X11::xcb + X11_X11_xcb_INCLUDE_PATH, X11_X11_xcb_LIB, X11_X11_xcb_FOUND, X11::X11_xcb + X11_xcb_icccm_INCLUDE_PATH, X11_xcb_icccm_LIB, X11_xcb_icccm_FOUND, X11::xcb_icccm + X11_xcb_xkb_INCLUDE_PATH, X11_xcb_xkb_LIB, X11_xcb_xkb_FOUND, X11::xcb_xkb X11_Xcomposite_INCLUDE_PATH, X11_Xcomposite_LIB, X11_Xcomposite_FOUND, X11::Xcomposite X11_Xcursor_INCLUDE_PATH, X11_Xcursor_LIB, X11_Xcursor_FOUND, X11::Xcursor X11_Xdamage_INCLUDE_PATH, X11_Xdamage_LIB, X11_Xdamage_FOUND, X11::Xdamage @@ -38,6 +42,8 @@ and also the following more fine grained variables and targets: X11_Xinerama_INCLUDE_PATH, X11_Xinerama_LIB, X11_Xinerama_FOUND, X11::Xinerama X11_Xkb_INCLUDE_PATH, X11_Xkblib_INCLUDE_PATH, X11_Xkb_FOUND, X11::Xkb + X11_xkbcommon_INCLUDE_PATH, X11_xkbcommon_LIB, X11_xkbcommon_FOUND, X11::xkbcommon + X11_xkbcommon_X11_INCLUDE_PATH,X11_xkbcommon_X11_LIB,X11_xkbcommon_X11_FOUND,X11::xkbcommon_X11 X11_xkbfile_INCLUDE_PATH, X11_xkbfile_LIB, X11_xkbfile_FOUND, X11::xkbfile X11_Xmu_INCLUDE_PATH, X11_Xmu_LIB, X11_Xmu_FOUND, X11::Xmu X11_Xpm_INCLUDE_PATH, X11_Xpm_LIB, X11_Xpm_FOUND, X11::Xpm @@ -94,6 +100,9 @@ if (UNIX) find_path(X11_Xaccessrules_INCLUDE_PATH X11/extensions/XKBrules.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xaccessstr_INCLUDE_PATH X11/extensions/XKBstr.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xau_INCLUDE_PATH X11/Xauth.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xcb_INCLUDE_PATH xcb/xcb.h ${X11_INC_SEARCH_PATH}) + find_path(X11_X11_xcb_INCLUDE_PATH X11/Xlib-xcb.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xcb_icccm_INCLUDE_PATH xcb/xcb_icccm.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xcomposite_INCLUDE_PATH X11/extensions/Xcomposite.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xcursor_INCLUDE_PATH X11/Xcursor/Xcursor.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xdamage_INCLUDE_PATH X11/extensions/Xdamage.h ${X11_INC_SEARCH_PATH}) @@ -107,6 +116,8 @@ if (UNIX) find_path(X11_Xi_INCLUDE_PATH X11/extensions/XInput.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xinerama_INCLUDE_PATH X11/extensions/Xinerama.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xkb_INCLUDE_PATH X11/extensions/XKB.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xkbcommon_INCLUDE_PATH xkbcommon/xkbcommon.h ${X11_INC_SEARCH_PATH}) + find_path(X11_xkbcommon_X11_INCLUDE_PATH xkbcommon/xkbcommon-x11.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xkblib_INCLUDE_PATH X11/XKBlib.h ${X11_INC_SEARCH_PATH}) find_path(X11_xkbfile_INCLUDE_PATH X11/extensions/XKBfile.h ${X11_INC_SEARCH_PATH}) find_path(X11_Xmu_INCLUDE_PATH X11/Xmu/Xmu.h ${X11_INC_SEARCH_PATH}) @@ -137,6 +148,10 @@ if (UNIX) find_library(X11_ICE_LIB ICE ${X11_LIB_SEARCH_PATH}) find_library(X11_SM_LIB SM ${X11_LIB_SEARCH_PATH}) find_library(X11_Xau_LIB Xau ${X11_LIB_SEARCH_PATH}) + find_library(X11_xcb_LIB xcb ${X11_LIB_SEARCH_PATH}) + find_library(X11_X11_xcb_LIB X11-xcb ${X11_LIB_SEARCH_PATH}) + find_library(X11_xcb_icccm_LIB xcb-icccm ${X11_LIB_SEARCH_PATH}) + find_library(X11_xcb_xkb_LIB xcb-xkb ${X11_LIB_SEARCH_PATH}) find_library(X11_Xcomposite_LIB Xcomposite ${X11_LIB_SEARCH_PATH}) find_library(X11_Xcursor_LIB Xcursor ${X11_LIB_SEARCH_PATH}) find_library(X11_Xdamage_LIB Xdamage ${X11_LIB_SEARCH_PATH}) @@ -146,6 +161,8 @@ if (UNIX) find_library(X11_Xft_LIB Xft ${X11_LIB_SEARCH_PATH}) find_library(X11_Xi_LIB Xi ${X11_LIB_SEARCH_PATH}) find_library(X11_Xinerama_LIB Xinerama ${X11_LIB_SEARCH_PATH}) + find_library(X11_xkbcommon_LIB xkbcommon ${X11_LIB_SEARCH_PATH}) + find_library(X11_xkbcommon_X11_LIB xkbcommon-x11 ${X11_LIB_SEARCH_PATH}) find_library(X11_xkbfile_LIB xkbfile ${X11_LIB_SEARCH_PATH}) find_library(X11_Xmu_LIB Xmu ${X11_LIB_SEARCH_PATH}) find_library(X11_Xpm_LIB Xpm ${X11_LIB_SEARCH_PATH}) @@ -221,6 +238,22 @@ if (UNIX) set(X11_Xau_FOUND TRUE) endif () + if (X11_xcb_LIB AND X11_xcb_INCLUDE_PATH) + set(X11_xcb_FOUND TRUE) + endif () + + if (X11_X11_xcb_LIB AND X11_X11_xcb_INCLUDE_PATH) + set(X11_X11_xcb_FOUND TRUE) + endif () + + if (X11_xcb_icccm_LIB AND X11_xcb_icccm_INCLUDE_PATH) + set(X11_xcb_icccm_FOUND TRUE) + endif () + + if (X11_xcb_xkb_LIB) + set(X11_xcb_xkb_FOUND TRUE) + endif () + if (X11_Xdmcp_INCLUDE_PATH AND X11_Xdmcp_LIB) set(X11_Xdmcp_FOUND TRUE) list(APPEND X11_INCLUDE_DIR ${X11_Xdmcp_INCLUDE_PATH}) @@ -326,6 +359,14 @@ if (UNIX) list(APPEND X11_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH} ) endif () + if (X11_xkbcommon_INCLUDE_PATH AND X11_xkbcommon_LIB) + set(X11_xkbcommon_FOUND TRUE) + endif () + + if (X11_xkbcommon_X11_INCLUDE_PATH AND X11_xkbcommon_X11_LIB) + set(X11_xkbcommon_X11_FOUND TRUE) + endif () + if (X11_xkbfile_INCLUDE_PATH AND X11_xkbfile_LIB AND X11_Xlib_INCLUDE_PATH) set(X11_xkbfile_FOUND TRUE) # Backwards compatibility. @@ -478,6 +519,35 @@ if (UNIX) INTERFACE_INCLUDE_DIRECTORIES "${X11_Xau_INCLUDE_PATH}") endif () + if (X11_xcb_FOUND AND NOT TARGET X11::xcb) + add_library(X11::xcb UNKNOWN IMPORTED) + set_target_properties(X11::xcb PROPERTIES + IMPORTED_LOCATION "${X11_xcb_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${X11_xcb_INCLUDE_PATH}") + endif () + + if (X11_X11_xcb_FOUND AND NOT TARGET X11::X11_xcb) + add_library(X11::X11_xcb UNKNOWN IMPORTED) + set_target_properties(X11::X11_xcb PROPERTIES + IMPORTED_LOCATION "${X11_X11_xcb_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${X11_X11_xcb_INCLUDE_PATH}" + INTERFACE_LINK_LIBRARIES "X11::xcb;X11::X11") + endif () + + if (X11_xcb_icccm_FOUND AND NOT TARGET X11::xcb_icccm) + add_library(X11::xcb_icccm UNKNOWN IMPORTED) + set_target_properties(X11::xcb_icccm PROPERTIES + IMPORTED_LOCATION "${X11_xcb_icccm_LIB}" + INTERFACE_LINK_LIBRARIES "X11::xcb") + endif () + + if (X11_xcb_xkb_FOUND AND NOT TARGET X11::xcb_xkb) + add_library(X11::xcb_xkb UNKNOWN IMPORTED) + set_target_properties(X11::xcb_xkb PROPERTIES + IMPORTED_LOCATION "${X11_xcb_xkb_LIB}" + INTERFACE_LINK_LIBRARIES "X11::xcb") + endif () + if (X11_Xcomposite_FOUND AND NOT TARGET X11::Xcomposite) add_library(X11::Xcomposite UNKNOWN IMPORTED) set_target_properties(X11::Xcomposite PROPERTIES @@ -572,6 +642,21 @@ if (UNIX) INTERFACE_LINK_LIBRARIES "X11::X11") endif () + if (X11_xkbcommon_FOUND AND NOT TARGET X11::xkbcommon) + add_library(X11::xkbcommon UNKNOWN IMPORTED) + set_target_properties(X11::xkbcommon PROPERTIES + IMPORTED_LOCATION "${X11_xkbcommon_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${X11_xkbcommon_INCLUDE_PATH}") + endif () + + if (X11_xkbcommon_X11_FOUND AND NOT TARGET X11::xkbcommon_X11) + add_library(X11::xkbcommon_X11 UNKNOWN IMPORTED) + set_target_properties(X11::xkbcommon_X11 PROPERTIES + IMPORTED_LOCATION "${X11_xkbcommon_X11_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${X11_xkbcommon_X11_INCLUDE_PATH}" + INTERFACE_LINK_LIBRARIES "X11::X11;X11::xkbcommon") + endif () + if (X11_xkbfile_FOUND AND NOT TARGET X11::xkbfile) add_library(X11::xkbfile UNKNOWN IMPORTED) set_target_properties(X11::xkbfile PROPERTIES @@ -668,6 +753,11 @@ if (UNIX) X11_Xext_LIB X11_Xau_LIB X11_Xau_INCLUDE_PATH + X11_xcb_LIB + X11_xcb_INCLUDE_PATH + X11_xcb_xkb_LIB + X11_X11_xcb_LIB + X11_X11_xcb_INCLUDE_PATH X11_Xlib_INCLUDE_PATH X11_Xutil_INCLUDE_PATH X11_Xcomposite_INCLUDE_PATH @@ -704,6 +794,10 @@ if (UNIX) X11_Xdmcp_INCLUDE_PATH X11_Xkb_INCLUDE_PATH X11_Xkblib_INCLUDE_PATH + X11_xkbcommon_INCLUDE_PATH + X11_xkbcommon_LIB + X11_xkbcommon_X11_INCLUDE_PATH + X11_xkbcommon_X11_LIB X11_xkbfile_INCLUDE_PATH X11_xkbfile_LIB X11_Xmu_INCLUDE_PATH diff --git a/Modules/FindXercesC.cmake b/Modules/FindXercesC.cmake index 47bfd62..db78b61 100644 --- a/Modules/FindXercesC.cmake +++ b/Modules/FindXercesC.cmake @@ -81,10 +81,14 @@ endif() if(NOT XercesC_LIBRARY) # Find all XercesC libraries find_library(XercesC_LIBRARY_RELEASE - NAMES "xerces-c" "xerces-c_${XercesC_VERSION_MAJOR}" + NAMES "xerces-c" + "xerces-c_${XercesC_VERSION_MAJOR}" + "xerces-c-${XercesC_VERSION_MAJOR}.${XercesC_VERSION_MINOR}" DOC "Xerces-C++ libraries (release)") find_library(XercesC_LIBRARY_DEBUG - NAMES "xerces-cd" "xerces-c_${XercesC_VERSION_MAJOR}D" "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D" + NAMES "xerces-cd" + "xerces-c_${XercesC_VERSION_MAJOR}D" + "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D" DOC "Xerces-C++ libraries (debug)") include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(XercesC) diff --git a/Modules/FortranCInterface/CMakeLists.txt b/Modules/FortranCInterface/CMakeLists.txt index 381080b..13e4498 100644 --- a/Modules/FortranCInterface/CMakeLists.txt +++ b/Modules/FortranCInterface/CMakeLists.txt @@ -101,3 +101,7 @@ set_property(TARGET symbols PROPERTY POSITION_INDEPENDENT_CODE 1) # Require symbols through Fortran. add_executable(FortranCInterface main.F call_sub.f ${call_mod}) target_link_libraries(FortranCInterface PUBLIC symbols) + +file(GENERATE OUTPUT exe-$<CONFIG>.cmake CONTENT [[ +set(FortranCInterface_EXE "$<TARGET_FILE:FortranCInterface>") +]]) diff --git a/Modules/FortranCInterface/Detect.cmake b/Modules/FortranCInterface/Detect.cmake index 33de6c6..c75067b 100644 --- a/Modules/FortranCInterface/Detect.cmake +++ b/Modules/FortranCInterface/Detect.cmake @@ -43,17 +43,11 @@ set(FortranCInterface_COMPILED ${FortranCInterface_COMPILED}) unset(FortranCInterface_COMPILED CACHE) # Locate the sample project executable. +set(FortranCInterface_EXE) if(FortranCInterface_COMPILED) - find_program(FortranCInterface_EXE - NAMES FortranCInterface${CMAKE_EXECUTABLE_SUFFIX} - PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Release - NO_DEFAULT_PATH - ) - set(FortranCInterface_EXE ${FortranCInterface_EXE}) - unset(FortranCInterface_EXE CACHE) + include(${FortranCInterface_BINARY_DIR}/exe-Release.cmake OPTIONAL) else() set(_result "Failed to compile") - set(FortranCInterface_EXE) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Fortran/C interface test project failed with the following output:\n" "${FortranCInterface_OUTPUT}\n") diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index a5bb863..975ce6c 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -151,6 +151,8 @@ same as the Google Test name (i.e. ``suite.testcase``); see also [PROPERTIES name1 value1...] [TEST_LIST var] [DISCOVERY_TIMEOUT seconds] + [XML_OUTPUT_DIR dir] + [DISCOVERY_MODE <POST_BUILD|PRE_TEST>] ) ``gtest_discover_tests`` sets up a post-build command on the test executable @@ -236,6 +238,29 @@ same as the Google Test name (i.e. ``suite.testcase``); see also problem. The ambiguous behavior of the ``TIMEOUT`` keyword in 3.10.1 and 3.10.2 has not been preserved. + ``XML_OUTPUT_DIR dir`` + If specified, the parameter is passed along with ``--gtest_output=xml:`` + to test executable. The actual file name is the same as the test target, + including prefix and suffix. This should be used instead of + ``EXTRA_ARGS --gtest_output=xml`` to avoid race conditions writing the + XML result output when using parallel test execution. + + ``DISCOVERY_MODE`` + Provides greater control over when ``gtest_discover_tests``performs test + discovery. By default, ``POST_BUILD`` sets up a post-build command + to perform test discovery at build time. In certain scenarios, like + cross-compiling, this ``POST_BUILD`` behavior is not desirable. + By contrast, ``PRE_TEST`` delays test discovery until just prior to test + execution. This way test discovery occurs in the target environment + where the test has a better chance at finding appropriate runtime + dependencies. + + ``DISCOVERY_MODE`` defaults to the value of the + ``CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE`` variable if it is not + passed when calling ``gtest_discover_tests``. This provides a mechanism + for globally selecting a preferred test discovery behavior without having + to modify each call site. + #]=======================================================================] # Save project's policies @@ -368,11 +393,12 @@ function(gtest_add_tests) endfunction() #------------------------------------------------------------------------------ + function(gtest_discover_tests TARGET) cmake_parse_arguments( "" "NO_PRETTY_TYPES;NO_PRETTY_VALUES" - "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;DISCOVERY_TIMEOUT" + "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;DISCOVERY_TIMEOUT;XML_OUTPUT_DIR;DISCOVERY_MODE" "EXTRA_ARGS;PROPERTIES" ${ARGN} ) @@ -386,6 +412,12 @@ function(gtest_discover_tests TARGET) if(NOT _DISCOVERY_TIMEOUT) set(_DISCOVERY_TIMEOUT 5) endif() + if(NOT _DISCOVERY_MODE) + if(NOT CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE) + set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "POST_BUILD") + endif() + set(_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE}) + endif() get_property( has_counter @@ -417,34 +449,86 @@ function(gtest_discover_tests TARGET) TARGET ${TARGET} PROPERTY CROSSCOMPILING_EMULATOR ) - add_custom_command( - TARGET ${TARGET} POST_BUILD - BYPRODUCTS "${ctest_tests_file}" - COMMAND "${CMAKE_COMMAND}" - -D "TEST_TARGET=${TARGET}" - -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" - -D "TEST_EXECUTOR=${crosscompiling_emulator}" - -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" - -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" - -D "TEST_PROPERTIES=${_PROPERTIES}" - -D "TEST_PREFIX=${_TEST_PREFIX}" - -D "TEST_SUFFIX=${_TEST_SUFFIX}" - -D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}" - -D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}" - -D "TEST_LIST=${_TEST_LIST}" - -D "CTEST_FILE=${ctest_tests_file}" - -D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}" - -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}" - VERBATIM - ) - file(WRITE "${ctest_include_file}" - "if(EXISTS \"${ctest_tests_file}\")\n" - " include(\"${ctest_tests_file}\")\n" - "else()\n" - " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n" - "endif()\n" - ) + if(_DISCOVERY_MODE STREQUAL "POST_BUILD") + add_custom_command( + TARGET ${TARGET} POST_BUILD + BYPRODUCTS "${ctest_tests_file}" + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TARGET=${TARGET}" + -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" + -D "TEST_EXECUTOR=${crosscompiling_emulator}" + -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" + -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" + -D "TEST_PROPERTIES=${_PROPERTIES}" + -D "TEST_PREFIX=${_TEST_PREFIX}" + -D "TEST_SUFFIX=${_TEST_SUFFIX}" + -D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}" + -D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}" + -D "TEST_LIST=${_TEST_LIST}" + -D "CTEST_FILE=${ctest_tests_file}" + -D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}" + -D "TEST_XML_OUTPUT_DIR=${_XML_OUTPUT_DIR}" + -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}" + VERBATIM + ) + + file(WRITE "${ctest_include_file}" + "if(EXISTS \"${ctest_tests_file}\")\n" + " include(\"${ctest_tests_file}\")\n" + "else()\n" + " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n" + "endif()\n" + ) + elseif(_DISCOVERY_MODE STREQUAL "PRE_TEST") + + get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL + PROPERTY GENERATOR_IS_MULTI_CONFIG + ) + + if(GENERATOR_IS_MULTI_CONFIG) + set(ctest_tests_file "${ctest_file_base}_tests-$<CONFIG>.cmake") + endif() + + string(CONCAT ctest_include_content + "if(EXISTS \"$<TARGET_FILE:${TARGET}>\")" "\n" + " if(\"$<TARGET_FILE:${TARGET}>\" IS_NEWER_THAN \"${ctest_tests_file}\")" "\n" + " include(GoogleTestAddTests)" "\n" + " gtest_discover_tests_impl(" "\n" + " TEST_EXECUTABLE" " [==[" "$<TARGET_FILE:${TARGET}>" "]==]" "\n" + " TEST_EXECUTOR" " [==[" "${crosscompiling_emulator}" "]==]" "\n" + " TEST_WORKING_DIR" " [==[" "${_WORKING_DIRECTORY}" "]==]" "\n" + " TEST_EXTRA_ARGS" " [==[" "${_EXTRA_ARGS}" "]==]" "\n" + " TEST_PROPERTIES" " [==[" "${_PROPERTIES}" "]==]" "\n" + " TEST_PREFIX" " [==[" "${_TEST_PREFIX}" "]==]" "\n" + " TEST_SUFFIX" " [==[" "${_TEST_SUFFIX}" "]==]" "\n" + " NO_PRETTY_TYPES" " [==[" "${_NO_PRETTY_TYPES}" "]==]" "\n" + " NO_PRETTY_VALUES" " [==[" "${_NO_PRETTY_VALUES}" "]==]" "\n" + " TEST_LIST" " [==[" "${_TEST_LIST}" "]==]" "\n" + " CTEST_FILE" " [==[" "${ctest_tests_file}" "]==]" "\n" + " TEST_DISCOVERY_TIMEOUT" " [==[" "${_DISCOVERY_TIMEOUT}" "]==]" "\n" + " TEST_XML_OUTPUT_DIR" " [==[" "${_XML_OUTPUT_DIR}" "]==]" "\n" + " )" "\n" + " endif()" "\n" + " include(\"${ctest_tests_file}\")" "\n" + "else()" "\n" + " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)" "\n" + "endif()" "\n" + ) + + if(GENERATOR_IS_MULTI_CONFIG) + foreach(_config ${CMAKE_CONFIGURATION_TYPES}) + file(GENERATE OUTPUT "${ctest_file_base}_include-${_config}.cmake" CONTENT "${ctest_include_content}" CONDITION $<CONFIG:${_config}>) + endforeach() + file(WRITE "${ctest_include_file}" "include(\"${ctest_file_base}_include-\${CTEST_CONFIGURATION_TYPE}.cmake\")") + else() + file(GENERATE OUTPUT "${ctest_file_base}_include.cmake" CONTENT "${ctest_include_content}") + file(WRITE "${ctest_include_file}" "include(\"${ctest_file_base}_include.cmake\")") + endif() + + else() + message(SEND_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}") + endif() # Add discovered tests to directory TEST_INCLUDE_FILES set_property(DIRECTORY diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake index 4abbbec..4af62ed 100644 --- a/Modules/GoogleTestAddTests.cmake +++ b/Modules/GoogleTestAddTests.cmake @@ -1,106 +1,188 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -set(prefix "${TEST_PREFIX}") -set(suffix "${TEST_SUFFIX}") -set(extra_args ${TEST_EXTRA_ARGS}) -set(properties ${TEST_PROPERTIES}) -set(script) -set(suite) -set(tests) - -function(add_command NAME) +cmake_minimum_required(VERSION ${CMAKE_VERSION}) + +# Overwrite possibly existing ${_CTEST_FILE} with empty file +set(flush_tests_MODE WRITE) + +# Flushes script to ${_CTEST_FILE} +macro(flush_script) + file(${flush_tests_MODE} "${_CTEST_FILE}" "${script}") + set(flush_tests_MODE APPEND) + + set(script "") +endmacro() + +# Flushes tests_buffer to tests +macro(flush_tests_buffer) + list(APPEND tests "${tests_buffer}") + set(tests_buffer "") +endmacro() + +macro(add_command NAME) set(_args "") foreach(_arg ${ARGN}) if(_arg MATCHES "[^-./:a-zA-Z0-9_]") - set(_args "${_args} [==[${_arg}]==]") + string(APPEND _args " [==[${_arg}]==]") else() - set(_args "${_args} ${_arg}") + string(APPEND _args " ${_arg}") endif() endforeach() - set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) -endfunction() + string(APPEND script "${NAME}(${_args})\n") + string(LENGTH "${script}" _script_len) + if(${_script_len} GREATER "50000") + flush_script() + endif() + # Unsets macro local variables to prevent leakage outside of this macro. + unset(_args) + unset(_script_len) +endmacro() + +function(gtest_discover_tests_impl) -# Run test executable to get list of available tests -if(NOT EXISTS "${TEST_EXECUTABLE}") - message(FATAL_ERROR - "Specified test executable does not exist.\n" - " Path: '${TEST_EXECUTABLE}'" + cmake_parse_arguments( + "" + "" + "NO_PRETTY_TYPES;NO_PRETTY_VALUES;TEST_EXECUTABLE;TEST_EXECUTOR;TEST_WORKING_DIR;TEST_PREFIX;TEST_SUFFIX;TEST_LIST;CTEST_FILE;TEST_DISCOVERY_TIMEOUT;TEST_XML_OUTPUT_DIR" + "TEST_EXTRA_ARGS;TEST_PROPERTIES" + ${ARGN} ) -endif() -execute_process( - COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --gtest_list_tests - WORKING_DIRECTORY "${TEST_WORKING_DIR}" - TIMEOUT ${TEST_DISCOVERY_TIMEOUT} - OUTPUT_VARIABLE output - RESULT_VARIABLE result -) -if(NOT ${result} EQUAL 0) - string(REPLACE "\n" "\n " output "${output}") - message(FATAL_ERROR - "Error running test executable.\n" - " Path: '${TEST_EXECUTABLE}'\n" - " Result: ${result}\n" - " Output:\n" - " ${output}\n" + + set(prefix "${_TEST_PREFIX}") + set(suffix "${_TEST_SUFFIX}") + set(extra_args ${_TEST_EXTRA_ARGS}) + set(properties ${_TEST_PROPERTIES}) + set(script) + set(suite) + set(tests) + set(tests_buffer) + + # Run test executable to get list of available tests + if(NOT EXISTS "${_TEST_EXECUTABLE}") + message(FATAL_ERROR + "Specified test executable does not exist.\n" + " Path: '${_TEST_EXECUTABLE}'" + ) + endif() + execute_process( + COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" --gtest_list_tests + WORKING_DIRECTORY "${_TEST_WORKING_DIR}" + TIMEOUT ${_TEST_DISCOVERY_TIMEOUT} + OUTPUT_VARIABLE output + RESULT_VARIABLE result ) -endif() + if(NOT ${result} EQUAL 0) + string(REPLACE "\n" "\n " output "${output}") + message(FATAL_ERROR + "Error running test executable.\n" + " Path: '${_TEST_EXECUTABLE}'\n" + " Result: ${result}\n" + " Output:\n" + " ${output}\n" + ) + endif() -string(REPLACE "\n" ";" output "${output}") - -# Parse output -foreach(line ${output}) - # Skip header - if(NOT line MATCHES "gtest_main\\.cc") - # Do we have a module name or a test name? - if(NOT line MATCHES "^ ") - # Module; remove trailing '.' to get just the name... - string(REGEX REPLACE "\\.( *#.*)?" "" suite "${line}") - if(line MATCHES "#" AND NOT NO_PRETTY_TYPES) - string(REGEX REPLACE "/[0-9]\\.+ +#.*= +" "/" pretty_suite "${line}") - else() - set(pretty_suite "${suite}") - endif() - string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}") - else() - # Test name; strip spaces and comments to get just the name... - string(REGEX REPLACE " +" "" test "${line}") - if(test MATCHES "#" AND NOT NO_PRETTY_VALUES) - string(REGEX REPLACE "/[0-9]+#GetParam..=" "/" pretty_test "${test}") + # Preserve semicolon in test-parameters + string(REPLACE [[;]] [[\;]] output "${output}") + string(REPLACE "\n" ";" output "${output}") + + # Parse output + foreach(line ${output}) + # Skip header + if(NOT line MATCHES "gtest_main\\.cc") + # Do we have a module name or a test name? + if(NOT line MATCHES "^ ") + # Module; remove trailing '.' to get just the name... + string(REGEX REPLACE "\\.( *#.*)?" "" suite "${line}") + if(line MATCHES "#" AND NOT _NO_PRETTY_TYPES) + string(REGEX REPLACE "/[0-9]\\.+ +#.*= +" "/" pretty_suite "${line}") + else() + set(pretty_suite "${suite}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}") else() - string(REGEX REPLACE "#.*" "" pretty_test "${test}") - endif() - string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}") - string(REGEX REPLACE "#.*" "" test "${test}") - # ...and add to script - add_command(add_test - "${prefix}${pretty_suite}.${pretty_test}${suffix}" - ${TEST_EXECUTOR} - "${TEST_EXECUTABLE}" - "--gtest_filter=${suite}.${test}" - "--gtest_also_run_disabled_tests" - ${extra_args} - ) - if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED") + # Test name; strip spaces and comments to get just the name... + string(REGEX REPLACE " +" "" test "${line}") + if(test MATCHES "#" AND NOT _NO_PRETTY_VALUES) + string(REGEX REPLACE "/[0-9]+#GetParam..=" "/" pretty_test "${test}") + else() + string(REGEX REPLACE "#.*" "" pretty_test "${test}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}") + string(REGEX REPLACE "#.*" "" test "${test}") + if(NOT "${_TEST_XML_OUTPUT_DIR}" STREQUAL "") + set(TEST_XML_OUTPUT_PARAM "--gtest_output=xml:${_TEST_XML_OUTPUT_DIR}/${prefix}${pretty_suite}.${pretty_test}${suffix}.xml") + else() + unset(TEST_XML_OUTPUT_PARAM) + endif() + + # sanitize test name for further processing downstream + set(testname "${prefix}${pretty_suite}.${pretty_test}${suffix}") + # escape \ + string(REPLACE [[\]] [[\\]] testname "${testname}") + # escape ; + string(REPLACE [[;]] [[\;]] testname "${testname}") + # escape $ + string(REPLACE [[$]] [[\$]] testname "${testname}") + + # ...and add to script + add_command(add_test + "${testname}" + ${_TEST_EXECUTOR} + "${_TEST_EXECUTABLE}" + "--gtest_filter=${suite}.${test}" + "--gtest_also_run_disabled_tests" + ${TEST_XML_OUTPUT_PARAM} + ${extra_args} + ) + if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED") + add_command(set_tests_properties + "${testname}" + PROPERTIES DISABLED TRUE + ) + endif() add_command(set_tests_properties - "${prefix}${pretty_suite}.${pretty_test}${suffix}" - PROPERTIES DISABLED TRUE + "${testname}" + PROPERTIES + WORKING_DIRECTORY "${_TEST_WORKING_DIR}" + SKIP_REGULAR_EXPRESSION "\\\\[ SKIPPED \\\\]" + ${properties} ) + list(APPEND tests_buffer "${testname}") + list(LENGTH tests_buffer tests_buffer_length) + if(${tests_buffer_length} GREATER "250") + flush_tests_buffer() + endif() endif() - add_command(set_tests_properties - "${prefix}${pretty_suite}.${pretty_test}${suffix}" - PROPERTIES - WORKING_DIRECTORY "${TEST_WORKING_DIR}" - ${properties} - ) - list(APPEND tests "${prefix}${pretty_suite}.${pretty_test}${suffix}") endif() - endif() -endforeach() + endforeach() + -# Create a list of all discovered tests, which users may use to e.g. set -# properties on the tests -add_command(set ${TEST_LIST} ${tests}) + # Create a list of all discovered tests, which users may use to e.g. set + # properties on the tests + flush_tests_buffer() + add_command(set ${_TEST_LIST} ${tests}) -# Write CTest script -file(WRITE "${CTEST_FILE}" "${script}") + # Write CTest script + flush_script() + +endfunction() + +if(CMAKE_SCRIPT_MODE_FILE) + gtest_discover_tests_impl( + NO_PRETTY_TYPES ${NO_PRETTY_TYPES} + NO_PRETTY_VALUES ${NO_PRETTY_VALUES} + TEST_EXECUTABLE ${TEST_EXECUTABLE} + TEST_EXECUTOR ${TEST_EXECUTOR} + TEST_WORKING_DIR ${TEST_WORKING_DIR} + TEST_PREFIX ${TEST_PREFIX} + TEST_SUFFIX ${TEST_SUFFIX} + TEST_LIST ${TEST_LIST} + CTEST_FILE ${CTEST_FILE} + TEST_DISCOVERY_TIMEOUT ${TEST_DISCOVERY_TIMEOUT} + TEST_XML_OUTPUT_DIR ${TEST_XML_OUTPUT_DIR} + TEST_EXTRA_ARGS ${TEST_EXTRA_ARGS} + TEST_PROPERTIES ${TEST_PROPERTIES} + ) +endif() diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 14bb104..db35e3a 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -83,6 +83,16 @@ function(cpack_deb_format_package_description TEXT OUTPUT_VAR) string(REPLACE "\n" ";" _lines "${_text}") list(POP_FRONT _lines _summary) + # If the description ends with a newline (e.g. typically if it was read + # from a file) the last line will be empty. We drop it here, otherwise + # it would be replaced by a `.` which would lead to the package violating + # the extended-description-contains-empty-paragraph debian policy + list(POP_BACK _lines _last_line) + string(STRIP "${_last_line}" _last_line_strip) + if(_last_line_strip) + list(APPEND _lines "${_last_line_strip}") + endif() + # Check if reformatting required cpack_deb_check_description("${_summary}" "${_lines}" _result) if(_result) diff --git a/Modules/Internal/CPack/CPackNuGet.cmake b/Modules/Internal/CPack/CPackNuGet.cmake index 1f4bcfd..20eed2e 100644 --- a/Modules/Internal/CPack/CPackNuGet.cmake +++ b/Modules/Internal/CPack/CPackNuGet.cmake @@ -287,7 +287,11 @@ if(CPACK_NUGET_ORDINAL_MONOLITIC) execute_process( COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + RESULT_VARIABLE _nuget_result ) + if(NOT _nuget_result EQUAL 0) + message(FATAL_ERROR "Nuget pack failed") + endif() elseif(CPACK_NUGET_ALL_IN_ONE) # This variable `CPACK_NUGET_ALL_IN_ONE` set by C++ code: @@ -300,7 +304,11 @@ elseif(CPACK_NUGET_ALL_IN_ONE) execute_process( COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + RESULT_VARIABLE _nuget_result ) + if(NOT _nuget_result EQUAL 0) + message(FATAL_ERROR "Nuget pack failed") + endif() else() # Is there any grouped component? @@ -322,7 +330,11 @@ else() execute_process( COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + RESULT_VARIABLE _nuget_result ) + if(NOT _nuget_result EQUAL 0) + message(FATAL_ERROR "Nuget pack failed") + endif() endforeach() endif() # Is there any single component package needed? @@ -341,7 +353,11 @@ else() execute_process( COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + RESULT_VARIABLE _nuget_result ) + if(NOT _nuget_result EQUAL 0) + message(FATAL_ERROR "Nuget pack failed") + endif() endforeach() endif() endif() diff --git a/Modules/Internal/CPack/CPackRPM.cmake b/Modules/Internal/CPack/CPackRPM.cmake index 3485e7d..08bbc68 100644 --- a/Modules/Internal/CPack/CPackRPM.cmake +++ b/Modules/Internal/CPack/CPackRPM.cmake @@ -1099,16 +1099,18 @@ function(cpack_rpm_generate_package) # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE) # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE) - # May be used to embed a post (un)installation script in the spec file. + # CPACK_RPM_POST_TRANS_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_TRANS_SCRIPT_FILE) + # May be used to embed a post installation/uninstallation/transaction script in the spec file. # The referred script file(s) will be read and directly - # put after the %post or %postun section + # put after the %post or %postun or %posttrans section # ---------------------------------------------------------------- # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE) # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE) - # May be used to embed a pre (un)installation script in the spec file. + # CPACK_RPM_PRE_TRANS_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_PRE_TRANS_SCRIPT_FILE) + # May be used to embed a pre installation/uninstallation/transaction script in the spec file. # The referred script file(s) will be read and directly - # put after the %pre or %preun section - foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL") + # put after the %pre or %preun or %pretrans section + foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL" "TRANS") foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST") set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE" "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}") @@ -1727,12 +1729,18 @@ mv %_topdir/tmpBBroot $RPM_BUILD_ROOT \@RPM_SYMLINK_POSTINSTALL\@ \@CPACK_RPM_SPEC_POSTINSTALL\@ +%posttrans +\@CPACK_RPM_SPEC_POSTTRANS\@ + %postun \@CPACK_RPM_SPEC_POSTUNINSTALL\@ %pre \@CPACK_RPM_SPEC_PREINSTALL\@ +%pretrans +\@CPACK_RPM_SPEC_PRETRANS\@ + %preun \@CPACK_RPM_SPEC_PREUNINSTALL\@ diff --git a/Modules/Internal/CPack/NSIS.template.in b/Modules/Internal/CPack/NSIS.template.in index 660bfa3..6009ce0 100644 --- a/Modules/Internal/CPack/NSIS.template.in +++ b/Modules/Internal/CPack/NSIS.template.in @@ -41,6 +41,7 @@ RequestExecutionLevel admin @CPACK_NSIS_DEFINES@ +@CPACK_NSIS_MANIFEST_DPI_AWARE_CODE@ !include Sections.nsh diff --git a/Modules/Internal/CUDAToolkit.cmake b/Modules/Internal/CUDAToolkit.cmake new file mode 100644 index 0000000..291bb01 --- /dev/null +++ b/Modules/Internal/CUDAToolkit.cmake @@ -0,0 +1,227 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# This file is for sharing code for finding basic CUDA toolkit information between +# CMakeDetermineCUDACompiler.cmake and FindCUDAToolkit.cmake. + +# For NVCC we can easily deduce the SDK binary directory from the compiler path. +if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + get_filename_component(cuda_dir "${CMAKE_CUDA_COMPILER}" DIRECTORY) + set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "") + mark_as_advanced(CUDAToolkit_BIN_DIR) + unset(cuda_dir) +endif() + +# Try language- or user-provided path first. +if(CUDAToolkit_BIN_DIR) + find_program(CUDAToolkit_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ${CUDAToolkit_BIN_DIR} + NO_DEFAULT_PATH + ) +endif() + +# Search using CUDAToolkit_ROOT +find_program(CUDAToolkit_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ENV CUDA_PATH + PATH_SUFFIXES bin +) + +# If the user specified CUDAToolkit_ROOT but nvcc could not be found, this is an error. +if(NOT CUDAToolkit_NVCC_EXECUTABLE AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT})) + # Declare error messages now, print later depending on find_package args. + set(fail_base "Could not find nvcc executable in path specified by") + set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}") + set(env_cuda_root_fail "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}") + + if(CUDAToolkit_FIND_REQUIRED) + if(DEFINED CUDAToolkit_ROOT) + message(FATAL_ERROR ${cuda_root_fail}) + elseif(DEFINED ENV{CUDAToolkit_ROOT}) + message(FATAL_ERROR ${env_cuda_root_fail}) + endif() + else() + if(NOT CUDAToolkit_FIND_QUIETLY) + if(DEFINED CUDAToolkit_ROOT) + message(STATUS ${cuda_root_fail}) + elseif(DEFINED ENV{CUDAToolkit_ROOT}) + message(STATUS ${env_cuda_root_fail}) + endif() + endif() + set(CUDAToolkit_FOUND FALSE) + unset(fail_base) + unset(cuda_root_fail) + unset(env_cuda_root_fail) + return() + 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 CUDAToolkit_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(possible_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 possible_versions ${p_version}) + endif() + endforeach() + + # Cannot use list(SORT) because that is alphabetical, we need numerical. + # NOTE: this is not an efficient sorting strategy. But even if a user had + # every possible version of CUDA installed, this wouldn't create any + # significant overhead. + set(versions) + foreach (v ${possible_versions}) + list(LENGTH versions num_versions) + # First version, nothing to compare with so just append. + if(num_versions EQUAL 0) + list(APPEND versions ${v}) + else() + # Loop through list. Insert at an index when comparison is + # VERSION_GREATER since we want a descending list. Duplicates will not + # happen since this came from a glob list of directories. + set(i 0) + set(early_terminate FALSE) + while (i LESS num_versions) + list(GET versions ${i} curr) + if(v VERSION_GREATER curr) + list(INSERT versions ${i} ${v}) + set(early_terminate TRUE) + break() + endif() + math(EXPR i "${i} + 1") + endwhile() + # If it did not get inserted, place it at the end. + if(NOT early_terminate) + list(APPEND versions ${v}) + endif() + endif() + endforeach() + + # 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(CUDAToolkit_NVCC_EXECUTABLE + NAMES nvcc nvcc.exe + PATHS ${search_paths} + PATH_SUFFIXES bin + ) + + # We are done with these variables now, cleanup for caller. + unset(platform_base) + unset(possible_paths) + unset(possible_versions) + unset(versions) + unset(i) + unset(early_terminate) + unset(search_paths) + + if(NOT CUDAToolkit_NVCC_EXECUTABLE) + if(CUDAToolkit_FIND_REQUIRED) + message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.") + elseif(NOT CUDAToolkit_FIND_QUIETLY) + message(STATUS "Could not find nvcc, please set CUDAToolkit_ROOT.") + endif() + + set(CUDAToolkit_FOUND FALSE) + return() + endif() +endif() + +if(NOT CUDAToolkit_BIN_DIR AND CUDAToolkit_NVCC_EXECUTABLE) + get_filename_component(cuda_dir "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) + set(CUDAToolkit_BIN_DIR "${cuda_dir}" CACHE PATH "" FORCE) + mark_as_advanced(CUDAToolkit_BIN_DIR) + unset(cuda_dir) +endif() + +get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE) + +# Handle cross compilation +if(CMAKE_CROSSCOMPILING) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + # Support for NVPACK + set(CUDAToolkit_TARGET_NAME "armv7-linux-androideabi") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") + # Support for arm cross compilation + set(CUDAToolkit_TARGET_NAME "armv7-linux-gnueabihf") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # Support for aarch64 cross compilation + if(ANDROID_ARCH_NAME STREQUAL "arm64") + set(CUDAToolkit_TARGET_NAME "aarch64-linux-androideabi") + else() + set(CUDAToolkit_TARGET_NAME "aarch64-linux") + endif(ANDROID_ARCH_NAME STREQUAL "arm64") + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(CUDAToolkit_TARGET_NAME "x86_64-linux") + endif() + + if(EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}") + set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}") + # add known CUDA target root path to the set of directories we search for programs, libraries and headers + list(PREPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}") + + # Mark that we need to pop the root search path changes after we have + # found all cuda libraries so that searches for our cross-compilation + # libraries work when another cuda sdk is in CMAKE_PREFIX_PATH or + # PATh + set(_CUDAToolkit_Pop_ROOT_PATH True) + endif() +else() + # Not cross compiling + set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}") + # Now that we have the real ROOT_DIR, find components inside it. + list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR}) + + # Mark that we need to pop the prefix path changes after we have + # found the cudart library. + set(_CUDAToolkit_Pop_Prefix True) +endif() + +# Find the include/ directory +find_path(CUDAToolkit_INCLUDE_DIR + NAMES cuda_runtime.h +) + +# Find a tentative CUDAToolkit_LIBRARY_DIR. FindCUDAToolkit overrides it by searching for the CUDA runtime, +# but we can't do that here, as CMakeDetermineCUDACompiler wants to use it before the variables necessary +# for find_library() have been initialized. +if(EXISTS "${CUDAToolkit_TARGET_DIR}/lib64") + set(CUDAToolkit_LIBRARY_DIR "${CUDAToolkit_TARGET_DIR}/lib64") +elseif(EXISTS "${CUDAToolkit_TARGET_DIR}/lib/x64") + set(CUDAToolkit_LIBRARY_DIR "${CUDAToolkit_TARGET_DIR}/lib/x64") +elseif(EXISTS "${CUDAToolkit_TARGET_DIR}/lib") + set(CUDAToolkit_LIBRARY_DIR "${CUDAToolkit_TARGET_DIR}/lib") +endif() diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake index 1affcd0..581fde4 100644 --- a/Modules/Platform/Android-Common.cmake +++ b/Modules/Platform/Android-Common.cmake @@ -73,7 +73,7 @@ if(CMAKE_ANDROID_STL_TYPE) macro(__android_stl lang) # FIXME: Add a way to add project-wide language-specific compile-only flags. set(CMAKE_CXX_COMPILE_OBJECT - "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -nostdinc++") + "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -nostdinc++") string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -nostdlib++") endmacro() else() diff --git a/Modules/Platform/BlueGeneL.cmake b/Modules/Platform/BlueGeneL.cmake index 082e46c..0ed9975 100644 --- a/Modules/Platform/BlueGeneL.cmake +++ b/Modules/Platform/BlueGeneL.cmake @@ -23,18 +23,18 @@ include(Platform/UnixPaths) if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_LINK_EXECUTABLE - "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lgcc,-lc -lnss_files -lnss_dns -lresolv") + "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lgcc,-lc -lnss_files -lnss_dns -lresolv") else() # when using IBM xlc we probably don't want to link to -lgcc set(CMAKE_C_LINK_EXECUTABLE - "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lc -lnss_files -lnss_dns -lresolv") + "<CMAKE_C_COMPILER> -Wl,-relax <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lc -lnss_files -lnss_dns -lresolv") endif() if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lgcc,-lc -lnss_files -lnss_dns -lresolv") + "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lgcc,-lc -lnss_files -lnss_dns -lresolv") else() # when using the IBM xlC we probably don't want to link to -lgcc set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lc -lnss_files -lnss_dns -lresolv") + "<CMAKE_CXX_COMPILER> -Wl,-relax <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lc -lnss_files -lnss_dns -lresolv") endif() diff --git a/Modules/Platform/BlueGeneP-base.cmake b/Modules/Platform/BlueGeneP-base.cmake index fe95b42..7095dd8 100644 --- a/Modules/Platform/BlueGeneP-base.cmake +++ b/Modules/Platform/BlueGeneP-base.cmake @@ -97,7 +97,7 @@ macro(__BlueGeneP_set_dynamic_flags compiler_id lang) set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") # : or empty set(BGP_${lang}_DEFAULT_EXE_FLAGS - "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGP_${lang}_DYNAMIC_EXE_FLAGS} ${BGP_${lang}_DEFAULT_EXE_FLAGS}") endmacro() @@ -108,7 +108,7 @@ endmacro() # macro(__BlueGeneP_set_static_flags compiler_id lang) set(BGP_${lang}_DEFAULT_EXE_FLAGS - "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGP_${lang}_DEFAULT_EXE_FLAGS}") endmacro() diff --git a/Modules/Platform/BlueGeneQ-base.cmake b/Modules/Platform/BlueGeneQ-base.cmake index 5e56d8e..94cb0a8 100644 --- a/Modules/Platform/BlueGeneQ-base.cmake +++ b/Modules/Platform/BlueGeneQ-base.cmake @@ -101,7 +101,7 @@ macro(__BlueGeneQ_common_setup compiler_id lang) foreach(dir ${CMAKE_SYSTEM_INCLUDE_PATH}) string(APPEND BGQ_SYSTEM_INCLUDES " -I${dir}") endforeach() - set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${BGQ_SYSTEM_INCLUDES} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") + set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${BGQ_SYSTEM_INCLUDES} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${BGQ_SYSTEM_INCLUDES} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") # @@ -146,7 +146,7 @@ macro(__BlueGeneQ_setup_dynamic compiler_id lang) # For dynamic executables, need to provide special BG/Q arguments. set(BGQ_${lang}_DEFAULT_EXE_FLAGS - "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DYNAMIC_EXE_FLAGS} ${BGQ_${lang}_DEFAULT_EXE_FLAGS}") endmacro() @@ -160,7 +160,7 @@ macro(__BlueGeneQ_setup_static compiler_id lang) # For static executables, use default link settings. set(BGQ_${lang}_DEFAULT_EXE_FLAGS - "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DEFAULT_EXE_FLAGS}") endmacro() diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake index ca90712..4fa14ce 100644 --- a/Modules/Platform/CYGWIN-GNU.cmake +++ b/Modules/Platform/CYGWIN-GNU.cmake @@ -22,7 +22,7 @@ macro(__cygwin_compiler_gnu lang) set(CMAKE_${lang}_CREATE_SHARED_LIBRARY "<CMAKE_${lang}_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE - "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") # No -fPIC on cygwin set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "") diff --git a/Modules/Platform/DOS-OpenWatcom-C.cmake b/Modules/Platform/DOS-OpenWatcom-C.cmake new file mode 100644 index 0000000..cf71c84 --- /dev/null +++ b/Modules/Platform/DOS-OpenWatcom-C.cmake @@ -0,0 +1 @@ +include(Platform/DOS-OpenWatcom) diff --git a/Modules/Platform/DOS-OpenWatcom-CXX.cmake b/Modules/Platform/DOS-OpenWatcom-CXX.cmake new file mode 100644 index 0000000..cf71c84 --- /dev/null +++ b/Modules/Platform/DOS-OpenWatcom-CXX.cmake @@ -0,0 +1 @@ +include(Platform/DOS-OpenWatcom) diff --git a/Modules/Platform/DOS-OpenWatcom.cmake b/Modules/Platform/DOS-OpenWatcom.cmake new file mode 100644 index 0000000..54c452e --- /dev/null +++ b/Modules/Platform/DOS-OpenWatcom.cmake @@ -0,0 +1,28 @@ + +# This module is shared by multiple languages; use include blocker. +include_guard() + +set(CMAKE_BUILD_TYPE_INIT Debug) + +if(DEFINED CMAKE_SYSTEM_PROCESSOR AND CMAKE_SYSTEM_PROCESSOR STREQUAL "I86") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system dos") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system dos") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system dos") +else() + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system dos4g") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system dos4g") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system dos4g") +endif() + +set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list +set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string. + +string(APPEND CMAKE_C_FLAGS_INIT " -bt=dos") +string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=dos -xs") + +if(NOT CMAKE_C_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h) +endif() +if(NOT CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h) +endif() diff --git a/Modules/Platform/DOS.cmake b/Modules/Platform/DOS.cmake new file mode 100644 index 0000000..fc95936 --- /dev/null +++ b/Modules/Platform/DOS.cmake @@ -0,0 +1,14 @@ +set(DOS 1) + +set(CMAKE_STATIC_LIBRARY_PREFIX "") +set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") +set(CMAKE_SHARED_LIBRARY_PREFIX "") +set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") +set(CMAKE_IMPORT_LIBRARY_PREFIX "") +set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") +set(CMAKE_EXECUTABLE_SUFFIX ".exe") +set(CMAKE_LINK_LIBRARY_SUFFIX ".lib") +set(CMAKE_DL_LIBS "") + +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") diff --git a/Modules/Platform/HP-UX-HP-C.cmake b/Modules/Platform/HP-UX-HP-C.cmake index 7610383..57ba2eb 100644 --- a/Modules/Platform/HP-UX-HP-C.cmake +++ b/Modules/Platform/HP-UX-HP-C.cmake @@ -3,4 +3,4 @@ __hpux_compiler_hp(C) set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>") set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>") -set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> -Aa -Ae <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") +set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> -Aa -Ae <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") diff --git a/Modules/Platform/Linux-OpenWatcom-C.cmake b/Modules/Platform/Linux-OpenWatcom-C.cmake new file mode 100644 index 0000000..383349a --- /dev/null +++ b/Modules/Platform/Linux-OpenWatcom-C.cmake @@ -0,0 +1 @@ +include(Platform/Linux-OpenWatcom) diff --git a/Modules/Platform/Linux-OpenWatcom-CXX.cmake b/Modules/Platform/Linux-OpenWatcom-CXX.cmake new file mode 100644 index 0000000..383349a --- /dev/null +++ b/Modules/Platform/Linux-OpenWatcom-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Linux-OpenWatcom) diff --git a/Modules/Platform/Linux-OpenWatcom.cmake b/Modules/Platform/Linux-OpenWatcom.cmake new file mode 100644 index 0000000..5b4e995 --- /dev/null +++ b/Modules/Platform/Linux-OpenWatcom.cmake @@ -0,0 +1,25 @@ +# 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. +include_guard() + +set(CMAKE_BUILD_TYPE_INIT Debug) + +string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system linux opt noextension") +string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system linux") +string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system linux") + +# single/multi-threaded /-bm +# default is setup for single-threaded libraries +string(APPEND CMAKE_C_FLAGS_INIT " -bt=linux") +string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=linux -xs") + +if(CMAKE_CROSSCOMPILING) + if(NOT CMAKE_C_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/lh) + endif() + if(NOT CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/lh) + endif() +endif() diff --git a/Modules/Platform/Linux-como.cmake b/Modules/Platform/Linux-como.cmake index d1550d2..f6db34c 100644 --- a/Modules/Platform/Linux-como.cmake +++ b/Modules/Platform/Linux-como.cmake @@ -11,7 +11,7 @@ set(CMAKE_CXX_CREATE_STATIC_LIBRARY set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --prelink_objects <OBJECTS>" - "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "") diff --git a/Modules/Platform/OS2-OpenWatcom-C.cmake b/Modules/Platform/OS2-OpenWatcom-C.cmake new file mode 100644 index 0000000..21a4d9e --- /dev/null +++ b/Modules/Platform/OS2-OpenWatcom-C.cmake @@ -0,0 +1 @@ +include(Platform/OS2-OpenWatcom) diff --git a/Modules/Platform/OS2-OpenWatcom-CXX.cmake b/Modules/Platform/OS2-OpenWatcom-CXX.cmake new file mode 100644 index 0000000..21a4d9e --- /dev/null +++ b/Modules/Platform/OS2-OpenWatcom-CXX.cmake @@ -0,0 +1 @@ +include(Platform/OS2-OpenWatcom) diff --git a/Modules/Platform/OS2-OpenWatcom.cmake b/Modules/Platform/OS2-OpenWatcom.cmake new file mode 100644 index 0000000..998fb9f --- /dev/null +++ b/Modules/Platform/OS2-OpenWatcom.cmake @@ -0,0 +1,35 @@ +# This module is shared by multiple languages; use include blocker. +include_guard() + +set(CMAKE_BUILD_TYPE_INIT Debug) + +if(DEFINED CMAKE_SYSTEM_PROCESSOR AND CMAKE_SYSTEM_PROCESSOR STREQUAL "I86") + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system os2") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system os2_dll") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system os2_dll") +else() + string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system os2v2") + string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system os2v2_dll") + string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system os2v2_dll") +endif() + +set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list +set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string. + +string(APPEND CMAKE_C_FLAGS_INIT " -bt=os2") +string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=os2 -xs") + +if(NOT CMAKE_C_STANDARD_INCLUDE_DIRECTORIES) + if(DEFINED CMAKE_SYSTEM_PROCESSOR AND CMAKE_SYSTEM_PROCESSOR STREQUAL "I86") + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/os21x) + else() + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/os2) + endif() +endif() +if(NOT CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES) + if(DEFINED CMAKE_SYSTEM_PROCESSOR AND CMAKE_SYSTEM_PROCESSOR STREQUAL "I86") + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/os21x) + else() + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/os2) + endif() +endif() diff --git a/Modules/Platform/OS2.cmake b/Modules/Platform/OS2.cmake new file mode 100644 index 0000000..a9df66d --- /dev/null +++ b/Modules/Platform/OS2.cmake @@ -0,0 +1,14 @@ +set(OS2 1) + +set(CMAKE_STATIC_LIBRARY_PREFIX "") +set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") +set(CMAKE_SHARED_LIBRARY_PREFIX "") +set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") +set(CMAKE_IMPORT_LIBRARY_PREFIX "") +set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") +set(CMAKE_EXECUTABLE_SUFFIX ".exe") +set(CMAKE_LINK_LIBRARY_SUFFIX ".lib") +set(CMAKE_DL_LIBS "") + +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake index 97f744d..b9381c3 100644 --- a/Modules/Platform/UnixPaths.cmake +++ b/Modules/Platform/UnixPaths.cmake @@ -21,6 +21,10 @@ get_filename_component(_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH) # List common installation prefixes. These will be used for all # search types. +# +# Reminder when adding new locations computed from environment variables +# please make sure to keep Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst +# synchronized list(APPEND CMAKE_SYSTEM_PREFIX_PATH # Standard /usr/local /usr / @@ -86,6 +90,17 @@ set(_CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES_INIT unset(_cmake_sysroot_compile) +# Reminder when adding new locations computed from environment variables +# please make sure to keep Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst +# synchronized +if(CMAKE_COMPILER_SYSROOT) + list(PREPEND CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_COMPILER_SYSROOT}") + + if(DEFINED ENV{CONDA_PREFIX} AND EXISTS "$ENV{CONDA_PREFIX}") + list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{CONDA_PREFIX}") + endif() +endif() + # Enable use of lib32 and lib64 search path variants by default. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index a048698..dff8166 100644 --- a/Modules/Platform/Windows-Clang.cmake +++ b/Modules/Platform/Windows-Clang.cmake @@ -55,13 +55,13 @@ macro(__windows_compiler_clang_gnu lang) # Create archiving rules to support large object file lists for static libraries. set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") - set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") set(CMAKE_${lang}_CREATE_SHARED_LIBRARY "<CMAKE_${lang}_COMPILER> -fuse-ld=lld-link -nostartfiles -nostdlib <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <OBJECTS> <LINK_LIBRARIES>") set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY}) set(CMAKE_${lang}_LINK_EXECUTABLE - "<CMAKE_${lang}_COMPILER> -fuse-ld=lld-link -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") + "<CMAKE_${lang}_COMPILER> -fuse-ld=lld-link -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") if(NOT "${lang}" STREQUAL "ASM") set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -Xclang -flto-visibility-public-std -D_MT -Xclang --dependent-lib=libcmt) diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake index 38a8cf4..a2e3811 100644 --- a/Modules/Platform/Windows-GNU.cmake +++ b/Modules/Platform/Windows-GNU.cmake @@ -47,16 +47,12 @@ if("${_help}" MATCHES "GNU ld .* 2\\.1[1-6]") set(__WINDOWS_GNU_LD_RESPONSE 0) endif() -if(NOT CMAKE_GENERATOR_RC AND CMAKE_GENERATOR MATCHES "Unix Makefiles") - set(CMAKE_GENERATOR_RC windres) -endif() - macro(__windows_compiler_gnu lang) if(MSYS OR MINGW) # Create archiving rules to support large object file lists for static libraries. set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") - set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") # Initialize C link type selection flags. These flags are used when @@ -108,7 +104,7 @@ macro(__windows_compiler_gnu lang) set(CMAKE_${lang}_CREATE_SHARED_LIBRARY "<CMAKE_${lang}_COMPILER> <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>") set(CMAKE_${lang}_LINK_EXECUTABLE - "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") + "<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>") list(APPEND CMAKE_${lang}_ABI_FILES "Platform/Windows-GNU-${lang}-ABI") @@ -132,7 +128,7 @@ macro(__windows_compiler_gnu lang) endif() if(NOT CMAKE_RC_COMPILER_INIT AND NOT CMAKE_GENERATOR_RC) - set(CMAKE_RC_COMPILER_INIT windres) + set(CMAKE_RC_COMPILER_INIT ${_CMAKE_TOOLCHAIN_PREFIX}windres) endif() enable_language(RC) diff --git a/Modules/Platform/Windows-Intel.cmake b/Modules/Platform/Windows-Intel.cmake index 96b1760..5d8f7fc 100644 --- a/Modules/Platform/Windows-Intel.cmake +++ b/Modules/Platform/Windows-Intel.cmake @@ -11,7 +11,7 @@ set(__WINDOWS_INTEL 1) include(Platform/Windows-MSVC) macro(__windows_compiler_intel lang) __windows_compiler_msvc(${lang}) - string(REPLACE "<CMAKE_LINKER> /lib" "xilib" CMAKE_${lang}_CREATE_STATIC_LIBRARY "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}") + string(REPLACE "<CMAKE_AR>" "xilib" CMAKE_${lang}_CREATE_STATIC_LIBRARY "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}") foreach(rule CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE) string(REPLACE "<CMAKE_LINKER>" "xilink" CMAKE_${lang}_${rule} "${CMAKE_${lang}_${rule}}") endforeach() diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index e1d6733..2476a33 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -316,7 +316,7 @@ macro(__windows_compiler_msvc lang) "${_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}") set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY}) - set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <DEFINES> <INCLUDES> <FLAGS> /Fo<OBJECT> /Fd<TARGET_COMPILE_PDB>${_FS_${lang}} -c <SOURCE>${CMAKE_END_TEMP_FILE}") @@ -331,13 +331,11 @@ macro(__windows_compiler_msvc lang) set(CMAKE_PCH_EXTENSION .pch) set(CMAKE_LINK_PCH ON) - if(MSVC_VERSION GREATER_EQUAL 1910) - # VS 2017 or greater - if (NOT ${CMAKE_${lang}_COMPILER_ID} STREQUAL "Clang") - set(CMAKE_PCH_PROLOGUE "#pragma system_header") - else() - set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") - endif() + if (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang") + set(CMAKE_PCH_PROLOGUE "#pragma clang system_header") + elseif(MSVC_VERSION GREATER_EQUAL 1913) + # At least MSVC toolet 14.13 from VS 2017 15.6 + set(CMAKE_PCH_PROLOGUE "#pragma system_header") endif() if (NOT ${CMAKE_${lang}_COMPILER_ID} STREQUAL "Clang") set(CMAKE_PCH_COPY_COMPILE_PDB ON) diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake index f809094..a88f4bc 100644 --- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake +++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake @@ -1,11 +1,11 @@ include(Platform/Windows-MSVC) set(CMAKE_CUDA_COMPILE_PTX_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -ptx <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -ptx <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -dc <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -dc <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -c <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -c <SOURCE> -o <OBJECT> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS") set(__IMPLICT_LINKS ) foreach(dir ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}) @@ -23,7 +23,7 @@ set(CMAKE_CUDA_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>${__IMPLICT_LINKS} ${CMAKE_END_TEMP_FILE}") set(CMAKE_CUDA_CREATE_SHARED_MODULE ${CMAKE_CUDA_CREATE_SHARED_LIBRARY}) -set(CMAKE_CUDA_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") +set(CMAKE_CUDA_CREATE_STATIC_LIBRARY "<CMAKE_AR> ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ") set(CMAKE_CUDA_LINKER_SUPPORTS_PDB ON) set(CMAKE_CUDA_LINK_EXECUTABLE "${_CMAKE_VS_LINK_EXE}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR>${_PLATFORM_LINK_FLAGS} <LINK_FLAGS> <LINK_LIBRARIES>${__IMPLICT_LINKS} ${CMAKE_END_TEMP_FILE}") @@ -46,9 +46,9 @@ endforeach() unset(__IMPLICT_DLINK_DIRS) set(CMAKE_CUDA_DEVICE_LINK_LIBRARY - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") + "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS} <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}") unset(__IMPLICT_DLINK_FLAGS) string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}") @@ -69,11 +69,14 @@ else() endif() unset(_cmp0092) -set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC") 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) + list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl") +endif() + string(APPEND CMAKE_CUDA_FLAGS_INIT " ${PLATFORM_DEFINES_CUDA} -D_WINDOWS -Xcompiler=\"${_W3}${_FLAGS_CXX}\"") string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=\"${_MDd}-Zi -Ob0 -Od ${_RTC1}\"") string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=\"${_MD}-O2 -Ob2\" -DNDEBUG") diff --git a/Modules/Platform/Windows-OpenWatcom.cmake b/Modules/Platform/Windows-OpenWatcom.cmake index 76cd28b..70055da 100644 --- a/Modules/Platform/Windows-OpenWatcom.cmake +++ b/Modules/Platform/Windows-OpenWatcom.cmake @@ -1,129 +1,32 @@ # 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(__WINDOWS_OPENWATCOM) - return() -endif() -set(__WINDOWS_OPENWATCOM 1) - -set(CMAKE_LIBRARY_PATH_FLAG "libpath ") -set(CMAKE_LINK_LIBRARY_FLAG "library ") -set(CMAKE_LINK_LIBRARY_FILE_FLAG "library ") +include_guard() -if(CMAKE_VERBOSE_MAKEFILE) - set(CMAKE_WCL_QUIET) - set(CMAKE_WLINK_QUIET) - set(CMAKE_LIB_QUIET) -else() - set(CMAKE_WCL_QUIET "-zq") - set(CMAKE_WLINK_QUIET "option quiet") - set(CMAKE_LIB_QUIET "-q") -endif() +set(CMAKE_BUILD_TYPE_INIT Debug) -string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ") set(CMAKE_CREATE_WIN32_EXE "system nt_win" ) set(CMAKE_CREATE_CONSOLE_EXE "system nt" ) string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system nt_dll") string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system nt_dll") -foreach(type SHARED MODULE EXE) - string(APPEND CMAKE_${type}_LINKER_FLAGS_DEBUG_INIT " debug all opt map") - string(APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO_INIT " debug all opt map") -endforeach() set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string. set(CMAKE_RC_COMPILER "rc" ) -set(CMAKE_BUILD_TYPE_INIT Debug) - # single/multi-threaded /-bm # static/DLL run-time libraries /-br # default is setup for multi-threaded + DLL run-time libraries -string(APPEND CMAKE_C_FLAGS_INIT " -bt=nt -w3 -dWIN32 -br -bm") -string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=nt -xs -w3 -dWIN32 -br -bm") -foreach(lang C CXX) - string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -d2") - string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -s -os -d0 -dNDEBUG") - string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -s -ot -d0 -dNDEBUG") - string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -s -ot -d1 -dNDEBUG") -endforeach() - -foreach(type CREATE_SHARED_LIBRARY CREATE_SHARED_MODULE LINK_EXECUTABLE) - set(CMAKE_C_${type}_USE_WATCOM_QUOTE 1) - set(CMAKE_CXX_${type}_USE_WATCOM_QUOTE 1) -endforeach() - -set(CMAKE_C_CREATE_IMPORT_LIBRARY - "wlib -c -q -n -b <TARGET_IMPLIB> +<TARGET_QUOTED>") -set(CMAKE_CXX_CREATE_IMPORT_LIBRARY ${CMAKE_C_CREATE_IMPORT_LIBRARY}) - -set(CMAKE_C_LINK_EXECUTABLE - "wlink ${CMAKE_START_TEMP_FILE} ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> file {<OBJECTS>} <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") - - -set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE}) - -# compile a C++ file into an object file -set(CMAKE_CXX_COMPILE_OBJECT - "<CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<OBJECT> -c -cc++ <SOURCE>${CMAKE_END_TEMP_FILE}") - -# compile a C file into an object file -set(CMAKE_C_COMPILE_OBJECT - "<CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<OBJECT> -c -cc <SOURCE>${CMAKE_END_TEMP_FILE}") - -# preprocess a C source file -set(CMAKE_C_CREATE_PREPROCESSED_SOURCE - "<CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<PREPROCESSED_SOURCE> -pl -cc <SOURCE>${CMAKE_END_TEMP_FILE}") - -# preprocess a C++ source file -set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE - "<CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_WCL_QUIET} -d+ <DEFINES> <INCLUDES> <FLAGS> -fo<PREPROCESSED_SOURCE> -pl -cc++ <SOURCE>${CMAKE_END_TEMP_FILE}") - -set(CMAKE_CXX_CREATE_SHARED_LIBRARY - "wlink ${CMAKE_START_TEMP_FILE} ${CMAKE_WLINK_QUIET} name <TARGET> <LINK_FLAGS> option implib=<TARGET_IMPLIB> file {<OBJECTS>} <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") -string(REPLACE " option implib=<TARGET_IMPLIB>" "" - CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_LIBRARY}") - -# create a C shared library -set(CMAKE_C_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY}) - -# create a C shared module -set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_MODULE}) - -# create a C++ static library -set(CMAKE_CXX_CREATE_STATIC_LIBRARY "wlib ${CMAKE_LIB_QUIET} -c -n -b <TARGET_QUOTED> <LINK_FLAGS> <OBJECTS> ") - -# create a C static library -set(CMAKE_C_CREATE_STATIC_LIBRARY ${CMAKE_CXX_CREATE_STATIC_LIBRARY}) +string(APPEND CMAKE_C_FLAGS_INIT " -bt=nt -dWIN32 -br -bm") +string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=nt -xs -dWIN32 -br -bm") -if(NOT _CMAKE_WATCOM_VERSION) - set(_CMAKE_WATCOM_VERSION 1) - if(CMAKE_C_COMPILER_VERSION) - set(_compiler_version ${CMAKE_C_COMPILER_VERSION}) - set(_compiler_id ${CMAKE_C_COMPILER_ID}) - else() - set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION}) - set(_compiler_id ${CMAKE_CXX_COMPILER_ID}) +if(CMAKE_CROSSCOMPILING) + if(NOT CMAKE_C_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/nt) endif() - set(WATCOM16) - set(WATCOM17) - set(WATCOM18) - set(WATCOM19) - if("${_compiler_id}" STREQUAL "OpenWatcom") - if("${_compiler_version}" VERSION_LESS 1.7) - set(WATCOM16 1) - endif() - if("${_compiler_version}" VERSION_EQUAL 1.7) - set(WATCOM17 1) - endif() - if("${_compiler_version}" VERSION_EQUAL 1.8) - set(WATCOM18 1) - endif() - if("${_compiler_version}" VERSION_EQUAL 1.9) - set(WATCOM19 1) - endif() + if(NOT CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/nt) endif() endif() diff --git a/Modules/Platform/Windows-df.cmake b/Modules/Platform/Windows-df.cmake index f948914..8b824bc 100644 --- a/Modules/Platform/Windows-df.cmake +++ b/Modules/Platform/Windows-df.cmake @@ -13,7 +13,7 @@ endif() set(CMAKE_Fortran_MODDIR_FLAG "-module:") set(CMAKE_Fortran_CREATE_SHARED_LIBRARY - "link ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out:<TARGET> /dll <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") + "link ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out:<TARGET> /dll <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}") set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY}) @@ -22,7 +22,7 @@ set(CMAKE_Fortran_CREATE_STATIC_LIBRARY "lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /o # compile a C++ file into an object file set(CMAKE_Fortran_COMPILE_OBJECT - "<CMAKE_Fortran_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /object:<OBJECT> <FLAGS> /compile_only <SOURCE>${CMAKE_END_TEMP_FILE}") + "<CMAKE_Fortran_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /object:<OBJECT> <FLAGS> /compile_only <SOURCE>${CMAKE_END_TEMP_FILE}") set(CMAKE_Fortran_LINK_EXECUTABLE "<CMAKE_Fortran_COMPILER> ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} <FLAGS> /exe:<TARGET> <OBJECTS> /link <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}") diff --git a/Modules/Platform/WindowsPaths.cmake b/Modules/Platform/WindowsPaths.cmake index 71cc609..b9e2f17 100644 --- a/Modules/Platform/WindowsPaths.cmake +++ b/Modules/Platform/WindowsPaths.cmake @@ -24,6 +24,10 @@ set(__WINDOWS_PATHS_INCLUDED 1) # ENV{ProgramFiles(x86)} = [C:\Program Files (x86)] # ENV{ProgramFiles} = [C:\Program Files (x86)] # ENV{ProgramW6432} = [C:\Program Files] +# +# Reminder when adding new locations computed from environment variables +# please make sure to keep Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst +# synchronized set(_programfiles "") foreach(v "ProgramW6432" "ProgramFiles" "ProgramFiles(x86)") if(DEFINED "ENV{${v}}") diff --git a/Modules/Platform/eCos.cmake b/Modules/Platform/eCos.cmake index e1279ef..25db028 100644 --- a/Modules/Platform/eCos.cmake +++ b/Modules/Platform/eCos.cmake @@ -52,8 +52,8 @@ include_directories(${ECOS_SYSTEM_CONFIG_HEADER_PATH}) add_definitions(-D__ECOS__=1 -D__ECOS=1) # special link commands for eCos executables -set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>") -set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>") +set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>") +set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld <LINK_LIBRARIES>") # eCos doesn't support shared libs set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) diff --git a/Modules/Platform/gas.cmake b/Modules/Platform/gas.cmake index 7c659f2..8484076 100644 --- a/Modules/Platform/gas.cmake +++ b/Modules/Platform/gas.cmake @@ -11,7 +11,7 @@ set(CMAKE_ASM${ASM_DIALECT}_CREATE_STATIC_LIBRARY "<CMAKE_RANLIB> <TARGET> ") set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE - "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM${ASM_DIALECT}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") # to be done set(CMAKE_ASM${ASM_DIALECT}_CREATE_SHARED_LIBRARY) diff --git a/Modules/Squish4RunTestCase.bat b/Modules/Squish4RunTestCase.bat index ad1cc8c..fe303b8 100755 --- a/Modules/Squish4RunTestCase.bat +++ b/Modules/Squish4RunTestCase.bat @@ -4,7 +4,6 @@ set TESTSUITE=%3 set TESTCASE=%4 set AUT=%5 set AUTDIR=%6 -set SETTINGSGROUP=%7 %SQUISHSERVER% --stop @@ -12,9 +11,9 @@ echo "Adding AUT... %SQUISHSERVER% --config addAUT %AUT% %AUTDIR%" %SQUISHSERVER% --config addAUT "%AUT%" "%AUTDIR%" echo "Starting the squish server... %SQUISHSERVER%" -start /B %SQUISHSERVER% +start /B "Squish Server" %SQUISHSERVER% -echo "Running the test case...%SQUISHRUNNER% --testsuite %TESTSUITE% --testcase %TESTCASE%" +echo "Running the test case... %SQUISHRUNNER% --testsuite %TESTSUITE% --testcase %TESTCASE%" %SQUISHRUNNER% --testsuite "%TESTSUITE%" --testcase "%TESTCASE%" set returnValue=%ERRORLEVEL% diff --git a/Modules/Squish4RunTestCase.sh b/Modules/Squish4RunTestCase.sh index 39a3907..4d1e382 100755 --- a/Modules/Squish4RunTestCase.sh +++ b/Modules/Squish4RunTestCase.sh @@ -6,20 +6,19 @@ TESTSUITE=$3 TESTCASE=$4 AUT=$5 AUTDIR=$6 -SETTINGSGROUP=$7 $SQUISHSERVER --stop > /dev/null 2>&1 -echo "Adding AUT... $SQUISHSERVER --settingsGroup $SETTINGSGROUP --config addAUT $AUT $AUTDIR" -$SQUISHSERVER --settingsGroup "$SETTINGSGROUP" --config addAUT "$AUT" "$AUTDIR" || exit 255 +echo "Adding AUT... $SQUISHSERVER --config addAUT $AUT $AUTDIR" +$SQUISHSERVER --config addAUT "$AUT" "$AUTDIR" || exit 255 # sleep 1 echo "Starting the squish server... $SQUISHSERVER --daemon" $SQUISHSERVER --daemon || exit 255 # sleep 2 -echo "Running the test case...$SQUISHRUNNER --settingsGroup $SETTINGSGROUP --testsuite $TESTSUITE --testcase $TESTCASE" -$SQUISHRUNNER --settingsGroup "$SETTINGSGROUP" --testsuite "$TESTSUITE" --testcase "$TESTCASE" +echo "Running the test case... $SQUISHRUNNER --testsuite $TESTSUITE --testcase $TESTCASE" +$SQUISHRUNNER --testsuite "$TESTSUITE" --testcase "$TESTCASE" returnValue=$? echo "Stopping the squish server... $SQUISHSERVER --stop" diff --git a/Modules/SquishTestScript.cmake b/Modules/SquishTestScript.cmake index 2a80be5..b0cb4af 100644 --- a/Modules/SquishTestScript.cmake +++ b/Modules/SquishTestScript.cmake @@ -31,7 +31,6 @@ message(STATUS "squish_test_case='${squish_test_case}'") message(STATUS "squish_wrapper='${squish_wrapper}'") message(STATUS "squish_env_vars='${squish_env_vars}'") message(STATUS "squish_module_dir='${squish_module_dir}'") -message(STATUS "squish_settingsgroup='${squish_settingsgroup}'") message(STATUS "squish_pre_command='${squish_pre_command}'") message(STATUS "squish_post_command='${squish_post_command}'") @@ -57,10 +56,10 @@ endif() # run the test if("${squish_version}" STREQUAL "4") if (WIN32) - execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.bat ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} ${squish_settingsgroup} + execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.bat ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} RESULT_VARIABLE test_rv ) elseif(UNIX) - execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.sh ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} ${squish_settingsgroup} + execute_process(COMMAND ${squish_module_dir}/Squish4RunTestCase.sh ${squish_server_executable} ${squish_client_executable} ${squish_test_suite} ${squish_test_case} ${squish_aut} ${squish_aut_dir} RESULT_VARIABLE test_rv ) endif () diff --git a/Modules/UseEcos.cmake b/Modules/UseEcos.cmake index 60324b1..83c9b20 100644 --- a/Modules/UseEcos.cmake +++ b/Modules/UseEcos.cmake @@ -185,11 +185,11 @@ macro(ECOS_ADD_EXECUTABLE _exe_NAME ) # when using nmake makefiles, the custom buildtype suppresses the default cl.exe flags # and the rules for creating objects are adjusted for gcc set(CMAKE_BUILD_TYPE CUSTOM_ECOS_BUILD) - set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") + set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") # special link commands for ecos-executables - set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}") - set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}") + set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}") + set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}") # some strict compiler flags set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -fno-rtti -Wctor-dtor-privacy -fno-strict-aliasing -fno-exceptions") diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index b668b9e..db3fb95 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -377,7 +377,9 @@ function (__java_copy_file src dest comment) ARGS ${src} ${dest} DEPENDS ${src} - COMMENT ${comment}) + COMMENT ${comment} + VERBATIM + ) endfunction () function(__java_lcat VAR) @@ -597,7 +599,10 @@ function(add_jar _TARGET_NAME) # Create the list of files to compile. set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources) string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"") - file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING}) + set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_JAVA_COMPILE_STRING}") + configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" + "${_JAVA_SOURCES_FILE}" @ONLY) + unset(CMAKE_CONFIGURABLE_FILE_CONTENT) list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}") endif() if (_JAVA_COMPILE_FILELISTS) @@ -610,6 +615,10 @@ function(add_jar _TARGET_NAME) add_custom_command( # NOTE: this command generates an artificial dependency file OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + COMMAND ${CMAKE_COMMAND} + -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH} + -DCMAKE_JAR_CLASSES_PREFIX=${CMAKE_JAR_CLASSES_PREFIX} + -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/UseJava/ClearClassFiles.cmake COMMAND ${Java_JAVAC_EXECUTABLE} ${CMAKE_JAVA_COMPILE_FLAGS} -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}" @@ -617,18 +626,20 @@ function(add_jar _TARGET_NAME) ${_GENERATE_NATIVE_HEADERS} ${_JAVA_SOURCES_FILELISTS} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} - DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS} + DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS} ${_JAVA_SOURCES_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Building Java objects for ${_TARGET_NAME}.jar" + VERBATIM ) add_custom_command( OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist COMMAND ${CMAKE_COMMAND} -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH} - -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}" + -DCMAKE_JAR_CLASSES_PREFIX=${CMAKE_JAR_CLASSES_PREFIX} -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/UseJavaClassFilelist.cmake DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM ) else () # create an empty java_class_filelist @@ -659,6 +670,7 @@ function(add_jar _TARGET_NAME) DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + VERBATIM ) else () add_custom_command( @@ -674,6 +686,7 @@ function(add_jar _TARGET_NAME) WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + VERBATIM ) endif () diff --git a/Modules/UseJava/ClearClassFiles.cmake b/Modules/UseJava/ClearClassFiles.cmake new file mode 100644 index 0000000..f3115c6 --- /dev/null +++ b/Modules/UseJava/ClearClassFiles.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 script deletes compiled Java class files. + +if(CMAKE_JAVA_CLASS_OUTPUT_PATH) + if(EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist") + file(STRINGS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist" classes) + list(TRANSFORM classes PREPEND "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/") + if(classes) + file(REMOVE ${classes}) + message(STATUS "Clean class files from previous build") + endif() + endif() +else() + message(FATAL_ERROR "Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH") +endif() diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 78522da..f6a20f8 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -341,6 +341,23 @@ function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile) list(APPEND files "${extra_file}") endforeach() + if (language STREQUAL "FORTRAN" AND CMAKE_Fortran_COMPILER_LOADED) + # Process possible user-supplied extension in flags (obtained via parent + # scope variable) to determine the source file name. + list(FIND SWIG_COMPILATION_FLAGS "-fext" fext_idx) + if (fext_idx EQUAL -1) + # Default Fortran generated extension + set(fext "f90") + else() + # Get extension from user-provided flag + math(EXPR fext_idx "${fext_idx} + 1") + list(GET SWIG_COMPILATION_FLAGS "${fext_idx}" fext) + endif() + set(extra_file "${generatedpath}/${module_basename}.${fext}") + set_source_files_properties("${extra_file}" PROPERTIES LANGUAGE "Fortran") + list(APPEND files "${extra_file}") + endif() + set (${outfiles} ${files} PARENT_SCOPE) endfunction() @@ -415,6 +432,7 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE) if (NOT SWIG_MODULE_${name}_NOPROXY) + set(SWIG_COMPILATION_FLAGS ${swig_source_file_flags}) SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE} swig_extra_generated_files "${outdir}" @@ -787,6 +805,8 @@ function(SWIG_ADD_LIBRARY name) if (APPLE) set_target_properties (${target_name} PROPERTIES SUFFIX ".dylib") endif () + elseif (swig_lowercase_language STREQUAL "fortran") + # Do *not* override the target's library prefix else() # assume empty prefix because we expect the module to be dynamically loaded set_target_properties (${target_name} PROPERTIES PREFIX "") diff --git a/Modules/readme.txt b/Modules/readme.txt index a629478..da78730 100644 --- a/Modules/readme.txt +++ b/Modules/readme.txt @@ -1,4 +1,4 @@ See the "Find Modules" section of the cmake-developer(7) manual page. For more information about how to contribute modules to CMake, see this page: -https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/dev/Module-Maintainers +https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/dev/Module-Maintainers |