summaryrefslogtreecommitdiffstats
path: root/Source/cmProjectCommand.cxx
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-07-17 14:20:58 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2019-07-24 09:11:25 (GMT)
commite91bfe440c1419b445ef6746552dd03ba302e6cf (patch)
treed541b14cb020c209aef9f050f35dbe592dce20e1 /Source/cmProjectCommand.cxx
parentf2ba968ef2a1c46e117dcd8eec34a55775f3d5f4 (diff)
downloadCMake-e91bfe440c1419b445ef6746552dd03ba302e6cf.zip
CMake-e91bfe440c1419b445ef6746552dd03ba302e6cf.tar.gz
CMake-e91bfe440c1419b445ef6746552dd03ba302e6cf.tar.bz2
cmMakefile: Let AddDefinition accept a value as cm::string_view
This changes `cmMakefile::AddDefinition` to take a `cm::string_view` as value argument instead of a `const char *`. Benefits are: - `std::string` can be passed to `cmMakefile::AddDefinition` directly without the `c_str()` plus string length recomputation fallback. - Lengths of literals passed to `cmMakefile::AddDefinition` can be computed at compile time. In various sources uses of `cmMakefile::AddDefinition` are adapted to avoid `std::string::c_str` calls and the `std::string` is passed directly. Uses of `cmMakefile::AddDefinition`, where a `nullptr` `const char*` might be passed to `cmMakefile::AddDefinition` are extended with `nullptr` checks.
Diffstat (limited to 'Source/cmProjectCommand.cxx')
-rw-r--r--Source/cmProjectCommand.cxx42
1 files changed, 20 insertions, 22 deletions
diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx
index e3d3bd8..1159ef7 100644
--- a/Source/cmProjectCommand.cxx
+++ b/Source/cmProjectCommand.cxx
@@ -45,12 +45,12 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
this->Makefile->GetCurrentSourceDirectory().c_str(),
"Value Computed by CMake", cmStateEnums::STATIC);
- this->Makefile->AddDefinition(
- "PROJECT_BINARY_DIR", this->Makefile->GetCurrentBinaryDirectory().c_str());
- this->Makefile->AddDefinition(
- "PROJECT_SOURCE_DIR", this->Makefile->GetCurrentSourceDirectory().c_str());
+ this->Makefile->AddDefinition("PROJECT_BINARY_DIR",
+ this->Makefile->GetCurrentBinaryDirectory());
+ this->Makefile->AddDefinition("PROJECT_SOURCE_DIR",
+ this->Makefile->GetCurrentSourceDirectory());
- this->Makefile->AddDefinition("PROJECT_NAME", projectName.c_str());
+ this->Makefile->AddDefinition("PROJECT_NAME", projectName);
// Set the CMAKE_PROJECT_NAME variable to be the highest-level
// project name in the tree. If there are two project commands
@@ -60,7 +60,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
// will work.
if (!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME") ||
(this->Makefile->IsRootMakefile())) {
- this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", projectName.c_str());
+ this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", projectName);
this->Makefile->AddCacheDefinition(
"CMAKE_PROJECT_NAME", projectName.c_str(), "Value Computed by CMake",
cmStateEnums::STATIC);
@@ -258,24 +258,24 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
std::string vv;
vv = projectName + "_VERSION";
- this->Makefile->AddDefinition("PROJECT_VERSION", version_string.c_str());
- this->Makefile->AddDefinition(vv, version_string.c_str());
+ this->Makefile->AddDefinition("PROJECT_VERSION", version_string);
+ this->Makefile->AddDefinition(vv, version_string);
vv = projectName + "_VERSION_MAJOR";
this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR",
- version_components[0].c_str());
- this->Makefile->AddDefinition(vv, version_components[0].c_str());
+ version_components[0]);
+ this->Makefile->AddDefinition(vv, version_components[0]);
vv = projectName + "_VERSION_MINOR";
this->Makefile->AddDefinition("PROJECT_VERSION_MINOR",
- version_components[1].c_str());
- this->Makefile->AddDefinition(vv, version_components[1].c_str());
+ version_components[1]);
+ this->Makefile->AddDefinition(vv, version_components[1]);
vv = projectName + "_VERSION_PATCH";
this->Makefile->AddDefinition("PROJECT_VERSION_PATCH",
- version_components[2].c_str());
- this->Makefile->AddDefinition(vv, version_components[2].c_str());
+ version_components[2]);
+ this->Makefile->AddDefinition(vv, version_components[2]);
vv = projectName + "_VERSION_TWEAK";
this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK",
- version_components[3].c_str());
- this->Makefile->AddDefinition(vv, version_components[3].c_str());
+ version_components[3]);
+ this->Makefile->AddDefinition(vv, version_components[3]);
// Also, try set top level variables
TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", version_string.c_str());
TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR",
@@ -327,14 +327,12 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
}
}
- this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description.c_str());
- this->Makefile->AddDefinition(projectName + "_DESCRIPTION",
- description.c_str());
+ this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description);
+ this->Makefile->AddDefinition(projectName + "_DESCRIPTION", description);
TopLevelCMakeVarCondSet("CMAKE_PROJECT_DESCRIPTION", description.c_str());
- this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage.c_str());
- this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL",
- homepage.c_str());
+ this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage);
+ this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL", homepage);
TopLevelCMakeVarCondSet("CMAKE_PROJECT_HOMEPAGE_URL", homepage.c_str());
if (languages.empty()) {