summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-10-07 13:10:54 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-10-07 13:10:54 (GMT)
commit89b03498ef0005778260f4734e3102e8a5463ff0 (patch)
treecfd2925210906b8d1a08ddb2e8f470d06432e752 /Source
parentf7fc93281b81d0ae824f0ef4dbaae3ea5e9fb6a0 (diff)
parent0f1fedbd6a298cf9af2f36577cc66c4ee167be3d (diff)
downloadCMake-89b03498ef0005778260f4734e3102e8a5463ff0.zip
CMake-89b03498ef0005778260f4734e3102e8a5463ff0.tar.gz
CMake-89b03498ef0005778260f4734e3102e8a5463ff0.tar.bz2
Merge topic 'CMP0065-LINK_FLAGS'
0f1fedbd CMP0065: Put computed flags into LINK_FLAGS not LINK_LIBRARIES 7f1cd328 cmLocalGenerator: Rename local variable to be more appropriate 2597bcf8 cmLocalGenerator: Extract policy handling into a method
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx105
-rw-r--r--Source/cmLocalGenerator.h3
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx5
3 files changed, 67 insertions, 46 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index f24b717..3fabd53 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1248,6 +1248,14 @@ void cmLocalGenerator::GetTargetFlags(
linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
linkFlags += " ";
}
+
+ std::string cmp0065Flags =
+ this->GetLinkLibsCMP0065(linkLanguage, *target);
+ if (!cmp0065Flags.empty()) {
+ linkFlags += cmp0065Flags;
+ linkFlags += " ";
+ }
+
const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
if (targetLinkFlags) {
linkFlags += targetLinkFlags;
@@ -1428,59 +1436,15 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
}
cmComputeLinkInformation& cli = *pcli;
- // Collect library linking flags command line options.
- std::string linkLibs;
-
std::string linkLanguage = cli.GetLinkLanguage();
+ std::string linkLibs;
+
std::string libPathFlag =
this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
std::string libPathTerminator =
this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
- // Flags to link an executable to shared libraries.
- if (tgt.GetType() == cmState::EXECUTABLE &&
- this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
- "TARGET_SUPPORTS_SHARED_LIBS")) {
- bool add_shlib_flags = false;
- switch (tgt.GetPolicyStatusCMP0065()) {
- case cmPolicies::WARN:
- if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
- this->Makefile->PolicyOptionalWarningEnabled(
- "CMAKE_POLICY_WARNING_CMP0065")) {
- std::ostringstream w;
- /* clang-format off */
- w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
- "For compatibility with older versions of CMake, "
- "additional flags may be added to export symbols on all "
- "executables regardless of their ENABLE_EXPORTS property.";
- /* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
- }
- case cmPolicies::OLD:
- // OLD behavior is to always add the flags
- add_shlib_flags = true;
- break;
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
- this->IssueMessage(
- cmake::FATAL_ERROR,
- cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
- case cmPolicies::NEW:
- // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
- add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
- break;
- }
-
- if (add_shlib_flags) {
- std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
- linkFlagsVar += linkLanguage;
- linkFlagsVar += "_FLAGS";
- linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
- linkLibs += " ";
- }
- }
-
// Append the framework search path flags.
std::string fwSearchFlagVar = "CMAKE_";
fwSearchFlagVar += linkLanguage;
@@ -1572,6 +1536,55 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
linkLibraries = fout.str();
}
+std::string cmLocalGenerator::GetLinkLibsCMP0065(
+ std::string const& linkLanguage, cmGeneratorTarget& tgt) const
+{
+ std::string linkFlags;
+
+ // Flags to link an executable to shared libraries.
+ if (tgt.GetType() == cmState::EXECUTABLE &&
+ this->StateSnapshot.GetState()->GetGlobalPropertyAsBool(
+ "TARGET_SUPPORTS_SHARED_LIBS")) {
+ bool add_shlib_flags = false;
+ switch (tgt.GetPolicyStatusCMP0065()) {
+ case cmPolicies::WARN:
+ if (!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
+ this->Makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0065")) {
+ std::ostringstream w;
+ /* clang-format off */
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
+ "For compatibility with older versions of CMake, "
+ "additional flags may be added to export symbols on all "
+ "executables regardless of their ENABLE_EXPORTS property.";
+ /* clang-format on */
+ this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to always add the flags
+ add_shlib_flags = true;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->IssueMessage(
+ cmake::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
+ case cmPolicies::NEW:
+ // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
+ add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
+ break;
+ }
+
+ if (add_shlib_flags) {
+ std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
+ linkFlagsVar += linkLanguage;
+ linkFlagsVar += "_FLAGS";
+ linkFlags = this->Makefile->GetSafeDefinition(linkFlagsVar);
+ }
+ }
+ return linkFlags;
+}
+
void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
cmGeneratorTarget const* target,
const std::string& lang,
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 19469be..2c1aeac 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -82,6 +82,9 @@ public:
return this->GlobalGenerator;
}
+ std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
+ cmGeneratorTarget& tgt) const;
+
cmState* GetState() const;
cmState::Snapshot GetStateSnapshot() const;
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index cb20117..42e12ad 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -192,6 +192,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->LocalGenerator->AppendFlags(
linkFlags, this->Makefile->GetDefinition(export_flag_var));
}
+
+ this->LocalGenerator->AppendFlags(linkFlags,
+ this->LocalGenerator->GetLinkLibsCMP0065(
+ linkLanguage, *this->GeneratorTarget));
+
if (this->GeneratorTarget->GetProperty("LINK_WHAT_YOU_USE")) {
this->LocalGenerator->AppendFlags(linkFlags, " -Wl,--no-as-needed");
}