From aec3c79acbe86a2156e3929678ef05bc2840edfa Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Jul 2016 14:41:21 -0400 Subject: [PATCH 1/4] Strip CMAKE_*_LINKER_FLAGS[_] initializer whitespace --- Modules/CMakeCommonLanguageInclude.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeCommonLanguageInclude.cmake b/Modules/CMakeCommonLanguageInclude.cmake index fa025a892..6b372089e 100644 --- a/Modules/CMakeCommonLanguageInclude.cmake +++ b/Modules/CMakeCommonLanguageInclude.cmake @@ -16,11 +16,15 @@ # cache values that can be initialized in the platform-compiler.cmake file # it may be included by more than one language. -if(NOT "x$ENV{LDFLAGS}" STREQUAL "x") - set (CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") - set (CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") - set (CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_MODULE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") -endif() +set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") +set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") +set(CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_MODULE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}") + +foreach(t EXE SHARED MODULE STATIC) + foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO) + string(STRIP "${CMAKE_${t}_LINKER_FLAGS${c}_INIT}" CMAKE_${t}_LINKER_FLAGS${c}_INIT) + endforeach() +endforeach() if(NOT CMAKE_NOT_USING_CONFIG_FLAGS) # default build type is none From 55c884ed3bf29069f3b74db7a0ba54ed62edb88f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Jul 2016 15:01:26 -0400 Subject: [PATCH 2/4] Embarcadero: Set all CMAKE_*_LINKER_FLAGS_INIT directly Avoid copying CMAKE_EXE_LINKER_FLAGS_INIT to the others. --- Modules/Platform/Windows-Embarcadero.cmake | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake index 8a87db371..79b0af51b 100644 --- a/Modules/Platform/Windows-Embarcadero.cmake +++ b/Modules/Platform/Windows-Embarcadero.cmake @@ -64,15 +64,11 @@ set(CMAKE_CREATE_CONSOLE_EXE "${_tC}" ) set (CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.") -set (CMAKE_EXE_LINKER_FLAGS_INIT "${_tM} -lS:1048576 -lSc:4098 -lH:1048576 -lHc:8192 ") -set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "-v") -set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-v") -set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT}) +foreach(t EXE SHARED MODULE) + set(CMAKE_${t}_LINKER_FLAGS_INIT "${_tM} -lS:1048576 -lSc:4098 -lH:1048576 -lHc:8192 ") + set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "-v") + set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "-v") +endforeach() # The Borland link tool does not support multiple concurrent # invocations within a single working directory. From 37d15c399e33f3140c1ab0259984c54084dc34f8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Jul 2016 15:05:32 -0400 Subject: [PATCH 3/4] MSVC: Set all CMAKE_*_LINKER_FLAGS_INIT directly Avoid copying CMAKE_EXE_LINKER_FLAGS_INIT to the others. --- Modules/Platform/Windows-MSVC.cmake | 45 ++++++++++++----------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index b1969a2e4..4184675cb 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -166,7 +166,9 @@ if(WINCE) endforeach() set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib") - set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib") + foreach(t EXE SHARED MODULE) + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib") + endforeach() if (MSVC_VERSION LESS 1600) set(CMAKE_C_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT} corelibc.lib") @@ -235,9 +237,6 @@ elseif(MSVC_CXX_ARCHITECTURE_ID) elseif(MSVC_Fortran_ARCHITECTURE_ID) set(_MACHINE_ARCH_FLAG "/machine:${MSVC_Fortran_ARCHITECTURE_ID}") endif() -set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}") -set(CMAKE_STATIC_LINKER_FLAGS_INIT "${CMAKE_STATIC_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}") -unset(_MACHINE_ARCH_FLAG) # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype # on versions that support it @@ -250,30 +249,22 @@ if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE) endif() endif() -if (CMAKE_COMPILER_SUPPORTS_PDBTYPE) - set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") - set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") -else () - set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") - set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") -endif () -# for release and minsize release default to no incremental linking -set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO") +foreach(t EXE SHARED MODULE) + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " ${_MACHINE_ARCH_FLAG}") + if (CMAKE_COMPILER_SUPPORTS_PDBTYPE) + set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") + set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") + else () + set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") + set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") + endif () + # for release and minsize release default to no incremental linking + set(CMAKE_${t}_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO") + set(CMAKE_${t}_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO") +endforeach() -# copy the EXE_LINKER flags to SHARED and MODULE linker flags -# shared linker flags -set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) -set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) -# module linker flags -set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT}) -set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) +string(APPEND CMAKE_STATIC_LINKER_FLAGS_INIT " ${_MACHINE_ARCH_FLAG}") +unset(_MACHINE_ARCH_FLAG) macro(__windows_compiler_msvc lang) if(NOT MSVC_VERSION LESS 1400) From 8a98cf643235a4d2869e1c876f8769b3e6bcd86f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Jul 2016 15:06:23 -0400 Subject: [PATCH 4/4] Honor CMAKE_*_LINKER_FLAGS[_]_INIT set in toolchain files Document these variables. Change our convention for setting these variables from: set(CMAKE_EXE_LINKER_FLAGS_INIT "...") to string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ...") so that any value previously set by a toolchain file will be used. --- Help/manual/cmake-variables.7.rst | 8 +++ Help/release/dev/toolchain-flag-init.rst | 9 +++ .../CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT.rst | 10 ++++ Help/variable/CMAKE_EXE_LINKER_FLAGS_INIT.rst | 11 ++++ .../CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT.rst | 10 ++++ .../CMAKE_MODULE_LINKER_FLAGS_INIT.rst | 11 ++++ .../CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT.rst | 10 ++++ .../CMAKE_SHARED_LINKER_FLAGS_INIT.rst | 11 ++++ .../CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT.rst | 10 ++++ .../CMAKE_STATIC_LINKER_FLAGS_INIT.rst | 11 ++++ Modules/Platform/AIX-GNU.cmake | 6 +- Modules/Platform/AIX-XL.cmake | 6 +- Modules/Platform/CYGWIN-GNU.cmake | 2 +- Modules/Platform/Windows-Embarcadero.cmake | 6 +- Modules/Platform/Windows-MSVC.cmake | 12 ++-- Modules/Platform/Windows-OpenWatcom.cmake | 10 ++-- .../ToolchainFile/LinkFlagsInit-stdout.txt | 60 +++++++++++++++++++ .../LinkFlagsInit-toolchain.cmake | 5 ++ .../ToolchainFile/LinkFlagsInit.cmake | 7 +++ .../RunCMake/ToolchainFile/RunCMakeTest.cmake | 1 + 20 files changed, 195 insertions(+), 21 deletions(-) create mode 100644 Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT.rst create mode 100644 Help/variable/CMAKE_EXE_LINKER_FLAGS_INIT.rst create mode 100644 Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT.rst create mode 100644 Help/variable/CMAKE_MODULE_LINKER_FLAGS_INIT.rst create mode 100644 Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT.rst create mode 100644 Help/variable/CMAKE_SHARED_LINKER_FLAGS_INIT.rst create mode 100644 Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT.rst create mode 100644 Help/variable/CMAKE_STATIC_LINKER_FLAGS_INIT.rst create mode 100644 Tests/RunCMake/ToolchainFile/LinkFlagsInit-stdout.txt create mode 100644 Tests/RunCMake/ToolchainFile/LinkFlagsInit-toolchain.cmake create mode 100644 Tests/RunCMake/ToolchainFile/LinkFlagsInit.cmake diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index e134a1a59..1138b8254 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -253,7 +253,9 @@ Variables that Control the Build /variable/CMAKE_DEBUG_POSTFIX /variable/CMAKE_ENABLE_EXPORTS /variable/CMAKE_EXE_LINKER_FLAGS_CONFIG + /variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT /variable/CMAKE_EXE_LINKER_FLAGS + /variable/CMAKE_EXE_LINKER_FLAGS_INIT /variable/CMAKE_Fortran_FORMAT /variable/CMAKE_Fortran_MODULE_DIRECTORY /variable/CMAKE_GNUtoMS @@ -280,7 +282,9 @@ Variables that Control the Build /variable/CMAKE_MACOSX_RPATH /variable/CMAKE_MAP_IMPORTED_CONFIG_CONFIG /variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG + /variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT /variable/CMAKE_MODULE_LINKER_FLAGS + /variable/CMAKE_MODULE_LINKER_FLAGS_INIT /variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX /variable/CMAKE_NO_BUILTIN_CHRPATH /variable/CMAKE_NO_SYSTEM_FROM_IMPORTED @@ -293,11 +297,15 @@ Variables that Control the Build /variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY /variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY_CONFIG /variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG + /variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT /variable/CMAKE_SHARED_LINKER_FLAGS + /variable/CMAKE_SHARED_LINKER_FLAGS_INIT /variable/CMAKE_SKIP_BUILD_RPATH /variable/CMAKE_SKIP_INSTALL_RPATH /variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG + /variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT /variable/CMAKE_STATIC_LINKER_FLAGS + /variable/CMAKE_STATIC_LINKER_FLAGS_INIT /variable/CMAKE_TRY_COMPILE_CONFIGURATION /variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES /variable/CMAKE_TRY_COMPILE_TARGET_TYPE diff --git a/Help/release/dev/toolchain-flag-init.rst b/Help/release/dev/toolchain-flag-init.rst index 251484bc8..37e363d67 100644 --- a/Help/release/dev/toolchain-flag-init.rst +++ b/Help/release/dev/toolchain-flag-init.rst @@ -5,3 +5,12 @@ toolchain-flag-init :variable:`CMAKE__FLAGS_INIT` variable to initialize the :variable:`CMAKE__FLAGS` cache entry the first time a language is enabled in a build tree. + +* :variable:`Toolchain files ` may now set + :variable:`CMAKE_EXE_LINKER_FLAGS_INIT`, + :variable:`CMAKE_SHARED_LINKER_FLAGS_INIT`, and + :variable:`CMAKE_MODULE_LINKER_FLAGS_INIT` variables to initialize the + :variable:`CMAKE_EXE_LINKER_FLAGS`, + :variable:`CMAKE_SHARED_LINKER_FLAGS`, and + :variable:`CMAKE_MODULE_LINKER_FLAGS` cache entries the first time + a language is enabled in a build tree. diff --git a/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT.rst b/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT.rst new file mode 100644 index 000000000..592a36973 --- /dev/null +++ b/Help/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT.rst @@ -0,0 +1,10 @@ +CMAKE_EXE_LINKER_FLAGS__INIT +------------------------------------ + +Value used to initialize the :variable:`CMAKE_EXE_LINKER_FLAGS_` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also :variable:`CMAKE_EXE_LINKER_FLAGS_INIT`. diff --git a/Help/variable/CMAKE_EXE_LINKER_FLAGS_INIT.rst b/Help/variable/CMAKE_EXE_LINKER_FLAGS_INIT.rst new file mode 100644 index 000000000..0b8afe4fe --- /dev/null +++ b/Help/variable/CMAKE_EXE_LINKER_FLAGS_INIT.rst @@ -0,0 +1,11 @@ +CMAKE_EXE_LINKER_FLAGS_INIT +--------------------------- + +Value used to initialize the :variable:`CMAKE_EXE_LINKER_FLAGS` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also the configuration-specific variable +:variable:`CMAKE_EXE_LINKER_FLAGS__INIT`. diff --git a/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT.rst b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT.rst new file mode 100644 index 000000000..327901409 --- /dev/null +++ b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT.rst @@ -0,0 +1,10 @@ +CMAKE_MODULE_LINKER_FLAGS__INIT +--------------------------------------- + +Value used to initialize the :variable:`CMAKE_MODULE_LINKER_FLAGS_` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also :variable:`CMAKE_MODULE_LINKER_FLAGS_INIT`. diff --git a/Help/variable/CMAKE_MODULE_LINKER_FLAGS_INIT.rst b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_INIT.rst new file mode 100644 index 000000000..91b39f6dd --- /dev/null +++ b/Help/variable/CMAKE_MODULE_LINKER_FLAGS_INIT.rst @@ -0,0 +1,11 @@ +CMAKE_MODULE_LINKER_FLAGS_INIT +------------------------------ + +Value used to initialize the :variable:`CMAKE_MODULE_LINKER_FLAGS` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also the configuration-specific variable +:variable:`CMAKE_MODULE_LINKER_FLAGS__INIT`. diff --git a/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT.rst b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT.rst new file mode 100644 index 000000000..185df387d --- /dev/null +++ b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_CONFIG_INIT.rst @@ -0,0 +1,10 @@ +CMAKE_SHARED_LINKER_FLAGS__INIT +--------------------------------------- + +Value used to initialize the :variable:`CMAKE_SHARED_LINKER_FLAGS_` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also :variable:`CMAKE_SHARED_LINKER_FLAGS_INIT`. diff --git a/Help/variable/CMAKE_SHARED_LINKER_FLAGS_INIT.rst b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_INIT.rst new file mode 100644 index 000000000..cb819a7d9 --- /dev/null +++ b/Help/variable/CMAKE_SHARED_LINKER_FLAGS_INIT.rst @@ -0,0 +1,11 @@ +CMAKE_SHARED_LINKER_FLAGS_INIT +------------------------------ + +Value used to initialize the :variable:`CMAKE_SHARED_LINKER_FLAGS` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also the configuration-specific variable +:variable:`CMAKE_SHARED_LINKER_FLAGS__INIT`. diff --git a/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT.rst b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT.rst new file mode 100644 index 000000000..a49d1cb74 --- /dev/null +++ b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT.rst @@ -0,0 +1,10 @@ +CMAKE_STATIC_LINKER_FLAGS__INIT +--------------------------------------- + +Value used to initialize the :variable:`CMAKE_STATIC_LINKER_FLAGS_` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also :variable:`CMAKE_STATIC_LINKER_FLAGS_INIT`. diff --git a/Help/variable/CMAKE_STATIC_LINKER_FLAGS_INIT.rst b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_INIT.rst new file mode 100644 index 000000000..113ca710f --- /dev/null +++ b/Help/variable/CMAKE_STATIC_LINKER_FLAGS_INIT.rst @@ -0,0 +1,11 @@ +CMAKE_STATIC_LINKER_FLAGS_INIT +------------------------------ + +Value used to initialize the :variable:`CMAKE_STATIC_LINKER_FLAGS` +cache entry the first time a build tree is configured. +This variable is meant to be set by a :variable:`toolchain file +`. CMake may prepend or append content to +the value based on the environment and target platform. + +See also the configuration-specific variable +:variable:`CMAKE_STATIC_LINKER_FLAGS__INIT`. diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake index d6f5331dd..df97ab105 100644 --- a/Modules/Platform/AIX-GNU.cmake +++ b/Modules/Platform/AIX-GNU.cmake @@ -21,9 +21,9 @@ set(__AIX_COMPILER_GNU 1) # # By default, runtime linking is enabled. All shared objects specified on the command line # will be listed, even if there are no symbols referenced, in the output file. -set (CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-brtl") -set (CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,-brtl") -set (CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-brtl") +string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " -Wl,-brtl") +string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " -Wl,-brtl") +string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-brtl") macro(__aix_compiler_gnu lang) diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake index 5470441f9..3be095efa 100644 --- a/Modules/Platform/AIX-XL.cmake +++ b/Modules/Platform/AIX-XL.cmake @@ -21,9 +21,9 @@ set(__AIX_COMPILER_XL 1) # # By default, runtime linking is enabled. All shared objects specified on the command line # will be listed, even if there are no symbols referenced, in the output file. -set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-brtl") -set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,-brtl") -set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-brtl") +string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " -Wl,-brtl") +string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " -Wl,-brtl") +string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-brtl") macro(__aix_compiler_xl lang) diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake index 1a46c1031..5090c08a8 100644 --- a/Modules/Platform/CYGWIN-GNU.cmake +++ b/Modules/Platform/CYGWIN-GNU.cmake @@ -19,7 +19,7 @@ endif() set(__CYGWIN_COMPILER_GNU 1) # TODO: Is -Wl,--enable-auto-import now always default? -set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--enable-auto-import") +string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,--enable-auto-import") set(CMAKE_CREATE_WIN32_EXE "-mwindows") set(CMAKE_GNULD_IMAGE_VERSION diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake index 79b0af51b..43ae2a3eb 100644 --- a/Modules/Platform/Windows-Embarcadero.cmake +++ b/Modules/Platform/Windows-Embarcadero.cmake @@ -65,9 +65,9 @@ set (CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.") foreach(t EXE SHARED MODULE) - set(CMAKE_${t}_LINKER_FLAGS_INIT "${_tM} -lS:1048576 -lSc:4098 -lH:1048576 -lHc:8192 ") - set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "-v") - set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "-v") + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " ${_tM} -lS:1048576 -lSc:4098 -lH:1048576 -lHc:8192 ") + string(APPEND CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT " -v") + string(APPEND CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT " -v") endforeach() # The Borland link tool does not support multiple concurrent diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 4184675cb..14d4c9b81 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -252,15 +252,15 @@ endif() foreach(t EXE SHARED MODULE) string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " ${_MACHINE_ARCH_FLAG}") if (CMAKE_COMPILER_SUPPORTS_PDBTYPE) - set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") - set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") + string(APPEND CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT " /debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") + string(APPEND CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT " /debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}") else () - set(CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") - set(CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}") + string(APPEND CMAKE_${t}_LINKER_FLAGS_DEBUG_INIT " /debug ${MSVC_INCREMENTAL_YES_FLAG}") + string(APPEND CMAKE_${t}_LINKER_FLAGS_RELWITHDEBINFO_INIT " /debug ${MSVC_INCREMENTAL_YES_FLAG}") endif () # for release and minsize release default to no incremental linking - set(CMAKE_${t}_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO") - set(CMAKE_${t}_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO") + string(APPEND CMAKE_${t}_LINKER_FLAGS_MINSIZEREL_INIT " /INCREMENTAL:NO") + string(APPEND CMAKE_${t}_LINKER_FLAGS_RELEASE_INIT " /INCREMENTAL:NO") endforeach() string(APPEND CMAKE_STATIC_LINKER_FLAGS_INIT " ${_MACHINE_ARCH_FLAG}") diff --git a/Modules/Platform/Windows-OpenWatcom.cmake b/Modules/Platform/Windows-OpenWatcom.cmake index 269f9230b..7419fe4d6 100644 --- a/Modules/Platform/Windows-OpenWatcom.cmake +++ b/Modules/Platform/Windows-OpenWatcom.cmake @@ -32,14 +32,14 @@ else() set(CMAKE_LIB_QUIET "-q") endif() -set(CMAKE_EXE_LINKER_FLAGS_INIT) +string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ") set(CMAKE_CREATE_WIN32_EXE "system nt_win" ) set(CMAKE_CREATE_CONSOLE_EXE "system nt" ) -set(CMAKE_SHARED_LINKER_FLAGS_INIT "system nt_dll") -set(CMAKE_MODULE_LINKER_FLAGS_INIT "system nt_dll") +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) - set(CMAKE_${type}_LINKER_FLAGS_DEBUG_INIT "debug all opt map") - set(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO_INIT "debug all opt map") + 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 diff --git a/Tests/RunCMake/ToolchainFile/LinkFlagsInit-stdout.txt b/Tests/RunCMake/ToolchainFile/LinkFlagsInit-stdout.txt new file mode 100644 index 000000000..0ddf7d2a3 --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/LinkFlagsInit-stdout.txt @@ -0,0 +1,60 @@ +-- CMAKE_EXE_LINKER_FLAGS='[^ +]*MY_EXE_FLAGS_INIT[^ +]*' +-- CMAKE_EXE_LINKER_FLAGS_DEBUG='[^ +]*MY_EXE_FLAGS_DEBUG_INIT[^ +]*' +-- CMAKE_EXE_LINKER_FLAGS_RELEASE='[^ +]*MY_EXE_FLAGS_RELEASE_INIT[^ +]*' +-- CMAKE_EXE_LINKER_FLAGS_MINSIZEREL='[^ +]*MY_EXE_FLAGS_MINSIZEREL_INIT[^ +]*' +-- CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO='[^ +]*MY_EXE_FLAGS_RELWITHDEBINFO_INIT[^ +]*' +-- CMAKE_SHARED_LINKER_FLAGS='[^ +]*MY_SHARED_FLAGS_INIT[^ +]*' +-- CMAKE_SHARED_LINKER_FLAGS_DEBUG='[^ +]*MY_SHARED_FLAGS_DEBUG_INIT[^ +]*' +-- CMAKE_SHARED_LINKER_FLAGS_RELEASE='[^ +]*MY_SHARED_FLAGS_RELEASE_INIT[^ +]*' +-- CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL='[^ +]*MY_SHARED_FLAGS_MINSIZEREL_INIT[^ +]*' +-- CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO='[^ +]*MY_SHARED_FLAGS_RELWITHDEBINFO_INIT[^ +]*' +-- CMAKE_MODULE_LINKER_FLAGS='[^ +]*MY_MODULE_FLAGS_INIT[^ +]*' +-- CMAKE_MODULE_LINKER_FLAGS_DEBUG='[^ +]*MY_MODULE_FLAGS_DEBUG_INIT[^ +]*' +-- CMAKE_MODULE_LINKER_FLAGS_RELEASE='[^ +]*MY_MODULE_FLAGS_RELEASE_INIT[^ +]*' +-- CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL='[^ +]*MY_MODULE_FLAGS_MINSIZEREL_INIT[^ +]*' +-- CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO='[^ +]*MY_MODULE_FLAGS_RELWITHDEBINFO_INIT[^ +]*' +-- CMAKE_STATIC_LINKER_FLAGS='[^ +]*MY_STATIC_FLAGS_INIT[^ +]*' +-- CMAKE_STATIC_LINKER_FLAGS_DEBUG='[^ +]*MY_STATIC_FLAGS_DEBUG_INIT[^ +]*' +-- CMAKE_STATIC_LINKER_FLAGS_RELEASE='[^ +]*MY_STATIC_FLAGS_RELEASE_INIT[^ +]*' +-- CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL='[^ +]*MY_STATIC_FLAGS_MINSIZEREL_INIT[^ +]*' +-- CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO='[^ +]*MY_STATIC_FLAGS_RELWITHDEBINFO_INIT[^ +]*' diff --git a/Tests/RunCMake/ToolchainFile/LinkFlagsInit-toolchain.cmake b/Tests/RunCMake/ToolchainFile/LinkFlagsInit-toolchain.cmake new file mode 100644 index 000000000..ca908ae84 --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/LinkFlagsInit-toolchain.cmake @@ -0,0 +1,5 @@ +foreach(t EXE SHARED MODULE STATIC) + foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO) + set(CMAKE_${t}_LINKER_FLAGS${c}_INIT MY_${t}_FLAGS${c}_INIT) + endforeach() +endforeach() diff --git a/Tests/RunCMake/ToolchainFile/LinkFlagsInit.cmake b/Tests/RunCMake/ToolchainFile/LinkFlagsInit.cmake new file mode 100644 index 000000000..069d7410e --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/LinkFlagsInit.cmake @@ -0,0 +1,7 @@ +set(CMAKE_C_COMPILER_FORCED 1) # skip compiler test so we can check cached values +enable_language(C) +foreach(t EXE SHARED MODULE STATIC) + foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO) + message(STATUS "CMAKE_${t}_LINKER_FLAGS${c}='${CMAKE_${t}_LINKER_FLAGS${c}}'") + endforeach() +endforeach() diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake index 88c82164f..8a202008f 100644 --- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake +++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake @@ -8,3 +8,4 @@ endfunction() run_cmake_toolchain(CallEnableLanguage) run_cmake_toolchain(CallProject) run_cmake_toolchain(FlagsInit) +run_cmake_toolchain(LinkFlagsInit)