cmExportInstallFileGenerator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 "cmExportInstallFileGenerator.h"
  4. #include <algorithm>
  5. #include <memory>
  6. #include <sstream>
  7. #include <utility>
  8. #include "cmExportSet.h"
  9. #include "cmFileSet.h"
  10. #include "cmGeneratedFileStream.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmInstallExportGenerator.h"
  15. #include "cmInstallFileSetGenerator.h"
  16. #include "cmInstallTargetGenerator.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmOutputConverter.h"
  20. #include "cmPolicies.h"
  21. #include "cmStateTypes.h"
  22. #include "cmStringAlgorithms.h"
  23. #include "cmSystemTools.h"
  24. #include "cmTarget.h"
  25. #include "cmTargetExport.h"
  26. #include "cmValue.h"
  27. cmExportInstallFileGenerator::cmExportInstallFileGenerator(
  28. cmInstallExportGenerator* iegen)
  29. : IEGen(iegen)
  30. {
  31. }
  32. std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
  33. {
  34. std::string glob = cmStrCat(this->FileBase, "-*", this->FileExt);
  35. return glob;
  36. }
  37. bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
  38. {
  39. std::vector<cmTargetExport*> allTargets;
  40. {
  41. std::string expectedTargets;
  42. std::string sep;
  43. for (std::unique_ptr<cmTargetExport> const& te :
  44. this->IEGen->GetExportSet()->GetTargetExports()) {
  45. if (te->NamelinkOnly) {
  46. continue;
  47. }
  48. expectedTargets += sep + this->Namespace + te->Target->GetExportName();
  49. sep = " ";
  50. if (this->ExportedTargets.insert(te->Target).second) {
  51. allTargets.push_back(te.get());
  52. } else {
  53. std::ostringstream e;
  54. e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName()
  55. << "\" ...) "
  56. << "includes target \"" << te->Target->GetName()
  57. << "\" more than once in the export set.";
  58. cmSystemTools::Error(e.str());
  59. return false;
  60. }
  61. }
  62. this->GenerateExpectedTargetsCode(os, expectedTargets);
  63. }
  64. // Compute the relative import prefix for the file
  65. this->GenerateImportPrefix(os);
  66. std::vector<std::string> missingTargets;
  67. bool require2_8_12 = false;
  68. bool require3_0_0 = false;
  69. bool require3_1_0 = false;
  70. bool requiresConfigFiles = false;
  71. // Create all the imported targets.
  72. for (cmTargetExport* te : allTargets) {
  73. cmGeneratorTarget* gt = te->Target;
  74. cmStateEnums::TargetType targetType = this->GetExportTargetType(te);
  75. requiresConfigFiles =
  76. requiresConfigFiles || targetType != cmStateEnums::INTERFACE_LIBRARY;
  77. this->GenerateImportTargetCode(os, gt, targetType);
  78. ImportPropertyMap properties;
  79. this->PopulateIncludeDirectoriesInterface(
  80. gt, cmGeneratorExpression::InstallInterface, properties, missingTargets);
  81. this->PopulateSourcesInterface(gt, cmGeneratorExpression::InstallInterface,
  82. properties, missingTargets);
  83. this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt,
  84. cmGeneratorExpression::InstallInterface,
  85. properties, missingTargets);
  86. this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", gt,
  87. cmGeneratorExpression::InstallInterface,
  88. properties, missingTargets);
  89. this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", gt,
  90. cmGeneratorExpression::InstallInterface,
  91. properties, missingTargets);
  92. this->PopulateInterfaceProperty("INTERFACE_PRECOMPILE_HEADERS", gt,
  93. cmGeneratorExpression::InstallInterface,
  94. properties, missingTargets);
  95. this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", gt,
  96. cmGeneratorExpression::InstallInterface,
  97. properties, missingTargets);
  98. this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gt,
  99. cmGeneratorExpression::InstallInterface,
  100. properties, missingTargets);
  101. this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gt,
  102. cmGeneratorExpression::InstallInterface,
  103. properties, missingTargets);
  104. this->PopulateLinkDirectoriesInterface(
  105. gt, cmGeneratorExpression::InstallInterface, properties, missingTargets);
  106. this->PopulateLinkDependsInterface(
  107. gt, cmGeneratorExpression::InstallInterface, properties, missingTargets);
  108. std::string errorMessage;
  109. if (!this->PopulateExportProperties(gt, properties, errorMessage)) {
  110. cmSystemTools::Error(errorMessage);
  111. return false;
  112. }
  113. const bool newCMP0022Behavior =
  114. gt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  115. gt->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  116. if (newCMP0022Behavior) {
  117. if (this->PopulateInterfaceLinkLibrariesProperty(
  118. gt, cmGeneratorExpression::InstallInterface, properties,
  119. missingTargets) &&
  120. !this->ExportOld) {
  121. require2_8_12 = true;
  122. }
  123. }
  124. if (targetType == cmStateEnums::INTERFACE_LIBRARY) {
  125. require3_0_0 = true;
  126. }
  127. if (gt->GetProperty("INTERFACE_SOURCES")) {
  128. // We can only generate INTERFACE_SOURCES in CMake 3.3, but CMake 3.1
  129. // can consume them.
  130. require3_1_0 = true;
  131. }
  132. this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gt,
  133. properties);
  134. this->PopulateCompatibleInterfaceProperties(gt, properties);
  135. this->GenerateInterfaceProperties(gt, os, properties);
  136. this->GenerateTargetFileSets(gt, os, te);
  137. }
  138. if (require3_1_0) {
  139. this->GenerateRequiredCMakeVersion(os, "3.1.0");
  140. } else if (require3_0_0) {
  141. this->GenerateRequiredCMakeVersion(os, "3.0.0");
  142. } else if (require2_8_12) {
  143. this->GenerateRequiredCMakeVersion(os, "2.8.12");
  144. }
  145. this->LoadConfigFiles(os);
  146. this->CleanupTemporaryVariables(os);
  147. this->GenerateImportedFileCheckLoop(os);
  148. bool result = true;
  149. // Generate an import file for each configuration.
  150. // Don't do this if we only export INTERFACE_LIBRARY targets.
  151. if (requiresConfigFiles) {
  152. for (std::string const& c : this->Configurations) {
  153. if (!this->GenerateImportFileConfig(c, missingTargets)) {
  154. result = false;
  155. }
  156. }
  157. }
  158. this->GenerateMissingTargetsCheckCode(os, missingTargets);
  159. return result;
  160. }
  161. void cmExportInstallFileGenerator::GenerateImportPrefix(std::ostream& os)
  162. {
  163. // Set an _IMPORT_PREFIX variable for import location properties
  164. // to reference if they are relative to the install prefix.
  165. std::string installPrefix =
  166. this->IEGen->GetLocalGenerator()->GetMakefile()->GetSafeDefinition(
  167. "CMAKE_INSTALL_PREFIX");
  168. std::string const& expDest = this->IEGen->GetDestination();
  169. if (cmSystemTools::FileIsFullPath(expDest)) {
  170. // The export file is being installed to an absolute path so the
  171. // package is not relocatable. Use the configured install prefix.
  172. /* clang-format off */
  173. os <<
  174. "# The installation prefix configured by this project.\n"
  175. "set(_IMPORT_PREFIX \"" << installPrefix << "\")\n"
  176. "\n";
  177. /* clang-format on */
  178. } else {
  179. // Add code to compute the installation prefix relative to the
  180. // import file location.
  181. std::string absDest = installPrefix + "/" + expDest;
  182. std::string absDestS = absDest + "/";
  183. os << "# Compute the installation prefix relative to this file.\n"
  184. << "get_filename_component(_IMPORT_PREFIX"
  185. << " \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
  186. if (cmHasLiteralPrefix(absDestS, "/lib/") ||
  187. cmHasLiteralPrefix(absDestS, "/lib64/") ||
  188. cmHasLiteralPrefix(absDestS, "/libx32/") ||
  189. cmHasLiteralPrefix(absDestS, "/usr/lib/") ||
  190. cmHasLiteralPrefix(absDestS, "/usr/lib64/") ||
  191. cmHasLiteralPrefix(absDestS, "/usr/libx32/")) {
  192. // Handle "/usr move" symlinks created by some Linux distros.
  193. /* clang-format off */
  194. os <<
  195. "# Use original install prefix when loaded through a\n"
  196. "# cross-prefix symbolic link such as /lib -> /usr/lib.\n"
  197. "get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)\n"
  198. "get_filename_component(_realOrig \"" << absDest << "\" REALPATH)\n"
  199. "if(_realCurr STREQUAL _realOrig)\n"
  200. " set(_IMPORT_PREFIX \"" << absDest << "\")\n"
  201. "endif()\n"
  202. "unset(_realOrig)\n"
  203. "unset(_realCurr)\n";
  204. /* clang-format on */
  205. }
  206. std::string dest = expDest;
  207. while (!dest.empty()) {
  208. os << "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" "
  209. "PATH)\n";
  210. dest = cmSystemTools::GetFilenamePath(dest);
  211. }
  212. os << "if(_IMPORT_PREFIX STREQUAL \"/\")\n"
  213. << " set(_IMPORT_PREFIX \"\")\n"
  214. << "endif()\n"
  215. << "\n";
  216. }
  217. }
  218. void cmExportInstallFileGenerator::CleanupTemporaryVariables(std::ostream& os)
  219. {
  220. /* clang-format off */
  221. os << "# Cleanup temporary variables.\n"
  222. << "set(_IMPORT_PREFIX)\n"
  223. << "\n";
  224. /* clang-format on */
  225. }
  226. void cmExportInstallFileGenerator::LoadConfigFiles(std::ostream& os)
  227. {
  228. // Now load per-configuration properties for them.
  229. /* clang-format off */
  230. os << "# Load information for each installed configuration.\n"
  231. << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
  232. << "file(GLOB CONFIG_FILES \"${_DIR}/"
  233. << this->GetConfigImportFileGlob() << "\")\n"
  234. << "foreach(f ${CONFIG_FILES})\n"
  235. << " include(${f})\n"
  236. << "endforeach()\n"
  237. << "\n";
  238. /* clang-format on */
  239. }
  240. void cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string& input)
  241. {
  242. cmGeneratorExpression::ReplaceInstallPrefix(input, "${_IMPORT_PREFIX}");
  243. }
  244. bool cmExportInstallFileGenerator::GenerateImportFileConfig(
  245. const std::string& config, std::vector<std::string>& missingTargets)
  246. {
  247. // Skip configurations not enabled for this export.
  248. if (!this->IEGen->InstallsForConfig(config)) {
  249. return true;
  250. }
  251. // Construct the name of the file to generate.
  252. std::string fileName = cmStrCat(this->FileDir, '/', this->FileBase, '-');
  253. if (!config.empty()) {
  254. fileName += cmSystemTools::LowerCase(config);
  255. } else {
  256. fileName += "noconfig";
  257. }
  258. fileName += this->FileExt;
  259. // Open the output file to generate it.
  260. cmGeneratedFileStream exportFileStream(fileName, true);
  261. if (!exportFileStream) {
  262. std::string se = cmSystemTools::GetLastSystemError();
  263. std::ostringstream e;
  264. e << "cannot write to file \"" << fileName << "\": " << se;
  265. cmSystemTools::Error(e.str());
  266. return false;
  267. }
  268. exportFileStream.SetCopyIfDifferent(true);
  269. std::ostream& os = exportFileStream;
  270. // Start with the import file header.
  271. this->GenerateImportHeaderCode(os, config);
  272. // Generate the per-config target information.
  273. this->GenerateImportConfig(os, config, missingTargets);
  274. // End with the import file footer.
  275. this->GenerateImportFooterCode(os);
  276. // Record this per-config import file.
  277. this->ConfigImportFiles[config] = fileName;
  278. return true;
  279. }
  280. void cmExportInstallFileGenerator::GenerateImportTargetsConfig(
  281. std::ostream& os, const std::string& config, std::string const& suffix,
  282. std::vector<std::string>& missingTargets)
  283. {
  284. // Add each target in the set to the export.
  285. for (std::unique_ptr<cmTargetExport> const& te :
  286. this->IEGen->GetExportSet()->GetTargetExports()) {
  287. // Collect import properties for this target.
  288. if (this->GetExportTargetType(te.get()) ==
  289. cmStateEnums::INTERFACE_LIBRARY) {
  290. continue;
  291. }
  292. ImportPropertyMap properties;
  293. std::set<std::string> importedLocations;
  294. this->SetImportLocationProperty(config, suffix, te->ArchiveGenerator,
  295. properties, importedLocations);
  296. this->SetImportLocationProperty(config, suffix, te->LibraryGenerator,
  297. properties, importedLocations);
  298. this->SetImportLocationProperty(config, suffix, te->RuntimeGenerator,
  299. properties, importedLocations);
  300. this->SetImportLocationProperty(config, suffix, te->ObjectsGenerator,
  301. properties, importedLocations);
  302. this->SetImportLocationProperty(config, suffix, te->FrameworkGenerator,
  303. properties, importedLocations);
  304. this->SetImportLocationProperty(config, suffix, te->BundleGenerator,
  305. properties, importedLocations);
  306. // If any file location was set for the target add it to the
  307. // import file.
  308. if (!properties.empty()) {
  309. // Get the rest of the target details.
  310. cmGeneratorTarget* gtgt = te->Target;
  311. this->SetImportDetailProperties(config, suffix, gtgt, properties,
  312. missingTargets);
  313. this->SetImportLinkInterface(config, suffix,
  314. cmGeneratorExpression::InstallInterface,
  315. gtgt, properties, missingTargets);
  316. // TODO: PUBLIC_HEADER_LOCATION
  317. // This should wait until the build feature propagation stuff
  318. // is done. Then this can be a propagated include directory.
  319. // this->GenerateImportProperty(config, te->HeaderGenerator,
  320. // properties);
  321. // Generate code in the export file.
  322. this->GenerateImportPropertyCode(os, config, gtgt, properties);
  323. this->GenerateImportedFileChecksCode(os, gtgt, properties,
  324. importedLocations);
  325. }
  326. }
  327. }
  328. void cmExportInstallFileGenerator::SetImportLocationProperty(
  329. const std::string& config, std::string const& suffix,
  330. cmInstallTargetGenerator* itgen, ImportPropertyMap& properties,
  331. std::set<std::string>& importedLocations)
  332. {
  333. // Skip rules that do not match this configuration.
  334. if (!(itgen && itgen->InstallsForConfig(config))) {
  335. return;
  336. }
  337. // Get the target to be installed.
  338. cmGeneratorTarget* target = itgen->GetTarget();
  339. // Construct the installed location of the target.
  340. std::string dest = itgen->GetDestination(config);
  341. std::string value;
  342. if (!cmSystemTools::FileIsFullPath(dest)) {
  343. // The target is installed relative to the installation prefix.
  344. value = "${_IMPORT_PREFIX}/";
  345. }
  346. value += dest;
  347. value += "/";
  348. if (itgen->IsImportLibrary()) {
  349. // Construct the property name.
  350. std::string prop = cmStrCat("IMPORTED_IMPLIB", suffix);
  351. // Append the installed file name.
  352. value += cmInstallTargetGenerator::GetInstallFilename(
  353. target, config, cmInstallTargetGenerator::NameImplib);
  354. // Store the property.
  355. properties[prop] = value;
  356. importedLocations.insert(prop);
  357. } else if (itgen->GetTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  358. // Construct the property name.
  359. std::string prop = cmStrCat("IMPORTED_OBJECTS", suffix);
  360. // Compute all the object files inside this target and setup
  361. // IMPORTED_OBJECTS as a list of object files
  362. std::vector<std::string> objects;
  363. itgen->GetInstallObjectNames(config, objects);
  364. for (std::string& obj : objects) {
  365. obj = cmStrCat(value, obj);
  366. }
  367. // Store the property.
  368. properties[prop] = cmJoin(objects, ";");
  369. importedLocations.insert(prop);
  370. } else {
  371. // Construct the property name.
  372. std::string prop = cmStrCat("IMPORTED_LOCATION", suffix);
  373. // Append the installed file name.
  374. if (target->IsAppBundleOnApple()) {
  375. value += cmInstallTargetGenerator::GetInstallFilename(target, config);
  376. value += ".app/Contents/MacOS/";
  377. value += cmInstallTargetGenerator::GetInstallFilename(target, config);
  378. } else {
  379. value += cmInstallTargetGenerator::GetInstallFilename(
  380. target, config, cmInstallTargetGenerator::NameReal);
  381. }
  382. // Store the property.
  383. properties[prop] = value;
  384. importedLocations.insert(prop);
  385. }
  386. }
  387. cmStateEnums::TargetType cmExportInstallFileGenerator::GetExportTargetType(
  388. cmTargetExport const* targetExport) const
  389. {
  390. cmStateEnums::TargetType targetType = targetExport->Target->GetType();
  391. // An OBJECT library installed with no OBJECTS DESTINATION
  392. // is transformed to an INTERFACE library.
  393. if (targetType == cmStateEnums::OBJECT_LIBRARY &&
  394. targetExport->ObjectsGenerator == nullptr) {
  395. targetType = cmStateEnums::INTERFACE_LIBRARY;
  396. }
  397. return targetType;
  398. }
  399. void cmExportInstallFileGenerator::HandleMissingTarget(
  400. std::string& link_libs, std::vector<std::string>& missingTargets,
  401. cmGeneratorTarget const* depender, cmGeneratorTarget* dependee)
  402. {
  403. const std::string name = dependee->GetName();
  404. cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator();
  405. auto exportInfo = this->FindNamespaces(gg, name);
  406. std::vector<std::string> const& exportFiles = exportInfo.first;
  407. if (exportFiles.size() == 1) {
  408. std::string missingTarget = exportInfo.second;
  409. missingTarget += dependee->GetExportName();
  410. link_libs += missingTarget;
  411. missingTargets.push_back(std::move(missingTarget));
  412. } else {
  413. // All exported targets should be known here and should be unique.
  414. // This is probably user-error.
  415. this->ComplainAboutMissingTarget(depender, dependee, exportFiles);
  416. }
  417. }
  418. std::pair<std::vector<std::string>, std::string>
  419. cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg,
  420. const std::string& name)
  421. {
  422. std::vector<std::string> exportFiles;
  423. std::string ns;
  424. const cmExportSetMap& exportSets = gg->GetExportSets();
  425. for (auto const& expIt : exportSets) {
  426. const cmExportSet& exportSet = expIt.second;
  427. bool containsTarget = false;
  428. for (auto const& target : exportSet.GetTargetExports()) {
  429. if (name == target->TargetName) {
  430. containsTarget = true;
  431. break;
  432. }
  433. }
  434. if (containsTarget) {
  435. std::vector<cmInstallExportGenerator const*> const* installs =
  436. exportSet.GetInstallations();
  437. for (cmInstallExportGenerator const* install : *installs) {
  438. exportFiles.push_back(install->GetDestinationFile());
  439. ns = install->GetNamespace();
  440. }
  441. }
  442. }
  443. return { exportFiles, ns };
  444. }
  445. void cmExportInstallFileGenerator::ComplainAboutMissingTarget(
  446. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  447. std::vector<std::string> const& exportFiles)
  448. {
  449. std::ostringstream e;
  450. e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName()
  451. << "\" ...) "
  452. << "includes target \"" << depender->GetName()
  453. << "\" which requires target \"" << dependee->GetName() << "\" ";
  454. if (exportFiles.empty()) {
  455. e << "that is not in any export set.";
  456. } else {
  457. e << "that is not in this export set, but in multiple other export sets: "
  458. << cmJoin(exportFiles, ", ") << ".\n";
  459. e << "An exported target cannot depend upon another target which is "
  460. "exported multiple times. Consider consolidating the exports of the "
  461. "\""
  462. << dependee->GetName() << "\" target to a single export.";
  463. }
  464. cmSystemTools::Error(e.str());
  465. }
  466. std::string cmExportInstallFileGenerator::InstallNameDir(
  467. cmGeneratorTarget const* target, const std::string& config)
  468. {
  469. std::string install_name_dir;
  470. cmMakefile* mf = target->Target->GetMakefile();
  471. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  472. install_name_dir =
  473. target->GetInstallNameDirForInstallTree(config, "${_IMPORT_PREFIX}");
  474. }
  475. return install_name_dir;
  476. }
  477. namespace {
  478. bool EntryIsContextSensitive(
  479. const std::unique_ptr<cmCompiledGeneratorExpression>& cge)
  480. {
  481. return cge->GetHadContextSensitiveCondition();
  482. }
  483. }
  484. std::string cmExportInstallFileGenerator::GetFileSetDirectories(
  485. cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te)
  486. {
  487. std::vector<std::string> resultVector;
  488. auto configs =
  489. gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  490. cmGeneratorExpression ge;
  491. auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
  492. for (auto const& config : configs) {
  493. auto dest = cmStrCat("${_IMPORT_PREFIX}/",
  494. cmOutputConverter::EscapeForCMake(
  495. cge->Evaluate(gte->LocalGenerator, config, gte),
  496. cmOutputConverter::WrapQuotes::NoWrap));
  497. if (cge->GetHadContextSensitiveCondition() && configs.size() != 1) {
  498. resultVector.push_back(
  499. cmStrCat("\"$<$<CONFIG:", config, ">:", dest, ">\""));
  500. } else {
  501. resultVector.push_back(cmStrCat('"', dest, '"'));
  502. break;
  503. }
  504. }
  505. return cmJoin(resultVector, " ");
  506. }
  507. std::string cmExportInstallFileGenerator::GetFileSetFiles(
  508. cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* te)
  509. {
  510. std::vector<std::string> resultVector;
  511. auto configs =
  512. gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  513. auto fileEntries = fileSet->CompileFileEntries();
  514. auto directoryEntries = fileSet->CompileDirectoryEntries();
  515. cmGeneratorExpression destGe;
  516. auto destCge =
  517. destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
  518. for (auto const& config : configs) {
  519. auto directories = fileSet->EvaluateDirectoryEntries(
  520. directoryEntries, gte->LocalGenerator, config, gte);
  521. std::map<std::string, std::vector<std::string>> files;
  522. for (auto const& entry : fileEntries) {
  523. fileSet->EvaluateFileEntry(directories, files, entry,
  524. gte->LocalGenerator, config, gte);
  525. }
  526. auto dest = cmStrCat("${_IMPORT_PREFIX}/",
  527. cmOutputConverter::EscapeForCMake(
  528. destCge->Evaluate(gte->LocalGenerator, config, gte),
  529. cmOutputConverter::WrapQuotes::NoWrap),
  530. '/');
  531. bool const contextSensitive = destCge->GetHadContextSensitiveCondition() ||
  532. std::any_of(directoryEntries.begin(), directoryEntries.end(),
  533. EntryIsContextSensitive) ||
  534. std::any_of(fileEntries.begin(), fileEntries.end(),
  535. EntryIsContextSensitive);
  536. for (auto const& it : files) {
  537. auto prefix = it.first.empty() ? "" : cmStrCat(it.first, '/');
  538. for (auto const& filename : it.second) {
  539. auto relFile =
  540. cmStrCat(prefix, cmSystemTools::GetFilenameName(filename));
  541. auto escapedFile =
  542. cmStrCat(dest,
  543. cmOutputConverter::EscapeForCMake(
  544. relFile, cmOutputConverter::WrapQuotes::NoWrap));
  545. if (contextSensitive && configs.size() != 1) {
  546. resultVector.push_back(
  547. cmStrCat("\"$<$<CONFIG:", config, ">:", escapedFile, ">\""));
  548. } else {
  549. resultVector.push_back(cmStrCat('"', escapedFile, '"'));
  550. }
  551. }
  552. }
  553. if (!(contextSensitive && configs.size() != 1)) {
  554. break;
  555. }
  556. }
  557. return cmJoin(resultVector, " ");
  558. }