cmExportFileGenerator.cxx 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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 "cmExportFileGenerator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmComputeLinkInformation.h"
  6. #include "cmGeneratedFileStream.h"
  7. #include "cmGeneratorTarget.h"
  8. #include "cmLinkItem.h"
  9. #include "cmLocalGenerator.h"
  10. #include "cmMakefile.h"
  11. #include "cmOutputConverter.h"
  12. #include "cmPolicies.h"
  13. #include "cmProperty.h"
  14. #include "cmPropertyMap.h"
  15. #include "cmStateTypes.h"
  16. #include "cmSystemTools.h"
  17. #include "cmTarget.h"
  18. #include "cmTargetExport.h"
  19. #include "cmake.h"
  20. #include "cmsys/FStream.hxx"
  21. #include <assert.h>
  22. #include <memory> // IWYU pragma: keep
  23. #include <sstream>
  24. #include <string.h>
  25. #include <utility>
  26. static std::string cmExportFileGeneratorEscape(std::string const& str)
  27. {
  28. // Escape a property value for writing into a .cmake file.
  29. std::string result = cmOutputConverter::EscapeForCMake(str);
  30. // Un-escape variable references generated by our own export code.
  31. cmSystemTools::ReplaceString(result, "\\${_IMPORT_PREFIX}",
  32. "${_IMPORT_PREFIX}");
  33. cmSystemTools::ReplaceString(result, "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}",
  34. "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
  35. return result;
  36. }
  37. cmExportFileGenerator::cmExportFileGenerator()
  38. {
  39. this->AppendMode = false;
  40. this->ExportOld = false;
  41. }
  42. void cmExportFileGenerator::AddConfiguration(const std::string& config)
  43. {
  44. this->Configurations.push_back(config);
  45. }
  46. void cmExportFileGenerator::SetExportFile(const char* mainFile)
  47. {
  48. this->MainImportFile = mainFile;
  49. this->FileDir = cmSystemTools::GetFilenamePath(this->MainImportFile);
  50. this->FileBase =
  51. cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
  52. this->FileExt =
  53. cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
  54. }
  55. const char* cmExportFileGenerator::GetMainExportFileName() const
  56. {
  57. return this->MainImportFile.c_str();
  58. }
  59. bool cmExportFileGenerator::GenerateImportFile()
  60. {
  61. // Open the output file to generate it.
  62. std::unique_ptr<cmsys::ofstream> foutPtr;
  63. if (this->AppendMode) {
  64. // Open for append.
  65. foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(),
  66. std::ios::app);
  67. } else {
  68. // Generate atomically and with copy-if-different.
  69. std::unique_ptr<cmGeneratedFileStream> ap(
  70. new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
  71. ap->SetCopyIfDifferent(true);
  72. foutPtr = std::move(ap);
  73. }
  74. if (!foutPtr.get() || !*foutPtr) {
  75. std::string se = cmSystemTools::GetLastSystemError();
  76. std::ostringstream e;
  77. e << "cannot write to file \"" << this->MainImportFile << "\": " << se;
  78. cmSystemTools::Error(e.str().c_str());
  79. return false;
  80. }
  81. std::ostream& os = *foutPtr;
  82. // Start with the import file header.
  83. this->GeneratePolicyHeaderCode(os);
  84. this->GenerateImportHeaderCode(os);
  85. // Create all the imported targets.
  86. bool result = this->GenerateMainFile(os);
  87. // End with the import file footer.
  88. this->GenerateImportFooterCode(os);
  89. this->GeneratePolicyFooterCode(os);
  90. return result;
  91. }
  92. void cmExportFileGenerator::GenerateImportConfig(
  93. std::ostream& os, const std::string& config,
  94. std::vector<std::string>& missingTargets)
  95. {
  96. // Construct the property configuration suffix.
  97. std::string suffix = "_";
  98. if (!config.empty()) {
  99. suffix += cmSystemTools::UpperCase(config);
  100. } else {
  101. suffix += "NOCONFIG";
  102. }
  103. // Generate the per-config target information.
  104. this->GenerateImportTargetsConfig(os, config, suffix, missingTargets);
  105. }
  106. void cmExportFileGenerator::PopulateInterfaceProperty(
  107. const std::string& propName, cmGeneratorTarget* target,
  108. ImportPropertyMap& properties)
  109. {
  110. const char* input = target->GetProperty(propName);
  111. if (input) {
  112. properties[propName] = input;
  113. }
  114. }
  115. void cmExportFileGenerator::PopulateInterfaceProperty(
  116. const std::string& propName, const std::string& outputName,
  117. cmGeneratorTarget* target,
  118. cmGeneratorExpression::PreprocessContext preprocessRule,
  119. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  120. {
  121. const char* input = target->GetProperty(propName);
  122. if (input) {
  123. if (!*input) {
  124. // Set to empty
  125. properties[outputName].clear();
  126. return;
  127. }
  128. std::string prepro =
  129. cmGeneratorExpression::Preprocess(input, preprocessRule);
  130. if (!prepro.empty()) {
  131. this->ResolveTargetsInGeneratorExpressions(prepro, target,
  132. missingTargets);
  133. properties[outputName] = prepro;
  134. }
  135. }
  136. }
  137. void cmExportFileGenerator::GenerateRequiredCMakeVersion(
  138. std::ostream& os, const char* versionString)
  139. {
  140. /* clang-format off */
  141. os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
  142. " message(FATAL_ERROR \"This file relies on consumers using "
  143. "CMake " << versionString << " or greater.\")\n"
  144. "endif()\n\n";
  145. /* clang-format on */
  146. }
  147. bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
  148. cmGeneratorTarget* target,
  149. cmGeneratorExpression::PreprocessContext preprocessRule,
  150. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  151. {
  152. if (!target->IsLinkable()) {
  153. return false;
  154. }
  155. const char* input = target->GetProperty("INTERFACE_LINK_LIBRARIES");
  156. if (input) {
  157. std::string prepro =
  158. cmGeneratorExpression::Preprocess(input, preprocessRule);
  159. if (!prepro.empty()) {
  160. this->ResolveTargetsInGeneratorExpressions(
  161. prepro, target, missingTargets, ReplaceFreeTargets);
  162. properties["INTERFACE_LINK_LIBRARIES"] = prepro;
  163. return true;
  164. }
  165. }
  166. return false;
  167. }
  168. static bool isSubDirectory(std::string const& a, std::string const& b)
  169. {
  170. return (cmSystemTools::ComparePath(a, b) ||
  171. cmSystemTools::IsSubDirectory(a, b));
  172. }
  173. static bool checkInterfaceDirs(const std::string& prepro,
  174. cmGeneratorTarget* target,
  175. const std::string& prop)
  176. {
  177. const char* installDir =
  178. target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  179. std::string const& topSourceDir =
  180. target->GetLocalGenerator()->GetSourceDirectory();
  181. std::string const& topBinaryDir =
  182. target->GetLocalGenerator()->GetBinaryDirectory();
  183. std::vector<std::string> parts;
  184. cmGeneratorExpression::Split(prepro, parts);
  185. const bool inSourceBuild = topSourceDir == topBinaryDir;
  186. bool hadFatalError = false;
  187. for (std::string const& li : parts) {
  188. size_t genexPos = cmGeneratorExpression::Find(li);
  189. if (genexPos == 0) {
  190. continue;
  191. }
  192. cmake::MessageType messageType = cmake::FATAL_ERROR;
  193. std::ostringstream e;
  194. if (genexPos != std::string::npos) {
  195. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  196. switch (target->GetPolicyStatusCMP0041()) {
  197. case cmPolicies::WARN:
  198. messageType = cmake::WARNING;
  199. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
  200. break;
  201. case cmPolicies::OLD:
  202. continue;
  203. case cmPolicies::REQUIRED_IF_USED:
  204. case cmPolicies::REQUIRED_ALWAYS:
  205. case cmPolicies::NEW:
  206. hadFatalError = true;
  207. break; // Issue fatal message.
  208. }
  209. } else {
  210. hadFatalError = true;
  211. }
  212. }
  213. if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) {
  214. continue;
  215. }
  216. if (!cmSystemTools::FileIsFullPath(li)) {
  217. /* clang-format off */
  218. e << "Target \"" << target->GetName() << "\" " << prop <<
  219. " property contains relative path:\n"
  220. " \"" << li << "\"";
  221. /* clang-format on */
  222. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  223. }
  224. bool inBinary = isSubDirectory(li, topBinaryDir);
  225. bool inSource = isSubDirectory(li, topSourceDir);
  226. if (isSubDirectory(li, installDir)) {
  227. // The include directory is inside the install tree. If the
  228. // install tree is not inside the source tree or build tree then
  229. // fall through to the checks below that the include directory is not
  230. // also inside the source tree or build tree.
  231. bool shouldContinue =
  232. (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
  233. (!inSource || isSubDirectory(installDir, topSourceDir));
  234. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  235. if (!shouldContinue) {
  236. switch (target->GetPolicyStatusCMP0052()) {
  237. case cmPolicies::WARN: {
  238. std::ostringstream s;
  239. s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
  240. s << "Directory:\n \"" << li
  241. << "\"\nin "
  242. "INTERFACE_INCLUDE_DIRECTORIES of target \""
  243. << target->GetName()
  244. << "\" is a subdirectory of the install "
  245. "directory:\n \""
  246. << installDir
  247. << "\"\nhowever it is also "
  248. "a subdirectory of the "
  249. << (inBinary ? "build" : "source") << " tree:\n \""
  250. << (inBinary ? topBinaryDir : topSourceDir) << "\""
  251. << std::endl;
  252. target->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING,
  253. s.str());
  254. CM_FALLTHROUGH;
  255. }
  256. case cmPolicies::OLD:
  257. shouldContinue = true;
  258. break;
  259. case cmPolicies::REQUIRED_ALWAYS:
  260. case cmPolicies::REQUIRED_IF_USED:
  261. case cmPolicies::NEW:
  262. break;
  263. }
  264. }
  265. }
  266. if (shouldContinue) {
  267. continue;
  268. }
  269. }
  270. if (inBinary) {
  271. /* clang-format off */
  272. e << "Target \"" << target->GetName() << "\" " << prop <<
  273. " property contains path:\n"
  274. " \"" << li << "\"\nwhich is prefixed in the build directory.";
  275. /* clang-format on */
  276. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  277. }
  278. if (!inSourceBuild) {
  279. if (inSource) {
  280. e << "Target \"" << target->GetName() << "\" " << prop
  281. << " property contains path:\n"
  282. " \""
  283. << li << "\"\nwhich is prefixed in the source directory.";
  284. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  285. }
  286. }
  287. }
  288. return !hadFatalError;
  289. }
  290. static void prefixItems(std::string& exportDirs)
  291. {
  292. std::vector<std::string> entries;
  293. cmGeneratorExpression::Split(exportDirs, entries);
  294. exportDirs.clear();
  295. const char* sep = "";
  296. for (std::string const& e : entries) {
  297. exportDirs += sep;
  298. sep = ";";
  299. if (!cmSystemTools::FileIsFullPath(e) &&
  300. e.find("${_IMPORT_PREFIX}") == std::string::npos) {
  301. exportDirs += "${_IMPORT_PREFIX}/";
  302. }
  303. exportDirs += e;
  304. }
  305. }
  306. void cmExportFileGenerator::PopulateSourcesInterface(
  307. cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
  308. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  309. {
  310. cmGeneratorTarget* gt = tei->Target;
  311. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  312. const char* propName = "INTERFACE_SOURCES";
  313. const char* input = gt->GetProperty(propName);
  314. if (!input) {
  315. return;
  316. }
  317. if (!*input) {
  318. properties[propName].clear();
  319. return;
  320. }
  321. std::string prepro =
  322. cmGeneratorExpression::Preprocess(input, preprocessRule, true);
  323. if (!prepro.empty()) {
  324. this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
  325. if (!checkInterfaceDirs(prepro, gt, propName)) {
  326. return;
  327. }
  328. properties[propName] = prepro;
  329. }
  330. }
  331. void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
  332. cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
  333. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  334. {
  335. cmGeneratorTarget* target = tei->Target;
  336. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  337. const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
  338. const char* input = target->GetProperty(propName);
  339. cmGeneratorExpression ge;
  340. std::string dirs = cmGeneratorExpression::Preprocess(
  341. tei->InterfaceIncludeDirectories, preprocessRule, true);
  342. this->ReplaceInstallPrefix(dirs);
  343. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
  344. std::string exportDirs =
  345. cge->Evaluate(target->GetLocalGenerator(), "", false, target);
  346. if (cge->GetHadContextSensitiveCondition()) {
  347. cmLocalGenerator* lg = target->GetLocalGenerator();
  348. std::ostringstream e;
  349. e << "Target \"" << target->GetName()
  350. << "\" is installed with "
  351. "INCLUDES DESTINATION set to a context sensitive path. Paths which "
  352. "depend on the configuration, policy values or the link interface "
  353. "are "
  354. "not supported. Consider using target_include_directories instead.";
  355. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  356. return;
  357. }
  358. if (!input && exportDirs.empty()) {
  359. return;
  360. }
  361. if ((input && !*input) && exportDirs.empty()) {
  362. // Set to empty
  363. properties[propName].clear();
  364. return;
  365. }
  366. prefixItems(exportDirs);
  367. std::string includes = (input ? input : "");
  368. const char* sep = input ? ";" : "";
  369. includes += sep + exportDirs;
  370. std::string prepro =
  371. cmGeneratorExpression::Preprocess(includes, preprocessRule, true);
  372. if (!prepro.empty()) {
  373. this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets);
  374. if (!checkInterfaceDirs(prepro, target, propName)) {
  375. return;
  376. }
  377. properties[propName] = prepro;
  378. }
  379. }
  380. void cmExportFileGenerator::PopulateInterfaceProperty(
  381. const std::string& propName, cmGeneratorTarget* target,
  382. cmGeneratorExpression::PreprocessContext preprocessRule,
  383. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  384. {
  385. this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
  386. properties, missingTargets);
  387. }
  388. void getPropertyContents(cmGeneratorTarget const* tgt, const std::string& prop,
  389. std::set<std::string>& ifaceProperties)
  390. {
  391. const char* p = tgt->GetProperty(prop);
  392. if (!p) {
  393. return;
  394. }
  395. std::vector<std::string> content;
  396. cmSystemTools::ExpandListArgument(p, content);
  397. ifaceProperties.insert(content.begin(), content.end());
  398. }
  399. void getCompatibleInterfaceProperties(cmGeneratorTarget* target,
  400. std::set<std::string>& ifaceProperties,
  401. const std::string& config)
  402. {
  403. if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  404. // object libraries have no link information, so nothing to compute
  405. return;
  406. }
  407. cmComputeLinkInformation* info = target->GetLinkInformation(config);
  408. if (!info) {
  409. cmLocalGenerator* lg = target->GetLocalGenerator();
  410. std::ostringstream e;
  411. e << "Exporting the target \"" << target->GetName()
  412. << "\" is not "
  413. "allowed since its linker language cannot be determined";
  414. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  415. return;
  416. }
  417. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  418. for (auto const& dep : deps) {
  419. if (!dep.Target) {
  420. continue;
  421. }
  422. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_BOOL",
  423. ifaceProperties);
  424. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_STRING",
  425. ifaceProperties);
  426. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  427. ifaceProperties);
  428. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  429. ifaceProperties);
  430. }
  431. }
  432. void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
  433. cmGeneratorTarget* gtarget, ImportPropertyMap& properties)
  434. {
  435. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL", gtarget,
  436. properties);
  437. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING", gtarget,
  438. properties);
  439. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN", gtarget,
  440. properties);
  441. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX", gtarget,
  442. properties);
  443. std::set<std::string> ifaceProperties;
  444. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
  445. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
  446. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  447. ifaceProperties);
  448. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  449. ifaceProperties);
  450. if (gtarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  451. getCompatibleInterfaceProperties(gtarget, ifaceProperties, "");
  452. std::vector<std::string> configNames;
  453. gtarget->Target->GetMakefile()->GetConfigurations(configNames);
  454. for (std::string const& cn : configNames) {
  455. getCompatibleInterfaceProperties(gtarget, ifaceProperties, cn);
  456. }
  457. }
  458. for (std::string const& ip : ifaceProperties) {
  459. this->PopulateInterfaceProperty("INTERFACE_" + ip, gtarget, properties);
  460. }
  461. }
  462. void cmExportFileGenerator::GenerateInterfaceProperties(
  463. const cmGeneratorTarget* target, std::ostream& os,
  464. const ImportPropertyMap& properties)
  465. {
  466. if (!properties.empty()) {
  467. std::string targetName = this->Namespace;
  468. targetName += target->GetExportName();
  469. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  470. for (auto const& property : properties) {
  471. os << " " << property.first << " "
  472. << cmExportFileGeneratorEscape(property.second) << "\n";
  473. }
  474. os << ")\n\n";
  475. }
  476. }
  477. bool cmExportFileGenerator::AddTargetNamespace(
  478. std::string& input, cmGeneratorTarget* target,
  479. std::vector<std::string>& missingTargets)
  480. {
  481. cmLocalGenerator* lg = target->GetLocalGenerator();
  482. cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(input);
  483. if (!tgt) {
  484. return false;
  485. }
  486. if (tgt->IsImported()) {
  487. return true;
  488. }
  489. if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) {
  490. input = this->Namespace + tgt->GetExportName();
  491. } else {
  492. std::string namespacedTarget;
  493. this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt);
  494. if (!namespacedTarget.empty()) {
  495. input = namespacedTarget;
  496. }
  497. }
  498. return true;
  499. }
  500. void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
  501. std::string& input, cmGeneratorTarget* target,
  502. std::vector<std::string>& missingTargets, FreeTargetsReplace replace)
  503. {
  504. if (replace == NoReplaceFreeTargets) {
  505. this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
  506. return;
  507. }
  508. std::vector<std::string> parts;
  509. cmGeneratorExpression::Split(input, parts);
  510. std::string sep;
  511. input.clear();
  512. for (std::string& li : parts) {
  513. if (cmGeneratorExpression::Find(li) == std::string::npos) {
  514. this->AddTargetNamespace(li, target, missingTargets);
  515. } else {
  516. this->ResolveTargetsInGeneratorExpression(li, target, missingTargets);
  517. }
  518. input += sep + li;
  519. sep = ";";
  520. }
  521. }
  522. void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
  523. std::string& input, cmGeneratorTarget* target,
  524. std::vector<std::string>& missingTargets)
  525. {
  526. std::string::size_type pos = 0;
  527. std::string::size_type lastPos = pos;
  528. while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) !=
  529. std::string::npos) {
  530. std::string::size_type nameStartPos =
  531. pos + sizeof("$<TARGET_PROPERTY:") - 1;
  532. std::string::size_type closePos = input.find('>', nameStartPos);
  533. std::string::size_type commaPos = input.find(',', nameStartPos);
  534. std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
  535. if (commaPos == std::string::npos // Implied 'this' target
  536. || closePos == std::string::npos // Incomplete expression.
  537. || closePos < commaPos // Implied 'this' target
  538. || nextOpenPos < commaPos) // Non-literal
  539. {
  540. lastPos = nameStartPos;
  541. continue;
  542. }
  543. std::string targetName =
  544. input.substr(nameStartPos, commaPos - nameStartPos);
  545. if (this->AddTargetNamespace(targetName, target, missingTargets)) {
  546. input.replace(nameStartPos, commaPos - nameStartPos, targetName);
  547. }
  548. lastPos = nameStartPos + targetName.size() + 1;
  549. }
  550. std::string errorString;
  551. pos = 0;
  552. lastPos = pos;
  553. while ((pos = input.find("$<TARGET_NAME:", lastPos)) != std::string::npos) {
  554. std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
  555. std::string::size_type endPos = input.find('>', nameStartPos);
  556. if (endPos == std::string::npos) {
  557. errorString = "$<TARGET_NAME:...> expression incomplete";
  558. break;
  559. }
  560. std::string targetName = input.substr(nameStartPos, endPos - nameStartPos);
  561. if (targetName.find("$<") != std::string::npos) {
  562. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  563. "literal.";
  564. break;
  565. }
  566. if (!this->AddTargetNamespace(targetName, target, missingTargets)) {
  567. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  568. "reachable target.";
  569. break;
  570. }
  571. input.replace(pos, endPos - pos + 1, targetName);
  572. lastPos = endPos;
  573. }
  574. pos = 0;
  575. lastPos = pos;
  576. while (errorString.empty() &&
  577. (pos = input.find("$<LINK_ONLY:", lastPos)) != std::string::npos) {
  578. std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1;
  579. std::string::size_type endPos = input.find('>', nameStartPos);
  580. if (endPos == std::string::npos) {
  581. errorString = "$<LINK_ONLY:...> expression incomplete";
  582. break;
  583. }
  584. std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
  585. if (cmGeneratorExpression::IsValidTargetName(libName) &&
  586. this->AddTargetNamespace(libName, target, missingTargets)) {
  587. input.replace(nameStartPos, endPos - nameStartPos, libName);
  588. }
  589. lastPos = nameStartPos + libName.size() + 1;
  590. }
  591. this->ReplaceInstallPrefix(input);
  592. if (!errorString.empty()) {
  593. target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString);
  594. }
  595. }
  596. void cmExportFileGenerator::ReplaceInstallPrefix(std::string& /*unused*/)
  597. {
  598. // Do nothing
  599. }
  600. void cmExportFileGenerator::SetImportLinkInterface(
  601. const std::string& config, std::string const& suffix,
  602. cmGeneratorExpression::PreprocessContext preprocessRule,
  603. cmGeneratorTarget* target, ImportPropertyMap& properties,
  604. std::vector<std::string>& missingTargets)
  605. {
  606. // Add the transitive link dependencies for this configuration.
  607. cmLinkInterface const* iface = target->GetLinkInterface(config, target);
  608. if (!iface) {
  609. return;
  610. }
  611. if (iface->ImplementationIsInterface) {
  612. // Policy CMP0022 must not be NEW.
  613. this->SetImportLinkProperty(suffix, target,
  614. "IMPORTED_LINK_INTERFACE_LIBRARIES",
  615. iface->Libraries, properties, missingTargets);
  616. return;
  617. }
  618. const char* propContent;
  619. if (const char* prop_suffixed =
  620. target->GetProperty("LINK_INTERFACE_LIBRARIES" + suffix)) {
  621. propContent = prop_suffixed;
  622. } else if (const char* prop =
  623. target->GetProperty("LINK_INTERFACE_LIBRARIES")) {
  624. propContent = prop;
  625. } else {
  626. return;
  627. }
  628. const bool newCMP0022Behavior =
  629. target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  630. target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  631. if (newCMP0022Behavior && !this->ExportOld) {
  632. cmLocalGenerator* lg = target->GetLocalGenerator();
  633. std::ostringstream e;
  634. e << "Target \"" << target->GetName()
  635. << "\" has policy CMP0022 enabled, "
  636. "but also has old-style LINK_INTERFACE_LIBRARIES properties "
  637. "populated, but it was exported without the "
  638. "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
  639. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  640. return;
  641. }
  642. if (!*propContent) {
  643. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear();
  644. return;
  645. }
  646. std::string prepro =
  647. cmGeneratorExpression::Preprocess(propContent, preprocessRule);
  648. if (!prepro.empty()) {
  649. this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets,
  650. ReplaceFreeTargets);
  651. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
  652. }
  653. }
  654. void cmExportFileGenerator::SetImportDetailProperties(
  655. const std::string& config, std::string const& suffix,
  656. cmGeneratorTarget* target, ImportPropertyMap& properties,
  657. std::vector<std::string>& missingTargets)
  658. {
  659. // Get the makefile in which to lookup target information.
  660. cmMakefile* mf = target->Makefile;
  661. // Add the soname for unix shared libraries.
  662. if (target->GetType() == cmStateEnums::SHARED_LIBRARY ||
  663. target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  664. if (!target->IsDLLPlatform()) {
  665. std::string prop;
  666. std::string value;
  667. if (target->HasSOName(config)) {
  668. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  669. value = this->InstallNameDir(target, config);
  670. }
  671. prop = "IMPORTED_SONAME";
  672. value += target->GetSOName(config);
  673. } else {
  674. prop = "IMPORTED_NO_SONAME";
  675. value = "TRUE";
  676. }
  677. prop += suffix;
  678. properties[prop] = value;
  679. }
  680. }
  681. // Add the transitive link dependencies for this configuration.
  682. if (cmLinkInterface const* iface =
  683. target->GetLinkInterface(config, target)) {
  684. this->SetImportLinkProperty(suffix, target,
  685. "IMPORTED_LINK_INTERFACE_LANGUAGES",
  686. iface->Languages, properties, missingTargets);
  687. std::vector<std::string> dummy;
  688. this->SetImportLinkProperty(suffix, target,
  689. "IMPORTED_LINK_DEPENDENT_LIBRARIES",
  690. iface->SharedDeps, properties, dummy);
  691. if (iface->Multiplicity > 0) {
  692. std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  693. prop += suffix;
  694. std::ostringstream m;
  695. m << iface->Multiplicity;
  696. properties[prop] = m.str();
  697. }
  698. }
  699. // Add information if this target is a managed target
  700. if (target->GetManagedType(config) !=
  701. cmGeneratorTarget::ManagedType::Native) {
  702. std::string prop = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  703. prop += suffix;
  704. std::string propval;
  705. if (auto* p = target->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  706. propval = p;
  707. } else if (target->IsCSharpOnly()) {
  708. // C# projects do not have the /clr flag, so we set the property
  709. // here to mark the target as (only) managed (i.e. no .lib file
  710. // to link to). Otherwise the COMMON_LANGUAGE_RUNTIME target
  711. // property would have to be set manually for C# targets to make
  712. // exporting/importing work.
  713. propval = "CSharp";
  714. }
  715. properties[prop] = propval;
  716. }
  717. }
  718. template <typename T>
  719. void cmExportFileGenerator::SetImportLinkProperty(
  720. std::string const& suffix, cmGeneratorTarget* target,
  721. const std::string& propName, std::vector<T> const& entries,
  722. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  723. {
  724. // Skip the property if there are no entries.
  725. if (entries.empty()) {
  726. return;
  727. }
  728. // Construct the property value.
  729. std::string link_entries;
  730. const char* sep = "";
  731. for (T const& l : entries) {
  732. // Separate this from the previous entry.
  733. link_entries += sep;
  734. sep = ";";
  735. std::string temp = l;
  736. this->AddTargetNamespace(temp, target, missingTargets);
  737. link_entries += temp;
  738. }
  739. // Store the property.
  740. std::string prop = propName;
  741. prop += suffix;
  742. properties[prop] = link_entries;
  743. }
  744. void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
  745. {
  746. // Protect that file against use with older CMake versions.
  747. /* clang-format off */
  748. os << "# Generated by CMake\n\n";
  749. os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
  750. << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
  751. << "endif()\n";
  752. /* clang-format on */
  753. // Isolate the file policy level.
  754. // We use 2.6 here instead of the current version because newer
  755. // versions of CMake should be able to export files imported by 2.6
  756. // until the import format changes.
  757. /* clang-format off */
  758. os << "cmake_policy(PUSH)\n"
  759. << "cmake_policy(VERSION 2.6)\n";
  760. /* clang-format on */
  761. }
  762. void cmExportFileGenerator::GeneratePolicyFooterCode(std::ostream& os)
  763. {
  764. os << "cmake_policy(POP)\n";
  765. }
  766. void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
  767. const std::string& config)
  768. {
  769. os << "#----------------------------------------------------------------\n"
  770. << "# Generated CMake target import file";
  771. if (!config.empty()) {
  772. os << " for configuration \"" << config << "\".\n";
  773. } else {
  774. os << ".\n";
  775. }
  776. os << "#----------------------------------------------------------------\n"
  777. << "\n";
  778. this->GenerateImportVersionCode(os);
  779. }
  780. void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
  781. {
  782. os << "# Commands beyond this point should not need to know the version.\n"
  783. << "set(CMAKE_IMPORT_FILE_VERSION)\n";
  784. }
  785. void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
  786. {
  787. // Store an import file format version. This will let us change the
  788. // format later while still allowing old import files to work.
  789. /* clang-format off */
  790. os << "# Commands may need to know the format version.\n"
  791. << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
  792. << "\n";
  793. /* clang-format on */
  794. }
  795. void cmExportFileGenerator::GenerateExpectedTargetsCode(
  796. std::ostream& os, const std::string& expectedTargets)
  797. {
  798. /* clang-format off */
  799. os << "# Protect against multiple inclusion, which would fail when already "
  800. "imported targets are added once more.\n"
  801. "set(_targetsDefined)\n"
  802. "set(_targetsNotDefined)\n"
  803. "set(_expectedTargets)\n"
  804. "foreach(_expectedTarget " << expectedTargets << ")\n"
  805. " list(APPEND _expectedTargets ${_expectedTarget})\n"
  806. " if(NOT TARGET ${_expectedTarget})\n"
  807. " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
  808. " endif()\n"
  809. " if(TARGET ${_expectedTarget})\n"
  810. " list(APPEND _targetsDefined ${_expectedTarget})\n"
  811. " endif()\n"
  812. "endforeach()\n"
  813. "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
  814. " unset(_targetsDefined)\n"
  815. " unset(_targetsNotDefined)\n"
  816. " unset(_expectedTargets)\n"
  817. " set(CMAKE_IMPORT_FILE_VERSION)\n"
  818. " cmake_policy(POP)\n"
  819. " return()\n"
  820. "endif()\n"
  821. "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
  822. " message(FATAL_ERROR \"Some (but not all) targets in this export "
  823. "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
  824. "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
  825. "endif()\n"
  826. "unset(_targetsDefined)\n"
  827. "unset(_targetsNotDefined)\n"
  828. "unset(_expectedTargets)\n"
  829. "\n\n";
  830. /* clang-format on */
  831. }
  832. void cmExportFileGenerator::GenerateImportTargetCode(
  833. std::ostream& os, cmGeneratorTarget const* target,
  834. cmStateEnums::TargetType targetType)
  835. {
  836. // Construct the imported target name.
  837. std::string targetName = this->Namespace;
  838. targetName += target->GetExportName();
  839. // Create the imported target.
  840. os << "# Create imported target " << targetName << "\n";
  841. switch (targetType) {
  842. case cmStateEnums::EXECUTABLE:
  843. os << "add_executable(" << targetName << " IMPORTED)\n";
  844. break;
  845. case cmStateEnums::STATIC_LIBRARY:
  846. os << "add_library(" << targetName << " STATIC IMPORTED)\n";
  847. break;
  848. case cmStateEnums::SHARED_LIBRARY:
  849. os << "add_library(" << targetName << " SHARED IMPORTED)\n";
  850. break;
  851. case cmStateEnums::MODULE_LIBRARY:
  852. os << "add_library(" << targetName << " MODULE IMPORTED)\n";
  853. break;
  854. case cmStateEnums::UNKNOWN_LIBRARY:
  855. os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
  856. break;
  857. case cmStateEnums::OBJECT_LIBRARY:
  858. os << "add_library(" << targetName << " OBJECT IMPORTED)\n";
  859. break;
  860. case cmStateEnums::INTERFACE_LIBRARY:
  861. os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
  862. break;
  863. default: // should never happen
  864. break;
  865. }
  866. // Mark the imported executable if it has exports.
  867. if (target->IsExecutableWithExports()) {
  868. os << "set_property(TARGET " << targetName
  869. << " PROPERTY ENABLE_EXPORTS 1)\n";
  870. }
  871. // Mark the imported library if it is a framework.
  872. if (target->IsFrameworkOnApple()) {
  873. os << "set_property(TARGET " << targetName << " PROPERTY FRAMEWORK 1)\n";
  874. }
  875. // Mark the imported executable if it is an application bundle.
  876. if (target->IsAppBundleOnApple()) {
  877. os << "set_property(TARGET " << targetName
  878. << " PROPERTY MACOSX_BUNDLE 1)\n";
  879. }
  880. if (target->IsCFBundleOnApple()) {
  881. os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n";
  882. }
  883. os << "\n";
  884. }
  885. void cmExportFileGenerator::GenerateImportPropertyCode(
  886. std::ostream& os, const std::string& config, cmGeneratorTarget const* target,
  887. ImportPropertyMap const& properties)
  888. {
  889. // Construct the imported target name.
  890. std::string targetName = this->Namespace;
  891. targetName += target->GetExportName();
  892. // Set the import properties.
  893. os << "# Import target \"" << targetName << "\" for configuration \""
  894. << config << "\"\n";
  895. os << "set_property(TARGET " << targetName
  896. << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
  897. if (!config.empty()) {
  898. os << cmSystemTools::UpperCase(config);
  899. } else {
  900. os << "NOCONFIG";
  901. }
  902. os << ")\n";
  903. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  904. for (auto const& property : properties) {
  905. os << " " << property.first << " "
  906. << cmExportFileGeneratorEscape(property.second) << "\n";
  907. }
  908. os << " )\n"
  909. << "\n";
  910. }
  911. void cmExportFileGenerator::GenerateMissingTargetsCheckCode(
  912. std::ostream& os, const std::vector<std::string>& missingTargets)
  913. {
  914. if (missingTargets.empty()) {
  915. /* clang-format off */
  916. os << "# This file does not depend on other imported targets which have\n"
  917. "# been exported from the same project but in a separate "
  918. "export set.\n\n";
  919. /* clang-format on */
  920. return;
  921. }
  922. /* clang-format off */
  923. os << "# Make sure the targets which have been exported in some other \n"
  924. "# export set exist.\n"
  925. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  926. "foreach(_target ";
  927. /* clang-format on */
  928. std::set<std::string> emitted;
  929. for (std::string const& missingTarget : missingTargets) {
  930. if (emitted.insert(missingTarget).second) {
  931. os << "\"" << missingTarget << "\" ";
  932. }
  933. }
  934. /* clang-format off */
  935. os << ")\n"
  936. " if(NOT TARGET \"${_target}\" )\n"
  937. " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
  938. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
  939. "\n"
  940. " endif()\n"
  941. "endforeach()\n"
  942. "\n"
  943. "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  944. " if(CMAKE_FIND_PACKAGE_NAME)\n"
  945. " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
  946. " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
  947. "\"The following imported targets are "
  948. "referenced, but are missing: "
  949. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  950. " else()\n"
  951. " message(FATAL_ERROR \"The following imported targets are "
  952. "referenced, but are missing: "
  953. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  954. " endif()\n"
  955. "endif()\n"
  956. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  957. "\n";
  958. /* clang-format on */
  959. }
  960. void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
  961. {
  962. // Add code which verifies at cmake time that the file which is being
  963. // imported actually exists on disk. This should in theory always be theory
  964. // case, but still when packages are split into normal and development
  965. // packages this might get broken (e.g. the Config.cmake could be part of
  966. // the non-development package, something similar happened to me without
  967. // on SUSE with a mysql pkg-config file, which claimed everything is fine,
  968. // but the development package was not installed.).
  969. /* clang-format off */
  970. os << "# Loop over all imported files and verify that they actually exist\n"
  971. "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
  972. " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
  973. " if(NOT EXISTS \"${file}\" )\n"
  974. " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
  975. " references the file\n"
  976. " \\\"${file}\\\"\n"
  977. "but this file does not exist. Possible reasons include:\n"
  978. "* The file was deleted, renamed, or moved to another location.\n"
  979. "* An install or uninstall procedure did not complete successfully.\n"
  980. "* The installation package was faulty and contained\n"
  981. " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
  982. "but not all the files it references.\n"
  983. "\")\n"
  984. " endif()\n"
  985. " endforeach()\n"
  986. " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
  987. "endforeach()\n"
  988. "unset(_IMPORT_CHECK_TARGETS)\n"
  989. "\n";
  990. /* clang-format on */
  991. }
  992. void cmExportFileGenerator::GenerateImportedFileChecksCode(
  993. std::ostream& os, cmGeneratorTarget* target,
  994. ImportPropertyMap const& properties,
  995. const std::set<std::string>& importedLocations)
  996. {
  997. // Construct the imported target name.
  998. std::string targetName = this->Namespace;
  999. targetName += target->GetExportName();
  1000. os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName
  1001. << " )\n"
  1002. "list(APPEND _IMPORT_CHECK_FILES_FOR_"
  1003. << targetName << " ";
  1004. for (std::string const& li : importedLocations) {
  1005. ImportPropertyMap::const_iterator pi = properties.find(li);
  1006. if (pi != properties.end()) {
  1007. os << cmExportFileGeneratorEscape(pi->second) << " ";
  1008. }
  1009. }
  1010. os << ")\n\n";
  1011. }
  1012. bool cmExportFileGenerator::PopulateExportProperties(
  1013. cmGeneratorTarget* gte, ImportPropertyMap& properties,
  1014. std::string& errorMessage)
  1015. {
  1016. auto& targetProperties = gte->Target->GetProperties();
  1017. const auto& exportProperties = targetProperties.find("EXPORT_PROPERTIES");
  1018. if (exportProperties != targetProperties.end()) {
  1019. std::vector<std::string> propsToExport;
  1020. cmSystemTools::ExpandListArgument(exportProperties->second.GetValue(),
  1021. propsToExport);
  1022. for (auto& prop : propsToExport) {
  1023. /* Black list reserved properties */
  1024. if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") ||
  1025. cmSystemTools::StringStartsWith(prop, "INTERFACE_")) {
  1026. std::ostringstream e;
  1027. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1028. << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* "
  1029. << "properties are reserved.";
  1030. errorMessage = e.str();
  1031. return false;
  1032. }
  1033. auto propertyValue = targetProperties.GetPropertyValue(prop);
  1034. if (propertyValue == nullptr) {
  1035. // Asked to export a property that isn't defined on the target. Do not
  1036. // consider this an error, there's just nothing to export.
  1037. continue;
  1038. }
  1039. std::string evaluatedValue = cmGeneratorExpression::Preprocess(
  1040. propertyValue, cmGeneratorExpression::StripAllGeneratorExpressions);
  1041. if (evaluatedValue != propertyValue) {
  1042. std::ostringstream e;
  1043. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1044. << prop << "\" in EXPORT_PROPERTIES but this property contains a "
  1045. << "generator expression. This is not allowed.";
  1046. errorMessage = e.str();
  1047. return false;
  1048. }
  1049. properties[prop] = propertyValue;
  1050. }
  1051. }
  1052. return true;
  1053. }