diff options
author | Brad King <brad.king@kitware.com> | 2017-02-17 13:46:14 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2017-02-17 13:46:14 (GMT) |
commit | f3e8a89a9b9a859b0e55abe474f85858a3cb2f40 (patch) | |
tree | aac1bb3d8c4a91b87ee409daff8b9b6f7f6e4ca3 /Source | |
parent | 988c63527ded3cfcb0469532a00c12abe7bc8d0c (diff) | |
parent | 1ba91291e3237e5535a46c6ff1bce6a33d298a76 (diff) | |
download | CMake-f3e8a89a9b9a859b0e55abe474f85858a3cb2f40.zip CMake-f3e8a89a9b9a859b0e55abe474f85858a3cb2f40.tar.gz CMake-f3e8a89a9b9a859b0e55abe474f85858a3cb2f40.tar.bz2 |
Merge topic 'install_name_policy'
1ba91291 Add policy CMP0068 separate install_name and RPATH settings on macOS
f7b9bf41 Apple: Add BUILD_WITH_INSTALL_NAME_DIR target property
4bff2d14 Apple: Refactor support for using INSTALL_NAME_DIR.
624fb9d7 Help: Format BUILD_WITH_INSTALL_RPATH documentation
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 86 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 10 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 25 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmPolicies.h | 8 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 1 |
6 files changed, 111 insertions, 22 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 6ce8140..8512b99 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1321,8 +1321,7 @@ bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir( return false; } const char* install_name = this->GetProperty("INSTALL_NAME_DIR"); - bool use_install_name = - this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"); + bool use_install_name = this->MacOSXUseInstallNameDir(); if (install_name && use_install_name && std::string(install_name) == "@rpath") { install_name_is_rpath = true; @@ -1395,6 +1394,53 @@ bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const return cmp0042 == cmPolicies::NEW; } +bool cmGeneratorTarget::MacOSXUseInstallNameDir() const +{ + const char* build_with_install_name = + this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR"); + if (build_with_install_name) { + return cmSystemTools::IsOn(build_with_install_name); + } + + cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068(); + if (cmp0068 == cmPolicies::NEW) { + return false; + } + + bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"); + + if (use_install_name && cmp0068 == cmPolicies::WARN) { + this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget( + this->GetName()); + } + + return use_install_name; +} + +bool cmGeneratorTarget::CanGenerateInstallNameDir( + InstallNameType name_type) const +{ + cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068(); + + if (cmp0068 == cmPolicies::NEW) { + return true; + } + + bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH"); + if (name_type == INSTALL_NAME_FOR_INSTALL) { + skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"); + } else { + skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH"); + } + + if (skip && cmp0068 == cmPolicies::WARN) { + this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget( + this->GetName()); + } + + return !skip; +} + std::string cmGeneratorTarget::GetSOName(const std::string& config) const { if (this->IsImported()) { @@ -1503,24 +1549,25 @@ std::string cmGeneratorTarget::GetFullName(const std::string& config, std::string cmGeneratorTarget::GetInstallNameDirForBuildTree( const std::string& config) const { - // If building directly for installation then the build tree install_name - // is the same as the install tree. - if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) { - return this->GetInstallNameDirForInstallTree(); - } + if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { - // Use the build tree directory for the target. - if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") && - !this->Makefile->IsOn("CMAKE_SKIP_RPATH") && - !this->GetPropertyAsBool("SKIP_BUILD_RPATH")) { - std::string dir; - if (this->MacOSXRpathInstallNameDirDefault()) { - dir = "@rpath"; - } else { - dir = this->GetDirectory(config); + // If building directly for installation then the build tree install_name + // is the same as the install tree. + if (this->MacOSXUseInstallNameDir()) { + return this->GetInstallNameDirForInstallTree(); + } + + // Use the build tree directory for the target. + if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) { + std::string dir; + if (this->MacOSXRpathInstallNameDirDefault()) { + dir = "@rpath"; + } else { + dir = this->GetDirectory(config); + } + dir += "/"; + return dir; } - dir += "/"; - return dir; } return ""; } @@ -1531,8 +1578,7 @@ std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const std::string dir; const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR"); - if (!this->Makefile->IsOn("CMAKE_SKIP_RPATH") && - !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH")) { + if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) { if (install_name_dir && *install_name_dir) { dir = install_name_dir; dir += "/"; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index f568699..689fbda 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -525,6 +525,16 @@ public: /** Whether this library defaults to \@rpath. */ bool MacOSXRpathInstallNameDirDefault() const; + enum InstallNameType + { + INSTALL_NAME_FOR_BUILD, + INSTALL_NAME_FOR_INSTALL + }; + /** Whether to use INSTALL_NAME_DIR. */ + bool MacOSXUseInstallNameDir() const; + /** Whether to generate an install_name. */ + bool CanGenerateInstallNameDir(InstallNameType t) const; + /** Test for special case of a third-party shared library that has no soname at all. */ bool IsImportedSharedLibWithoutSOName(const std::string& config) const; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index f118250..b6b7d9e 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1194,6 +1194,11 @@ void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target) this->CMP0042WarnTargets.insert(target); } +void cmGlobalGenerator::AddCMP0068WarnTarget(const std::string& target) +{ + this->CMP0068WarnTargets.insert(target); +} + bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const { // If the property is not enabled then okay. @@ -1235,6 +1240,8 @@ bool cmGlobalGenerator::Compute() // clear targets to issue warning CMP0042 for this->CMP0042WarnTargets.clear(); + // clear targets to issue warning CMP0068 for + this->CMP0068WarnTargets.clear(); // Check whether this generator is allowed to run. if (!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS()) { @@ -1366,6 +1373,24 @@ void cmGlobalGenerator::Generate() this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } + if (!this->CMP0068WarnTargets.empty()) { + std::ostringstream w; + /* clang-format off */ + w << + cmPolicies::GetPolicyWarning(cmPolicies::CMP0068) << "\n" + "For compatibility with older versions of CMake, the install_name " + "fields for the following targets are still affected by RPATH " + "settings:\n" + ; + /* clang-format on */ + for (std::set<std::string>::iterator iter = + this->CMP0068WarnTargets.begin(); + iter != this->CMP0068WarnTargets.end(); ++iter) { + w << " " << *iter << "\n"; + } + this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + } + this->CMakeInstance->UpdateProgress("Generating done", -1); } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 18e3730..b3cb41f 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -357,6 +357,7 @@ public: cmExportBuildFileGenerator* GetExportedTargetsFile( const std::string& filename) const; void AddCMP0042WarnTarget(const std::string& target); + void AddCMP0068WarnTarget(const std::string& target); virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; @@ -562,6 +563,8 @@ private: // track targets to issue CMP0042 warning for. std::set<std::string> CMP0042WarnTargets; + // track targets to issue CMP0068 warning for. + std::set<std::string> CMP0068WarnTargets; mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*> > FilenameTargetDepends; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 62e67c7..ecf06b3 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -200,7 +200,10 @@ class cmMakefile; 7, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0067, \ "Honor language standard in try_compile() source-file signature.", \ - 3, 8, 0, cmPolicies::WARN) + 3, 8, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0068, \ + "RPATH settings on macOS do not affect install_name.", 3, 9, 0, \ + cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ @@ -221,7 +224,8 @@ class cmMakefile; F(CMP0052) \ F(CMP0060) \ F(CMP0063) \ - F(CMP0065) + F(CMP0065) \ + F(CMP0068) /** \class cmPolicies * \brief Handles changes in CMake behavior and policies diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index fe3472d..ad3d604 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -253,6 +253,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->SetPropertyDefault("WIN32_EXECUTABLE", CM_NULLPTR); this->SetPropertyDefault("MACOSX_BUNDLE", CM_NULLPTR); this->SetPropertyDefault("MACOSX_RPATH", CM_NULLPTR); + this->SetPropertyDefault("BUILD_WITH_INSTALL_NAME_DIR", CM_NULLPTR); this->SetPropertyDefault("C_CLANG_TIDY", CM_NULLPTR); this->SetPropertyDefault("C_COMPILER_LAUNCHER", CM_NULLPTR); this->SetPropertyDefault("C_CPPLINT", CM_NULLPTR); |