cmQtAutoGenInitializer.cxx 56 KB

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