diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2021-07-08 14:10:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-07-08 16:15:10 (GMT) |
commit | 854dcb0d01676f444d0aae9e6a095a80c5819496 (patch) | |
tree | 4b8fcac5c687daf962861f7990b03c05cd0f8596 | |
parent | 16d9c317a30431b98c144f9529124746e4ea1d80 (diff) | |
download | CMake-854dcb0d01676f444d0aae9e6a095a80c5819496.zip CMake-854dcb0d01676f444d0aae9e6a095a80c5819496.tar.gz CMake-854dcb0d01676f444d0aae9e6a095a80c5819496.tar.bz2 |
cmMakefile: Split out CreateNewTarget from AddNewTarget
`CreateNewTarget` tells whether the target is inserted or not.
-rw-r--r-- | Source/cmMakefile.cxx | 20 | ||||
-rw-r--r-- | Source/cmMakefile.h | 5 |
2 files changed, 19 insertions, 6 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index f6ecf8e..7ac5113 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2118,15 +2118,23 @@ cmTarget* cmMakefile::AddExecutable(const std::string& exeName, cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, const std::string& name) { - auto it = this->Targets - .emplace(name, - cmTarget(name, type, cmTarget::VisibilityNormal, this, - cmTarget::PerConfig::Yes)) - .first; + return &this->CreateNewTarget(name, type).first; +} + +std::pair<cmTarget&, bool> cmMakefile::CreateNewTarget( + const std::string& name, cmStateEnums::TargetType type, + cmTarget::PerConfig perConfig) +{ + auto ib = this->Targets.emplace( + name, cmTarget(name, type, cmTarget::VisibilityNormal, this, perConfig)); + auto it = ib.first; + if (!ib.second) { + return std::make_pair(std::ref(it->second), false); + } this->OrderedTargets.push_back(&it->second); this->GetGlobalGenerator()->IndexTarget(&it->second); this->GetStateSnapshot().GetDirectory().AddNormalTargetName(name); - return &it->second; + return std::make_pair(std::ref(it->second), true); } cmTarget* cmMakefile::AddNewUtilityTarget(const std::string& utilityName, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 14c1a0f..5886c86 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -13,6 +13,7 @@ #include <stack> #include <string> #include <unordered_map> +#include <utility> #include <vector> #include <cm/optional> @@ -230,6 +231,10 @@ public: cmTarget* AddImportedTarget(const std::string& name, cmStateEnums::TargetType type, bool global); + std::pair<cmTarget&, bool> CreateNewTarget( + const std::string& name, cmStateEnums::TargetType type, + cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes); + cmTarget* AddNewTarget(cmStateEnums::TargetType type, const std::string& name); |