cmQtAutoGenInitializer.cxx 57 KB

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