From d560bfd2739f2594119c49d82485b99bb4fbbe1f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 19:19:47 +0200 Subject: [PATCH] cmGeneratorTarget: Move GetInstallNameDir* from cmTarget. --- Source/cmExportBuildFileGenerator.cxx | 4 +- Source/cmExportBuildFileGenerator.h | 3 +- Source/cmExportFileGenerator.cxx | 2 +- Source/cmExportFileGenerator.h | 2 +- Source/cmExportInstallFileGenerator.cxx | 4 +- Source/cmExportInstallFileGenerator.h | 3 +- Source/cmExportTryCompileFileGenerator.cxx | 4 +- Source/cmExportTryCompileFileGenerator.h | 2 +- Source/cmGeneratorTarget.cxx | 67 +++++++++++++++++++++ Source/cmGeneratorTarget.h | 9 +++ Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmInstallTargetGenerator.cxx | 11 ++-- Source/cmMakefileLibraryTargetGenerator.cxx | 2 +- Source/cmNinjaNormalTargetGenerator.cxx | 3 +- Source/cmTarget.cxx | 67 --------------------- Source/cmTarget.h | 9 --- 16 files changed, 100 insertions(+), 94 deletions(-) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 6274c3fb6..fed0dbc90 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -333,12 +333,12 @@ cmExportBuildFileGenerator } std::string -cmExportBuildFileGenerator::InstallNameDir(cmTarget* target, +cmExportBuildFileGenerator::InstallNameDir(cmGeneratorTarget* target, const std::string& config) { std::string install_name_dir; - cmMakefile* mf = target->GetMakefile(); + cmMakefile* mf = target->Target->GetMakefile(); if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { install_name_dir = diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 4d8e0625d..ff3d2e1a9 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -71,7 +71,8 @@ protected: cmGeneratorTarget* target, ImportPropertyMap& properties); - std::string InstallNameDir(cmTarget* target, const std::string& config); + std::string InstallNameDir(cmGeneratorTarget* target, + const std::string& config); std::vector FindNamespaces(cmMakefile* mf, const std::string& name); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index e3652c56e..cae60b7e3 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -893,7 +893,7 @@ cmExportFileGenerator { if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { - value = this->InstallNameDir(target->Target, config); + value = this->InstallNameDir(target, config); } prop = "IMPORTED_SONAME"; value += target->GetSOName(config); diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 4e547404b..44f779b67 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -200,7 +200,7 @@ private: virtual void ReplaceInstallPrefix(std::string &input); - virtual std::string InstallNameDir(cmTarget* target, + virtual std::string InstallNameDir(cmGeneratorTarget* target, const std::string& config) = 0; }; diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index b0bc68653..d55be1172 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -546,12 +546,12 @@ cmExportInstallFileGenerator } std::string -cmExportInstallFileGenerator::InstallNameDir(cmTarget* target, +cmExportInstallFileGenerator::InstallNameDir(cmGeneratorTarget* target, const std::string&) { std::string install_name_dir; - cmMakefile* mf = target->GetMakefile(); + cmMakefile* mf = target->Target->GetMakefile(); if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { install_name_dir = diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 6f86ac9f9..b06fee541 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -83,7 +83,8 @@ protected: std::set& importedLocations ); - std::string InstallNameDir(cmTarget* target, const std::string& config); + std::string InstallNameDir(cmGeneratorTarget* target, + const std::string& config); cmInstallExportGenerator* IEGen; diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index 94831f86d..ba66531fd 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -125,12 +125,12 @@ cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target, } std::string -cmExportTryCompileFileGenerator::InstallNameDir(cmTarget* target, +cmExportTryCompileFileGenerator::InstallNameDir(cmGeneratorTarget* target, const std::string& config) { std::string install_name_dir; - cmMakefile* mf = target->GetMakefile(); + cmMakefile* mf = target->Target->GetMakefile(); if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { install_name_dir = diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 749f3efdd..8838eca82 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -45,7 +45,7 @@ protected: ImportPropertyMap& properties, std::set &emitted); - std::string InstallNameDir(cmTarget* target, + std::string InstallNameDir(cmGeneratorTarget* target, const std::string& config); private: std::string FindTargets(const std::string& prop, cmTarget const* tgt, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 45577e595..2de3c77ee 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -890,6 +890,73 @@ std::string cmGeneratorTarget::GetSOName(const std::string& config) const } } +//---------------------------------------------------------------------------- +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(); + } + + // 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->Target->MacOSXRpathInstallNameDirDefault()) + { + dir = "@rpath"; + } + else + { + dir = this->Target->GetDirectory(config); + } + dir += "/"; + return dir; + } + else + { + return ""; + } +} + +//---------------------------------------------------------------------------- +std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const +{ + if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) + { + 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(install_name_dir && *install_name_dir) + { + dir = install_name_dir; + dir += "/"; + } + } + if(!install_name_dir) + { + if(this->Target->MacOSXRpathInstallNameDirDefault()) + { + dir = "@rpath/"; + } + } + return dir; + } + else + { + return ""; + } +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::GetFullNameComponents(std::string& prefix, std::string& base, diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 8fc1b4489..6d084f7c4 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -115,6 +115,15 @@ public: bool realname) const; std::string NormalGetRealName(const std::string& config) const; + /** Return the install name directory for the target in the + * build tree. For example: "\@rpath/", "\@loader_path/", + * or "/full/path/to/library". */ + std::string GetInstallNameDirForBuildTree(const std::string& config) const; + + /** Return the install name directory for the target in the + * install tree. For example: "\@rpath/" or "\@loader_path/". */ + std::string GetInstallNameDirForInstallTree() const; + /** Get the soname of the target. Allowed only for a shared library. */ std::string GetSOName(const std::string& config) const; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 03f6d8f53..d53ecde41 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2331,7 +2331,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, if(target.GetType() == cmTarget::SHARED_LIBRARY) { // Get the install_name directory for the build tree. - install_name_dir = target.GetInstallNameDirForBuildTree(configName); + install_name_dir = gtgt->GetInstallNameDirForBuildTree(configName); // Xcode doesn't create the correct install_name in some cases. // That is, if the INSTALL_PATH is empty, or if we have versioning // of dylib libraries, we want to specify the install_name. diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 24c1c49e9..30cf17522 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -576,11 +576,14 @@ cmInstallTargetGenerator continue; } + cmGeneratorTarget *gtgt = tgt->GetMakefile() + ->GetGlobalGenerator() + ->GetGeneratorTarget(tgt); // If the build tree and install tree use different path // components of the install_name field then we need to create a // mapping to be applied after installation. - std::string for_build = tgt->GetInstallNameDirForBuildTree(config); - std::string for_install = tgt->GetInstallNameDirForInstallTree(); + std::string for_build = gtgt->GetInstallNameDirForBuildTree(config); + std::string for_install = gtgt->GetInstallNameDirForInstallTree(); if(for_build != for_install) { // The directory portions differ. Append the filename to @@ -605,9 +608,9 @@ cmInstallTargetGenerator if(this->Target->GetType() == cmTarget::SHARED_LIBRARY) { std::string for_build = - this->Target->Target->GetInstallNameDirForBuildTree(config); + this->Target->GetInstallNameDirForBuildTree(config); std::string for_install = - this->Target->Target->GetInstallNameDirForInstallTree(); + this->Target->GetInstallNameDirForInstallTree(); if(this->Target->Target->IsFrameworkOnApple() && for_install.empty()) { diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index a2fcbad02..b85b8a8df 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -666,7 +666,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules { // Get the install_name directory for the build tree. install_name_dir = - this->Target->GetInstallNameDirForBuildTree(this->ConfigName); + this->GeneratorTarget->GetInstallNameDirForBuildTree(this->ConfigName); // Set the rule variable replacement value. if(install_name_dir.empty()) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index c80f485dd..183584160 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -537,7 +537,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() vars["SONAME"] = this->TargetNameSO; if (targetType == cmTarget::SHARED_LIBRARY) { - std::string install_dir = target.GetInstallNameDirForBuildTree(cfgName); + std::string install_dir = + this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName); if (!install_dir.empty()) { vars["INSTALLNAME_DIR"] = localGen.Convert(install_dir, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0f1d3090a..b49ad9b51 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3845,73 +3845,6 @@ bool cmTarget::HaveInstallTreeRPATH() const !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"); } -//---------------------------------------------------------------------------- -std::string cmTarget::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 GetInstallNameDirForInstallTree(); - } - - // 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; - bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault(); - if(macosx_rpath) - { - dir = "@rpath"; - } - else - { - dir = this->GetDirectory(config); - } - dir += "/"; - return dir; - } - else - { - return ""; - } -} - -//---------------------------------------------------------------------------- -std::string cmTarget::GetInstallNameDirForInstallTree() const -{ - if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) - { - 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(install_name_dir && *install_name_dir) - { - dir = install_name_dir; - dir += "/"; - } - } - if(!install_name_dir) - { - if(this->MacOSXRpathInstallNameDirDefault()) - { - dir = "@rpath/"; - } - } - return dir; - } - else - { - return ""; - } -} - //---------------------------------------------------------------------------- const char* cmTarget::GetOutputTargetType(bool implib) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index d03ba3be0..c1c518f91 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -394,15 +394,6 @@ public: bool HaveBuildTreeRPATH(const std::string& config) const; bool HaveInstallTreeRPATH() const; - /** Return the install name directory for the target in the - * build tree. For example: "\@rpath/", "\@loader_path/", - * or "/full/path/to/library". */ - std::string GetInstallNameDirForBuildTree(const std::string& config) const; - - /** Return the install name directory for the target in the - * install tree. For example: "\@rpath/" or "\@loader_path/". */ - std::string GetInstallNameDirForInstallTree() const; - // Get the properties cmPropertyMap &GetProperties() const { return this->Properties; }