cmQtAutoGenInitializer.cxx 56 KB

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