cmExportFileGenerator.cxx 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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 <algorithm>
  5. #include <array>
  6. #include <cassert>
  7. #include <cstring>
  8. #include <sstream>
  9. #include <utility>
  10. #include <cm/memory>
  11. #include <cm/optional>
  12. #include <cm/string_view>
  13. #include <cmext/string_view>
  14. #include "cmsys/FStream.hxx"
  15. #include "cmComputeLinkInformation.h"
  16. #include "cmExportSet.h"
  17. #include "cmFileSet.h"
  18. #include "cmFindPackageStack.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmGeneratorTarget.h"
  21. #include "cmLinkItem.h"
  22. #include "cmList.h"
  23. #include "cmLocalGenerator.h"
  24. #include "cmMakefile.h"
  25. #include "cmMessageType.h"
  26. #include "cmOutputConverter.h"
  27. #include "cmPolicies.h"
  28. #include "cmPropertyMap.h"
  29. #include "cmStateTypes.h"
  30. #include "cmStringAlgorithms.h"
  31. #include "cmSystemTools.h"
  32. #include "cmTarget.h"
  33. #include "cmValue.h"
  34. #include "cmVersion.h"
  35. static std::string cmExportFileGeneratorEscape(std::string const& str)
  36. {
  37. // Escape a property value for writing into a .cmake file.
  38. std::string result = cmOutputConverter::EscapeForCMake(str);
  39. // Un-escape variable references generated by our own export code.
  40. cmSystemTools::ReplaceString(result, "\\${_IMPORT_PREFIX}",
  41. "${_IMPORT_PREFIX}");
  42. cmSystemTools::ReplaceString(result, "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}",
  43. "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
  44. return result;
  45. }
  46. cmExportFileGenerator::cmExportFileGenerator()
  47. {
  48. this->AppendMode = false;
  49. this->ExportOld = false;
  50. }
  51. void cmExportFileGenerator::AddConfiguration(const std::string& config)
  52. {
  53. this->Configurations.push_back(config);
  54. }
  55. void cmExportFileGenerator::SetExportFile(const char* mainFile)
  56. {
  57. this->MainImportFile = mainFile;
  58. this->FileDir = cmSystemTools::GetFilenamePath(this->MainImportFile);
  59. this->FileBase =
  60. cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
  61. this->FileExt =
  62. cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
  63. }
  64. const std::string& cmExportFileGenerator::GetMainExportFileName() const
  65. {
  66. return this->MainImportFile;
  67. }
  68. bool cmExportFileGenerator::GenerateImportFile()
  69. {
  70. // Open the output file to generate it.
  71. std::unique_ptr<cmsys::ofstream> foutPtr;
  72. if (this->AppendMode) {
  73. // Open for append.
  74. auto openmodeApp = std::ios::app;
  75. foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(),
  76. openmodeApp);
  77. } else {
  78. // Generate atomically and with copy-if-different.
  79. std::unique_ptr<cmGeneratedFileStream> ap(
  80. new cmGeneratedFileStream(this->MainImportFile, true));
  81. ap->SetCopyIfDifferent(true);
  82. foutPtr = std::move(ap);
  83. }
  84. if (!foutPtr || !*foutPtr) {
  85. std::string se = cmSystemTools::GetLastSystemError();
  86. std::ostringstream e;
  87. e << "cannot write to file \"" << this->MainImportFile << "\": " << se;
  88. cmSystemTools::Error(e.str());
  89. return false;
  90. }
  91. std::ostream& os = *foutPtr;
  92. std::stringstream mainFileWithHeadersAndFootersBuffer;
  93. // Start with the import file header.
  94. this->GenerateImportHeaderCode(mainFileWithHeadersAndFootersBuffer);
  95. // Create all the imported targets.
  96. std::stringstream mainFileBuffer;
  97. bool result = this->GenerateMainFile(mainFileBuffer);
  98. // Export find_dependency() calls. Must be done after GenerateMainFile(),
  99. // because that's when target dependencies are gathered, which we need for
  100. // the find_dependency() calls.
  101. if (!this->AppendMode && this->GetExportSet() &&
  102. this->ExportPackageDependencies) {
  103. this->SetRequiredCMakeVersion(3, 9, 0);
  104. this->GenerateFindDependencyCalls(mainFileWithHeadersAndFootersBuffer);
  105. }
  106. // Write cached import code.
  107. mainFileWithHeadersAndFootersBuffer << mainFileBuffer.rdbuf();
  108. // End with the import file footer.
  109. this->GenerateImportFooterCode(mainFileWithHeadersAndFootersBuffer);
  110. this->GeneratePolicyFooterCode(mainFileWithHeadersAndFootersBuffer);
  111. // This has to be done last, after the minimum CMake version has been
  112. // determined.
  113. this->GeneratePolicyHeaderCode(os);
  114. os << mainFileWithHeadersAndFootersBuffer.rdbuf();
  115. return result;
  116. }
  117. void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
  118. const std::string& config)
  119. {
  120. // Construct the property configuration suffix.
  121. std::string suffix = "_";
  122. if (!config.empty()) {
  123. suffix += cmSystemTools::UpperCase(config);
  124. } else {
  125. suffix += "NOCONFIG";
  126. }
  127. // Generate the per-config target information.
  128. this->GenerateImportTargetsConfig(os, config, suffix);
  129. }
  130. void cmExportFileGenerator::PopulateInterfaceProperty(
  131. const std::string& propName, cmGeneratorTarget const* target,
  132. ImportPropertyMap& properties)
  133. {
  134. cmValue input = target->GetProperty(propName);
  135. if (input) {
  136. properties[propName] = *input;
  137. }
  138. }
  139. void cmExportFileGenerator::PopulateInterfaceProperty(
  140. const std::string& propName, const std::string& outputName,
  141. cmGeneratorTarget const* target,
  142. cmGeneratorExpression::PreprocessContext preprocessRule,
  143. ImportPropertyMap& properties)
  144. {
  145. cmValue input = target->GetProperty(propName);
  146. if (input) {
  147. if (input->empty()) {
  148. // Set to empty
  149. properties[outputName].clear();
  150. return;
  151. }
  152. std::string prepro =
  153. cmGeneratorExpression::Preprocess(*input, preprocessRule);
  154. if (!prepro.empty()) {
  155. this->ResolveTargetsInGeneratorExpressions(prepro, target);
  156. properties[outputName] = prepro;
  157. }
  158. }
  159. }
  160. bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
  161. cmGeneratorTarget const* target,
  162. cmGeneratorExpression::PreprocessContext preprocessRule,
  163. ImportPropertyMap& properties)
  164. {
  165. if (!target->IsLinkable()) {
  166. return false;
  167. }
  168. static const std::array<std::string, 3> linkIfaceProps = {
  169. { "INTERFACE_LINK_LIBRARIES", "INTERFACE_LINK_LIBRARIES_DIRECT",
  170. "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE" }
  171. };
  172. bool hadINTERFACE_LINK_LIBRARIES = false;
  173. for (std::string const& linkIfaceProp : linkIfaceProps) {
  174. if (cmValue input = target->GetProperty(linkIfaceProp)) {
  175. std::string prepro =
  176. cmGeneratorExpression::Preprocess(*input, preprocessRule);
  177. if (!prepro.empty()) {
  178. this->ResolveTargetsInGeneratorExpressions(prepro, target,
  179. ReplaceFreeTargets);
  180. properties[linkIfaceProp] = prepro;
  181. hadINTERFACE_LINK_LIBRARIES = true;
  182. }
  183. }
  184. }
  185. return hadINTERFACE_LINK_LIBRARIES;
  186. }
  187. static bool isSubDirectory(std::string const& a, std::string const& b)
  188. {
  189. return (cmSystemTools::ComparePath(a, b) ||
  190. cmSystemTools::IsSubDirectory(a, b));
  191. }
  192. static bool checkInterfaceDirs(const std::string& prepro,
  193. cmGeneratorTarget const* target,
  194. const std::string& prop)
  195. {
  196. std::string const& installDir =
  197. target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  198. std::string const& topSourceDir =
  199. target->GetLocalGenerator()->GetSourceDirectory();
  200. std::string const& topBinaryDir =
  201. target->GetLocalGenerator()->GetBinaryDirectory();
  202. std::vector<std::string> parts;
  203. cmGeneratorExpression::Split(prepro, parts);
  204. const bool inSourceBuild = topSourceDir == topBinaryDir;
  205. bool hadFatalError = false;
  206. for (std::string const& li : parts) {
  207. size_t genexPos = cmGeneratorExpression::Find(li);
  208. if (genexPos == 0) {
  209. continue;
  210. }
  211. if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) {
  212. continue;
  213. }
  214. MessageType messageType = MessageType::FATAL_ERROR;
  215. std::ostringstream e;
  216. if (genexPos != std::string::npos) {
  217. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  218. switch (target->GetPolicyStatusCMP0041()) {
  219. case cmPolicies::WARN:
  220. messageType = MessageType::WARNING;
  221. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
  222. break;
  223. case cmPolicies::OLD:
  224. continue;
  225. case cmPolicies::REQUIRED_IF_USED:
  226. case cmPolicies::REQUIRED_ALWAYS:
  227. case cmPolicies::NEW:
  228. hadFatalError = true;
  229. break; // Issue fatal message.
  230. }
  231. } else {
  232. hadFatalError = true;
  233. }
  234. }
  235. if (!cmSystemTools::FileIsFullPath(li)) {
  236. /* clang-format off */
  237. e << "Target \"" << target->GetName() << "\" " << prop <<
  238. " property contains relative path:\n"
  239. " \"" << li << "\"";
  240. /* clang-format on */
  241. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  242. }
  243. bool inBinary = isSubDirectory(li, topBinaryDir);
  244. bool inSource = isSubDirectory(li, topSourceDir);
  245. if (isSubDirectory(li, installDir)) {
  246. // The include directory is inside the install tree. If the
  247. // install tree is not inside the source tree or build tree then
  248. // fall through to the checks below that the include directory is not
  249. // also inside the source tree or build tree.
  250. bool shouldContinue =
  251. (!inBinary || isSubDirectory(installDir, topBinaryDir)) &&
  252. (!inSource || isSubDirectory(installDir, topSourceDir));
  253. if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
  254. if (!shouldContinue) {
  255. switch (target->GetPolicyStatusCMP0052()) {
  256. case cmPolicies::WARN: {
  257. std::ostringstream s;
  258. s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
  259. s << "Directory:\n \"" << li
  260. << "\"\nin "
  261. "INTERFACE_INCLUDE_DIRECTORIES of target \""
  262. << target->GetName()
  263. << "\" is a subdirectory of the install "
  264. "directory:\n \""
  265. << installDir
  266. << "\"\nhowever it is also "
  267. "a subdirectory of the "
  268. << (inBinary ? "build" : "source") << " tree:\n \""
  269. << (inBinary ? topBinaryDir : topSourceDir) << "\"\n";
  270. target->GetLocalGenerator()->IssueMessage(
  271. MessageType::AUTHOR_WARNING, s.str());
  272. CM_FALLTHROUGH;
  273. }
  274. case cmPolicies::OLD:
  275. shouldContinue = true;
  276. break;
  277. case cmPolicies::REQUIRED_ALWAYS:
  278. case cmPolicies::REQUIRED_IF_USED:
  279. case cmPolicies::NEW:
  280. break;
  281. }
  282. }
  283. }
  284. if (shouldContinue) {
  285. continue;
  286. }
  287. }
  288. if (inBinary) {
  289. /* clang-format off */
  290. e << "Target \"" << target->GetName() << "\" " << prop <<
  291. " property contains path:\n"
  292. " \"" << li << "\"\nwhich is prefixed in the build directory.";
  293. /* clang-format on */
  294. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  295. }
  296. if (!inSourceBuild) {
  297. if (inSource) {
  298. e << "Target \"" << target->GetName() << "\" " << prop
  299. << " property contains path:\n"
  300. " \""
  301. << li << "\"\nwhich is prefixed in the source directory.";
  302. target->GetLocalGenerator()->IssueMessage(messageType, e.str());
  303. }
  304. }
  305. }
  306. return !hadFatalError;
  307. }
  308. static void prefixItems(std::string& exportDirs)
  309. {
  310. std::vector<std::string> entries;
  311. cmGeneratorExpression::Split(exportDirs, entries);
  312. exportDirs.clear();
  313. const char* sep = "";
  314. for (std::string const& e : entries) {
  315. exportDirs += sep;
  316. sep = ";";
  317. if (!cmSystemTools::FileIsFullPath(e) &&
  318. e.find("${_IMPORT_PREFIX}") == std::string::npos) {
  319. exportDirs += "${_IMPORT_PREFIX}/";
  320. }
  321. exportDirs += e;
  322. }
  323. }
  324. void cmExportFileGenerator::PopulateSourcesInterface(
  325. cmGeneratorTarget const* gt,
  326. cmGeneratorExpression::PreprocessContext preprocessRule,
  327. ImportPropertyMap& properties)
  328. {
  329. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  330. const char* propName = "INTERFACE_SOURCES";
  331. cmValue input = gt->GetProperty(propName);
  332. if (!input) {
  333. return;
  334. }
  335. if (input->empty()) {
  336. properties[propName].clear();
  337. return;
  338. }
  339. std::string prepro =
  340. cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
  341. if (!prepro.empty()) {
  342. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  343. if (!checkInterfaceDirs(prepro, gt, propName)) {
  344. return;
  345. }
  346. properties[propName] = prepro;
  347. }
  348. }
  349. void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
  350. cmGeneratorTarget const* target,
  351. cmGeneratorExpression::PreprocessContext preprocessRule,
  352. ImportPropertyMap& properties, cmTargetExport const& te,
  353. std::string& includesDestinationDirs)
  354. {
  355. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  356. includesDestinationDirs.clear();
  357. const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
  358. cmValue input = target->GetProperty(propName);
  359. cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance());
  360. std::string dirs = cmGeneratorExpression::Preprocess(
  361. cmList::to_string(target->Target->GetInstallIncludeDirectoriesEntries(te)),
  362. preprocessRule, true);
  363. this->ReplaceInstallPrefix(dirs);
  364. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
  365. std::string exportDirs =
  366. cge->Evaluate(target->GetLocalGenerator(), "", target);
  367. if (cge->GetHadContextSensitiveCondition()) {
  368. cmLocalGenerator* lg = target->GetLocalGenerator();
  369. std::ostringstream e;
  370. e << "Target \"" << target->GetName()
  371. << "\" is installed with "
  372. "INCLUDES DESTINATION set to a context sensitive path. Paths which "
  373. "depend on the configuration, policy values or the link interface "
  374. "are "
  375. "not supported. Consider using target_include_directories instead.";
  376. lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
  377. return;
  378. }
  379. if (!input && exportDirs.empty()) {
  380. return;
  381. }
  382. if ((input && input->empty()) && exportDirs.empty()) {
  383. // Set to empty
  384. properties[propName].clear();
  385. return;
  386. }
  387. prefixItems(exportDirs);
  388. includesDestinationDirs = exportDirs;
  389. std::string includes = (input ? *input : "");
  390. const char* sep = input ? ";" : "";
  391. includes += sep + exportDirs;
  392. std::string prepro =
  393. cmGeneratorExpression::Preprocess(includes, preprocessRule, true);
  394. if (!prepro.empty()) {
  395. this->ResolveTargetsInGeneratorExpressions(prepro, target);
  396. if (!checkInterfaceDirs(prepro, target, propName)) {
  397. return;
  398. }
  399. properties[propName] = prepro;
  400. }
  401. }
  402. void cmExportFileGenerator::PopulateLinkDependsInterface(
  403. cmGeneratorTarget const* gt,
  404. cmGeneratorExpression::PreprocessContext preprocessRule,
  405. ImportPropertyMap& properties)
  406. {
  407. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  408. const char* propName = "INTERFACE_LINK_DEPENDS";
  409. cmValue input = gt->GetProperty(propName);
  410. if (!input) {
  411. return;
  412. }
  413. if (input->empty()) {
  414. properties[propName].clear();
  415. return;
  416. }
  417. std::string prepro =
  418. cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
  419. if (!prepro.empty()) {
  420. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  421. if (!checkInterfaceDirs(prepro, gt, propName)) {
  422. return;
  423. }
  424. properties[propName] = prepro;
  425. }
  426. }
  427. void cmExportFileGenerator::PopulateLinkDirectoriesInterface(
  428. cmGeneratorTarget const* gt,
  429. cmGeneratorExpression::PreprocessContext preprocessRule,
  430. ImportPropertyMap& properties)
  431. {
  432. assert(preprocessRule == cmGeneratorExpression::InstallInterface);
  433. const char* propName = "INTERFACE_LINK_DIRECTORIES";
  434. cmValue input = gt->GetProperty(propName);
  435. if (!input) {
  436. return;
  437. }
  438. if (input->empty()) {
  439. properties[propName].clear();
  440. return;
  441. }
  442. std::string prepro =
  443. cmGeneratorExpression::Preprocess(*input, preprocessRule, true);
  444. if (!prepro.empty()) {
  445. this->ResolveTargetsInGeneratorExpressions(prepro, gt);
  446. if (!checkInterfaceDirs(prepro, gt, propName)) {
  447. return;
  448. }
  449. properties[propName] = prepro;
  450. }
  451. }
  452. void cmExportFileGenerator::PopulateInterfaceProperty(
  453. const std::string& propName, cmGeneratorTarget const* target,
  454. cmGeneratorExpression::PreprocessContext preprocessRule,
  455. ImportPropertyMap& properties)
  456. {
  457. this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
  458. properties);
  459. }
  460. static void getPropertyContents(cmGeneratorTarget const* tgt,
  461. const std::string& prop,
  462. std::set<std::string>& ifaceProperties)
  463. {
  464. cmValue p = tgt->GetProperty(prop);
  465. if (!p) {
  466. return;
  467. }
  468. cmList content{ *p };
  469. ifaceProperties.insert(content.begin(), content.end());
  470. }
  471. static void getCompatibleInterfaceProperties(
  472. cmGeneratorTarget const* target, std::set<std::string>& ifaceProperties,
  473. const std::string& config)
  474. {
  475. if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  476. // object libraries have no link information, so nothing to compute
  477. return;
  478. }
  479. cmComputeLinkInformation* info = target->GetLinkInformation(config);
  480. if (!info) {
  481. cmLocalGenerator* lg = target->GetLocalGenerator();
  482. std::ostringstream e;
  483. e << "Exporting the target \"" << target->GetName()
  484. << "\" is not "
  485. "allowed since its linker language cannot be determined";
  486. lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
  487. return;
  488. }
  489. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  490. for (auto const& dep : deps) {
  491. if (!dep.Target || dep.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  492. continue;
  493. }
  494. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_BOOL",
  495. ifaceProperties);
  496. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_STRING",
  497. ifaceProperties);
  498. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  499. ifaceProperties);
  500. getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  501. ifaceProperties);
  502. }
  503. }
  504. void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
  505. cmGeneratorTarget const* gtarget, ImportPropertyMap& properties)
  506. {
  507. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL", gtarget,
  508. properties);
  509. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING", gtarget,
  510. properties);
  511. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN", gtarget,
  512. properties);
  513. this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX", gtarget,
  514. properties);
  515. std::set<std::string> ifaceProperties;
  516. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
  517. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
  518. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  519. ifaceProperties);
  520. getPropertyContents(gtarget, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  521. ifaceProperties);
  522. if (gtarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  523. std::vector<std::string> configNames =
  524. gtarget->Target->GetMakefile()->GetGeneratorConfigs(
  525. cmMakefile::IncludeEmptyConfig);
  526. for (std::string const& cn : configNames) {
  527. getCompatibleInterfaceProperties(gtarget, ifaceProperties, cn);
  528. }
  529. }
  530. for (std::string const& ip : ifaceProperties) {
  531. this->PopulateInterfaceProperty("INTERFACE_" + ip, gtarget, properties);
  532. }
  533. }
  534. void cmExportFileGenerator::PopulateCustomTransitiveInterfaceProperties(
  535. cmGeneratorTarget const* target,
  536. cmGeneratorExpression::PreprocessContext preprocessRule,
  537. ImportPropertyMap& properties)
  538. {
  539. this->PopulateInterfaceProperty("TRANSITIVE_COMPILE_PROPERTIES", target,
  540. properties);
  541. this->PopulateInterfaceProperty("TRANSITIVE_LINK_PROPERTIES", target,
  542. properties);
  543. cmGeneratorTarget::CheckLinkLibrariesSuppressionRAII cllSuppressRAII;
  544. std::set<std::string> ifaceProperties;
  545. for (std::string const& config : this->Configurations) {
  546. for (auto const& i : target->GetCustomTransitiveProperties(
  547. config, cmGeneratorTarget::PropertyFor::Interface)) {
  548. ifaceProperties.emplace(i.second.InterfaceName);
  549. }
  550. }
  551. for (std::string const& ip : ifaceProperties) {
  552. this->PopulateInterfaceProperty(ip, target, preprocessRule, properties);
  553. }
  554. }
  555. void cmExportFileGenerator::GenerateInterfaceProperties(
  556. const cmGeneratorTarget* target, std::ostream& os,
  557. const ImportPropertyMap& properties)
  558. {
  559. if (!properties.empty()) {
  560. std::string targetName =
  561. cmStrCat(this->Namespace, target->GetExportName());
  562. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  563. for (auto const& property : properties) {
  564. os << " " << property.first << " "
  565. << cmExportFileGeneratorEscape(property.second) << "\n";
  566. }
  567. os << ")\n\n";
  568. }
  569. }
  570. bool cmExportFileGenerator::AddTargetNamespace(std::string& input,
  571. cmGeneratorTarget const* target,
  572. cmLocalGenerator const* lg)
  573. {
  574. cmGeneratorTarget::TargetOrString resolved =
  575. target->ResolveTargetReference(input, lg);
  576. cmGeneratorTarget* tgt = resolved.Target;
  577. if (!tgt) {
  578. input = resolved.String;
  579. return false;
  580. }
  581. cmFindPackageStack const& pkgStack = tgt->Target->GetFindPackageStack();
  582. if (!pkgStack.Empty() ||
  583. tgt->Target->GetProperty("EXPORT_FIND_PACKAGE_NAME")) {
  584. this->ExternalTargets.emplace(tgt);
  585. }
  586. if (tgt->IsImported()) {
  587. input = tgt->GetName();
  588. return true;
  589. }
  590. if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) {
  591. input = this->Namespace + tgt->GetExportName();
  592. } else {
  593. std::string namespacedTarget;
  594. this->HandleMissingTarget(namespacedTarget, target, tgt);
  595. if (!namespacedTarget.empty()) {
  596. input = namespacedTarget;
  597. } else {
  598. input = tgt->GetName();
  599. }
  600. }
  601. return true;
  602. }
  603. void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
  604. std::string& input, cmGeneratorTarget const* target,
  605. FreeTargetsReplace replace)
  606. {
  607. cmLocalGenerator const* lg = target->GetLocalGenerator();
  608. if (replace == NoReplaceFreeTargets) {
  609. this->ResolveTargetsInGeneratorExpression(input, target, lg);
  610. return;
  611. }
  612. std::vector<std::string> parts;
  613. cmGeneratorExpression::Split(input, parts);
  614. std::string sep;
  615. input.clear();
  616. for (std::string& li : parts) {
  617. if (target->IsLinkLookupScope(li, lg)) {
  618. continue;
  619. }
  620. if (cmGeneratorExpression::Find(li) == std::string::npos) {
  621. this->AddTargetNamespace(li, target, lg);
  622. } else {
  623. this->ResolveTargetsInGeneratorExpression(li, target, lg);
  624. }
  625. input += sep + li;
  626. sep = ";";
  627. }
  628. }
  629. void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
  630. std::string& input, cmGeneratorTarget const* target,
  631. cmLocalGenerator const* lg)
  632. {
  633. std::string::size_type pos = 0;
  634. std::string::size_type lastPos = pos;
  635. while ((pos = input.find("$<TARGET_PROPERTY:", lastPos)) !=
  636. std::string::npos) {
  637. std::string::size_type nameStartPos = pos + cmStrLen("$<TARGET_PROPERTY:");
  638. std::string::size_type closePos = input.find('>', nameStartPos);
  639. std::string::size_type commaPos = input.find(',', nameStartPos);
  640. std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
  641. if (commaPos == std::string::npos // Implied 'this' target
  642. || closePos == std::string::npos // Incomplete expression.
  643. || closePos < commaPos // Implied 'this' target
  644. || nextOpenPos < commaPos) // Non-literal
  645. {
  646. lastPos = nameStartPos;
  647. continue;
  648. }
  649. std::string targetName =
  650. input.substr(nameStartPos, commaPos - nameStartPos);
  651. if (this->AddTargetNamespace(targetName, target, lg)) {
  652. input.replace(nameStartPos, commaPos - nameStartPos, targetName);
  653. }
  654. lastPos = nameStartPos + targetName.size() + 1;
  655. }
  656. std::string errorString;
  657. pos = 0;
  658. lastPos = pos;
  659. while ((pos = input.find("$<TARGET_NAME:", lastPos)) != std::string::npos) {
  660. std::string::size_type nameStartPos = pos + cmStrLen("$<TARGET_NAME:");
  661. std::string::size_type endPos = input.find('>', nameStartPos);
  662. if (endPos == std::string::npos) {
  663. errorString = "$<TARGET_NAME:...> expression incomplete";
  664. break;
  665. }
  666. std::string targetName = input.substr(nameStartPos, endPos - nameStartPos);
  667. if (targetName.find("$<") != std::string::npos) {
  668. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  669. "literal.";
  670. break;
  671. }
  672. if (!this->AddTargetNamespace(targetName, target, lg)) {
  673. errorString = "$<TARGET_NAME:...> requires its parameter to be a "
  674. "reachable target.";
  675. break;
  676. }
  677. input.replace(pos, endPos - pos + 1, targetName);
  678. lastPos = pos + targetName.size();
  679. }
  680. pos = 0;
  681. lastPos = pos;
  682. while (errorString.empty() &&
  683. (pos = input.find("$<LINK_ONLY:", lastPos)) != std::string::npos) {
  684. std::string::size_type nameStartPos = pos + cmStrLen("$<LINK_ONLY:");
  685. std::string::size_type endPos = input.find('>', nameStartPos);
  686. if (endPos == std::string::npos) {
  687. errorString = "$<LINK_ONLY:...> expression incomplete";
  688. break;
  689. }
  690. std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
  691. if (cmGeneratorExpression::IsValidTargetName(libName) &&
  692. this->AddTargetNamespace(libName, target, lg)) {
  693. input.replace(nameStartPos, endPos - nameStartPos, libName);
  694. }
  695. lastPos = nameStartPos + libName.size() + 1;
  696. }
  697. while (errorString.empty() &&
  698. (pos = input.find("$<COMPILE_ONLY:", lastPos)) != std::string::npos) {
  699. std::string::size_type nameStartPos = pos + cmStrLen("$<COMPILE_ONLY:");
  700. std::string::size_type endPos = input.find('>', nameStartPos);
  701. if (endPos == std::string::npos) {
  702. errorString = "$<COMPILE_ONLY:...> expression incomplete";
  703. break;
  704. }
  705. std::string libName = input.substr(nameStartPos, endPos - nameStartPos);
  706. if (cmGeneratorExpression::IsValidTargetName(libName) &&
  707. this->AddTargetNamespace(libName, target, lg)) {
  708. input.replace(nameStartPos, endPos - nameStartPos, libName);
  709. }
  710. lastPos = nameStartPos + libName.size() + 1;
  711. }
  712. this->ReplaceInstallPrefix(input);
  713. if (!errorString.empty()) {
  714. target->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  715. errorString);
  716. }
  717. }
  718. void cmExportFileGenerator::ReplaceInstallPrefix(std::string& /*unused*/)
  719. {
  720. // Do nothing
  721. }
  722. void cmExportFileGenerator::SetImportLinkInterface(
  723. const std::string& config, std::string const& suffix,
  724. cmGeneratorExpression::PreprocessContext preprocessRule,
  725. cmGeneratorTarget const* target, ImportPropertyMap& properties)
  726. {
  727. // Add the transitive link dependencies for this configuration.
  728. cmLinkInterface const* iface = target->GetLinkInterface(config, target);
  729. if (!iface) {
  730. return;
  731. }
  732. if (iface->ImplementationIsInterface) {
  733. // Policy CMP0022 must not be NEW.
  734. this->SetImportLinkProperty(
  735. suffix, target, "IMPORTED_LINK_INTERFACE_LIBRARIES", iface->Libraries,
  736. properties, ImportLinkPropertyTargetNames::Yes);
  737. return;
  738. }
  739. cmValue propContent;
  740. if (cmValue prop_suffixed =
  741. target->GetProperty("LINK_INTERFACE_LIBRARIES" + suffix)) {
  742. propContent = prop_suffixed;
  743. } else if (cmValue prop = target->GetProperty("LINK_INTERFACE_LIBRARIES")) {
  744. propContent = prop;
  745. } else {
  746. return;
  747. }
  748. const bool newCMP0022Behavior =
  749. target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  750. target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  751. if (newCMP0022Behavior && !this->ExportOld) {
  752. cmLocalGenerator* lg = target->GetLocalGenerator();
  753. std::ostringstream e;
  754. e << "Target \"" << target->GetName()
  755. << "\" has policy CMP0022 enabled, "
  756. "but also has old-style LINK_INTERFACE_LIBRARIES properties "
  757. "populated, but it was exported without the "
  758. "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
  759. lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
  760. return;
  761. }
  762. if (propContent->empty()) {
  763. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear();
  764. return;
  765. }
  766. std::string prepro =
  767. cmGeneratorExpression::Preprocess(*propContent, preprocessRule);
  768. if (!prepro.empty()) {
  769. this->ResolveTargetsInGeneratorExpressions(prepro, target,
  770. ReplaceFreeTargets);
  771. properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
  772. }
  773. }
  774. void cmExportFileGenerator::SetImportDetailProperties(
  775. const std::string& config, std::string const& suffix,
  776. cmGeneratorTarget* target, ImportPropertyMap& properties)
  777. {
  778. // Get the makefile in which to lookup target information.
  779. cmMakefile* mf = target->Makefile;
  780. // Add the soname for unix shared libraries.
  781. if (target->GetType() == cmStateEnums::SHARED_LIBRARY ||
  782. target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  783. if (!target->IsDLLPlatform()) {
  784. std::string prop;
  785. std::string value;
  786. if (target->HasSOName(config)) {
  787. if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  788. value = this->InstallNameDir(target, config);
  789. }
  790. prop = "IMPORTED_SONAME";
  791. value += target->GetSOName(config);
  792. } else {
  793. prop = "IMPORTED_NO_SONAME";
  794. value = "TRUE";
  795. }
  796. prop += suffix;
  797. properties[prop] = value;
  798. }
  799. }
  800. // Add the transitive link dependencies for this configuration.
  801. if (cmLinkInterface const* iface =
  802. target->GetLinkInterface(config, target)) {
  803. this->SetImportLinkProperty(
  804. suffix, target, "IMPORTED_LINK_INTERFACE_LANGUAGES", iface->Languages,
  805. properties, ImportLinkPropertyTargetNames::No);
  806. // Export IMPORTED_LINK_DEPENDENT_LIBRARIES to help consuming linkers
  807. // find private dependencies of shared libraries.
  808. std::size_t oldMissingTargetsSize = this->MissingTargets.size();
  809. auto oldExternalTargets = this->ExternalTargets;
  810. this->SetImportLinkProperty(
  811. suffix, target, "IMPORTED_LINK_DEPENDENT_LIBRARIES", iface->SharedDeps,
  812. properties, ImportLinkPropertyTargetNames::Yes);
  813. // Avoid enforcing shared library private dependencies as public package
  814. // dependencies by ignoring missing targets added for them.
  815. this->MissingTargets.resize(oldMissingTargetsSize);
  816. this->ExternalTargets = std::move(oldExternalTargets);
  817. if (iface->Multiplicity > 0) {
  818. std::string prop =
  819. cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix);
  820. properties[prop] = std::to_string(iface->Multiplicity);
  821. }
  822. }
  823. // Add information if this target is a managed target
  824. if (target->GetManagedType(config) !=
  825. cmGeneratorTarget::ManagedType::Native) {
  826. std::string prop = cmStrCat("IMPORTED_COMMON_LANGUAGE_RUNTIME", suffix);
  827. std::string propval;
  828. if (cmValue p = target->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  829. propval = *p;
  830. } else if (target->IsCSharpOnly()) {
  831. // C# projects do not have the /clr flag, so we set the property
  832. // here to mark the target as (only) managed (i.e. no .lib file
  833. // to link to). Otherwise the COMMON_LANGUAGE_RUNTIME target
  834. // property would have to be set manually for C# targets to make
  835. // exporting/importing work.
  836. propval = "CSharp";
  837. }
  838. properties[prop] = propval;
  839. }
  840. }
  841. static std::string const& asString(std::string const& l)
  842. {
  843. return l;
  844. }
  845. static std::string const& asString(cmLinkItem const& l)
  846. {
  847. return l.AsStr();
  848. }
  849. template <typename T>
  850. void cmExportFileGenerator::SetImportLinkProperty(
  851. std::string const& suffix, cmGeneratorTarget const* target,
  852. const std::string& propName, std::vector<T> const& entries,
  853. ImportPropertyMap& properties, ImportLinkPropertyTargetNames targetNames)
  854. {
  855. // Skip the property if there are no entries.
  856. if (entries.empty()) {
  857. return;
  858. }
  859. cmLocalGenerator const* lg = target->GetLocalGenerator();
  860. // Construct the property value.
  861. std::string link_entries;
  862. const char* sep = "";
  863. for (T const& l : entries) {
  864. // Separate this from the previous entry.
  865. link_entries += sep;
  866. sep = ";";
  867. if (targetNames == ImportLinkPropertyTargetNames::Yes) {
  868. std::string temp = asString(l);
  869. this->AddTargetNamespace(temp, target, lg);
  870. link_entries += temp;
  871. } else {
  872. link_entries += asString(l);
  873. }
  874. }
  875. // Store the property.
  876. std::string prop = cmStrCat(propName, suffix);
  877. properties[prop] = link_entries;
  878. }
  879. void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
  880. {
  881. // Protect that file against use with older CMake versions.
  882. /* clang-format off */
  883. os << "# Generated by CMake\n\n";
  884. os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
  885. << " message(FATAL_ERROR \"CMake >= 2.8.0 required\")\n"
  886. << "endif()\n"
  887. << "if(CMAKE_VERSION VERSION_LESS \""
  888. << this->RequiredCMakeVersionMajor << '.'
  889. << this->RequiredCMakeVersionMinor << '.'
  890. << this->RequiredCMakeVersionPatch << "\")\n"
  891. << " message(FATAL_ERROR \"CMake >= "
  892. << this->RequiredCMakeVersionMajor << '.'
  893. << this->RequiredCMakeVersionMinor << '.'
  894. << this->RequiredCMakeVersionPatch << " required\")\n"
  895. << "endif()\n";
  896. /* clang-format on */
  897. // Isolate the file policy level.
  898. // Support CMake versions as far back as the
  899. // RequiredCMakeVersion{Major,Minor,Patch}, but also support using NEW
  900. // policy settings for up to CMake 3.28 (this upper limit may be reviewed
  901. // and increased from time to time). This reduces the opportunity for CMake
  902. // warnings when an older export file is later used with newer CMake
  903. // versions.
  904. /* clang-format off */
  905. os << "cmake_policy(PUSH)\n"
  906. << "cmake_policy(VERSION "
  907. << this->RequiredCMakeVersionMajor << '.'
  908. << this->RequiredCMakeVersionMinor << '.'
  909. << this->RequiredCMakeVersionPatch << "...3.28)\n";
  910. /* clang-format on */
  911. }
  912. void cmExportFileGenerator::GeneratePolicyFooterCode(std::ostream& os)
  913. {
  914. os << "cmake_policy(POP)\n";
  915. }
  916. void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
  917. const std::string& config)
  918. {
  919. os << "#----------------------------------------------------------------\n"
  920. << "# Generated CMake target import file";
  921. if (!config.empty()) {
  922. os << " for configuration \"" << config << "\".\n";
  923. } else {
  924. os << ".\n";
  925. }
  926. os << "#----------------------------------------------------------------\n"
  927. << "\n";
  928. this->GenerateImportVersionCode(os);
  929. }
  930. void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
  931. {
  932. os << "# Commands beyond this point should not need to know the version.\n"
  933. << "set(CMAKE_IMPORT_FILE_VERSION)\n";
  934. }
  935. void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
  936. {
  937. // Store an import file format version. This will let us change the
  938. // format later while still allowing old import files to work.
  939. /* clang-format off */
  940. os << "# Commands may need to know the format version.\n"
  941. << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
  942. << "\n";
  943. /* clang-format on */
  944. }
  945. void cmExportFileGenerator::GenerateExpectedTargetsCode(
  946. std::ostream& os, const std::string& expectedTargets)
  947. {
  948. /* clang-format off */
  949. os << "# Protect against multiple inclusion, which would fail when already "
  950. "imported targets are added once more.\n"
  951. "set(_cmake_targets_defined \"\")\n"
  952. "set(_cmake_targets_not_defined \"\")\n"
  953. "set(_cmake_expected_targets \"\")\n"
  954. "foreach(_cmake_expected_target IN ITEMS " << expectedTargets << ")\n"
  955. " list(APPEND _cmake_expected_targets \"${_cmake_expected_target}\")\n"
  956. " if(TARGET \"${_cmake_expected_target}\")\n"
  957. " list(APPEND _cmake_targets_defined \"${_cmake_expected_target}\")\n"
  958. " else()\n"
  959. " list(APPEND _cmake_targets_not_defined \"${_cmake_expected_target}\")\n"
  960. " endif()\n"
  961. "endforeach()\n"
  962. "unset(_cmake_expected_target)\n"
  963. "if(_cmake_targets_defined STREQUAL _cmake_expected_targets)\n"
  964. " unset(_cmake_targets_defined)\n"
  965. " unset(_cmake_targets_not_defined)\n"
  966. " unset(_cmake_expected_targets)\n"
  967. " unset(CMAKE_IMPORT_FILE_VERSION)\n"
  968. " cmake_policy(POP)\n"
  969. " return()\n"
  970. "endif()\n"
  971. "if(NOT _cmake_targets_defined STREQUAL \"\")\n"
  972. " string(REPLACE \";\" \", \" _cmake_targets_defined_text \"${_cmake_targets_defined}\")\n"
  973. " string(REPLACE \";\" \", \" _cmake_targets_not_defined_text \"${_cmake_targets_not_defined}\")\n"
  974. " message(FATAL_ERROR \"Some (but not all) targets in this export "
  975. "set were already defined.\\nTargets Defined: ${_cmake_targets_defined_text}\\n"
  976. "Targets not yet defined: ${_cmake_targets_not_defined_text}\\n\")\n"
  977. "endif()\n"
  978. "unset(_cmake_targets_defined)\n"
  979. "unset(_cmake_targets_not_defined)\n"
  980. "unset(_cmake_expected_targets)\n"
  981. "\n\n";
  982. /* clang-format on */
  983. }
  984. void cmExportFileGenerator::GenerateImportTargetCode(
  985. std::ostream& os, cmGeneratorTarget const* target,
  986. cmStateEnums::TargetType targetType)
  987. {
  988. // Construct the imported target name.
  989. std::string targetName = this->Namespace;
  990. targetName += target->GetExportName();
  991. // Create the imported target.
  992. os << "# Create imported target " << targetName << "\n";
  993. switch (targetType) {
  994. case cmStateEnums::EXECUTABLE:
  995. os << "add_executable(" << targetName << " IMPORTED)\n";
  996. break;
  997. case cmStateEnums::STATIC_LIBRARY:
  998. os << "add_library(" << targetName << " STATIC IMPORTED)\n";
  999. break;
  1000. case cmStateEnums::SHARED_LIBRARY:
  1001. os << "add_library(" << targetName << " SHARED IMPORTED)\n";
  1002. break;
  1003. case cmStateEnums::MODULE_LIBRARY:
  1004. os << "add_library(" << targetName << " MODULE IMPORTED)\n";
  1005. break;
  1006. case cmStateEnums::UNKNOWN_LIBRARY:
  1007. os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
  1008. break;
  1009. case cmStateEnums::OBJECT_LIBRARY:
  1010. os << "add_library(" << targetName << " OBJECT IMPORTED)\n";
  1011. break;
  1012. case cmStateEnums::INTERFACE_LIBRARY:
  1013. os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
  1014. break;
  1015. default: // should never happen
  1016. break;
  1017. }
  1018. // Mark the imported executable if it has exports.
  1019. if (target->IsExecutableWithExports() ||
  1020. (target->IsSharedLibraryWithExports() && target->HasImportLibrary(""))) {
  1021. os << "set_property(TARGET " << targetName
  1022. << " PROPERTY ENABLE_EXPORTS 1)\n";
  1023. }
  1024. // Mark the imported library if it is a framework.
  1025. if (target->IsFrameworkOnApple()) {
  1026. os << "set_property(TARGET " << targetName << " PROPERTY FRAMEWORK 1)\n";
  1027. }
  1028. // Mark the imported executable if it is an application bundle.
  1029. if (target->IsAppBundleOnApple()) {
  1030. os << "set_property(TARGET " << targetName
  1031. << " PROPERTY MACOSX_BUNDLE 1)\n";
  1032. }
  1033. if (target->IsCFBundleOnApple()) {
  1034. os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n";
  1035. }
  1036. // generate DEPRECATION
  1037. if (target->IsDeprecated()) {
  1038. os << "set_property(TARGET " << targetName << " PROPERTY DEPRECATION "
  1039. << cmExportFileGeneratorEscape(target->GetDeprecation()) << ")\n";
  1040. }
  1041. if (target->GetPropertyAsBool("IMPORTED_NO_SYSTEM")) {
  1042. os << "set_property(TARGET " << targetName
  1043. << " PROPERTY IMPORTED_NO_SYSTEM 1)\n";
  1044. }
  1045. if (target->GetPropertyAsBool("EXPORT_NO_SYSTEM")) {
  1046. os << "set_property(TARGET " << targetName << " PROPERTY SYSTEM 0)\n";
  1047. }
  1048. os << "\n";
  1049. }
  1050. void cmExportFileGenerator::GenerateImportPropertyCode(
  1051. std::ostream& os, const std::string& config, const std::string& suffix,
  1052. cmGeneratorTarget const* target, ImportPropertyMap const& properties,
  1053. const std::string& importedXcFrameworkLocation)
  1054. {
  1055. // Construct the imported target name.
  1056. std::string targetName = this->Namespace;
  1057. targetName += target->GetExportName();
  1058. // Set the import properties.
  1059. os << "# Import target \"" << targetName << "\" for configuration \""
  1060. << config << "\"\n";
  1061. os << "set_property(TARGET " << targetName
  1062. << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
  1063. if (!config.empty()) {
  1064. os << cmSystemTools::UpperCase(config);
  1065. } else {
  1066. os << "NOCONFIG";
  1067. }
  1068. os << ")\n";
  1069. os << "set_target_properties(" << targetName << " PROPERTIES\n";
  1070. std::string importedLocationProp = cmStrCat("IMPORTED_LOCATION", suffix);
  1071. for (auto const& property : properties) {
  1072. if (importedXcFrameworkLocation.empty() ||
  1073. property.first != importedLocationProp) {
  1074. os << " " << property.first << " "
  1075. << cmExportFileGeneratorEscape(property.second) << "\n";
  1076. }
  1077. }
  1078. os << " )\n";
  1079. if (!importedXcFrameworkLocation.empty()) {
  1080. auto importedLocationIt = properties.find(importedLocationProp);
  1081. if (importedLocationIt != properties.end()) {
  1082. os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.28\" AND IS_DIRECTORY "
  1083. << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
  1084. << ")\n"
  1085. " set_property(TARGET "
  1086. << targetName << " PROPERTY " << importedLocationProp << " "
  1087. << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
  1088. << ")\nelse()\n set_property(TARGET " << targetName << " PROPERTY "
  1089. << importedLocationProp << " "
  1090. << cmExportFileGeneratorEscape(importedLocationIt->second)
  1091. << ")\nendif()\n";
  1092. }
  1093. }
  1094. os << "\n";
  1095. }
  1096. void cmExportFileGenerator::GenerateFindDependencyCalls(std::ostream& os)
  1097. {
  1098. os << "include(CMakeFindDependencyMacro)\n";
  1099. std::map<std::string, cmExportSet::PackageDependency> packageDependencies;
  1100. auto* exportSet = this->GetExportSet();
  1101. if (exportSet) {
  1102. packageDependencies = exportSet->GetPackageDependencies();
  1103. }
  1104. for (cmGeneratorTarget const* gt : this->ExternalTargets) {
  1105. std::string findPackageName;
  1106. auto exportFindPackageName = gt->GetProperty("EXPORT_FIND_PACKAGE_NAME");
  1107. cmFindPackageStack pkgStack = gt->Target->GetFindPackageStack();
  1108. if (!exportFindPackageName.IsEmpty()) {
  1109. findPackageName = *exportFindPackageName;
  1110. } else {
  1111. if (!pkgStack.Empty()) {
  1112. cmFindPackageCall const& fpc = pkgStack.Top();
  1113. findPackageName = fpc.Name;
  1114. }
  1115. }
  1116. if (!findPackageName.empty()) {
  1117. auto& dep = packageDependencies[findPackageName];
  1118. if (!pkgStack.Empty()) {
  1119. dep.FindPackageIndex = pkgStack.Top().Index;
  1120. }
  1121. if (dep.Enabled == cmExportSet::PackageDependencyExportEnabled::Auto) {
  1122. dep.Enabled = cmExportSet::PackageDependencyExportEnabled::On;
  1123. }
  1124. }
  1125. }
  1126. std::vector<std::pair<std::string, cmExportSet::PackageDependency>>
  1127. packageDependenciesSorted(packageDependencies.begin(),
  1128. packageDependencies.end());
  1129. std::sort(
  1130. packageDependenciesSorted.begin(), packageDependenciesSorted.end(),
  1131. [](const std::pair<std::string, cmExportSet::PackageDependency>& lhs,
  1132. const std::pair<std::string, cmExportSet::PackageDependency>& rhs)
  1133. -> bool {
  1134. if (lhs.second.SpecifiedIndex) {
  1135. if (rhs.second.SpecifiedIndex) {
  1136. return lhs.second.SpecifiedIndex < rhs.second.SpecifiedIndex;
  1137. }
  1138. assert(rhs.second.FindPackageIndex);
  1139. return true;
  1140. }
  1141. assert(lhs.second.FindPackageIndex);
  1142. if (rhs.second.SpecifiedIndex) {
  1143. return false;
  1144. }
  1145. assert(rhs.second.FindPackageIndex);
  1146. return lhs.second.FindPackageIndex < rhs.second.FindPackageIndex;
  1147. });
  1148. for (auto const& it : packageDependenciesSorted) {
  1149. if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
  1150. os << "find_dependency(" << it.first;
  1151. for (auto const& arg : it.second.ExtraArguments) {
  1152. os << " " << cmOutputConverter::EscapeForCMake(arg);
  1153. }
  1154. os << ")\n";
  1155. }
  1156. }
  1157. os << "\n\n";
  1158. }
  1159. void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os)
  1160. {
  1161. if (this->MissingTargets.empty()) {
  1162. /* clang-format off */
  1163. os << "# This file does not depend on other imported targets which have\n"
  1164. "# been exported from the same project but in a separate "
  1165. "export set.\n\n";
  1166. /* clang-format on */
  1167. return;
  1168. }
  1169. /* clang-format off */
  1170. os << "# Make sure the targets which have been exported in some other\n"
  1171. "# export set exist.\n"
  1172. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  1173. "foreach(_target ";
  1174. /* clang-format on */
  1175. std::set<std::string> emitted;
  1176. for (std::string const& missingTarget : this->MissingTargets) {
  1177. if (emitted.insert(missingTarget).second) {
  1178. os << "\"" << missingTarget << "\" ";
  1179. }
  1180. }
  1181. /* clang-format off */
  1182. os << ")\n"
  1183. " if(NOT TARGET \"${_target}\" )\n"
  1184. " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
  1185. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
  1186. "\n"
  1187. " endif()\n"
  1188. "endforeach()\n"
  1189. "\n"
  1190. "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  1191. " if(CMAKE_FIND_PACKAGE_NAME)\n"
  1192. " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
  1193. " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
  1194. "\"The following imported targets are "
  1195. "referenced, but are missing: "
  1196. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  1197. " else()\n"
  1198. " message(FATAL_ERROR \"The following imported targets are "
  1199. "referenced, but are missing: "
  1200. "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
  1201. " endif()\n"
  1202. "endif()\n"
  1203. "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
  1204. "\n";
  1205. /* clang-format on */
  1206. }
  1207. void cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
  1208. {
  1209. // Add code which verifies at cmake time that the file which is being
  1210. // imported actually exists on disk. This should in theory always be theory
  1211. // case, but still when packages are split into normal and development
  1212. // packages this might get broken (e.g. the Config.cmake could be part of
  1213. // the non-development package, something similar happened to me without
  1214. // on SUSE with a mysql pkg-config file, which claimed everything is fine,
  1215. // but the development package was not installed.).
  1216. /* clang-format off */
  1217. os << "# Loop over all imported files and verify that they actually exist\n"
  1218. "foreach(_cmake_target IN LISTS _cmake_import_check_targets)\n"
  1219. " if(CMAKE_VERSION VERSION_LESS \"3.28\"\n"
  1220. " OR NOT DEFINED "
  1221. "_cmake_import_check_xcframework_for_${_cmake_target}\n"
  1222. " OR NOT IS_DIRECTORY "
  1223. "\"${_cmake_import_check_xcframework_for_${_cmake_target}}\")\n"
  1224. " foreach(_cmake_file IN LISTS "
  1225. "\"_cmake_import_check_files_for_${_cmake_target}\")\n"
  1226. " if(NOT EXISTS \"${_cmake_file}\")\n"
  1227. " message(FATAL_ERROR \"The imported target "
  1228. "\\\"${_cmake_target}\\\" references the file\n"
  1229. " \\\"${_cmake_file}\\\"\n"
  1230. "but this file does not exist. Possible reasons include:\n"
  1231. "* The file was deleted, renamed, or moved to another location.\n"
  1232. "* An install or uninstall procedure did not complete successfully.\n"
  1233. "* The installation package was faulty and contained\n"
  1234. " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
  1235. "but not all the files it references.\n"
  1236. "\")\n"
  1237. " endif()\n"
  1238. " endforeach()\n"
  1239. " endif()\n"
  1240. " unset(_cmake_file)\n"
  1241. " unset(\"_cmake_import_check_files_for_${_cmake_target}\")\n"
  1242. "endforeach()\n"
  1243. "unset(_cmake_target)\n"
  1244. "unset(_cmake_import_check_targets)\n"
  1245. "\n";
  1246. /* clang-format on */
  1247. }
  1248. void cmExportFileGenerator::GenerateImportedFileChecksCode(
  1249. std::ostream& os, cmGeneratorTarget* target,
  1250. ImportPropertyMap const& properties,
  1251. const std::set<std::string>& importedLocations,
  1252. const std::string& importedXcFrameworkLocation)
  1253. {
  1254. // Construct the imported target name.
  1255. std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
  1256. os << "list(APPEND _cmake_import_check_targets " << targetName << " )\n";
  1257. if (!importedXcFrameworkLocation.empty()) {
  1258. os << "set(_cmake_import_check_xcframework_for_" << targetName << ' '
  1259. << cmExportFileGeneratorEscape(importedXcFrameworkLocation) << ")\n";
  1260. }
  1261. os << "list(APPEND _cmake_import_check_files_for_" << targetName << " ";
  1262. for (std::string const& li : importedLocations) {
  1263. auto pi = properties.find(li);
  1264. if (pi != properties.end()) {
  1265. os << cmExportFileGeneratorEscape(pi->second) << " ";
  1266. }
  1267. }
  1268. os << ")\n\n";
  1269. }
  1270. enum class ExportWhen
  1271. {
  1272. Defined,
  1273. Always,
  1274. };
  1275. enum class PropertyType
  1276. {
  1277. Strings,
  1278. Paths,
  1279. IncludePaths,
  1280. };
  1281. namespace {
  1282. bool PropertyTypeIsForPaths(PropertyType pt)
  1283. {
  1284. switch (pt) {
  1285. case PropertyType::Strings:
  1286. return false;
  1287. case PropertyType::Paths:
  1288. case PropertyType::IncludePaths:
  1289. return true;
  1290. }
  1291. return false;
  1292. }
  1293. }
  1294. struct ModuleTargetPropertyTable
  1295. {
  1296. cm::static_string_view Name;
  1297. ExportWhen Cond;
  1298. };
  1299. struct ModulePropertyTable
  1300. {
  1301. cm::static_string_view Name;
  1302. PropertyType Type;
  1303. };
  1304. bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
  1305. cmGeneratorTarget const* gte, ImportPropertyMap& properties,
  1306. cmGeneratorExpression::PreprocessContext ctx,
  1307. std::string const& includesDestinationDirs, std::string& errorMessage)
  1308. {
  1309. if (!gte->HaveCxx20ModuleSources(&errorMessage)) {
  1310. return true;
  1311. }
  1312. const ModuleTargetPropertyTable exportedDirectModuleProperties[] = {
  1313. { "CXX_EXTENSIONS"_s, ExportWhen::Defined },
  1314. // Always define this property as it is an intrinsic property of the target
  1315. // and should not be inherited from the in-scope `CMAKE_CXX_MODULE_STD`
  1316. // variable.
  1317. //
  1318. // TODO(cxxmodules): A future policy may make this "ON" based on the target
  1319. // policies if unset. Add a new `ExportWhen` condition to handle it when
  1320. // this happens.
  1321. { "CXX_MODULE_STD"_s, ExportWhen::Always },
  1322. };
  1323. for (auto const& prop : exportedDirectModuleProperties) {
  1324. auto const propNameStr = std::string(prop.Name);
  1325. cmValue propValue = gte->Target->GetComputedProperty(
  1326. propNameStr, *gte->Target->GetMakefile());
  1327. if (!propValue) {
  1328. propValue = gte->Target->GetProperty(propNameStr);
  1329. }
  1330. if (propValue) {
  1331. properties[propNameStr] =
  1332. cmGeneratorExpression::Preprocess(*propValue, ctx);
  1333. } else if (prop.Cond == ExportWhen::Always) {
  1334. properties[propNameStr] = "";
  1335. }
  1336. }
  1337. const ModulePropertyTable exportedModuleProperties[] = {
  1338. { "INCLUDE_DIRECTORIES"_s, PropertyType::IncludePaths },
  1339. { "COMPILE_DEFINITIONS"_s, PropertyType::Strings },
  1340. { "COMPILE_OPTIONS"_s, PropertyType::Strings },
  1341. { "COMPILE_FEATURES"_s, PropertyType::Strings },
  1342. };
  1343. for (auto const& propEntry : exportedModuleProperties) {
  1344. auto const propNameStr = std::string(propEntry.Name);
  1345. cmValue prop = gte->Target->GetComputedProperty(
  1346. propNameStr, *gte->Target->GetMakefile());
  1347. if (!prop) {
  1348. prop = gte->Target->GetProperty(propNameStr);
  1349. }
  1350. if (prop) {
  1351. auto const exportedPropName =
  1352. cmStrCat("IMPORTED_CXX_MODULES_", propEntry.Name);
  1353. properties[exportedPropName] =
  1354. cmGeneratorExpression::Preprocess(*prop, ctx);
  1355. if (ctx == cmGeneratorExpression::InstallInterface &&
  1356. PropertyTypeIsForPaths(propEntry.Type)) {
  1357. this->ReplaceInstallPrefix(properties[exportedPropName]);
  1358. prefixItems(properties[exportedPropName]);
  1359. if (propEntry.Type == PropertyType::IncludePaths &&
  1360. !includesDestinationDirs.empty()) {
  1361. if (!properties[exportedPropName].empty()) {
  1362. properties[exportedPropName] += ';';
  1363. }
  1364. properties[exportedPropName] += includesDestinationDirs;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. const cm::static_string_view exportedLinkModuleProperties[] = {
  1370. "LINK_LIBRARIES"_s,
  1371. };
  1372. for (auto const& propName : exportedLinkModuleProperties) {
  1373. auto const propNameStr = std::string(propName);
  1374. cmValue prop = gte->Target->GetComputedProperty(
  1375. propNameStr, *gte->Target->GetMakefile());
  1376. if (!prop) {
  1377. prop = gte->Target->GetProperty(propNameStr);
  1378. }
  1379. if (prop) {
  1380. auto const exportedPropName =
  1381. cmStrCat("IMPORTED_CXX_MODULES_", propName);
  1382. auto value = cmGeneratorExpression::Preprocess(*prop, ctx);
  1383. this->ResolveTargetsInGeneratorExpressions(
  1384. value, gte, cmExportFileGenerator::ReplaceFreeTargets);
  1385. properties[exportedPropName] = value;
  1386. }
  1387. }
  1388. return true;
  1389. }
  1390. bool cmExportFileGenerator::PopulateExportProperties(
  1391. cmGeneratorTarget const* gte, ImportPropertyMap& properties,
  1392. std::string& errorMessage)
  1393. {
  1394. const auto& targetProperties = gte->Target->GetProperties();
  1395. if (cmValue exportProperties =
  1396. targetProperties.GetPropertyValue("EXPORT_PROPERTIES")) {
  1397. for (auto& prop : cmList{ *exportProperties }) {
  1398. /* Black list reserved properties */
  1399. if (cmHasLiteralPrefix(prop, "IMPORTED_") ||
  1400. cmHasLiteralPrefix(prop, "INTERFACE_")) {
  1401. std::ostringstream e;
  1402. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1403. << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* "
  1404. << "properties are reserved.";
  1405. errorMessage = e.str();
  1406. return false;
  1407. }
  1408. cmValue propertyValue = targetProperties.GetPropertyValue(prop);
  1409. if (!propertyValue) {
  1410. // Asked to export a property that isn't defined on the target. Do not
  1411. // consider this an error, there's just nothing to export.
  1412. continue;
  1413. }
  1414. std::string evaluatedValue = cmGeneratorExpression::Preprocess(
  1415. *propertyValue, cmGeneratorExpression::StripAllGeneratorExpressions);
  1416. if (evaluatedValue != *propertyValue) {
  1417. std::ostringstream e;
  1418. e << "Target \"" << gte->Target->GetName() << "\" contains property \""
  1419. << prop << "\" in EXPORT_PROPERTIES but this property contains a "
  1420. << "generator expression. This is not allowed.";
  1421. errorMessage = e.str();
  1422. return false;
  1423. }
  1424. properties[prop] = *propertyValue;
  1425. }
  1426. }
  1427. return true;
  1428. }
  1429. void cmExportFileGenerator::GenerateTargetFileSets(cmGeneratorTarget* gte,
  1430. std::ostream& os,
  1431. cmTargetExport* te)
  1432. {
  1433. auto interfaceFileSets = gte->Target->GetAllInterfaceFileSets();
  1434. if (!interfaceFileSets.empty()) {
  1435. std::string targetName = cmStrCat(this->Namespace, gte->GetExportName());
  1436. os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.23.0\")\n"
  1437. " target_sources("
  1438. << targetName << "\n";
  1439. for (auto const& name : interfaceFileSets) {
  1440. auto* fileSet = gte->Target->GetFileSet(name);
  1441. if (!fileSet) {
  1442. gte->Makefile->IssueMessage(
  1443. MessageType::FATAL_ERROR,
  1444. cmStrCat("File set \"", name,
  1445. "\" is listed in interface file sets of ", gte->GetName(),
  1446. " but has not been created"));
  1447. return;
  1448. }
  1449. os << " INTERFACE"
  1450. << "\n FILE_SET " << cmOutputConverter::EscapeForCMake(name)
  1451. << "\n TYPE "
  1452. << cmOutputConverter::EscapeForCMake(fileSet->GetType())
  1453. << "\n BASE_DIRS "
  1454. << this->GetFileSetDirectories(gte, fileSet, te) << "\n FILES "
  1455. << this->GetFileSetFiles(gte, fileSet, te) << "\n";
  1456. }
  1457. os << " )\nelse()\n set_property(TARGET " << targetName
  1458. << "\n APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES";
  1459. for (auto const& name : interfaceFileSets) {
  1460. auto* fileSet = gte->Target->GetFileSet(name);
  1461. if (!fileSet) {
  1462. gte->Makefile->IssueMessage(
  1463. MessageType::FATAL_ERROR,
  1464. cmStrCat("File set \"", name,
  1465. "\" is listed in interface file sets of ", gte->GetName(),
  1466. " but has not been created"));
  1467. return;
  1468. }
  1469. if (fileSet->GetType() == "HEADERS"_s) {
  1470. os << "\n " << this->GetFileSetDirectories(gte, fileSet, te);
  1471. }
  1472. }
  1473. os << "\n )\nendif()\n\n";
  1474. }
  1475. }
  1476. void cmExportFileGenerator::GenerateCxxModuleInformation(
  1477. std::string const& name, std::ostream& os)
  1478. {
  1479. auto const cxx_module_dirname = this->GetCxxModulesDirectory();
  1480. if (cxx_module_dirname.empty()) {
  1481. return;
  1482. }
  1483. // Write the include.
  1484. os << "# Include C++ module properties\n"
  1485. << "include(\"${CMAKE_CURRENT_LIST_DIR}/" << cxx_module_dirname
  1486. << "/cxx-modules-" << name << ".cmake\")\n\n";
  1487. // Get the path to the file we're going to write.
  1488. std::string path = this->MainImportFile;
  1489. path = cmSystemTools::GetFilenamePath(path);
  1490. auto trampoline_path =
  1491. cmStrCat(path, '/', cxx_module_dirname, "/cxx-modules-", name, ".cmake");
  1492. // Include all configuration-specific include files.
  1493. cmGeneratedFileStream ap(trampoline_path, true);
  1494. ap.SetCopyIfDifferent(true);
  1495. this->GenerateCxxModuleConfigInformation(name, ap);
  1496. }
  1497. void cmExportFileGenerator::SetRequiredCMakeVersion(unsigned int major,
  1498. unsigned int minor,
  1499. unsigned int patch)
  1500. {
  1501. if (CMake_VERSION_ENCODE(major, minor, patch) >
  1502. CMake_VERSION_ENCODE(this->RequiredCMakeVersionMajor,
  1503. this->RequiredCMakeVersionMinor,
  1504. this->RequiredCMakeVersionPatch)) {
  1505. this->RequiredCMakeVersionMajor = major;
  1506. this->RequiredCMakeVersionMinor = minor;
  1507. this->RequiredCMakeVersionPatch = patch;
  1508. }
  1509. }