Commit e91bfe44 authored by Sebastian Holtermann's avatar Sebastian Holtermann

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.
parent f2ba968e
......@@ -759,7 +759,7 @@ int cmCPackGenerator::InstallCMakeProject(
if (this->GetOption("CPACK_INSTALL_PREFIX")) {
dir += this->GetOption("CPACK_INSTALL_PREFIX");
}
mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir);
cmCPackLogger(
cmCPackLog::LOG_DEBUG,
......@@ -799,7 +799,7 @@ int cmCPackGenerator::InstallCMakeProject(
return 0;
}
} else {
mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
if (!cmsys::SystemTools::MakeDirectory(tempInstallDirectory,
default_dir_mode)) {
......@@ -818,11 +818,11 @@ int cmCPackGenerator::InstallCMakeProject(
}
if (!buildConfig.empty()) {
mf.AddDefinition("BUILD_TYPE", buildConfig.c_str());
mf.AddDefinition("BUILD_TYPE", buildConfig);
}
std::string installComponentLowerCase = cmSystemTools::LowerCase(component);
if (installComponentLowerCase != "all") {
mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component.c_str());
mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component);
}
// strip on TRUE, ON, 1, one or several file names, but not on
......@@ -863,9 +863,8 @@ int cmCPackGenerator::InstallCMakeProject(
// forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
// to CPack (may be used by generators like CPack RPM or DEB)
// in order to transparently handle ABSOLUTE PATH
if (mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES",
mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"));
if (const char* def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", def);
}
// Now rebuild the list of files after installation
......
......@@ -270,7 +270,7 @@ int main(int argc, char const* const* argv)
}
if (!cpackBuildConfig.empty()) {
globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig);
}
if (cmSystemTools::FileExists(cpackConfigFile)) {
......@@ -292,24 +292,21 @@ int main(int argc, char const* const* argv)
}
if (!generator.empty()) {
globalMF.AddDefinition("CPACK_GENERATOR", generator.c_str());
globalMF.AddDefinition("CPACK_GENERATOR", generator);
}
if (!cpackProjectName.empty()) {
globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName);
}
if (!cpackProjectVersion.empty()) {
globalMF.AddDefinition("CPACK_PACKAGE_VERSION",
cpackProjectVersion.c_str());
globalMF.AddDefinition("CPACK_PACKAGE_VERSION", cpackProjectVersion);
}
if (!cpackProjectVendor.empty()) {
globalMF.AddDefinition("CPACK_PACKAGE_VENDOR",
cpackProjectVendor.c_str());
globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", cpackProjectVendor);
}
// if this is not empty it has been set on the command line
// go for it. Command line override values set in config file.
if (!cpackProjectDirectory.empty()) {
globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY",
cpackProjectDirectory.c_str());
globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory);
}
// The value has not been set on the command line
else {
......@@ -318,11 +315,11 @@ int main(int argc, char const* const* argv)
// use default value iff no value has been provided by the config file
if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) {
globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY",
cpackProjectDirectory.c_str());
cpackProjectDirectory);
}
}
for (auto const& cd : definitions.Map) {
globalMF.AddDefinition(cd.first, cd.second.c_str());
globalMF.AddDefinition(cd.first, cd.second);
}
const char* cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH");
......@@ -426,7 +423,7 @@ int main(int argc, char const* const* argv)
std::ostringstream ostr;
ostr << projVersionMajor << "." << projVersionMinor << "."
<< projVersionPatch;
mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str());
mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str());
}
int res = cpackGenerator->DoPackage();
......
......@@ -156,15 +156,14 @@ bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args,
if (this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS]) {
std::ostringstream str;
str << this->Handler->GetTotalErrors();
this->Makefile->AddDefinition(this->Values[ctb_NUMBER_ERRORS],
str.str().c_str());
this->Makefile->AddDefinition(this->Values[ctb_NUMBER_ERRORS], str.str());
}
if (this->Values[ctb_NUMBER_WARNINGS] &&
*this->Values[ctb_NUMBER_WARNINGS]) {
std::ostringstream str;
str << this->Handler->GetTotalWarnings();
this->Makefile->AddDefinition(this->Values[ctb_NUMBER_WARNINGS],
str.str().c_str());
str.str());
}
return ret;
}
......@@ -230,8 +230,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
if (this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) {
std::ostringstream str;
str << res;
this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE],
str.str().c_str());
this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE], str.str());
}
this->ProcessAdditionalValues(handler);
// log the error message if there was an error
......
......@@ -3,7 +3,6 @@
#include "cmCTestMemCheckCommand.h"
#include <sstream>
#include <string>
#include <vector>
#include "cmCTest.h"
......@@ -47,7 +46,6 @@ void cmCTestMemCheckCommand::ProcessAdditionalValues(
if (this->Values[ctm_DEFECT_COUNT] && *this->Values[ctm_DEFECT_COUNT]) {
std::ostringstream str;
str << static_cast<cmCTestMemCheckHandler*>(handler)->GetDefectCount();
this->Makefile->AddDefinition(this->Values[ctm_DEFECT_COUNT],
str.str().c_str());
this->Makefile->AddDefinition(this->Values[ctm_DEFECT_COUNT], str.str());
}
}
......@@ -43,7 +43,7 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args,
args[i].c_str(), !np, &ret);
std::ostringstream str;
str << ret;
this->Makefile->AddDefinition(returnVariable, str.str().c_str());
this->Makefile->AddDefinition(returnVariable, str.str());
}
}
return true;
......
......@@ -168,7 +168,7 @@ void cmCTestScriptHandler::UpdateElapsedTime()
auto itime = cmDurationTo<unsigned int>(std::chrono::steady_clock::now() -
this->ScriptStartTime);
auto timeString = std::to_string(itime);
this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString.c_str());
this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString);
}
}
......@@ -352,21 +352,21 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
this->CreateCMake();
// set a variable with the path to the current script
this->Makefile->AddDefinition(
"CTEST_SCRIPT_DIRECTORY", cmSystemTools::GetFilenamePath(script).c_str());
this->Makefile->AddDefinition(
"CTEST_SCRIPT_NAME", cmSystemTools::GetFilenameName(script).c_str());
this->Makefile->AddDefinition("CTEST_SCRIPT_DIRECTORY",
cmSystemTools::GetFilenamePath(script));
this->Makefile->AddDefinition("CTEST_SCRIPT_NAME",
cmSystemTools::GetFilenameName(script));
this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME",
cmSystemTools::GetCTestCommand().c_str());
cmSystemTools::GetCTestCommand());
this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
cmSystemTools::GetCMakeCommand().c_str());
cmSystemTools::GetCMakeCommand());
this->Makefile->AddDefinitionBool("CTEST_RUN_CURRENT_SCRIPT", true);
this->SetRunCurrentScript(true);
this->UpdateElapsedTime();
// add the script arg if defined
if (!script_arg.empty()) {
this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg.c_str());
this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg);
}
#if defined(__CYGWIN__)
......@@ -398,7 +398,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
const std::map<std::string, std::string>& defs =
this->CTest->GetDefinitions();
for (auto const& d : defs) {
this->Makefile->AddDefinition(d.first, d.second.c_str());
this->Makefile->AddDefinition(d.first, d.second);
}
// finally read in the script
......
......@@ -143,7 +143,7 @@ bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
if (this->Values[cts_BUILD_ID] && *this->Values[cts_BUILD_ID]) {
this->Makefile->AddDefinition(this->Values[cts_BUILD_ID],
this->CTest->GetBuildID().c_str());
this->CTest->GetBuildID());
}
return ret;
......
......@@ -1714,8 +1714,7 @@ void cmCTestTestHandler::GetListOfTests()
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
mf.AddDefinition("CTEST_CONFIGURATION_TYPE",
this->CTest->GetConfigType().c_str());
mf.AddDefinition("CTEST_CONFIGURATION_TYPE", this->CTest->GetConfigType());
// Add handler for ADD_TEST
auto newCom1 = cm::make_unique<cmCTestAddTestCommand>();
......
......@@ -74,6 +74,6 @@ bool cmAuxSourceDirectoryCommand::InitialPass(
sourceListValue += ";";
}
sourceListValue += cmJoin(files, ";");
this->Makefile->AddDefinition(args[1], sourceListValue.c_str());
this->Makefile->AddDefinition(args[1], sourceListValue);
return true;
}
......@@ -92,7 +92,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
target, configuration, "", this->Makefile->IgnoreErrorsCMP0061());
this->Makefile->AddDefinition(variable, makecommand.c_str());
this->Makefile->AddDefinition(variable, makecommand);
return true;
}
......
......@@ -55,7 +55,7 @@ bool cmCMakeHostSystemInformationCommand::InitialPass(
result_list += value;
}
this->Makefile->AddDefinition(variable, result_list.c_str());
this->Makefile->AddDefinition(variable, result_list);
return true;
}
......
......@@ -61,8 +61,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
}
// Save the required version string.
this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
version_min.c_str());
this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION", version_min);
// Get the current version number.
unsigned int current_major = cmVersion::GetMajorVersion();
......
......@@ -209,8 +209,7 @@ bool cmCMakePolicyCommand::HandleGetWarningMode(
}
// Lookup the policy warning.
this->Makefile->AddDefinition(var,
cmPolicies::GetPolicyWarning(pid).c_str());
this->Makefile->AddDefinition(var, cmPolicies::GetPolicyWarning(pid));
return true;
}
......@@ -65,8 +65,10 @@ unsigned int CCONV cmGetMinorVersion(void*)
void CCONV cmAddDefinition(void* arg, const char* name, const char* value)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
mf->AddDefinition(name, value);
if (value) {
cmMakefile* mf = static_cast<cmMakefile*>(arg);
mf->AddDefinition(name, value);
}
}
/* Add a definition to this makefile and the global cmake cache. */
......
......@@ -932,7 +932,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
cmStateEnums::INTERNAL);
if (!outputVariable.empty()) {
this->Makefile->AddDefinition(outputVariable, output.c_str());
this->Makefile->AddDefinition(outputVariable, output);
}
if (this->SrcFileSignature) {
......@@ -961,8 +961,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
if (!copyFileError.empty()) {
this->Makefile->AddDefinition(copyFileError,
copyFileErrorMessage.c_str());
this->Makefile->AddDefinition(copyFileError, copyFileErrorMessage);
}
}
return res;
......
......@@ -125,16 +125,15 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
}
if (!extraInclude.empty()) {
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
extraInclude.c_str());
extraInclude);
}
if (!function.empty()) {
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION",
function.c_str());
this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function);
}
this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
forwardDeclareCode.c_str());
forwardDeclareCode);
this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
functionMapCode.c_str());
functionMapCode);
bool res = true;
if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) {
res = false;
......@@ -154,6 +153,6 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
sourceListValue += *i;
}
this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
this->Makefile->AddDefinition(sourceList, sourceListValue);
return res;
}
......@@ -103,7 +103,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
}
std::string coutput = std::string(output, first, last - first + 1);
this->Makefile->AddDefinition(output_variable, coutput.c_str());
this->Makefile->AddDefinition(output_variable, coutput);
}
if (!return_variable.empty()) {
......
......@@ -332,7 +332,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
}
}
this->Makefile->AddDefinition(arguments.ResultsVariable,
cmJoin(res, ";").c_str());
cmJoin(res, ";"));
} break;
case cmsysProcess_State_Exception:
this->Makefile->AddDefinition(arguments.ResultsVariable,
......
......@@ -117,8 +117,9 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
}
sourceListValue += generatedSourcesClasses[classNum]->GetFullPath();
}
std::string const varName = target + "_FLTK_UI_SRCS";
this->Makefile->AddDefinition(varName, sourceListValue.c_str());
this->Makefile->AddDefinition(varName, sourceListValue);
this->Makefile->AddFinalAction(
[target](cmMakefile& makefile) { FinalAction(makefile, target); });
......
......@@ -365,7 +365,7 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
}
}
}
this->Makefile->AddDefinition(variable, output.c_str());
this->Makefile->AddDefinition(variable, output);
return true;
}
......@@ -383,7 +383,7 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args)
if (hash) {
std::string out = hash->HashFile(args[1]);
if (!out.empty()) {
this->Makefile->AddDefinition(args[2], out.c_str());
this->Makefile->AddDefinition(args[2], out);
return true;
}
std::ostringstream e;
......@@ -751,7 +751,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
}
// Save the output in a makefile variable.
this->Makefile->AddDefinition(outVar, output.c_str());
this->Makefile->AddDefinition(outVar, output);
return true;
}
......@@ -938,7 +938,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
std::sort(files.begin(), files.end());
files.erase(std::unique(files.begin(), files.end()), files.end());
this->Makefile->AddDefinition(variable, cmJoin(files, ";").c_str());
this->Makefile->AddDefinition(variable, cmJoin(files, ";"));
return true;
}
......@@ -1298,14 +1298,14 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args)
if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
std::string rpath(se_rpath->Value);
std::replace(rpath.begin(), rpath.end(), ':', ';');
this->Makefile->AddDefinition(arguments.RPath, rpath.c_str());
this->Makefile->AddDefinition(arguments.RPath, rpath);
}
}
if (!arguments.RunPath.empty()) {
if (cmELF::StringEntry const* se_runpath = elf.GetRunPath()) {
std::string runpath(se_runpath->Value);
std::replace(runpath.begin(), runpath.end(), ':', ';');
this->Makefile->AddDefinition(arguments.RunPath, runpath.c_str());
this->Makefile->AddDefinition(arguments.RunPath, runpath);
}
}
......@@ -1316,7 +1316,7 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args)
this->SetError(error);
return false;
}
this->Makefile->AddDefinition(arguments.Error, error.c_str());
this->Makefile->AddDefinition(arguments.Error, error);
return true;
#endif
}
......@@ -1354,7 +1354,7 @@ bool cmFileCommand::HandleRelativePathCommand(
}
std::string res = cmSystemTools::RelativePath(directoryName, fileName);
this->Makefile->AddDefinition(outVar, res.c_str());
this->Makefile->AddDefinition(outVar, res);
return true;
}
......@@ -1460,7 +1460,7 @@ bool cmFileCommand::HandleCMakePathCommand(
std::string value = cmJoin(
cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";");
this->Makefile->AddDefinition(args[2], value.c_str());
this->Makefile->AddDefinition(args[2], value);
return true;
}
......@@ -1800,7 +1800,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
if (!statusVar.empty()) {
std::ostringstream result;
result << 0 << ";\"" << msg;
this->Makefile->AddDefinition(statusVar, result.str().c_str());
this->Makefile->AddDefinition(statusVar, result.str());
}
return true;
}
......@@ -1949,7 +1949,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
std::ostringstream result;
result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res)
<< "\"";
this->Makefile->AddDefinition(statusVar, result.str().c_str());
this->Makefile->AddDefinition(statusVar, result.str());
}
::curl_global_cleanup();
......@@ -1981,7 +1981,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
std::string status = "1;HASH mismatch: "
"expected: " +
expectedHash + " actual: " + actualHash;
this->Makefile->AddDefinition(statusVar, status.c_str());
this->Makefile->AddDefinition(statusVar, status);
}
this->SetError(oss.str());
......@@ -2236,7 +2236,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
std::ostringstream result;
result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res)
<< "\"";
this->Makefile->AddDefinition(statusVar, result.str().c_str());
this->Makefile->AddDefinition(statusVar, result.str());
}
::curl_global_cleanup();
......@@ -2261,7 +2261,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
log += "\n";
}
this->Makefile->AddDefinition(logVar, log.c_str());
this->Makefile->AddDefinition(logVar, log);
}
return true;
......@@ -2479,7 +2479,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
}
if (!resultVariable.empty()) {
this->Makefile->AddDefinition(resultVariable, result.c_str());
this->Makefile->AddDefinition(resultVariable, result);
}
return true;
......@@ -2528,7 +2528,7 @@ bool cmFileCommand::HandleTimestampCommand(
cmTimestamp timestamp;
std::string result =
timestamp.FileModificationTime(filename.c_str(), formatString, utcFlag);
this->Makefile->AddDefinition(outputVariable, result.c_str());
this->Makefile->AddDefinition(outputVariable, result);
return true;
}
......@@ -2556,8 +2556,7 @@ bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args)
}
this->Makefile->AddDefinition(
outputVariable,
std::to_string(cmSystemTools::FileLength(filename)).c_str());
outputVariable, std::to_string(cmSystemTools::FileLength(filename)));
return true;
}
......@@ -2584,7 +2583,7 @@ bool cmFileCommand::HandleReadSymlinkCommand(
return false;
}
this->Makefile->AddDefinition(outputVariable, result.c_str());
this->Makefile->AddDefinition(outputVariable, result);
return true;
}
......@@ -2630,7 +2629,7 @@ bool cmFileCommand::HandleCreateLinkCommand(
if (fileName == newFileName) {
result = "CREATE_LINK cannot use same file and newfile";
if (!arguments.Result.empty()) {
this->Makefile->AddDefinition(arguments.Result, result.c_str());
this->Makefile->AddDefinition(arguments.Result, result);
return true;
}
this->SetError(result);
......@@ -2641,7 +2640,7 @@ bool cmFileCommand::HandleCreateLinkCommand(
if (!arguments.Symbolic && !cmSystemTools::FileExists(fileName)) {
result = "Cannot hard link \'" + fileName + "\' as it does not exist.";
if (!arguments.Result.empty()) {
this->Makefile->AddDefinition(arguments.Result, result.c_str());
this->Makefile->AddDefinition(arguments.Result, result);
return true;
}
this->SetError(result);
......@@ -2658,7 +2657,7 @@ bool cmFileCommand::HandleCreateLinkCommand(
<< cmSystemTools::GetLastSystemError() << "\n";
if (!arguments.Result.empty()) {
this->Makefile->AddDefinition(arguments.Result, e.str().c_str());
this->Makefile->AddDefinition(arguments.Result, e.str());
return true;
}
this->SetError(e.str());
......@@ -2693,7 +2692,7 @@ bool cmFileCommand::HandleCreateLinkCommand(
}
if (!arguments.Result.empty()) {
this->Makefile->AddDefinition(arguments.Result, result.c_str());
this->Makefile->AddDefinition(arguments.Result, result);
}
return true;
......@@ -2821,7 +2820,7 @@ bool cmFileCommand::HandleGetRuntimeDependenciesCommand(
std::string varName =
parsedArgs.ConflictingDependenciesPrefix + "_" + val.first;
std::string pathsStr = cmJoin(paths, ";");
this->Makefile->AddDefinition(varName, pathsStr.c_str());
this->Makefile->AddDefinition(varName, pathsStr);
} else {
std::ostringstream e;
e << "Multiple conflicting paths found for " << val.first << ":";
......@@ -2851,18 +2850,16 @@ bool cmFileCommand::HandleGetRuntimeDependenciesCommand(
if (!parsedArgs.ResolvedDependenciesVar.empty()) {
std::string val = cmJoin(deps, ";");
this->Makefile->AddDefinition(parsedArgs.ResolvedDependenciesVar,
val.c_str());
this->Makefile->AddDefinition(parsedArgs.ResolvedDependenciesVar, val);
}
if (!parsedArgs.UnresolvedDependenciesVar.empty()) {
std::string val = cmJoin(unresolvedDeps, ";");
this->Makefile->AddDefinition(parsedArgs.UnresolvedDependenciesVar,
val.c_str());
this->Makefile->AddDefinition(parsedArgs.UnresolvedDependenciesVar, val);
}
if (!parsedArgs.ConflictingDependenciesPrefix.empty()) {
std::string val = cmJoin(conflictingDeps, ";");
this->Makefile->AddDefinition(
parsedArgs.ConflictingDependenciesPrefix + "_FILENAMES", val.c_str());
parsedArgs.ConflictingDependenciesPrefix + "_FILENAMES", val);
}
return true;
}
......@@ -38,7 +38,7 @@ cmFileInstaller::~cmFileInstaller()
{
// Save the updated install manifest.
this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES",
this->Manifest.c_str());
this->Manifest);
}
void cmFileInstaller::ManifestAppend(std::string const& file)
......
......@@ -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.
......
......@@ -53,7 +53,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
// set the variable to the loop value
mf.AddDefinition(this->Args[0], arg.c_str());
mf.AddDefinition(this->Args[0], arg);
// Invoke all the functions that were collected in the block.
cmExecutionStatus status(mf);
for (cmListFileFunction const& func : this->Functions) {
......@@ -62,12 +62,12 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
if (status.GetReturnInvoked()) {
inStatus.SetReturnInvoked();
// restore the variable to its prior value
mf.AddDefinition(this->Args[0], oldDef.c_str());
mf.AddDefinition(this->Args[0], oldDef);
return true;
}
if (status.GetBreakInvoked()) {
// restore the variable to its prior value
mf.AddDefinition(this->Args[0], oldDef.c_str());
mf.AddDefinition(this->Args[0], oldDef);
return true;
}
if (status.GetContinueInvoked()) {
......@@ -80,7 +80,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
}
// restore the variable to its prior value
mf.AddDefinition(this->Args[0], oldDef.c_str());
mf.AddDefinition(this->Args[0], oldDef);
return true;
}
// close out a nested foreach
......