cmExportInstallFileGenerator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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 <cassert>
  6. #include <cstddef>
  7. #include <memory>
  8. #include <set>
  9. #include <sstream>
  10. #include <utility>
  11. #include "cmExportSet.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGeneratorTarget.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmInstallTargetGenerator.h"
  16. #include "cmList.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmMakefile.h"
  19. #include "cmMessageType.h"
  20. #include "cmPolicies.h"
  21. #include "cmStringAlgorithms.h"
  22. #include "cmSystemTools.h"
  23. #include "cmTarget.h"
  24. #include "cmTargetExport.h"
  25. #include "cmValue.h"
  26. #include "cmake.h"
  27. cmExportInstallFileGenerator::cmExportInstallFileGenerator(
  28. cmInstallExportGenerator* iegen)
  29. : IEGen(iegen)
  30. {
  31. }
  32. void cmExportInstallFileGenerator::ReplaceInstallPrefix(
  33. std::string& input) const
  34. {
  35. cmGeneratorExpression::ReplaceInstallPrefix(input, this->GetInstallPrefix());
  36. }
  37. void cmExportInstallFileGenerator::PopulateImportProperties(
  38. std::string const& config, std::string const& suffix,
  39. cmTargetExport const* targetExport, ImportPropertyMap& properties,
  40. std::set<std::string>& importedLocations)
  41. {
  42. this->SetImportLocationProperty(config, suffix,
  43. targetExport->ArchiveGenerator, properties,
  44. importedLocations);
  45. this->SetImportLocationProperty(config, suffix,
  46. targetExport->LibraryGenerator, properties,
  47. importedLocations);
  48. this->SetImportLocationProperty(config, suffix,
  49. targetExport->RuntimeGenerator, properties,
  50. importedLocations);
  51. this->SetImportLocationProperty(config, suffix,
  52. targetExport->ObjectsGenerator, properties,
  53. importedLocations);
  54. this->SetImportLocationProperty(config, suffix,
  55. targetExport->FrameworkGenerator, properties,
  56. importedLocations);
  57. this->SetImportLocationProperty(config, suffix,
  58. targetExport->BundleGenerator, properties,
  59. importedLocations);
  60. // If any file location was set for the target add it to the
  61. // import file.
  62. if (!properties.empty()) {
  63. // Get the rest of the target details.
  64. cmGeneratorTarget const* const gtgt = targetExport->Target;
  65. this->SetImportDetailProperties(config, suffix, gtgt, properties);
  66. // TODO: PUBLIC_HEADER_LOCATION
  67. // This should wait until the build feature propagation stuff is done.
  68. // Then this can be a propagated include directory.
  69. // this->GenerateImportProperty(config, te->HeaderGenerator, properties);
  70. }
  71. }
  72. std::string cmExportInstallFileGenerator::GetImportXcFrameworkLocation(
  73. std::string const& config, cmTargetExport const* targetExport) const
  74. {
  75. std::string importedXcFrameworkLocation = targetExport->XcFrameworkLocation;
  76. if (!importedXcFrameworkLocation.empty()) {
  77. importedXcFrameworkLocation = cmGeneratorExpression::Preprocess(
  78. importedXcFrameworkLocation,
  79. cmGeneratorExpression::PreprocessContext::InstallInterface,
  80. this->GetImportPrefixWithSlash());
  81. importedXcFrameworkLocation = cmGeneratorExpression::Evaluate(
  82. importedXcFrameworkLocation, targetExport->Target->GetLocalGenerator(),
  83. config, targetExport->Target, nullptr, targetExport->Target);
  84. if (!importedXcFrameworkLocation.empty() &&
  85. !cmSystemTools::FileIsFullPath(importedXcFrameworkLocation) &&
  86. !cmHasPrefix(importedXcFrameworkLocation,
  87. this->GetImportPrefixWithSlash())) {
  88. return cmStrCat(this->GetImportPrefixWithSlash(),
  89. importedXcFrameworkLocation);
  90. }
  91. }
  92. return importedXcFrameworkLocation;
  93. }
  94. bool cmExportInstallFileGenerator::GenerateImportFileConfig(
  95. std::string const& config)
  96. {
  97. // Skip configurations not enabled for this export.
  98. if (!this->IEGen->InstallsForConfig(config)) {
  99. return true;
  100. }
  101. // Construct the name of the file to generate.
  102. std::string fileName = cmStrCat(this->FileDir, '/', this->FileBase,
  103. this->GetConfigFileNameSeparator());
  104. if (!config.empty()) {
  105. fileName += cmSystemTools::LowerCase(config);
  106. } else {
  107. fileName += "noconfig";
  108. }
  109. fileName += this->FileExt;
  110. // Open the output file to generate it.
  111. cmGeneratedFileStream exportFileStream(fileName, true);
  112. if (!exportFileStream) {
  113. std::string se = cmSystemTools::GetLastSystemError();
  114. std::ostringstream e;
  115. e << "cannot write to file \"" << fileName << "\": " << se;
  116. cmSystemTools::Error(e.str());
  117. return false;
  118. }
  119. exportFileStream.SetCopyIfDifferent(true);
  120. std::ostream& os = exportFileStream;
  121. // Generate the per-config target information.
  122. this->GenerateImportConfig(os, config);
  123. // Record this per-config import file.
  124. this->ConfigImportFiles[config] = fileName;
  125. return true;
  126. }
  127. void cmExportInstallFileGenerator::SetImportLocationProperty(
  128. std::string const& config, std::string const& suffix,
  129. cmInstallTargetGenerator* itgen, ImportPropertyMap& properties,
  130. std::set<std::string>& importedLocations)
  131. {
  132. // Skip rules that do not match this configuration.
  133. if (!(itgen && itgen->InstallsForConfig(config))) {
  134. return;
  135. }
  136. // Get the target to be installed.
  137. cmGeneratorTarget* target = itgen->GetTarget();
  138. // Construct the installed location of the target.
  139. std::string dest = itgen->GetDestination(config);
  140. std::string value;
  141. if (!cmSystemTools::FileIsFullPath(dest)) {
  142. // The target is installed relative to the installation prefix.
  143. value = std::string{ this->GetImportPrefixWithSlash() };
  144. }
  145. value += dest;
  146. value += "/";
  147. if (itgen->IsImportLibrary()) {
  148. // Construct the property name.
  149. std::string prop = cmStrCat("IMPORTED_IMPLIB", suffix);
  150. // Append the installed file name.
  151. value += cmInstallTargetGenerator::GetInstallFilename(
  152. target, config, cmInstallTargetGenerator::NameImplibReal);
  153. // Store the property.
  154. properties[prop] = value;
  155. importedLocations.insert(prop);
  156. } else if (itgen->GetTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  157. // Construct the property name.
  158. std::string prop = cmStrCat("IMPORTED_OBJECTS", suffix);
  159. // Compute all the object files inside this target and setup
  160. // IMPORTED_OBJECTS as a list of object files
  161. std::vector<std::string> objects;
  162. itgen->GetInstallObjectNames(config, objects);
  163. for (std::string& obj : objects) {
  164. obj = cmStrCat(value, obj);
  165. }
  166. // Store the property.
  167. properties[prop] = cmList::to_string(objects);
  168. importedLocations.insert(prop);
  169. } else {
  170. if (target->IsFrameworkOnApple() && target->HasImportLibrary(config)) {
  171. // store as well IMPLIB value
  172. auto importProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  173. auto importValue =
  174. cmStrCat(value,
  175. cmInstallTargetGenerator::GetInstallFilename(
  176. target, config, cmInstallTargetGenerator::NameImplibReal));
  177. // Store the property.
  178. properties[importProp] = importValue;
  179. importedLocations.insert(importProp);
  180. }
  181. // Construct the property name.
  182. std::string prop = cmStrCat("IMPORTED_LOCATION", suffix);
  183. // Append the installed file name.
  184. if (target->IsAppBundleOnApple()) {
  185. value += cmInstallTargetGenerator::GetInstallFilename(target, config);
  186. value += ".app/";
  187. if (!target->Makefile->PlatformIsAppleEmbedded()) {
  188. value += "Contents/MacOS/";
  189. }
  190. value += cmInstallTargetGenerator::GetInstallFilename(target, config);
  191. } else {
  192. value += cmInstallTargetGenerator::GetInstallFilename(
  193. target, config, cmInstallTargetGenerator::NameReal);
  194. }
  195. // Store the property.
  196. properties[prop] = value;
  197. importedLocations.insert(prop);
  198. }
  199. }
  200. cmStateEnums::TargetType cmExportInstallFileGenerator::GetExportTargetType(
  201. cmTargetExport const* targetExport) const
  202. {
  203. cmStateEnums::TargetType targetType = targetExport->Target->GetType();
  204. // An OBJECT library installed with no OBJECTS DESTINATION
  205. // is transformed to an INTERFACE library.
  206. if (targetType == cmStateEnums::OBJECT_LIBRARY &&
  207. !targetExport->ObjectsGenerator) {
  208. targetType = cmStateEnums::INTERFACE_LIBRARY;
  209. }
  210. return targetType;
  211. }
  212. std::string const& cmExportInstallFileGenerator::GetExportName() const
  213. {
  214. return this->GetExportSet()->GetName();
  215. }
  216. void cmExportInstallFileGenerator::HandleMissingTarget(
  217. std::string& link_libs, cmGeneratorTarget const* depender,
  218. cmGeneratorTarget* dependee)
  219. {
  220. auto const& exportInfo = this->FindExportInfo(dependee);
  221. if (exportInfo.Namespaces.size() == 1 && exportInfo.Sets.size() == 1) {
  222. std::string missingTarget = *exportInfo.Namespaces.begin();
  223. missingTarget += dependee->GetExportName();
  224. link_libs += missingTarget;
  225. this->MissingTargets.emplace_back(std::move(missingTarget));
  226. } else {
  227. // All exported targets should be known here and should be unique.
  228. // This is probably user-error.
  229. this->ComplainAboutMissingTarget(depender, dependee, exportInfo);
  230. }
  231. }
  232. cmExportFileGenerator::ExportInfo cmExportInstallFileGenerator::FindExportInfo(
  233. cmGeneratorTarget const* target) const
  234. {
  235. std::vector<std::string> exportFiles;
  236. std::set<std::string> exportSets;
  237. std::set<std::string> namespaces;
  238. auto const& name = target->GetName();
  239. auto& allExportSets =
  240. target->GetLocalGenerator()->GetGlobalGenerator()->GetExportSets();
  241. for (auto const& exp : allExportSets) {
  242. auto const& exportSet = exp.second;
  243. auto const& targets = exportSet.GetTargetExports();
  244. if (std::any_of(targets.begin(), targets.end(),
  245. [&name](std::unique_ptr<cmTargetExport> const& te) {
  246. return te->TargetName == name;
  247. })) {
  248. exportSets.insert(exp.first);
  249. std::vector<cmInstallExportGenerator const*> const* installs =
  250. exportSet.GetInstallations();
  251. for (cmInstallExportGenerator const* install : *installs) {
  252. exportFiles.push_back(install->GetDestinationFile());
  253. namespaces.insert(install->GetNamespace());
  254. }
  255. }
  256. }
  257. return { exportFiles, exportSets, namespaces };
  258. }
  259. void cmExportInstallFileGenerator::ComplainAboutMissingTarget(
  260. cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee,
  261. ExportInfo const& exportInfo) const
  262. {
  263. std::ostringstream e;
  264. e << "install(" << this->IEGen->InstallSubcommand() << " \""
  265. << this->GetExportName() << "\" ...) "
  266. << "includes target \"" << depender->GetName()
  267. << "\" which requires target \"" << dependee->GetName() << "\" ";
  268. if (exportInfo.Sets.empty()) {
  269. e << "that is not in any export set.";
  270. } else {
  271. if (exportInfo.Sets.size() == 1) {
  272. e << "that is not in this export set, but in another export set which "
  273. "is "
  274. "exported multiple times with different namespaces: ";
  275. } else {
  276. e << "that is not in this export set, but in multiple other export "
  277. "sets: ";
  278. }
  279. e << cmJoin(exportInfo.Files, ", ") << ".\n"
  280. << "An exported target cannot depend upon another target which is "
  281. "exported in more than one export set or with more than one "
  282. "namespace. "
  283. "Consider consolidating the exports of the \""
  284. << dependee->GetName() << "\" target to a single export.";
  285. }
  286. this->ReportError(e.str());
  287. }
  288. void cmExportInstallFileGenerator::ComplainAboutDuplicateTarget(
  289. std::string const& targetName) const
  290. {
  291. std::ostringstream e;
  292. e << "install(" << this->IEGen->InstallSubcommand() << " \""
  293. << this->GetExportName() << "\" ...) "
  294. << "includes target \"" << targetName
  295. << "\" more than once in the export set.";
  296. this->ReportError(e.str());
  297. }
  298. void cmExportInstallFileGenerator::ReportError(
  299. std::string const& errorMessage) const
  300. {
  301. this->IEGen->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  302. MessageType::FATAL_ERROR, errorMessage,
  303. this->IEGen->GetLocalGenerator()->GetMakefile()->GetBacktrace());
  304. }
  305. std::string cmExportInstallFileGenerator::InstallNameDir(
  306. cmGeneratorTarget const* target, std::string const& config)
  307. {
  308. std::string install_name_dir;
  309. cmMakefile* mf = target->Target->GetMakefile();
  310. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  311. auto const& prefix = this->GetInstallPrefix();
  312. install_name_dir = target->GetInstallNameDirForInstallTree(config, prefix);
  313. }
  314. return install_name_dir;
  315. }
  316. std::string cmExportInstallFileGenerator::GetCxxModuleFile() const
  317. {
  318. return this->GetCxxModuleFile(this->GetExportSet()->GetName());
  319. }
  320. bool cmExportInstallFileGenerator::CollectExports(
  321. std::function<void(cmTargetExport const*)> const& visitor)
  322. {
  323. auto pred = [&](std::unique_ptr<cmTargetExport> const& te) -> bool {
  324. if (te->NamelinkOnly) {
  325. return true;
  326. }
  327. if (this->ExportedTargets.insert(te->Target).second) {
  328. visitor(te.get());
  329. return true;
  330. }
  331. this->ComplainAboutDuplicateTarget(te->Target->GetName());
  332. return false;
  333. };
  334. auto const& targets = this->GetExportSet()->GetTargetExports();
  335. return std::all_of(targets.begin(), targets.end(), pred);
  336. }
  337. bool cmExportInstallFileGenerator::PopulateInterfaceProperties(
  338. cmTargetExport const* targetExport, ImportPropertyMap& properties)
  339. {
  340. cmGeneratorTarget const* const gt = targetExport->Target;
  341. std::string includesDestinationDirs;
  342. this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt,
  343. cmGeneratorExpression::InstallInterface,
  344. properties);
  345. this->PopulateIncludeDirectoriesInterface(
  346. gt, cmGeneratorExpression::InstallInterface, properties, *targetExport,
  347. includesDestinationDirs);
  348. this->PopulateLinkDirectoriesInterface(
  349. gt, cmGeneratorExpression::InstallInterface, properties);
  350. this->PopulateLinkDependsInterface(
  351. gt, cmGeneratorExpression::InstallInterface, properties);
  352. this->PopulateSourcesInterface(gt, cmGeneratorExpression::InstallInterface,
  353. properties);
  354. return this->PopulateInterfaceProperties(
  355. gt, includesDestinationDirs, cmGeneratorExpression::InstallInterface,
  356. properties);
  357. }
  358. namespace {
  359. bool isSubDirectory(std::string const& a, std::string const& b)
  360. {
  361. return (cmSystemTools::ComparePath(a, b) ||
  362. cmSystemTools::IsSubDirectory(a, b));
  363. }
  364. }
  365. bool cmExportInstallFileGenerator::CheckInterfaceDirs(
  366. std::string const& prepro, cmGeneratorTarget const* target,
  367. std::string const& prop) const
  368. {
  369. std::string const& installDir =
  370. target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  371. std::string const& topSourceDir =
  372. target->GetLocalGenerator()->GetSourceDirectory();
  373. std::string const& topBinaryDir =
  374. target->GetLocalGenerator()->GetBinaryDirectory();
  375. std::vector<std::string> parts;
  376. cmGeneratorExpression::Split(prepro, parts);
  377. bool const inSourceBuild = topSourceDir == topBinaryDir;
  378. bool hadFatalError = false;
  379. for (std::string const& li : parts) {
  380. size_t genexPos = cmGeneratorExpression::Find(li);
  381. if (genexPos == 0) {
  382. continue;
  383. }
  384. if (cmHasPrefix(li, this->GetImportPrefixWithSlash())) {
  385. continue;
  386. }
  387. MessageType messageType = MessageType::FATAL_ERROR;
  388. std::ostringstream e;
  389. if (genexPos != std::string::npos) {
  390. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  391. switch (target->GetPolicyStatusCMP0041()) {
  392. case cmPolicies::WARN:
  393. messageType = MessageType::WARNING;
  394. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
  395. break;
  396. case cmPolicies::OLD:
  397. continue;
  398. case cmPolicies::NEW:
  399. hadFatalError = true;
  400. break; // Issue fatal message.
  401. }
  402. } else {
  403. hadFatalError = true;
  404. }
  405. }
  406. if (!cmSystemTools::FileIsFullPath(li)) {
  407. /* clang-format off */
  408. e << "Target \"" << target->GetName() << "\" " << prop <<
  409. " property contains relative path:\n"
  410. " \"" << li << "\"";
  411. /* clang-format on */
  412. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  413. }
  414. bool inBinary = isSubDirectory(li, topBinaryDir);
  415. bool inSource = isSubDirectory(li, topSourceDir);
  416. if (isSubDirectory(li, installDir)) {
  417. // The include directory is inside the install tree. If the
  418. // install tree is not inside the source tree or build tree then
  419. // fall through to the checks below that the include directory is not
  420. // also inside the source tree or build tree.
  421. bool shouldContinue =
  422. (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
  423. (!inSource || isSubDirectory(installDir, topSourceDir));
  424. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  425. if (!shouldContinue) {
  426. switch (target->GetPolicyStatusCMP0052()) {
  427. case cmPolicies::WARN: {
  428. std::ostringstream s;
  429. s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
  430. s << "Directory:\n \"" << li
  431. << "\"\nin "
  432. "INTERFACE_INCLUDE_DIRECTORIES of target \""
  433. << target->GetName()
  434. << "\" is a subdirectory of the install "
  435. "directory:\n \""
  436. << installDir
  437. << "\"\nhowever it is also "
  438. "a subdirectory of the "
  439. << (inBinary ? "build" : "source") << " tree:\n \""
  440. << (inBinary ? topBinaryDir : topSourceDir) << "\"\n";
  441. target->GetLocalGenerator()->IssueMessage(
  442. MessageType::AUTHOR_WARNING, s.str());
  443. CM_FALLTHROUGH;
  444. }
  445. case cmPolicies::OLD:
  446. shouldContinue = true;
  447. break;
  448. case cmPolicies::NEW:
  449. break;
  450. }
  451. }
  452. }
  453. if (shouldContinue) {
  454. continue;
  455. }
  456. }
  457. if (inBinary) {
  458. /* clang-format off */
  459. e << "Target \"" << target->GetName() << "\" " << prop <<
  460. " property contains path:\n"
  461. " \"" << li << "\"\nwhich is prefixed in the build directory.";
  462. /* clang-format on */
  463. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  464. }
  465. if (!inSourceBuild) {
  466. if (inSource) {
  467. e << "Target \"" << target->GetName() << "\" " << prop
  468. << " property contains path:\n"
  469. " \""
  470. << li << "\"\nwhich is prefixed in the source directory.";
  471. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  472. }
  473. }
  474. }
  475. return !hadFatalError;
  476. }
  477. void cmExportInstallFileGenerator::PopulateSourcesInterface(
  478. cmGeneratorTarget const* gt,
  479. cmGeneratorExpression::PreprocessContext preprocessRule,
  480. ImportPropertyMap& properties)
  481. {
  482. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  483. char const* const propName = "INTERFACE_SOURCES";
  484. cmValue input = gt->GetProperty(propName);
  485. if (!input) {
  486. return;
  487. }
  488. if (input->empty()) {
  489. properties[propName].clear();
  490. return;
  491. }
  492. std::string prepro = cmGeneratorExpression::Preprocess(
  493. *input, preprocessRule, this->GetImportPrefixWithSlash());
  494. if (!prepro.empty()) {
  495. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  496. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  497. return;
  498. }
  499. properties[propName] = prepro;
  500. }
  501. }
  502. void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface(
  503. cmGeneratorTarget const* target,
  504. cmGeneratorExpression::PreprocessContext preprocessRule,
  505. ImportPropertyMap& properties, cmTargetExport const& te,
  506. std::string& includesDestinationDirs)
  507. {
  508. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  509. includesDestinationDirs.clear();
  510. char const* const propName = "INTERFACE_INCLUDE_DIRECTORIES";
  511. cmValue input = target->GetProperty(propName);
  512. cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance());
  513. std::string dirs = cmGeneratorExpression::Preprocess(
  514. cmList::to_string(target->Target->GetInstallIncludeDirectoriesEntries(te)),
  515. preprocessRule, this->GetImportPrefixWithSlash());
  516. this->ReplaceInstallPrefix(dirs);
  517. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
  518. std::string exportDirs =
  519. cge->Evaluate(target->GetLocalGenerator(), "", target);
  520. if (cge->GetHadContextSensitiveCondition()) {
  521. cmLocalGenerator* lg = target->GetLocalGenerator();
  522. std::ostringstream e;
  523. e << "Target \"" << target->GetName()
  524. << "\" is installed with "
  525. "INCLUDES DESTINATION set to a context sensitive path. Paths which "
  526. "depend on the configuration, policy values or the link interface "
  527. "are "
  528. "not supported. Consider using target_include_directories instead.";
  529. lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
  530. return;
  531. }
  532. if (!input && exportDirs.empty()) {
  533. return;
  534. }
  535. if ((input && input->empty()) && exportDirs.empty()) {
  536. // Set to empty
  537. properties[propName].clear();
  538. return;
  539. }
  540. this->AddImportPrefix(exportDirs);
  541. includesDestinationDirs = exportDirs;
  542. std::string includes = (input ? *input : "");
  543. char const* const sep = input ? ";" : "";
  544. includes += sep + exportDirs;
  545. std::string prepro = cmGeneratorExpression::Preprocess(
  546. includes, preprocessRule, this->GetImportPrefixWithSlash());
  547. if (!prepro.empty()) {
  548. this->ResolveTargetsInGeneratorExpressions(prepro, target);
  549. if (!this->CheckInterfaceDirs(prepro, target, propName)) {
  550. return;
  551. }
  552. properties[propName] = prepro;
  553. }
  554. }
  555. void cmExportInstallFileGenerator::PopulateLinkDependsInterface(
  556. cmGeneratorTarget const* gt,
  557. cmGeneratorExpression::PreprocessContext preprocessRule,
  558. ImportPropertyMap& properties)
  559. {
  560. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  561. char const* const propName = "INTERFACE_LINK_DEPENDS";
  562. cmValue input = gt->GetProperty(propName);
  563. if (!input) {
  564. return;
  565. }
  566. if (input->empty()) {
  567. properties[propName].clear();
  568. return;
  569. }
  570. std::string prepro = cmGeneratorExpression::Preprocess(
  571. *input, preprocessRule, this->GetImportPrefixWithSlash());
  572. if (!prepro.empty()) {
  573. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  574. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  575. return;
  576. }
  577. properties[propName] = prepro;
  578. }
  579. }
  580. void cmExportInstallFileGenerator::PopulateLinkDirectoriesInterface(
  581. cmGeneratorTarget const* gt,
  582. cmGeneratorExpression::PreprocessContext preprocessRule,
  583. ImportPropertyMap& properties)
  584. {
  585. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  586. char const* const propName = "INTERFACE_LINK_DIRECTORIES";
  587. cmValue input = gt->GetProperty(propName);
  588. if (!input) {
  589. return;
  590. }
  591. if (input->empty()) {
  592. properties[propName].clear();
  593. return;
  594. }
  595. std::string prepro = cmGeneratorExpression::Preprocess(
  596. *input, preprocessRule, this->GetImportPrefixWithSlash());
  597. if (!prepro.empty()) {
  598. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  599. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  600. return;
  601. }
  602. properties[propName] = prepro;
  603. }
  604. }