mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 19:00:54 -06:00
LINK_OPTIONS: Add support of "LINKER:" prefix
This commit is contained in:
10
Help/command/LINK_OPTIONS_LINKER.txt
Normal file
10
Help/command/LINK_OPTIONS_LINKER.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
To pass options to the linker tool, each compiler driver has is own syntax.
|
||||
The ``LINKER:`` prefix can be used to specify, in a portable way, options
|
||||
to pass to the linker tool. The ``LINKER:`` prefix is replaced by the required
|
||||
driver option and the rest of the option string defines linker arguments using
|
||||
``,`` as separator. These arguments will be formatted according to the
|
||||
:variable:`CMAKE_<LANG>_LINKER_WRAPPER_FLAG` and
|
||||
:variable:`CMAKE_<LANG>_LINKER_WRAPPER_FLAG_SEP` variables.
|
||||
|
||||
For example, ``"LINKER:-z,defs"`` becomes ``-Xlinker -z -Xlinker defs`` for
|
||||
``Clang`` and ``-Wl,-z,defs`` for ``GNU GCC``.
|
||||
@@ -7,12 +7,12 @@ Adds options to the link of targets.
|
||||
|
||||
add_link_options(<option> ...)
|
||||
|
||||
Adds options to the linker command line for targets in the current
|
||||
directory and below that are added after this command is invoked.
|
||||
See documentation of the :prop_dir:`directory <LINK_OPTIONS>` and
|
||||
Adds options to the link step for targets in the current directory and below
|
||||
that are added after this command is invoked. See documentation of the
|
||||
:prop_dir:`directory <LINK_OPTIONS>` and
|
||||
:prop_tgt:`target <LINK_OPTIONS>` ``LINK_OPTIONS`` properties.
|
||||
|
||||
This command can be used to add any options, but alternative command
|
||||
This command can be used to add any options, but alternative commands
|
||||
exist to add libraries (:command:`target_link_libraries` or
|
||||
:command:`link_libraries`).
|
||||
|
||||
@@ -21,4 +21,6 @@ the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
|
||||
manual for available expressions. See the :manual:`cmake-buildsystem(7)`
|
||||
manual for more on defining buildsystem properties.
|
||||
|
||||
.. include:: LINK_OPTIONS_LINKER.txt
|
||||
|
||||
.. include:: OPTIONS_SHELL.txt
|
||||
|
||||
@@ -29,7 +29,7 @@ items will populate the :prop_tgt:`LINK_OPTIONS` property of
|
||||
``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
|
||||
:prop_tgt:`INTERFACE_LINK_OPTIONS` property of ``<target>``.
|
||||
(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
|
||||
The following arguments specify compile options. Repeated calls for the same
|
||||
The following arguments specify link options. Repeated calls for the same
|
||||
``<target>`` append items in the order called.
|
||||
|
||||
Arguments to ``target_link_options`` may use "generator expressions"
|
||||
@@ -37,4 +37,6 @@ with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
|
||||
manual for available expressions. See the :manual:`cmake-buildsystem(7)`
|
||||
manual for more on defining buildsystem properties.
|
||||
|
||||
.. include:: LINK_OPTIONS_LINKER.txt
|
||||
|
||||
.. include:: OPTIONS_SHELL.txt
|
||||
|
||||
@@ -460,6 +460,8 @@ Variables for Languages
|
||||
/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE
|
||||
/variable/CMAKE_LANG_LINKER_PREFERENCE
|
||||
/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES
|
||||
/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG
|
||||
/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG_SEP
|
||||
/variable/CMAKE_LANG_LINK_EXECUTABLE
|
||||
/variable/CMAKE_LANG_OUTPUT_EXTENSION
|
||||
/variable/CMAKE_LANG_PLATFORM_ID
|
||||
|
||||
@@ -3,9 +3,9 @@ LINK_OPTIONS
|
||||
|
||||
* CMake gained new capabilities to manage link step:
|
||||
|
||||
* :prop_dir:`LINK_OPTIONS` directory property
|
||||
* :prop_dir:`LINK_OPTIONS` directory property.
|
||||
* :prop_tgt:`LINK_OPTIONS` and :prop_tgt:`INTERFACE_LINK_OPTIONS` target
|
||||
properties
|
||||
properties.
|
||||
* :command:`add_link_options` command to add link options in the current
|
||||
directory
|
||||
* :command:`target_link_options` command to add link options to targets
|
||||
directory.
|
||||
* :command:`target_link_options` command to add link options to targets.
|
||||
|
||||
39
Help/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG.rst
Normal file
39
Help/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG.rst
Normal file
@@ -0,0 +1,39 @@
|
||||
CMAKE_<LANG>_LINKER_WRAPPER_FLAG
|
||||
--------------------------------
|
||||
|
||||
Defines the syntax of compiler driver option to pass options to the linker
|
||||
tool. It will be used to translate the ``LINKER:`` prefix in the link options
|
||||
(see :command:`add_link_options` and :command:`target_link_options`).
|
||||
|
||||
This variable holds a :ref:`;-list <CMake Language Lists>` of tokens.
|
||||
If a space (i.e. " ") is specified as last token, flag and ``LINKER:``
|
||||
arguments will be specified as separate arguments to the compiler driver.
|
||||
The :variable:`CMAKE_<LANG>_LINKER_WRAPPER_FLAG_SEP` variable can be specified
|
||||
to manage concatenation of arguments.
|
||||
|
||||
For example, for ``Clang`` we have:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set (CMAKE_C_LINKER_WRAPPER_FLAG "-Xlinker" " ")
|
||||
|
||||
Specifying ``"LINKER:-z defs"`` will be transformed in
|
||||
``-Xlinker -z -Xlinker defs``.
|
||||
|
||||
For ``GNU GCC``:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set (CMAKE_C_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set (CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
Specifying ``"LINKER:-z defs"`` will be transformed in ``-Wl,-z,defs``.
|
||||
|
||||
And for ``SunPro``:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set (CMAKE_C_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
|
||||
set (CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
Specifying ``"LINKER:-z defs"`` will be transformed in ``-Qoption ld -z,defs``.
|
||||
9
Help/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG_SEP.rst
Normal file
9
Help/variable/CMAKE_LANG_LINKER_WRAPPER_FLAG_SEP.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
CMAKE_<LANG>_LINKER_WRAPPER_FLAG_SEP
|
||||
------------------------------------
|
||||
|
||||
This variable is used with :variable:`CMAKE_<LANG>_LINKER_WRAPPER_FLAG`
|
||||
variable to format ``LINKER:`` prefix in the link options
|
||||
(see :command:`add_link_options` and :command:`target_link_options`).
|
||||
|
||||
When specified, arguments of the ``LINKER:`` prefix will be concatenated using
|
||||
this value as separator.
|
||||
@@ -34,4 +34,6 @@ macro(__compiler_armcc lang)
|
||||
set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> --create -cr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
|
||||
set(CMAKE_DEPFILE_FLAGS_${lang} "--depend=<DEPFILE> --depend_single_line --no_depend_system_headers")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
|
||||
endmacro()
|
||||
|
||||
@@ -8,3 +8,4 @@ set(CMAKE_Fortran_MODPATH_FLAG "-p")
|
||||
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
||||
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed")
|
||||
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree")
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-X")
|
||||
|
||||
@@ -5,3 +5,5 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -g")
|
||||
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
|
||||
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-X")
|
||||
|
||||
@@ -30,6 +30,8 @@ else()
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
|
||||
endif()
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP)
|
||||
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
|
||||
@@ -7,3 +7,5 @@ set(CMAKE_Fortran_MODDIR_FLAG "-fmod=")
|
||||
set(CMAKE_Fortran_VERBOSE_FLAG "-v")
|
||||
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
|
||||
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
@@ -24,6 +24,9 @@ macro(__compiler_gnu lang)
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
# Older versions of gcc (< 4.5) contain a bug causing them to report a missing
|
||||
# header file as a warning if depfiles are enabled, causing check_header_file
|
||||
# tests to always succeed. Work around this by disabling dependency tracking
|
||||
|
||||
@@ -2,3 +2,6 @@ set(CMAKE_C_VERBOSE_FLAG "-v")
|
||||
|
||||
set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||
set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
@@ -3,6 +3,9 @@ set(CMAKE_CXX_VERBOSE_FLAG "-v")
|
||||
set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||
set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
# HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98
|
||||
# template support. It is known that version 6.25 doesn't need that flag.
|
||||
# Current assumption: the flag is needed for every version from 3.80 to 4
|
||||
|
||||
@@ -4,3 +4,6 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "+source=free")
|
||||
|
||||
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG ",")
|
||||
|
||||
@@ -25,6 +25,9 @@ macro(__compiler_pgi lang)
|
||||
string(APPEND CMAKE_${lang}_FLAGS_INIT " -Bdynamic")
|
||||
endif()
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG ",")
|
||||
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le AND (NOT CMAKE_HOST_WIN32 OR CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 16.3))
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
|
||||
@@ -13,6 +13,9 @@ macro(__compiler_qcc lang)
|
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-Wp,-isystem,")
|
||||
set(CMAKE_DEPFILE_FLAGS_${lang} "-Wc,-MD,<DEPFILE>,-MT,<OBJECT>,-MF,<DEPFILE>")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE NO)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
|
||||
|
||||
@@ -15,4 +15,7 @@ macro(__compiler_sco lang)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_DLL -belf)
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-Kpic -belf")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-belf -Wl,-Bexport")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
endmacro()
|
||||
|
||||
@@ -29,6 +29,9 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
|
||||
set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Bdynamic")
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.13)
|
||||
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89")
|
||||
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=c89")
|
||||
|
||||
@@ -29,6 +29,9 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
|
||||
set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS "-Bdynamic")
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
|
||||
set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -g -xO2 -DNDEBUG")
|
||||
set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
|
||||
set(CMAKE_Fortran_MODPATH_FLAG "-M")
|
||||
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
|
||||
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(CMAKE_Fortran_PREPROCESS_SOURCE
|
||||
"<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -F -fpp <SOURCE> -o <PREPROCESSED_SOURCE>")
|
||||
|
||||
|
||||
@@ -6,3 +6,6 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -g")
|
||||
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
|
||||
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
@@ -23,6 +23,9 @@ macro(__compiler_xl lang)
|
||||
set(CMAKE_${lang}_RESPONSE_FILE_FLAG "-qoptfile=")
|
||||
set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-qoptfile=")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
|
||||
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O")
|
||||
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O")
|
||||
|
||||
@@ -10,6 +10,9 @@ macro(__apple_compiler_intel lang)
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
|
||||
set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0)
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
|
||||
endif()
|
||||
|
||||
@@ -9,6 +9,9 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " ")
|
||||
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " ")
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-flags-link" " ")
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(CMAKE_C_CREATE_STATIC_LIBRARY
|
||||
"<CMAKE_C_COMPILER> -build-lib -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -o <TARGET> <CMAKE_C_LINK_FLAGS> <OBJECTS>")
|
||||
|
||||
@@ -17,4 +20,3 @@ set(CMAKE_C_LINK_EXECUTABLE
|
||||
|
||||
set(CMAKE_C_CREATE_SHARED_LIBRARY)
|
||||
set(CMAKE_C_CREATE_MODULE_LIBRARY)
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " ")
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ")
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " ")
|
||||
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-flags-link" " ")
|
||||
set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(CMAKE_CXX_CREATE_STATIC_LIBRARY
|
||||
"<CMAKE_CXX_COMPILER> -build-lib -proc ${ADSP_PROCESSOR} -si-revision ${ADSP_PROCESSOR_SILICIUM_REVISION} -o <TARGET> <CMAKE_CXX_LINK_FLAGS> <OBJECTS>")
|
||||
|
||||
@@ -15,4 +18,3 @@ set(CMAKE_CXX_LINK_EXECUTABLE
|
||||
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY)
|
||||
set(CMAKE_CXX_CREATE_MODULE_LIBRARY)
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
|
||||
set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl" ",")
|
||||
|
||||
# compile a C file into an object file
|
||||
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
||||
|
||||
@@ -51,4 +53,3 @@ set(CMAKE_C_CREATE_STATIC_LIBRARY
|
||||
# not supported by sdcc
|
||||
set(CMAKE_C_CREATE_SHARED_LIBRARY "")
|
||||
set(CMAKE_C_CREATE_MODULE_LIBRARY "")
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ macro(__linux_compiler_intel lang)
|
||||
# executables that use dlopen but do not set ENABLE_EXPORTS.
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
|
||||
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
|
||||
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
|
||||
if(XIAR)
|
||||
|
||||
@@ -76,6 +76,8 @@ macro(__embarcadero_language lang)
|
||||
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}") # ... while this is a space separated string.
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
|
||||
|
||||
set (CMAKE_${lang}_LINKER_WRAPPER_FLAG "-l")
|
||||
|
||||
# compile a source file into an object file
|
||||
# place <DEFINES> outside the response file because Borland refuses
|
||||
# to parse quotes from the response file.
|
||||
|
||||
@@ -2861,7 +2861,8 @@ void cmGeneratorTarget::GetCompileDefinitions(
|
||||
cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
|
||||
}
|
||||
|
||||
static void processLinkOptions(
|
||||
namespace {
|
||||
void processLinkOptions(
|
||||
cmGeneratorTarget const* tgt,
|
||||
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
|
||||
std::vector<std::string>& options,
|
||||
@@ -2873,6 +2874,7 @@ static void processLinkOptions(
|
||||
config, debugOptions, "link options", language,
|
||||
OptionsParse::Shell);
|
||||
}
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
|
||||
const std::string& config,
|
||||
@@ -2912,6 +2914,98 @@ void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
|
||||
language);
|
||||
|
||||
cmDeleteAll(linkInterfaceLinkOptionsEntries);
|
||||
|
||||
// Last step: replace "LINKER:" prefixed elements by
|
||||
// actual linker wrapper
|
||||
const std::string wrapper(this->Makefile->GetSafeDefinition(
|
||||
"CMAKE_" + language + "_LINKER_WRAPPER_FLAG"));
|
||||
std::vector<std::string> wrapperFlag;
|
||||
cmSystemTools::ExpandListArgument(wrapper, wrapperFlag);
|
||||
const std::string wrapperSep(this->Makefile->GetSafeDefinition(
|
||||
"CMAKE_" + language + "_LINKER_WRAPPER_FLAG_SEP"));
|
||||
bool concatFlagAndArgs = true;
|
||||
if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
|
||||
concatFlagAndArgs = false;
|
||||
wrapperFlag.pop_back();
|
||||
}
|
||||
|
||||
const std::string LINKER{ "LINKER:" };
|
||||
const std::string SHELL{ "SHELL:" };
|
||||
const std::string LINKER_SHELL = LINKER + SHELL;
|
||||
|
||||
std::vector<std::string>::iterator entry;
|
||||
while ((entry = std::find_if(result.begin(), result.end(),
|
||||
[&LINKER](const std::string& item) -> bool {
|
||||
return item.compare(0, LINKER.length(),
|
||||
LINKER) == 0;
|
||||
})) != result.end()) {
|
||||
std::vector<std::string> linkerOptions;
|
||||
if (entry->compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
|
||||
cmSystemTools::ParseUnixCommandLine(
|
||||
entry->c_str() + LINKER_SHELL.length(), linkerOptions);
|
||||
} else {
|
||||
linkerOptions =
|
||||
cmSystemTools::tokenize(entry->substr(LINKER.length()), ",");
|
||||
}
|
||||
entry = result.erase(entry);
|
||||
|
||||
if (linkerOptions.empty() ||
|
||||
(linkerOptions.size() == 1 && linkerOptions.front().empty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// for now, raise an error if prefix SHELL: is part of arguments
|
||||
if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
|
||||
[&SHELL](const std::string& item) -> bool {
|
||||
return item.find(SHELL) != std::string::npos;
|
||||
}) != linkerOptions.end()) {
|
||||
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
|
||||
cmake::FATAL_ERROR,
|
||||
"'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
|
||||
this->GetBacktrace());
|
||||
return;
|
||||
}
|
||||
|
||||
if (wrapperFlag.empty()) {
|
||||
// nothing specified, insert elements as is
|
||||
result.insert(entry, linkerOptions.begin(), linkerOptions.end());
|
||||
} else {
|
||||
std::vector<std::string> options;
|
||||
|
||||
if (!wrapperSep.empty()) {
|
||||
if (concatFlagAndArgs) {
|
||||
// insert flag elements except last one
|
||||
options.insert(options.end(), wrapperFlag.begin(),
|
||||
wrapperFlag.end() - 1);
|
||||
// concatenate last flag element and all LINKER list values
|
||||
// in one option
|
||||
options.push_back(wrapperFlag.back() +
|
||||
cmJoin(linkerOptions, wrapperSep));
|
||||
} else {
|
||||
options.insert(options.end(), wrapperFlag.begin(),
|
||||
wrapperFlag.end());
|
||||
// concatenate all LINKER list values in one option
|
||||
options.push_back(cmJoin(linkerOptions, wrapperSep));
|
||||
}
|
||||
} else {
|
||||
// prefix each element of LINKER list with wrapper
|
||||
if (concatFlagAndArgs) {
|
||||
std::transform(
|
||||
linkerOptions.begin(), linkerOptions.end(), linkerOptions.begin(),
|
||||
[&wrapperFlag](const std::string& value) -> std::string {
|
||||
return wrapperFlag.back() + value;
|
||||
});
|
||||
}
|
||||
for (const auto& value : linkerOptions) {
|
||||
options.insert(options.end(), wrapperFlag.begin(),
|
||||
concatFlagAndArgs ? wrapperFlag.end() - 1
|
||||
: wrapperFlag.end());
|
||||
options.push_back(value);
|
||||
}
|
||||
}
|
||||
result.insert(entry, options.begin(), options.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
set (LINKER_OPTION "LINKER:SHELL:-foo bar")
|
||||
|
||||
include ("LINKER_expansion-list.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
36
Tests/RunCMake/add_link_options/LINKER_expansion-list.cmake
Normal file
36
Tests/RunCMake/add_link_options/LINKER_expansion-list.cmake
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_executable(dump dump.c)
|
||||
|
||||
add_link_options("${LINKER_OPTION}")
|
||||
|
||||
# ensure no temp file will be used
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
|
||||
|
||||
add_library(example SHARED LinkOptionsLib.c)
|
||||
# use LAUNCH facility to dump linker command
|
||||
set_property(TARGET example PROPERTY RULE_LAUNCH_LINK "\"${CMAKE_CURRENT_BINARY_DIR}/dump${CMAKE_EXECUTABLE_SUFFIX}\"")
|
||||
|
||||
add_dependencies (example dump)
|
||||
|
||||
# generate reference for LINKER flag
|
||||
if (CMAKE_C_LINKER_WRAPPER_FLAG)
|
||||
set(linker_flag ${CMAKE_C_LINKER_WRAPPER_FLAG})
|
||||
list(GET linker_flag -1 linker_space)
|
||||
if (linker_space STREQUAL " ")
|
||||
list(REMOVE_AT linker_flag -1)
|
||||
else()
|
||||
set(linker_space)
|
||||
endif()
|
||||
list (JOIN linker_flag " " linker_flag)
|
||||
if (CMAKE_C_LINKER_WRAPPER_FLAG_SEP)
|
||||
string (APPEND linker_flag "${linker_space}" "-foo${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}bar")
|
||||
else()
|
||||
set (linker_flag "${linker_flag}${linker_space}-foo ${linker_flag}${linker_space}bar")
|
||||
endif()
|
||||
else()
|
||||
set(linker_flag "-foo bar")
|
||||
endif()
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}")
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
if (actual_stdout MATCHES "(LINKER|SHELL):")
|
||||
set (RunCMake_TEST_FAILED "LINKER: prefix was not expanded.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/LINKER.txt")
|
||||
set (RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/LINKER.txt: Reference file not found.")
|
||||
return()
|
||||
endif()
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/LINKER.txt" linker_flag)
|
||||
|
||||
if (NOT actual_stdout MATCHES "${linker_flag}")
|
||||
set (RunCMake_TEST_FAILED "LINKER: was not expanded correctly.")
|
||||
endif()
|
||||
4
Tests/RunCMake/add_link_options/LINKER_expansion.cmake
Normal file
4
Tests/RunCMake/add_link_options/LINKER_expansion.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
set (LINKER_OPTION "LINKER:-foo,bar")
|
||||
|
||||
include ("LINKER_expansion-list.cmake")
|
||||
@@ -26,3 +26,13 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
unset(RunCMake_TEST_OPTIONS)
|
||||
unset(RunCMake_TEST_OUTPUT_MERGE)
|
||||
endif()
|
||||
|
||||
run_cmake(bad_SHELL_usage)
|
||||
|
||||
if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)")
|
||||
run_cmake(LINKER_expansion)
|
||||
run_cmake_target(LINKER_expansion build all)
|
||||
|
||||
run_cmake(LINKER_SHELL_expansion)
|
||||
run_cmake_target(LINKER_SHELL_expansion build all)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,4 @@
|
||||
CMake Error at bad_SHELL_usage.cmake:6 \(add_library\):
|
||||
'SHELL:' prefix is not supported as part of 'LINKER:' arguments.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:5 \(include\)
|
||||
6
Tests/RunCMake/add_link_options/bad_SHELL_usage.cmake
Normal file
6
Tests/RunCMake/add_link_options/bad_SHELL_usage.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_link_options("LINKER:-foo,SHELL:-bar")
|
||||
|
||||
add_library(example SHARED LinkOptionsLib.c)
|
||||
13
Tests/RunCMake/add_link_options/dump.c
Normal file
13
Tests/RunCMake/add_link_options/dump.c
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
printf("%s ", argv[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
if (actual_stdout MATCHES "LINKER:")
|
||||
set (RunCMake_TEST_FAILED "LINKER: prefix was not expanded.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/LINKER.txt")
|
||||
set (RunCMake_TEST_FAILED "${RunCMake_TEST_BINARY_DIR}/LINKER.txt: Reference file not found.")
|
||||
return()
|
||||
endif()
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/LINKER.txt" linker_flag)
|
||||
|
||||
if (NOT actual_stdout MATCHES "${linker_flag}")
|
||||
set (RunCMake_TEST_FAILED "LINKER: was not expanded correctly.")
|
||||
endif()
|
||||
49
Tests/RunCMake/target_link_options/LINKER_expansion.cmake
Normal file
49
Tests/RunCMake/target_link_options/LINKER_expansion.cmake
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_executable(dump dump.c)
|
||||
|
||||
# ensure no temp file will be used
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
|
||||
|
||||
|
||||
# Use LINKER alone
|
||||
add_library(linker SHARED LinkOptionsLib.c)
|
||||
target_link_options(linker PRIVATE "LINKER:-foo,bar")
|
||||
|
||||
# use LAUNCH facility to dump linker command
|
||||
set_property(TARGET linker PROPERTY RULE_LAUNCH_LINK "\"${CMAKE_CURRENT_BINARY_DIR}/dump${CMAKE_EXECUTABLE_SUFFIX}\"")
|
||||
|
||||
add_dependencies (linker dump)
|
||||
|
||||
|
||||
# Use LINKER with SHELL
|
||||
add_library(linker_shell SHARED LinkOptionsLib.c)
|
||||
target_link_options(linker_shell PRIVATE "LINKER:SHELL:-foo bar")
|
||||
|
||||
# use LAUNCH facility to dump linker command
|
||||
set_property(TARGET linker_shell PROPERTY RULE_LAUNCH_LINK "\"${CMAKE_CURRENT_BINARY_DIR}/dump${CMAKE_EXECUTABLE_SUFFIX}\"")
|
||||
|
||||
add_dependencies (linker_shell dump)
|
||||
|
||||
|
||||
# generate reference for LINKER flag
|
||||
if (CMAKE_C_LINKER_WRAPPER_FLAG)
|
||||
set(linker_flag ${CMAKE_C_LINKER_WRAPPER_FLAG})
|
||||
list(GET linker_flag -1 linker_space)
|
||||
if (linker_space STREQUAL " ")
|
||||
list(REMOVE_AT linker_flag -1)
|
||||
else()
|
||||
set(linker_space)
|
||||
endif()
|
||||
list (JOIN linker_flag " " linker_flag)
|
||||
if (CMAKE_C_LINKER_WRAPPER_FLAG_SEP)
|
||||
string (APPEND linker_flag "${linker_space}" "-foo${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}bar")
|
||||
else()
|
||||
set (linker_flag "${linker_flag}${linker_space}-foo ${linker_flag}${linker_space}bar")
|
||||
endif()
|
||||
else()
|
||||
set(linker_flag "-foo bar")
|
||||
endif()
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}")
|
||||
@@ -29,34 +29,11 @@ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
unset(RunCMake_TEST_OUTPUT_MERGE)
|
||||
endif()
|
||||
|
||||
run_cmake(bad_SHELL_usage)
|
||||
|
||||
# include(RunCMake)
|
||||
if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)")
|
||||
run_cmake(LINKER_expansion)
|
||||
|
||||
# macro(run_cmake_build test)
|
||||
# run_cmake(${test})
|
||||
|
||||
# set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
|
||||
# set(RunCMake_TEST_NO_CLEAN 1)
|
||||
# run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . ${ARGN})
|
||||
|
||||
# unset(RunCMake_TEST_BINARY_DIR)
|
||||
# unset(RunCMake_TEST_NO_CLEAN)
|
||||
# endmacro()
|
||||
|
||||
# if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
# # Intel compiler does not reject bad flags or objects!
|
||||
# set(RunCMake_TEST_OUTPUT_MERGE TRUE)
|
||||
|
||||
# run_cmake_build(LINK_OPTIONS)
|
||||
# run_cmake_build(INTERFACE_LINK_OPTIONS)
|
||||
|
||||
# if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
|
||||
# set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
|
||||
# endif()
|
||||
# run_cmake_build(LINK_OPTIONS_shared --config Release)
|
||||
# run_cmake_build(LINK_OPTIONS_mod --config Release)
|
||||
# run_cmake_build(LINK_OPTIONS_exe --config Release)
|
||||
# unset(RunCMake_TEST_OPTIONS)
|
||||
|
||||
# unset(RunCMake_TEST_OUTPUT_MERGE)
|
||||
# endif()
|
||||
run_cmake_target(LINKER_expansion LINKER linker)
|
||||
run_cmake_target(LINKER_expansion LINKER_SHELL linker_shell)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,4 @@
|
||||
CMake Error at bad_SHELL_usage.cmake:4 \(add_library\):
|
||||
'SHELL:' prefix is not supported as part of 'LINKER:' arguments.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:5 \(include\)
|
||||
5
Tests/RunCMake/target_link_options/bad_SHELL_usage.cmake
Normal file
5
Tests/RunCMake/target_link_options/bad_SHELL_usage.cmake
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_library(example SHARED LinkOptionsLib.c)
|
||||
target_link_options(example PRIVATE "LINKER:-foo,SHELL:-bar")
|
||||
13
Tests/RunCMake/target_link_options/dump.c
Normal file
13
Tests/RunCMake/target_link_options/dump.c
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
printf("%s ", argv[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user