cmExportInstallFileGenerator.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. if (exportInfo.Files.size() == 1) {
  221. std::string missingTarget = exportInfo.Namespace;
  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, exportInfo.Files);
  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. }
  352. bool cmExportInstallFileGenerator::CheckInterfaceDirs(
  353. std::string const& prepro, cmGeneratorTarget const* target,
  354. std::string const& prop) const
  355. {
  356. std::string const& installDir =
  357. target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  358. std::string const& topSourceDir =
  359. target->GetLocalGenerator()->GetSourceDirectory();
  360. std::string const& topBinaryDir =
  361. target->GetLocalGenerator()->GetBinaryDirectory();
  362. std::vector<std::string> parts;
  363. cmGeneratorExpression::Split(prepro, parts);
  364. bool const inSourceBuild = topSourceDir == topBinaryDir;
  365. bool hadFatalError = false;
  366. for (std::string const& li : parts) {
  367. size_t genexPos = cmGeneratorExpression::Find(li);
  368. if (genexPos == 0) {
  369. continue;
  370. }
  371. if (cmHasPrefix(li, this->GetImportPrefixWithSlash())) {
  372. continue;
  373. }
  374. MessageType messageType = MessageType::FATAL_ERROR;
  375. std::ostringstream e;
  376. if (genexPos != std::string::npos) {
  377. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  378. switch (target->GetPolicyStatusCMP0041()) {
  379. case cmPolicies::WARN:
  380. messageType = MessageType::WARNING;
  381. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
  382. break;
  383. case cmPolicies::OLD:
  384. continue;
  385. case cmPolicies::NEW:
  386. hadFatalError = true;
  387. break; // Issue fatal message.
  388. }
  389. } else {
  390. hadFatalError = true;
  391. }
  392. }
  393. if (!cmSystemTools::FileIsFullPath(li)) {
  394. /* clang-format off */
  395. e << "Target \"" << target->GetName() << "\" " << prop <<
  396. " property contains relative path:\n"
  397. " \"" << li << "\"";
  398. /* clang-format on */
  399. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  400. }
  401. bool inBinary = isSubDirectory(li, topBinaryDir);
  402. bool inSource = isSubDirectory(li, topSourceDir);
  403. if (isSubDirectory(li, installDir)) {
  404. // The include directory is inside the install tree. If the
  405. // install tree is not inside the source tree or build tree then
  406. // fall through to the checks below that the include directory is not
  407. // also inside the source tree or build tree.
  408. bool shouldContinue =
  409. (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
  410. (!inSource || isSubDirectory(installDir, topSourceDir));
  411. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  412. if (!shouldContinue) {
  413. switch (target->GetPolicyStatusCMP0052()) {
  414. case cmPolicies::WARN: {
  415. std::ostringstream s;
  416. s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
  417. s << "Directory:\n \"" << li
  418. << "\"\nin "
  419. "INTERFACE_INCLUDE_DIRECTORIES of target \""
  420. << target->GetName()
  421. << "\" is a subdirectory of the install "
  422. "directory:\n \""
  423. << installDir
  424. << "\"\nhowever it is also "
  425. "a subdirectory of the "
  426. << (inBinary ? "build" : "source") << " tree:\n \""
  427. << (inBinary ? topBinaryDir : topSourceDir) << "\"\n";
  428. target->GetLocalGenerator()->IssueMessage(
  429. MessageType::AUTHOR_WARNING, s.str());
  430. CM_FALLTHROUGH;
  431. }
  432. case cmPolicies::OLD:
  433. shouldContinue = true;
  434. break;
  435. case cmPolicies::NEW:
  436. break;
  437. }
  438. }
  439. }
  440. if (shouldContinue) {
  441. continue;
  442. }
  443. }
  444. if (inBinary) {
  445. /* clang-format off */
  446. e << "Target \"" << target->GetName() << "\" " << prop <<
  447. " property contains path:\n"
  448. " \"" << li << "\"\nwhich is prefixed in the build directory.";
  449. /* clang-format on */
  450. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  451. }
  452. if (!inSourceBuild) {
  453. if (inSource) {
  454. e << "Target \"" << target->GetName() << "\" " << prop
  455. << " property contains path:\n"
  456. " \""
  457. << li << "\"\nwhich is prefixed in the source directory.";
  458. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  459. }
  460. }
  461. }
  462. return !hadFatalError;
  463. }
  464. void cmExportInstallFileGenerator::PopulateSourcesInterface(
  465. cmGeneratorTarget const* gt,
  466. cmGeneratorExpression::PreprocessContext preprocessRule,
  467. ImportPropertyMap& properties)
  468. {
  469. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  470. char const* const propName = "INTERFACE_SOURCES";
  471. cmValue input = gt->GetProperty(propName);
  472. if (!input) {
  473. return;
  474. }
  475. if (input->empty()) {
  476. properties[propName].clear();
  477. return;
  478. }
  479. std::string prepro = cmGeneratorExpression::Preprocess(
  480. *input, preprocessRule, this->GetImportPrefixWithSlash());
  481. if (!prepro.empty()) {
  482. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  483. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  484. return;
  485. }
  486. properties[propName] = prepro;
  487. }
  488. }
  489. void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface(
  490. cmGeneratorTarget const* target,
  491. cmGeneratorExpression::PreprocessContext preprocessRule,
  492. ImportPropertyMap& properties, cmTargetExport const& te,
  493. std::string& includesDestinationDirs)
  494. {
  495. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  496. includesDestinationDirs.clear();
  497. char const* const propName = "INTERFACE_INCLUDE_DIRECTORIES";
  498. cmValue input = target->GetProperty(propName);
  499. cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance());
  500. std::string dirs = cmGeneratorExpression::Preprocess(
  501. cmList::to_string(target->Target->GetInstallIncludeDirectoriesEntries(te)),
  502. preprocessRule, this->GetImportPrefixWithSlash());
  503. this->ReplaceInstallPrefix(dirs);
  504. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
  505. std::string exportDirs =
  506. cge->Evaluate(target->GetLocalGenerator(), "", target);
  507. if (cge->GetHadContextSensitiveCondition()) {
  508. cmLocalGenerator* lg = target->GetLocalGenerator();
  509. std::ostringstream e;
  510. e << "Target \"" << target->GetName()
  511. << "\" is installed with "
  512. "INCLUDES DESTINATION set to a context sensitive path. Paths which "
  513. "depend on the configuration, policy values or the link interface "
  514. "are "
  515. "not supported. Consider using target_include_directories instead.";
  516. lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
  517. return;
  518. }
  519. if (!input && exportDirs.empty()) {
  520. return;
  521. }
  522. if ((input && input->empty()) && exportDirs.empty()) {
  523. // Set to empty
  524. properties[propName].clear();
  525. return;
  526. }
  527. this->AddImportPrefix(exportDirs);
  528. includesDestinationDirs = exportDirs;
  529. std::string includes = (input ? *input : "");
  530. char const* const sep = input ? ";" : "";
  531. includes += sep + exportDirs;
  532. std::string prepro = cmGeneratorExpression::Preprocess(
  533. includes, preprocessRule, this->GetImportPrefixWithSlash());
  534. if (!prepro.empty()) {
  535. this->ResolveTargetsInGeneratorExpressions(prepro, target);
  536. if (!this->CheckInterfaceDirs(prepro, target, propName)) {
  537. return;
  538. }
  539. properties[propName] = prepro;
  540. }
  541. }
  542. void cmExportInstallFileGenerator::PopulateLinkDependsInterface(
  543. cmGeneratorTarget const* gt,
  544. cmGeneratorExpression::PreprocessContext preprocessRule,
  545. ImportPropertyMap& properties)
  546. {
  547. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  548. char const* const propName = "INTERFACE_LINK_DEPENDS";
  549. cmValue input = gt->GetProperty(propName);
  550. if (!input) {
  551. return;
  552. }
  553. if (input->empty()) {
  554. properties[propName].clear();
  555. return;
  556. }
  557. std::string prepro = cmGeneratorExpression::Preprocess(
  558. *input, preprocessRule, this->GetImportPrefixWithSlash());
  559. if (!prepro.empty()) {
  560. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  561. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  562. return;
  563. }
  564. properties[propName] = prepro;
  565. }
  566. }
  567. void cmExportInstallFileGenerator::PopulateLinkDirectoriesInterface(
  568. cmGeneratorTarget const* gt,
  569. cmGeneratorExpression::PreprocessContext preprocessRule,
  570. ImportPropertyMap& properties)
  571. {
  572. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  573. char const* const propName = "INTERFACE_LINK_DIRECTORIES";
  574. cmValue input = gt->GetProperty(propName);
  575. if (!input) {
  576. return;
  577. }
  578. if (input->empty()) {
  579. properties[propName].clear();
  580. return;
  581. }
  582. std::string prepro = cmGeneratorExpression::Preprocess(
  583. *input, preprocessRule, this->GetImportPrefixWithSlash());
  584. if (!prepro.empty()) {
  585. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  586. if (!this->CheckInterfaceDirs(prepro, gt, propName)) {
  587. return;
  588. }
  589. properties[propName] = prepro;
  590. }
  591. }