diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-09-10 13:47:23 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-09-10 13:47:39 (GMT) |
commit | 9488f8a7b7c4b4f180d16cde8a819a7a5216ef56 (patch) | |
tree | 1c90c2fec972d3d1589e580a55b8a04bff9e74a6 | |
parent | 293070c325ec4cb91668dbe75dd259b7dfb0aa7d (diff) | |
parent | f84193292cb36e26d13a3f1f56a1539f088e8827 (diff) | |
download | CMake-9488f8a7b7c4b4f180d16cde8a819a7a5216ef56.zip CMake-9488f8a7b7c4b4f180d16cde8a819a7a5216ef56.tar.gz CMake-9488f8a7b7c4b4f180d16cde8a819a7a5216ef56.tar.bz2 |
Merge topic 'enh-AddCacheEntry-accepts-new-types'
f84193292c Use new AddCacheEntry signatures
3c2e58eeb8 AddCacheEntry accept cmProp or std::string
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6495
-rw-r--r-- | Source/cmCacheManager.cxx | 14 | ||||
-rw-r--r-- | Source/cmCacheManager.h | 16 | ||||
-rw-r--r-- | Source/cmFindBase.cxx | 4 | ||||
-rw-r--r-- | Source/cmGlobalCommonGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 5 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioVersionedGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 5 | ||||
-rw-r--r-- | Source/cmIncludeExternalMSProjectCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 8 | ||||
-rw-r--r-- | Source/cmState.cxx | 2 | ||||
-rw-r--r-- | Source/cmState.h | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 60 | ||||
-rw-r--r-- | Source/cmake.h | 12 |
14 files changed, 90 insertions, 63 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 8fefaa6..17369c8 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -232,17 +232,17 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) // before writing the cache, update the version numbers // to the this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", - std::to_string(cmVersion::GetMajorVersion()).c_str(), + std::to_string(cmVersion::GetMajorVersion()), "Major version of cmake used to create the " "current loaded cache", cmStateEnums::INTERNAL); this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", - std::to_string(cmVersion::GetMinorVersion()).c_str(), + std::to_string(cmVersion::GetMinorVersion()), "Minor version of cmake used to create the " "current loaded cache", cmStateEnums::INTERNAL); this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", - std::to_string(cmVersion::GetPatchVersion()).c_str(), + std::to_string(cmVersion::GetPatchVersion()), "Patch version of cmake used to create the " "current loaded cache", cmStateEnums::INTERNAL); @@ -256,7 +256,7 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) currentcwd[0] = static_cast<char>(currentcwd[0] - 'A' + 'a'); } cmSystemTools::ConvertToUnixSlashes(currentcwd); - this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(), + this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd, "This is the directory where this CMakeCache.txt" " was created", cmStateEnums::INTERNAL); @@ -521,7 +521,7 @@ void cmCacheManager::PrintCache(std::ostream& out) const "=================================================\n"; } -void cmCacheManager::AddCacheEntry(const std::string& key, const char* value, +void cmCacheManager::AddCacheEntry(const std::string& key, cmProp value, const char* helpString, cmStateEnums::CacheEntryType type) { @@ -550,10 +550,10 @@ void cmCacheManager::AddCacheEntry(const std::string& key, const char* value, : "(This variable does not exist and should not be used)"); } -void cmCacheManager::CacheEntry::SetValue(const char* value) +void cmCacheManager::CacheEntry::SetValue(cmProp value) { if (value) { - this->Value = value; + this->Value = *value; this->Initialized = true; } else { this->Value.clear(); diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 0238fb8..eca7150 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -31,7 +31,7 @@ class cmCacheManager public: const std::string& GetValue() const { return this->Value; } - void SetValue(const char*); + void SetValue(cmProp); cmStateEnums::CacheEntryType GetType() const { return this->Type; } void SetType(cmStateEnums::CacheEntryType ty) { this->Type = ty; } @@ -83,7 +83,7 @@ public: void SetCacheEntryValue(std::string const& key, std::string const& value) { if (auto* entry = this->GetCacheEntry(key)) { - entry->SetValue(value.c_str()); + entry->SetValue(cmProp(value)); } } @@ -173,6 +173,18 @@ public: //! Add an entry into the cache void AddCacheEntry(const std::string& key, const char* value, + const char* helpString, cmStateEnums::CacheEntryType type) + { + this->AddCacheEntry(key, + value ? cmProp(std::string(value)) : cmProp(nullptr), + helpString, type); + } + void AddCacheEntry(const std::string& key, const std::string& value, + const char* helpString, cmStateEnums::CacheEntryType type) + { + this->AddCacheEntry(key, cmProp(value), helpString, type); + } + void AddCacheEntry(const std::string& key, cmProp value, const char* helpString, cmStateEnums::CacheEntryType type); diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index f4e1763..37f9572 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -358,8 +358,8 @@ void cmFindBase::NormalizeFindResult() // value. if (value != *existingValue || this->AlreadyInCacheWithoutMetaInfo) { this->Makefile->GetCMakeInstance()->AddCacheEntry( - this->VariableName, value.c_str(), - this->VariableDocumentation.c_str(), this->VariableType); + this->VariableName, value, this->VariableDocumentation.c_str(), + this->VariableType); if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == cmPolicies::NEW) { if (this->Makefile->IsNormalDefinitionSet(this->VariableName)) { diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx index a8e0f23..24c8944 100644 --- a/Source/cmGlobalCommonGenerator.cxx +++ b/Source/cmGlobalCommonGenerator.cxx @@ -117,7 +117,7 @@ std::string cmGlobalCommonGenerator::GetEditCacheCommand() const editCacheCommand = cmSystemTools::GetCMakeGUICommand(); } if (!editCacheCommand.empty()) { - cm->AddCacheEntry("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(), + cm->AddCacheEntry("CMAKE_EDIT_COMMAND", editCacheCommand, "Path to cache edit program executable.", cmStateEnums::INTERNAL); } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 17cd95e..fd1a197 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2185,9 +2185,8 @@ void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen, this->TryCompileOuterMakefile = mf; cmProp make = gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM"); - this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", cmToCStr(make), - "make program", - cmStateEnums::FILEPATH); + this->GetCMakeInstance()->AddCacheEntry( + "CMAKE_MAKE_PROGRAM", make, "make program", cmStateEnums::FILEPATH); // copy the enabled languages this->GetCMakeInstance()->GetState()->SetEnabledLanguages( gen->GetCMakeInstance()->GetState()->GetEnabledLanguages()); diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index d0ad53e..3ecf32e 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -467,9 +467,9 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( // Save the selected instance persistently. std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"); if (vsInstance != genInstance) { - this->CMakeInstance->AddCacheEntry( - "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(), - "Generator instance identifier.", cmStateEnums::INTERNAL); + this->CMakeInstance->AddCacheEntry("CMAKE_GENERATOR_INSTANCE", vsInstance, + "Generator instance identifier.", + cmStateEnums::INTERNAL); } return true; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 763f12a..fa76b01 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3241,9 +3241,8 @@ std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name, return *storedGUID; } - this->CMakeInstance->AddCacheEntry(guidStoreName, id.c_str(), - "Stored Xcode object GUID", - cmStateEnums::INTERNAL); + this->CMakeInstance->AddCacheEntry( + guidStoreName, id, "Stored Xcode object GUID", cmStateEnums::INTERNAL); return id; } diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index 5b532ce..c8b4a39 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -77,9 +77,8 @@ bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args, if (!customGuid.empty()) { std::string guidVariable = utility_name + "_GUID_CMAKE"; - mf.GetCMakeInstance()->AddCacheEntry(guidVariable, customGuid.c_str(), - "Stored GUID", - cmStateEnums::INTERNAL); + mf.GetCMakeInstance()->AddCacheEntry( + guidVariable, customGuid, "Stored GUID", cmStateEnums::INTERNAL); } // Create a target instance for this utility. diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 06d738f..7b5fed6 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -2142,7 +2142,7 @@ void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID( std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE"); // save the GUID in the cache this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry( - guidStoreName, parser.GUID.c_str(), "Stored GUID", cmStateEnums::INTERNAL); + guidStoreName, parser.GUID, "Stored GUID", cmStateEnums::INTERNAL); } std::string cmLocalVisualStudio7Generator::GetTargetDirectory( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 9e7816f..ef31d76 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1927,7 +1927,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, nvalue += files[cc]; } - this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type); + this->GetCMakeInstance()->AddCacheEntry(name, nvalue, doc, type); nvalue = *this->GetState()->GetInitializedCacheValue(name); value = nvalue.c_str(); } @@ -3561,13 +3561,13 @@ int cmMakefile::TryCompile(const std::string& srcdir, // Tell the single-configuration generator which one to use. // Add this before the user-provided CMake arguments in case // one of the arguments is -DCMAKE_BUILD_TYPE=... - cm.AddCacheEntry("CMAKE_BUILD_TYPE", config->c_str(), - "Build configuration", cmStateEnums::STRING); + cm.AddCacheEntry("CMAKE_BUILD_TYPE", config, "Build configuration", + cmStateEnums::STRING); } } cmProp recursionDepth = this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH"); if (recursionDepth) { - cm.AddCacheEntry("CMAKE_MAXIMUM_RECURSION_DEPTH", recursionDepth->c_str(), + cm.AddCacheEntry("CMAKE_MAXIMUM_RECURSION_DEPTH", recursionDepth, "Maximum recursion depth", cmStateEnums::STRING); } // if cmake args were provided then pass them in diff --git a/Source/cmState.cxx b/Source/cmState.cxx index cfd9ad0..16718e8 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -206,7 +206,7 @@ bool cmState::GetCacheEntryPropertyAsBool(std::string const& key, return this->CacheManager->GetCacheEntryPropertyAsBool(key, propertyName); } -void cmState::AddCacheEntry(const std::string& key, const char* value, +void cmState::AddCacheEntry(const std::string& key, cmProp value, const char* helpString, cmStateEnums::CacheEntryType type) { diff --git a/Source/cmState.h b/Source/cmState.h index 0fd28d0..390f6d6 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -219,6 +219,18 @@ public: private: friend class cmake; void AddCacheEntry(const std::string& key, const char* value, + const char* helpString, cmStateEnums::CacheEntryType type) + { + this->AddCacheEntry(key, + value ? cmProp(std::string(value)) : cmProp(nullptr), + helpString, type); + } + void AddCacheEntry(const std::string& key, const std::string& value, + const char* helpString, cmStateEnums::CacheEntryType type) + { + this->AddCacheEntry(key, cmProp(value), helpString, type); + } + void AddCacheEntry(const std::string& key, cmProp value, const char* helpString, cmStateEnums::CacheEntryType type); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index beb5d16..7cafaee 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -605,9 +605,8 @@ void cmake::ProcessCacheArg(const std::string& var, const std::string& value, } } - this->AddCacheEntry(var, value.c_str(), - "No help, variable specified on the command line.", - type); + this->AddCacheEntry( + var, value, "No help, variable specified on the command line.", type); if (this->WarnUnusedCli) { if (!haveValue || @@ -1517,16 +1516,15 @@ void cmake::SetDirectoriesFromFile(const std::string& arg) int cmake::AddCMakePaths() { // Save the value in the cache - this->AddCacheEntry("CMAKE_COMMAND", - cmSystemTools::GetCMakeCommand().c_str(), + this->AddCacheEntry("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand(), "Path to CMake executable.", cmStateEnums::INTERNAL); #ifndef CMAKE_BOOTSTRAP - this->AddCacheEntry( - "CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(), - "Path to ctest program executable.", cmStateEnums::INTERNAL); - this->AddCacheEntry( - "CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(), - "Path to cpack program executable.", cmStateEnums::INTERNAL); + this->AddCacheEntry("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand(), + "Path to ctest program executable.", + cmStateEnums::INTERNAL); + this->AddCacheEntry("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand(), + "Path to cpack program executable.", + cmStateEnums::INTERNAL); #endif if (!cmSystemTools::FileExists( (cmSystemTools::GetCMakeRoot() + "/Modules/CMake.cmake"))) { @@ -1538,7 +1536,7 @@ int cmake::AddCMakePaths() cmSystemTools::GetCMakeRoot()); return 0; } - this->AddCacheEntry("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(), + this->AddCacheEntry("CMAKE_ROOT", cmSystemTools::GetCMakeRoot(), "Path to CMake installation.", cmStateEnums::INTERNAL); return 1; @@ -1886,7 +1884,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) this->LoadCache(); // restore the changed compilers for (SaveCacheEntry const& i : saved) { - this->AddCacheEntry(i.key, i.value.c_str(), i.help.c_str(), i.type); + this->AddCacheEntry(i.key, i.value, i.help.c_str(), i.type); } cmSystemTools::Message(warning.str()); // avoid reconfigure if there were errors @@ -1993,7 +1991,7 @@ int cmake::ActualConfigure() } if (!res) { this->AddCacheEntry( - "CMAKE_HOME_DIRECTORY", this->GetHomeDirectory().c_str(), + "CMAKE_HOME_DIRECTORY", this->GetHomeDirectory(), "Source directory with the top level CMakeLists.txt file for this " "project", cmStateEnums::INTERNAL); @@ -2038,19 +2036,17 @@ int cmake::ActualConfigure() } } if (!this->State->GetInitializedCacheValue("CMAKE_GENERATOR")) { - this->AddCacheEntry("CMAKE_GENERATOR", - this->GlobalGenerator->GetName().c_str(), + this->AddCacheEntry("CMAKE_GENERATOR", this->GlobalGenerator->GetName(), "Name of generator.", cmStateEnums::INTERNAL); - this->AddCacheEntry("CMAKE_EXTRA_GENERATOR", - this->GlobalGenerator->GetExtraGeneratorName().c_str(), - "Name of external makefile project generator.", - cmStateEnums::INTERNAL); + this->AddCacheEntry( + "CMAKE_EXTRA_GENERATOR", this->GlobalGenerator->GetExtraGeneratorName(), + "Name of external makefile project generator.", cmStateEnums::INTERNAL); if (!this->State->GetInitializedCacheValue("CMAKE_TOOLCHAIN_FILE")) { std::string envToolchain; if (cmSystemTools::GetEnv("CMAKE_TOOLCHAIN_FILE", envToolchain) && !envToolchain.empty()) { - this->AddCacheEntry("CMAKE_TOOLCHAIN_FILE", envToolchain.c_str(), + this->AddCacheEntry("CMAKE_TOOLCHAIN_FILE", envToolchain, "The CMake toolchain file", cmStateEnums::FILEPATH); } @@ -2069,9 +2065,9 @@ int cmake::ActualConfigure() return -2; } } else { - this->AddCacheEntry( - "CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance.c_str(), - "Generator instance identifier.", cmStateEnums::INTERNAL); + this->AddCacheEntry("CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance, + "Generator instance identifier.", + cmStateEnums::INTERNAL); } if (cmProp platformName = @@ -2087,8 +2083,7 @@ int cmake::ActualConfigure() return -2; } } else { - this->AddCacheEntry("CMAKE_GENERATOR_PLATFORM", - this->GeneratorPlatform.c_str(), + this->AddCacheEntry("CMAKE_GENERATOR_PLATFORM", this->GeneratorPlatform, "Name of generator platform.", cmStateEnums::INTERNAL); } @@ -2104,8 +2099,7 @@ int cmake::ActualConfigure() return -2; } } else { - this->AddCacheEntry("CMAKE_GENERATOR_TOOLSET", - this->GeneratorToolset.c_str(), + this->AddCacheEntry("CMAKE_GENERATOR_TOOLSET", this->GeneratorToolset, "Name of generator toolset.", cmStateEnums::INTERNAL); } @@ -2416,7 +2410,7 @@ int cmake::Generate() return 0; } -void cmake::AddCacheEntry(const std::string& key, const char* value, +void cmake::AddCacheEntry(const std::string& key, cmProp value, const char* helpString, int type) { this->State->AddCacheEntry(key, value, helpString, @@ -3540,7 +3534,7 @@ void cmake::SetSuppressDevWarnings(bool b) value = "FALSE"; } - this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", value.c_str(), + this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", value, "Suppress Warnings that are meant for" " the author of the CMakeLists.txt files.", cmStateEnums::INTERNAL); @@ -3564,7 +3558,7 @@ void cmake::SetSuppressDeprecatedWarnings(bool b) value = "TRUE"; } - this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value.c_str(), + this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value, "Whether to issue warnings for deprecated " "functionality.", cmStateEnums::INTERNAL); @@ -3588,7 +3582,7 @@ void cmake::SetDevWarningsAsErrors(bool b) value = "TRUE"; } - this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value.c_str(), + this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_ERRORS", value, "Suppress errors that are meant for" " the author of the CMakeLists.txt files.", cmStateEnums::INTERNAL); @@ -3612,7 +3606,7 @@ void cmake::SetDeprecatedWarningsAsErrors(bool b) value = "FALSE"; } - this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value.c_str(), + this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value, "Whether to issue deprecation errors for macros" " and functions.", cmStateEnums::INTERNAL); diff --git a/Source/cmake.h b/Source/cmake.h index 32c7582..7408044 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -332,6 +332,18 @@ public: cmProp GetCacheDefinition(const std::string&) const; //! Add an entry into the cache void AddCacheEntry(const std::string& key, const char* value, + const char* helpString, int type) + { + this->AddCacheEntry(key, + value ? cmProp(std::string(value)) : cmProp(nullptr), + helpString, type); + } + void AddCacheEntry(const std::string& key, const std::string& value, + const char* helpString, int type) + { + this->AddCacheEntry(key, cmProp(value), helpString, type); + } + void AddCacheEntry(const std::string& key, cmProp value, const char* helpString, int type); bool DoWriteGlobVerifyTarget() const; |