diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-07-17 14:20:58 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-07-24 09:11:25 (GMT) |
commit | e91bfe440c1419b445ef6746552dd03ba302e6cf (patch) | |
tree | d541b14cb020c209aef9f050f35dbe592dce20e1 /Source/cmFindPackageCommand.cxx | |
parent | f2ba968ef2a1c46e117dcd8eec34a55775f3d5f4 (diff) | |
download | CMake-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/cmFindPackageCommand.cxx')
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c6d599e..5d656c1 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -675,7 +675,9 @@ void cmFindPackageCommand::AddFindDefinition(const std::string& var, } else { this->OriginalDefs[var].exists = false; } - this->Makefile->AddDefinition(var, val); + if (val) { + this->Makefile->AddDefinition(var, val); + } } void cmFindPackageCommand::RestoreFindDefinitions() @@ -683,7 +685,7 @@ void cmFindPackageCommand::RestoreFindDefinitions() for (auto const& i : this->OriginalDefs) { OriginalDef const& od = i.second; if (od.exists) { - this->Makefile->AddDefinition(i.first, od.value.c_str()); + this->Makefile->AddDefinition(i.first, od.value); } else { this->Makefile->RemoveDefinition(i.first); } @@ -957,7 +959,7 @@ bool cmFindPackageCommand::HandlePackageMode( std::string fileVar = this->Name; fileVar += "_CONFIG"; if (found) { - this->Makefile->AddDefinition(fileVar, this->FileFound.c_str()); + this->Makefile->AddDefinition(fileVar, this->FileFound); } else { this->Makefile->RemoveDefinition(fileVar); } @@ -979,11 +981,9 @@ bool cmFindPackageCommand::HandlePackageMode( sep = ";"; } - this->Makefile->AddDefinition(consideredConfigsVar, - consideredConfigFiles.c_str()); + this->Makefile->AddDefinition(consideredConfigsVar, consideredConfigFiles); - this->Makefile->AddDefinition(consideredVersionsVar, - consideredVersions.c_str()); + this->Makefile->AddDefinition(consideredVersionsVar, consideredVersions); return result; } @@ -1612,8 +1612,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file, this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT"); // Set the input variables. - this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str()); - this->Makefile->AddDefinition("PACKAGE_FIND_VERSION", this->Version.c_str()); + this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name); + this->Makefile->AddDefinition("PACKAGE_FIND_VERSION", this->Version); char buf[64]; sprintf(buf, "%u", this->VersionMajor); this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf); @@ -1690,7 +1690,7 @@ void cmFindPackageCommand::StoreVersionFound() if (this->VersionFound.empty()) { this->Makefile->RemoveDefinition(ver); } else { - this->Makefile->AddDefinition(ver, this->VersionFound.c_str()); + this->Makefile->AddDefinition(ver, this->VersionFound); } // Store the version components. |