summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-04-22 13:02:28 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-04-22 13:02:34 (GMT)
commitf415b457e3694375f028c0ce228ce78382425a7f (patch)
tree8d88b7610991b0fad5644db06db2ea406a4ef6d5 /Source
parentbd8acc3a1bb190cf47fc7be6a8656eaa4feacb7c (diff)
parent408512858670c04597b644b03c5db04856b474e8 (diff)
downloadCMake-f415b457e3694375f028c0ce228ce78382425a7f.zip
CMake-f415b457e3694375f028c0ce228ce78382425a7f.tar.gz
CMake-f415b457e3694375f028c0ce228ce78382425a7f.tar.bz2
Merge topic 'cmake-install-script-gen-style'
4085128586 generated-scripts: use CMAKE_CURRENT_LIST_DIR where possible a1a7f62918 generated-scripts: improve prose messages with CMake lists c2194176db generated-scripts: unset used variables 233997a914 generated-scripts: use `foreach(IN LISTS)` 2ec44be41e generated-scripts: quote variable expansions d74761b181 generated-scripts: simplify `if` conditions 59cc92085e generated-cmake: use `_cmake_` prefixes for local variables a2cb1754a5 cmExportFileGenerator: require CMake 2.8.3 Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !7194
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExportFileGenerator.cxx73
-rw-r--r--Source/cmExportInstallFileGenerator.cxx9
-rw-r--r--Source/cmInstallExportGenerator.cxx16
-rw-r--r--Source/cmInstallGenerator.cxx4
-rw-r--r--Source/cmScriptGenerator.cxx6
5 files changed, 59 insertions, 49 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 6d6df71..452eb99 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -922,8 +922,11 @@ void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
// Protect that file against use with older CMake versions.
/* clang-format off */
os << "# Generated by CMake\n\n";
- os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.6)\n"
- << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
+ os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
+ << " message(FATAL_ERROR \"CMake >= 2.8.0 required\")\n"
+ << "endif()\n"
+ << "if(CMAKE_VERSION VERSION_LESS \"2.8.3\")\n"
+ << " message(FATAL_ERROR \"CMake >= 2.8.3 required\")\n"
<< "endif()\n";
/* clang-format on */
@@ -935,7 +938,7 @@ void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
// versions.
/* clang-format off */
os << "cmake_policy(PUSH)\n"
- << "cmake_policy(VERSION 2.6...3.22)\n";
+ << "cmake_policy(VERSION 2.8.3...3.22)\n";
/* clang-format on */
}
@@ -982,34 +985,36 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(
/* clang-format off */
os << "# Protect against multiple inclusion, which would fail when already "
"imported targets are added once more.\n"
- "set(_targetsDefined)\n"
- "set(_targetsNotDefined)\n"
- "set(_expectedTargets)\n"
- "foreach(_expectedTarget " << expectedTargets << ")\n"
- " list(APPEND _expectedTargets ${_expectedTarget})\n"
- " if(NOT TARGET ${_expectedTarget})\n"
- " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
- " endif()\n"
- " if(TARGET ${_expectedTarget})\n"
- " list(APPEND _targetsDefined ${_expectedTarget})\n"
+ "set(_cmake_targets_defined \"\")\n"
+ "set(_cmake_targets_not_defined \"\")\n"
+ "set(_cmake_expected_targets \"\")\n"
+ "foreach(_cmake_expected_target IN ITEMS " << expectedTargets << ")\n"
+ " list(APPEND _cmake_expected_targets \"${_cmake_expected_target}\")\n"
+ " if(TARGET \"${_cmake_expected_target}\")\n"
+ " list(APPEND _cmake_targets_defined \"${_cmake_expected_target}\")\n"
+ " else()\n"
+ " list(APPEND _cmake_targets_not_defined \"${_cmake_expected_target}\")\n"
" endif()\n"
"endforeach()\n"
- "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
- " unset(_targetsDefined)\n"
- " unset(_targetsNotDefined)\n"
- " unset(_expectedTargets)\n"
- " set(CMAKE_IMPORT_FILE_VERSION)\n"
+ "unset(_cmake_expected_target)\n"
+ "if(_cmake_targets_defined STREQUAL _cmake_expected_targets)\n"
+ " unset(_cmake_targets_defined)\n"
+ " unset(_cmake_targets_not_defined)\n"
+ " unset(_cmake_expected_targets)\n"
+ " unset(CMAKE_IMPORT_FILE_VERSION)\n"
" cmake_policy(POP)\n"
" return()\n"
"endif()\n"
- "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ "if(NOT _cmake_targets_defined STREQUAL \"\")\n"
+ " string(REPLACE \";\" \", \" _cmake_targets_defined_text \"${_cmake_targets_defined}\")\n"
+ " string(REPLACE \";\" \", \" _cmake_targets_not_defined_text \"${_cmake_targets_not_defined}\")\n"
" message(FATAL_ERROR \"Some (but not all) targets in this export "
- "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
- "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
+ "set were already defined.\\nTargets Defined: ${_cmake_targets_defined_text}\\n"
+ "Targets not yet defined: ${_cmake_targets_not_defined_text}\\n\")\n"
"endif()\n"
- "unset(_targetsDefined)\n"
- "unset(_targetsNotDefined)\n"
- "unset(_expectedTargets)\n"
+ "unset(_cmake_targets_defined)\n"
+ "unset(_cmake_targets_not_defined)\n"
+ "unset(_cmake_expected_targets)\n"
"\n\n";
/* clang-format on */
}
@@ -1175,12 +1180,12 @@ void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
// but the development package was not installed.).
/* clang-format off */
os << "# Loop over all imported files and verify that they actually exist\n"
- "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
- " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
- " if(NOT EXISTS \"${file}\" )\n"
- " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
+ "foreach(_cmake_target IN LISTS _cmake_import_check_targets)\n"
+ " foreach(_cmake_file IN LISTS \"_cmake_import_check_files_for_${_cmake_target}\")\n"
+ " if(NOT EXISTS \"${_cmake_file}\")\n"
+ " message(FATAL_ERROR \"The imported target \\\"${_cmake_target}\\\""
" references the file\n"
- " \\\"${file}\\\"\n"
+ " \\\"${_cmake_file}\\\"\n"
"but this file does not exist. Possible reasons include:\n"
"* The file was deleted, renamed, or moved to another location.\n"
"* An install or uninstall procedure did not complete successfully.\n"
@@ -1190,9 +1195,11 @@ void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
"\")\n"
" endif()\n"
" endforeach()\n"
- " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
+ " unset(_cmake_file)\n"
+ " unset(\"_cmake_import_check_files_for_${_cmake_target}\")\n"
"endforeach()\n"
- "unset(_IMPORT_CHECK_TARGETS)\n"
+ "unset(_cmake_target)\n"
+ "unset(_cmake_import_check_targets)\n"
"\n";
/* clang-format on */
}
@@ -1205,9 +1212,9 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode(
// Construct the imported target name.
std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
- os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName
+ os << "list(APPEND _cmake_import_check_targets " << targetName
<< " )\n"
- "list(APPEND _IMPORT_CHECK_FILES_FOR_"
+ "list(APPEND _cmake_import_check_files_for_"
<< targetName << " ";
for (std::string const& li : importedLocations) {
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 0c41946..adccdfe 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -253,12 +253,13 @@ void cmExportInstallFileGenerator::LoadConfigFiles(std::ostream& os)
// Now load per-configuration properties for them.
/* clang-format off */
os << "# Load information for each installed configuration.\n"
- << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
- << "file(GLOB CONFIG_FILES \"${_DIR}/"
+ << "file(GLOB _cmake_config_files \"${CMAKE_CURRENT_LIST_DIR}/"
<< this->GetConfigImportFileGlob() << "\")\n"
- << "foreach(f ${CONFIG_FILES})\n"
- << " include(${f})\n"
+ << "foreach(_cmake_config_file IN LISTS _cmake_config_files)\n"
+ << " include(\"${_cmake_config_file}\")\n"
<< "endforeach()\n"
+ << "unset(_cmake_config_file)\n"
+ << "unset(_cmake_config_files)\n"
<< "\n";
/* clang-format on */
}
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx
index 627f59d..eb7537d 100644
--- a/Source/cmInstallExportGenerator.cxx
+++ b/Source/cmInstallExportGenerator.cxx
@@ -195,18 +195,22 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os,
Indent indentNN = indentN.Next();
Indent indentNNN = indentNN.Next();
/* clang-format off */
- os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
+ os << indentN << "file(DIFFERENT _cmake_export_file_changed FILES\n"
<< indentN << " \"" << installedFile << "\"\n"
<< indentN << " \"" << this->MainImportFile << "\")\n";
- os << indentN << "if(EXPORT_FILE_CHANGED)\n";
- os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir
+ os << indentN << "if(_cmake_export_file_changed)\n";
+ os << indentNN << "file(GLOB _cmake_old_config_files \"" << installedDir
<< this->EFGen->GetConfigImportFileGlob() << "\")\n";
- os << indentNN << "if(OLD_CONFIG_FILES)\n";
+ os << indentNN << "if(_cmake_old_config_files)\n";
+ os << indentNNN << "string(REPLACE \";\" \", \" _cmake_old_config_files_text \"${_cmake_old_config_files}\")\n";
os << indentNNN << R"(message(STATUS "Old export file \")" << installedFile
- << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
- os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n";
+ << "\\\" will be replaced. Removing files [${_cmake_old_config_files_text}].\")\n";
+ os << indentNNN << "unset(_cmake_old_config_files_text)\n";
+ os << indentNNN << "file(REMOVE ${_cmake_old_config_files})\n";
os << indentNN << "endif()\n";
+ os << indentNN << "unset(_cmake_old_config_files)\n";
os << indentN << "endif()\n";
+ os << indentN << "unset(_cmake_export_file_changed)\n";
os << indent << "endif()\n";
/* clang-format on */
diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx
index 4cfeb47..00eb8c3 100644
--- a/Source/cmInstallGenerator.cxx
+++ b/Source/cmInstallGenerator.cxx
@@ -160,9 +160,9 @@ void cmInstallGenerator::AddInstallRule(
std::string cmInstallGenerator::CreateComponentTest(
const std::string& component, bool exclude_from_all)
{
- std::string result = R"("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "x)";
+ std::string result = "CMAKE_INSTALL_COMPONENT STREQUAL \"";
result += component;
- result += "x\"";
+ result += "\"";
if (!exclude_from_all) {
result += " OR NOT CMAKE_INSTALL_COMPONENT";
}
diff --git a/Source/cmScriptGenerator.cxx b/Source/cmScriptGenerator.cxx
index 5ac7be9..437b938 100644
--- a/Source/cmScriptGenerator.cxx
+++ b/Source/cmScriptGenerator.cxx
@@ -52,8 +52,7 @@ static void cmScriptGeneratorEncodeConfig(const std::string& config,
std::string cmScriptGenerator::CreateConfigTest(const std::string& config)
{
- std::string result =
- cmStrCat("\"${", this->RuntimeConfigVariable, "}\" MATCHES \"^(");
+ std::string result = cmStrCat(this->RuntimeConfigVariable, " MATCHES \"^(");
if (!config.empty()) {
cmScriptGeneratorEncodeConfig(config, result);
}
@@ -64,8 +63,7 @@ std::string cmScriptGenerator::CreateConfigTest(const std::string& config)
std::string cmScriptGenerator::CreateConfigTest(
std::vector<std::string> const& configs)
{
- std::string result =
- cmStrCat("\"${", this->RuntimeConfigVariable, "}\" MATCHES \"^(");
+ std::string result = cmStrCat(this->RuntimeConfigVariable, " MATCHES \"^(");
const char* sep = "";
for (std::string const& config : configs) {
result += sep;