cmExportFileGenerator.cxx 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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() << "\" is a subdirectory of the install "
  244. "directory:\n \""
  245. << installDir << "\"\nhowever it is also "
  246. "a subdirectory of the "
  247. << (inBinary ? "build" : "source") << " tree:\n \""
  248. << (inBinary ? topBinaryDir : topSourceDir) << "\""
  249. << std::endl;
  250. target->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING,
  251. s.str());
  252. CM_FALLTHROUGH;
  253. }
  254. case cmPolicies::OLD:
  255. shouldContinue = true;
  256. break;
  257. case cmPolicies::REQUIRED_ALWAYS:
  258. case cmPolicies::REQUIRED_IF_USED:
  259. case cmPolicies::NEW:
  260. break;
  261. }
  262. }
  263. }
  264. if (shouldContinue) {
  265. continue;
  266. }
  267. }
  268. if (inBinary) {
  269. /* clang-format off */
  270. e << "Target \"" << target->GetName() << "\" " << prop <<
  271. " property contains path:\n"
  272. " \"" << li << "\"\nwhich is prefixed in the build directory.";
  273. /* clang-format on */
  274. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  275. }
  276. if (!inSourceBuild) {
  277. if (inSource) {
  278. e << "Target \"" << target->GetName() << "\" " << prop
  279. << " property contains path:\n"
  280. " \""
  281. << li << "\"\nwhich is prefixed in the source directory.";
  282. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  283. }
  284. }
  285. }
  286. return !hadFatalError;
  287. }
  288. static void prefixItems(std::string& exportDirs)
  289. {
  290. std::vector<std::string> entries;
  291. cmGeneratorExpression::Split(exportDirs, entries);
  292. exportDirs.clear();
  293. const char* sep = "";
  294. for (std::string const& e : entries) {
  295. exportDirs += sep;
  296. sep = ";";
  297. if (!cmSystemTools::FileIsFullPath(e) &&
  298. e.find("${_IMPORT_PREFIX}") == std::string::npos) {
  299. exportDirs += "${_IMPORT_PREFIX}/";
  300. }
  301. exportDirs += e;
  302. }
  303. }
  304. void cmExportFileGenerator::PopulateSourcesInterface(
  305. cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
  306. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  307. {
  308. cmGeneratorTarget* gt = tei->Target;
  309. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  310. const char* propName = "INTERFACE_SOURCES";
  311. const char* input = gt->GetProperty(propName);
  312. if (!input) {
  313. return;
  314. }
  315. if (!*input) {
  316. properties[propName].clear();
  317. return;
  318. }
  319. std::string prepro =
  320. cmGeneratorExpression::Preprocess(input, preprocessRule, true);
  321. if (!prepro.empty()) {
  322. this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
  323. if (!checkInterfaceDirs(prepro, gt, propName)) {
  324. return;
  325. }
  326. properties[propName] = prepro;
  327. }
  328. }
  329. void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
  330. cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
  331. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  332. {
  333. cmGeneratorTarget* target = tei->Target;
  334. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  335. const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
  336. const char* input = target->GetProperty(propName);
  337. cmGeneratorExpression ge;
  338. std::string dirs = cmGeneratorExpression::Preprocess(
  339. tei->InterfaceIncludeDirectories, preprocessRule, true);
  340. this->ReplaceInstallPrefix(dirs);
  341. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
  342. std::string exportDirs =
  343. cge->Evaluate(target->GetLocalGenerator(), "", false, target);
  344. if (cge->GetHadContextSensitiveCondition()) {
  345. cmLocalGenerator* lg = target->GetLocalGenerator();
  346. std::ostringstream e;
  347. e << "Target \"" << target->GetName()
  348. << "\" is installed with "
  349. "INCLUDES DESTINATION set to a context sensitive path. Paths which "
  350. "depend on the configuration, policy values or the link interface "
  351. "are "
  352. "not supported. Consider using target_include_directories instead.";
  353. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  354. return;
  355. }
  356. if (!input && exportDirs.empty()) {
  357. return;
  358. }
  359. if ((input && !*input) && exportDirs.empty()) {
  360. // Set to empty
  361. properties[propName].clear();
  362. return;
  363. }
  364. prefixItems(exportDirs);
  365. std::string includes = (input ? input : "");
  366. const char* sep = input ? ";" : "";
  367. includes += sep + exportDirs;
  368. std::string prepro =
  369. cmGeneratorExpression::Preprocess(includes, preprocessRule, true);
  370. if (!prepro.empty()) {
  371. this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets);
  372. if (!checkInterfaceDirs(prepro, target, propName)) {
  373. return;
  374. }
  375. properties[propName] = prepro;
  376. }
  377. }
  378. void cmExportFileGenerator::PopulateInterfaceProperty(
  379. const std::string& propName, cmGeneratorTarget* target,
  380. cmGeneratorExpression::PreprocessContext preprocessRule,
  381. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  382. {
  383. this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
  384. properties, missingTargets);
  385. }
  386. void getPropertyContents(cmGeneratorTarget const* tgt, const std::string& prop,
  387. std::set<std::string>& ifaceProperties)
  388. {
  389. const char* p = tgt->GetProperty(prop);
  390. if (!p) {
  391. return;
  392. }
  393. std::vector<std::string> content;
  394. cmSystemTools::ExpandListArgument(p, content);
  395. ifaceProperties.insert(content.begin(), content.end());
  396. }
  397. void getCompatibleInterfaceProperties(cmGeneratorTarget* target,
  398. std::set<std::string>& ifaceProperties,
  399. const std::string& config)
  400. {
  401. if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  402. // object libraries have no link information, so nothing to compute
  403. return;
  404. }
  405. cmComputeLinkInformation* info = target->GetLinkInformation(config);
  406. if (!info) {
  407. cmLocalGenerator* lg = target->GetLocalGenerator();
  408. std::ostringstream e;
  409. e << "Exporting the target \"" << target->GetName()
  410. << "\" is not "
  411. "allowed since its linker language cannot be determined";
  412. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  413. return;
  414. }
  415. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  416. for (auto const& dep : deps) {
  417. if (!dep.Target) {
  418. continue;
  419. }
  420. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_BOOL",
  421. ifaceProperties);
  422. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_STRING",
  423. ifaceProperties);
  424. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  425. ifaceProperties);
  426. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  427. ifaceProperties);
  428. }
  429. }
  430. void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
  431. cmGeneratorTarget* gtarget, ImportPropertyMap& properties)
  432. {
  433. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL", gtarget,
  434. properties);
  435. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING", gtarget,
  436. properties);
  437. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN", gtarget,
  438. properties);
  439. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX", gtarget,
  440. properties);
  441. std::set<std::string> ifaceProperties;
  442. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
  443. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
  444. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  445. ifaceProperties);
  446. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  447. ifaceProperties);
  448. if (gtarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  449. getCompatibleInterfaceProperties(gtarget, ifaceProperties, "");
  450. std::vector<std::string> configNames;
  451. gtarget->Target->GetMakefile()->GetConfigurations(configNames);
  452. for (std::string const& cn : configNames) {
  453. getCompatibleInterfaceProperties(gtarget, ifaceProperties, cn);
  454. }
  455. }
  456. for (std::string const& ip : ifaceProperties) {
  457. this->PopulateInterfaceProperty("INTERFACE_" + ip, gtarget, properties);
  458. }
  459. }
  460. void cmExportFileGenerator::GenerateInterfaceProperties(
  461. const cmGeneratorTarget* target, std::ostream& os,
  462. const ImportPropertyMap& properties)
  463. {
  464. if (!properties.empty()) {
  465. std::string targetName = this->Namespace;
  466. targetName += target->GetExportName();
  467. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  468. for (auto const& property : properties) {
  469. os << " " << property.first << " "
  470. << cmExportFileGeneratorEscape(property.second) << "\n";
  471. }
  472. os << ")\n\n";
  473. }
  474. }
  475. bool cmExportFileGenerator::AddTargetNamespace(
  476. std::string& input, cmGeneratorTarget* target,
  477. std::vector<std::string>& missingTargets)
  478. {
  479. cmLocalGenerator* lg = target->GetLocalGenerator();
  480. cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(input);
  481. if (!tgt) {
  482. return false;
  483. }
  484. if (tgt->IsImported()) {
  485. return true;
  486. }
  487. if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) {
  488. input = this->Namespace + tgt->GetExportName();
  489. } else {
  490. std::string namespacedTarget;
  491. this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt);
  492. if (!namespacedTarget.empty()) {
  493. input = namespacedTarget;
  494. }
  495. }
  496. return true;
  497. }
  498. void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
  499. std::string& input, cmGeneratorTarget* target,
  500. std::vector<std::string>& missingTargets, FreeTargetsReplace replace)
  501. {
  502. if (replace == NoReplaceFreeTargets) {
  503. this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
  504. return;
  505. }
  506. std::vector<std::string> parts;
  507. cmGeneratorExpression::Split(input, parts);
  508. std::string sep;
  509. input.clear();
  510. for (std::string& li : parts) {
  511. if (cmGeneratorExpression::Find(li) == std::string::npos) {
  512. this->AddTargetNamespace(li, target, missingTargets);
  513. } else {
  514. this->ResolveTargetsInGeneratorExpression(li, target, missingTargets);
  515. }
  516. input += sep + li;
  517. sep = ";";
  518. }
  519. }
  520. void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
  521. std::string& input, cmGeneratorTarget* target,
  522. std::vector<std::string>& missingTargets)
  523. {
  524. std::string::size_type pos = 0;
  525. std::string::size_type lastPos = pos;
  526. while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) !=
  527. std::string::npos) {
  528. std::string::size_type nameStartPos =
  529. pos + sizeof("$<TARGET_PROPERTY:") - 1;
  530. std::string::size_type closePos = input.find('>', nameStartPos);
  531. std::string::size_type commaPos = input.find(',', nameStartPos);
  532. std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
  533. if (commaPos == std::string::npos // Implied 'this' target
  534. || closePos == std::string::npos // Incomplete expression.
  535. || closePos < commaPos // Implied 'this' target
  536. || nextOpenPos < commaPos) // Non-literal
  537. {
  538. lastPos = nameStartPos;
  539. continue;
  540. }
  541. std::string targetName =
  542. input.substr(nameStartPos, commaPos - nameStartPos);
  543. if (this->AddTargetNamespace(targetName, target, missingTargets)) {
  544. input.replace(nameStartPos, commaPos - nameStartPos, targetName);
  545. }
  546. lastPos = nameStartPos + targetName.size() + 1;
  547. }
  548. std::string errorString;
  549. pos = 0;
  550. lastPos = pos;
  551. while ((pos = input.find("$<TARGET_NAME:", lastPos)) != std::string::npos) {
  552. std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
  553. std::string::size_type endPos = input.find('>', nameStartPos);
  554. if (endPos == std::string::npos) {
  555. errorString = "$<TARGET_NAME:...> expression incomplete";
  556. break;
  557. }
  558. std::string targetName = input.substr(nameStartPos, endPos - nameStartPos);
  559. if (targetName.find("$<") != std::string::npos) {
  560. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  561. "literal.";
  562. break;
  563. }
  564. if (!this->AddTargetNamespace(targetName, target, missingTargets)) {
  565. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  566. "reachable target.";
  567. break;
  568. }
  569. input.replace(pos, endPos - pos + 1, targetName);
  570. lastPos = endPos;
  571. }
  572. pos = 0;
  573. lastPos = pos;
  574. while (errorString.empty() &&
  575. (pos = input.find("$<LINK_ONLY:", lastPos)) != std::string::npos) {
  576. std::string::size_type nameStartPos = pos + sizeof("$<LINK_ONLY:") - 1;
  577. std::string::size_type endPos = input.find('>', nameStartPos);
  578. if (endPos == std::string::npos) {
  579. errorString = "$<LINK_ONLY:...> expression incomplete";
  580. break;
  581. }
  582. std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
  583. if (cmGeneratorExpression::IsValidTargetName(libName) &&
  584. this->AddTargetNamespace(libName, target, missingTargets)) {
  585. input.replace(nameStartPos, endPos - nameStartPos, libName);
  586. }
  587. lastPos = nameStartPos + libName.size() + 1;
  588. }
  589. this->ReplaceInstallPrefix(input);
  590. if (!errorString.empty()) {
  591. target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString);
  592. }
  593. }
  594. void cmExportFileGenerator::ReplaceInstallPrefix(std::string& /*unused*/)
  595. {
  596. // Do nothing
  597. }
  598. void cmExportFileGenerator::SetImportLinkInterface(
  599. const std::string& config, std::string const& suffix,
  600. cmGeneratorExpression::PreprocessContext preprocessRule,
  601. cmGeneratorTarget* target, ImportPropertyMap& properties,
  602. std::vector<std::string>& missingTargets)
  603. {
  604. // Add the transitive link dependencies for this configuration.
  605. cmLinkInterface const* iface = target->GetLinkInterface(config, target);
  606. if (!iface) {
  607. return;
  608. }
  609. if (iface->ImplementationIsInterface) {
  610. // Policy CMP0022 must not be NEW.
  611. this->SetImportLinkProperty(suffix, target,
  612. "IMPORTED_LINK_INTERFACE_LIBRARIES",
  613. iface->Libraries, properties, missingTargets);
  614. return;
  615. }
  616. const char* propContent;
  617. if (const char* prop_suffixed =
  618. target->GetProperty("LINK_INTERFACE_LIBRARIES" + suffix)) {
  619. propContent = prop_suffixed;
  620. } else if (const char* prop =
  621. target->GetProperty("LINK_INTERFACE_LIBRARIES")) {
  622. propContent = prop;
  623. } else {
  624. return;
  625. }
  626. const bool newCMP0022Behavior =
  627. target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  628. target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  629. if (newCMP0022Behavior && !this->ExportOld) {
  630. cmLocalGenerator* lg = target->GetLocalGenerator();
  631. std::ostringstream e;
  632. e << "Target \"" << target->GetName()
  633. << "\" has policy CMP0022 enabled, "
  634. "but also has old-style LINK_INTERFACE_LIBRARIES properties "
  635. "populated, but it was exported without the "
  636. "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
  637. lg->IssueMessage(cmake::FATAL_ERROR, e.str());
  638. return;
  639. }
  640. if (!*propContent) {
  641. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear();
  642. return;
  643. }
  644. std::string prepro =
  645. cmGeneratorExpression::Preprocess(propContent, preprocessRule);
  646. if (!prepro.empty()) {
  647. this->ResolveTargetsInGeneratorExpressions(prepro, target, missingTargets,
  648. ReplaceFreeTargets);
  649. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
  650. }
  651. }
  652. void cmExportFileGenerator::SetImportDetailProperties(
  653. const std::string& config, std::string const& suffix,
  654. cmGeneratorTarget* target, ImportPropertyMap& properties,
  655. std::vector<std::string>& missingTargets)
  656. {
  657. // Get the makefile in which to lookup target information.
  658. cmMakefile* mf = target->Makefile;
  659. // Add the soname for unix shared libraries.
  660. if (target->GetType() == cmStateEnums::SHARED_LIBRARY ||
  661. target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  662. if (!target->IsDLLPlatform()) {
  663. std::string prop;
  664. std::string value;
  665. if (target->HasSOName(config)) {
  666. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  667. value = this->InstallNameDir(target, config);
  668. }
  669. prop = "IMPORTED_SONAME";
  670. value += target->GetSOName(config);
  671. } else {
  672. prop = "IMPORTED_NO_SONAME";
  673. value = "TRUE";
  674. }
  675. prop += suffix;
  676. properties[prop] = value;
  677. }
  678. }
  679. // Add the transitive link dependencies for this configuration.
  680. if (cmLinkInterface const* iface =
  681. target->GetLinkInterface(config, target)) {
  682. this->SetImportLinkProperty(suffix, target,
  683. "IMPORTED_LINK_INTERFACE_LANGUAGES",
  684. iface->Languages, properties, missingTargets);
  685. std::vector<std::string> dummy;
  686. this->SetImportLinkProperty(suffix, target,
  687. "IMPORTED_LINK_DEPENDENT_LIBRARIES",
  688. iface->SharedDeps, properties, dummy);
  689. if (iface->Multiplicity > 0) {
  690. std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  691. prop += suffix;
  692. std::ostringstream m;
  693. m << iface->Multiplicity;
  694. properties[prop] = m.str();
  695. }
  696. }
  697. // Add information if this target is a managed target
  698. if (target->GetManagedType(config) !=
  699. cmGeneratorTarget::ManagedType::Native) {
  700. std::string prop = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  701. prop += suffix;
  702. std::string propval;
  703. if (auto* p = target->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  704. propval = p;
  705. } else if (target->HasLanguage("CSharp", config)) {
  706. // C# projects do not have the /clr flag, so we set the property
  707. // here to mark the target as (only) managed (i.e. no .lib file
  708. // to link to). Otherwise the COMMON_LANGUAGE_RUNTIME target
  709. // property would have to be set manually for C# targets to make
  710. // exporting/importing work.
  711. propval = "CSharp";
  712. }
  713. properties[prop] = propval;
  714. }
  715. }
  716. template <typename T>
  717. void cmExportFileGenerator::SetImportLinkProperty(
  718. std::string const& suffix, cmGeneratorTarget* target,
  719. const std::string& propName, std::vector<T> const& entries,
  720. ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
  721. {
  722. // Skip the property if there are no entries.
  723. if (entries.empty()) {
  724. return;
  725. }
  726. // Construct the property value.
  727. std::string link_entries;
  728. const char* sep = "";
  729. for (T const& l : entries) {
  730. // Separate this from the previous entry.
  731. link_entries += sep;
  732. sep = ";";
  733. std::string temp = l;
  734. this->AddTargetNamespace(temp, target, missingTargets);
  735. link_entries += temp;
  736. }
  737. // Store the property.
  738. std::string prop = propName;
  739. prop += suffix;
  740. properties[prop] = link_entries;
  741. }
  742. void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
  743. {
  744. // Protect that file against use with older CMake versions.
  745. /* clang-format off */
  746. os << "# Generated by CMake\n\n";
  747. os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
  748. << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
  749. << "endif()\n";
  750. /* clang-format on */
  751. // Isolate the file policy level.
  752. // We use 2.6 here instead of the current version because newer
  753. // versions of CMake should be able to export files imported by 2.6
  754. // until the import format changes.
  755. /* clang-format off */
  756. os << "cmake_policy(PUSH)\n"
  757. << "cmake_policy(VERSION 2.6)\n";
  758. /* clang-format on */
  759. }
  760. void cmExportFileGenerator::GeneratePolicyFooterCode(std::ostream& os)
  761. {
  762. os << "cmake_policy(POP)\n";
  763. }
  764. void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
  765. const std::string& config)
  766. {
  767. os << "#----------------------------------------------------------------\n"
  768. << "# Generated CMake target import file";
  769. if (!config.empty()) {
  770. os << " for configuration \"" << config << "\".\n";
  771. } else {
  772. os << ".\n";
  773. }
  774. os << "#----------------------------------------------------------------\n"
  775. << "\n";
  776. this->GenerateImportVersionCode(os);
  777. }
  778. void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
  779. {
  780. os << "# Commands beyond this point should not need to know the version.\n"
  781. << "set(CMAKE_IMPORT_FILE_VERSION)\n";
  782. }
  783. void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
  784. {
  785. // Store an import file format version. This will let us change the
  786. // format later while still allowing old import files to work.
  787. /* clang-format off */
  788. os << "# Commands may need to know the format version.\n"
  789. << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
  790. << "\n";
  791. /* clang-format on */
  792. }
  793. void cmExportFileGenerator::GenerateExpectedTargetsCode(
  794. std::ostream& os, const std::string& expectedTargets)
  795. {
  796. /* clang-format off */
  797. os << "# Protect against multiple inclusion, which would fail when already "
  798. "imported targets are added once more.\n"
  799. "set(_targetsDefined)\n"
  800. "set(_targetsNotDefined)\n"
  801. "set(_expectedTargets)\n"
  802. "foreach(_expectedTarget " << expectedTargets << ")\n"
  803. " list(APPEND _expectedTargets ${_expectedTarget})\n"
  804. " if(NOT TARGET ${_expectedTarget})\n"
  805. " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
  806. " endif()\n"
  807. " if(TARGET ${_expectedTarget})\n"
  808. " list(APPEND _targetsDefined ${_expectedTarget})\n"
  809. " endif()\n"
  810. "endforeach()\n"
  811. "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
  812. " unset(_targetsDefined)\n"
  813. " unset(_targetsNotDefined)\n"
  814. " unset(_expectedTargets)\n"
  815. " set(CMAKE_IMPORT_FILE_VERSION)\n"
  816. " cmake_policy(POP)\n"
  817. " return()\n"
  818. "endif()\n"
  819. "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
  820. " message(FATAL_ERROR \"Some (but not all) targets in this export "
  821. "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
  822. "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
  823. "endif()\n"
  824. "unset(_targetsDefined)\n"
  825. "unset(_targetsNotDefined)\n"
  826. "unset(_expectedTargets)\n"
  827. "\n\n";
  828. /* clang-format on */
  829. }
  830. void cmExportFileGenerator::GenerateImportTargetCode(
  831. std::ostream& os, cmGeneratorTarget const* target,
  832. cmStateEnums::TargetType targetType)
  833. {
  834. // Construct the imported target name.
  835. std::string targetName = this->Namespace;
  836. targetName += target->GetExportName();
  837. // Create the imported target.
  838. os << "# Create imported target " << targetName << "\n";
  839. switch (targetType) {
  840. case cmStateEnums::EXECUTABLE:
  841. os << "add_executable(" << targetName << " IMPORTED)\n";
  842. break;
  843. case cmStateEnums::STATIC_LIBRARY:
  844. os << "add_library(" << targetName << " STATIC IMPORTED)\n";
  845. break;
  846. case cmStateEnums::SHARED_LIBRARY:
  847. os << "add_library(" << targetName << " SHARED IMPORTED)\n";
  848. break;
  849. case cmStateEnums::MODULE_LIBRARY:
  850. os << "add_library(" << targetName << " MODULE IMPORTED)\n";
  851. break;
  852. case cmStateEnums::UNKNOWN_LIBRARY:
  853. os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
  854. break;
  855. case cmStateEnums::OBJECT_LIBRARY:
  856. os << "add_library(" << targetName << " OBJECT IMPORTED)\n";
  857. break;
  858. case cmStateEnums::INTERFACE_LIBRARY:
  859. os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
  860. break;
  861. default: // should never happen
  862. break;
  863. }
  864. // Mark the imported executable if it has exports.
  865. if (target->IsExecutableWithExports()) {
  866. os << "set_property(TARGET " << targetName
  867. << " PROPERTY ENABLE_EXPORTS 1)\n";
  868. }
  869. // Mark the imported library if it is a framework.
  870. if (target->IsFrameworkOnApple()) {
  871. os << "set_property(TARGET " << targetName << " PROPERTY FRAMEWORK 1)\n";
  872. }
  873. // Mark the imported executable if it is an application bundle.
  874. if (target->IsAppBundleOnApple()) {
  875. os << "set_property(TARGET " << targetName
  876. << " PROPERTY MACOSX_BUNDLE 1)\n";
  877. }
  878. if (target->IsCFBundleOnApple()) {
  879. os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n";
  880. }
  881. os << "\n";
  882. }
  883. void cmExportFileGenerator::GenerateImportPropertyCode(
  884. std::ostream& os, const std::string& config, cmGeneratorTarget const* target,
  885. ImportPropertyMap const& properties)
  886. {
  887. // Construct the imported target name.
  888. std::string targetName = this->Namespace;
  889. targetName += target->GetExportName();
  890. // Set the import properties.
  891. os << "# Import target \"" << targetName << "\" for configuration \""
  892. << config << "\"\n";
  893. os << "set_property(TARGET " << targetName
  894. << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
  895. if (!config.empty()) {
  896. os << cmSystemTools::UpperCase(config);
  897. } else {
  898. os << "NOCONFIG";
  899. }
  900. os << ")\n";
  901. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  902. for (auto const& property : properties) {
  903. os << " " << property.first << " "
  904. << cmExportFileGeneratorEscape(property.second) << "\n";
  905. }
  906. os << " )\n"
  907. << "\n";
  908. }
  909. void cmExportFileGenerator::GenerateMissingTargetsCheckCode(
  910. std::ostream& os, const std::vector<std::string>& missingTargets)
  911. {
  912. if (missingTargets.empty()) {
  913. /* clang-format off */
  914. os << "# This file does not depend on other imported targets which have\n"
  915. "# been exported from the same project but in a separate "
  916. "export set.\n\n";
  917. /* clang-format on */
  918. return;
  919. }
  920. /* clang-format off */
  921. os << "# Make sure the targets which have been exported in some other \n"
  922. "# export set exist.\n"
  923. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  924. "foreach(_target ";
  925. /* clang-format on */
  926. std::set<std::string> emitted;
  927. for (std::string const& missingTarget : missingTargets) {
  928. if (emitted.insert(missingTarget).second) {
  929. os << "\"" << missingTarget << "\" ";
  930. }
  931. }
  932. /* clang-format off */
  933. os << ")\n"
  934. " if(NOT TARGET \"${_target}\" )\n"
  935. " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
  936. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
  937. "\n"
  938. " endif()\n"
  939. "endforeach()\n"
  940. "\n"
  941. "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  942. " if(CMAKE_FIND_PACKAGE_NAME)\n"
  943. " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
  944. " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
  945. "\"The following imported targets are "
  946. "referenced, but are missing: "
  947. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  948. " else()\n"
  949. " message(FATAL_ERROR \"The following imported targets are "
  950. "referenced, but are missing: "
  951. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  952. " endif()\n"
  953. "endif()\n"
  954. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  955. "\n";
  956. /* clang-format on */
  957. }
  958. void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
  959. {
  960. // Add code which verifies at cmake time that the file which is being
  961. // imported actually exists on disk. This should in theory always be theory
  962. // case, but still when packages are split into normal and development
  963. // packages this might get broken (e.g. the Config.cmake could be part of
  964. // the non-development package, something similar happened to me without
  965. // on SUSE with a mysql pkg-config file, which claimed everything is fine,
  966. // but the development package was not installed.).
  967. /* clang-format off */
  968. os << "# Loop over all imported files and verify that they actually exist\n"
  969. "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
  970. " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
  971. " if(NOT EXISTS \"${file}\" )\n"
  972. " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
  973. " references the file\n"
  974. " \\\"${file}\\\"\n"
  975. "but this file does not exist. Possible reasons include:\n"
  976. "* The file was deleted, renamed, or moved to another location.\n"
  977. "* An install or uninstall procedure did not complete successfully.\n"
  978. "* The installation package was faulty and contained\n"
  979. " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
  980. "but not all the files it references.\n"
  981. "\")\n"
  982. " endif()\n"
  983. " endforeach()\n"
  984. " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
  985. "endforeach()\n"
  986. "unset(_IMPORT_CHECK_TARGETS)\n"
  987. "\n";
  988. /* clang-format on */
  989. }
  990. void cmExportFileGenerator::GenerateImportedFileChecksCode(
  991. std::ostream& os, cmGeneratorTarget* target,
  992. ImportPropertyMap const& properties,
  993. const std::set<std::string>& importedLocations)
  994. {
  995. // Construct the imported target name.
  996. std::string targetName = this->Namespace;
  997. targetName += target->GetExportName();
  998. os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName
  999. << " )\n"
  1000. "list(APPEND _IMPORT_CHECK_FILES_FOR_"
  1001. << targetName << " ";
  1002. for (std::string const& li : importedLocations) {
  1003. ImportPropertyMap::const_iterator pi = properties.find(li);
  1004. if (pi != properties.end()) {
  1005. os << cmExportFileGeneratorEscape(pi->second) << " ";
  1006. }
  1007. }
  1008. os << ")\n\n";
  1009. }
  1010. bool cmExportFileGenerator::PopulateExportProperties(
  1011. cmGeneratorTarget* gte, ImportPropertyMap& properties,
  1012. std::string& errorMessage)
  1013. {
  1014. auto& targetProperties = gte->Target->GetProperties();
  1015. const auto& exportProperties = targetProperties.find("EXPORT_PROPERTIES");
  1016. if (exportProperties != targetProperties.end()) {
  1017. std::vector<std::string> propsToExport;
  1018. cmSystemTools::ExpandListArgument(exportProperties->second.GetValue(),
  1019. propsToExport);
  1020. for (auto& prop : propsToExport) {
  1021. /* Black list reserved properties */
  1022. if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") ||
  1023. cmSystemTools::StringStartsWith(prop, "INTERFACE_")) {
  1024. std::ostringstream e;
  1025. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1026. << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* "
  1027. << "properties are reserved.";
  1028. errorMessage = e.str();
  1029. return false;
  1030. }
  1031. auto propertyValue = targetProperties.GetPropertyValue(prop);
  1032. std::string evaluatedValue = cmGeneratorExpression::Preprocess(
  1033. propertyValue, cmGeneratorExpression::StripAllGeneratorExpressions);
  1034. if (evaluatedValue != propertyValue) {
  1035. std::ostringstream e;
  1036. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1037. << prop << "\" in EXPORT_PROPERTIES but this property contains a "
  1038. << "generator expression. This is not allowed.";
  1039. errorMessage = e.str();
  1040. return false;
  1041. }
  1042. properties[prop] = propertyValue;
  1043. }
  1044. }
  1045. return true;
  1046. }