cmExportInstallFileGenerator.cxx 22 KB

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