diff options
author | Brad King <brad.king@kitware.com> | 2021-05-13 14:08:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-13 16:48:22 (GMT) |
commit | d346805e419b213230e4ff24d8be0100bee7168d (patch) | |
tree | fdf3668b88783388e9aa1b022c8c93f41dac03d8 | |
parent | 15fa3200715869d5acb94a282feb301d2e10a0eb (diff) | |
download | CMake-d346805e419b213230e4ff24d8be0100bee7168d.zip CMake-d346805e419b213230e4ff24d8be0100bee7168d.tar.gz CMake-d346805e419b213230e4ff24d8be0100bee7168d.tar.bz2 |
cmLocalCommonGenerator: Select work directory semantically
-rw-r--r-- | Source/cmLocalCommonGenerator.cxx | 22 | ||||
-rw-r--r-- | Source/cmLocalCommonGenerator.h | 14 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 2 |
4 files changed, 30 insertions, 10 deletions
diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 50657f6..211525a 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -9,14 +9,17 @@ #include "cmMakefile.h" #include "cmOutputConverter.h" #include "cmProperty.h" +#include "cmState.h" +#include "cmStateDirectory.h" +#include "cmStateSnapshot.h" #include "cmStringAlgorithms.h" class cmGlobalGenerator; cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg, - cmMakefile* mf, std::string wd) + cmMakefile* mf, WorkDir wd) : cmLocalGenerator(gg, mf) - , WorkingDirectory(std::move(wd)) + , WorkingDirectory(wd) { this->ConfigNames = this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); @@ -24,10 +27,21 @@ cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg, cmLocalCommonGenerator::~cmLocalCommonGenerator() = default; +std::string const& cmLocalCommonGenerator::GetWorkingDirectory() const +{ + if (this->WorkingDirectory == WorkDir::TopBin) { + return this->GetState()->GetBinaryDirectory(); + } + return this->StateSnapshot.GetDirectory().GetCurrentBinary(); +} + std::string cmLocalCommonGenerator::MaybeRelativeToWorkDir( std::string const& path) const { - return this->MaybeRelativeTo(this->WorkingDirectory, path); + if (this->WorkingDirectory == WorkDir::TopBin) { + return this->MaybeRelativeToTopBinDir(path); + } + return this->MaybeRelativeToCurBinDir(path); } std::string cmLocalCommonGenerator::GetTargetFortranFlags( @@ -41,7 +55,7 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags( // Add a module output directory flag if necessary. std::string mod_dir = - target->GetFortranModuleDirectory(this->WorkingDirectory); + target->GetFortranModuleDirectory(this->GetWorkingDirectory()); if (!mod_dir.empty()) { mod_dir = this->ConvertToOutputFormat( this->MaybeRelativeToWorkDir(mod_dir), cmOutputConverter::SHELL); diff --git a/Source/cmLocalCommonGenerator.h b/Source/cmLocalCommonGenerator.h index 72c8e83..0505c13 100644 --- a/Source/cmLocalCommonGenerator.h +++ b/Source/cmLocalCommonGenerator.h @@ -20,9 +20,15 @@ class cmSourceFile; */ class cmLocalCommonGenerator : public cmLocalGenerator { +protected: + enum class WorkDir + { + TopBin, + CurBin, + }; + public: - cmLocalCommonGenerator(cmGlobalGenerator* gg, cmMakefile* mf, - std::string wd); + cmLocalCommonGenerator(cmGlobalGenerator* gg, cmMakefile* mf, WorkDir wd); ~cmLocalCommonGenerator() override; std::vector<std::string> const& GetConfigNames() const @@ -30,7 +36,7 @@ public: return this->ConfigNames; } - std::string GetWorkingDirectory() const { return this->WorkingDirectory; } + std::string const& GetWorkingDirectory() const; std::string MaybeRelativeToWorkDir(std::string const& path) const; @@ -42,7 +48,7 @@ public: cmGeneratorTarget const* gt = nullptr) override; protected: - std::string WorkingDirectory; + WorkDir WorkingDirectory; std::vector<std::string> ConfigNames; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 475045a..a8570e2 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -39,7 +39,7 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf) - : cmLocalCommonGenerator(gg, mf, mf->GetState()->GetBinaryDirectory()) + : cmLocalCommonGenerator(gg, mf, WorkDir::TopBin) { } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 4e7562d..a652c7b 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -110,7 +110,7 @@ private: cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3( cmGlobalGenerator* gg, cmMakefile* mf) - : cmLocalCommonGenerator(gg, mf, mf->GetCurrentBinaryDirectory()) + : cmLocalCommonGenerator(gg, mf, WorkDir::CurBin) { this->MakefileVariableSize = 0; this->ColorMakefile = false; |