summaryrefslogtreecommitdiffstats
path: root/Source/cmCoreTryCompile.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-09-27 13:22:55 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2023-10-13 09:52:35 (GMT)
commit96a953b1ed7e41260aa0869bad0ff14c788cf57e (patch)
treed9bedd8494b073f3795e4ed80f01b22a2b5a9093 /Source/cmCoreTryCompile.cxx
parentee5f31ba727e392e1ebc9f5be54c74ac1868d029 (diff)
downloadCMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.zip
CMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.tar.gz
CMake-96a953b1ed7e41260aa0869bad0ff14c788cf57e.tar.bz2
Add options to specify linker tool
Offer the capability, through variable `CMAKE_LINKER_TYPE`, as well as the target property `LINKER_TYPE` to specify which linker must be used. The implementation of this capability is specified by variables specific to the language and linker type: `CMAKE_<LANG>_USING_LINKER_<TYPE>`. Some definitions are provided as part of `CMake`. For example, to select the `LLVM` linker rather than the standard one, the type `LLD` should be specified through the variable `CMAKE_LINKER_TYPE`. And, on `Apple`, `Linux` and some environments on `Windows`, the variable `CMAKE_<LANG>_USING_LINKER_LLD` has value `-fuse-ld=lld`. And for `Windows` environments based on `MSVC`, where the linker is used directly, the tool `lld-link.exe` will be used rather than `link.exe`. Fixes: #19174, #24254, #24990
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r--Source/cmCoreTryCompile.cxx16
1 files changed, 16 insertions, 0 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 7e19812..69d5ffc 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -14,6 +14,7 @@
#include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx"
+#include "cmsys/RegularExpression.hxx"
#include "cmArgumentParser.h"
#include "cmConfigureLog.h"
@@ -83,6 +84,7 @@ std::string const kCMAKE_HIP_PLATFORM = "CMAKE_HIP_PLATFORM";
std::string const kCMAKE_HIP_RUNTIME_LIBRARY = "CMAKE_HIP_RUNTIME_LIBRARY";
std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS";
std::string const kCMAKE_ISPC_HEADER_SUFFIX = "CMAKE_ISPC_HEADER_SUFFIX";
+std::string const kCMAKE_LINKER_TYPE = "CMAKE_LINKER_TYPE";
std::string const kCMAKE_LINK_SEARCH_END_STATIC =
"CMAKE_LINK_SEARCH_END_STATIC";
std::string const kCMAKE_LINK_SEARCH_START_STATIC =
@@ -1114,6 +1116,20 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
vars.insert(varList.begin(), varList.end());
}
+ if (this->Makefile->GetDefinition(kCMAKE_LINKER_TYPE)) {
+ // propagate various variables to support linker selection
+ vars.insert(kCMAKE_LINKER_TYPE);
+ auto defs = this->Makefile->GetDefinitions();
+ cmsys::RegularExpression linkerTypeDef{
+ "^CMAKE_[A-Za-z]+_USING_LINKER_"
+ };
+ for (auto const& def : defs) {
+ if (linkerTypeDef.find(def)) {
+ vars.insert(def);
+ }
+ }
+ }
+
if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) ==
cmPolicies::NEW) {
// To ensure full support of PIE, propagate cache variables