cmQtAutoGenInitializer.cxx 56 KB

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