mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 13:19:51 -05:00
Merge topic 'LINKER-prefix-generalization'
61aee8c7bdAdd support of "LINKER:" prefix for Windows executable creation8bcf9c7a3eAdd support of "LINKER:" prefix for artifact creation flags2bd4c06c26Refactoring cmRulePlaceHolderExpander: propagate cmBuildStep information35350c419dAdd support of "LINKER:" prefix for CMAKE_<TYPE>_LINKER_FLAGS variable Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9922
This commit is contained in:
@@ -336,6 +336,10 @@ Other Behavior Settings
|
||||
The current settings of :policy:`CMP0065` and :policy:`CMP0083` are propagated
|
||||
through to the generated test project.
|
||||
|
||||
.. versionadded:: 3.32
|
||||
The current setting of :policy:`CMP0181` policy is propagated through to the
|
||||
generated test project.
|
||||
|
||||
Set variable :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` to choose a build
|
||||
configuration:
|
||||
|
||||
|
||||
@@ -51,6 +51,14 @@ The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used
|
||||
to determine whether to report an error on use of deprecated macros or
|
||||
functions.
|
||||
|
||||
Policies Introduced by CMake 3.32
|
||||
=================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
CMP0181: Link command-line fragment variables are parsed and re-quoted. </policy/CMP0181>
|
||||
|
||||
Policies Introduced by CMake 3.31
|
||||
=================================
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
CMP0181
|
||||
-------
|
||||
|
||||
.. versionadded:: 3.32
|
||||
|
||||
The :variable:`CMAKE_EXE_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_MODULE_LINKER_FLAGS`,
|
||||
and :variable:`CMAKE_MODULE_LINKER_FLAGS_<CONFIG>` variables are parsed and
|
||||
re-quoted and support the ``LINKER:`` prefix.
|
||||
|
||||
CMake 3.31 and below use the content of these variables as is.
|
||||
|
||||
CMake 3.32 and above parse the content of these variables and manage the
|
||||
escaping of special characters. Moreover, the ``LINKER:`` prefix is now
|
||||
recognized and expanded.
|
||||
|
||||
The ``OLD`` behavior of this policy is to consume the content of the
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_MODULE_LINKER_FLAGS`,
|
||||
and :variable:`CMAKE_MODULE_LINKER_FLAGS_<CONFIG>` variables as is.
|
||||
|
||||
The ``NEW`` behavior of this policy is to parse and re-quote the content of the
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_MODULE_LINKER_FLAGS`,
|
||||
and :variable:`CMAKE_MODULE_LINKER_FLAGS_<CONFIG>` variables as well as to
|
||||
expand the ``LINKER:`` prefix.
|
||||
|
||||
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.32
|
||||
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
|
||||
.. include:: STANDARD_ADVICE.txt
|
||||
|
||||
.. include:: DEPRECATED.txt
|
||||
@@ -0,0 +1,13 @@
|
||||
CMAKE_TYPE_LINKER_FLAGS-LINKER-prefix-support
|
||||
---------------------------------------------
|
||||
|
||||
* The :variable:`CMAKE_EXE_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_EXE_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS`,
|
||||
:variable:`CMAKE_SHARED_LINKER_FLAGS_<CONFIG>`,
|
||||
:variable:`CMAKE_MODULE_LINKER_FLAGS`,
|
||||
and :variable:`CMAKE_MODULE_LINKER_FLAGS_<CONFIG>` variables learned to
|
||||
support the ``LINKER:`` prefix.
|
||||
|
||||
This support implies to parse and re-quote the content of these variables.
|
||||
This parsing is controlled by :policy:`CMP0181` policy.
|
||||
@@ -4,3 +4,5 @@ CMAKE_EXE_LINKER_FLAGS
|
||||
Linker flags to be used to create executables.
|
||||
|
||||
These flags will be used by the linker when creating an executable.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -5,3 +5,5 @@ Flags to be used when linking an executable.
|
||||
|
||||
Same as ``CMAKE_C_FLAGS_*`` but used by the linker when creating
|
||||
executables.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -4,3 +4,5 @@ CMAKE_MODULE_LINKER_FLAGS
|
||||
Linker flags to be used to create modules.
|
||||
|
||||
These flags will be used by the linker when creating a module.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -4,3 +4,5 @@ CMAKE_MODULE_LINKER_FLAGS_<CONFIG>
|
||||
Flags to be used when linking a module.
|
||||
|
||||
Same as ``CMAKE_C_FLAGS_*`` but used by the linker when creating modules.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -4,3 +4,5 @@ CMAKE_SHARED_LINKER_FLAGS
|
||||
Linker flags to be used to create shared libraries.
|
||||
|
||||
These flags will be used by the linker when creating a shared library.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -5,3 +5,5 @@ Flags to be used when linking a shared library.
|
||||
|
||||
Same as ``CMAKE_C_FLAGS_*`` but used by the linker when creating shared
|
||||
libraries.
|
||||
|
||||
.. include:: ../variable/LINKER_FLAGS.txt
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
.. include:: ../command/LINK_LIBRARIES_LINKER.txt
|
||||
|
||||
This support implies to parse and re-quote the content of the variable. See
|
||||
policy :policy:`CMP0181`.
|
||||
@@ -910,6 +910,14 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
|
||||
? "OLD"
|
||||
: "NEW");
|
||||
|
||||
/* Set the appropriate policy information for the LINKER: prefix expansion
|
||||
*/
|
||||
fprintf(fout, "cmake_policy(SET CMP0181 %s)\n",
|
||||
this->Makefile->GetPolicyStatus(cmPolicies::CMP0181) ==
|
||||
cmPolicies::NEW
|
||||
? "NEW"
|
||||
: "OLD");
|
||||
|
||||
// Workaround for -Wl,-headerpad_max_install_names issue until we can avoid
|
||||
// adding that flag in the platform and compiler language files
|
||||
fprintf(fout,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#pragma once
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
/** Flag if byproducts shall also be considered. */
|
||||
enum class cmSourceOutputKind
|
||||
{
|
||||
OutputOnly,
|
||||
OutputOrByproduct
|
||||
};
|
||||
|
||||
/** What scanner to use for dependencies lookup. */
|
||||
enum class cmDependencyScannerKind
|
||||
{
|
||||
CMake,
|
||||
Compiler
|
||||
};
|
||||
|
||||
/** What to compute language flags for */
|
||||
enum class cmBuildStep
|
||||
{
|
||||
Compile,
|
||||
Link
|
||||
};
|
||||
|
||||
/** What compilation mode the swift files are in */
|
||||
enum class cmSwiftCompileMode
|
||||
{
|
||||
Wholemodule,
|
||||
Incremental,
|
||||
Singlefile,
|
||||
Unknown,
|
||||
};
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorExpressionDAGChecker.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmList.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmCustomCommandGenerator.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGhsMultiGenerator.h"
|
||||
#include "cmLinkLineComputer.h" // IWYU pragma: keep
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "cmCustomCommandTypes.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGeneratorFactory.h"
|
||||
#include "cmLinkItem.h"
|
||||
@@ -2538,7 +2539,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
}
|
||||
if (!extraLinkOptionsVar.empty()) {
|
||||
this->CurrentLocalGenerator->AddConfigVariableFlags(
|
||||
extraLinkOptions, extraLinkOptionsVar, configName);
|
||||
extraLinkOptions, extraLinkOptionsVar, gtgt, cmBuildStep::Link, llang,
|
||||
configName);
|
||||
}
|
||||
|
||||
if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY ||
|
||||
@@ -2693,7 +2695,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
// in many ways as an application bundle, as far as
|
||||
// link flags go
|
||||
std::string createFlags = this->LookupFlags(
|
||||
"CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS", "-bundle");
|
||||
"CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS", gtgt, "-bundle");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
@@ -2719,7 +2721,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
this->CreateString("NO"));
|
||||
// Add the flags to create an executable.
|
||||
std::string createFlags =
|
||||
this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", "");
|
||||
this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", gtgt, "");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
@@ -2748,8 +2750,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
this->CreateString(plist));
|
||||
} else {
|
||||
// Add the flags to create a shared library.
|
||||
std::string createFlags = this->LookupFlags(
|
||||
"CMAKE_SHARED_LIBRARY_CREATE_", llang, "_FLAGS", "-dynamiclib");
|
||||
std::string createFlags =
|
||||
this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", llang, "_FLAGS",
|
||||
gtgt, "-dynamiclib");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
@@ -2769,7 +2772,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
case cmStateEnums::EXECUTABLE: {
|
||||
// Add the flags to create an executable.
|
||||
std::string createFlags =
|
||||
this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", "");
|
||||
this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", gtgt, "");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
@@ -5207,13 +5210,17 @@ void cmGlobalXCodeGenerator::AppendDirectoryForConfig(
|
||||
|
||||
std::string cmGlobalXCodeGenerator::LookupFlags(
|
||||
const std::string& varNamePrefix, const std::string& varNameLang,
|
||||
const std::string& varNameSuffix, const std::string& default_flags)
|
||||
const std::string& varNameSuffix, cmGeneratorTarget const* gt,
|
||||
const std::string& default_flags)
|
||||
{
|
||||
if (!varNameLang.empty()) {
|
||||
std::string varName = cmStrCat(varNamePrefix, varNameLang, varNameSuffix);
|
||||
if (cmValue varValue = this->CurrentMakefile->GetDefinition(varName)) {
|
||||
if (!varValue->empty()) {
|
||||
return *varValue;
|
||||
std::string flags;
|
||||
this->CurrentLocalGenerator->AppendFlags(
|
||||
flags, *varValue, varName, gt, cmBuildStep::Link, varNameLang);
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,6 +304,7 @@ private:
|
||||
std::string LookupFlags(const std::string& varNamePrefix,
|
||||
const std::string& varNameLang,
|
||||
const std::string& varNameSuffix,
|
||||
cmGeneratorTarget const* gt,
|
||||
const std::string& default_flags);
|
||||
|
||||
class Factory;
|
||||
|
||||
+141
-24
@@ -208,12 +208,62 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
|
||||
}
|
||||
|
||||
std::unique_ptr<cmRulePlaceholderExpander>
|
||||
cmLocalGenerator::CreateRulePlaceholderExpander() const
|
||||
cmLocalGenerator::CreateRulePlaceholderExpander(cmBuildStep buildStep) const
|
||||
{
|
||||
return cm::make_unique<cmRulePlaceholderExpander>(
|
||||
this->Compilers, this->VariableMappings, this->CompilerSysroot,
|
||||
buildStep, this->Compilers, this->VariableMappings, this->CompilerSysroot,
|
||||
this->LinkerSysroot);
|
||||
}
|
||||
std::unique_ptr<cmRulePlaceholderExpander>
|
||||
cmLocalGenerator::CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep, cmGeneratorTarget const* target,
|
||||
std::string const& language)
|
||||
{
|
||||
auto targetType = target->GetType();
|
||||
if (buildStep == cmBuildStep::Link &&
|
||||
(targetType == cmStateEnums::EXECUTABLE ||
|
||||
targetType == cmStateEnums::SHARED_LIBRARY ||
|
||||
targetType == cmStateEnums::MODULE_LIBRARY)) {
|
||||
auto mappings = this->VariableMappings;
|
||||
auto updateMapping = [buildStep, target, &language, &mappings,
|
||||
this](std::string const& variable) {
|
||||
auto search = this->VariableMappings.find(variable);
|
||||
if (search != this->VariableMappings.end()) {
|
||||
std::string finalFlags;
|
||||
this->AppendFlags(finalFlags, search->second, variable, target,
|
||||
buildStep, language);
|
||||
mappings[variable] = std::move(finalFlags);
|
||||
}
|
||||
};
|
||||
|
||||
switch (targetType) {
|
||||
// FALLTHROUGH is used because, depending of the compiler and/or
|
||||
// platform, the wrong variable is used. For example
|
||||
// CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS is used to generate a module,
|
||||
// and the variable CMAKE_SHARED_MODULE_CREATE_<LANG>_FLAGS is ignored.
|
||||
case cmStateEnums::MODULE_LIBRARY:
|
||||
updateMapping(
|
||||
cmStrCat("CMAKE_SHARED_MODULE_CREATE_", language, "_FLAGS"));
|
||||
CM_FALLTHROUGH;
|
||||
case cmStateEnums::SHARED_LIBRARY:
|
||||
updateMapping(
|
||||
cmStrCat("CMAKE_SHARED_LIBRARY_CREATE_", language, "_FLAGS"));
|
||||
CM_FALLTHROUGH;
|
||||
case cmStateEnums::EXECUTABLE:
|
||||
updateMapping(cmStrCat("CMAKE_", language, "_LINK_FLAGS"));
|
||||
break;
|
||||
default:
|
||||
// no action needed
|
||||
;
|
||||
}
|
||||
|
||||
return cm::make_unique<cmRulePlaceholderExpander>(
|
||||
buildStep, this->Compilers, std::move(mappings), this->CompilerSysroot,
|
||||
this->LinkerSysroot);
|
||||
}
|
||||
|
||||
return this->CreateRulePlaceholderExpander(buildStep);
|
||||
}
|
||||
|
||||
cmLocalGenerator::~cmLocalGenerator() = default;
|
||||
|
||||
@@ -1495,17 +1545,16 @@ void cmLocalGenerator::GetTargetFlags(
|
||||
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
|
||||
CM_FALLTHROUGH;
|
||||
case cmStateEnums::SHARED_LIBRARY: {
|
||||
std::string sharedLibFlags;
|
||||
if (this->IsSplitSwiftBuild() || linkLanguage != "Swift") {
|
||||
sharedLibFlags = cmStrCat(
|
||||
this->Makefile->GetSafeDefinition(libraryLinkVariable), ' ');
|
||||
if (!configUpper.empty()) {
|
||||
std::string build = cmStrCat(libraryLinkVariable, '_', configUpper);
|
||||
sharedLibFlags += this->Makefile->GetSafeDefinition(build);
|
||||
sharedLibFlags += " ";
|
||||
std::string libFlags;
|
||||
this->AddConfigVariableFlags(libFlags, libraryLinkVariable, target,
|
||||
cmBuildStep::Link, linkLanguage, config);
|
||||
if (!libFlags.empty()) {
|
||||
linkFlags.emplace_back(std::move(libFlags));
|
||||
}
|
||||
}
|
||||
|
||||
std::string sharedLibFlags;
|
||||
cmValue targetLinkFlags = target->GetProperty("LINK_FLAGS");
|
||||
if (targetLinkFlags) {
|
||||
sharedLibFlags += *targetLinkFlags;
|
||||
@@ -1538,7 +1587,6 @@ void cmLocalGenerator::GetTargetFlags(
|
||||
}
|
||||
} break;
|
||||
case cmStateEnums::EXECUTABLE: {
|
||||
std::string exeFlags;
|
||||
if (linkLanguage.empty()) {
|
||||
cmSystemTools::Error(
|
||||
"CMake can not determine linker language for target: " +
|
||||
@@ -1547,25 +1595,28 @@ void cmLocalGenerator::GetTargetFlags(
|
||||
}
|
||||
|
||||
if (linkLanguage != "Swift") {
|
||||
exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
|
||||
exeFlags += " ";
|
||||
if (!configUpper.empty()) {
|
||||
exeFlags += this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_EXE_LINKER_FLAGS_", configUpper));
|
||||
exeFlags += " ";
|
||||
std::string exeFlags;
|
||||
this->AddConfigVariableFlags(exeFlags, "CMAKE_EXE_LINKER_FLAGS",
|
||||
target, cmBuildStep::Link, linkLanguage,
|
||||
config);
|
||||
if (!exeFlags.empty()) {
|
||||
linkFlags.emplace_back(std::move(exeFlags));
|
||||
}
|
||||
}
|
||||
|
||||
if (target->IsWin32Executable(config)) {
|
||||
exeFlags += this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE"));
|
||||
exeFlags += " ";
|
||||
} else {
|
||||
exeFlags += this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE"));
|
||||
exeFlags += " ";
|
||||
{
|
||||
auto exeType = cmStrCat(
|
||||
"CMAKE_", linkLanguage, "_CREATE_",
|
||||
(target->IsWin32Executable(config) ? "WIN32" : "CONSOLE"), "_EXE");
|
||||
std::string exeFlags;
|
||||
this->AppendFlags(exeFlags, this->Makefile->GetDefinition(exeType),
|
||||
exeType, target, cmBuildStep::Link, linkLanguage);
|
||||
if (!exeFlags.empty()) {
|
||||
linkFlags.emplace_back(std::move(exeFlags));
|
||||
}
|
||||
}
|
||||
|
||||
std::string exeFlags;
|
||||
if (target->IsExecutableWithExports()) {
|
||||
exeFlags += this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG"));
|
||||
@@ -2621,6 +2672,19 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
|
||||
this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar));
|
||||
}
|
||||
}
|
||||
void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
|
||||
const std::string& var,
|
||||
cmGeneratorTarget const* target,
|
||||
cmBuildStep compileOrLink,
|
||||
const std::string& lang,
|
||||
const std::string& config)
|
||||
{
|
||||
std::string newFlags;
|
||||
this->AddConfigVariableFlags(newFlags, var, config);
|
||||
if (!newFlags.empty()) {
|
||||
this->AppendFlags(flags, newFlags, var, target, compileOrLink, lang);
|
||||
}
|
||||
}
|
||||
|
||||
void cmLocalGenerator::AppendFlags(std::string& flags,
|
||||
const std::string& newFlags) const
|
||||
@@ -2651,6 +2715,59 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags,
|
||||
this->EscapeForShell(rawFlag, false, false, false, this->IsNinjaMulti()));
|
||||
}
|
||||
|
||||
void cmLocalGenerator::AppendFlags(std::string& flags,
|
||||
std::string const& newFlags,
|
||||
const std::string& name,
|
||||
const cmGeneratorTarget* target,
|
||||
cmBuildStep compileOrLink,
|
||||
const std::string& language)
|
||||
{
|
||||
switch (target->GetPolicyStatusCMP0181()) {
|
||||
case cmPolicies::WARN:
|
||||
if (!this->Makefile->GetCMakeInstance()->GetIsInTryCompile() &&
|
||||
this->Makefile->PolicyOptionalWarningEnabled(
|
||||
"CMAKE_POLICY_WARNING_CMP0181")) {
|
||||
this->Makefile->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::AUTHOR_WARNING,
|
||||
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0181),
|
||||
"\nSince the policy is not set, the contents of variable '",
|
||||
name,
|
||||
"' will "
|
||||
"be used as is."),
|
||||
target->GetBacktrace());
|
||||
}
|
||||
CM_FALLTHROUGH;
|
||||
case cmPolicies::OLD:
|
||||
this->AppendFlags(flags, newFlags);
|
||||
break;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
this->Makefile->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0181),
|
||||
target->GetBacktrace());
|
||||
CM_FALLTHROUGH;
|
||||
case cmPolicies::NEW:
|
||||
if (compileOrLink == cmBuildStep::Link) {
|
||||
std::vector<std::string> options;
|
||||
cmSystemTools::ParseUnixCommandLine(newFlags.c_str(), options);
|
||||
this->SetLinkScriptShell(this->GlobalGenerator->GetUseLinkScript());
|
||||
std::vector<BT<std::string>> optionsWithBT{ options.size() };
|
||||
std::transform(options.cbegin(), options.cend(), optionsWithBT.begin(),
|
||||
[](const std::string& item) -> BT<std::string> {
|
||||
return BT<std::string>{ item };
|
||||
});
|
||||
target->ResolveLinkerWrapper(optionsWithBT, language);
|
||||
for (const auto& item : optionsWithBT) {
|
||||
this->AppendFlagEscape(flags, item.Value);
|
||||
}
|
||||
this->SetLinkScriptShell(false);
|
||||
} else {
|
||||
this->AppendFlags(flags, newFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
|
||||
{
|
||||
std::vector<std::string> enabledLanguages =
|
||||
|
||||
+20
-31
@@ -19,6 +19,7 @@
|
||||
#include <cm3p/kwiml/int.h>
|
||||
|
||||
#include "cmCustomCommandTypes.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmListFileCache.h"
|
||||
#include "cmMessageType.h" // IWYU pragma: keep
|
||||
@@ -46,36 +47,6 @@ class cmake;
|
||||
template <typename Iter>
|
||||
class cmRange;
|
||||
|
||||
/** Flag if byproducts shall also be considered. */
|
||||
enum class cmSourceOutputKind
|
||||
{
|
||||
OutputOnly,
|
||||
OutputOrByproduct
|
||||
};
|
||||
|
||||
/** What scanner to use for dependencies lookup. */
|
||||
enum class cmDependencyScannerKind
|
||||
{
|
||||
CMake,
|
||||
Compiler
|
||||
};
|
||||
|
||||
/** What to compute language flags for */
|
||||
enum class cmBuildStep
|
||||
{
|
||||
Compile,
|
||||
Link
|
||||
};
|
||||
|
||||
/** What compilation mode the swift files are in */
|
||||
enum class cmSwiftCompileMode
|
||||
{
|
||||
Wholemodule,
|
||||
Incremental,
|
||||
Singlefile,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
/** Target and source file which have a specific output. */
|
||||
struct cmSourcesWithOutput
|
||||
{
|
||||
@@ -147,7 +118,12 @@ public:
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<cmRulePlaceholderExpander>
|
||||
CreateRulePlaceholderExpander() const;
|
||||
CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep = cmBuildStep::Compile) const;
|
||||
virtual std::unique_ptr<cmRulePlaceholderExpander>
|
||||
CreateRulePlaceholderExpander(cmBuildStep buildStep,
|
||||
cmGeneratorTarget const* target,
|
||||
std::string const& language);
|
||||
|
||||
std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
|
||||
cmGeneratorTarget& tgt) const;
|
||||
@@ -174,6 +150,12 @@ public:
|
||||
const std::string& lang);
|
||||
void AddConfigVariableFlags(std::string& flags, const std::string& var,
|
||||
const std::string& config);
|
||||
// Handle prefixes processing (like LINKER:)
|
||||
void AddConfigVariableFlags(std::string& flags, const std::string& var,
|
||||
cmGeneratorTarget const* target,
|
||||
cmBuildStep compileOrLink,
|
||||
const std::string& lang,
|
||||
const std::string& config);
|
||||
void AddColorDiagnosticsFlags(std::string& flags, const std::string& lang);
|
||||
//! Append flags to a string.
|
||||
virtual void AppendFlags(std::string& flags,
|
||||
@@ -182,6 +164,13 @@ public:
|
||||
const std::vector<BT<std::string>>& newFlags) const;
|
||||
virtual void AppendFlagEscape(std::string& flags,
|
||||
const std::string& rawFlag) const;
|
||||
/**
|
||||
* Append flags after parsing, prefixes processing (like LINKER:) and
|
||||
* escaping
|
||||
*/
|
||||
void AppendFlags(std::string& flags, std::string const& newFlags,
|
||||
const std::string& name, const cmGeneratorTarget* target,
|
||||
cmBuildStep compileOrLink, const std::string& lang);
|
||||
void AddISPCDependencies(cmGeneratorTarget* target);
|
||||
void AddPchDependencies(cmGeneratorTarget* target);
|
||||
void AddUnityBuild(cmGeneratorTarget* target);
|
||||
|
||||
@@ -50,9 +50,20 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
|
||||
// Virtual public methods.
|
||||
|
||||
std::unique_ptr<cmRulePlaceholderExpander>
|
||||
cmLocalNinjaGenerator::CreateRulePlaceholderExpander() const
|
||||
cmLocalNinjaGenerator::CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep) const
|
||||
{
|
||||
auto ret = this->cmLocalGenerator::CreateRulePlaceholderExpander();
|
||||
auto ret = this->cmLocalGenerator::CreateRulePlaceholderExpander(buildStep);
|
||||
ret->SetTargetImpLib("$TARGET_IMPLIB");
|
||||
return std::unique_ptr<cmRulePlaceholderExpander>(std::move(ret));
|
||||
}
|
||||
std::unique_ptr<cmRulePlaceholderExpander>
|
||||
cmLocalNinjaGenerator::CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep, cmGeneratorTarget const* target,
|
||||
std::string const& language)
|
||||
{
|
||||
auto ret = this->cmLocalGenerator::CreateRulePlaceholderExpander(
|
||||
buildStep, target, language);
|
||||
ret->SetTargetImpLib("$TARGET_IMPLIB");
|
||||
return std::unique_ptr<cmRulePlaceholderExpander>(std::move(ret));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmLocalCommonGenerator.h"
|
||||
#include "cmNinjaTypes.h"
|
||||
#include "cmOutputConverter.h"
|
||||
@@ -42,8 +43,11 @@ public:
|
||||
|
||||
void Generate() override;
|
||||
|
||||
std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander()
|
||||
const override;
|
||||
std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep = cmBuildStep::Compile) const override;
|
||||
std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander(
|
||||
cmBuildStep buildStep, cmGeneratorTarget const* target,
|
||||
std::string const& language) override;
|
||||
|
||||
std::string GetTargetDirectory(
|
||||
cmGeneratorTarget const* target) const override;
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cmDepends.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmLocalCommonGenerator.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
|
||||
class cmCustomCommand;
|
||||
class cmCustomCommandGenerator;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "cmCustomCommandLines.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmGlobalVisualStudio7Generator.h"
|
||||
@@ -664,16 +665,16 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
|
||||
}
|
||||
std::string flags;
|
||||
std::string langForClCompile;
|
||||
const std::string& linkLanguage =
|
||||
(this->FortranProject ? std::string("Fortran")
|
||||
: target->GetLinkerLanguage(configName));
|
||||
if (linkLanguage.empty()) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("CMake can not determine linker language for target: ",
|
||||
target->GetName()));
|
||||
return;
|
||||
}
|
||||
if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
|
||||
const std::string& linkLanguage =
|
||||
(this->FortranProject ? std::string("Fortran")
|
||||
: target->GetLinkerLanguage(configName));
|
||||
if (linkLanguage.empty()) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("CMake can not determine linker language for target: ",
|
||||
target->GetName()));
|
||||
return;
|
||||
}
|
||||
langForClCompile = linkLanguage;
|
||||
if (langForClCompile == "C" || langForClCompile == "CXX" ||
|
||||
langForClCompile == "Fortran") {
|
||||
@@ -957,26 +958,14 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
|
||||
}
|
||||
|
||||
this->OutputTargetRules(fout, configName, target, libName);
|
||||
this->OutputBuildTool(fout, configName, target, targetOptions);
|
||||
this->OutputBuildTool(fout, linkLanguage, configName, target, targetOptions);
|
||||
this->OutputDeploymentDebuggerTool(fout, configName, target);
|
||||
fout << "\t\t</Configuration>\n";
|
||||
}
|
||||
|
||||
std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
|
||||
std::string const& rootLinkerFlags, const std::string& configName)
|
||||
{
|
||||
std::string configTypeUpper = cmSystemTools::UpperCase(configName);
|
||||
std::string extraLinkOptionsBuildTypeDef =
|
||||
cmStrCat(rootLinkerFlags, '_', configTypeUpper);
|
||||
|
||||
const std::string& extraLinkOptionsBuildType =
|
||||
this->Makefile->GetRequiredDefinition(extraLinkOptionsBuildTypeDef);
|
||||
|
||||
return extraLinkOptionsBuildType;
|
||||
}
|
||||
|
||||
void cmLocalVisualStudio7Generator::OutputBuildTool(
|
||||
std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
|
||||
std::ostream& fout, const std::string& linkLanguage,
|
||||
const std::string& configName, cmGeneratorTarget* target,
|
||||
const Options& targetOptions)
|
||||
{
|
||||
cmGlobalVisualStudio7Generator* gg =
|
||||
@@ -984,19 +973,19 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
||||
std::string temp;
|
||||
std::string extraLinkOptions;
|
||||
if (target->GetType() == cmStateEnums::EXECUTABLE) {
|
||||
extraLinkOptions = cmStrCat(
|
||||
this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS"), ' ',
|
||||
GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName));
|
||||
this->AddConfigVariableFlags(extraLinkOptions, "CMAKE_EXE_LINKER_FLAGS",
|
||||
target, cmBuildStep::Link, linkLanguage,
|
||||
configName);
|
||||
}
|
||||
if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
|
||||
extraLinkOptions = cmStrCat(
|
||||
this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS"), ' ',
|
||||
GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName));
|
||||
this->AddConfigVariableFlags(extraLinkOptions, "CMAKE_SHARED_LINKER_FLAGS",
|
||||
target, cmBuildStep::Link, linkLanguage,
|
||||
configName);
|
||||
}
|
||||
if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
|
||||
extraLinkOptions = cmStrCat(
|
||||
this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS"), ' ',
|
||||
GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName));
|
||||
this->AddConfigVariableFlags(extraLinkOptions, "CMAKE_MODULE_LINKER_FLAGS",
|
||||
target, cmBuildStep::Link, linkLanguage,
|
||||
configName);
|
||||
}
|
||||
|
||||
cmValue targetLinkFlags = target->GetProperty("LINK_FLAGS");
|
||||
@@ -1089,7 +1078,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
||||
return;
|
||||
}
|
||||
cmComputeLinkInformation& cli = *pcli;
|
||||
std::string linkLanguage = cli.GetLinkLanguage();
|
||||
|
||||
if (!target->GetLinkerTypeProperty(linkLanguage, configName).empty()) {
|
||||
// Visual Studio 10 or upper is required for this feature
|
||||
@@ -1173,7 +1161,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
||||
return;
|
||||
}
|
||||
cmComputeLinkInformation& cli = *pcli;
|
||||
std::string linkLanguage = cli.GetLinkLanguage();
|
||||
|
||||
if (!target->GetLinkerTypeProperty(linkLanguage, configName).empty()) {
|
||||
// Visual Studio 10 or upper is required for this feature
|
||||
|
||||
@@ -99,8 +99,6 @@ protected:
|
||||
private:
|
||||
using Options = cmVS7GeneratorOptions;
|
||||
using FCInfo = cmLocalVisualStudio7GeneratorFCInfo;
|
||||
std::string GetBuildTypeLinkerFlags(std::string const& rootLinkerFlags,
|
||||
const std::string& configName);
|
||||
void FixGlobalTargets();
|
||||
void WriteVCProjHeader(std::ostream& fout, const std::string& libName,
|
||||
cmGeneratorTarget* tgt,
|
||||
@@ -119,8 +117,9 @@ private:
|
||||
void OutputTargetRules(std::ostream& fout, const std::string& configName,
|
||||
cmGeneratorTarget* target,
|
||||
const std::string& libName);
|
||||
void OutputBuildTool(std::ostream& fout, const std::string& configName,
|
||||
cmGeneratorTarget* t, const Options& targetOptions);
|
||||
void OutputBuildTool(std::ostream& fout, const std::string& linkLanguage,
|
||||
const std::string& configName, cmGeneratorTarget* t,
|
||||
const Options& targetOptions);
|
||||
void OutputDeploymentDebuggerTool(std::ostream& fout,
|
||||
std::string const& config,
|
||||
cmGeneratorTarget* target);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalUnixMakefileGenerator3.h"
|
||||
#include "cmLinkLineComputer.h"
|
||||
@@ -233,7 +234,8 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule(
|
||||
}
|
||||
|
||||
auto rulePlaceholderExpander =
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander();
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GeneratorTarget, linkLanguage);
|
||||
|
||||
// Expand placeholders in the commands.
|
||||
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
|
||||
@@ -370,19 +372,20 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||
|
||||
// Add flags to create an executable.
|
||||
this->LocalGenerator->AddConfigVariableFlags(
|
||||
linkFlags, "CMAKE_EXE_LINKER_FLAGS", this->GetConfigName());
|
||||
linkFlags, "CMAKE_EXE_LINKER_FLAGS", this->GeneratorTarget,
|
||||
cmBuildStep::Link, linkLanguage, this->GetConfigName());
|
||||
|
||||
if (this->GeneratorTarget->IsWin32Executable(
|
||||
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"))) {
|
||||
{
|
||||
auto exeType =
|
||||
cmStrCat("CMAKE_", linkLanguage, "_CREATE_",
|
||||
(this->GeneratorTarget->IsWin32Executable(
|
||||
this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
|
||||
? "WIN32"
|
||||
: "CONSOLE"),
|
||||
"_EXE");
|
||||
this->LocalGenerator->AppendFlags(
|
||||
linkFlags,
|
||||
this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE")));
|
||||
} else {
|
||||
this->LocalGenerator->AppendFlags(
|
||||
linkFlags,
|
||||
this->Makefile->GetSafeDefinition(
|
||||
cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE")));
|
||||
linkFlags, this->Makefile->GetDefinition(exeType), exeType,
|
||||
this->GeneratorTarget, cmBuildStep::Link, linkLanguage);
|
||||
}
|
||||
|
||||
// Add symbol export flags if necessary.
|
||||
@@ -602,7 +605,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||
}
|
||||
|
||||
auto rulePlaceholderExpander =
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander();
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GeneratorTarget, linkLanguage);
|
||||
|
||||
// Expand placeholders in the commands.
|
||||
rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalUnixMakefileGenerator3.h"
|
||||
#include "cmLinkLineComputer.h"
|
||||
@@ -177,7 +178,8 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
|
||||
std::string extraFlags;
|
||||
this->GetTargetLinkFlags(extraFlags, linkLanguage);
|
||||
this->LocalGenerator->AddConfigVariableFlags(
|
||||
extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->GetConfigName());
|
||||
extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->GeneratorTarget,
|
||||
cmBuildStep::Link, linkLanguage, this->GetConfigName());
|
||||
|
||||
std::unique_ptr<cmLinkLineComputer> linkLineComputer =
|
||||
this->CreateLinkLineComputer(
|
||||
@@ -212,7 +214,8 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
|
||||
std::string extraFlags;
|
||||
this->GetTargetLinkFlags(extraFlags, linkLanguage);
|
||||
this->LocalGenerator->AddConfigVariableFlags(
|
||||
extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->GetConfigName());
|
||||
extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->GeneratorTarget,
|
||||
cmBuildStep::Link, linkLanguage, this->GetConfigName());
|
||||
|
||||
std::unique_ptr<cmLinkLineComputer> linkLineComputer =
|
||||
this->CreateLinkLineComputer(
|
||||
@@ -239,7 +242,8 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
|
||||
std::string extraFlags;
|
||||
this->GetTargetLinkFlags(extraFlags, linkLanguage);
|
||||
this->LocalGenerator->AddConfigVariableFlags(
|
||||
extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->GetConfigName());
|
||||
extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->GeneratorTarget,
|
||||
cmBuildStep::Link, linkLanguage, this->GetConfigName());
|
||||
|
||||
this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
|
||||
}
|
||||
@@ -382,7 +386,8 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules(
|
||||
}
|
||||
|
||||
auto rulePlaceholderExpander =
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander();
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GeneratorTarget, linkLanguage);
|
||||
|
||||
// Construct the main link rule and expand placeholders.
|
||||
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
|
||||
@@ -707,7 +712,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
|
||||
|
||||
// Expand the rule variables.
|
||||
auto rulePlaceholderExpander =
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander();
|
||||
this->LocalGenerator->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GeneratorTarget, linkLanguage);
|
||||
bool useWatcomQuote =
|
||||
this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE");
|
||||
cmList real_link_commands;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "cmFileSet.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalUnixMakefileGenerator3.h"
|
||||
#include "cmLinkLineComputer.h" // IWYU pragma: keep
|
||||
@@ -1707,7 +1708,8 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
|
||||
vars.Flags = flags.c_str();
|
||||
|
||||
std::string compileCmd = this->GetLinkRule("CMAKE_CUDA_DEVICE_LINK_COMPILE");
|
||||
auto rulePlaceholderExpander = localGen->CreateRulePlaceholderExpander();
|
||||
auto rulePlaceholderExpander = localGen->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GetGeneratorTarget(), "CUDA");
|
||||
rulePlaceholderExpander->ExpandRuleVariables(localGen, compileCmd, vars);
|
||||
|
||||
commands.emplace_back(compileCmd);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "cmCustomCommand.h" // IWYU pragma: keep
|
||||
#include "cmCustomCommandGenerator.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalNinjaGenerator.h"
|
||||
#include "cmLinkLineComputer.h"
|
||||
@@ -350,7 +351,9 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule(
|
||||
}
|
||||
|
||||
auto rulePlaceholderExpander =
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GetGeneratorTarget(),
|
||||
this->TargetLinkLanguage(config));
|
||||
|
||||
// Rule for linking library/executable.
|
||||
std::vector<std::string> linkCmds = this->ComputeDeviceLinkCmd();
|
||||
@@ -413,7 +416,9 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
|
||||
std::string compileCmd = this->GetMakefile()->GetRequiredDefinition(
|
||||
"CMAKE_CUDA_DEVICE_LINK_COMPILE");
|
||||
auto rulePlaceholderExpander =
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GetGeneratorTarget(),
|
||||
this->TargetLinkLanguage(config));
|
||||
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
|
||||
compileCmd, vars);
|
||||
|
||||
@@ -566,7 +571,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
|
||||
}
|
||||
|
||||
auto rulePlaceholderExpander =
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
|
||||
this->GetLocalGenerator()->CreateRulePlaceholderExpander(
|
||||
cmBuildStep::Link, this->GetGeneratorTarget(),
|
||||
this->TargetLinkLanguage(config));
|
||||
|
||||
// Rule for linking library/executable.
|
||||
std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "cmFileSet.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalCommonGenerator.h"
|
||||
#include "cmGlobalNinjaGenerator.h"
|
||||
|
||||
+6
-2
@@ -552,7 +552,10 @@ class cmMakefile;
|
||||
3, 31, 0, cmPolicies::WARN) \
|
||||
SELECT(POLICY, CMP0180, \
|
||||
"project() always sets <PROJECT-NAME>_* as normal variables.", 3, \
|
||||
31, 0, cmPolicies::WARN)
|
||||
31, 0, cmPolicies::WARN) \
|
||||
SELECT(POLICY, CMP0181, \
|
||||
"Link command-line fragment variables are parsed and re-quoted.", 3, \
|
||||
32, 0, cmPolicies::WARN)
|
||||
|
||||
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||
#define CM_FOR_EACH_POLICY_ID(POLICY) \
|
||||
@@ -597,7 +600,8 @@ class cmMakefile;
|
||||
F(CMP0157) \
|
||||
F(CMP0160) \
|
||||
F(CMP0162) \
|
||||
F(CMP0179)
|
||||
F(CMP0179) \
|
||||
F(CMP0181)
|
||||
|
||||
#define CM_FOR_EACH_CUSTOM_COMMAND_POLICY(F) \
|
||||
F(CMP0116) \
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmRulePlaceholderExpander::cmRulePlaceholderExpander(
|
||||
std::map<std::string, std::string> compilers,
|
||||
cmBuildStep buildStep, std::map<std::string, std::string> compilers,
|
||||
std::map<std::string, std::string> variableMappings,
|
||||
std::string compilerSysroot, std::string linkerSysroot)
|
||||
: Compilers(std::move(compilers))
|
||||
: BuildStep(buildStep)
|
||||
, Compilers(std::move(compilers))
|
||||
, VariableMappings(std::move(variableMappings))
|
||||
, CompilerSysroot(std::move(compilerSysroot))
|
||||
, LinkerSysroot(std::move(linkerSysroot))
|
||||
@@ -320,9 +321,8 @@ std::string cmRulePlaceholderExpander::ExpandVariable(
|
||||
}
|
||||
std::string sysroot;
|
||||
// Some platforms may use separate sysroots for compiling and linking.
|
||||
// If we detect link flags, then we pass the link sysroot instead.
|
||||
// FIXME: Use a more robust way to detect link line expansion.
|
||||
if (this->ReplaceValues->LinkFlags) {
|
||||
// When the build step is link, pass the link sysroot instead.
|
||||
if (this->BuildStep == cmBuildStep::Link) {
|
||||
sysroot = this->LinkerSysroot;
|
||||
} else {
|
||||
sysroot = this->CompilerSysroot;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmPlaceholderExpander.h"
|
||||
|
||||
class cmOutputConverter;
|
||||
@@ -16,7 +17,7 @@ class cmRulePlaceholderExpander : public cmPlaceholderExpander
|
||||
{
|
||||
public:
|
||||
cmRulePlaceholderExpander(
|
||||
std::map<std::string, std::string> compilers,
|
||||
cmBuildStep buildStep, std::map<std::string, std::string> compilers,
|
||||
std::map<std::string, std::string> variableMappings,
|
||||
std::string compilerSysroot, std::string linkerSysroot);
|
||||
|
||||
@@ -84,6 +85,7 @@ private:
|
||||
|
||||
std::string TargetImpLib;
|
||||
|
||||
cmBuildStep BuildStep = cmBuildStep::Compile;
|
||||
std::map<std::string, std::string> Compilers;
|
||||
std::map<std::string, std::string> VariableMappings;
|
||||
std::string CompilerSysroot;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "cmFileSet.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorOptions.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmGlobalVisualStudio10Generator.h"
|
||||
@@ -4426,12 +4427,9 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
||||
linkType = "EXE";
|
||||
}
|
||||
std::string flags;
|
||||
std::string linkFlagVarBase = cmStrCat("CMAKE_", linkType, "_LINKER_FLAGS");
|
||||
flags += ' ';
|
||||
flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
|
||||
std::string linkFlagVar = cmStrCat(linkFlagVarBase, '_', CONFIG);
|
||||
flags += ' ';
|
||||
flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
|
||||
this->LocalGenerator->AddConfigVariableFlags(
|
||||
flags, cmStrCat("CMAKE_", linkType, "_LINKER_FLAGS"),
|
||||
this->GeneratorTarget, cmBuildStep::Link, linkLanguage, config);
|
||||
cmValue targetLinkFlags = this->GeneratorTarget->GetProperty("LINK_FLAGS");
|
||||
if (targetLinkFlags) {
|
||||
flags += ' ';
|
||||
|
||||
@@ -875,7 +875,9 @@ add_RunCMake_test(target_link_libraries-LINK_GROUP -DCMAKE_SYSTEM_NAME=${CMAKE_S
|
||||
-DCMAKE_IMPORT_LIBRARY_PREFIX=${CMAKE_IMPORT_LIBRARY_PREFIX}
|
||||
-DCMAKE_IMPORT_LIBRARY_SUFFIX=${CMAKE_IMPORT_LIBRARY_SUFFIX}
|
||||
-DCMAKE_LINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG})
|
||||
add_RunCMake_test(target_link_libraries-LINKER-prefix -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
|
||||
add_RunCMake_test(target_link_libraries-LINKER-prefix -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
|
||||
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
|
||||
-DCMAKE_C_COMPILER_FRONTEND_VARIANT=${CMAKE_C_COMPILER_FRONTEND_VARIANT})
|
||||
add_RunCMake_test(add_link_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
|
||||
add_RunCMake_test(target_link_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
|
||||
-DCMake_TEST_CUDA=${CMake_TEST_CUDA})
|
||||
|
||||
@@ -87,13 +87,7 @@
|
||||
"link": {
|
||||
"language": "CXX",
|
||||
"lto": null,
|
||||
"commandFragments": [
|
||||
{
|
||||
"fragment" : ".*",
|
||||
"role" : "flags",
|
||||
"backtrace": null
|
||||
}
|
||||
]
|
||||
"commandFragments": null
|
||||
},
|
||||
"archive": null,
|
||||
"dependencies": [
|
||||
|
||||
@@ -91,13 +91,7 @@
|
||||
"link": {
|
||||
"language": "CXX",
|
||||
"lto": null,
|
||||
"commandFragments": [
|
||||
{
|
||||
"fragment" : ".*",
|
||||
"role" : "flags",
|
||||
"backtrace": null
|
||||
}
|
||||
]
|
||||
"commandFragments": null
|
||||
},
|
||||
"archive": null,
|
||||
"dependencies": [
|
||||
|
||||
@@ -87,13 +87,7 @@
|
||||
"link": {
|
||||
"language": "CXX",
|
||||
"lto": null,
|
||||
"commandFragments": [
|
||||
{
|
||||
"fragment" : ".*",
|
||||
"role" : "flags",
|
||||
"backtrace": null
|
||||
}
|
||||
]
|
||||
"commandFragments": null
|
||||
},
|
||||
"archive": null,
|
||||
"dependencies": [
|
||||
|
||||
+1
-7
@@ -91,13 +91,7 @@
|
||||
"link": {
|
||||
"language": "CXX",
|
||||
"lto": null,
|
||||
"commandFragments": [
|
||||
{
|
||||
"fragment" : ".*",
|
||||
"role" : "flags",
|
||||
"backtrace": null
|
||||
}
|
||||
]
|
||||
"commandFragments": null
|
||||
},
|
||||
"archive": null,
|
||||
"dependencies": [
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
\* CMP0160
|
||||
\* CMP0162
|
||||
\* CMP0179
|
||||
\* CMP0181
|
||||
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
|
||||
if (NOT actual_stdout MATCHES "LINKER:-foo,bar")
|
||||
set (RunCMake_TEST_FAILED "LINKER: prefix was expanded.")
|
||||
return()
|
||||
endif()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
cmake_policy(SET CMP0181 ${CMP0181})
|
||||
|
||||
# ensure command line is always displayed and do not use any response file
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Borland|NMake")
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
|
||||
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}")
|
||||
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
|
||||
endif()
|
||||
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} LINKER:-foo,bar")
|
||||
add_executable(exe_linker_flags main.c)
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} LINKER:-foo,bar")
|
||||
add_library(shared_linker_flags SHARED LinkOptionsLib.c)
|
||||
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} LINKER:-foo,bar")
|
||||
add_library(module_linker_flags MODULE LinkOptionsLib.c)
|
||||
|
||||
|
||||
# generate reference for LINKER flag
|
||||
if (CMP0181 STREQUAL "NEW")
|
||||
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)
|
||||
set(linker_sep "${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}")
|
||||
|
||||
string (APPEND linker_flag "${linker_space}" "-foo${linker_sep}bar")
|
||||
else()
|
||||
set(linker_prefix "${linker_flag}${linker_space}")
|
||||
|
||||
set (linker_flag "${linker_prefix}-foo ${linker_prefix}bar")
|
||||
endif()
|
||||
else()
|
||||
set(linker_flag "-foo bar")
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}")
|
||||
endif()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
cmake_policy(SET CMP0181 ${CMP0181})
|
||||
|
||||
# ensure command line is always displayed and do not use any response file
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Borland|NMake")
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
|
||||
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}")
|
||||
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
|
||||
endif()
|
||||
|
||||
|
||||
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} LINKER:-foo,bar")
|
||||
add_executable(c_exe_create_link_flags main.c)
|
||||
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} LINKER:-foo,bar")
|
||||
add_library(c_shared_create_link_flags SHARED LinkOptionsLib.c)
|
||||
|
||||
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} LINKER:-foo,bar")
|
||||
add_library(c_module_create_link_flags MODULE LinkOptionsLib.c)
|
||||
|
||||
# generate reference for LINKER flag
|
||||
if (CMP0181 STREQUAL "NEW")
|
||||
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)
|
||||
set(linker_sep "${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}")
|
||||
|
||||
string (APPEND linker_flag "${linker_space}" "-foo${linker_sep}bar")
|
||||
else()
|
||||
set(linker_prefix "${linker_flag}${linker_space}")
|
||||
|
||||
set (linker_flag "${linker_prefix}-foo ${linker_prefix}bar")
|
||||
endif()
|
||||
else()
|
||||
set(linker_flag "-foo bar")
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}")
|
||||
endif()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
set(reference_file "LINKER.txt")
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/LINKER_expansion-CMP0181-OLD-validation.cmake")
|
||||
+1
@@ -0,0 +1 @@
|
||||
.*
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
cmake_policy(SET CMP0181 ${CMP0181})
|
||||
|
||||
# ensure command line is always displayed and do not use any response file
|
||||
set(CMAKE_VERBOSE_MAKEFILE TRUE)
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Borland|NMake")
|
||||
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
|
||||
endif()
|
||||
|
||||
|
||||
set(CMAKE_C_CREATE_WIN32_EXE "${CMAKE_C_CREATE_WIN32_EXE} LINKER:-foo,bar")
|
||||
add_executable (c_create_win32_exe WIN32 main.c)
|
||||
|
||||
set(CMAKE_C_CREATE_CONSOLE_EXE "${CMAKE_C_CREATE_CONSOLE_EXE} LINKER:-foo,bar")
|
||||
add_executable(c_create_console_exe main.c)
|
||||
|
||||
|
||||
# generate reference for LINKER flag
|
||||
if (CMP0181 STREQUAL "NEW")
|
||||
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)
|
||||
set(linker_sep "${CMAKE_C_LINKER_WRAPPER_FLAG_SEP}")
|
||||
|
||||
string (APPEND linker_flag "${linker_space}" "-foo${linker_sep}bar")
|
||||
else()
|
||||
set(linker_prefix "${linker_flag}${linker_space}")
|
||||
|
||||
set (linker_flag "${linker_prefix}-foo ${linker_prefix}bar")
|
||||
endif()
|
||||
else()
|
||||
set(linker_flag "-foo bar")
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LINKER.txt" "${linker_flag}")
|
||||
endif()
|
||||
@@ -20,3 +20,40 @@ if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)")
|
||||
run_cmake_target(LINKER_expansion LINKER_SHELL linker_shell)
|
||||
run_cmake_target(LINKER_expansion LINKER_CONSUMER linker_consumer)
|
||||
endif()
|
||||
|
||||
# Some environments are excluded because they are not able to honor verbose mode
|
||||
if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Xcode|Visual Studio"
|
||||
AND NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
||||
set(RunCMake_TEST_OUTPUT_MERGE TRUE)
|
||||
|
||||
foreach(policy IN ITEMS OLD NEW)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/LINKER_expansion2-CMP0181-${policy}-build)
|
||||
run_cmake_with_options(LINKER_expansion2 -DCMP0181=${policy})
|
||||
|
||||
run_cmake_target(LINKER_expansion2-CMP0181-${policy} EXE_LINKER_FLAGS exe_linker_flags --verbose)
|
||||
run_cmake_target(LINKER_expansion2-CMP0181-${policy} SHARED_LINKER_FLAGS shared_linker_flags --verbose)
|
||||
run_cmake_target(LINKER_expansion2-CMP0181-${policy} MODULE_LINKER_FLAGS module_linker_flags --verbose)
|
||||
|
||||
|
||||
if (NOT (RunCMake_GENERATOR MATCHES "Visual Studio" OR CMAKE_C_COMPILER_ID MATCHES "Borland|Embarcadero"))
|
||||
# Visual Studio generator and Borland, Embarcadero compilers do not use these variables
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/LINKER_expansion3-CMP0181-${policy}-build)
|
||||
run_cmake_with_options(LINKER_expansion3 -DCMP0181=${policy})
|
||||
|
||||
run_cmake_target(LINKER_expansion3-CMP0181-${policy} C_EXE_CREATE_LINK_FLAGS c_exe_create_link_flags --verbose)
|
||||
if (NOT (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
|
||||
# MSVC compiler does not use these variables
|
||||
run_cmake_target(LINKER_expansion3-CMP0181-${policy} C_SHARED_CREATE_LINK_FLAGS c_shared_create_link_flags --verbose)
|
||||
run_cmake_target(LINKER_expansion3-CMP0181-${policy} C_MODULE_CREATE_LINK_FLAGS c_module_create_link_flags --verbose)
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/LINKER_expansion4-CMP0181-${policy}-build)
|
||||
run_cmake_with_options(LINKER_expansion4 -DCMP0181=${policy})
|
||||
|
||||
run_cmake_target(LINKER_expansion4-CMP0181-${policy} C_CREATE_WIN32_EXE c_create_win32_exe --verbose)
|
||||
run_cmake_target(LINKER_expansion4-CMP0181-${policy} C_CREATE_CONSOLE_EXE c_create_console_exe --verbose)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user