Merge topic 'getdef-expand'

7ed8c9ebe3 cmMakefile: add GetDefExpandList() that splits value into std::vector

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4819
This commit is contained in:
Brad King
2020-06-02 12:02:14 +00:00
committed by Kitware Robot
16 changed files with 70 additions and 137 deletions
+9 -24
View File
@@ -1331,18 +1331,13 @@ void cmComputeLinkInformation::ComputeFrameworkInfo()
std::vector<std::string> implicitDirVec;
// Get platform-wide implicit directories.
if (const char* implicitLinks = this->Makefile->GetDefinition(
"CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES")) {
cmExpandList(implicitLinks, implicitDirVec);
}
this->Makefile->GetDefExpandList(
"CMAKE_PLATFORM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES", implicitDirVec);
// Get language-specific implicit directories.
std::string implicitDirVar = cmStrCat(
"CMAKE_", this->LinkLanguage, "_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES");
if (const char* implicitDirs =
this->Makefile->GetDefinition(implicitDirVar)) {
cmExpandList(implicitDirs, implicitDirVec);
}
this->Makefile->GetDefExpandList(implicitDirVar, implicitDirVec);
this->FrameworkPathsEmmitted.insert(implicitDirVec.begin(),
implicitDirVec.end());
@@ -1555,10 +1550,8 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
std::vector<std::string> implicitDirVec;
// Get platform-wide implicit directories.
if (const char* implicitLinks = (this->Makefile->GetDefinition(
"CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES"))) {
cmExpandList(implicitLinks, implicitDirVec);
}
this->Makefile->GetDefExpandList("CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES",
implicitDirVec);
// Append library architecture to all implicit platform directories
// and add them to the set
@@ -1572,10 +1565,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
// Get language-specific implicit directories.
std::string implicitDirVar =
cmStrCat("CMAKE_", this->LinkLanguage, "_IMPLICIT_LINK_DIRECTORIES");
if (const char* implicitDirs =
this->Makefile->GetDefinition(implicitDirVar)) {
cmExpandList(implicitDirs, implicitDirVec);
}
this->Makefile->GetDefExpandList(implicitDirVar, implicitDirVec);
// Store implicit link directories.
this->ImplicitLinkDirs.insert(implicitDirVec.begin(), implicitDirVec.end());
@@ -1584,10 +1574,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
std::vector<std::string> implicitLibVec;
std::string implicitLibVar =
cmStrCat("CMAKE_", this->LinkLanguage, "_IMPLICIT_LINK_LIBRARIES");
if (const char* implicitLibs =
this->Makefile->GetDefinition(implicitLibVar)) {
cmExpandList(implicitLibs, implicitLibVec);
}
this->Makefile->GetDefExpandList(implicitLibVar, implicitLibVec);
// Store implicit link libraries.
for (std::string const& item : implicitLibVec) {
@@ -1599,10 +1586,8 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
}
// Get platform specific rpath link directories
if (const char* rpathDirs =
(this->Makefile->GetDefinition("CMAKE_PLATFORM_RUNTIME_PATH"))) {
cmExpandList(rpathDirs, this->RuntimeLinkDirs);
}
this->Makefile->GetDefExpandList("CMAKE_PLATFORM_RUNTIME_PATH",
this->RuntimeLinkDirs);
}
std::vector<std::string> const&
+1 -3
View File
@@ -384,9 +384,7 @@ void cmDependsC::SetupTransforms()
// Get the transformation rules.
std::vector<std::string> transformRules;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
if (const char* xform = mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS")) {
cmExpandList(xform, transformRules, true);
}
mf->GetDefExpandList("CMAKE_INCLUDE_TRANSFORMS", transformRules, true);
for (std::string const& tr : transformRules) {
this->ParseTransform(tr);
}
+2 -8
View File
@@ -80,10 +80,7 @@ cmDependsFortran::cmDependsFortran(cmLocalUnixMakefileGenerator3* lg)
// Get the list of definitions.
std::vector<std::string> definitions;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
if (const char* c_defines =
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS_Fortran")) {
cmExpandList(c_defines, definitions);
}
mf->GetDefExpandList("CMAKE_TARGET_DEFINITIONS_Fortran", definitions);
// translate i.e. FOO=BAR to FOO and add it to the list of defined
// preprocessor symbols
@@ -243,10 +240,7 @@ void cmDependsFortran::LocateModules()
// Load information about other targets.
cmMakefile* mf = this->LocalGenerator->GetMakefile();
std::vector<std::string> infoFiles;
if (const char* infoFilesValue =
mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES")) {
cmExpandList(infoFilesValue, infoFiles);
}
mf->GetDefExpandList("CMAKE_TARGET_LINKED_INFO_FILES", infoFiles);
for (std::string const& i : infoFiles) {
std::string targetDir = cmSystemTools::GetFilenamePath(i);
std::string fname = targetDir + "/fortran.internal";
+1 -7
View File
@@ -4,7 +4,6 @@
#include <algorithm>
#include <array>
#include <cstring>
#include <utility>
#include <cmext/algorithm>
@@ -280,12 +279,7 @@ void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
// Construct the list of path roots with no trailing slashes.
for (const char** pathName = paths; *pathName; ++pathName) {
// Get the list of paths to ignore from the variable.
const char* ignorePath = this->Makefile->GetDefinition(*pathName);
if ((ignorePath == nullptr) || (strlen(ignorePath) == 0)) {
continue;
}
cmExpandList(ignorePath, ignore);
this->Makefile->GetDefExpandList(*pathName, ignore);
}
for (std::string& i : ignore) {
+1 -3
View File
@@ -505,9 +505,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
case cmPolicies::NEW: {
// NEW behavior is to honor the <pkg>_ROOT variables.
std::string const rootVar = this->Name + "_ROOT";
if (const char* pkgRoot = this->Makefile->GetDefinition(rootVar)) {
cmExpandList(pkgRoot, rootPaths, false);
}
this->Makefile->GetDefExpandList(rootVar, rootPaths, false);
cmSystemTools::GetPath(rootPaths, rootVar.c_str());
} break;
}
+18 -45
View File
@@ -1486,11 +1486,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
}
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugSources =
!this->DebugSourcesDone && cm::contains(debugProperties, "SOURCES");
@@ -3306,11 +3303,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
nullptr, nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugIncludes = !this->DebugIncludesDone &&
cm::contains(debugProperties, "INCLUDE_DIRECTORIES");
@@ -3493,11 +3487,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugOptions = !this->DebugCompileOptionsDone &&
cm::contains(debugProperties, "COMPILE_OPTIONS");
@@ -3538,11 +3529,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugFeatures = !this->DebugCompileFeaturesDone &&
cm::contains(debugProperties, "COMPILE_FEATURES");
@@ -3585,11 +3573,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
nullptr, nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugDefines = !this->DebugCompileDefinitionsDone &&
cm::contains(debugProperties, "COMPILE_DEFINITIONS");
@@ -3645,11 +3630,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
nullptr, nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugDefines = !this->DebugPrecompileHeadersDone &&
std::find(debugProperties.begin(), debugProperties.end(),
@@ -4024,11 +4006,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugOptions = !this->DebugLinkOptionsDone &&
cm::contains(debugProperties, "LINK_OPTIONS");
@@ -4286,11 +4265,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Makefile->GetDefExpandList("CMAKE_DEBUG_TARGET_PROPERTIES",
debugProperties);
bool debugDirectories = !this->DebugLinkDirectoriesDone &&
cm::contains(debugProperties, "LINK_DIRECTORIES");
@@ -5811,11 +5787,8 @@ void cmGeneratorTarget::ReportPropertyOrigin(
const std::string& compatibilityType) const
{
std::vector<std::string> debugProperties;
const char* debugProp = this->Target->GetMakefile()->GetDefinition(
"CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmExpandList(debugProp, debugProperties);
}
this->Target->GetMakefile()->GetDefExpandList(
"CMAKE_DEBUG_TARGET_PROPERTIES", debugProperties);
bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
cm::contains(debugProperties, p);
+2 -3
View File
@@ -2524,9 +2524,8 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.push_back("--force-new-ctest-process");
if (auto testArgs = mf->GetDefinition("CMAKE_CTEST_ARGUMENTS")) {
std::vector<std::string> args;
cmExpandList(testArgs, args);
std::vector<std::string> args;
if (mf->GetDefExpandList("CMAKE_CTEST_ARGUMENTS", args)) {
for (auto const& arg : args) {
singleLine.push_back(arg);
}
+2 -3
View File
@@ -3204,10 +3204,9 @@ std::string cmGlobalXCodeGenerator::GetObjectsDirectory(
void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf)
{
this->Architectures.clear();
const char* osxArch = mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
const char* sysroot = mf->GetDefinition("CMAKE_OSX_SYSROOT");
if (osxArch && sysroot) {
cmExpandList(std::string(osxArch), this->Architectures);
if (sysroot) {
mf->GetDefExpandList("CMAKE_OSX_ARCHITECTURES", this->Architectures);
}
if (this->Architectures.empty()) {
+4 -5
View File
@@ -1236,11 +1236,10 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
// * Compilers like gfortran do not search their own implicit include
// directories for modules ('.mod' files).
if (lang != "Fortran") {
const char* value = this->Makefile->GetDefinition(
cmStrCat("CMAKE_", lang, "_IMPLICIT_INCLUDE_DIRECTORIES"));
if (value != nullptr) {
size_t const impDirVecOldSize = impDirVec.size();
cmExpandList(value, impDirVec);
size_t const impDirVecOldSize = impDirVec.size();
if (this->Makefile->GetDefExpandList(
cmStrCat("CMAKE_", lang, "_IMPLICIT_INCLUDE_DIRECTORIES"),
impDirVec)) {
// FIXME: Use cmRange with 'advance()' when it supports non-const.
for (size_t i = impDirVecOldSize; i < impDirVec.size(); ++i) {
cmSystemTools::ConvertToUnixSlashes(impDirVec[i]);
+13 -4
View File
@@ -2745,6 +2745,18 @@ const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const
return *def;
}
bool cmMakefile::GetDefExpandList(const std::string& name,
std::vector<std::string>& out,
bool emptyArgs) const
{
cmProp def = this->GetDef(name);
if (!def) {
return false;
}
cmExpandList(*def, out, emptyArgs);
return true;
}
std::vector<std::string> cmMakefile::GetDefinitions() const
{
std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
@@ -3273,10 +3285,7 @@ std::string cmMakefile::GetConfigurations(std::vector<std::string>& configs,
bool singleConfig) const
{
if (this->GetGlobalGenerator()->IsMultiConfig()) {
if (const char* configTypes =
this->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
cmExpandList(configTypes, configs);
}
this->GetDefExpandList("CMAKE_CONFIGURATION_TYPES", configs);
return "";
}
const std::string& buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
+2
View File
@@ -512,6 +512,8 @@ public:
const std::string& GetSafeDefinition(const std::string&) const;
const std::string& GetRequiredDefinition(const std::string& name) const;
bool IsDefinitionSet(const std::string&) const;
bool GetDefExpandList(const std::string& name, std::vector<std::string>& out,
bool emptyArgs = false) const;
/**
* Get the list of all variables in the current space. If argument
* cacheonly is specified and is greater than 0, then only cache
@@ -478,9 +478,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// add it now.
std::string implibRuleVar =
cmStrCat("CMAKE_", linkLanguage, "_CREATE_IMPORT_LIBRARY");
if (const char* rule = this->Makefile->GetDefinition(implibRuleVar)) {
cmExpandList(rule, real_link_commands);
}
this->Makefile->GetDefExpandList(implibRuleVar, real_link_commands);
}
bool useResponseFileForObjects =
+3 -9
View File
@@ -642,27 +642,21 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
arCreateVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
arCreateVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arCreateVar)) {
cmExpandList(rule, archiveCreateCommands);
}
this->Makefile->GetDefExpandList(arCreateVar, archiveCreateCommands);
std::string arAppendVar =
cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_APPEND");
arAppendVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
arAppendVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arAppendVar)) {
cmExpandList(rule, archiveAppendCommands);
}
this->Makefile->GetDefExpandList(arAppendVar, archiveAppendCommands);
std::string arFinishVar =
cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_FINISH");
arFinishVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
arFinishVar, linkLanguage, this->GetConfigName());
if (const char* rule = this->Makefile->GetDefinition(arFinishVar)) {
cmExpandList(rule, archiveFinishCommands);
}
this->Makefile->GetDefExpandList(arFinishVar, archiveFinishCommands);
}
// Decide whether to use archiving rules.
+6 -9
View File
@@ -454,14 +454,12 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeDeviceLinkCmd()
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: {
const std::string cudaLinkCmd(
this->GetMakefile()->GetDefinition("CMAKE_CUDA_DEVICE_LINK_LIBRARY"));
cmExpandList(cudaLinkCmd, linkCmds);
this->GetMakefile()->GetDefExpandList("CMAKE_CUDA_DEVICE_LINK_LIBRARY",
linkCmds);
} break;
case cmStateEnums::EXECUTABLE: {
const std::string cudaLinkCmd(this->GetMakefile()->GetDefinition(
"CMAKE_CUDA_DEVICE_LINK_EXECUTABLE"));
cmExpandList(cudaLinkCmd, linkCmds);
this->GetMakefile()->GetDefExpandList(
"CMAKE_CUDA_DEVICE_LINK_EXECUTABLE", linkCmds);
} break;
default:
break;
@@ -558,9 +556,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd(
case cmStateEnums::EXECUTABLE:
if (this->TargetLinkLanguage(config) == "Swift") {
if (this->GeneratorTarget->IsExecutableWithExports()) {
const std::string flags =
this->Makefile->GetSafeDefinition("CMAKE_EXE_EXPORTS_Swift_FLAG");
cmExpandList(flags, linkCmds);
this->Makefile->GetDefExpandList("CMAKE_EXE_EXPORTS_Swift_FLAG",
linkCmds);
}
}
break;
+2 -3
View File
@@ -571,9 +571,8 @@ bool cmQtAutoGenInitializer::InitMoc()
if (this->GenTarget->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
(this->QtVersion >= IntegerVersion(5, 8))) {
// Command
cmExpandList(this->Makefile->GetSafeDefinition(
"CMAKE_CXX_COMPILER_PREDEFINES_COMMAND"),
this->Moc.PredefsCmd);
this->Makefile->GetDefExpandList("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND",
this->Moc.PredefsCmd);
// Header
if (!this->Moc.PredefsCmd.empty()) {
ConfigFileNames(this->Moc.PredefsFile,
+3 -8
View File
@@ -2286,9 +2286,7 @@ int cmake::CheckBuildSystem()
// If any byproduct of makefile generation is missing we must re-run.
std::vector<std::string> products;
if (const char* productStr = mf.GetDefinition("CMAKE_MAKEFILE_PRODUCTS")) {
cmExpandList(productStr, products);
}
mf.GetDefExpandList("CMAKE_MAKEFILE_PRODUCTS", products);
for (std::string const& p : products) {
if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) {
if (verbose) {
@@ -2303,11 +2301,8 @@ int cmake::CheckBuildSystem()
// Get the set of dependencies and outputs.
std::vector<std::string> depends;
std::vector<std::string> outputs;
const char* dependsStr = mf.GetDefinition("CMAKE_MAKEFILE_DEPENDS");
const char* outputsStr = mf.GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
if (dependsStr && outputsStr) {
cmExpandList(dependsStr, depends);
cmExpandList(outputsStr, outputs);
if (mf.GetDefExpandList("CMAKE_MAKEFILE_DEPENDS", depends)) {
mf.GetDefExpandList("CMAKE_MAKEFILE_OUTPUTS", outputs);
}
if (depends.empty() || outputs.empty()) {
// Not enough information was provided to do the test. Just rerun.