cmQtAutoGenInitializer.cxx 56 KB

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