cmExportFileGenerator.cxx 42 KB

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