diff options
author | Stephen Kelly <steveire@gmail.com> | 2016-10-04 21:16:27 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2016-10-06 20:17:30 (GMT) |
commit | 2597bcf831dae6a0a7a212607ea4b926ec6b10e0 (patch) | |
tree | 277564c9108097e0e841d93f1346ab5140c1233e | |
parent | b2cf1cba07633a242d5d13f694609a505c6a6235 (diff) | |
download | CMake-2597bcf831dae6a0a7a212607ea4b926ec6b10e0.zip CMake-2597bcf831dae6a0a7a212607ea4b926ec6b10e0.tar.gz CMake-2597bcf831dae6a0a7a212607ea4b926ec6b10e0.tar.bz2 |
cmLocalGenerator: Extract policy handling into a method
-rw-r--r-- | Source/cmLocalGenerator.cxx | 98 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 3 |
2 files changed, 55 insertions, 46 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f24b717..6cc03e8 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1428,59 +1428,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 = this->GetLinkLibsCMP0065(linkLanguage, tgt); + 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 +1528,56 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, linkLibraries = fout.str(); } +std::string cmLocalGenerator::GetLinkLibsCMP0065( + std::string const& linkLanguage, cmGeneratorTarget& tgt) const +{ + std::string linkLibs; + + // 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 += " "; + } + } + return linkLibs; +} + 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; |