cmExportInstallFileGenerator.cxx 23 KB

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