diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CheckPIESupported.cmake | 134 | ||||
-rw-r--r-- | Modules/Compiler/AppleClang-C.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/AppleClang-CXX.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/Clang.cmake | 20 | ||||
-rw-r--r-- | Modules/Compiler/GNU.cmake | 19 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-C.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-CXX.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-Fortran.cmake | 1 | ||||
-rw-r--r-- | Modules/ExternalProject.cmake | 51 | ||||
-rw-r--r-- | Modules/FindLibLZMA.cmake | 58 | ||||
-rw-r--r-- | Modules/Internal/CMakeCheckCompilerFlag.cmake | 26 | ||||
-rw-r--r-- | Modules/Platform/CYGWIN-GNU.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Fuchsia.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Linux-Intel.cmake | 2 | ||||
-rw-r--r-- | Modules/Platform/Linux-PGI.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/SINIX.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/UNIX_SV.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/UnixWare.cmake | 1 | ||||
-rw-r--r-- | Modules/Platform/Windows-GNU.cmake | 1 |
19 files changed, 261 insertions, 65 deletions
diff --git a/Modules/CheckPIESupported.cmake b/Modules/CheckPIESupported.cmake new file mode 100644 index 0000000..720217d --- /dev/null +++ b/Modules/CheckPIESupported.cmake @@ -0,0 +1,134 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +CheckPIESupported +----------------- + +Check whether the linker supports position independent code (PIE) or no +position independent code (NO_PIE) for executables. +Use this to ensure that the :prop_tgt:`POSITION_INDEPENDENT_CODE` target +property for executables will be honored at link time. + +.. command:: check_pie_supported + + :: + + check_pie_supported([OUTPUT_VARIABLE <output>] + [LANGUAGES <lang>...]) + + Options are: + + ``OUTPUT_VARIABLE <output>`` + Set ``<output>`` variable with details about any error. + ``LANGUAGES <lang>...`` + Check the linkers used for each of the specified languages. + Supported languages are ``C``, ``CXX``, and ``Fortran``. + +It makes no sense to use this module when :policy:`CMP0083` is set to ``OLD``, +so the command will return an error in this case. See policy :policy:`CMP0083` +for details. + +Variables +^^^^^^^^^ + +For each language checked, two boolean cache variables are defined. + + ``CMAKE_<lang>_LINK_PIE_SUPPORTED`` + Set to ``YES`` if ``PIE`` is supported by the linker and ``NO`` otherwise. + ``CMAKE_<lang>_LINK_NO_PIE_SUPPORTED`` + Set to ``YES`` if ``NO_PIE`` is supported by the linker and ``NO`` otherwise. + +Examples +^^^^^^^^ + +.. code-block:: cmake + + check_pie_supported() + set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) + +.. code-block:: cmake + + # Retrieve any error message. + check_pie_supported(OUTPUT_VARIABLE output LANGUAGES C) + set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE) + if(NOT CMAKE_C_LINK_PIE_SUPPORTED) + message(WARNING "PIE is not supported at link time: ${output}.\n" + "PIE link options will not be passed to linker.") + endif() + +#]=======================================================================] + + +include (Internal/CMakeCheckCompilerFlag) + +function (check_pie_supported) + cmake_policy(GET CMP0083 cmp0083) + + if (NOT cmp0083) + message(FATAL_ERROR "check_pie_supported: Policy CMP0083 is not set") + endif() + + if(cmp0083 STREQUAL "OLD") + message(FATAL_ERROR "check_pie_supported: Policy CMP0083 set to OLD") + endif() + + set(optional) + set(one OUTPUT_VARIABLE) + set(multiple LANGUAGES) + + cmake_parse_arguments(CHECK_PIE "${optional}" "${one}" "${multiple}" "${ARGN}") + if(CHECK_PIE_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "check_pie_supported: Unparsed arguments: ${CHECK_PIE_UNPARSED_ARGUMENTS}") + endif() + + if (CHECK_PIE_LANGUAGES) + set (unsupported_languages "${CHECK_PIE_LANGUAGES}") + list (REMOVE_ITEM unsupported_languages "C" "CXX" "Fortran") + if(unsupported_languages) + message(FATAL_ERROR "check_pie_supported: language(s) '${unsupported_languages}' not supported") + endif() + else() + # User did not set any languages, use defaults + get_property (enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT enabled_languages) + return() + endif() + + list (FILTER enabled_languages INCLUDE REGEX "^(C|CXX|Fortran)$") + if (NOT enabled_languages) + return() + endif() + + set (CHECK_PIE_LANGUAGES ${enabled_languages}) + endif() + + set (outputs) + + foreach(lang IN LISTS CHECK_PIE_LANGUAGES) + if(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER) + cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_LINK_OPTIONS_PIE}" + CMAKE_${lang}_LINK_PIE_SUPPORTED + OUTPUT_VARIABLE output) + if (NOT CMAKE_${lang}_LINK_PIE_SUPPORTED) + string (APPEND outputs "PIE (${lang}): ${output}\n") + endif() + + cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_LINK_OPTIONS_NO_PIE}" + CMAKE_${lang}_LINK_NO_PIE_SUPPORTED + OUTPUT_VARIABLE output) + if (NOT CMAKE_${lang}_LINK_NO_PIE_SUPPORTED) + string (APPEND outputs "NO_PIE (${lang}): ${output}\n") + endif() + else() + # no support at link time. Set cache variables to NO + set(CMAKE_${lang}_LINK_PIE_SUPPORTED NO CACHE INTERNAL "PIE (${lang})") + set(CMAKE_${lang}_LINK_NO_PIE_SUPPORTED NO CACHE INTERNAL "NO_PIE (${lang})") + string (APPEND outputs "PIE and NO_PIE are not supported by linker for ${lang}") + endif() + endforeach() + + if (CHECK_PIE_OUTPUT_VARIABLE) + set (${CHECK_PIE_OUTPUT_VARIABLE} "${outputs}" PARENT_SCOPE) + endif() +endfunction() diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake index 8754951..a48adec 100644 --- a/Modules/Compiler/AppleClang-C.cmake +++ b/Modules/Compiler/AppleClang-C.cmake @@ -1,9 +1,6 @@ include(Compiler/Clang) __compiler_clang(C) -set(CMAKE_C_LINK_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE} -Xlinker -pie) -set(CMAKE_C_LINK_OPTIONS_NO_PIE -Xlinker -no_pie) - if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90") set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90") diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake index 54c1388..e5fd647 100644 --- a/Modules/Compiler/AppleClang-CXX.cmake +++ b/Modules/Compiler/AppleClang-CXX.cmake @@ -1,9 +1,6 @@ include(Compiler/Clang) __compiler_clang(CXX) -set(CMAKE_CXX_LINK_OPTIONS_PIE ${CMAKE_CXX_COMPILE_OPTIONS_PIE} -Xlinker -pie) -set(CMAKE_CXX_LINK_OPTIONS_NO_PIE -Xlinker -no_pie) - if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") endif() diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index 7cee9c7..c3f13f3 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -23,23 +23,9 @@ else() set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") # Link options for PIE are already set in 'Compiler/GNU.cmake' # but clang may require alternate syntax on some platforms - if (NOT CMAKE_${lang}_FLAG_PIE) - cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_COMPILE_OPTIONS_PIE};-Xlinker;-pie" - CMAKE_${lang}_FLAG_XLINKER_PIE) - if (CMAKE_${lang}_FLAG_XLINKER_PIE) - set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-Xlinker" "-pie") - else() - set(CMAKE_${lang}_LINK_OPTIONS_PIE "") - endif() - endif() - if (NOT CMAKE_${lang}_FLAG_NO_PIE) - cmake_check_compiler_flag(${lang} "-Xlinker;-no_pie" - CMAKE_${lang}_FLAG_XLINKER_NO_PIE) - if (CMAKE_${lang}_FLAG_XLINKER_NO_PIE) - set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-Xlinker" "-no_pie") - else() - set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") - endif() + if (APPLE) + set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} -Xlinker -pie) + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE -Xlinker -no_pie) endif() set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 688a1b5..6b1bd3a 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -15,23 +15,14 @@ macro(__compiler_gnu lang) # Feature flags. set(CMAKE_${lang}_VERBOSE_FLAG "-v") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") + set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4) set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") # Support of PIE at link stage depends on various elements : platform, compiler, linker - # so the easiest way is to check if compiler supports these flags - cmake_check_compiler_flag(${lang} "${CMAKE_${lang}_COMPILE_OPTIONS_PIE};-pie" - CMAKE_${lang}_FLAG_PIE) - if (CMAKE_${lang}_FLAG_PIE) - set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie") - else() - set(CMAKE_${lang}_LINK_OPTIONS_PIE "") - endif() - cmake_check_compiler_flag(${lang} "-no-pie" CMAKE_${lang}_FLAG_NO_PIE) - if (CMAKE_${lang}_FLAG_NO_PIE) - set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie") - else() - set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") - endif() + # so to activate it, module CheckPIESupported must be used. + set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES) + set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie") + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie") endif() if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.0) set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake index 75b8fe6..c4aba8e 100644 --- a/Modules/Compiler/SunPro-C.cmake +++ b/Modules/Compiler/SunPro-C.cmake @@ -7,6 +7,7 @@ set(CMAKE_C_VERBOSE_FLAG "-#") set(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_C_LINK_OPTIONS_PIE "") set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC") diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake index 662ac30..5ce58b2 100644 --- a/Modules/Compiler/SunPro-CXX.cmake +++ b/Modules/Compiler/SunPro-CXX.cmake @@ -7,6 +7,7 @@ set(CMAKE_CXX_VERBOSE_FLAG "-v") set(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC) set(CMAKE_CXX_COMPILE_OPTIONS_PIE "") +set(_CMAKE_CXX_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_CXX_LINK_OPTIONS_PIE "") set(CMAKE_CXX_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC") diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake index e110253..0c93c94 100644 --- a/Modules/Compiler/SunPro-Fortran.cmake +++ b/Modules/Compiler/SunPro-Fortran.cmake @@ -4,6 +4,7 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free") set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-KPIC") set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "") +set(_CMAKE_Fortran_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_Fortran_LINK_OPTIONS_PIE "") set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-KPIC") diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 93cd74a..e763bab 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -550,6 +550,14 @@ External Project Definition ``LOG_MERGED_STDOUTERR <bool>`` When enabled, the output the step is not split by stdout and stderr. + ``LOG_OUTPUT_ON_FAILURE <bool>`` + This option only has an effect if at least one of the other ``LOG_<step>`` + options is enabled. If an error occurs for a step which has logging to + file enabled, that step's output will be printed to the console if + ``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount + of output is recorded, just the end of that output may be printed to the + console. + **Terminal Access Options:** Steps can be given direct access to the terminal in some cases. Giving a step access to the terminal may allow it to receive terminal input if @@ -1953,6 +1961,7 @@ endif() set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake) set(logbase ${log_dir}/${name}-${step}) get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR) + get_property(log_output_on_failure TARGET ${name} PROPERTY _EP_LOG_OUTPUT_ON_FAILURE) if (log_merged) set(stdout_log "${logbase}.log") set(stderr_log "${logbase}.log") @@ -1961,21 +1970,55 @@ endif() set(stderr_log "${logbase}-err.log") endif() set(code " +cmake_minimum_required(VERSION 3.13) ${code_cygpath_make} set(command \"${command}\") +set(log_merged \"${log_merged}\") +set(log_output_on_failure \"${log_output_on_failure}\") +set(stdout_log \"${stdout_log}\") +set(stderr_log \"${stderr_log}\") execute_process( COMMAND \${command} RESULT_VARIABLE result - OUTPUT_FILE \"${stdout_log}\" - ERROR_FILE \"${stderr_log}\" + OUTPUT_FILE \"\${stdout_log}\" + ERROR_FILE \"\${stderr_log}\" ) +macro(read_up_to_max_size log_file output_var) + file(SIZE \${log_file} determined_size) + set(max_size 10240) + if (determined_size GREATER max_size) + math(EXPR seek_position \"\${determined_size} - \${max_size}\") + file(READ \${log_file} \${output_var} OFFSET \${seek_position}) + set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\") + else() + file(READ \${log_file} \${output_var}) + endif() +endmacro() if(result) set(msg \"Command failed: \${result}\\n\") foreach(arg IN LISTS command) set(msg \"\${msg} '\${arg}'\") endforeach() - set(msg \"\${msg}\\nSee also\\n ${stderr_log}\") - message(FATAL_ERROR \"\${msg}\") + if (\${log_merged}) + set(msg \"\${msg}\\nSee also\\n \${stderr_log}\") + else() + set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\") + endif() + if (\${log_output_on_failure}) + message(SEND_ERROR \"\${msg}\") + if (\${log_merged}) + read_up_to_max_size(\"\${stderr_log}\" error_log_contents) + message(STATUS \"Log output is:\\n\${error_log_contents}\") + else() + read_up_to_max_size(\"\${stdout_log}\" out_log_contents) + read_up_to_max_size(\"\${stderr_log}\" err_log_contents) + message(STATUS \"stdout output is:\\n\${out_log_contents}\") + message(STATUS \"stderr output is:\\n\${err_log_contents}\") + endif() + message(FATAL_ERROR \"Stopping after outputting logs.\") + else() + message(FATAL_ERROR \"\${msg}\") + endif() else() set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\") message(STATUS \"\${msg}\") diff --git a/Modules/FindLibLZMA.cmake b/Modules/FindLibLZMA.cmake index 6d30e57..6225744 100644 --- a/Modules/FindLibLZMA.cmake +++ b/Modules/FindLibLZMA.cmake @@ -5,22 +5,40 @@ FindLibLZMA ----------- -Find LibLZMA +Find LZMA compression algorithm headers and library. -Find LibLZMA headers and library -:: +Imported Targets +^^^^^^^^^^^^^^^^ - LIBLZMA_FOUND - True if liblzma is found. - LIBLZMA_INCLUDE_DIRS - Directory where liblzma headers are located. - LIBLZMA_LIBRARIES - Lzma libraries to link against. - LIBLZMA_HAS_AUTO_DECODER - True if lzma_auto_decoder() is found (required). - LIBLZMA_HAS_EASY_ENCODER - True if lzma_easy_encoder() is found (required). - LIBLZMA_HAS_LZMA_PRESET - True if lzma_lzma_preset() is found (required). - LIBLZMA_VERSION_MAJOR - The major version of lzma - LIBLZMA_VERSION_MINOR - The minor version of lzma - LIBLZMA_VERSION_PATCH - The patch version of lzma - LIBLZMA_VERSION_STRING - version number as a string (ex: "5.0.3") +This module defines :prop_tgt:`IMPORTED` target ``LibLZMA::LibLZMA``, if +liblzma has been found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``LIBLZMA_FOUND`` + True if liblzma headers and library were found. +``LIBLZMA_INCLUDE_DIRS`` + Directory where liblzma headers are located. +``LIBLZMA_LIBRARIES`` + Lzma libraries to link against. +``LIBLZMA_HAS_AUTO_DECODER`` + True if lzma_auto_decoder() is found (required). +``LIBLZMA_HAS_EASY_ENCODER`` + True if lzma_easy_encoder() is found (required). +``LIBLZMA_HAS_LZMA_PRESET`` + True if lzma_lzma_preset() is found (required). +``LIBLZMA_VERSION_MAJOR`` + The major version of lzma +``LIBLZMA_VERSION_MINOR`` + The minor version of lzma +``LIBLZMA_VERSION_PATCH`` + The patch version of lzma +``LIBLZMA_VERSION_STRING`` + version number as a string (ex: "5.0.3") #]=======================================================================] find_path(LIBLZMA_INCLUDE_DIR lzma.h ) @@ -51,17 +69,23 @@ if (LIBLZMA_LIBRARY) endif () include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibLZMA REQUIRED_VARS LIBLZMA_INCLUDE_DIR - LIBLZMA_LIBRARY +find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY + LIBLZMA_INCLUDE_DIR LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET VERSION_VAR LIBLZMA_VERSION_STRING ) +mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY ) if (LIBLZMA_FOUND) set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY}) set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR}) + if(NOT TARGET LibLZMA::LibLZMA) + add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED) + set_target_properties(LibLZMA::LibLZMA PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${LIBLZMA_INCLUDE_DIR} + IMPORTED_LINK_INTERFACE_LANGUAGES C + IMPORTED_LOCATION ${LIBLZMA_LIBRARY}) + endif() endif () - -mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY ) diff --git a/Modules/Internal/CMakeCheckCompilerFlag.cmake b/Modules/Internal/CMakeCheckCompilerFlag.cmake index ca9b356..9c8dfb6 100644 --- a/Modules/Internal/CMakeCheckCompilerFlag.cmake +++ b/Modules/Internal/CMakeCheckCompilerFlag.cmake @@ -12,12 +12,17 @@ The function does not use the try_compile() command so as to avoid infinite recursion. It may not work for all platforms or toolchains, the caller is responsible for ensuring it is only called in valid situations. + cmake_check_compiler_flag(<lang> <flag> <result> + [SRC_EXT <ext>] [COMMAND_PATTERN <pattern>] + [FAIL_REGEX <regex> ...] + [OUTPUT_VARIABLE <output>]) + Parameters: - lang - Language to check. - flag - The flag to add to the compile/link command line. - result - Boolean output variable. It will be stored in the cache as an - internal variable and if true, will cause future tests that assign - to that variable to be bypassed. + <lang> - Language to check. + <flag> - The flag to add to the compile/link command line. + <result> - Boolean output variable. It will be stored in the cache as an + internal variable and if true, will cause future tests that assign + to that variable to be bypassed. Optional parameters: SRC_EXT - Overrides the extension of the source file used for the @@ -28,7 +33,7 @@ Optional parameters: the output, give a failed result for the check. A common set of regular expressions will be included in addition to those given by FAIL_REGEX. - + OUTPUT_VARIABLE - Set <output> variable with details about any error. #]=] include_guard(GLOBAL) @@ -58,7 +63,7 @@ function(CMAKE_CHECK_COMPILER_FLAG lang flag result) set(check_lang ${lang}) endif() - cmake_parse_arguments(CCCF "" "SRC_EXT;COMMAND_PATTERN" "FAIL_REGEX" ${ARGN}) + cmake_parse_arguments(CCCF "" "SRC_EXT;COMMAND_PATTERN;OUTPUT_VARIABLE" "FAIL_REGEX" ${ARGN}) if (NOT CCCF_COMMAND_PATTERN) set (CCCF_COMMAND_PATTERN "<FLAG> -o <OUTPUT> <SOURCE>") @@ -95,6 +100,10 @@ function(CMAKE_CHECK_COMPILER_FLAG lang flag result) endif() endif() + if (CCCF_OUTPUT_VARIABLE) + unset(${CCCF_OUTPUT_VARIABLE} PARENT_SCOPE) + endif() + # Compute the directory in which to run the test. set(COMPILER_FLAG_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp") # Compute source and output files. @@ -139,6 +148,9 @@ function(CMAKE_CHECK_COMPILER_FLAG lang flag result) "Determining if the ${flag} option " "is supported for ${lang} language failed with the following output:\n" "${COMPILER_FLAG_OUTPUT}\n") + if (CCCF_OUTPUT_VARIABLE) + set(${CCCF_OUTPUT_VARIABLE} "${COMPILER_FLAG_OUTPUT}" PARENT_SCOPE) + endif() return() endif() diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake index f55b80d..ca90712 100644 --- a/Modules/Platform/CYGWIN-GNU.cmake +++ b/Modules/Platform/CYGWIN-GNU.cmake @@ -27,6 +27,7 @@ macro(__cygwin_compiler_gnu lang) # No -fPIC on cygwin set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "") + set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_${lang}_LINK_OPTIONS_PIE "") set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") diff --git a/Modules/Platform/Fuchsia.cmake b/Modules/Platform/Fuchsia.cmake index 7b33434..4b13805 100644 --- a/Modules/Platform/Fuchsia.cmake +++ b/Modules/Platform/Fuchsia.cmake @@ -3,6 +3,7 @@ set(FUCHSIA 1) set(CMAKE_DL_LIBS "") set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE") +set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER YES) set(CMAKE_C_LINK_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE} "-pie") set(CMAKE_C_LINK_OPTIONS_NO_PIE "-no-pie") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake index ab22b1d..3b5ca59 100644 --- a/Modules/Platform/Linux-Intel.cmake +++ b/Modules/Platform/Linux-Intel.cmake @@ -23,7 +23,9 @@ endif() macro(__linux_compiler_intel lang) set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") + set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 13.0) + set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES) set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie") set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie") endif() diff --git a/Modules/Platform/Linux-PGI.cmake b/Modules/Platform/Linux-PGI.cmake index 3e7e391..0341654 100644 --- a/Modules/Platform/Linux-PGI.cmake +++ b/Modules/Platform/Linux-PGI.cmake @@ -12,6 +12,7 @@ macro(__linux_compiler_pgi lang) # Shared library compile and link flags. set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "") + set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_${lang}_LINK_OPTIONS_PIE "") set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") diff --git a/Modules/Platform/SINIX.cmake b/Modules/Platform/SINIX.cmake index e44ceef..e3b0a05 100644 --- a/Modules/Platform/SINIX.cmake +++ b/Modules/Platform/SINIX.cmake @@ -1,5 +1,6 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_C_LINK_OPTIONS_PIE "") set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") diff --git a/Modules/Platform/UNIX_SV.cmake b/Modules/Platform/UNIX_SV.cmake index 433daf3..bd1ffce 100644 --- a/Modules/Platform/UNIX_SV.cmake +++ b/Modules/Platform/UNIX_SV.cmake @@ -1,5 +1,6 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_C_LINK_OPTIONS_PIE "") set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") diff --git a/Modules/Platform/UnixWare.cmake b/Modules/Platform/UnixWare.cmake index 8c9d430..94888d9 100644 --- a/Modules/Platform/UnixWare.cmake +++ b/Modules/Platform/UnixWare.cmake @@ -1,5 +1,6 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_C_LINK_OPTIONS_PIE "") set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake index 2e854e5..71189b1 100644 --- a/Modules/Platform/Windows-GNU.cmake +++ b/Modules/Platform/Windows-GNU.cmake @@ -72,6 +72,7 @@ macro(__windows_compiler_gnu lang) # No -fPIC on Windows set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "") + set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_${lang}_LINK_OPTIONS_PIE "") set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") |