From 2065bd73cb6a9a3bc463c5bb0dc6877433782973 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Jul 2021 14:12:45 -0400 Subject: cmState: Construct with mode --- Source/CTest/cmCTestTestHandler.cxx | 2 +- Source/cmState.cxx | 12 ++++-------- Source/cmState.h | 15 +++++++-------- Source/cmake.cxx | 3 +-- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 72b86c1..b60a664 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2165,7 +2165,7 @@ bool cmCTestTestHandler::SetTestsProperties( // Ensure we have complete triples otherwise the data is corrupt. if (triples.size() % 3 == 0) { - cmState state; + cmState state(cmState::Unknown); rt.Backtrace = cmListFileBacktrace(state.CreateBaseSnapshot()); // the first entry represents the top of the trace so we need to diff --git a/Source/cmState.cxx b/Source/cmState.cxx index ce6eb31..b235abd 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -26,7 +26,8 @@ #include "cmSystemTools.h" #include "cmake.h" -cmState::cmState() +cmState::cmState(Mode mode) + : StateMode(mode) { this->CacheManager = cm::make_unique(); this->GlobVerificationManager = cm::make_unique(); @@ -771,17 +772,12 @@ unsigned int cmState::GetCacheMinorVersion() const cmState::Mode cmState::GetMode() const { - return this->CurrentMode; + return this->StateMode; } std::string cmState::GetModeString() const { - return ModeToString(this->CurrentMode); -} - -void cmState::SetMode(cmState::Mode mode) -{ - this->CurrentMode = mode; + return ModeToString(this->StateMode); } std::string cmState::ModeToString(cmState::Mode mode) diff --git a/Source/cmState.h b/Source/cmState.h index 9951b9a..c7f6a1e 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -35,12 +35,6 @@ class cmState friend class cmStateSnapshot; public: - cmState(); - ~cmState(); - - cmState(const cmState&) = delete; - cmState& operator=(const cmState&) = delete; - enum Mode { Unknown, @@ -51,6 +45,12 @@ public: CPack, }; + cmState(Mode mode); + ~cmState(); + + cmState(const cmState&) = delete; + cmState& operator=(const cmState&) = delete; + static const std::string& GetTargetTypeName( cmStateEnums::TargetType targetType); @@ -207,7 +207,6 @@ public: Mode GetMode() const; std::string GetModeString() const; - void SetMode(Mode mode); static std::string ModeToString(Mode mode); @@ -258,5 +257,5 @@ private: bool NMake = false; bool MSYSShell = false; bool NinjaMulti = false; - Mode CurrentMode = Unknown; + Mode StateMode = Unknown; }; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 73f5ad5..a2b2571 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -162,11 +162,10 @@ cmake::cmake(Role role, cmState::Mode mode) #ifndef CMAKE_BOOTSTRAP , VariableWatch(cm::make_unique()) #endif - , State(cm::make_unique()) + , State(cm::make_unique(mode)) , Messenger(cm::make_unique()) { this->TraceFile.close(); - this->State->SetMode(mode); this->CurrentSnapshot = this->State->CreateBaseSnapshot(); #ifdef __APPLE__ -- cgit v0.12 From 6c440ea3ce36d4c5b1629f111f376e809c7e99b2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Jul 2021 14:23:38 -0400 Subject: cmake: Model normal and try-compile project kinds explicitly Construct with the project kind instead of mutating state after construction. --- Source/cmListFileCache.cxx | 4 ++-- Source/cmMakefile.cxx | 4 ++-- Source/cmState.cxx | 23 ++++++++++------------- Source/cmState.h | 15 ++++++++++----- Source/cmake.cxx | 17 ++++++----------- Source/cmake.h | 4 ++-- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 4f7c959..2e444f2 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -548,7 +548,7 @@ void cmListFileBacktrace::PrintTitle(std::ostream& out) const } cmListFileContext lfc = this->TopEntry->Context; cmStateSnapshot bottom = this->GetBottom(); - if (!bottom.GetState()->GetIsInTryCompile()) { + if (bottom.GetState()->GetProjectKind() == cmState::ProjectKind::Normal) { lfc.FilePath = cmSystemTools::RelativeIfUnder( bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } @@ -579,7 +579,7 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const out << "Call Stack (most recent call first):\n"; } cmListFileContext lfc = cur->Context; - if (!bottom.GetState()->GetIsInTryCompile()) { + if (bottom.GetState()->GetProjectKind() == cmState::ProjectKind::Normal) { lfc.FilePath = cmSystemTools::RelativeIfUnder( bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7ac5113..6d477a7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3567,8 +3567,8 @@ int cmMakefile::TryCompile(const std::string& srcdir, // make sure the same generator is used // use this program as the cmake to be run, it should not // be run that way but the cmake object requires a vailid path - cmake cm(cmake::RoleProject, cmState::Project); - cm.SetIsInTryCompile(true); + cmake cm(cmake::RoleProject, cmState::Project, + cmState::ProjectKind::TryCompile); auto gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName()); if (!gg) { this->IssueMessage(MessageType::INTERNAL_ERROR, diff --git a/Source/cmState.cxx b/Source/cmState.cxx index b235abd..bdb5bda 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -26,8 +26,9 @@ #include "cmSystemTools.h" #include "cmake.h" -cmState::cmState(Mode mode) +cmState::cmState(Mode mode, ProjectKind projectKind) : StateMode(mode) + , StateProjectKind(projectKind) { this->CacheManager = cm::make_unique(); this->GlobVerificationManager = cm::make_unique(); @@ -382,16 +383,6 @@ void cmState::ClearEnabledLanguages() this->EnabledLanguages.clear(); } -bool cmState::GetIsInTryCompile() const -{ - return this->IsInTryCompile; -} - -void cmState::SetIsInTryCompile(bool b) -{ - this->IsInTryCompile = b; -} - bool cmState::GetIsGeneratorMultiConfig() const { return this->IsGeneratorMultiConfig; @@ -594,8 +585,9 @@ cmProp cmState::GetGlobalProperty(const std::string& prop) std::vector commands = this->GetCommandNames(); this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str()); } else if (prop == "IN_TRY_COMPILE") { - this->SetGlobalProperty("IN_TRY_COMPILE", - this->IsInTryCompile ? "1" : "0"); + this->SetGlobalProperty( + "IN_TRY_COMPILE", + this->StateProjectKind == ProjectKind::TryCompile ? "1" : "0"); } else if (prop == "GENERATOR_IS_MULTI_CONFIG") { this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG", this->IsGeneratorMultiConfig ? "1" : "0"); @@ -799,6 +791,11 @@ std::string cmState::ModeToString(cmState::Mode mode) return "UNKNOWN"; } +cmState::ProjectKind cmState::GetProjectKind() const +{ + return this->StateProjectKind; +} + std::string const& cmState::GetBinaryDirectory() const { return this->BinaryDirectory; diff --git a/Source/cmState.h b/Source/cmState.h index c7f6a1e..8561fc0 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -45,7 +45,13 @@ public: CPack, }; - cmState(Mode mode); + enum class ProjectKind + { + Normal, + TryCompile, + }; + + cmState(Mode mode, ProjectKind projectKind = ProjectKind::Normal); ~cmState(); cmState(const cmState&) = delete; @@ -141,9 +147,6 @@ public: void SetEnabledLanguages(std::vector const& langs); void ClearEnabledLanguages(); - bool GetIsInTryCompile() const; - void SetIsInTryCompile(bool b); - bool GetIsGeneratorMultiConfig() const; void SetIsGeneratorMultiConfig(bool b); @@ -210,6 +213,8 @@ public: static std::string ModeToString(Mode mode); + ProjectKind GetProjectKind() const; + private: friend class cmake; void AddCacheEntry(const std::string& key, const char* value, @@ -247,7 +252,6 @@ private: std::string SourceDirectory; std::string BinaryDirectory; - bool IsInTryCompile = false; bool IsGeneratorMultiConfig = false; bool WindowsShell = false; bool WindowsVSIDE = false; @@ -258,4 +262,5 @@ private: bool MSYSShell = false; bool NinjaMulti = false; Mode StateMode = Unknown; + ProjectKind StateProjectKind = ProjectKind::Normal; }; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index a2b2571..ab8309d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -156,13 +156,13 @@ static void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/, } #endif -cmake::cmake(Role role, cmState::Mode mode) +cmake::cmake(Role role, cmState::Mode mode, cmState::ProjectKind projectKind) : CMakeWorkingDirectory(cmSystemTools::GetCurrentWorkingDirectory()) , FileTimeCache(cm::make_unique()) #ifndef CMAKE_BOOTSTRAP , VariableWatch(cm::make_unique()) #endif - , State(cm::make_unique(mode)) + , State(cm::make_unique(mode, projectKind)) , Messenger(cm::make_unique()) { this->TraceFile.close(); @@ -1842,7 +1842,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) std::vector argsSplit = cmExpandedList(var, true); // erase the property to avoid infinite recursion this->State->SetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", ""); - if (this->State->GetIsInTryCompile()) { + if (this->GetIsInTryCompile()) { return 0; } std::vector saved; @@ -2110,7 +2110,7 @@ int cmake::ActualConfigure() // reset any system configuration information, except for when we are // InTryCompile. With TryCompile the system info is taken from the parent's // info to save time - if (!this->State->GetIsInTryCompile()) { + if (!this->GetIsInTryCompile()) { this->GlobalGenerator->ClearEnabledLanguages(); this->TruncateOutputLog("CMakeOutput.log"); @@ -2621,19 +2621,14 @@ void cmake::SetProgressCallback(ProgressCallbackType f) void cmake::UpdateProgress(const std::string& msg, float prog) { - if (this->ProgressCallback && !this->State->GetIsInTryCompile()) { + if (this->ProgressCallback && !this->GetIsInTryCompile()) { this->ProgressCallback(msg, prog); } } bool cmake::GetIsInTryCompile() const { - return this->State->GetIsInTryCompile(); -} - -void cmake::SetIsInTryCompile(bool b) -{ - this->State->SetIsInTryCompile(b); + return this->State->GetProjectKind() == cmState::ProjectKind::TryCompile; } void cmake::AppendGlobalGeneratorsDocumentation( diff --git a/Source/cmake.h b/Source/cmake.h index 5a2a88f..12cce7e 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -168,7 +168,8 @@ public: static const int DEFAULT_BUILD_PARALLEL_LEVEL = 0; /// Default constructor - cmake(Role role, cmState::Mode mode); + cmake(Role role, cmState::Mode mode, + cmState::ProjectKind projectKind = cmState::ProjectKind::Normal); /// Destructor ~cmake(); @@ -356,7 +357,6 @@ public: //! Is this cmake running as a result of a TRY_COMPILE command bool GetIsInTryCompile() const; - void SetIsInTryCompile(bool b); #ifndef CMAKE_BOOTSTRAP void SetWarningFromPreset(const std::string& name, -- cgit v0.12