cmExportBuildFileGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmExportBuildFileGenerator.h"
  4. #include <algorithm>
  5. #include <cstddef>
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <sstream>
  10. #include <utility>
  11. #include <cm/string_view>
  12. #include <cmext/string_view>
  13. #include "cmCryptoHash.h"
  14. #include "cmExportSet.h"
  15. #include "cmFileSet.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmGeneratorExpression.h"
  18. #include "cmGeneratorTarget.h"
  19. #include "cmGlobalGenerator.h"
  20. #include "cmList.h"
  21. #include "cmLocalGenerator.h"
  22. #include "cmMakefile.h"
  23. #include "cmMessageType.h"
  24. #include "cmOutputConverter.h"
  25. #include "cmPolicies.h"
  26. #include "cmStateTypes.h"
  27. #include "cmStringAlgorithms.h"
  28. #include "cmSystemTools.h"
  29. #include "cmTarget.h"
  30. #include "cmTargetExport.h"
  31. #include "cmValue.h"
  32. #include "cmake.h"
  33. class cmSourceFile;
  34. cmExportBuildFileGenerator::cmExportBuildFileGenerator()
  35. {
  36. this->LG = nullptr;
  37. this->ExportSet = nullptr;
  38. }
  39. void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
  40. {
  41. this->LG = lg;
  42. if (this->ExportSet) {
  43. this->ExportSet->Compute(lg);
  44. }
  45. }
  46. bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
  47. {
  48. {
  49. std::string expectedTargets;
  50. std::string sep;
  51. std::vector<TargetExport> targets;
  52. bool generatedInterfaceRequired = false;
  53. this->GetTargets(targets);
  54. for (auto const& tei : targets) {
  55. cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei.Name);
  56. expectedTargets += sep + this->Namespace + te->GetExportName();
  57. sep = " ";
  58. if (this->ExportedTargets.insert(te).second) {
  59. this->Exports.emplace_back(te, tei.XcFrameworkLocation);
  60. } else {
  61. std::ostringstream e;
  62. e << "given target \"" << te->GetName() << "\" more than once.";
  63. this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  64. MessageType::FATAL_ERROR, e.str(),
  65. this->LG->GetMakefile()->GetBacktrace());
  66. return false;
  67. }
  68. generatedInterfaceRequired |=
  69. this->GetExportTargetType(te) == cmStateEnums::INTERFACE_LIBRARY;
  70. }
  71. if (generatedInterfaceRequired) {
  72. this->SetRequiredCMakeVersion(3, 0, 0);
  73. }
  74. this->GenerateExpectedTargetsCode(os, expectedTargets);
  75. }
  76. // Create all the imported targets.
  77. for (auto const& exp : this->Exports) {
  78. cmGeneratorTarget* gte = exp.Target;
  79. this->GenerateImportTargetCode(os, gte, this->GetExportTargetType(gte));
  80. gte->Target->AppendBuildInterfaceIncludes();
  81. ImportPropertyMap properties;
  82. this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", gte,
  83. cmGeneratorExpression::BuildInterface,
  84. properties);
  85. this->PopulateInterfaceProperty("INTERFACE_SOURCES", gte,
  86. cmGeneratorExpression::BuildInterface,
  87. properties);
  88. this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", gte,
  89. cmGeneratorExpression::BuildInterface,
  90. properties);
  91. this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", gte,
  92. cmGeneratorExpression::BuildInterface,
  93. properties);
  94. this->PopulateInterfaceProperty("INTERFACE_PRECOMPILE_HEADERS", gte,
  95. cmGeneratorExpression::BuildInterface,
  96. properties);
  97. this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", gte,
  98. cmGeneratorExpression::BuildInterface,
  99. properties);
  100. this->PopulateInterfaceProperty("INTERFACE_AUTOMOC_MACRO_NAMES", gte,
  101. cmGeneratorExpression::BuildInterface,
  102. properties);
  103. this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gte,
  104. cmGeneratorExpression::BuildInterface,
  105. properties);
  106. this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gte,
  107. cmGeneratorExpression::BuildInterface,
  108. properties);
  109. this->PopulateInterfaceProperty("INTERFACE_LINK_DIRECTORIES", gte,
  110. cmGeneratorExpression::BuildInterface,
  111. properties);
  112. this->PopulateInterfaceProperty("INTERFACE_LINK_DEPENDS", gte,
  113. cmGeneratorExpression::BuildInterface,
  114. properties);
  115. this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gte,
  116. properties);
  117. std::string errorMessage;
  118. if (!this->PopulateCxxModuleExportProperties(
  119. gte, properties, cmGeneratorExpression::BuildInterface, {},
  120. errorMessage)) {
  121. this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  122. MessageType::FATAL_ERROR, errorMessage,
  123. this->LG->GetMakefile()->GetBacktrace());
  124. return false;
  125. }
  126. if (!this->PopulateExportProperties(gte, properties, errorMessage)) {
  127. this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  128. MessageType::FATAL_ERROR, errorMessage,
  129. this->LG->GetMakefile()->GetBacktrace());
  130. return false;
  131. }
  132. const bool newCMP0022Behavior =
  133. gte->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  134. gte->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  135. if (newCMP0022Behavior) {
  136. this->PopulateInterfaceLinkLibrariesProperty(
  137. gte, cmGeneratorExpression::BuildInterface, properties);
  138. }
  139. this->PopulateCompatibleInterfaceProperties(gte, properties);
  140. this->GenerateInterfaceProperties(gte, os, properties);
  141. this->GenerateTargetFileSets(gte, os);
  142. }
  143. std::string cxx_modules_name;
  144. if (this->ExportSet) {
  145. cxx_modules_name = this->ExportSet->GetName();
  146. } else {
  147. cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512);
  148. constexpr std::size_t HASH_TRUNCATION = 12;
  149. for (auto const& target : this->Targets) {
  150. hasher.Append(target.Name);
  151. }
  152. cxx_modules_name = hasher.FinalizeHex().substr(0, HASH_TRUNCATION);
  153. }
  154. this->GenerateCxxModuleInformation(cxx_modules_name, os);
  155. // Generate import file content for each configuration.
  156. for (std::string const& c : this->Configurations) {
  157. this->GenerateImportConfig(os, c);
  158. }
  159. // Generate import file content for each configuration.
  160. for (std::string const& c : this->Configurations) {
  161. this->GenerateImportCxxModuleConfigTargetInclusion(cxx_modules_name, c);
  162. }
  163. this->GenerateMissingTargetsCheckCode(os);
  164. return true;
  165. }
  166. void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
  167. std::ostream& os, const std::string& config, std::string const& suffix)
  168. {
  169. for (auto const& exp : this->Exports) {
  170. cmGeneratorTarget* target = exp.Target;
  171. // Collect import properties for this target.
  172. ImportPropertyMap properties;
  173. if (this->GetExportTargetType(target) != cmStateEnums::INTERFACE_LIBRARY) {
  174. this->SetImportLocationProperty(config, suffix, target, properties);
  175. }
  176. if (!properties.empty()) {
  177. // Get the rest of the target details.
  178. if (this->GetExportTargetType(target) !=
  179. cmStateEnums::INTERFACE_LIBRARY) {
  180. this->SetImportDetailProperties(config, suffix, target, properties);
  181. this->SetImportLinkInterface(config, suffix,
  182. cmGeneratorExpression::BuildInterface,
  183. target, properties);
  184. }
  185. // TODO: PUBLIC_HEADER_LOCATION
  186. // This should wait until the build feature propagation stuff
  187. // is done. Then this can be a propagated include directory.
  188. // this->GenerateImportProperty(config, te->HeaderGenerator,
  189. // properties);
  190. // Generate code in the export file.
  191. std::string importedXcFrameworkLocation = exp.XcFrameworkLocation;
  192. if (!importedXcFrameworkLocation.empty()) {
  193. importedXcFrameworkLocation = cmGeneratorExpression::Preprocess(
  194. importedXcFrameworkLocation,
  195. cmGeneratorExpression::PreprocessContext::BuildInterface);
  196. importedXcFrameworkLocation = cmGeneratorExpression::Evaluate(
  197. importedXcFrameworkLocation, exp.Target->GetLocalGenerator(), config,
  198. exp.Target, nullptr, exp.Target);
  199. if (!importedXcFrameworkLocation.empty() &&
  200. !cmSystemTools::FileIsFullPath(importedXcFrameworkLocation)) {
  201. importedXcFrameworkLocation =
  202. cmStrCat(this->LG->GetCurrentBinaryDirectory(), '/',
  203. importedXcFrameworkLocation);
  204. }
  205. }
  206. this->GenerateImportPropertyCode(os, config, suffix, target, properties,
  207. importedXcFrameworkLocation);
  208. }
  209. }
  210. }
  211. cmStateEnums::TargetType cmExportBuildFileGenerator::GetExportTargetType(
  212. cmGeneratorTarget const* target) const
  213. {
  214. cmStateEnums::TargetType targetType = target->GetType();
  215. // An object library exports as an interface library if we cannot
  216. // tell clients where to find the objects. This is sufficient
  217. // to support transitive usage requirements on other targets that
  218. // use the object library.
  219. if (targetType == cmStateEnums::OBJECT_LIBRARY &&
  220. !target->Target->HasKnownObjectFileLocation(nullptr)) {
  221. targetType = cmStateEnums::INTERFACE_LIBRARY;
  222. }
  223. return targetType;
  224. }
  225. void cmExportBuildFileGenerator::SetExportSet(cmExportSet* exportSet)
  226. {
  227. this->ExportSet = exportSet;
  228. }
  229. void cmExportBuildFileGenerator::SetImportLocationProperty(
  230. const std::string& config, std::string const& suffix,
  231. cmGeneratorTarget* target, ImportPropertyMap& properties)
  232. {
  233. // Get the makefile in which to lookup target information.
  234. cmMakefile* mf = target->Makefile;
  235. if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  236. std::string prop = cmStrCat("IMPORTED_OBJECTS", suffix);
  237. // Compute all the object files inside this target and setup
  238. // IMPORTED_OBJECTS as a list of object files
  239. std::vector<cmSourceFile const*> objectSources;
  240. target->GetObjectSources(objectSources, config);
  241. std::string const obj_dir = target->GetObjectDirectory(config);
  242. std::vector<std::string> objects;
  243. for (cmSourceFile const* sf : objectSources) {
  244. const std::string& obj = target->GetObjectName(sf);
  245. objects.push_back(obj_dir + obj);
  246. }
  247. // Store the property.
  248. properties[prop] = cmList::to_string(objects);
  249. } else {
  250. // Add the main target file.
  251. {
  252. std::string prop = cmStrCat("IMPORTED_LOCATION", suffix);
  253. std::string value;
  254. if (target->IsAppBundleOnApple()) {
  255. value =
  256. target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  257. } else {
  258. value = target->GetFullPath(config,
  259. cmStateEnums::RuntimeBinaryArtifact, true);
  260. }
  261. properties[prop] = value;
  262. }
  263. // Add the import library for windows DLLs.
  264. if (target->HasImportLibrary(config)) {
  265. std::string prop = cmStrCat("IMPORTED_IMPLIB", suffix);
  266. std::string value =
  267. target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact, true);
  268. if (mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
  269. target->GetImplibGNUtoMS(config, value, value,
  270. "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
  271. }
  272. properties[prop] = value;
  273. }
  274. }
  275. }
  276. void cmExportBuildFileGenerator::HandleMissingTarget(
  277. std::string& link_libs, cmGeneratorTarget const* depender,
  278. cmGeneratorTarget* dependee)
  279. {
  280. // The target is not in the export.
  281. if (!this->AppendMode) {
  282. const std::string name = dependee->GetName();
  283. cmGlobalGenerator* gg =
  284. dependee->GetLocalGenerator()->GetGlobalGenerator();
  285. auto exportInfo = this->FindBuildExportInfo(gg, name);
  286. std::vector<std::string> const& exportFiles = exportInfo.first;
  287. if (exportFiles.size() == 1) {
  288. std::string missingTarget = exportInfo.second;
  289. missingTarget += dependee->GetExportName();
  290. link_libs += missingTarget;
  291. this->MissingTargets.emplace_back(std::move(missingTarget));
  292. return;
  293. }
  294. // We are not appending, so all exported targets should be
  295. // known here. This is probably user-error.
  296. this->ComplainAboutMissingTarget(depender, dependee, exportFiles);
  297. }
  298. // Assume the target will be exported by another command.
  299. // Append it with the export namespace.
  300. link_libs += this->Namespace;
  301. link_libs += dependee->GetExportName();
  302. }
  303. void cmExportBuildFileGenerator::GetTargets(
  304. std::vector<TargetExport>& targets) const
  305. {
  306. if (this->ExportSet) {
  307. for (std::unique_ptr<cmTargetExport> const& te :
  308. this->ExportSet->GetTargetExports()) {
  309. if (te->NamelinkOnly) {
  310. continue;
  311. }
  312. targets.emplace_back(te->TargetName, te->XcFrameworkLocation);
  313. }
  314. return;
  315. }
  316. targets = this->Targets;
  317. }
  318. std::pair<std::vector<std::string>, std::string>
  319. cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg,
  320. const std::string& name)
  321. {
  322. std::vector<std::string> exportFiles;
  323. std::string ns;
  324. auto& exportSets = gg->GetBuildExportSets();
  325. for (auto const& exp : exportSets) {
  326. const auto& exportSet = exp.second;
  327. std::vector<TargetExport> targets;
  328. exportSet->GetTargets(targets);
  329. if (std::any_of(
  330. targets.begin(), targets.end(),
  331. [&name](const TargetExport& te) { return te.Name == name; })) {
  332. exportFiles.push_back(exp.first);
  333. ns = exportSet->GetNamespace();
  334. }
  335. }
  336. return { exportFiles, ns };
  337. }
  338. void cmExportBuildFileGenerator::ComplainAboutMissingTarget(
  339. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  340. std::vector<std::string> const& exportFiles)
  341. {
  342. std::ostringstream e;
  343. e << "export called with target \"" << depender->GetName()
  344. << "\" which requires target \"" << dependee->GetName() << "\" ";
  345. if (exportFiles.empty()) {
  346. e << "that is not in any export set.";
  347. } else {
  348. e << "that is not in this export set, but in multiple other export sets: "
  349. << cmJoin(exportFiles, ", ") << ".\n";
  350. e << "An exported target cannot depend upon another target which is "
  351. "exported multiple times. Consider consolidating the exports of the "
  352. "\""
  353. << dependee->GetName() << "\" target to a single export.";
  354. }
  355. this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
  356. MessageType::FATAL_ERROR, e.str(),
  357. this->LG->GetMakefile()->GetBacktrace());
  358. }
  359. std::string cmExportBuildFileGenerator::InstallNameDir(
  360. cmGeneratorTarget const* target, const std::string& config)
  361. {
  362. std::string install_name_dir;
  363. cmMakefile* mf = target->Target->GetMakefile();
  364. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  365. install_name_dir = target->GetInstallNameDirForBuildTree(config);
  366. }
  367. return install_name_dir;
  368. }
  369. namespace {
  370. bool EntryIsContextSensitive(
  371. const std::unique_ptr<cmCompiledGeneratorExpression>& cge)
  372. {
  373. return cge->GetHadContextSensitiveCondition();
  374. }
  375. }
  376. std::string cmExportBuildFileGenerator::GetFileSetDirectories(
  377. cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* /*te*/)
  378. {
  379. std::vector<std::string> resultVector;
  380. auto configs =
  381. gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  382. auto directoryEntries = fileSet->CompileDirectoryEntries();
  383. for (auto const& config : configs) {
  384. auto directories = fileSet->EvaluateDirectoryEntries(
  385. directoryEntries, gte->LocalGenerator, config, gte);
  386. bool const contextSensitive =
  387. std::any_of(directoryEntries.begin(), directoryEntries.end(),
  388. EntryIsContextSensitive);
  389. auto const& type = fileSet->GetType();
  390. // C++ modules do not support interface file sets which are dependent upon
  391. // the configuration.
  392. if (contextSensitive && type == "CXX_MODULES"_s) {
  393. auto* mf = this->LG->GetMakefile();
  394. std::ostringstream e;
  395. e << "The \"" << gte->GetName() << "\" target's interface file set \""
  396. << fileSet->GetName() << "\" of type \"" << type
  397. << "\" contains context-sensitive base directory entries which is not "
  398. "supported.";
  399. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  400. return std::string{};
  401. }
  402. for (auto const& directory : directories) {
  403. auto dest = cmOutputConverter::EscapeForCMake(
  404. directory, cmOutputConverter::WrapQuotes::NoWrap);
  405. if (contextSensitive && configs.size() != 1) {
  406. resultVector.push_back(
  407. cmStrCat("\"$<$<CONFIG:", config, ">:", dest, ">\""));
  408. } else {
  409. resultVector.emplace_back(cmStrCat('"', dest, '"'));
  410. break;
  411. }
  412. }
  413. }
  414. return cmJoin(resultVector, " ");
  415. }
  416. std::string cmExportBuildFileGenerator::GetFileSetFiles(cmGeneratorTarget* gte,
  417. cmFileSet* fileSet,
  418. cmTargetExport* /*te*/)
  419. {
  420. std::vector<std::string> resultVector;
  421. auto configs =
  422. gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  423. auto fileEntries = fileSet->CompileFileEntries();
  424. auto directoryEntries = fileSet->CompileDirectoryEntries();
  425. for (auto const& config : configs) {
  426. auto directories = fileSet->EvaluateDirectoryEntries(
  427. directoryEntries, gte->LocalGenerator, config, gte);
  428. std::map<std::string, std::vector<std::string>> files;
  429. for (auto const& entry : fileEntries) {
  430. fileSet->EvaluateFileEntry(directories, files, entry,
  431. gte->LocalGenerator, config, gte);
  432. }
  433. bool const contextSensitive =
  434. std::any_of(directoryEntries.begin(), directoryEntries.end(),
  435. EntryIsContextSensitive) ||
  436. std::any_of(fileEntries.begin(), fileEntries.end(),
  437. EntryIsContextSensitive);
  438. auto const& type = fileSet->GetType();
  439. // C++ modules do not support interface file sets which are dependent upon
  440. // the configuration.
  441. if (contextSensitive && type == "CXX_MODULES"_s) {
  442. auto* mf = this->LG->GetMakefile();
  443. std::ostringstream e;
  444. e << "The \"" << gte->GetName() << "\" target's interface file set \""
  445. << fileSet->GetName() << "\" of type \"" << type
  446. << "\" contains context-sensitive file entries which is not "
  447. "supported.";
  448. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  449. return std::string{};
  450. }
  451. for (auto const& it : files) {
  452. for (auto const& filename : it.second) {
  453. auto escapedFile = cmOutputConverter::EscapeForCMake(
  454. filename, cmOutputConverter::WrapQuotes::NoWrap);
  455. if (contextSensitive && configs.size() != 1) {
  456. resultVector.push_back(
  457. cmStrCat("\"$<$<CONFIG:", config, ">:", escapedFile, ">\""));
  458. } else {
  459. resultVector.emplace_back(cmStrCat('"', escapedFile, '"'));
  460. }
  461. }
  462. }
  463. if (!(contextSensitive && configs.size() != 1)) {
  464. break;
  465. }
  466. }
  467. return cmJoin(resultVector, " ");
  468. }
  469. std::string cmExportBuildFileGenerator::GetCxxModulesDirectory() const
  470. {
  471. return this->CxxModulesDirectory;
  472. }
  473. void cmExportBuildFileGenerator::GenerateCxxModuleConfigInformation(
  474. std::string const& name, std::ostream& os) const
  475. {
  476. const char* opt = "";
  477. if (this->Configurations.size() > 1) {
  478. // With more than one configuration, each individual file is optional.
  479. opt = " OPTIONAL";
  480. }
  481. // Generate import file content for each configuration.
  482. for (std::string c : this->Configurations) {
  483. if (c.empty()) {
  484. c = "noconfig";
  485. }
  486. os << "include(\"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << name << '-'
  487. << c << ".cmake\"" << opt << ")\n";
  488. }
  489. }
  490. bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion(
  491. std::string const& name, std::string config) const
  492. {
  493. auto cxx_modules_dirname = this->GetCxxModulesDirectory();
  494. if (cxx_modules_dirname.empty()) {
  495. return true;
  496. }
  497. if (config.empty()) {
  498. config = "noconfig";
  499. }
  500. std::string fileName =
  501. cmStrCat(this->FileDir, '/', cxx_modules_dirname, "/cxx-modules-", name,
  502. '-', config, ".cmake");
  503. cmGeneratedFileStream os(fileName, true);
  504. if (!os) {
  505. std::string se = cmSystemTools::GetLastSystemError();
  506. std::ostringstream e;
  507. e << "cannot write to file \"" << fileName << "\": " << se;
  508. cmSystemTools::Error(e.str());
  509. return false;
  510. }
  511. os.SetCopyIfDifferent(true);
  512. for (auto const* tgt : this->ExportedTargets) {
  513. // Only targets with C++ module sources will have a
  514. // collator-generated install script.
  515. if (!tgt->HaveCxx20ModuleSources()) {
  516. continue;
  517. }
  518. os << "include(\"${CMAKE_CURRENT_LIST_DIR}/target-" << tgt->GetExportName()
  519. << '-' << config << ".cmake\")\n";
  520. }
  521. return true;
  522. }