cmake::GetCacheDefinition: Return cmProp

This commit is contained in:
vvs31415
2020-09-28 09:00:00 -07:00
parent 1b03ac7da7
commit d298ae7470
8 changed files with 35 additions and 38 deletions

View File

@@ -446,13 +446,13 @@ bool cmExtraSublimeTextGenerator::Open(const std::string& bindir,
const std::string& projectName,
bool dryRun)
{
const char* sublExecutable =
cmProp sublExecutable =
this->GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(
"CMAKE_SUBLIMETEXT_EXECUTABLE");
if (!sublExecutable) {
return false;
}
if (cmIsNOTFOUND(sublExecutable)) {
if (cmIsNOTFOUND(*sublExecutable)) {
return false;
}
@@ -462,5 +462,5 @@ bool cmExtraSublimeTextGenerator::Open(const std::string& bindir,
}
return cmSystemTools::RunSingleCommand(
{ sublExecutable, "--project", filename });
{ *sublExecutable, "--project", filename });
}

View File

@@ -197,12 +197,12 @@ std::string cmGlobalGenerator::SelectMakeProgram(
{
std::string makeProgram = inMakeProgram;
if (cmIsOff(makeProgram)) {
const char* makeProgramCSTR =
cmProp makeProgramCSTR =
this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
if (cmIsOff(makeProgramCSTR)) {
makeProgram = makeDefault;
} else {
makeProgram = makeProgramCSTR;
makeProgram = *makeProgramCSTR;
}
if (cmIsOff(makeProgram) && !makeProgram.empty()) {
makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
@@ -2153,10 +2153,11 @@ void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen,
{
this->SetConfiguredFilesPath(gen);
this->TryCompileOuterMakefile = mf;
const char* make =
cmProp make =
gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
this->GetCMakeInstance()->AddCacheEntry(
"CMAKE_MAKE_PROGRAM", make, "make program", cmStateEnums::FILEPATH);
this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", cmToCStr(make),
"make program",
cmStateEnums::FILEPATH);
// copy the enabled languages
this->GetCMakeInstance()->GetState()->SetEnabledLanguages(
gen->GetCMakeInstance()->GetState()->GetEnabledLanguages());

View File

@@ -3,7 +3,6 @@
#include "cmGlobalGhsMultiGenerator.h"
#include <algorithm>
#include <cstring>
#include <map>
#include <ostream>
#include <utility>
@@ -335,23 +334,23 @@ void cmGlobalGhsMultiGenerator::WriteTopLevelProject(std::ostream& fout,
fout << "# Top Level Project File\n";
// Specify BSP option if supplied by user
const char* bspName =
cmProp bspName =
this->GetCMakeInstance()->GetCacheDefinition("GHS_BSP_NAME");
if (!cmIsOff(bspName)) {
fout << " -bsp " << bspName << '\n';
fout << " -bsp " << *bspName << '\n';
}
// Specify OS DIR if supplied by user
// -- not all platforms require this entry in the project file
if (!cmIsOff(this->OsDir)) {
const char* osDirOption =
cmProp osDirOption =
this->GetCMakeInstance()->GetCacheDefinition("GHS_OS_DIR_OPTION");
std::replace(this->OsDir.begin(), this->OsDir.end(), '\\', '/');
fout << " ";
if (cmIsOff(osDirOption)) {
fout << "";
} else {
fout << osDirOption;
fout << *osDirOption;
}
fout << "\"" << this->OsDir << "\"\n";
}
@@ -565,9 +564,9 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
{
GeneratedMakeCommand makeCommand = {};
std::string gbuild;
if (const char* gbuildCached =
if (cmProp gbuildCached =
this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM")) {
gbuild = gbuildCached;
gbuild = *gbuildCached;
}
makeCommand.Add(this->SelectMakeProgram(makeProgram, gbuild));
@@ -618,11 +617,10 @@ void cmGlobalGhsMultiGenerator::WriteMacros(std::ostream& fout,
cmLocalGenerator* root)
{
fout << "macro PROJ_NAME=" << root->GetProjectName() << '\n';
char const* ghsGpjMacros =
cmProp ghsGpjMacros =
this->GetCMakeInstance()->GetCacheDefinition("GHS_GPJ_MACROS");
if (nullptr != ghsGpjMacros) {
std::vector<std::string> expandedList =
cmExpandedList(std::string(ghsGpjMacros));
if (ghsGpjMacros) {
std::vector<std::string> expandedList = cmExpandedList(*ghsGpjMacros);
for (std::string const& arg : expandedList) {
fout << "macro " << arg << '\n';
}
@@ -634,17 +632,17 @@ void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives(
{
/* set primary target */
std::string tgt;
const char* t =
cmProp t =
this->GetCMakeInstance()->GetCacheDefinition("GHS_PRIMARY_TARGET");
if (cmNonempty(t)) {
tgt = t;
tgt = *t;
this->GetCMakeInstance()->MarkCliAsUsed("GHS_PRIMARY_TARGET");
} else {
const char* a =
cmProp a =
this->GetCMakeInstance()->GetCacheDefinition("CMAKE_GENERATOR_PLATFORM");
const char* p =
cmProp p =
this->GetCMakeInstance()->GetCacheDefinition("GHS_TARGET_PLATFORM");
tgt = cmStrCat((a ? a : ""), '_', (p ? p : ""), ".tgt");
tgt = cmStrCat((a ? *a : ""), '_', (p ? *p : ""), ".tgt");
}
/* clang-format off */
@@ -655,11 +653,11 @@ void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives(
<< "/CMakeFiles/custom_target.bod" << '\n';
/* clang-format on */
char const* const customization =
cmProp const customization =
this->GetCMakeInstance()->GetCacheDefinition("GHS_CUSTOMIZATION");
if (nullptr != customization && strlen(customization) > 0) {
if (cmNonempty(customization)) {
fout << "customization="
<< cmGlobalGhsMultiGenerator::TrimQuotes(customization) << '\n';
<< cmGlobalGhsMultiGenerator::TrimQuotes(*customization) << '\n';
this->GetCMakeInstance()->MarkCliAsUsed("GHS_CUSTOMIZATION");
}
}

View File

@@ -104,8 +104,8 @@ std::string cmGlobalUnixMakefileGenerator3::GetEditCacheCommand() const
cmStateEnums::INTERNAL);
}
}
const char* edit_cmd = cm->GetCacheDefinition("CMAKE_EDIT_COMMAND");
return edit_cmd ? edit_cmd : "";
cmProp edit_cmd = cm->GetCacheDefinition("CMAKE_EDIT_COMMAND");
return edit_cmd ? *edit_cmd : std::string();
}
void cmGlobalUnixMakefileGenerator3::ComputeTargetObjectDirectory(

View File

@@ -625,9 +625,9 @@ std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
{
std::string const& guidStoreName = name + "_GUID_CMAKE";
if (const char* storedGUID =
if (cmProp storedGUID =
this->CMakeInstance->GetCacheDefinition(guidStoreName)) {
return std::string(storedGUID);
return *storedGUID;
}
// Compute a GUID that is deterministic but unique to the build tree.
std::string input =

View File

@@ -3140,11 +3140,10 @@ std::string cmGlobalXCodeGenerator::GetOrCreateId(const std::string& name,
const std::string& id)
{
std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
const char* storedGUID =
this->CMakeInstance->GetCacheDefinition(guidStoreName);
cmProp storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName);
if (storedGUID) {
return storedGUID;
return *storedGUID;
}
this->CMakeInstance->AddCacheEntry(guidStoreName, id.c_str(),

View File

@@ -2000,10 +2000,9 @@ std::string cmake::StripExtension(const std::string& file) const
return file;
}
const char* cmake::GetCacheDefinition(const std::string& name) const
cmProp cmake::GetCacheDefinition(const std::string& name) const
{
cmProp p = this->State->GetInitializedCacheValue(name);
return p ? p->c_str() : nullptr;
return this->State->GetInitializedCacheValue(name);
}
void cmake::AddScriptingCommands()

View File

@@ -299,7 +299,7 @@ public:
/**
* Given a variable name, return its value (as a string).
*/
const char* GetCacheDefinition(const std::string&) const;
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);