mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 15:20:56 -06:00
cmExportCMakeConfigGenerator: Optimize std::ostream::operator<< calls
This commit is contained in:
@@ -93,8 +93,8 @@ void cmExportCMakeConfigGenerator::GenerateInterfaceProperties(
|
||||
cmStrCat(this->Namespace, target->GetExportName());
|
||||
os << "set_target_properties(" << targetName << " PROPERTIES\n";
|
||||
for (auto const& property : properties) {
|
||||
os << " " << property.first << " "
|
||||
<< cmExportFileGeneratorEscape(property.second) << "\n";
|
||||
os << " " << property.first << ' '
|
||||
<< cmExportFileGeneratorEscape(property.second) << '\n';
|
||||
}
|
||||
os << ")\n\n";
|
||||
}
|
||||
@@ -164,22 +164,22 @@ void cmExportCMakeConfigGenerator::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.8)\n"
|
||||
<< " message(FATAL_ERROR \"CMake >= "
|
||||
os << "# Generated by CMake\n\n"
|
||||
"if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
|
||||
" message(FATAL_ERROR \"CMake >= "
|
||||
<< this->RequiredCMakeVersionMajor << '.'
|
||||
<< this->RequiredCMakeVersionMinor << '.'
|
||||
<< this->RequiredCMakeVersionPatch << " required\")\n"
|
||||
<< "endif()\n"
|
||||
<< "if(CMAKE_VERSION VERSION_LESS \""
|
||||
"endif()\n"
|
||||
"if(CMAKE_VERSION VERSION_LESS \""
|
||||
<< this->RequiredCMakeVersionMajor << '.'
|
||||
<< this->RequiredCMakeVersionMinor << '.'
|
||||
<< this->RequiredCMakeVersionPatch << "\")\n"
|
||||
<< " message(FATAL_ERROR \"CMake >= "
|
||||
" message(FATAL_ERROR \"CMake >= "
|
||||
<< this->RequiredCMakeVersionMajor << '.'
|
||||
<< this->RequiredCMakeVersionMinor << '.'
|
||||
<< this->RequiredCMakeVersionPatch << " required\")\n"
|
||||
<< "endif()\n";
|
||||
"endif()\n";
|
||||
/* clang-format on */
|
||||
|
||||
// Isolate the file policy level.
|
||||
@@ -191,7 +191,7 @@ void cmExportCMakeConfigGenerator::GeneratePolicyHeaderCode(std::ostream& os)
|
||||
// versions.
|
||||
/* clang-format off */
|
||||
os << "cmake_policy(PUSH)\n"
|
||||
<< "cmake_policy(VERSION "
|
||||
"cmake_policy(VERSION "
|
||||
<< this->RequiredCMakeVersionMajor << '.'
|
||||
<< this->RequiredCMakeVersionMinor << '.'
|
||||
<< this->RequiredCMakeVersionPatch << "...3.30)\n";
|
||||
@@ -207,32 +207,30 @@ void cmExportCMakeConfigGenerator::GenerateImportHeaderCode(
|
||||
std::ostream& os, std::string const& config)
|
||||
{
|
||||
os << "#----------------------------------------------------------------\n"
|
||||
<< "# Generated CMake target import file";
|
||||
"# Generated CMake target import file";
|
||||
if (!config.empty()) {
|
||||
os << " for configuration \"" << config << "\".\n";
|
||||
} else {
|
||||
os << ".\n";
|
||||
}
|
||||
os << "#----------------------------------------------------------------\n"
|
||||
<< "\n";
|
||||
"\n";
|
||||
this->GenerateImportVersionCode(os);
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateImportFooterCode(std::ostream& os)
|
||||
{
|
||||
os << "# Commands beyond this point should not need to know the version.\n"
|
||||
<< "set(CMAKE_IMPORT_FILE_VERSION)\n";
|
||||
"set(CMAKE_IMPORT_FILE_VERSION)\n";
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateImportVersionCode(std::ostream& os)
|
||||
{
|
||||
// Store an import file format version. This will let us change the
|
||||
// format later while still allowing old import files to work.
|
||||
/* clang-format off */
|
||||
os << "# Commands may need to know the format version.\n"
|
||||
<< "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
|
||||
<< "\n";
|
||||
/* clang-format on */
|
||||
"set(CMAKE_IMPORT_FILE_VERSION 1)\n"
|
||||
"\n";
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateExpectedTargetsCode(
|
||||
@@ -355,7 +353,7 @@ void cmExportCMakeConfigGenerator::GenerateImportTargetCode(
|
||||
os << "set_property(TARGET " << targetName << " PROPERTY SYSTEM 0)\n";
|
||||
}
|
||||
|
||||
os << "\n";
|
||||
os << '\n';
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
|
||||
@@ -370,22 +368,24 @@ void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
|
||||
|
||||
// Set the import properties.
|
||||
os << "# Import target \"" << targetName << "\" for configuration \""
|
||||
<< config << "\"\n";
|
||||
os << "set_property(TARGET " << targetName
|
||||
<< " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
|
||||
<< config
|
||||
<< "\"\n"
|
||||
"set_property(TARGET "
|
||||
<< targetName << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
|
||||
if (!config.empty()) {
|
||||
os << cmSystemTools::UpperCase(config);
|
||||
} else {
|
||||
os << "NOCONFIG";
|
||||
}
|
||||
os << ")\n";
|
||||
os << "set_target_properties(" << targetName << " PROPERTIES\n";
|
||||
os << ")\n"
|
||||
"set_target_properties("
|
||||
<< targetName << " PROPERTIES\n";
|
||||
std::string importedLocationProp = cmStrCat("IMPORTED_LOCATION", suffix);
|
||||
for (auto const& property : properties) {
|
||||
if (importedXcFrameworkLocation.empty() ||
|
||||
property.first != importedLocationProp) {
|
||||
os << " " << property.first << " "
|
||||
<< cmExportFileGeneratorEscape(property.second) << "\n";
|
||||
os << " " << property.first << ' '
|
||||
<< cmExportFileGeneratorEscape(property.second) << '\n';
|
||||
}
|
||||
}
|
||||
os << " )\n";
|
||||
@@ -396,15 +396,15 @@ void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
|
||||
<< cmExportFileGeneratorEscape(importedXcFrameworkLocation)
|
||||
<< ")\n"
|
||||
" set_property(TARGET "
|
||||
<< targetName << " PROPERTY " << importedLocationProp << " "
|
||||
<< targetName << " PROPERTY " << importedLocationProp << ' '
|
||||
<< cmExportFileGeneratorEscape(importedXcFrameworkLocation)
|
||||
<< ")\nelse()\n set_property(TARGET " << targetName << " PROPERTY "
|
||||
<< importedLocationProp << " "
|
||||
<< importedLocationProp << ' '
|
||||
<< cmExportFileGeneratorEscape(importedLocationIt->second)
|
||||
<< ")\nendif()\n";
|
||||
}
|
||||
}
|
||||
os << "\n";
|
||||
os << '\n';
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
|
||||
@@ -467,7 +467,7 @@ void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
|
||||
if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
|
||||
os << "find_dependency(" << it.first;
|
||||
for (auto const& arg : it.second.ExtraArguments) {
|
||||
os << " " << cmOutputConverter::EscapeForCMake(arg);
|
||||
os << ' ' << cmOutputConverter::EscapeForCMake(arg);
|
||||
}
|
||||
os << ")\n";
|
||||
}
|
||||
@@ -479,26 +479,21 @@ void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(
|
||||
std::ostream& os)
|
||||
{
|
||||
if (this->MissingTargets.empty()) {
|
||||
/* clang-format off */
|
||||
os << "# This file does not depend on other imported targets which have\n"
|
||||
"# been exported from the same project but in a separate "
|
||||
"export set.\n\n";
|
||||
/* clang-format on */
|
||||
"export set.\n\n";
|
||||
return;
|
||||
}
|
||||
/* clang-format off */
|
||||
os << "# Make sure the targets which have been exported in some other\n"
|
||||
"# export set exist.\n"
|
||||
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
|
||||
"foreach(_target ";
|
||||
/* clang-format on */
|
||||
std::set<std::string> emitted;
|
||||
for (std::string const& missingTarget : this->MissingTargets) {
|
||||
if (emitted.insert(missingTarget).second) {
|
||||
os << "\"" << missingTarget << "\" ";
|
||||
os << '"' << missingTarget << "\" ";
|
||||
}
|
||||
}
|
||||
/* clang-format off */
|
||||
os << ")\n"
|
||||
" if(NOT TARGET \"${_target}\" )\n"
|
||||
" set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
|
||||
@@ -513,16 +508,15 @@ void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(
|
||||
" set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
|
||||
"\"The following imported targets are "
|
||||
"referenced, but are missing: "
|
||||
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
||||
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
||||
" else()\n"
|
||||
" message(FATAL_ERROR \"The following imported targets are "
|
||||
"referenced, but are missing: "
|
||||
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
||||
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
||||
" endif()\n"
|
||||
"endif()\n"
|
||||
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
|
||||
"\n";
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
|
||||
@@ -535,7 +529,6 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
|
||||
// the non-development package, something similar happened to me without
|
||||
// on SUSE with a mysql pkg-config file, which claimed everything is fine,
|
||||
// but the development package was not installed.).
|
||||
/* clang-format off */
|
||||
os << "# Loop over all imported files and verify that they actually exist\n"
|
||||
"foreach(_cmake_target IN LISTS _cmake_import_check_targets)\n"
|
||||
" if(CMAKE_VERSION VERSION_LESS \"3.28\"\n"
|
||||
@@ -565,7 +558,6 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
|
||||
"unset(_cmake_target)\n"
|
||||
"unset(_cmake_import_check_targets)\n"
|
||||
"\n";
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateImportedFileChecksCode(
|
||||
@@ -582,12 +574,12 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileChecksCode(
|
||||
os << "set(_cmake_import_check_xcframework_for_" << targetName << ' '
|
||||
<< cmExportFileGeneratorEscape(importedXcFrameworkLocation) << ")\n";
|
||||
}
|
||||
os << "list(APPEND _cmake_import_check_files_for_" << targetName << " ";
|
||||
os << "list(APPEND _cmake_import_check_files_for_" << targetName << ' ';
|
||||
|
||||
for (std::string const& li : importedLocations) {
|
||||
auto pi = properties.find(li);
|
||||
if (pi != properties.end()) {
|
||||
os << cmExportFileGeneratorEscape(pi->second) << " ";
|
||||
os << cmExportFileGeneratorEscape(pi->second) << ' ';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,7 +594,7 @@ void cmExportCMakeConfigGenerator::GenerateTargetFileSets(
|
||||
std::string targetName = cmStrCat(this->Namespace, gte->GetExportName());
|
||||
os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.23.0\")\n"
|
||||
" target_sources("
|
||||
<< targetName << "\n";
|
||||
<< targetName << '\n';
|
||||
|
||||
for (auto const& name : interfaceFileSets) {
|
||||
auto* fileSet = gte->Target->GetFileSet(name);
|
||||
@@ -621,7 +613,7 @@ void cmExportCMakeConfigGenerator::GenerateTargetFileSets(
|
||||
<< cmOutputConverter::EscapeForCMake(fileSet->GetType())
|
||||
<< "\n BASE_DIRS "
|
||||
<< this->GetFileSetDirectories(gte, fileSet, te) << "\n FILES "
|
||||
<< this->GetFileSetFiles(gte, fileSet, te) << "\n";
|
||||
<< this->GetFileSetFiles(gte, fileSet, te) << '\n';
|
||||
}
|
||||
|
||||
os << " )\nelse()\n set_property(TARGET " << targetName
|
||||
@@ -667,8 +659,8 @@ void cmExportCMakeConfigGenerator::GenerateCxxModuleInformation(
|
||||
|
||||
// Write the include.
|
||||
os << "# Include C++ module properties\n"
|
||||
<< "include(\"${CMAKE_CURRENT_LIST_DIR}/" << cxx_module_dirname
|
||||
<< "/cxx-modules-" << name << ".cmake\")\n\n";
|
||||
"include(\"${CMAKE_CURRENT_LIST_DIR}/"
|
||||
<< cxx_module_dirname << "/cxx-modules-" << name << ".cmake\")\n\n";
|
||||
|
||||
// Include all configuration-specific include files.
|
||||
cmGeneratedFileStream ap(this->GetCxxModuleFile(name), true);
|
||||
|
||||
Reference in New Issue
Block a user