cmQtAutoGenInitializer.cxx 56 KB

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