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 void AddCleanFile(cmMakefile* makefile, std::string const& fileName)
  52. {
  53. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(),
  54. false);
  55. }
  56. static std::string FileProjectRelativePath(cmMakefile* makefile,
  57. std::string const& fileName)
  58. {
  59. std::string res;
  60. {
  61. std::string pSource = cmSystemTools::RelativePath(
  62. makefile->GetCurrentSourceDirectory(), fileName);
  63. std::string pBinary = cmSystemTools::RelativePath(
  64. makefile->GetCurrentBinaryDirectory(), fileName);
  65. if (pSource.size() < pBinary.size()) {
  66. res = std::move(pSource);
  67. } else if (pBinary.size() < fileName.size()) {
  68. res = std::move(pBinary);
  69. } else {
  70. res = fileName;
  71. }
  72. }
  73. return res;
  74. }
  75. /**
  76. * Tests if targetDepend is a STATIC_LIBRARY and if any of its
  77. * recursive STATIC_LIBRARY dependencies depends on targetOrigin
  78. * (STATIC_LIBRARY cycle).
  79. */
  80. static bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
  81. cmGeneratorTarget const* targetDepend,
  82. std::string const& config)
  83. {
  84. bool cycle = false;
  85. if ((targetOrigin->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  86. (targetDepend->GetType() == cmStateEnums::STATIC_LIBRARY)) {
  87. std::set<cmGeneratorTarget const*> knownLibs;
  88. std::deque<cmGeneratorTarget const*> testLibs;
  89. // Insert initial static_library dependency
  90. knownLibs.insert(targetDepend);
  91. testLibs.push_back(targetDepend);
  92. while (!testLibs.empty()) {
  93. cmGeneratorTarget const* testTarget = testLibs.front();
  94. testLibs.pop_front();
  95. // Check if the test target is the origin target (cycle)
  96. if (testTarget == targetOrigin) {
  97. cycle = true;
  98. break;
  99. }
  100. // Collect all static_library dependencies from the test target
  101. cmLinkImplementationLibraries const* libs =
  102. testTarget->GetLinkImplementationLibraries(config);
  103. if (libs != nullptr) {
  104. for (cmLinkItem const& item : libs->Libraries) {
  105. cmGeneratorTarget const* depTarget = item.Target;
  106. if ((depTarget != nullptr) &&
  107. (depTarget->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  108. knownLibs.insert(depTarget).second) {
  109. testLibs.push_back(depTarget);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. return cycle;
  116. }
  117. cmQtAutoGenInitializer::InfoWriter::InfoWriter(std::string const& filename)
  118. {
  119. Ofs_.SetCopyIfDifferent(true);
  120. Ofs_.Open(filename, false, true);
  121. }
  122. template <class IT>
  123. std::string cmQtAutoGenInitializer::InfoWriter::ListJoin(IT it_begin,
  124. IT it_end)
  125. {
  126. std::string res;
  127. for (IT it = it_begin; it != it_end; ++it) {
  128. if (it != it_begin) {
  129. res += ';';
  130. }
  131. for (const char* c = it->c_str(); *c; ++c) {
  132. if (*c == '"') {
  133. // Escape the double quote to avoid ending the argument.
  134. res += "\\\"";
  135. } else if (*c == '$') {
  136. // Escape the dollar to avoid expanding variables.
  137. res += "\\$";
  138. } else if (*c == '\\') {
  139. // Escape the backslash to avoid other escapes.
  140. res += "\\\\";
  141. } else if (*c == ';') {
  142. // Escape the semicolon to avoid list expansion.
  143. res += "\\;";
  144. } else {
  145. // Other characters will be parsed correctly.
  146. res += *c;
  147. }
  148. }
  149. }
  150. return res;
  151. }
  152. std::string cmQtAutoGenInitializer::InfoWriter::ConfigKey(
  153. const char* key, std::string const& config)
  154. {
  155. std::string ckey = key;
  156. ckey += '_';
  157. ckey += config;
  158. return ckey;
  159. }
  160. void cmQtAutoGenInitializer::InfoWriter::Write(const char* key,
  161. std::string const& value)
  162. {
  163. Ofs_ << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value)
  164. << ")\n";
  165. };
  166. void cmQtAutoGenInitializer::InfoWriter::WriteUInt(const char* key,
  167. unsigned int value)
  168. {
  169. Ofs_ << "set(" << key << " " << value << ")\n";
  170. };
  171. template <class C>
  172. void cmQtAutoGenInitializer::InfoWriter::WriteStrings(const char* key,
  173. C const& container)
  174. {
  175. Ofs_ << "set(" << key << " \""
  176. << ListJoin(container.begin(), container.end()) << "\")\n";
  177. }
  178. void cmQtAutoGenInitializer::InfoWriter::WriteConfig(
  179. const char* key, std::map<std::string, std::string> const& map)
  180. {
  181. for (auto const& item : map) {
  182. Write(ConfigKey(key, item.first).c_str(), item.second);
  183. }
  184. };
  185. template <class C>
  186. void cmQtAutoGenInitializer::InfoWriter::WriteConfigStrings(
  187. const char* key, std::map<std::string, C> const& map)
  188. {
  189. for (auto const& item : map) {
  190. WriteStrings(ConfigKey(key, item.first).c_str(), item.second);
  191. }
  192. }
  193. void cmQtAutoGenInitializer::InfoWriter::WriteNestedLists(
  194. const char* key, std::vector<std::vector<std::string>> const& lists)
  195. {
  196. std::vector<std::string> seplist;
  197. for (const std::vector<std::string>& list : lists) {
  198. std::string blist = "{";
  199. blist += ListJoin(list.begin(), list.end());
  200. blist += "}";
  201. seplist.push_back(std::move(blist));
  202. }
  203. Write(key, cmJoin(seplist, cmQtAutoGen::ListSep));
  204. };
  205. cmQtAutoGenInitializer::cmQtAutoGenInitializer(
  206. cmQtAutoGenGlobalInitializer* globalInitializer, cmGeneratorTarget* target,
  207. IntegerVersion const& qtVersion, bool mocEnabled, bool uicEnabled,
  208. bool rccEnabled, bool globalAutogenTarget, bool globalAutoRccTarget)
  209. : GlobalInitializer(globalInitializer)
  210. , Target(target)
  211. , QtVersion(qtVersion)
  212. {
  213. AutogenTarget.GlobalTarget = globalAutogenTarget;
  214. Moc.Enabled = mocEnabled;
  215. Uic.Enabled = uicEnabled;
  216. Rcc.Enabled = rccEnabled;
  217. Rcc.GlobalTarget = globalAutoRccTarget;
  218. }
  219. bool cmQtAutoGenInitializer::InitCustomTargets()
  220. {
  221. cmMakefile* makefile = this->Target->Target->GetMakefile();
  222. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  223. cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator();
  224. // Configurations
  225. this->MultiConfig = globalGen->IsMultiConfig();
  226. this->ConfigDefault = makefile->GetConfigurations(this->ConfigsList);
  227. if (this->ConfigsList.empty()) {
  228. this->ConfigsList.push_back(this->ConfigDefault);
  229. }
  230. // Verbosity
  231. this->Verbosity = makefile->GetSafeDefinition("CMAKE_AUTOGEN_VERBOSE");
  232. if (!this->Verbosity.empty()) {
  233. unsigned long iVerb = 0;
  234. if (!cmSystemTools::StringToULong(this->Verbosity.c_str(), &iVerb)) {
  235. // Non numeric verbosity
  236. this->Verbosity = cmSystemTools::IsOn(this->Verbosity) ? "1" : "0";
  237. }
  238. }
  239. // Targets FOLDER
  240. {
  241. const char* folder =
  242. makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  243. if (folder == nullptr) {
  244. folder =
  245. makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
  246. }
  247. // Inherit FOLDER property from target (#13688)
  248. if (folder == nullptr) {
  249. folder = this->Target->GetProperty("FOLDER");
  250. }
  251. if (folder != nullptr) {
  252. this->TargetsFolder = folder;
  253. }
  254. }
  255. // Check status of policy CMP0071
  256. {
  257. cmPolicies::PolicyStatus const CMP0071_status =
  258. makefile->GetPolicyStatus(cmPolicies::CMP0071);
  259. switch (CMP0071_status) {
  260. case cmPolicies::WARN:
  261. this->CMP0071Warn = true;
  262. CM_FALLTHROUGH;
  263. case cmPolicies::OLD:
  264. // Ignore GENERATED file
  265. break;
  266. case cmPolicies::REQUIRED_IF_USED:
  267. case cmPolicies::REQUIRED_ALWAYS:
  268. case cmPolicies::NEW:
  269. // Process GENERATED file
  270. this->CMP0071Accept = true;
  271. break;
  272. }
  273. }
  274. // Common directories
  275. {
  276. // Collapsed current binary directory
  277. std::string const cbd = cmSystemTools::CollapseFullPath(
  278. std::string(), makefile->GetCurrentBinaryDirectory());
  279. // Info directory
  280. this->Dir.Info = cbd;
  281. this->Dir.Info += "/CMakeFiles";
  282. this->Dir.Info += '/';
  283. this->Dir.Info += this->Target->GetName();
  284. this->Dir.Info += "_autogen";
  285. this->Dir.Info += ".dir";
  286. cmSystemTools::ConvertToUnixSlashes(this->Dir.Info);
  287. // Build directory
  288. this->Dir.Build = this->Target->GetSafeProperty("AUTOGEN_BUILD_DIR");
  289. if (this->Dir.Build.empty()) {
  290. this->Dir.Build = cbd;
  291. this->Dir.Build += '/';
  292. this->Dir.Build += this->Target->GetName();
  293. this->Dir.Build += "_autogen";
  294. }
  295. cmSystemTools::ConvertToUnixSlashes(this->Dir.Build);
  296. // Cleanup build directory
  297. AddCleanFile(makefile, this->Dir.Build);
  298. // Working directory
  299. this->Dir.Work = cbd;
  300. cmSystemTools::ConvertToUnixSlashes(this->Dir.Work);
  301. // Include directory
  302. this->Dir.Include = this->Dir.Build;
  303. this->Dir.Include += "/include";
  304. if (this->MultiConfig) {
  305. this->Dir.Include += "_$<CONFIG>";
  306. }
  307. // Per config include directories
  308. if (this->MultiConfig) {
  309. for (std::string const& cfg : this->ConfigsList) {
  310. std::string& dir = this->Dir.ConfigInclude[cfg];
  311. dir = this->Dir.Build;
  312. dir += "/include_";
  313. dir += cfg;
  314. }
  315. }
  316. }
  317. // Moc, Uic and _autogen target settings
  318. if (this->MocOrUicEnabled()) {
  319. // Init moc specific settings
  320. if (this->Moc.Enabled && !InitMoc()) {
  321. return false;
  322. }
  323. // Init uic specific settings
  324. if (this->Uic.Enabled && !InitUic()) {
  325. return false;
  326. }
  327. // Autogen target name
  328. this->AutogenTarget.Name = this->Target->GetName();
  329. this->AutogenTarget.Name += "_autogen";
  330. // Autogen target parallel processing
  331. this->AutogenTarget.Parallel =
  332. this->Target->GetSafeProperty("AUTOGEN_PARALLEL");
  333. if (this->AutogenTarget.Parallel.empty() ||
  334. (this->AutogenTarget.Parallel == "AUTO")) {
  335. // Autodetect number of CPUs
  336. this->AutogenTarget.Parallel = std::to_string(GetParallelCPUCount());
  337. }
  338. // Autogen target info and settings files
  339. {
  340. this->AutogenTarget.InfoFile = this->Dir.Info;
  341. this->AutogenTarget.InfoFile += "/AutogenInfo.cmake";
  342. this->AutogenTarget.SettingsFile = this->Dir.Info;
  343. this->AutogenTarget.SettingsFile += "/AutogenOldSettings.txt";
  344. if (this->MultiConfig) {
  345. for (std::string const& cfg : this->ConfigsList) {
  346. std::string& filename = this->AutogenTarget.ConfigSettingsFile[cfg];
  347. filename =
  348. AppendFilenameSuffix(this->AutogenTarget.SettingsFile, "_" + cfg);
  349. AddCleanFile(makefile, filename);
  350. }
  351. } else {
  352. AddCleanFile(makefile, this->AutogenTarget.SettingsFile);
  353. }
  354. this->AutogenTarget.ParseCacheFile = this->Dir.Info;
  355. this->AutogenTarget.ParseCacheFile += "/ParseCache.txt";
  356. AddCleanFile(makefile, this->AutogenTarget.ParseCacheFile);
  357. }
  358. // Autogen target: Compute user defined dependencies
  359. {
  360. this->AutogenTarget.DependOrigin =
  361. this->Target->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
  362. std::string const deps =
  363. this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
  364. if (!deps.empty()) {
  365. std::vector<std::string> extraDeps;
  366. cmSystemTools::ExpandListArgument(deps, extraDeps);
  367. for (std::string const& depName : extraDeps) {
  368. // Allow target and file dependencies
  369. auto* depTarget = makefile->FindTargetToUse(depName);
  370. if (depTarget != nullptr) {
  371. this->AutogenTarget.DependTargets.insert(depTarget);
  372. } else {
  373. this->AutogenTarget.DependFiles.insert(depName);
  374. }
  375. }
  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, nullptr)) {
  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. cmSystemTools::ExpandListArgument(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, nullptr)) {
  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. std::string stdOut;
  532. if (!this->GetQtExecutable(this->Rcc, "rcc", false, &stdOut)) {
  533. return false;
  534. }
  535. // Evaluate test output
  536. if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
  537. if (stdOut.find("--list") != std::string::npos) {
  538. this->Rcc.ListOptions.emplace_back("--list");
  539. } else if (stdOut.find("-list") != std::string::npos) {
  540. this->Rcc.ListOptions.emplace_back("-list");
  541. }
  542. }
  543. }
  544. return true;
  545. }
  546. bool cmQtAutoGenInitializer::InitScanFiles()
  547. {
  548. cmMakefile* makefile = this->Target->Target->GetMakefile();
  549. auto const& kw = this->GlobalInitializer->kw();
  550. auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
  551. bool muIt) -> MUFileHandle {
  552. MUFileHandle muf = cm::make_unique<MUFile>();
  553. muf->RealPath = cmSystemTools::GetRealPath(fullPath);
  554. muf->SF = sf;
  555. muf->Generated = sf->GetIsGenerated();
  556. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  557. muf->SkipMoc = this->Moc.Enabled &&
  558. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC));
  559. muf->SkipUic = this->Uic.Enabled &&
  560. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  561. if (muIt) {
  562. muf->MocIt = this->Moc.Enabled && !muf->SkipMoc;
  563. muf->UicIt = this->Uic.Enabled && !muf->SkipUic;
  564. }
  565. return muf;
  566. };
  567. auto addMUFile = [&](MUFileHandle&& muf, bool isHeader) {
  568. if ((muf->MocIt || muf->UicIt) && muf->Generated) {
  569. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  570. }
  571. if (isHeader) {
  572. this->AutogenTarget.Headers.emplace(muf->SF, std::move(muf));
  573. } else {
  574. this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf));
  575. }
  576. };
  577. // Scan through target files
  578. {
  579. // Scan through target files
  580. std::vector<cmSourceFile*> srcFiles;
  581. this->Target->GetConfigCommonSourceFiles(srcFiles);
  582. for (cmSourceFile* sf : srcFiles) {
  583. // sf->GetExtension() is only valid after sf->GetFullPath() ...
  584. // Since we're iterating over source files that might be not in the
  585. // target we need to check for path errors (not existing files).
  586. std::string pathError;
  587. std::string const& fullPath = sf->GetFullPath(&pathError);
  588. if (!pathError.empty() || fullPath.empty()) {
  589. continue;
  590. }
  591. std::string const& ext = sf->GetExtension();
  592. // Register files that will be scanned by moc or uic
  593. if (this->MocOrUicEnabled()) {
  594. switch (cmSystemTools::GetFileFormat(ext)) {
  595. case cmSystemTools::HEADER_FILE_FORMAT:
  596. addMUFile(makeMUFile(sf, fullPath, true), true);
  597. break;
  598. case cmSystemTools::CXX_FILE_FORMAT:
  599. addMUFile(makeMUFile(sf, fullPath, true), false);
  600. break;
  601. default:
  602. break;
  603. }
  604. }
  605. // Register rcc enabled files
  606. if (this->Rcc.Enabled) {
  607. if ((ext == kw.qrc) && !sf->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
  608. !sf->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
  609. // Register qrc file
  610. Qrc qrc;
  611. qrc.QrcFile = cmSystemTools::GetRealPath(fullPath);
  612. qrc.QrcName =
  613. cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile);
  614. qrc.Generated = sf->GetIsGenerated();
  615. // RCC options
  616. {
  617. std::string const opts = sf->GetSafeProperty(kw.AUTORCC_OPTIONS);
  618. if (!opts.empty()) {
  619. cmSystemTools::ExpandListArgument(opts, qrc.Options);
  620. }
  621. }
  622. this->Rcc.Qrcs.push_back(std::move(qrc));
  623. }
  624. }
  625. }
  626. }
  627. // cmGeneratorTarget::GetConfigCommonSourceFiles computes the target's
  628. // sources meta data cache. Clear it so that OBJECT library targets that
  629. // are AUTOGEN initialized after this target get their added
  630. // mocs_compilation.cpp source acknowledged by this target.
  631. this->Target->ClearSourcesCache();
  632. // For source files find additional headers and private headers
  633. if (this->MocOrUicEnabled()) {
  634. std::vector<MUFileHandle> extraHeaders;
  635. extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2);
  636. // Header search suffixes and extensions
  637. std::array<std::string, 2> const suffixes{ { "", "_p" } };
  638. auto const& exts = makefile->GetCMakeInstance()->GetHeaderExtensions();
  639. // Scan through sources
  640. for (auto const& pair : this->AutogenTarget.Sources) {
  641. MUFile const& muf = *pair.second;
  642. if (muf.MocIt || muf.UicIt) {
  643. // Search for the default header file and a private header
  644. std::string const& realPath = muf.RealPath;
  645. std::string basePath = cmQtAutoGen::SubDirPrefix(realPath);
  646. basePath += cmSystemTools::GetFilenameWithoutLastExtension(realPath);
  647. for (auto const& suffix : suffixes) {
  648. std::string const suffixedPath = basePath + suffix;
  649. for (auto const& ext : exts) {
  650. std::string fullPath = suffixedPath;
  651. fullPath += '.';
  652. fullPath += ext;
  653. auto constexpr locationKind = cmSourceFileLocationKind::Known;
  654. cmSourceFile* sf = makefile->GetSource(fullPath, locationKind);
  655. if (sf != nullptr) {
  656. // Check if we know about this header already
  657. if (this->AutogenTarget.Headers.find(sf) !=
  658. this->AutogenTarget.Headers.end()) {
  659. continue;
  660. }
  661. // We only accept not-GENERATED files that do exist.
  662. if (!sf->GetIsGenerated() &&
  663. !cmSystemTools::FileExists(fullPath)) {
  664. continue;
  665. }
  666. } else if (cmSystemTools::FileExists(fullPath)) {
  667. // Create a new source file for the existing file
  668. sf = makefile->CreateSource(fullPath, false, locationKind);
  669. }
  670. if (sf != nullptr) {
  671. auto eMuf = makeMUFile(sf, fullPath, true);
  672. // Ony process moc/uic when the parent is processed as well
  673. if (!muf.MocIt) {
  674. eMuf->MocIt = false;
  675. }
  676. if (!muf.UicIt) {
  677. eMuf->UicIt = false;
  678. }
  679. extraHeaders.emplace_back(std::move(eMuf));
  680. }
  681. }
  682. }
  683. }
  684. }
  685. // Move generated files to main headers list
  686. for (auto& eMuf : extraHeaders) {
  687. addMUFile(std::move(eMuf), true);
  688. }
  689. }
  690. // Scan through all source files in the makefile to extract moc and uic
  691. // parameters. Historically we support non target source file parameters.
  692. // The reason is that their file names might be discovered from source files
  693. // at generation time.
  694. if (this->MocOrUicEnabled()) {
  695. for (cmSourceFile* sf : makefile->GetSourceFiles()) {
  696. // sf->GetExtension() is only valid after sf->GetFullPath() ...
  697. // Since we're iterating over source files that might be not in the
  698. // target we need to check for path errors (not existing files).
  699. std::string pathError;
  700. std::string const& fullPath = sf->GetFullPath(&pathError);
  701. if (!pathError.empty() || fullPath.empty()) {
  702. continue;
  703. }
  704. std::string const& ext = sf->GetExtension();
  705. auto const fileFormat = cmSystemTools::GetFileFormat(ext);
  706. if (fileFormat == cmSystemTools::HEADER_FILE_FORMAT) {
  707. if (this->AutogenTarget.Headers.find(sf) ==
  708. this->AutogenTarget.Headers.end()) {
  709. auto muf = makeMUFile(sf, fullPath, false);
  710. if (muf->SkipMoc || muf->SkipUic) {
  711. this->AutogenTarget.Headers.emplace(sf, std::move(muf));
  712. }
  713. }
  714. } else if (fileFormat == cmSystemTools::CXX_FILE_FORMAT) {
  715. if (this->AutogenTarget.Sources.find(sf) ==
  716. this->AutogenTarget.Sources.end()) {
  717. auto muf = makeMUFile(sf, fullPath, false);
  718. if (muf->SkipMoc || muf->SkipUic) {
  719. this->AutogenTarget.Sources.emplace(sf, std::move(muf));
  720. }
  721. }
  722. } else if (this->Uic.Enabled && (ext == kw.ui)) {
  723. // .ui file
  724. std::string realPath = cmSystemTools::GetRealPath(fullPath);
  725. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  726. bool const skipUic =
  727. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  728. if (!skipUic) {
  729. // Check if the .ui file has uic options
  730. std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS);
  731. if (!uicOpts.empty()) {
  732. this->Uic.FileFiles.push_back(std::move(realPath));
  733. std::vector<std::string> optsVec;
  734. cmSystemTools::ExpandListArgument(uicOpts, optsVec);
  735. this->Uic.FileOptions.push_back(std::move(optsVec));
  736. }
  737. } else {
  738. // Register skipped .ui file
  739. this->Uic.SkipUi.insert(std::move(realPath));
  740. }
  741. }
  742. }
  743. }
  744. // Process GENERATED sources and headers
  745. if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) {
  746. if (this->CMP0071Accept) {
  747. // Let the autogen target depend on the GENERATED files
  748. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  749. this->AutogenTarget.DependFiles.insert(muf->RealPath);
  750. }
  751. } else if (this->CMP0071Warn) {
  752. std::string msg;
  753. msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071);
  754. msg += '\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. cmSystemTools::ExpandListArgument(
  788. this->Target->GetSafeProperty(kw.AUTORCC_OPTIONS), 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. {
  806. std::string rccFile = this->Dir.Build + "/";
  807. rccFile += qrc.PathChecksum;
  808. rccFile += "/qrc_";
  809. rccFile += qrc.QrcName;
  810. rccFile += ".cpp";
  811. qrc.RccFile = std::move(rccFile);
  812. }
  813. {
  814. std::string base = this->Dir.Info;
  815. base += "/RCC";
  816. base += qrc.QrcName;
  817. if (!qrc.Unique) {
  818. base += qrc.PathChecksum;
  819. }
  820. qrc.LockFile = base;
  821. qrc.LockFile += ".lock";
  822. qrc.InfoFile = base;
  823. qrc.InfoFile += "Info.cmake";
  824. qrc.SettingsFile = base;
  825. qrc.SettingsFile += "Settings.txt";
  826. if (this->MultiConfig) {
  827. for (std::string const& cfg : this->ConfigsList) {
  828. qrc.ConfigSettingsFile[cfg] =
  829. AppendFilenameSuffix(qrc.SettingsFile, "_" + cfg);
  830. }
  831. }
  832. }
  833. }
  834. }
  835. // RCC options
  836. for (Qrc& qrc : this->Rcc.Qrcs) {
  837. // Target options
  838. std::vector<std::string> opts = optionsTarget;
  839. // Merge computed "-name XYZ" option
  840. {
  841. std::string name = qrc.QrcName;
  842. // Replace '-' with '_'. The former is not valid for symbol names.
  843. std::replace(name.begin(), name.end(), '-', '_');
  844. if (!qrc.Unique) {
  845. name += "_";
  846. name += qrc.PathChecksum;
  847. }
  848. std::vector<std::string> nameOpts;
  849. nameOpts.emplace_back("-name");
  850. nameOpts.emplace_back(std::move(name));
  851. RccMergeOptions(opts, nameOpts, modernQt);
  852. }
  853. // Merge file option
  854. RccMergeOptions(opts, qrc.Options, modernQt);
  855. qrc.Options = std::move(opts);
  856. }
  857. // RCC resources
  858. for (Qrc& qrc : this->Rcc.Qrcs) {
  859. if (!qrc.Generated) {
  860. std::string error;
  861. RccLister const lister(this->Rcc.Executable, this->Rcc.ListOptions);
  862. if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
  863. cmSystemTools::Error(error);
  864. return false;
  865. }
  866. }
  867. }
  868. }
  869. return true;
  870. }
  871. bool cmQtAutoGenInitializer::InitAutogenTarget()
  872. {
  873. cmMakefile* makefile = this->Target->Target->GetMakefile();
  874. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  875. cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator();
  876. // Register info file as generated by CMake
  877. makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
  878. // Files provided by the autogen target
  879. std::vector<std::string> autogenProvides;
  880. if (this->Moc.Enabled) {
  881. this->AddGeneratedSource(this->Moc.MocsCompilation, this->Moc, true);
  882. autogenProvides.push_back(this->Moc.MocsCompilation);
  883. }
  884. // Compose target comment
  885. std::string autogenComment;
  886. {
  887. std::string tools;
  888. if (this->Moc.Enabled) {
  889. tools += "MOC";
  890. }
  891. if (this->Uic.Enabled) {
  892. if (!tools.empty()) {
  893. tools += " and ";
  894. }
  895. tools += "UIC";
  896. }
  897. autogenComment = "Automatic ";
  898. autogenComment += tools;
  899. autogenComment += " for target ";
  900. autogenComment += this->Target->GetName();
  901. }
  902. // Compose command lines
  903. cmCustomCommandLines commandLines;
  904. {
  905. cmCustomCommandLine currentLine;
  906. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  907. currentLine.push_back("-E");
  908. currentLine.push_back("cmake_autogen");
  909. currentLine.push_back(this->AutogenTarget.InfoFile);
  910. currentLine.push_back("$<CONFIGURATION>");
  911. commandLines.push_back(std::move(currentLine));
  912. }
  913. // Use PRE_BUILD on demand
  914. bool usePRE_BUILD = false;
  915. if (globalGen->GetName().find("Visual Studio") != std::string::npos) {
  916. // Under VS use a PRE_BUILD event instead of a separate target to
  917. // reduce the number of targets loaded into the IDE.
  918. // This also works around a VS 11 bug that may skip updating the target:
  919. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  920. usePRE_BUILD = true;
  921. }
  922. // Disable PRE_BUILD in some cases
  923. if (usePRE_BUILD) {
  924. // Cannot use PRE_BUILD with file depends
  925. if (!this->AutogenTarget.DependFiles.empty()) {
  926. usePRE_BUILD = false;
  927. }
  928. // Cannot use PRE_BUILD when a global autogen target is in place
  929. if (AutogenTarget.GlobalTarget) {
  930. usePRE_BUILD = false;
  931. }
  932. }
  933. // Create the autogen target/command
  934. if (usePRE_BUILD) {
  935. // Add additional autogen target dependencies to origin target
  936. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  937. this->Target->Target->AddUtility(depTarget->GetName(), makefile);
  938. }
  939. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  940. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  941. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  942. //
  943. // PRE_BUILD does not support file dependencies!
  944. const std::vector<std::string> no_output;
  945. const std::vector<std::string> no_deps;
  946. cmCustomCommand cc(makefile, no_output, autogenProvides, no_deps,
  947. commandLines, autogenComment.c_str(),
  948. this->Dir.Work.c_str());
  949. cc.SetEscapeOldStyle(false);
  950. cc.SetEscapeAllowMakeVars(true);
  951. this->Target->Target->AddPreBuildCommand(cc);
  952. } else {
  953. // Add link library target dependencies to the autogen target
  954. // dependencies
  955. if (this->AutogenTarget.DependOrigin) {
  956. // add_dependencies/addUtility do not support generator expressions.
  957. // We depend only on the libraries found in all configs therefore.
  958. std::map<cmGeneratorTarget const*, std::size_t> commonTargets;
  959. for (std::string const& config : this->ConfigsList) {
  960. cmLinkImplementationLibraries const* libs =
  961. this->Target->GetLinkImplementationLibraries(config);
  962. if (libs != nullptr) {
  963. for (cmLinkItem const& item : libs->Libraries) {
  964. cmGeneratorTarget const* libTarget = item.Target;
  965. if ((libTarget != nullptr) &&
  966. !StaticLibraryCycle(this->Target, libTarget, config)) {
  967. // Increment target config count
  968. commonTargets[libTarget]++;
  969. }
  970. }
  971. }
  972. }
  973. for (auto const& item : commonTargets) {
  974. if (item.second == this->ConfigsList.size()) {
  975. this->AutogenTarget.DependTargets.insert(item.first->Target);
  976. }
  977. }
  978. }
  979. // Create autogen target
  980. cmTarget* autogenTarget = makefile->AddUtilityCommand(
  981. this->AutogenTarget.Name, cmMakefile::TargetOrigin::Generator, true,
  982. this->Dir.Work.c_str(), /*byproducts=*/autogenProvides,
  983. std::vector<std::string>(this->AutogenTarget.DependFiles.begin(),
  984. this->AutogenTarget.DependFiles.end()),
  985. commandLines, false, autogenComment.c_str());
  986. // Create autogen generator target
  987. localGen->AddGeneratorTarget(
  988. new cmGeneratorTarget(autogenTarget, localGen));
  989. // Forward origin utilities to autogen target
  990. if (this->AutogenTarget.DependOrigin) {
  991. for (BT<std::string> const& depName : this->Target->GetUtilities()) {
  992. autogenTarget->AddUtility(depName.Value, makefile);
  993. }
  994. }
  995. // Add additional autogen target dependencies to autogen target
  996. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  997. autogenTarget->AddUtility(depTarget->GetName(), makefile);
  998. }
  999. // Set FOLDER property in autogen target
  1000. if (!this->TargetsFolder.empty()) {
  1001. autogenTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
  1002. }
  1003. // Add autogen target to the origin target dependencies
  1004. this->Target->Target->AddUtility(this->AutogenTarget.Name, makefile);
  1005. // Add autogen target to the global autogen target dependencies
  1006. if (this->AutogenTarget.GlobalTarget) {
  1007. this->GlobalInitializer->AddToGlobalAutoGen(localGen,
  1008. this->AutogenTarget.Name);
  1009. }
  1010. }
  1011. return true;
  1012. }
  1013. bool cmQtAutoGenInitializer::InitRccTargets()
  1014. {
  1015. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1016. cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
  1017. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1018. // Register info file as generated by CMake
  1019. makefile->AddCMakeOutputFile(qrc.InfoFile);
  1020. // Register file at target
  1021. this->AddGeneratedSource(qrc.RccFile, this->Rcc);
  1022. std::vector<std::string> ccOutput;
  1023. ccOutput.push_back(qrc.RccFile);
  1024. std::vector<std::string> ccDepends;
  1025. // Add the .qrc and info file to the custom command dependencies
  1026. ccDepends.push_back(qrc.QrcFile);
  1027. ccDepends.push_back(qrc.InfoFile);
  1028. cmCustomCommandLines commandLines;
  1029. if (this->MultiConfig) {
  1030. // Build for all configurations
  1031. for (std::string const& config : this->ConfigsList) {
  1032. cmCustomCommandLine currentLine;
  1033. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  1034. currentLine.push_back("-E");
  1035. currentLine.push_back("cmake_autorcc");
  1036. currentLine.push_back(qrc.InfoFile);
  1037. currentLine.push_back(config);
  1038. commandLines.push_back(std::move(currentLine));
  1039. }
  1040. } else {
  1041. cmCustomCommandLine currentLine;
  1042. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  1043. currentLine.push_back("-E");
  1044. currentLine.push_back("cmake_autorcc");
  1045. currentLine.push_back(qrc.InfoFile);
  1046. currentLine.push_back("$<CONFIG>");
  1047. commandLines.push_back(std::move(currentLine));
  1048. }
  1049. std::string ccComment = "Automatic RCC for ";
  1050. ccComment += FileProjectRelativePath(makefile, qrc.QrcFile);
  1051. if (qrc.Generated || this->Rcc.GlobalTarget) {
  1052. // Create custom rcc target
  1053. std::string ccName;
  1054. {
  1055. ccName = this->Target->GetName();
  1056. ccName += "_arcc_";
  1057. ccName += qrc.QrcName;
  1058. if (!qrc.Unique) {
  1059. ccName += "_";
  1060. ccName += qrc.PathChecksum;
  1061. }
  1062. cmTarget* autoRccTarget = makefile->AddUtilityCommand(
  1063. ccName, cmMakefile::TargetOrigin::Generator, true,
  1064. this->Dir.Work.c_str(), ccOutput, ccDepends, commandLines, false,
  1065. ccComment.c_str());
  1066. // Create autogen generator target
  1067. localGen->AddGeneratorTarget(
  1068. new cmGeneratorTarget(autoRccTarget, localGen));
  1069. // Set FOLDER property in autogen target
  1070. if (!this->TargetsFolder.empty()) {
  1071. autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
  1072. }
  1073. if (!this->Rcc.ExecutableTargetName.empty()) {
  1074. autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, makefile);
  1075. }
  1076. }
  1077. // Add autogen target to the origin target dependencies
  1078. this->Target->Target->AddUtility(ccName, makefile);
  1079. // Add autogen target to the global autogen target dependencies
  1080. if (this->Rcc.GlobalTarget) {
  1081. this->GlobalInitializer->AddToGlobalAutoRcc(localGen, ccName);
  1082. }
  1083. } else {
  1084. // Create custom rcc command
  1085. {
  1086. std::vector<std::string> ccByproducts;
  1087. // Add the resource files to the dependencies
  1088. for (std::string const& fileName : qrc.Resources) {
  1089. // Add resource file to the custom command dependencies
  1090. ccDepends.push_back(fileName);
  1091. }
  1092. if (!this->Rcc.ExecutableTargetName.empty()) {
  1093. ccDepends.push_back(this->Rcc.ExecutableTargetName);
  1094. }
  1095. makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
  1096. /*main_dependency*/ std::string(),
  1097. commandLines, ccComment.c_str(),
  1098. this->Dir.Work.c_str());
  1099. }
  1100. // Reconfigure when .qrc file changes
  1101. makefile->AddCMakeDependFile(qrc.QrcFile);
  1102. }
  1103. }
  1104. return true;
  1105. }
  1106. bool cmQtAutoGenInitializer::SetupCustomTargets()
  1107. {
  1108. // Create info directory on demand
  1109. if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
  1110. std::string emsg = ("AutoGen: Could not create directory: ");
  1111. emsg += Quoted(this->Dir.Info);
  1112. cmSystemTools::Error(emsg);
  1113. return false;
  1114. }
  1115. // Generate autogen target info file
  1116. if (this->MocOrUicEnabled()) {
  1117. // Write autogen target info files
  1118. if (!this->SetupWriteAutogenInfo()) {
  1119. return false;
  1120. }
  1121. }
  1122. // Write AUTORCC info files
  1123. return !this->Rcc.Enabled || this->SetupWriteRccInfo();
  1124. }
  1125. bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
  1126. {
  1127. InfoWriter ofs(this->AutogenTarget.InfoFile);
  1128. if (ofs) {
  1129. // Utility lambdas
  1130. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1131. auto MfDef = [makefile](const char* key) {
  1132. return makefile->GetSafeDefinition(key);
  1133. };
  1134. // Write common settings
  1135. ofs.Write("# Meta\n");
  1136. ofs.Write("AM_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE");
  1137. ofs.Write("AM_PARALLEL", this->AutogenTarget.Parallel);
  1138. ofs.Write("AM_VERBOSITY", this->Verbosity);
  1139. ofs.Write("# Directories\n");
  1140. ofs.Write("AM_CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1141. ofs.Write("AM_CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1142. ofs.Write("AM_CMAKE_CURRENT_SOURCE_DIR",
  1143. MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1144. ofs.Write("AM_CMAKE_CURRENT_BINARY_DIR",
  1145. MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1146. ofs.Write("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE",
  1147. MfDef("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"));
  1148. ofs.Write("AM_BUILD_DIR", this->Dir.Build);
  1149. ofs.Write("AM_INCLUDE_DIR", this->Dir.Include);
  1150. ofs.WriteConfig("AM_INCLUDE_DIR", this->Dir.ConfigInclude);
  1151. std::vector<std::string> headers;
  1152. std::vector<std::string> headersFlags;
  1153. std::vector<std::string> headersBuildPaths;
  1154. std::vector<std::string> sources;
  1155. std::vector<std::string> sourcesFlags;
  1156. std::set<std::string> moc_skip;
  1157. std::set<std::string> uic_skip;
  1158. // Filter headers
  1159. {
  1160. auto headerCount = this->AutogenTarget.Headers.size();
  1161. headers.reserve(headerCount);
  1162. headersFlags.reserve(headerCount);
  1163. std::vector<MUFile const*> sortedHeaders;
  1164. {
  1165. sortedHeaders.reserve(headerCount);
  1166. for (auto const& pair : this->AutogenTarget.Headers) {
  1167. sortedHeaders.emplace_back(pair.second.get());
  1168. }
  1169. std::sort(sortedHeaders.begin(), sortedHeaders.end(),
  1170. [](MUFile const* a, MUFile const* b) {
  1171. return (a->RealPath < b->RealPath);
  1172. });
  1173. }
  1174. for (MUFile const* const muf : sortedHeaders) {
  1175. if (muf->Generated && !this->CMP0071Accept) {
  1176. continue;
  1177. }
  1178. if (muf->SkipMoc) {
  1179. moc_skip.insert(muf->RealPath);
  1180. }
  1181. if (muf->SkipUic) {
  1182. uic_skip.insert(muf->RealPath);
  1183. }
  1184. if (muf->MocIt || muf->UicIt) {
  1185. headers.emplace_back(muf->RealPath);
  1186. std::string flags;
  1187. flags += muf->MocIt ? 'M' : 'm';
  1188. flags += muf->UicIt ? 'U' : 'u';
  1189. headersFlags.emplace_back(std::move(flags));
  1190. }
  1191. }
  1192. }
  1193. // Header build paths
  1194. {
  1195. cmFilePathChecksum const fpathCheckSum(makefile);
  1196. std::unordered_set<std::string> emitted;
  1197. for (std::string const& hdr : headers) {
  1198. std::string basePath = fpathCheckSum.getPart(hdr);
  1199. basePath += "/moc_";
  1200. basePath += cmSystemTools::GetFilenameWithoutLastExtension(hdr);
  1201. for (unsigned int ii = 1; ii != 1024; ++ii) {
  1202. std::string path = basePath;
  1203. if (ii > 1) {
  1204. path += '_';
  1205. path += std::to_string(ii);
  1206. }
  1207. path += ".cpp";
  1208. if (emitted.emplace(path).second) {
  1209. headersBuildPaths.emplace_back(std::move(path));
  1210. break;
  1211. }
  1212. }
  1213. }
  1214. }
  1215. // Filter sources
  1216. {
  1217. auto sourcesCount = this->AutogenTarget.Sources.size();
  1218. sources.reserve(sourcesCount);
  1219. sourcesFlags.reserve(sourcesCount);
  1220. std::vector<MUFile const*> sorted;
  1221. sorted.reserve(sourcesCount);
  1222. for (auto const& pair : this->AutogenTarget.Sources) {
  1223. sorted.emplace_back(pair.second.get());
  1224. }
  1225. std::sort(sorted.begin(), sorted.end(),
  1226. [](MUFile const* a, MUFile const* b) {
  1227. return (a->RealPath < b->RealPath);
  1228. });
  1229. for (MUFile const* const muf : sorted) {
  1230. if (muf->Generated && !this->CMP0071Accept) {
  1231. continue;
  1232. }
  1233. if (muf->SkipMoc) {
  1234. moc_skip.insert(muf->RealPath);
  1235. }
  1236. if (muf->SkipUic) {
  1237. uic_skip.insert(muf->RealPath);
  1238. }
  1239. if (muf->MocIt || muf->UicIt) {
  1240. sources.emplace_back(muf->RealPath);
  1241. std::string flags;
  1242. flags += muf->MocIt ? 'M' : 'm';
  1243. flags += muf->UicIt ? 'U' : 'u';
  1244. sourcesFlags.emplace_back(std::move(flags));
  1245. }
  1246. }
  1247. }
  1248. ofs.Write("# Qt\n");
  1249. ofs.WriteUInt("AM_QT_VERSION_MAJOR", this->QtVersion.Major);
  1250. ofs.Write("AM_QT_MOC_EXECUTABLE", this->Moc.Executable);
  1251. ofs.Write("AM_QT_UIC_EXECUTABLE", this->Uic.Executable);
  1252. ofs.Write("# Files\n");
  1253. ofs.Write("AM_CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand());
  1254. ofs.Write("AM_SETTINGS_FILE", this->AutogenTarget.SettingsFile);
  1255. ofs.WriteConfig("AM_SETTINGS_FILE",
  1256. this->AutogenTarget.ConfigSettingsFile);
  1257. ofs.Write("AM_PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
  1258. ofs.WriteStrings("AM_HEADERS", headers);
  1259. ofs.WriteStrings("AM_HEADERS_FLAGS", headersFlags);
  1260. ofs.WriteStrings("AM_HEADERS_BUILD_PATHS", headersBuildPaths);
  1261. ofs.WriteStrings("AM_SOURCES", sources);
  1262. ofs.WriteStrings("AM_SOURCES_FLAGS", sourcesFlags);
  1263. // Write moc settings
  1264. if (this->Moc.Enabled) {
  1265. ofs.Write("# MOC settings\n");
  1266. ofs.WriteStrings("AM_MOC_SKIP", moc_skip);
  1267. ofs.WriteStrings("AM_MOC_DEFINITIONS", this->Moc.Defines);
  1268. ofs.WriteConfigStrings("AM_MOC_DEFINITIONS", this->Moc.ConfigDefines);
  1269. ofs.WriteStrings("AM_MOC_INCLUDES", this->Moc.Includes);
  1270. ofs.WriteConfigStrings("AM_MOC_INCLUDES", this->Moc.ConfigIncludes);
  1271. ofs.Write("AM_MOC_OPTIONS",
  1272. this->Target->GetSafeProperty("AUTOMOC_MOC_OPTIONS"));
  1273. ofs.Write("AM_MOC_RELAXED_MODE", MfDef("CMAKE_AUTOMOC_RELAXED_MODE"));
  1274. ofs.Write("AM_MOC_MACRO_NAMES",
  1275. this->Target->GetSafeProperty("AUTOMOC_MACRO_NAMES"));
  1276. ofs.Write("AM_MOC_DEPEND_FILTERS",
  1277. this->Target->GetSafeProperty("AUTOMOC_DEPEND_FILTERS"));
  1278. ofs.Write("AM_MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
  1279. }
  1280. // Write uic settings
  1281. if (this->Uic.Enabled) {
  1282. // Add skipped .ui files
  1283. uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end());
  1284. ofs.Write("# UIC settings\n");
  1285. ofs.WriteStrings("AM_UIC_SKIP", uic_skip);
  1286. ofs.WriteStrings("AM_UIC_TARGET_OPTIONS", this->Uic.Options);
  1287. ofs.WriteConfigStrings("AM_UIC_TARGET_OPTIONS", this->Uic.ConfigOptions);
  1288. ofs.WriteStrings("AM_UIC_OPTIONS_FILES", this->Uic.FileFiles);
  1289. ofs.WriteNestedLists("AM_UIC_OPTIONS_OPTIONS", this->Uic.FileOptions);
  1290. ofs.WriteStrings("AM_UIC_SEARCH_PATHS", this->Uic.SearchPaths);
  1291. }
  1292. } else {
  1293. std::string err = "AutoGen: Could not write file ";
  1294. err += this->AutogenTarget.InfoFile;
  1295. cmSystemTools::Error(err);
  1296. return false;
  1297. }
  1298. return true;
  1299. }
  1300. bool cmQtAutoGenInitializer::SetupWriteRccInfo()
  1301. {
  1302. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1303. InfoWriter ofs(qrc.InfoFile);
  1304. if (ofs) {
  1305. // Write
  1306. ofs.Write("# Configurations\n");
  1307. ofs.Write("ARCC_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE");
  1308. ofs.Write("ARCC_VERBOSITY", this->Verbosity);
  1309. ofs.Write("# Settings file\n");
  1310. ofs.Write("ARCC_SETTINGS_FILE", qrc.SettingsFile);
  1311. ofs.WriteConfig("ARCC_SETTINGS_FILE", qrc.ConfigSettingsFile);
  1312. ofs.Write("# Directories\n");
  1313. ofs.Write("ARCC_BUILD_DIR", this->Dir.Build);
  1314. ofs.Write("ARCC_INCLUDE_DIR", this->Dir.Include);
  1315. ofs.WriteConfig("ARCC_INCLUDE_DIR", this->Dir.ConfigInclude);
  1316. ofs.Write("# Rcc executable\n");
  1317. ofs.Write("ARCC_RCC_EXECUTABLE", this->Rcc.Executable);
  1318. ofs.WriteStrings("ARCC_RCC_LIST_OPTIONS", this->Rcc.ListOptions);
  1319. ofs.Write("# Rcc job\n");
  1320. ofs.Write("ARCC_LOCK_FILE", qrc.LockFile);
  1321. ofs.Write("ARCC_SOURCE", qrc.QrcFile);
  1322. ofs.Write("ARCC_OUTPUT_CHECKSUM", qrc.PathChecksum);
  1323. ofs.Write("ARCC_OUTPUT_NAME",
  1324. cmSystemTools::GetFilenameName(qrc.RccFile));
  1325. ofs.WriteStrings("ARCC_OPTIONS", qrc.Options);
  1326. ofs.WriteStrings("ARCC_INPUTS", qrc.Resources);
  1327. } else {
  1328. std::string err = "AutoRcc: Could not write file ";
  1329. err += qrc.InfoFile;
  1330. cmSystemTools::Error(err);
  1331. return false;
  1332. }
  1333. }
  1334. return true;
  1335. }
  1336. void cmQtAutoGenInitializer::RegisterGeneratedSource(
  1337. std::string const& filename)
  1338. {
  1339. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1340. cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true);
  1341. gFile->SetProperty("GENERATED", "1");
  1342. gFile->SetProperty("SKIP_AUTOGEN", "1");
  1343. }
  1344. bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
  1345. GenVarsT const& genVars,
  1346. bool prepend)
  1347. {
  1348. // Register source at makefile
  1349. this->RegisterGeneratedSource(filename);
  1350. // Add source file to target
  1351. this->Target->AddSource(filename, prepend);
  1352. // Add source file to source group
  1353. return this->AddToSourceGroup(filename, genVars.GenNameUpper);
  1354. }
  1355. bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
  1356. std::string const& genNameUpper)
  1357. {
  1358. cmMakefile* makefile = this->Target->Target->GetMakefile();
  1359. cmSourceGroup* sourceGroup = nullptr;
  1360. // Acquire source group
  1361. {
  1362. std::string property;
  1363. std::string groupName;
  1364. {
  1365. // Prefer generator specific source group name
  1366. std::array<std::string, 2> props{ { genNameUpper + "_SOURCE_GROUP",
  1367. "AUTOGEN_SOURCE_GROUP" } };
  1368. for (std::string& prop : props) {
  1369. const char* propName = makefile->GetState()->GetGlobalProperty(prop);
  1370. if ((propName != nullptr) && (*propName != '\0')) {
  1371. groupName = propName;
  1372. property = std::move(prop);
  1373. break;
  1374. }
  1375. }
  1376. }
  1377. // Generate a source group on demand
  1378. if (!groupName.empty()) {
  1379. sourceGroup = makefile->GetOrCreateSourceGroup(groupName);
  1380. if (sourceGroup == nullptr) {
  1381. std::string err;
  1382. err += genNameUpper;
  1383. err += " error in ";
  1384. err += property;
  1385. err += ": Could not find or create the source group ";
  1386. err += cmQtAutoGen::Quoted(groupName);
  1387. cmSystemTools::Error(err);
  1388. return false;
  1389. }
  1390. }
  1391. }
  1392. if (sourceGroup != nullptr) {
  1393. sourceGroup->AddGroupFile(fileName);
  1394. }
  1395. return true;
  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. }