diff options
Diffstat (limited to 'Modules')
26 files changed, 257 insertions, 28 deletions
diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake index 2bb3128..50b2807 100644 --- a/Modules/CMakeAddFortranSubdirectory.cmake +++ b/Modules/CMakeAddFortranSubdirectory.cmake @@ -5,18 +5,18 @@ CMakeAddFortranSubdirectory --------------------------- -Use MinGW gfortran from VS if a fortran compiler is not found. +Add a fortran-only subdirectory, find a fortran compiler, and build. -The 'add_fortran_subdirectory' function adds a subdirectory to a -project that contains a fortran only sub-project. The module will +The ``cmake_add_fortran_subdirectory`` function adds a subdirectory +to a project that contains a fortran-only subproject. The module will check the current compiler and see if it can support fortran. If no fortran compiler is found and the compiler is MSVC, then this module will find the MinGW gfortran. It will then use an external project to build with the MinGW tools. It will also create imported targets for the libraries created. This will only work if the fortran code is -built into a dll, so BUILD_SHARED_LIBS is turned on in the project. -In addition the CMAKE_GNUtoMS option is set to on, so that the MS .lib -files are created. Usage is as follows: +built into a dll, so :variable:`BUILD_SHARED_LIBS` is turned on in +the project. In addition the :variable:`CMAKE_GNUtoMS` option is set +to on, so that Microsoft .lib files are created. Usage is as follows: :: diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake index 2975874..a896b99 100644 --- a/Modules/CMakeCXXInformation.cmake +++ b/Modules/CMakeCXXInformation.cmake @@ -105,6 +105,12 @@ endif() if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE) set(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE}) endif() +if(NOT CMAKE_CXX_LINK_OPTIONS_PIE) + set(CMAKE_CXX_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE}) +endif() +if(NOT CMAKE_CXX_LINK_OPTIONS_NO_PIE) + set(CMAKE_CXX_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE}) +endif() if(NOT CMAKE_CXX_COMPILE_OPTIONS_DLL) set(CMAKE_CXX_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL}) @@ -269,4 +275,3 @@ CMAKE_VERBOSE_MAKEFILE ) set(CMAKE_CXX_INFORMATION_LOADED 1) - diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index cceac83..ffa6a24 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -74,6 +74,12 @@ endif() if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE) set(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE}) endif() +if(NOT CMAKE_Fortran_LINK_OPTIONS_PIE) + set(CMAKE_Fortran_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE}) +endif() +if(NOT CMAKE_Fortran_LINK_OPTIONS_NO_PIE) + set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE}) +endif() if(NOT CMAKE_Fortran_COMPILE_OPTIONS_DLL) set(CMAKE_Fortran_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL}) diff --git a/Modules/CMakePrintHelpers.cmake b/Modules/CMakePrintHelpers.cmake index d5bbb4f..1af0bb7 100644 --- a/Modules/CMakePrintHelpers.cmake +++ b/Modules/CMakePrintHelpers.cmake @@ -5,32 +5,33 @@ CMakePrintHelpers ----------------- -Convenience macros for printing properties and variables, useful e.g. for debugging. +Convenience functions for printing properties and variables, useful +e.g. for debugging. :: - CMAKE_PRINT_PROPERTIES([TARGETS target1 .. targetN] + cmake_print_properties([TARGETS target1 .. targetN] [SOURCES source1 .. sourceN] [DIRECTORIES dir1 .. dirN] [TESTS test1 .. testN] [CACHE_ENTRIES entry1 .. entryN] PROPERTIES prop1 .. propN ) -This macro prints the values of the properties of the given targets, +This function prints the values of the properties of the given targets, source files, directories, tests or cache entries. Exactly one of the scope keywords must be used. Example:: - cmake_print_properties(TARGETS foo bar PROPERTIES - LOCATION INTERFACE_INCLUDE_DIRS) + cmake_print_properties(TARGETS foo bar PROPERTIES + LOCATION INTERFACE_INCLUDE_DIRS) This will print the LOCATION and INTERFACE_INCLUDE_DIRS properties for both targets foo and bar. +:: + cmake_print_variables(var1 var2 .. varN) -CMAKE_PRINT_VARIABLES(var1 var2 .. varN) - -This macro will print the name of each variable followed by its value. +This function will print the name of each variable followed by its value. Example:: cmake_print_variables(CMAKE_C_COMPILER CMAKE_MAJOR_VERSION DOES_NOT_EXIST) @@ -40,7 +41,7 @@ Gives:: -- CMAKE_C_COMPILER="/usr/bin/gcc" ; CMAKE_MAJOR_VERSION="2" ; DOES_NOT_EXIST="" #]=======================================================================] -function(CMAKE_PRINT_VARIABLES) +function(cmake_print_variables) set(msg "") foreach(var ${ARGN}) if(msg) @@ -52,7 +53,7 @@ function(CMAKE_PRINT_VARIABLES) endfunction() -function(CMAKE_PRINT_PROPERTIES ) +function(cmake_print_properties) set(options ) set(oneValueArgs ) set(multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES ) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index f3e3423..ebce851 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -7,8 +7,8 @@ CPack Build binary and source package installers. -Variables common to all CPack generators -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Introduction +^^^^^^^^^^^^ The CPack module generates binary and source installers in a variety of formats using the cpack program. Inclusion of the CPack module adds @@ -23,6 +23,9 @@ 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. +CPack generators +^^^^^^^^^^^^^^^^ + The :variable:`CPACK_GENERATOR` variable has different meanings in different contexts. In a ``CMakeLists.txt`` file, :variable:`CPACK_GENERATOR` is a *list of generators*: and when :manual:`cpack <cpack(1)>` is run with no other @@ -57,6 +60,9 @@ This is the key: For each generator listed in :variable:`CPACK_GENERATOR` in internally to *the one currently being used* and then include the :variable:`CPACK_PROJECT_CONFIG_FILE`. +Variables common to all CPack generators +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Before including this CPack module in your ``CMakeLists.txt`` file, there are a variety of variables that can be set to customize the resulting installers. The most commonly-used variables are: diff --git a/Modules/CheckPrototypeDefinition.cmake b/Modules/CheckPrototypeDefinition.cmake index b379ec4..c90b766 100644 --- a/Modules/CheckPrototypeDefinition.cmake +++ b/Modules/CheckPrototypeDefinition.cmake @@ -28,7 +28,7 @@ Example: "unistd.h;pwd.h" SOLARIS_GETPWENT_R) -The following variables may be set before calling this macro to modify +The following variables may be set before calling this function to modify the way the check is run: :: @@ -46,7 +46,7 @@ get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) include_guard(GLOBAL) -function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE) +function(check_prototype_definition _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE) if (NOT DEFINED ${_VARIABLE}) set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n") diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake index a48adec..8754951 100644 --- a/Modules/Compiler/AppleClang-C.cmake +++ b/Modules/Compiler/AppleClang-C.cmake @@ -1,6 +1,9 @@ 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 e5fd647..54c1388 100644 --- a/Modules/Compiler/AppleClang-CXX.cmake +++ b/Modules/Compiler/AppleClang-CXX.cmake @@ -1,6 +1,9 @@ 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 e23470b..7cee9c7 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -21,6 +21,26 @@ else() macro(__compiler_clang lang) __compiler_gnu(${lang}) 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() + endif() set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0) diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 4491d4b..688a1b5 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -9,6 +9,7 @@ endif() set(__COMPILER_GNU 1) include(Compiler/CMakeCommonCompilerMacros) +include(Internal/CMakeCheckCompilerFlag) macro(__compiler_gnu lang) # Feature flags. @@ -16,6 +17,21 @@ macro(__compiler_gnu lang) set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") 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() 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 047de43..75b8fe6 100644 --- a/Modules/Compiler/SunPro-C.cmake +++ b/Modules/Compiler/SunPro-C.cmake @@ -6,6 +6,9 @@ include(Compiler/SunPro) set(CMAKE_C_VERBOSE_FLAG "-#") set(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC) +set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC") set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G") set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R") diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake index 4c1ac5b..662ac30 100644 --- a/Modules/Compiler/SunPro-CXX.cmake +++ b/Modules/Compiler/SunPro-CXX.cmake @@ -6,6 +6,9 @@ include(Compiler/SunPro) set(CMAKE_CXX_VERBOSE_FLAG "-v") set(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC) +set(CMAKE_CXX_COMPILE_OPTIONS_PIE "") +set(CMAKE_CXX_LINK_OPTIONS_PIE "") +set(CMAKE_CXX_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC") set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G") set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R") diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake index 2247dd0..e110253 100644 --- a/Modules/Compiler/SunPro-Fortran.cmake +++ b/Modules/Compiler/SunPro-Fortran.cmake @@ -3,6 +3,9 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free") set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-KPIC") +set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "") +set(CMAKE_Fortran_LINK_OPTIONS_PIE "") +set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-KPIC") set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-G") set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG "-R") diff --git a/Modules/Documentation.cmake b/Modules/Documentation.cmake index 229b8ab..aaf24f6 100644 --- a/Modules/Documentation.cmake +++ b/Modules/Documentation.cmake @@ -5,9 +5,7 @@ Documentation ------------- -DocumentationVTK.cmake - -This file provides support for the VTK documentation framework. It +This module provides support for the VTK documentation framework. It relies on several tools (Doxygen, Perl, etc). #]=======================================================================] diff --git a/Modules/Internal/CMakeCheckCompilerFlag.cmake b/Modules/Internal/CMakeCheckCompilerFlag.cmake new file mode 100644 index 0000000..ca9b356 --- /dev/null +++ b/Modules/Internal/CMakeCheckCompilerFlag.cmake @@ -0,0 +1,146 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=[ + +NOTE: This function is used internally by CMake. Projects should not include + this file directly. + +The cmake_check_compiler_flag() function can be used to compile and link a +source file to check whether a specific compiler or linker flag is supported. +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. + +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. + +Optional parameters: + SRC_EXT - Overrides the extension of the source file used for the + check. Defaults are 'c' (C), 'cxx' (CXX), 'F' (Fortran). + COMMAND_PATTERN - Pattern to be used for the command line. The default is + '<FLAG> -o <OUTPUT> <SOURCE>' + FAIL_REGEX - List of additional regular expressions that, if matched by + 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. + +#]=] + +include_guard(GLOBAL) +include(CMakeCheckCompilerFlagCommonPatterns) + +function(CMAKE_CHECK_COMPILER_FLAG lang flag result) + # Cache results between runs similar to check_<lang>_source_compiles() + if(DEFINED ${result}) + return() + endif() + + set(comment "Is the '${flag}' option(s) supported") + string(REPLACE ";" " " comment "${comment}") + + if (NOT lang MATCHES "^(C|CXX|Fortran|ASM)$") + # other possible languages are not supported + # log message to keep trace of this problem... + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Function 'CMAKE_CHECK_COMPILER_FLAG' called with unsupported language: ${lang}\n") + set(${result} FALSE CACHE INTERNAL ${comment}) + return() + endif() + if (lang STREQUAL "ASM") + # assume ASM compiler is a multi-language compiler, so supports C language as well + set(check_lang C) + else() + set(check_lang ${lang}) + endif() + + cmake_parse_arguments(CCCF "" "SRC_EXT;COMMAND_PATTERN" "FAIL_REGEX" ${ARGN}) + + if (NOT CCCF_COMMAND_PATTERN) + set (CCCF_COMMAND_PATTERN "<FLAG> -o <OUTPUT> <SOURCE>") + endif() + + list (APPEND CCCF_FAIL_REGEX "argument unused during compilation") # clang + if (check_lang STREQUAL "C") + list(APPEND CCCF_FAIL_REGEX + "command line option .* is valid for .* but not for C") # GNU + elseif(check_lang STREQUAL "CXX") + list(APPEND CCCF_FAIL_REGEX + "command line option .* is valid for .* but not for C\\+\\+") # GNU + elseif(check_lang STREQUAL "Fortran") + list(APPEND CCCF_FAIL_REGEX + "command line option .* is valid for .* but not for Fortran") # GNU + endif() + + # Add patterns for common errors + check_compiler_flag_common_patterns(COMPILER_FLAG_COMMON_PATTERNS) + foreach(arg IN LISTS COMPILER_FLAG_COMMON_PATTERNS) + if(arg MATCHES "^FAIL_REGEX$") + continue() + endif() + list(APPEND CCCF_FAIL_REGEX "${arg}") + endforeach() + + if(NOT CCCF_SRC_EXT) + if (check_lang STREQUAL "C") + set(CCCF_SRC_EXT c) + elseif(check_lang STREQUAL "CXX") + set(CCCF_SRC_EXT cxx) + elseif(check_lang STREQUAL "Fortran") + set(CCCF_SRC_EXT F) + endif() + 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. + set(COMPILER_FLAG_SRC + "${COMPILER_FLAG_DIR}/CompilerFlag${lang}.${CCCF_SRC_EXT}") + if(check_lang STREQUAL "Fortran") + file(WRITE "${COMPILER_FLAG_SRC}" + " program simple\n end program simple\n") + else() + file(WRITE "${COMPILER_FLAG_SRC}" "int main (void)\n{ return 0; }\n") + endif() + get_filename_component(COMPILER_FLAG_EXE "${COMPILER_FLAG_SRC}" NAME_WE) + string(APPEND COMPILER_FLAG_EXE "${CMAKE_EXECUTABLE_SUFFIX}") + + # Build command line + separate_arguments(CCCF_COMMAND_PATTERN UNIX_COMMAND + "${CCCF_COMMAND_PATTERN}") + list(TRANSFORM CCCF_COMMAND_PATTERN REPLACE "<SOURCE>" "${COMPILER_FLAG_SRC}") + list(TRANSFORM CCCF_COMMAND_PATTERN REPLACE "<OUTPUT>" "${COMPILER_FLAG_EXE}") + list(TRANSFORM CCCF_COMMAND_PATTERN REPLACE "<FLAG>" "${flag}") + + execute_process( + COMMAND "${CMAKE_COMMAND}" -E env LC_ALL=C LC_MESSAGES=C LANG=C + "${CMAKE_${lang}_COMPILER}" ${CCCF_COMMAND_PATTERN} + WORKING_DIRECTORY "${COMPILER_FLAG_DIR}" + OUTPUT_VARIABLE COMPILER_FLAG_OUTPUT + ERROR_VARIABLE COMPILER_FLAG_OUTPUT + RESULT_VARIABLE COMPILER_FLAG_RESULT) + + # Record result in the cache so we can avoid re-testing every CMake run + if (COMPILER_FLAG_RESULT) + set(${result} FALSE CACHE INTERNAL ${comment}) + else() + foreach(regex IN LISTS CCCF_FAIL_REGEX) + if(COMPILER_FLAG_OUTPUT MATCHES "${regex}") + set(${result} FALSE CACHE INTERNAL ${comment}) + endif() + endforeach() + endif() + if (DEFINED ${result}) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the ${flag} option " + "is supported for ${lang} language failed with the following output:\n" + "${COMPILER_FLAG_OUTPUT}\n") + return() + endif() + + set(${result} TRUE CACHE INTERNAL ${comment}) +endfunction() diff --git a/Modules/Platform/Android/abi-common.cmake b/Modules/Platform/Android/abi-common.cmake index 10fb897..a0b47f4 100644 --- a/Modules/Platform/Android/abi-common.cmake +++ b/Modules/Platform/Android/abi-common.cmake @@ -12,10 +12,6 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() -if(CMAKE_POSITION_INDEPENDENT_CODE) - string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -fPIE -pie") -endif() - string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,--gc-sections") if(NOT _ANDROID_ABI_INIT_EXE_LDFLAGS_NO_nocopyreloc) diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake index 784c8c6..f55b80d 100644 --- a/Modules/Platform/CYGWIN-GNU.cmake +++ b/Modules/Platform/CYGWIN-GNU.cmake @@ -27,6 +27,8 @@ macro(__cygwin_compiler_gnu lang) # No -fPIC on cygwin set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "") + set(CMAKE_${lang}_LINK_OPTIONS_PIE "") + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") # Initialize C link type selection flags. These flags are used when diff --git a/Modules/Platform/FreeBSD.cmake b/Modules/Platform/FreeBSD.cmake index 082e9f6..4a4c00d 100644 --- a/Modules/Platform/FreeBSD.cmake +++ b/Modules/Platform/FreeBSD.cmake @@ -1,6 +1,7 @@ set(CMAKE_DL_LIBS "") set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE") +# PIE link options are managed in Compiler/<compiler>.cmake file set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib diff --git a/Modules/Platform/Fuchsia.cmake b/Modules/Platform/Fuchsia.cmake index 896da7b..7b33434 100644 --- a/Modules/Platform/Fuchsia.cmake +++ b/Modules/Platform/Fuchsia.cmake @@ -3,6 +3,8 @@ set(FUCHSIA 1) set(CMAKE_DL_LIBS "") set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE") +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") set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake index f712e2b..ab22b1d 100644 --- a/Modules/Platform/Linux-Intel.cmake +++ b/Modules/Platform/Linux-Intel.cmake @@ -23,6 +23,10 @@ endif() macro(__linux_compiler_intel lang) set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") + if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 13.0) + set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie") + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie") + endif() set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") diff --git a/Modules/Platform/Linux-PGI.cmake b/Modules/Platform/Linux-PGI.cmake index db032c2..3e7e391 100644 --- a/Modules/Platform/Linux-PGI.cmake +++ b/Modules/Platform/Linux-PGI.cmake @@ -12,6 +12,8 @@ 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}_LINK_OPTIONS_PIE "") + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS " ") diff --git a/Modules/Platform/NetBSD.cmake b/Modules/Platform/NetBSD.cmake index a8f4cc8..d99cb4a 100644 --- a/Modules/Platform/NetBSD.cmake +++ b/Modules/Platform/NetBSD.cmake @@ -1,6 +1,7 @@ set(CMAKE_DL_LIBS "") set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE") +# PIE link options are managed in Compiler/<compiler>.cmake file set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") # -pic set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib diff --git a/Modules/Platform/SINIX.cmake b/Modules/Platform/SINIX.cmake index c37a113..e44ceef 100644 --- a/Modules/Platform/SINIX.cmake +++ b/Modules/Platform/SINIX.cmake @@ -1,4 +1,6 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") include(Platform/UnixPaths) diff --git a/Modules/Platform/UNIX_SV.cmake b/Modules/Platform/UNIX_SV.cmake index 1ec96ae..433daf3 100644 --- a/Modules/Platform/UNIX_SV.cmake +++ b/Modules/Platform/UNIX_SV.cmake @@ -1,5 +1,7 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-Bexport") include(Platform/UnixPaths) diff --git a/Modules/Platform/UnixWare.cmake b/Modules/Platform/UnixWare.cmake index e649bd2..8c9d430 100644 --- a/Modules/Platform/UnixWare.cmake +++ b/Modules/Platform/UnixWare.cmake @@ -1,5 +1,7 @@ set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC) set(CMAKE_C_COMPILE_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_PIE "") +set(CMAKE_C_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC") set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-Wl,-Bexport") include(Platform/UnixPaths) diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake index cfb325b..2e854e5 100644 --- a/Modules/Platform/Windows-GNU.cmake +++ b/Modules/Platform/Windows-GNU.cmake @@ -72,6 +72,8 @@ macro(__windows_compiler_gnu lang) # No -fPIC on Windows set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "") + set(CMAKE_${lang}_LINK_OPTIONS_PIE "") + set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "") set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS ${__WINDOWS_GNU_LD_RESPONSE}) |