cmQtAutoGenInitializer.cxx 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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 "cmQtAutoGenInitializer.h"
  4. #include "cmQtAutoGen.h"
  5. #include "cmQtAutoGenGlobalInitializer.h"
  6. #include "cmCustomCommand.h"
  7. #include "cmCustomCommandLines.h"
  8. #include "cmFilePathChecksum.h"
  9. #include "cmGeneratorExpression.h"
  10. #include "cmGeneratorTarget.h"
  11. #include "cmGlobalGenerator.h"
  12. #include "cmLinkItem.h"
  13. #include "cmListFileCache.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmMessageType.h"
  17. #include "cmOutputConverter.h"
  18. #include "cmPolicies.h"
  19. #include "cmSourceFile.h"
  20. #include "cmSourceFileLocationKind.h"
  21. #include "cmSourceGroup.h"
  22. #include "cmState.h"
  23. #include "cmStateTypes.h"
  24. #include "cmStringAlgorithms.h"
  25. #include "cmSystemTools.h"
  26. #include "cmTarget.h"
  27. #include "cmake.h"
  28. #include "cmsys/SystemInformation.hxx"
  29. #include <algorithm>
  30. #include <array>
  31. #include <deque>
  32. #include <map>
  33. #include <set>
  34. #include <string>
  35. #include <unordered_set>
  36. #include <utility>
  37. #include <vector>
  38. #include "cm_memory.hxx"
  39. static std::size_t GetParallelCPUCount()
  40. {
  41. static std::size_t count = 0;
  42. // Detect only on the first call
  43. if (count == 0) {
  44. cmsys::SystemInformation info;
  45. info.RunCPUCheck();
  46. count = info.GetNumberOfPhysicalCPU();
  47. count = std::max<std::size_t>(count, 1);
  48. count = std::min<std::size_t>(count, cmQtAutoGen::ParallelMax);
  49. }
  50. return count;
  51. }
  52. static std::string FileProjectRelativePath(cmMakefile* makefile,
  53. std::string const& fileName)
  54. {
  55. std::string res;
  56. {
  57. std::string pSource = cmSystemTools::RelativePath(
  58. makefile->GetCurrentSourceDirectory(), fileName);
  59. std::string pBinary = cmSystemTools::RelativePath(
  60. makefile->GetCurrentBinaryDirectory(), fileName);
  61. if (pSource.size() < pBinary.size()) {
  62. res = std::move(pSource);
  63. } else if (pBinary.size() < fileName.size()) {
  64. res = std::move(pBinary);
  65. } else {
  66. res = fileName;
  67. }
  68. }
  69. return res;
  70. }
  71. /**
  72. * Tests if targetDepend is a STATIC_LIBRARY and if any of its
  73. * recursive STATIC_LIBRARY dependencies depends on targetOrigin
  74. * (STATIC_LIBRARY cycle).
  75. */
  76. static bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
  77. cmGeneratorTarget const* targetDepend,
  78. std::string const& config)
  79. {
  80. bool cycle = false;
  81. if ((targetOrigin->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  82. (targetDepend->GetType() == cmStateEnums::STATIC_LIBRARY)) {
  83. std::set<cmGeneratorTarget const*> knownLibs;
  84. std::deque<cmGeneratorTarget const*> testLibs;
  85. // Insert initial static_library dependency
  86. knownLibs.insert(targetDepend);
  87. testLibs.push_back(targetDepend);
  88. while (!testLibs.empty()) {
  89. cmGeneratorTarget const* testTarget = testLibs.front();
  90. testLibs.pop_front();
  91. // Check if the test target is the origin target (cycle)
  92. if (testTarget == targetOrigin) {
  93. cycle = true;
  94. break;
  95. }
  96. // Collect all static_library dependencies from the test target
  97. cmLinkImplementationLibraries const* libs =
  98. testTarget->GetLinkImplementationLibraries(config);
  99. if (libs != nullptr) {
  100. for (cmLinkItem const& item : libs->Libraries) {
  101. cmGeneratorTarget const* depTarget = item.Target;
  102. if ((depTarget != nullptr) &&
  103. (depTarget->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  104. knownLibs.insert(depTarget).second) {
  105. testLibs.push_back(depTarget);
  106. }
  107. }
  108. }
  109. }
  110. }
  111. return cycle;
  112. }
  113. cmQtAutoGenInitializer::InfoWriter::InfoWriter(std::string const& filename)
  114. {
  115. Ofs_.SetCopyIfDifferent(true);
  116. Ofs_.Open(filename, false, true);
  117. }
  118. template <class IT>
  119. std::string cmQtAutoGenInitializer::InfoWriter::ListJoin(IT it_begin,
  120. IT it_end)
  121. {
  122. std::string res;
  123. for (IT it = it_begin; it != it_end; ++it) {
  124. if (it != it_begin) {
  125. res += ';';
  126. }
  127. for (const char* c = it->c_str(); *c; ++c) {
  128. if (*c == '"') {
  129. // Escape the double quote to avoid ending the argument.
  130. res += "\\\"";
  131. } else if (*c == '$') {
  132. // Escape the dollar to avoid expanding variables.
  133. res += "\\$";
  134. } else if (*c == '\\') {
  135. // Escape the backslash to avoid other escapes.
  136. res += "\\\\";
  137. } else if (*c == ';') {
  138. // Escape the semicolon to avoid list expansion.
  139. res += "\\;";
  140. } else {
  141. // Other characters will be parsed correctly.
  142. res += *c;
  143. }
  144. }
  145. }
  146. return res;
  147. }
  148. inline std::string cmQtAutoGenInitializer::InfoWriter::ConfigKey(
  149. cm::string_view key, std::string const& config)
  150. {
  151. return cmStrCat(key, "_", config);
  152. }
  153. void cmQtAutoGenInitializer::InfoWriter::Write(cm::string_view key,
  154. std::string const& value)
  155. {
  156. Ofs_ << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value)
  157. << ")\n";
  158. };
  159. void cmQtAutoGenInitializer::InfoWriter::WriteUInt(cm::string_view key,
  160. unsigned int value)
  161. {
  162. Ofs_ << "set(" << key << " " << value << ")\n";
  163. };
  164. template <class C>
  165. void cmQtAutoGenInitializer::InfoWriter::WriteStrings(cm::string_view key,
  166. C const& container)
  167. {
  168. Ofs_ << "set(" << key << " \""
  169. << ListJoin(container.begin(), container.end()) << "\")\n";
  170. }
  171. void cmQtAutoGenInitializer::InfoWriter::WriteConfig(
  172. cm::string_view key, std::map<std::string, std::string> const& map)
  173. {
  174. for (auto const& item : map) {
  175. Write(ConfigKey(key, item.first), item.second);
  176. }
  177. };
  178. template <class C>
  179. void cmQtAutoGenInitializer::InfoWriter::WriteConfigStrings(
  180. cm::string_view key, std::map<std::string, C> const& map)
  181. {
  182. for (auto const& item : map) {
  183. WriteStrings(ConfigKey(key, item.first), item.second);
  184. }
  185. }
  186. void cmQtAutoGenInitializer::InfoWriter::WriteNestedLists(
  187. cm::string_view key, std::vector<std::vector<std::string>> const& lists)
  188. {
  189. std::vector<std::string> seplist;
  190. seplist.reserve(lists.size());
  191. for (std::vector<std::string> const& list : lists) {
  192. seplist.push_back(cmStrCat("{", ListJoin(list.begin(), list.end()), "}"));
  193. }
  194. Write(key, cmJoin(seplist, cmQtAutoGen::ListSep));
  195. };
  196. cmQtAutoGenInitializer::cmQtAutoGenInitializer(
  197. cmQtAutoGenGlobalInitializer* globalInitializer, cmGeneratorTarget* target,
  198. IntegerVersion const& qtVersion, bool mocEnabled, bool uicEnabled,
  199. bool rccEnabled, bool globalAutogenTarget, bool globalAutoRccTarget)
  200. : GlobalInitializer(globalInitializer)
  201. , Target(target)
  202. , QtVersion(qtVersion)
  203. {
  204. AutogenTarget.GlobalTarget = globalAutogenTarget;
  205. Moc.Enabled = mocEnabled;
  206. Uic.Enabled = uicEnabled;
  207. Rcc.Enabled = rccEnabled;
  208. Rcc.GlobalTarget = globalAutoRccTarget;
  209. }
  210. bool cmQtAutoGenInitializer::InitCustomTargets()
  211. {
  212. cmMakefile* makefile = this->Target->Target->GetMakefile();
  213. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  214. cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator();
  215. // Configurations
  216. this->MultiConfig = globalGen->IsMultiConfig();
  217. this->ConfigDefault = makefile->GetConfigurations(this->ConfigsList);
  218. if (this->ConfigsList.empty()) {
  219. this->ConfigsList.push_back(this->ConfigDefault);
  220. }
  221. // Verbosity
  222. this->Verbosity = makefile->GetSafeDefinition("CMAKE_AUTOGEN_VERBOSE");
  223. if (!this->Verbosity.empty()) {
  224. unsigned long iVerb = 0;
  225. if (!cmStrToULong(this->Verbosity, &iVerb)) {
  226. // Non numeric verbosity
  227. this->Verbosity = cmIsOn(this->Verbosity) ? "1" : "0";
  228. }
  229. }
  230. // Targets FOLDER
  231. {
  232. const char* folder =
  233. makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  234. if (folder == nullptr) {
  235. folder =
  236. makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
  237. }
  238. // Inherit FOLDER property from target (#13688)
  239. if (folder == nullptr) {
  240. folder = this->Target->GetProperty("FOLDER");
  241. }
  242. if (folder != nullptr) {
  243. this->TargetsFolder = folder;
  244. }
  245. }
  246. // Check status of policy CMP0071
  247. {
  248. cmPolicies::PolicyStatus const CMP0071_status =
  249. makefile->GetPolicyStatus(cmPolicies::CMP0071);
  250. switch (CMP0071_status) {
  251. case cmPolicies::WARN:
  252. this->CMP0071Warn = true;
  253. CM_FALLTHROUGH;
  254. case cmPolicies::OLD:
  255. // Ignore GENERATED file
  256. break;
  257. case cmPolicies::REQUIRED_IF_USED:
  258. case cmPolicies::REQUIRED_ALWAYS:
  259. case cmPolicies::NEW:
  260. // Process GENERATED file
  261. this->CMP0071Accept = true;
  262. break;
  263. }
  264. }
  265. // Common directories
  266. {
  267. // Collapsed current binary directory
  268. std::string const cbd = cmSystemTools::CollapseFullPath(
  269. std::string(), makefile->GetCurrentBinaryDirectory());
  270. // Info directory
  271. this->Dir.Info = cbd;
  272. this->Dir.Info += "/CMakeFiles";
  273. this->Dir.Info += '/';
  274. this->Dir.Info += this->Target->GetName();
  275. this->Dir.Info += "_autogen";
  276. this->Dir.Info += ".dir";
  277. cmSystemTools::ConvertToUnixSlashes(this->Dir.Info);
  278. // Build directory
  279. this->Dir.Build = this->Target->GetSafeProperty("AUTOGEN_BUILD_DIR");
  280. if (this->Dir.Build.empty()) {
  281. this->Dir.Build = cbd;
  282. this->Dir.Build += '/';
  283. this->Dir.Build += this->Target->GetName();
  284. this->Dir.Build += "_autogen";
  285. }
  286. cmSystemTools::ConvertToUnixSlashes(this->Dir.Build);
  287. // Cleanup build directory
  288. this->AddCleanFile(this->Dir.Build);
  289. // Working directory
  290. this->Dir.Work = cbd;
  291. cmSystemTools::ConvertToUnixSlashes(this->Dir.Work);
  292. // Include directory
  293. this->Dir.Include = this->Dir.Build;
  294. this->Dir.Include += "/include";
  295. if (this->MultiConfig) {
  296. this->Dir.Include += "_$<CONFIG>";
  297. }
  298. // Per config include directories
  299. if (this->MultiConfig) {
  300. for (std::string const& cfg : this->ConfigsList) {
  301. std::string& dir = this->Dir.ConfigInclude[cfg];
  302. dir = this->Dir.Build;
  303. dir += "/include_";
  304. dir += cfg;
  305. }
  306. }
  307. }
  308. // Moc, Uic and _autogen target settings
  309. if (this->MocOrUicEnabled()) {
  310. // Init moc specific settings
  311. if (this->Moc.Enabled && !InitMoc()) {
  312. return false;
  313. }
  314. // Init uic specific settings
  315. if (this->Uic.Enabled && !InitUic()) {
  316. return false;
  317. }
  318. // Autogen target name
  319. this->AutogenTarget.Name = this->Target->GetName();
  320. this->AutogenTarget.Name += "_autogen";
  321. // Autogen target parallel processing
  322. this->AutogenTarget.Parallel =
  323. this->Target->GetSafeProperty("AUTOGEN_PARALLEL");
  324. if (this->AutogenTarget.Parallel.empty() ||
  325. (this->AutogenTarget.Parallel == "AUTO")) {
  326. // Autodetect number of CPUs
  327. this->AutogenTarget.Parallel = std::to_string(GetParallelCPUCount());
  328. }
  329. // Autogen target info and settings files
  330. {
  331. this->AutogenTarget.InfoFile = this->Dir.Info;
  332. this->AutogenTarget.InfoFile += "/AutogenInfo.cmake";
  333. this->AutogenTarget.SettingsFile = this->Dir.Info;
  334. this->AutogenTarget.SettingsFile += "/AutogenOldSettings.txt";
  335. if (this->MultiConfig) {
  336. for (std::string const& cfg : this->ConfigsList) {
  337. std::string& filename = this->AutogenTarget.ConfigSettingsFile[cfg];
  338. filename =
  339. AppendFilenameSuffix(this->AutogenTarget.SettingsFile, "_" + cfg);
  340. this->AddCleanFile(filename);
  341. }
  342. } else {
  343. this->AddCleanFile(this->AutogenTarget.SettingsFile);
  344. }
  345. this->AutogenTarget.ParseCacheFile = this->Dir.Info;
  346. this->AutogenTarget.ParseCacheFile += "/ParseCache.txt";
  347. this->AddCleanFile(this->AutogenTarget.ParseCacheFile);
  348. }
  349. // Autogen target: Compute user defined dependencies
  350. {
  351. this->AutogenTarget.DependOrigin =
  352. this->Target->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
  353. std::string const deps =
  354. this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
  355. if (!deps.empty()) {
  356. std::vector<std::string> extraDeps;
  357. cmExpandList(deps, extraDeps);
  358. for (std::string const& depName : extraDeps) {
  359. // Allow target and file dependencies
  360. auto* depTarget = makefile->FindTargetToUse(depName);
  361. if (depTarget != nullptr) {
  362. this->AutogenTarget.DependTargets.insert(depTarget);
  363. } else {
  364. this->AutogenTarget.DependFiles.insert(depName);
  365. }
  366. }
  367. }
  368. }
  369. // CMAKE_AUTOMOC_RELAXED_MODE deprecation warning
  370. if (this->Moc.Enabled) {
  371. if (cmIsOn(makefile->GetDefinition("CMAKE_AUTOMOC_RELAXED_MODE"))) {
  372. std::string msg = "AUTOMOC: CMAKE_AUTOMOC_RELAXED_MODE is "
  373. "deprecated an will be removed in the future. ";
  374. msg += "Consider disabling it and converting the target ";
  375. msg += this->Target->GetName();
  376. msg += " to regular mode.";
  377. makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
  378. }
  379. }
  380. }
  381. // Init rcc specific settings
  382. if (this->Rcc.Enabled && !InitRcc()) {
  383. return false;
  384. }
  385. // Add autogen include directory to the origin target INCLUDE_DIRECTORIES
  386. if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) {
  387. this->Target->AddIncludeDirectory(this->Dir.Include, true);
  388. }
  389. // Scan files
  390. if (!this->InitScanFiles()) {
  391. return false;
  392. }
  393. // Create autogen target
  394. if (this->MocOrUicEnabled() && !this->InitAutogenTarget()) {
  395. return false;
  396. }
  397. // Create rcc targets
  398. if (this->Rcc.Enabled && !this->InitRccTargets()) {
  399. return false;
  400. }
  401. return true;
  402. }
  403. bool cmQtAutoGenInitializer::InitMoc()
  404. {
  405. cmMakefile* makefile = this->Target->Target->GetMakefile();
  406. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  407. // Mocs compilation file
  408. this->Moc.MocsCompilation = this->Dir.Build;
  409. this->Moc.MocsCompilation += "/mocs_compilation.cpp";
  410. // Moc predefs command
  411. if (this->Target->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
  412. (this->QtVersion >= IntegerVersion(5, 8))) {
  413. this->Moc.PredefsCmd =
  414. makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND");
  415. }
  416. // Moc includes
  417. {
  418. bool const appendImplicit = (this->QtVersion.Major >= 5);
  419. auto GetIncludeDirs =
  420. [this, localGen,
  421. appendImplicit](std::string const& cfg) -> std::vector<std::string> {
  422. // Get the include dirs for this target, without stripping the implicit
  423. // include dirs off, see
  424. // https://gitlab.kitware.com/cmake/cmake/issues/13667
  425. std::vector<std::string> dirs;
  426. localGen->GetIncludeDirectoriesImplicit(dirs, this->Target, "CXX", cfg,
  427. false, appendImplicit);
  428. return dirs;
  429. };
  430. // Default configuration include directories
  431. this->Moc.Includes = GetIncludeDirs(this->ConfigDefault);
  432. // Other configuration settings
  433. if (this->MultiConfig) {
  434. for (std::string const& cfg : this->ConfigsList) {
  435. std::vector<std::string> dirs = GetIncludeDirs(cfg);
  436. if (dirs != this->Moc.Includes) {
  437. this->Moc.ConfigIncludes[cfg] = std::move(dirs);
  438. }
  439. }
  440. }
  441. }
  442. // Moc compile definitions
  443. {
  444. auto GetCompileDefinitions =
  445. [this, localGen](std::string const& cfg) -> std::set<std::string> {
  446. std::set<std::string> defines;
  447. localGen->GetTargetDefines(this->Target, cfg, "CXX", defines);
  448. #ifdef _WIN32
  449. if (this->Moc.PredefsCmd.empty()) {
  450. // Add WIN32 definition if we don't have a moc_predefs.h
  451. defines.insert("WIN32");
  452. }
  453. #endif
  454. return defines;
  455. };
  456. // Default configuration defines
  457. this->Moc.Defines = GetCompileDefinitions(this->ConfigDefault);
  458. // Other configuration defines
  459. if (this->MultiConfig) {
  460. for (std::string const& cfg : this->ConfigsList) {
  461. std::set<std::string> defines = GetCompileDefinitions(cfg);
  462. if (defines != this->Moc.Defines) {
  463. this->Moc.ConfigDefines[cfg] = std::move(defines);
  464. }
  465. }
  466. }
  467. }
  468. // Moc executable
  469. {
  470. if (!this->GetQtExecutable(this->Moc, "moc", false)) {
  471. return false;
  472. }
  473. // Let the _autogen target depend on the moc executable
  474. if (this->Moc.ExecutableTarget != nullptr) {
  475. this->AutogenTarget.DependTargets.insert(
  476. this->Moc.ExecutableTarget->Target);
  477. }
  478. }
  479. return true;
  480. }
  481. bool cmQtAutoGenInitializer::InitUic()
  482. {
  483. cmMakefile* makefile = this->Target->Target->GetMakefile();
  484. // Uic search paths
  485. {
  486. std::string const usp =
  487. this->Target->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
  488. if (!usp.empty()) {
  489. cmExpandList(usp, this->Uic.SearchPaths);
  490. std::string const& srcDir = makefile->GetCurrentSourceDirectory();
  491. for (std::string& path : this->Uic.SearchPaths) {
  492. path = cmSystemTools::CollapseFullPath(path, srcDir);
  493. }
  494. }
  495. }
  496. // Uic target options
  497. {
  498. auto UicGetOpts =
  499. [this](std::string const& cfg) -> std::vector<std::string> {
  500. std::vector<std::string> opts;
  501. this->Target->GetAutoUicOptions(opts, cfg);
  502. return opts;
  503. };
  504. // Default settings
  505. this->Uic.Options = UicGetOpts(this->ConfigDefault);
  506. // Configuration specific settings
  507. if (this->MultiConfig) {
  508. for (std::string const& cfg : this->ConfigsList) {
  509. std::vector<std::string> options = UicGetOpts(cfg);
  510. if (options != this->Uic.Options) {
  511. this->Uic.ConfigOptions[cfg] = std::move(options);
  512. }
  513. }
  514. }
  515. }
  516. // Uic executable
  517. {
  518. if (!this->GetQtExecutable(this->Uic, "uic", true)) {
  519. return false;
  520. }
  521. // Let the _autogen target depend on the uic executable
  522. if (this->Uic.ExecutableTarget != nullptr) {
  523. this->AutogenTarget.DependTargets.insert(
  524. this->Uic.ExecutableTarget->Target);
  525. }
  526. }
  527. return true;
  528. }
  529. bool cmQtAutoGenInitializer::InitRcc()
  530. {
  531. // Rcc executable
  532. {
  533. if (!this->GetQtExecutable(this->Rcc, "rcc", false)) {
  534. return false;
  535. }
  536. // Evaluate test output on demand
  537. CompilerFeatures& features = *this->Rcc.ExecutableFeatures;
  538. if (!features.Evaluated) {
  539. // Look for list options
  540. if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
  541. if (features.HelpOutput.find("--list") != std::string::npos) {
  542. features.ListOptions.emplace_back("--list");
  543. } else if (features.HelpOutput.find("-list") != std::string::npos) {
  544. features.ListOptions.emplace_back("-list");
  545. }
  546. }
  547. // Evaluation finished
  548. features.Evaluated = true;
  549. }
  550. }
  551. return true;
  552. }
  553. bool cmQtAutoGenInitializer::InitScanFiles()
  554. {
  555. cmMakefile* makefile = this->Target->Target->GetMakefile();
  556. cmake const* cm = makefile->GetCMakeInstance();
  557. auto const& kw = this->GlobalInitializer->kw();
  558. auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
  559. bool muIt) -> MUFileHandle {
  560. MUFileHandle muf = cm::make_unique<MUFile>();
  561. muf->RealPath = cmSystemTools::GetRealPath(fullPath);
  562. muf->SF = sf;
  563. muf->Generated = sf->GetIsGenerated();
  564. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  565. muf->SkipMoc = this->Moc.Enabled &&
  566. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC));
  567. muf->SkipUic = this->Uic.Enabled &&
  568. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  569. if (muIt) {
  570. muf->MocIt = this->Moc.Enabled && !muf->SkipMoc;
  571. muf->UicIt = this->Uic.Enabled && !muf->SkipUic;
  572. }
  573. return muf;
  574. };
  575. auto addMUFile = [&](MUFileHandle&& muf, bool isHeader) {
  576. if ((muf->MocIt || muf->UicIt) && muf->Generated) {
  577. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  578. }
  579. if (isHeader) {
  580. this->AutogenTarget.Headers.emplace(muf->SF, std::move(muf));
  581. } else {
  582. this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf));
  583. }
  584. };
  585. // Scan through target files
  586. {
  587. // Scan through target files
  588. std::vector<cmSourceFile*> srcFiles;
  589. this->Target->GetConfigCommonSourceFiles(srcFiles);
  590. for (cmSourceFile* sf : srcFiles) {
  591. // sf->GetExtension() is only valid after sf->GetFullPath() ...
  592. // Since we're iterating over source files that might be not in the
  593. // target we need to check for path errors (not existing files).
  594. std::string pathError;
  595. std::string const& fullPath = sf->GetFullPath(&pathError);
  596. if (!pathError.empty() || fullPath.empty()) {
  597. continue;
  598. }
  599. std::string const& extLower =
  600. cmSystemTools::LowerCase(sf->GetExtension());
  601. // Register files that will be scanned by moc or uic
  602. if (this->MocOrUicEnabled()) {
  603. if (cm->IsHeaderExtension(extLower)) {
  604. addMUFile(makeMUFile(sf, fullPath, true), true);
  605. } else if (cm->IsSourceExtension(extLower)) {
  606. addMUFile(makeMUFile(sf, fullPath, true), false);
  607. }
  608. }
  609. // Register rcc enabled files
  610. if (this->Rcc.Enabled) {
  611. if ((extLower == kw.qrc) && !sf->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
  612. !sf->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
  613. // Register qrc file
  614. Qrc qrc;
  615. qrc.QrcFile = cmSystemTools::GetRealPath(fullPath);
  616. qrc.QrcName =
  617. cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile);
  618. qrc.Generated = sf->GetIsGenerated();
  619. // RCC options
  620. {
  621. std::string const opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS);
  622. if (!opts.empty()) {
  623. cmExpandList(opts, qrc.Options);
  624. }
  625. }
  626. this->Rcc.Qrcs.push_back(std::move(qrc));
  627. }
  628. }
  629. }
  630. }
  631. // cmGeneratorTarget::GetConfigCommonSourceFiles computes the target's
  632. // sources meta data cache. Clear it so that OBJECT library targets that
  633. // are AUTOGEN initialized after this target get their added
  634. // mocs_compilation.cpp source acknowledged by this target.
  635. this->Target->ClearSourcesCache();
  636. // For source files find additional headers and private headers
  637. if (this->MocOrUicEnabled()) {
  638. std::vector<MUFileHandle> extraHeaders;
  639. extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2);
  640. // Header search suffixes and extensions
  641. std::array<std::string, 2> const suffixes{ { "", "_p" } };
  642. auto const& exts = cm->GetHeaderExtensions();
  643. // Scan through sources
  644. for (auto const& pair : this->AutogenTarget.Sources) {
  645. MUFile const& muf = *pair.second;
  646. if (muf.MocIt || muf.UicIt) {
  647. // Search for the default header file and a private header
  648. std::string const& srcPath = muf.SF->GetFullPath();
  649. std::string basePath =
  650. cmStrCat(cmQtAutoGen::SubDirPrefix(srcPath),
  651. cmSystemTools::GetFilenameWithoutLastExtension(srcPath));
  652. for (auto const& suffix : suffixes) {
  653. std::string const suffixedPath = basePath + suffix;
  654. for (auto const& ext : exts) {
  655. std::string fullPath = cmStrCat(suffixedPath, '.', ext);
  656. auto constexpr locationKind = cmSourceFileLocationKind::Known;
  657. cmSourceFile* sf = makefile->GetSource(fullPath, locationKind);
  658. if (sf != nullptr) {
  659. // Check if we know about this header already
  660. if (this->AutogenTarget.Headers.find(sf) !=
  661. this->AutogenTarget.Headers.end()) {
  662. continue;
  663. }
  664. // We only accept not-GENERATED files that do exist.
  665. if (!sf->GetIsGenerated() &&
  666. !cmSystemTools::FileExists(fullPath)) {
  667. continue;
  668. }
  669. } else if (cmSystemTools::FileExists(fullPath)) {
  670. // Create a new source file for the existing file
  671. sf = makefile->CreateSource(fullPath, false, locationKind);
  672. }
  673. if (sf != nullptr) {
  674. auto eMuf = makeMUFile(sf, fullPath, true);
  675. // Ony process moc/uic when the parent is processed as well
  676. if (!muf.MocIt) {
  677. eMuf->MocIt = false;
  678. }
  679. if (!muf.UicIt) {
  680. eMuf->UicIt = false;
  681. }
  682. extraHeaders.emplace_back(std::move(eMuf));
  683. }
  684. }
  685. }
  686. }
  687. }
  688. // Move generated files to main headers list
  689. for (auto& eMuf : extraHeaders) {
  690. addMUFile(std::move(eMuf), true);
  691. }
  692. }
  693. // Scan through all source files in the makefile to extract moc and uic
  694. // parameters. Historically we support non target source file parameters.
  695. // The reason is that their file names might be discovered from source files
  696. // at generation time.
  697. if (this->MocOrUicEnabled()) {
  698. for (cmSourceFile* sf : makefile->GetSourceFiles()) {
  699. // sf->GetExtension() is only valid after sf->GetFullPath() ...
  700. // Since we're iterating over source files that might be not in the
  701. // target we need to check for path errors (not existing files).
  702. std::string pathError;
  703. std::string const& fullPath = sf->GetFullPath(&pathError);
  704. if (!pathError.empty() || fullPath.empty()) {
  705. continue;
  706. }
  707. std::string const& extLower =
  708. cmSystemTools::LowerCase(sf->GetExtension());
  709. if (cm->IsHeaderExtension(extLower)) {
  710. if (this->AutogenTarget.Headers.find(sf) ==
  711. this->AutogenTarget.Headers.end()) {
  712. auto muf = makeMUFile(sf, fullPath, false);
  713. if (muf->SkipMoc || muf->SkipUic) {
  714. this->AutogenTarget.Headers.emplace(sf, std::move(muf));
  715. }
  716. }
  717. } else if (cm->IsSourceExtension(extLower)) {
  718. if (this->AutogenTarget.Sources.find(sf) ==
  719. this->AutogenTarget.Sources.end()) {
  720. auto muf = makeMUFile(sf, fullPath, false);
  721. if (muf->SkipMoc || muf->SkipUic) {
  722. this->AutogenTarget.Sources.emplace(sf, std::move(muf));
  723. }
  724. }
  725. } else if (this->Uic.Enabled && (extLower == kw.ui)) {
  726. // .ui file
  727. std::string realPath = cmSystemTools::GetRealPath(fullPath);
  728. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  729. bool const skipUic =
  730. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  731. if (!skipUic) {
  732. // Check if the .ui file has uic options
  733. std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS);
  734. if (!uicOpts.empty()) {
  735. this->Uic.FileFiles.push_back(std::move(realPath));
  736. std::vector<std::string> optsVec;
  737. cmExpandList(uicOpts, optsVec);
  738. this->Uic.FileOptions.push_back(std::move(optsVec));
  739. }
  740. } else {
  741. // Register skipped .ui file
  742. this->Uic.SkipUi.insert(std::move(realPath));
  743. }
  744. }
  745. }
  746. }
  747. // Process GENERATED sources and headers
  748. if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) {
  749. if (this->CMP0071Accept) {
  750. // Let the autogen target depend on the GENERATED files
  751. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  752. this->AutogenTarget.DependFiles.insert(muf->RealPath);
  753. }
  754. } else if (this->CMP0071Warn) {
  755. std::string msg =
  756. cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n');
  757. std::string property;
  758. if (this->Moc.Enabled && this->Uic.Enabled) {
  759. property = kw.SKIP_AUTOGEN;
  760. } else if (this->Moc.Enabled) {
  761. property = kw.SKIP_AUTOMOC;
  762. } else if (this->Uic.Enabled) {
  763. property = kw.SKIP_AUTOUIC;
  764. }
  765. msg += "For compatibility, CMake is excluding the GENERATED source "
  766. "file(s):\n";
  767. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  768. msg += " ";
  769. msg += Quoted(muf->RealPath);
  770. msg += '\n';
  771. }
  772. msg += "from processing by ";
  773. msg += cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false);
  774. msg += ". If any of the files should be processed, set CMP0071 to NEW. "
  775. "If any of the files should not be processed, "
  776. "explicitly exclude them by setting the source file property ";
  777. msg += property;
  778. msg += ":\n set_property(SOURCE file.h PROPERTY ";
  779. msg += property;
  780. msg += " ON)\n";
  781. makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
  782. }
  783. }
  784. // Process qrc files
  785. if (!this->Rcc.Qrcs.empty()) {
  786. const bool modernQt = (this->QtVersion.Major >= 5);
  787. // Target rcc options
  788. std::vector<std::string> optionsTarget;
  789. cmExpandList(this->Target->GetSafeProperty(kw.AUTORCC_OPTIONS),
  790. optionsTarget);
  791. // Check if file name is unique
  792. for (Qrc& qrc : this->Rcc.Qrcs) {
  793. qrc.Unique = true;
  794. for (Qrc const& qrc2 : this->Rcc.Qrcs) {
  795. if ((&qrc != &qrc2) && (qrc.QrcName == qrc2.QrcName)) {
  796. qrc.Unique = false;
  797. break;
  798. }
  799. }
  800. }
  801. // Path checksum and file names
  802. {
  803. cmFilePathChecksum const fpathCheckSum(makefile);
  804. for (Qrc& qrc : this->Rcc.Qrcs) {
  805. qrc.PathChecksum = fpathCheckSum.getPart(qrc.QrcFile);
  806. // RCC output file name
  807. qrc.RccFile = cmStrCat(this->Dir.Build + "/", qrc.PathChecksum,
  808. "/qrc_", qrc.QrcName, ".cpp");
  809. {
  810. std::string base = cmStrCat(this->Dir.Info, "/RCC", qrc.QrcName);
  811. if (!qrc.Unique) {
  812. base += qrc.PathChecksum;
  813. }
  814. qrc.LockFile = base;
  815. qrc.LockFile += ".lock";
  816. qrc.InfoFile = base;
  817. qrc.InfoFile += "Info.cmake";
  818. qrc.SettingsFile = base;
  819. qrc.SettingsFile += "Settings.txt";
  820. if (this->MultiConfig) {
  821. for (std::string const& cfg : this->ConfigsList) {
  822. qrc.ConfigSettingsFile[cfg] =
  823. AppendFilenameSuffix(qrc.SettingsFile, "_" + cfg);
  824. }
  825. }
  826. }
  827. }
  828. }
  829. // RCC options
  830. for (Qrc& qrc : this->Rcc.Qrcs) {
  831. // Target options
  832. std::vector<std::string> opts = optionsTarget;
  833. // Merge computed "-name XYZ" option
  834. {
  835. std::string name = qrc.QrcName;
  836. // Replace '-' with '_'. The former is not valid for symbol names.
  837. std::replace(name.begin(), name.end(), '-', '_');
  838. if (!qrc.Unique) {
  839. name += cmStrCat("_", qrc.PathChecksum);
  840. }
  841. std::vector<std::string> nameOpts;
  842. nameOpts.emplace_back("-name");
  843. nameOpts.emplace_back(std::move(name));
  844. RccMergeOptions(opts, nameOpts, modernQt);
  845. }
  846. // Merge file option
  847. RccMergeOptions(opts, qrc.Options, modernQt);
  848. qrc.Options = std::move(opts);
  849. }
  850. // RCC resources
  851. for (Qrc& qrc : this->Rcc.Qrcs) {
  852. if (!qrc.Generated) {
  853. std::string error;
  854. RccLister const lister(this->Rcc.Executable,
  855. this->Rcc.ExecutableFeatures->ListOptions);
  856. if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
  857. cmSystemTools::Error(error);
  858. return false;
  859. }
  860. }
  861. }
  862. }
  863. return true;
  864. }
  865. bool cmQtAutoGenInitializer::InitAutogenTarget()
  866. {
  867. cmMakefile* makefile = this->Target->Target->GetMakefile();
  868. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  869. cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator();
  870. // Register info file as generated by CMake
  871. makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
  872. // Files provided by the autogen target
  873. std::vector<std::string> autogenProvides;
  874. if (this->Moc.Enabled) {
  875. this->AddGeneratedSource(this->Moc.MocsCompilation, this->Moc, true);
  876. autogenProvides.push_back(this->Moc.MocsCompilation);
  877. }
  878. // Compose target comment
  879. std::string autogenComment;
  880. {
  881. std::string tools;
  882. if (this->Moc.Enabled) {
  883. tools += "MOC";
  884. }
  885. if (this->Uic.Enabled) {
  886. if (!tools.empty()) {
  887. tools += " and ";
  888. }
  889. tools += "UIC";
  890. }
  891. autogenComment = "Automatic ";
  892. autogenComment += tools;
  893. autogenComment += " for target ";
  894. autogenComment += this->Target->GetName();
  895. }
  896. // Compose command lines
  897. cmCustomCommandLines commandLines;
  898. {
  899. cmCustomCommandLine currentLine;
  900. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  901. currentLine.push_back("-E");
  902. currentLine.push_back("cmake_autogen");
  903. currentLine.push_back(this->AutogenTarget.InfoFile);
  904. currentLine.push_back("$<CONFIGURATION>");
  905. commandLines.push_back(std::move(currentLine));
  906. }
  907. // Use PRE_BUILD on demand
  908. bool usePRE_BUILD = false;
  909. if (globalGen->GetName().find("Visual Studio") != std::string::npos) {
  910. // Under VS use a PRE_BUILD event instead of a separate target to
  911. // reduce the number of targets loaded into the IDE.
  912. // This also works around a VS 11 bug that may skip updating the target:
  913. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  914. usePRE_BUILD = true;
  915. }
  916. // Disable PRE_BUILD in some cases
  917. if (usePRE_BUILD) {
  918. // Cannot use PRE_BUILD with file depends
  919. if (!this->AutogenTarget.DependFiles.empty()) {
  920. usePRE_BUILD = false;
  921. }
  922. // Cannot use PRE_BUILD when a global autogen target is in place
  923. if (AutogenTarget.GlobalTarget) {
  924. usePRE_BUILD = false;
  925. }
  926. }
  927. // Create the autogen target/command
  928. if (usePRE_BUILD) {
  929. // Add additional autogen target dependencies to origin target
  930. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  931. this->Target->Target->AddUtility(depTarget->GetName(), makefile);
  932. }
  933. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  934. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  935. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  936. //
  937. // PRE_BUILD does not support file dependencies!
  938. const std::vector<std::string> no_output;
  939. const std::vector<std::string> no_deps;
  940. cmCustomCommand cc(makefile, no_output, autogenProvides, no_deps,
  941. commandLines, autogenComment.c_str(),
  942. this->Dir.Work.c_str());
  943. cc.SetEscapeOldStyle(false);
  944. cc.SetEscapeAllowMakeVars(true);
  945. this->Target->Target->AddPreBuildCommand(cc);
  946. } else {
  947. // Add link library target dependencies to the autogen target
  948. // dependencies
  949. if (this->AutogenTarget.DependOrigin) {
  950. // add_dependencies/addUtility do not support generator expressions.
  951. // We depend only on the libraries found in all configs therefore.
  952. std::map<cmGeneratorTarget const*, std::size_t> commonTargets;
  953. for (std::string const& config : this->ConfigsList) {
  954. cmLinkImplementationLibraries const* libs =
  955. this->Target->GetLinkImplementationLibraries(config);
  956. if (libs != nullptr) {
  957. for (cmLinkItem const& item : libs->Libraries) {
  958. cmGeneratorTarget const* libTarget = item.Target;
  959. if ((libTarget != nullptr) &&
  960. !StaticLibraryCycle(this->Target, libTarget, config)) {
  961. // Increment target config count
  962. commonTargets[libTarget]++;
  963. }
  964. }
  965. }
  966. }
  967. for (auto const& item : commonTargets) {
  968. if (item.second == this->ConfigsList.size()) {
  969. this->AutogenTarget.DependTargets.insert(item.first->Target);
  970. }
  971. }
  972. }
  973. // Create autogen target
  974. cmTarget* autogenTarget = makefile->AddUtilityCommand(
  975. this->AutogenTarget.Name, cmMakefile::TargetOrigin::Generator, true,
  976. this->Dir.Work.c_str(), /*byproducts=*/autogenProvides,
  977. std::vector<std::string>(this->AutogenTarget.DependFiles.begin(),
  978. this->AutogenTarget.DependFiles.end()),
  979. commandLines, false, autogenComment.c_str());
  980. // Create autogen generator target
  981. localGen->AddGeneratorTarget(
  982. new cmGeneratorTarget(autogenTarget, localGen));
  983. // Forward origin utilities to autogen target
  984. if (this->AutogenTarget.DependOrigin) {
  985. for (BT<std::string> const& depName : this->Target->GetUtilities()) {
  986. autogenTarget->AddUtility(depName.Value, makefile);
  987. }
  988. }
  989. // Add additional autogen target dependencies to autogen target
  990. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  991. autogenTarget->AddUtility(depTarget->GetName(), makefile);
  992. }
  993. // Set FOLDER property in autogen target
  994. if (!this->TargetsFolder.empty()) {
  995. autogenTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
  996. }
  997. // Add autogen target to the origin target dependencies
  998. this->Target->Target->AddUtility(this->AutogenTarget.Name, makefile);
  999. // Add autogen target to the global autogen target dependencies
  1000. if (this->AutogenTarget.GlobalTarget) {
  1001. this->GlobalInitializer->AddToGlobalAutoGen(localGen,
  1002. this->AutogenTarget.Name);
  1003. }
  1004. }
  1005. return true;
  1006. }
  1007. bool cmQtAutoGenInitializer::InitRccTargets()
  1008. {
  1009. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1010. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  1011. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1012. // Register info file as generated by CMake
  1013. makefile->AddCMakeOutputFile(qrc.InfoFile);
  1014. // Register file at target
  1015. this->AddGeneratedSource(qrc.RccFile, this->Rcc);
  1016. std::vector<std::string> ccOutput;
  1017. ccOutput.push_back(qrc.RccFile);
  1018. std::vector<std::string> ccDepends;
  1019. // Add the .qrc and info file to the custom command dependencies
  1020. ccDepends.push_back(qrc.QrcFile);
  1021. ccDepends.push_back(qrc.InfoFile);
  1022. cmCustomCommandLines commandLines;
  1023. if (this->MultiConfig) {
  1024. // Build for all configurations
  1025. for (std::string const& config : this->ConfigsList) {
  1026. cmCustomCommandLine currentLine;
  1027. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  1028. currentLine.push_back("-E");
  1029. currentLine.push_back("cmake_autorcc");
  1030. currentLine.push_back(qrc.InfoFile);
  1031. currentLine.push_back(config);
  1032. commandLines.push_back(std::move(currentLine));
  1033. }
  1034. } else {
  1035. cmCustomCommandLine currentLine;
  1036. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  1037. currentLine.push_back("-E");
  1038. currentLine.push_back("cmake_autorcc");
  1039. currentLine.push_back(qrc.InfoFile);
  1040. currentLine.push_back("$<CONFIG>");
  1041. commandLines.push_back(std::move(currentLine));
  1042. }
  1043. std::string ccComment = cmStrCat(
  1044. "Automatic RCC for ", FileProjectRelativePath(makefile, qrc.QrcFile));
  1045. if (qrc.Generated || this->Rcc.GlobalTarget) {
  1046. // Create custom rcc target
  1047. std::string ccName;
  1048. {
  1049. ccName = this->Target->GetName();
  1050. ccName += "_arcc_";
  1051. ccName += qrc.QrcName;
  1052. if (!qrc.Unique) {
  1053. ccName += "_";
  1054. ccName += qrc.PathChecksum;
  1055. }
  1056. cmTarget* autoRccTarget = makefile->AddUtilityCommand(
  1057. ccName, cmMakefile::TargetOrigin::Generator, true,
  1058. this->Dir.Work.c_str(), ccOutput, ccDepends, commandLines, false,
  1059. ccComment.c_str());
  1060. // Create autogen generator target
  1061. localGen->AddGeneratorTarget(
  1062. new cmGeneratorTarget(autoRccTarget, localGen));
  1063. // Set FOLDER property in autogen target
  1064. if (!this->TargetsFolder.empty()) {
  1065. autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
  1066. }
  1067. if (!this->Rcc.ExecutableTargetName.empty()) {
  1068. autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, makefile);
  1069. }
  1070. }
  1071. // Add autogen target to the origin target dependencies
  1072. this->Target->Target->AddUtility(ccName, makefile);
  1073. // Add autogen target to the global autogen target dependencies
  1074. if (this->Rcc.GlobalTarget) {
  1075. this->GlobalInitializer->AddToGlobalAutoRcc(localGen, ccName);
  1076. }
  1077. } else {
  1078. // Create custom rcc command
  1079. {
  1080. std::vector<std::string> ccByproducts;
  1081. // Add the resource files to the dependencies
  1082. for (std::string const& fileName : qrc.Resources) {
  1083. // Add resource file to the custom command dependencies
  1084. ccDepends.push_back(fileName);
  1085. }
  1086. if (!this->Rcc.ExecutableTargetName.empty()) {
  1087. ccDepends.push_back(this->Rcc.ExecutableTargetName);
  1088. }
  1089. makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
  1090. /*main_dependency*/ std::string(),
  1091. commandLines, ccComment.c_str(),
  1092. this->Dir.Work.c_str());
  1093. }
  1094. // Reconfigure when .qrc file changes
  1095. makefile->AddCMakeDependFile(qrc.QrcFile);
  1096. }
  1097. }
  1098. return true;
  1099. }
  1100. bool cmQtAutoGenInitializer::SetupCustomTargets()
  1101. {
  1102. // Create info directory on demand
  1103. if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
  1104. cmSystemTools::Error(cmStrCat("AutoGen: Could not create directory: ",
  1105. Quoted(this->Dir.Info)));
  1106. return false;
  1107. }
  1108. // Generate autogen target info file
  1109. if (this->MocOrUicEnabled()) {
  1110. // Write autogen target info files
  1111. if (!this->SetupWriteAutogenInfo()) {
  1112. return false;
  1113. }
  1114. }
  1115. // Write AUTORCC info files
  1116. return !this->Rcc.Enabled || this->SetupWriteRccInfo();
  1117. }
  1118. bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
  1119. {
  1120. InfoWriter ofs(this->AutogenTarget.InfoFile);
  1121. if (ofs) {
  1122. // Utility lambdas
  1123. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1124. auto MfDef = [makefile](const char* key) {
  1125. return makefile->GetSafeDefinition(key);
  1126. };
  1127. // Write common settings
  1128. ofs.Write("# Meta\n");
  1129. ofs.Write("AM_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE");
  1130. ofs.Write("AM_PARALLEL", this->AutogenTarget.Parallel);
  1131. ofs.Write("AM_VERBOSITY", this->Verbosity);
  1132. ofs.Write("# Directories\n");
  1133. ofs.Write("AM_CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1134. ofs.Write("AM_CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1135. ofs.Write("AM_CMAKE_CURRENT_SOURCE_DIR",
  1136. MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1137. ofs.Write("AM_CMAKE_CURRENT_BINARY_DIR",
  1138. MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1139. ofs.Write("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE",
  1140. MfDef("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"));
  1141. ofs.Write("AM_BUILD_DIR", this->Dir.Build);
  1142. ofs.Write("AM_INCLUDE_DIR", this->Dir.Include);
  1143. ofs.WriteConfig("AM_INCLUDE_DIR", this->Dir.ConfigInclude);
  1144. std::vector<std::string> headers;
  1145. std::vector<std::string> headersFlags;
  1146. std::vector<std::string> headersBuildPaths;
  1147. std::vector<std::string> sources;
  1148. std::vector<std::string> sourcesFlags;
  1149. std::set<std::string> moc_skip;
  1150. std::set<std::string> uic_skip;
  1151. // Filter headers
  1152. {
  1153. auto headerCount = this->AutogenTarget.Headers.size();
  1154. headers.reserve(headerCount);
  1155. headersFlags.reserve(headerCount);
  1156. std::vector<MUFile const*> sortedHeaders;
  1157. {
  1158. sortedHeaders.reserve(headerCount);
  1159. for (auto const& pair : this->AutogenTarget.Headers) {
  1160. sortedHeaders.emplace_back(pair.second.get());
  1161. }
  1162. std::sort(sortedHeaders.begin(), sortedHeaders.end(),
  1163. [](MUFile const* a, MUFile const* b) {
  1164. return (a->RealPath < b->RealPath);
  1165. });
  1166. }
  1167. for (MUFile const* const muf : sortedHeaders) {
  1168. if (muf->Generated && !this->CMP0071Accept) {
  1169. continue;
  1170. }
  1171. if (muf->SkipMoc) {
  1172. moc_skip.insert(muf->RealPath);
  1173. }
  1174. if (muf->SkipUic) {
  1175. uic_skip.insert(muf->RealPath);
  1176. }
  1177. if (muf->MocIt || muf->UicIt) {
  1178. headers.emplace_back(muf->RealPath);
  1179. headersFlags.emplace_back(
  1180. cmStrCat(muf->MocIt ? "M" : "m", muf->UicIt ? "U" : "u"));
  1181. }
  1182. }
  1183. }
  1184. // Header build paths
  1185. {
  1186. cmFilePathChecksum const fpathCheckSum(makefile);
  1187. std::unordered_set<std::string> emitted;
  1188. for (std::string const& hdr : headers) {
  1189. std::string basePath =
  1190. cmStrCat(fpathCheckSum.getPart(hdr), "/moc_",
  1191. cmSystemTools::GetFilenameWithoutLastExtension(hdr));
  1192. for (int ii = 1; ii != 1024; ++ii) {
  1193. std::string path = basePath;
  1194. if (ii > 1) {
  1195. path += cmStrCat("_", ii);
  1196. }
  1197. path += ".cpp";
  1198. if (emitted.emplace(path).second) {
  1199. headersBuildPaths.emplace_back(std::move(path));
  1200. break;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. // Filter sources
  1206. {
  1207. auto sourcesCount = this->AutogenTarget.Sources.size();
  1208. sources.reserve(sourcesCount);
  1209. sourcesFlags.reserve(sourcesCount);
  1210. std::vector<MUFile const*> sorted;
  1211. sorted.reserve(sourcesCount);
  1212. for (auto const& pair : this->AutogenTarget.Sources) {
  1213. sorted.emplace_back(pair.second.get());
  1214. }
  1215. std::sort(sorted.begin(), sorted.end(),
  1216. [](MUFile const* a, MUFile const* b) {
  1217. return (a->RealPath < b->RealPath);
  1218. });
  1219. for (MUFile const* const muf : sorted) {
  1220. if (muf->Generated && !this->CMP0071Accept) {
  1221. continue;
  1222. }
  1223. if (muf->SkipMoc) {
  1224. moc_skip.insert(muf->RealPath);
  1225. }
  1226. if (muf->SkipUic) {
  1227. uic_skip.insert(muf->RealPath);
  1228. }
  1229. if (muf->MocIt || muf->UicIt) {
  1230. sources.emplace_back(muf->RealPath);
  1231. sourcesFlags.emplace_back(
  1232. cmStrCat(muf->MocIt ? "M" : "m", muf->UicIt ? "U" : "u"));
  1233. }
  1234. }
  1235. }
  1236. ofs.Write("# Qt\n");
  1237. ofs.WriteUInt("AM_QT_VERSION_MAJOR", this->QtVersion.Major);
  1238. ofs.Write("AM_QT_MOC_EXECUTABLE", this->Moc.Executable);
  1239. ofs.Write("AM_QT_UIC_EXECUTABLE", this->Uic.Executable);
  1240. ofs.Write("# Files\n");
  1241. ofs.Write("AM_CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand());
  1242. ofs.Write("AM_SETTINGS_FILE", this->AutogenTarget.SettingsFile);
  1243. ofs.WriteConfig("AM_SETTINGS_FILE",
  1244. this->AutogenTarget.ConfigSettingsFile);
  1245. ofs.Write("AM_PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
  1246. ofs.WriteStrings("AM_HEADERS", headers);
  1247. ofs.WriteStrings("AM_HEADERS_FLAGS", headersFlags);
  1248. ofs.WriteStrings("AM_HEADERS_BUILD_PATHS", headersBuildPaths);
  1249. ofs.WriteStrings("AM_SOURCES", sources);
  1250. ofs.WriteStrings("AM_SOURCES_FLAGS", sourcesFlags);
  1251. // Write moc settings
  1252. if (this->Moc.Enabled) {
  1253. ofs.Write("# MOC settings\n");
  1254. ofs.WriteStrings("AM_MOC_SKIP", moc_skip);
  1255. ofs.WriteStrings("AM_MOC_DEFINITIONS", this->Moc.Defines);
  1256. ofs.WriteConfigStrings("AM_MOC_DEFINITIONS", this->Moc.ConfigDefines);
  1257. ofs.WriteStrings("AM_MOC_INCLUDES", this->Moc.Includes);
  1258. ofs.WriteConfigStrings("AM_MOC_INCLUDES", this->Moc.ConfigIncludes);
  1259. ofs.Write("AM_MOC_OPTIONS",
  1260. this->Target->GetSafeProperty("AUTOMOC_MOC_OPTIONS"));
  1261. ofs.Write("AM_MOC_RELAXED_MODE", MfDef("CMAKE_AUTOMOC_RELAXED_MODE"));
  1262. ofs.Write("AM_MOC_MACRO_NAMES",
  1263. this->Target->GetSafeProperty("AUTOMOC_MACRO_NAMES"));
  1264. ofs.Write("AM_MOC_DEPEND_FILTERS",
  1265. this->Target->GetSafeProperty("AUTOMOC_DEPEND_FILTERS"));
  1266. ofs.Write("AM_MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
  1267. }
  1268. // Write uic settings
  1269. if (this->Uic.Enabled) {
  1270. // Add skipped .ui files
  1271. uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end());
  1272. ofs.Write("# UIC settings\n");
  1273. ofs.WriteStrings("AM_UIC_SKIP", uic_skip);
  1274. ofs.WriteStrings("AM_UIC_TARGET_OPTIONS", this->Uic.Options);
  1275. ofs.WriteConfigStrings("AM_UIC_TARGET_OPTIONS", this->Uic.ConfigOptions);
  1276. ofs.WriteStrings("AM_UIC_OPTIONS_FILES", this->Uic.FileFiles);
  1277. ofs.WriteNestedLists("AM_UIC_OPTIONS_OPTIONS", this->Uic.FileOptions);
  1278. ofs.WriteStrings("AM_UIC_SEARCH_PATHS", this->Uic.SearchPaths);
  1279. }
  1280. } else {
  1281. cmSystemTools::Error(cmStrCat("AutoGen: Could not write file ",
  1282. this->AutogenTarget.InfoFile));
  1283. return false;
  1284. }
  1285. return true;
  1286. }
  1287. bool cmQtAutoGenInitializer::SetupWriteRccInfo()
  1288. {
  1289. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1290. InfoWriter ofs(qrc.InfoFile);
  1291. if (ofs) {
  1292. // Write
  1293. ofs.Write("# Configurations\n");
  1294. ofs.Write("ARCC_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE");
  1295. ofs.Write("ARCC_VERBOSITY", this->Verbosity);
  1296. ofs.Write("# Settings file\n");
  1297. ofs.Write("ARCC_SETTINGS_FILE", qrc.SettingsFile);
  1298. ofs.WriteConfig("ARCC_SETTINGS_FILE", qrc.ConfigSettingsFile);
  1299. ofs.Write("# Directories\n");
  1300. ofs.Write("ARCC_BUILD_DIR", this->Dir.Build);
  1301. ofs.Write("ARCC_INCLUDE_DIR", this->Dir.Include);
  1302. ofs.WriteConfig("ARCC_INCLUDE_DIR", this->Dir.ConfigInclude);
  1303. ofs.Write("# Rcc executable\n");
  1304. ofs.Write("ARCC_RCC_EXECUTABLE", this->Rcc.Executable);
  1305. ofs.WriteStrings("ARCC_RCC_LIST_OPTIONS",
  1306. this->Rcc.ExecutableFeatures->ListOptions);
  1307. ofs.Write("# Rcc job\n");
  1308. ofs.Write("ARCC_LOCK_FILE", qrc.LockFile);
  1309. ofs.Write("ARCC_SOURCE", qrc.QrcFile);
  1310. ofs.Write("ARCC_OUTPUT_CHECKSUM", qrc.PathChecksum);
  1311. ofs.Write("ARCC_OUTPUT_NAME",
  1312. cmSystemTools::GetFilenameName(qrc.RccFile));
  1313. ofs.WriteStrings("ARCC_OPTIONS", qrc.Options);
  1314. ofs.WriteStrings("ARCC_INPUTS", qrc.Resources);
  1315. } else {
  1316. cmSystemTools::Error(
  1317. cmStrCat("AutoRcc: Could not write file ", qrc.InfoFile));
  1318. return false;
  1319. }
  1320. }
  1321. return true;
  1322. }
  1323. void cmQtAutoGenInitializer::RegisterGeneratedSource(
  1324. std::string const& filename)
  1325. {
  1326. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1327. cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true);
  1328. gFile->SetProperty("GENERATED", "1");
  1329. gFile->SetProperty("SKIP_AUTOGEN", "1");
  1330. }
  1331. bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
  1332. GenVarsT const& genVars,
  1333. bool prepend)
  1334. {
  1335. // Register source at makefile
  1336. this->RegisterGeneratedSource(filename);
  1337. // Add source file to target
  1338. this->Target->AddSource(filename, prepend);
  1339. // Add source file to source group
  1340. return this->AddToSourceGroup(filename, genVars.GenNameUpper);
  1341. }
  1342. bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
  1343. std::string const& genNameUpper)
  1344. {
  1345. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1346. cmSourceGroup* sourceGroup = nullptr;
  1347. // Acquire source group
  1348. {
  1349. std::string property;
  1350. std::string groupName;
  1351. {
  1352. // Prefer generator specific source group name
  1353. std::array<std::string, 2> props{ { genNameUpper + "_SOURCE_GROUP",
  1354. "AUTOGEN_SOURCE_GROUP" } };
  1355. for (std::string& prop : props) {
  1356. const char* propName = makefile->GetState()->GetGlobalProperty(prop);
  1357. if ((propName != nullptr) && (*propName != '\0')) {
  1358. groupName = propName;
  1359. property = std::move(prop);
  1360. break;
  1361. }
  1362. }
  1363. }
  1364. // Generate a source group on demand
  1365. if (!groupName.empty()) {
  1366. sourceGroup = makefile->GetOrCreateSourceGroup(groupName);
  1367. if (sourceGroup == nullptr) {
  1368. cmSystemTools::Error(
  1369. cmStrCat(genNameUpper, " error in ", property,
  1370. ": Could not find or create the source group ",
  1371. cmQtAutoGen::Quoted(groupName)));
  1372. return false;
  1373. }
  1374. }
  1375. }
  1376. if (sourceGroup != nullptr) {
  1377. sourceGroup->AddGroupFile(fileName);
  1378. }
  1379. return true;
  1380. }
  1381. void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
  1382. {
  1383. Target->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName.c_str(),
  1384. false);
  1385. }
  1386. static unsigned int CharPtrToUInt(const char* const input)
  1387. {
  1388. unsigned long tmp = 0;
  1389. if (input != nullptr && cmStrToULong(input, &tmp)) {
  1390. return static_cast<unsigned int>(tmp);
  1391. }
  1392. return 0;
  1393. }
  1394. static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
  1395. cmGeneratorTarget const* target)
  1396. {
  1397. // Qt version variable prefixes
  1398. static std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core",
  1399. "QT" } };
  1400. std::vector<cmQtAutoGen::IntegerVersion> result;
  1401. result.reserve(prefixes.size() * 2);
  1402. // Adds a version to the result (nullptr safe)
  1403. auto addVersion = [&result](const char* major, const char* minor) {
  1404. cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major),
  1405. CharPtrToUInt(minor));
  1406. if (ver.Major != 0) {
  1407. result.emplace_back(ver);
  1408. }
  1409. };
  1410. cmMakefile* makefile = target->Target->GetMakefile();
  1411. // Read versions from variables
  1412. for (const std::string& prefix : prefixes) {
  1413. addVersion(makefile->GetDefinition(prefix + "_VERSION_MAJOR"),
  1414. makefile->GetDefinition(prefix + "_VERSION_MINOR"));
  1415. }
  1416. // Read versions from directory properties
  1417. for (const std::string& prefix : prefixes) {
  1418. addVersion(makefile->GetProperty(prefix + "_VERSION_MAJOR"),
  1419. makefile->GetProperty(prefix + "_VERSION_MINOR"));
  1420. }
  1421. return result;
  1422. }
  1423. std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
  1424. cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target)
  1425. {
  1426. std::pair<IntegerVersion, unsigned int> res(
  1427. IntegerVersion(),
  1428. CharPtrToUInt(target->GetLinkInterfaceDependentStringProperty(
  1429. "QT_MAJOR_VERSION", "")));
  1430. auto knownQtVersions = GetKnownQtVersions(target);
  1431. if (!knownQtVersions.empty()) {
  1432. if (res.second == 0) {
  1433. // No specific version was requested by the target:
  1434. // Use highest known Qt version.
  1435. res.first = knownQtVersions.at(0);
  1436. } else {
  1437. // Pick a version from the known versions:
  1438. for (auto it : knownQtVersions) {
  1439. if (it.Major == res.second) {
  1440. res.first = it;
  1441. break;
  1442. }
  1443. }
  1444. }
  1445. }
  1446. return res;
  1447. }
  1448. bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
  1449. const std::string& executable,
  1450. bool ignoreMissingTarget) const
  1451. {
  1452. auto print_err = [this, &genVars](std::string const& err) {
  1453. cmSystemTools::Error(cmStrCat(genVars.GenNameUpper, " for target ",
  1454. this->Target->GetName(), ": ", err));
  1455. };
  1456. // Custom executable
  1457. {
  1458. std::string const prop = genVars.GenNameUpper + "_EXECUTABLE";
  1459. std::string const val = this->Target->Target->GetSafeProperty(prop);
  1460. if (!val.empty()) {
  1461. // Evaluate generator expression
  1462. {
  1463. cmListFileBacktrace lfbt =
  1464. this->Target->Target->GetMakefile()->GetBacktrace();
  1465. cmGeneratorExpression ge(lfbt);
  1466. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
  1467. genVars.Executable =
  1468. cge->Evaluate(this->Target->GetLocalGenerator(), "");
  1469. }
  1470. if (genVars.Executable.empty() && !ignoreMissingTarget) {
  1471. print_err(prop + " evaluates to an empty value");
  1472. return false;
  1473. }
  1474. // Create empty compiler features.
  1475. genVars.ExecutableFeatures =
  1476. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1477. return true;
  1478. }
  1479. }
  1480. // Find executable target
  1481. {
  1482. // Find executable target name
  1483. std::string targetName;
  1484. if (this->QtVersion.Major == 4) {
  1485. targetName = "Qt4::";
  1486. } else if (this->QtVersion.Major == 5) {
  1487. targetName = "Qt5::";
  1488. } else if (this->QtVersion.Major == 6) {
  1489. targetName = "Qt6::";
  1490. }
  1491. targetName += executable;
  1492. // Find target
  1493. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  1494. cmGeneratorTarget* target = localGen->FindGeneratorTargetToUse(targetName);
  1495. if (target != nullptr) {
  1496. genVars.ExecutableTargetName = targetName;
  1497. genVars.ExecutableTarget = target;
  1498. if (target->IsImported()) {
  1499. genVars.Executable = target->ImportedGetLocation("");
  1500. } else {
  1501. genVars.Executable = target->GetLocation("");
  1502. }
  1503. } else {
  1504. if (ignoreMissingTarget) {
  1505. // Create empty compiler features.
  1506. genVars.ExecutableFeatures =
  1507. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1508. return true;
  1509. }
  1510. print_err(cmStrCat("Could not find ", executable, " executable target ",
  1511. targetName));
  1512. return false;
  1513. }
  1514. }
  1515. // Get executable features
  1516. {
  1517. std::string err;
  1518. genVars.ExecutableFeatures = this->GlobalInitializer->GetCompilerFeatures(
  1519. executable, genVars.Executable, err);
  1520. if (!genVars.ExecutableFeatures) {
  1521. print_err(err);
  1522. return false;
  1523. }
  1524. }
  1525. return true;
  1526. }