From 3b6f1587bed536e3d31e6665aff35aa27f5e79bc Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Tue, 30 Aug 2016 20:55:37 +0200 Subject: Factor IDE folder name retrieval out into helper method Add a `cmGeneratorTarget::GetEffectiveFolderName` helper to abstract lookup of the `FOLDER` property in combination with checking for generator support of folders. --- Source/cmGeneratorTarget.cxx | 16 ++++++++++++++++ Source/cmGeneratorTarget.h | 3 +++ Source/cmGhsMultiTargetGenerator.cxx | 4 +--- Source/cmGlobalGenerator.cxx | 2 +- Source/cmGlobalGenerator.h | 3 ++- Source/cmGlobalGhsMultiGenerator.cxx | 6 +----- Source/cmGlobalVisualStudio7Generator.cxx | 4 ++-- Source/cmGlobalXCodeGenerator.cxx | 4 ++-- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 7eb0ebf..f11149a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1767,6 +1767,22 @@ std::string cmGeneratorTarget::GetMacContentDirectory( return fpath; } +std::string cmGeneratorTarget::GetEffectiveFolderName() const +{ + std::string effectiveFolder; + + if (!this->GlobalGenerator->UseFolderProperty()) { + return effectiveFolder; + } + + const char* targetFolder = this->GetProperty("FOLDER"); + if (targetFolder) { + effectiveFolder += targetFolder; + } + + return effectiveFolder; +} + cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo( const std::string& config) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 68ffd5c..9382726 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -220,6 +220,9 @@ public: std::string GetMacContentDirectory(const std::string& config = CM_NULLPTR, bool implib = false) const; + /** @return folder prefix for IDEs. */ + std::string GetEffectiveFolderName() const; + cmTarget* Target; cmMakefile* Makefile; cmLocalGenerator* LocalGenerator; diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 5fbaea4..3154f8d 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -44,9 +44,7 @@ cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator() std::string cmGhsMultiTargetGenerator::GetRelBuildFilePath( const cmGeneratorTarget* target) { - std::string output; - char const* folderProp = target->GetProperty("FOLDER"); - output = NULL == folderProp ? "" : folderProp; + std::string output = target->GetEffectiveFolderName(); cmSystemTools::ConvertToUnixSlashes(output); if (!output.empty()) { output += "/"; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1aa6af1..7d0c2da 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2377,7 +2377,7 @@ const char* cmGlobalGenerator::GetPredefinedTargetsFolder() return "CMakePredefinedTargets"; } -bool cmGlobalGenerator::UseFolderProperty() +bool cmGlobalGenerator::UseFolderProperty() const { const char* prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty("USE_FOLDERS"); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 38eaa76..c3498e0 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -334,6 +334,8 @@ public: i.e. "Can I build Debug and Release in the same tree?" */ virtual bool IsMultiConfig() const { return false; } + virtual bool UseFolderProperty() const; + std::string GetSharedLibFlagsForLanguage(std::string const& lang) const; /** Generate an .rule file path for a given command output. */ @@ -463,7 +465,6 @@ protected: std::string const& name) const; const char* GetPredefinedTargetsFolder(); - virtual bool UseFolderProperty(); private: #if defined(CMAKE_BUILD_WITH_CMAKE) diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 0eac338..d4ae677 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -439,11 +439,7 @@ void cmGlobalGhsMultiGenerator::UpdateBuildFiles( tgtsI != tgts.end(); ++tgtsI) { const cmGeneratorTarget* tgt = *tgtsI; if (IsTgtForBuild(tgt)) { - char const* rawFolderName = tgt->GetProperty("FOLDER"); - if (NULL == rawFolderName) { - rawFolderName = ""; - } - std::string folderName(rawFolderName); + std::string folderName = tgt->GetEffectiveFolderName(); if (this->TargetFolderBuildStreams.end() == this->TargetFolderBuildStreams.find(folderName)) { this->AddFilesUpToPath( diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 3637fed..0287def 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -409,8 +409,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( // Create "solution folder" information from FOLDER target property // if (written && this->UseFolderProperty()) { - const char* targetFolder = target->GetProperty("FOLDER"); - if (targetFolder) { + const std::string targetFolder = target->GetEffectiveFolderName(); + if (!targetFolder.empty()) { std::vector tokens = cmSystemTools::SplitString(targetFolder, '/', false); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0ddfc9a..7b1afa5 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2723,8 +2723,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( { std::string s; std::string target; - const char* targetFolder = gtgt->GetProperty("FOLDER"); - if (targetFolder) { + const std::string targetFolder = gtgt->GetEffectiveFolderName(); + if (!targetFolder.empty()) { target = targetFolder; target += "/"; } -- cgit v0.12