mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-03 20:29:56 -06:00
Merge topic 'LINKER_TYPE-mold-support'
801ae06952LINKER_TYPE: Support MOLD only on GCC versions that support it939ac5287eLINKER_TYPE: fix spelling error in message922883782bLINKER_TYPE: Document that linker tool should be in the PATH Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9334
This commit is contained in:
@@ -9,6 +9,12 @@ property :prop_tgt:`LINKER_TYPE`. It can hold compiler flags for the link step
|
||||
or directly the linker tool. The type of data is given by the variable
|
||||
:variable:`CMAKE_<LANG>_USING_LINKER_MODE`.
|
||||
|
||||
.. note::
|
||||
|
||||
The specified linker tool is expected to be accessible through
|
||||
the ``PATH`` environment variable, particularly when the
|
||||
:variable:`CMAKE_<LANG>_USING_LINKER_MODE` variable is set to ``FLAG``.
|
||||
|
||||
For example, to specify the ``LLVM`` linker for ``GNU`` compilers, we have:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
@@ -20,5 +20,8 @@ macro(__linux_compiler_gnu lang)
|
||||
set(CMAKE_${lang}_USING_LINKER_LLD "-fuse-ld=lld")
|
||||
set(CMAKE_${lang}_USING_LINKER_BFD "-fuse-ld=bfd")
|
||||
set(CMAKE_${lang}_USING_LINKER_GOLD "-fuse-ld=gold")
|
||||
set(CMAKE_${lang}_USING_LINKER_MOLD "-fuse-ld=mold")
|
||||
if(NOT CMAKE_${lang}_COMPILER_ID STREQUAL "GNU"
|
||||
OR CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL "12.1")
|
||||
set(CMAKE_${lang}_USING_LINKER_MOLD "-fuse-ld=mold")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
@@ -5585,11 +5586,22 @@ std::string cmGeneratorTarget::GetLinkerTool(const std::string& lang,
|
||||
linkerTool = this->Makefile->GetDefinition("CMAKE_LINKER");
|
||||
|
||||
if (linkerType != "DEFAULT"_s) {
|
||||
this->LocalGenerator->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown. Did you forgot to define '", usingLinker,
|
||||
"' variable?"));
|
||||
auto isCMakeLinkerType = [](const std::string& type) -> bool {
|
||||
return std::all_of(type.cbegin(), type.cend(),
|
||||
[](char c) { return std::isupper(c); });
|
||||
};
|
||||
if (isCMakeLinkerType(linkerType)) {
|
||||
this->LocalGenerator->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown or not supported by this toolchain."));
|
||||
} else {
|
||||
this->LocalGenerator->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown. Did you forget to define the '", usingLinker,
|
||||
"' variable?"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <initializer_list>
|
||||
@@ -3356,10 +3357,22 @@ void cmLocalGenerator::AppendLinkerTypeFlags(std::string& flags,
|
||||
this->AppendFlags(flags, linkerFlags);
|
||||
}
|
||||
} else if (linkerType != "DEFAULT"_s) {
|
||||
this->IssueMessage(MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown. Did you forgot to define '",
|
||||
usingLinker, "' variable?"));
|
||||
auto isCMakeLinkerType = [](const std::string& type) -> bool {
|
||||
return std::all_of(type.cbegin(), type.cend(),
|
||||
[](char c) { return std::isupper(c); });
|
||||
};
|
||||
if (isCMakeLinkerType(linkerType)) {
|
||||
this->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown or not supported by this toolchain."));
|
||||
} else {
|
||||
this->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("LINKER_TYPE '", linkerType,
|
||||
"' is unknown. Did you forget to define the '", usingLinker,
|
||||
"' variable?"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
CMake Error in CMakeLists.txt:
|
||||
LINKER_TYPE 'FOO' is unknown. Did you forgot to define
|
||||
'CMAKE_C_USING_LINKER_FOO' variable\?
|
||||
@@ -0,0 +1,2 @@
|
||||
CMake Error in CMakeLists.txt:
|
||||
LINKER_TYPE 'FOO' is unknown or not supported by this toolchain.
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,3 @@
|
||||
CMake Error in CMakeLists.txt:
|
||||
LINKER_TYPE 'foo' is unknown. Did you forget to define the
|
||||
'CMAKE_C_USING_LINKER_foo' variable\?
|
||||
5
Tests/RunCMake/LinkerSelection/InvalidLinkerType2.cmake
Normal file
5
Tests/RunCMake/LinkerSelection/InvalidLinkerType2.cmake
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
set(CMAKE_LINKER_TYPE foo)
|
||||
add_executable(main main.c)
|
||||
@@ -5,7 +5,8 @@ if (RunCMake_GENERATOR MATCHES "Visual Studio 9 2008")
|
||||
return()
|
||||
endif()
|
||||
|
||||
run_cmake(InvalidLinkerType)
|
||||
run_cmake(InvalidLinkerType1)
|
||||
run_cmake(InvalidLinkerType2)
|
||||
|
||||
# look-up for LLVM linker
|
||||
if (WIN32)
|
||||
|
||||
Reference in New Issue
Block a user