cmExportInstallFileGenerator.cxx 23 KB

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