cmExportInstallFileGenerator.cxx 22 KB

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