cmQtAutoGenInitializer.cxx 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  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 <cstddef>
  5. #include <deque>
  6. #include <initializer_list>
  7. #include <limits>
  8. #include <map>
  9. #include <set>
  10. #include <sstream> // for basic_ios, istringstream
  11. #include <string>
  12. #include <unordered_set>
  13. #include <utility>
  14. #include <vector>
  15. #include <cm/algorithm>
  16. #include <cm/iterator>
  17. #include <cm/memory>
  18. #include <cmext/algorithm>
  19. #include <cmext/string_view>
  20. #include <cm3p/json/value.h>
  21. #include <cm3p/json/writer.h>
  22. #include "cmsys/SystemInformation.hxx"
  23. #include "cmAlgorithms.h"
  24. #include "cmCustomCommand.h"
  25. #include "cmCustomCommandLines.h"
  26. #include "cmEvaluatedTargetProperty.h"
  27. #include "cmGeneratedFileStream.h"
  28. #include "cmGeneratorExpression.h"
  29. #include "cmGeneratorExpressionDAGChecker.h"
  30. #include "cmGeneratorTarget.h"
  31. #include "cmGlobalGenerator.h"
  32. #include "cmLinkItem.h"
  33. #include "cmList.h"
  34. #include "cmListFileCache.h"
  35. #include "cmLocalGenerator.h"
  36. #include "cmMakefile.h"
  37. #include "cmMessageType.h"
  38. #include "cmPolicies.h"
  39. #include "cmQtAutoGen.h"
  40. #include "cmQtAutoGenGlobalInitializer.h"
  41. #include "cmSourceFile.h"
  42. #include "cmSourceFileLocationKind.h"
  43. #include "cmSourceGroup.h"
  44. #include "cmStandardLevelResolver.h"
  45. #include "cmState.h"
  46. #include "cmStateTypes.h"
  47. #include "cmStringAlgorithms.h"
  48. #include "cmSystemTools.h"
  49. #include "cmTarget.h"
  50. #include "cmValue.h"
  51. #include "cmake.h"
  52. namespace {
  53. unsigned int GetParallelCPUCount()
  54. {
  55. static unsigned int count = 0;
  56. // Detect only on the first call
  57. if (count == 0) {
  58. cmsys::SystemInformation info;
  59. info.RunCPUCheck();
  60. count =
  61. cm::clamp(info.GetNumberOfPhysicalCPU(), 1u, cmQtAutoGen::ParallelMax);
  62. }
  63. return count;
  64. }
  65. std::string FileProjectRelativePath(cmMakefile* makefile,
  66. std::string const& fileName)
  67. {
  68. std::string res;
  69. {
  70. std::string pSource = cmSystemTools::RelativePath(
  71. makefile->GetCurrentSourceDirectory(), fileName);
  72. std::string pBinary = cmSystemTools::RelativePath(
  73. makefile->GetCurrentBinaryDirectory(), fileName);
  74. if (pSource.size() < pBinary.size()) {
  75. res = std::move(pSource);
  76. } else if (pBinary.size() < fileName.size()) {
  77. res = std::move(pBinary);
  78. } else {
  79. res = fileName;
  80. }
  81. }
  82. return res;
  83. }
  84. /**
  85. * Tests if targetDepend is a STATIC_LIBRARY and if any of its
  86. * recursive STATIC_LIBRARY dependencies depends on targetOrigin
  87. * (STATIC_LIBRARY cycle).
  88. */
  89. bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
  90. cmGeneratorTarget const* targetDepend,
  91. std::string const& config)
  92. {
  93. bool cycle = false;
  94. if ((targetOrigin->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  95. (targetDepend->GetType() == cmStateEnums::STATIC_LIBRARY)) {
  96. std::set<cmGeneratorTarget const*> knownLibs;
  97. std::deque<cmGeneratorTarget const*> testLibs;
  98. // Insert initial static_library dependency
  99. knownLibs.insert(targetDepend);
  100. testLibs.push_back(targetDepend);
  101. while (!testLibs.empty()) {
  102. cmGeneratorTarget const* testTarget = testLibs.front();
  103. testLibs.pop_front();
  104. // Check if the test target is the origin target (cycle)
  105. if (testTarget == targetOrigin) {
  106. cycle = true;
  107. break;
  108. }
  109. // Collect all static_library dependencies from the test target
  110. cmLinkImplementationLibraries const* libs =
  111. testTarget->GetLinkImplementationLibraries(
  112. config, cmGeneratorTarget::LinkInterfaceFor::Link);
  113. if (libs) {
  114. for (cmLinkItem const& item : libs->Libraries) {
  115. cmGeneratorTarget const* depTarget = item.Target;
  116. if (depTarget &&
  117. (depTarget->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  118. knownLibs.insert(depTarget).second) {
  119. testLibs.push_back(depTarget);
  120. }
  121. }
  122. }
  123. }
  124. }
  125. return cycle;
  126. }
  127. /** Sanitizes file search paths. */
  128. class SearchPathSanitizer
  129. {
  130. public:
  131. SearchPathSanitizer(cmMakefile* makefile)
  132. : SourcePath_(makefile->GetCurrentSourceDirectory())
  133. {
  134. }
  135. std::vector<std::string> operator()(
  136. std::vector<std::string> const& paths) const;
  137. private:
  138. std::string SourcePath_;
  139. };
  140. std::vector<std::string> SearchPathSanitizer::operator()(
  141. std::vector<std::string> const& paths) const
  142. {
  143. std::vector<std::string> res;
  144. res.reserve(paths.size());
  145. for (std::string const& srcPath : paths) {
  146. // Collapse relative paths
  147. std::string path =
  148. cmSystemTools::CollapseFullPath(srcPath, this->SourcePath_);
  149. // Remove suffix slashes
  150. while (cmHasSuffix(path, '/')) {
  151. path.pop_back();
  152. }
  153. // Accept only non empty paths
  154. if (!path.empty()) {
  155. res.emplace_back(std::move(path));
  156. }
  157. }
  158. return res;
  159. }
  160. /** @brief Writes a CMake info file. */
  161. class InfoWriter
  162. {
  163. public:
  164. // -- Single value
  165. void Set(std::string const& key, std::string const& value)
  166. {
  167. this->Value_[key] = value;
  168. }
  169. void SetConfig(std::string const& key,
  170. cmQtAutoGenInitializer::ConfigString const& cfgStr);
  171. void SetBool(std::string const& key, bool value)
  172. {
  173. this->Value_[key] = value;
  174. }
  175. void SetUInt(std::string const& key, unsigned int value)
  176. {
  177. this->Value_[key] = value;
  178. }
  179. // -- Array utility
  180. template <typename CONT>
  181. static bool MakeArray(Json::Value& jval, CONT const& container);
  182. template <typename CONT>
  183. static void MakeStringArray(Json::Value& jval, CONT const& container);
  184. // -- Array value
  185. template <typename CONT>
  186. void SetArray(std::string const& key, CONT const& container);
  187. template <typename CONT>
  188. void SetConfigArray(
  189. std::string const& key,
  190. cmQtAutoGenInitializer::ConfigStrings<CONT> const& cfgStr);
  191. // -- Array of arrays
  192. template <typename CONT, typename FUNC>
  193. void SetArrayArray(std::string const& key, CONT const& container, FUNC func);
  194. // -- Save to json file
  195. bool Save(std::string const& filename);
  196. private:
  197. Json::Value Value_;
  198. };
  199. void InfoWriter::SetConfig(std::string const& key,
  200. cmQtAutoGenInitializer::ConfigString const& cfgStr)
  201. {
  202. this->Set(key, cfgStr.Default);
  203. for (auto const& item : cfgStr.Config) {
  204. this->Set(cmStrCat(key, '_', item.first), item.second);
  205. }
  206. }
  207. template <typename CONT>
  208. bool InfoWriter::MakeArray(Json::Value& jval, CONT const& container)
  209. {
  210. jval = Json::arrayValue;
  211. std::size_t const listSize = cm::size(container);
  212. if (listSize == 0) {
  213. return false;
  214. }
  215. jval.resize(static_cast<unsigned int>(listSize));
  216. return true;
  217. }
  218. template <typename CONT>
  219. void InfoWriter::MakeStringArray(Json::Value& jval, CONT const& container)
  220. {
  221. if (MakeArray(jval, container)) {
  222. Json::ArrayIndex ii = 0;
  223. for (std::string const& item : container) {
  224. jval[ii++] = item;
  225. }
  226. }
  227. }
  228. template <typename CONT>
  229. void InfoWriter::SetArray(std::string const& key, CONT const& container)
  230. {
  231. MakeStringArray(this->Value_[key], container);
  232. }
  233. template <typename CONT, typename FUNC>
  234. void InfoWriter::SetArrayArray(std::string const& key, CONT const& container,
  235. FUNC func)
  236. {
  237. Json::Value& jval = this->Value_[key];
  238. if (MakeArray(jval, container)) {
  239. Json::ArrayIndex ii = 0;
  240. for (auto const& citem : container) {
  241. Json::Value& aval = jval[ii++];
  242. aval = Json::arrayValue;
  243. func(aval, citem);
  244. }
  245. }
  246. }
  247. template <typename CONT>
  248. void InfoWriter::SetConfigArray(
  249. std::string const& key,
  250. cmQtAutoGenInitializer::ConfigStrings<CONT> const& cfgStr)
  251. {
  252. this->SetArray(key, cfgStr.Default);
  253. for (auto const& item : cfgStr.Config) {
  254. this->SetArray(cmStrCat(key, '_', item.first), item.second);
  255. }
  256. }
  257. bool InfoWriter::Save(std::string const& filename)
  258. {
  259. cmGeneratedFileStream fileStream;
  260. fileStream.SetCopyIfDifferent(true);
  261. fileStream.Open(filename, false, true);
  262. if (!fileStream) {
  263. return false;
  264. }
  265. Json::StyledStreamWriter jsonWriter;
  266. try {
  267. jsonWriter.write(fileStream, this->Value_);
  268. } catch (...) {
  269. return false;
  270. }
  271. return fileStream.Close();
  272. }
  273. void AddAutogenExecutableToDependencies(
  274. cmQtAutoGenInitializer::GenVarsT const& genVars,
  275. std::vector<std::string>& dependencies)
  276. {
  277. if (genVars.ExecutableTarget != nullptr) {
  278. dependencies.push_back(genVars.ExecutableTarget->Target->GetName());
  279. } else if (!genVars.Executable.empty()) {
  280. dependencies.push_back(genVars.Executable);
  281. }
  282. }
  283. } // End of unnamed namespace
  284. cmQtAutoGenInitializer::cmQtAutoGenInitializer(
  285. cmQtAutoGenGlobalInitializer* globalInitializer,
  286. cmGeneratorTarget* genTarget, IntegerVersion const& qtVersion,
  287. bool mocEnabled, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget,
  288. bool globalAutoRccTarget)
  289. : GlobalInitializer(globalInitializer)
  290. , GenTarget(genTarget)
  291. , GlobalGen(genTarget->GetGlobalGenerator())
  292. , LocalGen(genTarget->GetLocalGenerator())
  293. , Makefile(genTarget->Makefile)
  294. , PathCheckSum(genTarget->Makefile)
  295. , QtVersion(qtVersion)
  296. {
  297. this->AutogenTarget.GlobalTarget = globalAutogenTarget;
  298. this->Moc.Enabled = mocEnabled;
  299. this->Uic.Enabled = uicEnabled;
  300. this->Rcc.Enabled = rccEnabled;
  301. this->Rcc.GlobalTarget = globalAutoRccTarget;
  302. }
  303. bool cmQtAutoGenInitializer::InitCustomTargets()
  304. {
  305. // Configurations
  306. this->MultiConfig = this->GlobalGen->IsMultiConfig();
  307. this->ConfigDefault = this->Makefile->GetDefaultConfiguration();
  308. this->ConfigsList =
  309. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  310. // Verbosity
  311. {
  312. std::string def =
  313. this->Makefile->GetSafeDefinition("CMAKE_AUTOGEN_VERBOSE");
  314. if (!def.empty()) {
  315. unsigned long iVerb = 0;
  316. if (cmStrToULong(def, &iVerb)) {
  317. // Numeric verbosity
  318. this->Verbosity = static_cast<unsigned int>(iVerb);
  319. } else {
  320. // Non numeric verbosity
  321. if (cmIsOn(def)) {
  322. this->Verbosity = 1;
  323. }
  324. }
  325. }
  326. }
  327. // Targets FOLDER
  328. {
  329. cmValue folder =
  330. this->Makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  331. if (!folder) {
  332. folder = this->Makefile->GetState()->GetGlobalProperty(
  333. "AUTOGEN_TARGETS_FOLDER");
  334. }
  335. // Inherit FOLDER property from target (#13688)
  336. if (!folder) {
  337. folder = this->GenTarget->GetProperty("FOLDER");
  338. }
  339. if (folder) {
  340. this->TargetsFolder = *folder;
  341. }
  342. }
  343. // Check status of policy CMP0071 regarding handling of GENERATED files
  344. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0071)) {
  345. case cmPolicies::WARN:
  346. // Ignore GENERATED files but warn
  347. this->CMP0071Warn = true;
  348. CM_FALLTHROUGH;
  349. case cmPolicies::OLD:
  350. // Ignore GENERATED files
  351. break;
  352. case cmPolicies::REQUIRED_IF_USED:
  353. case cmPolicies::REQUIRED_ALWAYS:
  354. case cmPolicies::NEW:
  355. // Process GENERATED files
  356. this->CMP0071Accept = true;
  357. break;
  358. }
  359. // Check status of policy CMP0100 regarding handling of .hh headers
  360. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0100)) {
  361. case cmPolicies::WARN:
  362. // Ignore but .hh files but warn
  363. this->CMP0100Warn = true;
  364. CM_FALLTHROUGH;
  365. case cmPolicies::OLD:
  366. // Ignore .hh files
  367. break;
  368. case cmPolicies::REQUIRED_IF_USED:
  369. case cmPolicies::REQUIRED_ALWAYS:
  370. case cmPolicies::NEW:
  371. // Process .hh file
  372. this->CMP0100Accept = true;
  373. break;
  374. }
  375. // Common directories
  376. std::string relativeBuildDir;
  377. {
  378. // Collapsed current binary directory
  379. std::string const cbd = cmSystemTools::CollapseFullPath(
  380. std::string(), this->Makefile->GetCurrentBinaryDirectory());
  381. // Info directory
  382. this->Dir.Info = cmStrCat(cbd, "/CMakeFiles/", this->GenTarget->GetName(),
  383. "_autogen.dir");
  384. cmSystemTools::ConvertToUnixSlashes(this->Dir.Info);
  385. // Build directory
  386. this->Dir.Build = this->GenTarget->GetSafeProperty("AUTOGEN_BUILD_DIR");
  387. if (this->Dir.Build.empty()) {
  388. this->Dir.Build =
  389. cmStrCat(cbd, '/', this->GenTarget->GetName(), "_autogen");
  390. }
  391. cmSystemTools::ConvertToUnixSlashes(this->Dir.Build);
  392. this->Dir.RelativeBuild =
  393. cmSystemTools::RelativePath(cbd, this->Dir.Build);
  394. // Cleanup build directory
  395. this->AddCleanFile(this->Dir.Build);
  396. // Working directory
  397. this->Dir.Work = cbd;
  398. cmSystemTools::ConvertToUnixSlashes(this->Dir.Work);
  399. // Include directory
  400. this->ConfigFileNamesAndGenex(this->Dir.Include, this->Dir.IncludeGenExp,
  401. cmStrCat(this->Dir.Build, "/include"), "");
  402. }
  403. // Moc, Uic and _autogen target settings
  404. if (this->MocOrUicEnabled()) {
  405. // Init moc specific settings
  406. if (this->Moc.Enabled && !this->InitMoc()) {
  407. return false;
  408. }
  409. // Init uic specific settings
  410. if (this->Uic.Enabled && !this->InitUic()) {
  411. return false;
  412. }
  413. // Autogen target name
  414. this->AutogenTarget.Name =
  415. cmStrCat(this->GenTarget->GetName(), "_autogen");
  416. // Autogen target parallel processing
  417. {
  418. using ParallelType = decltype(this->AutogenTarget.Parallel);
  419. unsigned long propInt = 0;
  420. std::string const& prop =
  421. this->GenTarget->GetSafeProperty("AUTOGEN_PARALLEL");
  422. if (prop.empty() || (prop == "AUTO")) {
  423. // Autodetect number of CPUs
  424. this->AutogenTarget.Parallel = GetParallelCPUCount();
  425. } else if (cmStrToULong(prop, &propInt) && propInt > 0 &&
  426. propInt <= std::numeric_limits<ParallelType>::max()) {
  427. this->AutogenTarget.Parallel = static_cast<ParallelType>(propInt);
  428. } else {
  429. // Warn the project author that AUTOGEN_PARALLEL is not valid.
  430. this->Makefile->IssueMessage(
  431. MessageType::AUTHOR_WARNING,
  432. cmStrCat("AUTOGEN_PARALLEL=\"", prop, "\" for target \"",
  433. this->GenTarget->GetName(),
  434. "\" is not valid. Using AUTOGEN_PARALLEL=1"));
  435. this->AutogenTarget.Parallel = 1;
  436. }
  437. }
  438. // Autogen target info and settings files
  439. {
  440. // Info file
  441. this->AutogenTarget.InfoFile =
  442. cmStrCat(this->Dir.Info, "/AutogenInfo.json");
  443. // Used settings file
  444. this->ConfigFileNames(this->AutogenTarget.SettingsFile,
  445. cmStrCat(this->Dir.Info, "/AutogenUsed"), ".txt");
  446. this->ConfigFileClean(this->AutogenTarget.SettingsFile);
  447. // Parse cache file
  448. this->ConfigFileNames(this->AutogenTarget.ParseCacheFile,
  449. cmStrCat(this->Dir.Info, "/ParseCache"), ".txt");
  450. this->ConfigFileClean(this->AutogenTarget.ParseCacheFile);
  451. }
  452. // Autogen target: Compute user defined dependencies
  453. {
  454. this->AutogenTarget.DependOrigin =
  455. this->GenTarget->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
  456. std::string const& deps =
  457. this->GenTarget->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
  458. if (!deps.empty()) {
  459. for (auto const& depName : cmList{ deps }) {
  460. // Allow target and file dependencies
  461. auto* depTarget = this->Makefile->FindTargetToUse(depName);
  462. if (depTarget) {
  463. this->AutogenTarget.DependTargets.insert(depTarget);
  464. } else {
  465. this->AutogenTarget.DependFiles.insert(depName);
  466. }
  467. }
  468. }
  469. }
  470. if (this->Moc.Enabled) {
  471. // Path prefix
  472. if (cmIsOn(this->GenTarget->GetProperty("AUTOMOC_PATH_PREFIX"))) {
  473. this->Moc.PathPrefix = true;
  474. }
  475. // CMAKE_AUTOMOC_RELAXED_MODE
  476. if (this->Makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE")) {
  477. this->Moc.RelaxedMode = true;
  478. this->Makefile->IssueMessage(
  479. MessageType::AUTHOR_WARNING,
  480. cmStrCat("AUTOMOC: CMAKE_AUTOMOC_RELAXED_MODE is "
  481. "deprecated an will be removed in the future. Consider "
  482. "disabling it and converting the target ",
  483. this->GenTarget->GetName(), " to regular mode."));
  484. }
  485. // Options
  486. cmExpandList(this->GenTarget->GetSafeProperty("AUTOMOC_MOC_OPTIONS"),
  487. this->Moc.Options);
  488. // Filters
  489. cmExpandList(this->GenTarget->GetSafeProperty("AUTOMOC_MACRO_NAMES"),
  490. this->Moc.MacroNames);
  491. this->Moc.MacroNames.erase(cmRemoveDuplicates(this->Moc.MacroNames),
  492. this->Moc.MacroNames.end());
  493. {
  494. cmList filterList = { this->GenTarget->GetSafeProperty(
  495. "AUTOMOC_DEPEND_FILTERS") };
  496. if ((filterList.size() % 2) != 0) {
  497. cmSystemTools::Error(
  498. cmStrCat("AutoMoc: AUTOMOC_DEPEND_FILTERS predefs size ",
  499. filterList.size(), " is not a multiple of 2."));
  500. return false;
  501. }
  502. this->Moc.DependFilters.reserve(1 + (filterList.size() / 2));
  503. this->Moc.DependFilters.emplace_back(
  504. "Q_PLUGIN_METADATA",
  505. "[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\("
  506. "[^\\)]*FILE[ \t]*\"([^\"]+)\"");
  507. for (cmList::index_type ii = 0;
  508. ii != static_cast<cmList::index_type>(filterList.size());
  509. ii += 2) {
  510. this->Moc.DependFilters.emplace_back(filterList[ii],
  511. filterList[ii + 1]);
  512. }
  513. }
  514. }
  515. }
  516. // Init rcc specific settings
  517. if (this->Rcc.Enabled && !this->InitRcc()) {
  518. return false;
  519. }
  520. // Add autogen include directory to the origin target INCLUDE_DIRECTORIES
  521. if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) {
  522. auto addBefore = false;
  523. auto const& value =
  524. this->GenTarget->GetProperty("AUTOGEN_USE_SYSTEM_INCLUDE");
  525. if (value.IsSet()) {
  526. if (cmIsOn(value)) {
  527. this->GenTarget->AddSystemIncludeDirectory(this->Dir.IncludeGenExp,
  528. "CXX");
  529. } else {
  530. addBefore = true;
  531. }
  532. } else {
  533. addBefore = true;
  534. }
  535. this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, addBefore);
  536. }
  537. // Scan files
  538. if (!this->InitScanFiles()) {
  539. return false;
  540. }
  541. // Create autogen target
  542. if (this->MocOrUicEnabled() && !this->InitAutogenTarget()) {
  543. return false;
  544. }
  545. // Create rcc targets
  546. if (this->Rcc.Enabled && !this->InitRccTargets()) {
  547. return false;
  548. }
  549. return true;
  550. }
  551. bool cmQtAutoGenInitializer::InitMoc()
  552. {
  553. // Mocs compilation file
  554. if (this->GlobalGen->IsXcode()) {
  555. // XXX(xcode-per-cfg-src): Drop this Xcode-specific code path
  556. // when the Xcode generator supports per-config sources.
  557. this->Moc.CompilationFile.Default =
  558. cmStrCat(this->Dir.Build, "/mocs_compilation.cpp");
  559. this->Moc.CompilationFileGenex = this->Moc.CompilationFile.Default;
  560. } else {
  561. this->ConfigFileNamesAndGenex(
  562. this->Moc.CompilationFile, this->Moc.CompilationFileGenex,
  563. cmStrCat(this->Dir.Build, "/mocs_compilation"_s), ".cpp"_s);
  564. }
  565. // Moc predefs
  566. if (this->GenTarget->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
  567. (this->QtVersion >= IntegerVersion(5, 8))) {
  568. // Command
  569. this->Makefile->GetDefExpandList("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND",
  570. this->Moc.PredefsCmd);
  571. // Header
  572. if (!this->Moc.PredefsCmd.empty()) {
  573. this->ConfigFileNames(this->Moc.PredefsFile,
  574. cmStrCat(this->Dir.Build, "/moc_predefs"), ".h");
  575. }
  576. }
  577. // Moc includes
  578. {
  579. SearchPathSanitizer sanitizer(this->Makefile);
  580. auto getDirs =
  581. [this, &sanitizer](std::string const& cfg) -> std::vector<std::string> {
  582. // Get the include dirs for this target, without stripping the implicit
  583. // include dirs off, see issue #13667.
  584. std::vector<std::string> dirs;
  585. bool const appendImplicit = (this->QtVersion.Major >= 5);
  586. this->LocalGen->GetIncludeDirectoriesImplicit(
  587. dirs, this->GenTarget, "CXX", cfg, false, appendImplicit);
  588. return sanitizer(dirs);
  589. };
  590. // Default configuration include directories
  591. this->Moc.Includes.Default = getDirs(this->ConfigDefault);
  592. // Other configuration settings
  593. if (this->MultiConfig) {
  594. for (std::string const& cfg : this->ConfigsList) {
  595. std::vector<std::string> dirs = getDirs(cfg);
  596. if (dirs == this->Moc.Includes.Default) {
  597. continue;
  598. }
  599. this->Moc.Includes.Config[cfg] = std::move(dirs);
  600. }
  601. }
  602. }
  603. // Moc compile definitions
  604. {
  605. auto getDefs = [this](std::string const& cfg) -> std::set<std::string> {
  606. std::set<std::string> defines;
  607. this->LocalGen->GetTargetDefines(this->GenTarget, cfg, "CXX", defines);
  608. if (this->Moc.PredefsCmd.empty() &&
  609. this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") ==
  610. "Windows") {
  611. // Add WIN32 definition if we don't have a moc_predefs.h
  612. defines.insert("WIN32");
  613. }
  614. return defines;
  615. };
  616. // Default configuration defines
  617. this->Moc.Defines.Default = getDefs(this->ConfigDefault);
  618. // Other configuration defines
  619. if (this->MultiConfig) {
  620. for (std::string const& cfg : this->ConfigsList) {
  621. std::set<std::string> defines = getDefs(cfg);
  622. if (defines == this->Moc.Defines.Default) {
  623. continue;
  624. }
  625. this->Moc.Defines.Config[cfg] = std::move(defines);
  626. }
  627. }
  628. }
  629. // Moc executable
  630. {
  631. if (!this->GetQtExecutable(this->Moc, "moc", false)) {
  632. return false;
  633. }
  634. // Let the _autogen target depend on the moc executable
  635. if (this->Moc.ExecutableTarget) {
  636. this->AutogenTarget.DependTargets.insert(
  637. this->Moc.ExecutableTarget->Target);
  638. }
  639. }
  640. return true;
  641. }
  642. bool cmQtAutoGenInitializer::InitUic()
  643. {
  644. // Uic search paths
  645. {
  646. std::string const& usp =
  647. this->GenTarget->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
  648. if (!usp.empty()) {
  649. this->Uic.SearchPaths =
  650. SearchPathSanitizer(this->Makefile)(cmList{ usp });
  651. }
  652. }
  653. // Uic target options
  654. {
  655. auto getOpts = [this](std::string const& cfg) -> std::vector<std::string> {
  656. std::vector<std::string> opts;
  657. this->GenTarget->GetAutoUicOptions(opts, cfg);
  658. return opts;
  659. };
  660. // Default options
  661. this->Uic.Options.Default = getOpts(this->ConfigDefault);
  662. // Configuration specific options
  663. if (this->MultiConfig) {
  664. for (std::string const& cfg : this->ConfigsList) {
  665. std::vector<std::string> options = getOpts(cfg);
  666. if (options == this->Uic.Options.Default) {
  667. continue;
  668. }
  669. this->Uic.Options.Config[cfg] = std::move(options);
  670. }
  671. }
  672. }
  673. // Uic executable
  674. {
  675. if (!this->GetQtExecutable(this->Uic, "uic", true)) {
  676. return false;
  677. }
  678. // Let the _autogen target depend on the uic executable
  679. if (this->Uic.ExecutableTarget) {
  680. this->AutogenTarget.DependTargets.insert(
  681. this->Uic.ExecutableTarget->Target);
  682. }
  683. }
  684. return true;
  685. }
  686. bool cmQtAutoGenInitializer::InitRcc()
  687. {
  688. // Rcc executable
  689. {
  690. if (!this->GetQtExecutable(this->Rcc, "rcc", false)) {
  691. return false;
  692. }
  693. // Evaluate test output on demand
  694. CompilerFeatures& features = *this->Rcc.ExecutableFeatures;
  695. if (!features.Evaluated) {
  696. // Look for list options
  697. if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
  698. if (features.HelpOutput.find("--list") != std::string::npos) {
  699. features.ListOptions.emplace_back("--list");
  700. } else if (features.HelpOutput.find("-list") != std::string::npos) {
  701. features.ListOptions.emplace_back("-list");
  702. }
  703. }
  704. // Evaluation finished
  705. features.Evaluated = true;
  706. }
  707. }
  708. return true;
  709. }
  710. bool cmQtAutoGenInitializer::InitScanFiles()
  711. {
  712. cmake const* cm = this->Makefile->GetCMakeInstance();
  713. auto const& kw = this->GlobalInitializer->kw();
  714. auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
  715. std::vector<size_t> const& configs,
  716. bool muIt) -> MUFileHandle {
  717. MUFileHandle muf = cm::make_unique<MUFile>();
  718. muf->FullPath = fullPath;
  719. muf->SF = sf;
  720. if (!configs.empty() && configs.size() != this->ConfigsList.size()) {
  721. muf->Configs = configs;
  722. }
  723. muf->Generated = sf->GetIsGenerated();
  724. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  725. muf->SkipMoc = this->Moc.Enabled &&
  726. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC));
  727. muf->SkipUic = this->Uic.Enabled &&
  728. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  729. if (muIt) {
  730. muf->MocIt = this->Moc.Enabled && !muf->SkipMoc;
  731. muf->UicIt = this->Uic.Enabled && !muf->SkipUic;
  732. }
  733. return muf;
  734. };
  735. auto addMUHeader = [this](MUFileHandle&& muf, cm::string_view extension) {
  736. cmSourceFile* sf = muf->SF;
  737. const bool muIt = (muf->MocIt || muf->UicIt);
  738. if (this->CMP0100Accept || (extension != "hh")) {
  739. // Accept
  740. if (muIt && muf->Generated) {
  741. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  742. }
  743. this->AutogenTarget.Headers.emplace(sf, std::move(muf));
  744. } else if (muIt && this->CMP0100Warn) {
  745. // Store file for warning message
  746. this->AutogenTarget.CMP0100HeadersWarn.push_back(sf);
  747. }
  748. };
  749. auto addMUSource = [this](MUFileHandle&& muf) {
  750. if ((muf->MocIt || muf->UicIt) && muf->Generated) {
  751. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  752. }
  753. this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf));
  754. };
  755. // Scan through target files
  756. {
  757. // Scan through target files
  758. for (cmGeneratorTarget::AllConfigSource const& acs :
  759. this->GenTarget->GetAllConfigSources()) {
  760. std::string const& fullPath = acs.Source->GetFullPath();
  761. std::string const& extLower =
  762. cmSystemTools::LowerCase(acs.Source->GetExtension());
  763. // Register files that will be scanned by moc or uic
  764. if (this->MocOrUicEnabled()) {
  765. if (cm->IsAHeaderExtension(extLower)) {
  766. addMUHeader(makeMUFile(acs.Source, fullPath, acs.Configs, true),
  767. extLower);
  768. } else if (cm->IsACLikeSourceExtension(extLower)) {
  769. addMUSource(makeMUFile(acs.Source, fullPath, acs.Configs, true));
  770. }
  771. }
  772. // Register rcc enabled files
  773. if (this->Rcc.Enabled) {
  774. if ((extLower == kw.qrc) &&
  775. !acs.Source->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
  776. !acs.Source->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
  777. // Register qrc file
  778. Qrc qrc;
  779. qrc.QrcFile = fullPath;
  780. qrc.QrcName =
  781. cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile);
  782. qrc.Generated = acs.Source->GetIsGenerated();
  783. // RCC options
  784. {
  785. std::string const& opts =
  786. acs.Source->GetSafeProperty(kw.AUTORCC_OPTIONS);
  787. if (!opts.empty()) {
  788. cmExpandList(opts, qrc.Options);
  789. }
  790. }
  791. this->Rcc.Qrcs.push_back(std::move(qrc));
  792. }
  793. }
  794. }
  795. }
  796. // cmGeneratorTarget::GetAllConfigSources computes the target's
  797. // sources meta data cache. Clear it so that OBJECT library targets that
  798. // are AUTOGEN initialized after this target get their added
  799. // mocs_compilation.cpp source acknowledged by this target.
  800. this->GenTarget->ClearSourcesCache();
  801. // For source files find additional headers and private headers
  802. if (this->MocOrUicEnabled()) {
  803. // Header search suffixes and extensions
  804. static std::initializer_list<cm::string_view> const suffixes{ "", "_p" };
  805. auto const& exts = cm->GetHeaderExtensions();
  806. // Scan through sources
  807. for (auto const& pair : this->AutogenTarget.Sources) {
  808. MUFile const& muf = *pair.second;
  809. if (muf.MocIt || muf.UicIt) {
  810. // Search for the default header file and a private header
  811. std::string const& srcFullPath = muf.SF->ResolveFullPath();
  812. std::string basePath = cmStrCat(
  813. cmQtAutoGen::SubDirPrefix(srcFullPath),
  814. cmSystemTools::GetFilenameWithoutLastExtension(srcFullPath));
  815. for (auto const& suffix : suffixes) {
  816. std::string const suffixedPath = cmStrCat(basePath, suffix);
  817. for (auto const& ext : exts) {
  818. std::string fullPath = cmStrCat(suffixedPath, '.', ext);
  819. auto constexpr locationKind = cmSourceFileLocationKind::Known;
  820. cmSourceFile* sf =
  821. this->Makefile->GetSource(fullPath, locationKind);
  822. if (sf) {
  823. // Check if we know about this header already
  824. if (cm::contains(this->AutogenTarget.Headers, sf)) {
  825. continue;
  826. }
  827. // We only accept not-GENERATED files that do exist.
  828. if (!sf->GetIsGenerated() &&
  829. !cmSystemTools::FileExists(fullPath)) {
  830. continue;
  831. }
  832. } else if (cmSystemTools::FileExists(fullPath)) {
  833. // Create a new source file for the existing file
  834. sf = this->Makefile->CreateSource(fullPath, false, locationKind);
  835. }
  836. if (sf) {
  837. auto eMuf = makeMUFile(sf, fullPath, muf.Configs, true);
  838. // Only process moc/uic when the parent is processed as well
  839. if (!muf.MocIt) {
  840. eMuf->MocIt = false;
  841. }
  842. if (!muf.UicIt) {
  843. eMuf->UicIt = false;
  844. }
  845. addMUHeader(std::move(eMuf), ext);
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. // Scan through all source files in the makefile to extract moc and uic
  853. // parameters. Historically we support non target source file parameters.
  854. // The reason is that their file names might be discovered from source files
  855. // at generation time.
  856. if (this->MocOrUicEnabled()) {
  857. for (const auto& sf : this->Makefile->GetSourceFiles()) {
  858. // sf->GetExtension() is only valid after sf->ResolveFullPath() ...
  859. // Since we're iterating over source files that might be not in the
  860. // target we need to check for path errors (not existing files).
  861. std::string pathError;
  862. std::string const& fullPath = sf->ResolveFullPath(&pathError);
  863. if (!pathError.empty() || fullPath.empty()) {
  864. continue;
  865. }
  866. std::string const& extLower =
  867. cmSystemTools::LowerCase(sf->GetExtension());
  868. if (cm->IsAHeaderExtension(extLower)) {
  869. if (!cm::contains(this->AutogenTarget.Headers, sf.get())) {
  870. auto muf = makeMUFile(sf.get(), fullPath, {}, false);
  871. if (muf->SkipMoc || muf->SkipUic) {
  872. addMUHeader(std::move(muf), extLower);
  873. }
  874. }
  875. } else if (cm->IsACLikeSourceExtension(extLower)) {
  876. if (!cm::contains(this->AutogenTarget.Sources, sf.get())) {
  877. auto muf = makeMUFile(sf.get(), fullPath, {}, false);
  878. if (muf->SkipMoc || muf->SkipUic) {
  879. addMUSource(std::move(muf));
  880. }
  881. }
  882. } else if (this->Uic.Enabled && (extLower == kw.ui)) {
  883. // .ui file
  884. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  885. bool const skipUic =
  886. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  887. if (!skipUic) {
  888. // Check if the .ui file has uic options
  889. std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS);
  890. if (uicOpts.empty()) {
  891. this->Uic.UiFilesNoOptions.emplace_back(fullPath);
  892. } else {
  893. this->Uic.UiFilesWithOptions.emplace_back(
  894. fullPath, std::move(cmList{ uicOpts }.data()));
  895. }
  896. auto uiHeaderRelativePath = cmSystemTools::RelativePath(
  897. this->LocalGen->GetCurrentSourceDirectory(),
  898. cmSystemTools::GetFilenamePath(fullPath));
  899. // Avoid creating a path containing adjacent slashes
  900. if (!uiHeaderRelativePath.empty() &&
  901. uiHeaderRelativePath.back() != '/') {
  902. uiHeaderRelativePath += '/';
  903. }
  904. auto uiHeaderFilePath = cmStrCat(
  905. '/', uiHeaderRelativePath, "ui_"_s,
  906. cmSystemTools::GetFilenameWithoutLastExtension(fullPath), ".h"_s);
  907. ConfigString uiHeader;
  908. std::string uiHeaderGenex;
  909. this->ConfigFileNamesAndGenex(
  910. uiHeader, uiHeaderGenex, cmStrCat(this->Dir.Build, "/include"_s),
  911. uiHeaderFilePath);
  912. this->Uic.UiHeaders.emplace_back(uiHeader, uiHeaderGenex);
  913. } else {
  914. // Register skipped .ui file
  915. this->Uic.SkipUi.insert(fullPath);
  916. }
  917. }
  918. }
  919. }
  920. // Process GENERATED sources and headers
  921. if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) {
  922. if (this->CMP0071Accept) {
  923. // Let the autogen target depend on the GENERATED files
  924. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  925. this->AutogenTarget.DependFiles.insert(muf->FullPath);
  926. }
  927. } else if (this->CMP0071Warn) {
  928. cm::string_view property;
  929. if (this->Moc.Enabled && this->Uic.Enabled) {
  930. property = "SKIP_AUTOGEN";
  931. } else if (this->Moc.Enabled) {
  932. property = "SKIP_AUTOMOC";
  933. } else if (this->Uic.Enabled) {
  934. property = "SKIP_AUTOUIC";
  935. }
  936. std::string files;
  937. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  938. files += cmStrCat(" ", Quoted(muf->FullPath), '\n');
  939. }
  940. this->Makefile->IssueMessage(
  941. MessageType::AUTHOR_WARNING,
  942. cmStrCat(
  943. cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n',
  944. "For compatibility, CMake is excluding the GENERATED source "
  945. "file(s):\n",
  946. files, "from processing by ",
  947. cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
  948. ". If any of the files should be processed, set CMP0071 to NEW. "
  949. "If any of the files should not be processed, "
  950. "explicitly exclude them by setting the source file property ",
  951. property, ":\n set_property(SOURCE file.h PROPERTY ", property,
  952. " ON)\n"));
  953. }
  954. }
  955. // Generate CMP0100 warning
  956. if (this->MocOrUicEnabled() &&
  957. !this->AutogenTarget.CMP0100HeadersWarn.empty()) {
  958. cm::string_view property;
  959. if (this->Moc.Enabled && this->Uic.Enabled) {
  960. property = "SKIP_AUTOGEN";
  961. } else if (this->Moc.Enabled) {
  962. property = "SKIP_AUTOMOC";
  963. } else if (this->Uic.Enabled) {
  964. property = "SKIP_AUTOUIC";
  965. }
  966. std::string files;
  967. for (cmSourceFile* sf : this->AutogenTarget.CMP0100HeadersWarn) {
  968. files += cmStrCat(" ", Quoted(sf->GetFullPath()), '\n');
  969. }
  970. this->Makefile->IssueMessage(
  971. MessageType::AUTHOR_WARNING,
  972. cmStrCat(
  973. cmPolicies::GetPolicyWarning(cmPolicies::CMP0100), '\n',
  974. "For compatibility, CMake is excluding the header file(s):\n", files,
  975. "from processing by ",
  976. cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
  977. ". If any of the files should be processed, set CMP0100 to NEW. "
  978. "If any of the files should not be processed, "
  979. "explicitly exclude them by setting the source file property ",
  980. property, ":\n set_property(SOURCE file.hh PROPERTY ", property,
  981. " ON)\n"));
  982. }
  983. // Process qrc files
  984. if (!this->Rcc.Qrcs.empty()) {
  985. const bool modernQt = (this->QtVersion.Major >= 5);
  986. // Target rcc options
  987. cmList optionsTarget{ this->GenTarget->GetSafeProperty(
  988. kw.AUTORCC_OPTIONS) };
  989. // Check if file name is unique
  990. for (Qrc& qrc : this->Rcc.Qrcs) {
  991. qrc.Unique = true;
  992. for (Qrc const& qrc2 : this->Rcc.Qrcs) {
  993. if ((&qrc != &qrc2) && (qrc.QrcName == qrc2.QrcName)) {
  994. qrc.Unique = false;
  995. break;
  996. }
  997. }
  998. }
  999. // Path checksum and file names
  1000. for (Qrc& qrc : this->Rcc.Qrcs) {
  1001. // Path checksum
  1002. qrc.QrcPathChecksum = this->PathCheckSum.getPart(qrc.QrcFile);
  1003. // Output file name
  1004. qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum,
  1005. "/qrc_", qrc.QrcName, ".cpp");
  1006. std::string const base = cmStrCat(this->Dir.Info, "/AutoRcc_",
  1007. qrc.QrcName, '_', qrc.QrcPathChecksum);
  1008. qrc.LockFile = cmStrCat(base, "_Lock.lock");
  1009. qrc.InfoFile = cmStrCat(base, "_Info.json");
  1010. this->ConfigFileNames(qrc.SettingsFile, cmStrCat(base, "_Used"), ".txt");
  1011. }
  1012. // rcc options
  1013. for (Qrc& qrc : this->Rcc.Qrcs) {
  1014. // Target options
  1015. std::vector<std::string> opts = optionsTarget;
  1016. // Merge computed "-name XYZ" option
  1017. {
  1018. std::string name = qrc.QrcName;
  1019. // Replace '-' with '_'. The former is not valid for symbol names.
  1020. std::replace(name.begin(), name.end(), '-', '_');
  1021. if (!qrc.Unique) {
  1022. name += cmStrCat('_', qrc.QrcPathChecksum);
  1023. }
  1024. std::vector<std::string> nameOpts;
  1025. nameOpts.emplace_back("-name");
  1026. nameOpts.emplace_back(std::move(name));
  1027. RccMergeOptions(opts, nameOpts, modernQt);
  1028. }
  1029. // Merge file option
  1030. RccMergeOptions(opts, qrc.Options, modernQt);
  1031. qrc.Options = std::move(opts);
  1032. }
  1033. // rcc resources
  1034. for (Qrc& qrc : this->Rcc.Qrcs) {
  1035. if (!qrc.Generated) {
  1036. std::string error;
  1037. RccLister const lister(this->Rcc.Executable,
  1038. this->Rcc.ExecutableFeatures->ListOptions);
  1039. if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
  1040. cmSystemTools::Error(error);
  1041. return false;
  1042. }
  1043. }
  1044. }
  1045. }
  1046. return true;
  1047. }
  1048. bool cmQtAutoGenInitializer::InitAutogenTarget()
  1049. {
  1050. // Register info file as generated by CMake
  1051. this->Makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
  1052. // Determine whether to use a depfile for the AUTOGEN target.
  1053. const bool useNinjaDepfile = this->QtVersion >= IntegerVersion(5, 15) &&
  1054. this->GlobalGen->GetName().find("Ninja") != std::string::npos;
  1055. // Files provided by the autogen target
  1056. std::vector<std::string> autogenByproducts;
  1057. std::vector<std::string> timestampByproducts;
  1058. if (this->Moc.Enabled) {
  1059. this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true);
  1060. if (useNinjaDepfile) {
  1061. if (this->MultiConfig) {
  1062. // Make all mocs_compilation_<CONFIG>.cpp files byproducts of the
  1063. // ${target}_autogen/timestamp custom command.
  1064. // We cannot just use Moc.CompilationFileGenex here, because that
  1065. // custom command runs cmake_autogen for each configuration.
  1066. for (const auto& p : this->Moc.CompilationFile.Config) {
  1067. timestampByproducts.push_back(p.second);
  1068. }
  1069. } else {
  1070. timestampByproducts.push_back(this->Moc.CompilationFileGenex);
  1071. }
  1072. } else {
  1073. autogenByproducts.push_back(this->Moc.CompilationFileGenex);
  1074. }
  1075. }
  1076. if (this->Uic.Enabled) {
  1077. for (const auto& file : this->Uic.UiHeaders) {
  1078. this->AddGeneratedSource(file.first, this->Uic);
  1079. autogenByproducts.push_back(file.second);
  1080. }
  1081. }
  1082. // Compose target comment
  1083. std::string autogenComment;
  1084. {
  1085. std::string tools;
  1086. if (this->Moc.Enabled) {
  1087. tools += "MOC";
  1088. }
  1089. if (this->Uic.Enabled) {
  1090. if (!tools.empty()) {
  1091. tools += " and ";
  1092. }
  1093. tools += "UIC";
  1094. }
  1095. autogenComment = cmStrCat("Automatic ", tools, " for target ",
  1096. this->GenTarget->GetName());
  1097. }
  1098. // Compose command lines
  1099. // FIXME: Take advantage of our per-config mocs_compilation_$<CONFIG>.cpp
  1100. // instead of fiddling with the include directories
  1101. std::vector<std::string> configs;
  1102. this->GlobalGen->GetQtAutoGenConfigs(configs);
  1103. bool stdPipesUTF8 = true;
  1104. cmCustomCommandLines commandLines;
  1105. for (auto const& config : configs) {
  1106. commandLines.push_back(cmMakeCommandLine(
  1107. { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
  1108. this->AutogenTarget.InfoFile, config }));
  1109. }
  1110. // Use PRE_BUILD on demand
  1111. bool usePRE_BUILD = false;
  1112. if (this->GlobalGen->GetName().find("Visual Studio") != std::string::npos) {
  1113. // Under VS use a PRE_BUILD event instead of a separate target to
  1114. // reduce the number of targets loaded into the IDE.
  1115. // This also works around a VS 11 bug that may skip updating the target:
  1116. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  1117. usePRE_BUILD = true;
  1118. }
  1119. // Disable PRE_BUILD in some cases
  1120. if (usePRE_BUILD) {
  1121. // Cannot use PRE_BUILD with file depends
  1122. if (!this->AutogenTarget.DependFiles.empty()) {
  1123. usePRE_BUILD = false;
  1124. }
  1125. // Cannot use PRE_BUILD when a global autogen target is in place
  1126. if (this->AutogenTarget.GlobalTarget) {
  1127. usePRE_BUILD = false;
  1128. }
  1129. }
  1130. // Create the autogen target/command
  1131. if (usePRE_BUILD) {
  1132. // Add additional autogen target dependencies to origin target
  1133. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  1134. this->GenTarget->Target->AddUtility(depTarget->GetName(), false,
  1135. this->Makefile);
  1136. }
  1137. if (!this->Uic.UiFilesNoOptions.empty() ||
  1138. !this->Uic.UiFilesWithOptions.empty()) {
  1139. // Add a generated timestamp file
  1140. ConfigString timestampFile;
  1141. std::string timestampFileGenex;
  1142. ConfigFileNamesAndGenex(timestampFile, timestampFileGenex,
  1143. cmStrCat(this->Dir.Build, "/autouic"_s),
  1144. ".stamp"_s);
  1145. this->AddGeneratedSource(timestampFile, this->Uic);
  1146. // Add a step in the pre-build command to touch the timestamp file
  1147. commandLines.push_back(
  1148. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", "touch",
  1149. timestampFileGenex }));
  1150. // UIC needs to be re-run if any of the known UI files change or the
  1151. // executable itself has been updated
  1152. auto uicDependencies = this->Uic.UiFilesNoOptions;
  1153. for (auto const& uiFile : this->Uic.UiFilesWithOptions) {
  1154. uicDependencies.push_back(uiFile.first);
  1155. }
  1156. AddAutogenExecutableToDependencies(this->Uic, uicDependencies);
  1157. // Add a rule file to cause the target to build if a dependency has
  1158. // changed, which will trigger the pre-build command to run autogen
  1159. auto cc = cm::make_unique<cmCustomCommand>();
  1160. cc->SetOutputs(timestampFileGenex);
  1161. cc->SetDepends(uicDependencies);
  1162. cc->SetComment("");
  1163. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1164. cc->SetEscapeOldStyle(false);
  1165. cc->SetStdPipesUTF8(stdPipesUTF8);
  1166. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1167. }
  1168. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  1169. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  1170. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  1171. //
  1172. // PRE_BUILD does not support file dependencies!
  1173. cmCustomCommand cc;
  1174. cc.SetByproducts(autogenByproducts);
  1175. cc.SetCommandLines(commandLines);
  1176. cc.SetComment(autogenComment.c_str());
  1177. cc.SetBacktrace(this->Makefile->GetBacktrace());
  1178. cc.SetWorkingDirectory(this->Dir.Work.c_str());
  1179. cc.SetStdPipesUTF8(stdPipesUTF8);
  1180. cc.SetEscapeOldStyle(false);
  1181. cc.SetEscapeAllowMakeVars(true);
  1182. this->GenTarget->Target->AddPreBuildCommand(std::move(cc));
  1183. } else {
  1184. // Add link library target dependencies to the autogen target
  1185. // dependencies
  1186. if (this->AutogenTarget.DependOrigin) {
  1187. // add_dependencies/addUtility do not support generator expressions.
  1188. // We depend only on the libraries found in all configs therefore.
  1189. std::map<cmGeneratorTarget const*, std::size_t> commonTargets;
  1190. for (std::string const& config : this->ConfigsList) {
  1191. cmLinkImplementationLibraries const* libs =
  1192. this->GenTarget->GetLinkImplementationLibraries(
  1193. config, cmGeneratorTarget::LinkInterfaceFor::Link);
  1194. if (libs) {
  1195. for (cmLinkItem const& item : libs->Libraries) {
  1196. cmGeneratorTarget const* libTarget = item.Target;
  1197. if (libTarget &&
  1198. !StaticLibraryCycle(this->GenTarget, libTarget, config)) {
  1199. // Increment target config count
  1200. commonTargets[libTarget]++;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. for (auto const& item : commonTargets) {
  1206. if (item.second == this->ConfigsList.size()) {
  1207. this->AutogenTarget.DependTargets.insert(item.first->Target);
  1208. }
  1209. }
  1210. }
  1211. std::vector<std::string> dependencies(
  1212. this->AutogenTarget.DependFiles.begin(),
  1213. this->AutogenTarget.DependFiles.end());
  1214. if (useNinjaDepfile) {
  1215. // Create a custom command that generates a timestamp file and
  1216. // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
  1217. //
  1218. // Also create an additional '_autogen_timestamp_deps' that the custom
  1219. // command will depend on. It will have no sources or commands to
  1220. // execute, but it will have dependencies that would originally be
  1221. // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will
  1222. // serve as a list of order-only dependencies for the custom command,
  1223. // without forcing the custom command to re-execute.
  1224. //
  1225. // The dependency tree would then look like
  1226. // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <-
  1227. // '_autogen' target.
  1228. const auto timestampTargetName =
  1229. cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
  1230. std::vector<std::string> timestampTargetProvides;
  1231. cmCustomCommandLines timestampTargetCommandLines;
  1232. // Add additional autogen target dependencies to
  1233. // '_autogen_timestamp_deps'.
  1234. for (const cmTarget* t : this->AutogenTarget.DependTargets) {
  1235. std::string depname = t->GetName();
  1236. if (t->IsImported()) {
  1237. auto ttype = t->GetType();
  1238. if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY ||
  1239. ttype == cmStateEnums::TargetType::SHARED_LIBRARY ||
  1240. ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) {
  1241. depname = cmStrCat("$<TARGET_LINKER_FILE:", t->GetName(), ">");
  1242. }
  1243. }
  1244. dependencies.push_back(depname);
  1245. }
  1246. auto cc = cm::make_unique<cmCustomCommand>();
  1247. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1248. cc->SetByproducts(timestampTargetProvides);
  1249. cc->SetDepends(dependencies);
  1250. cc->SetCommandLines(timestampTargetCommandLines);
  1251. cc->SetEscapeOldStyle(false);
  1252. cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
  1253. timestampTargetName, true, std::move(cc));
  1254. this->LocalGen->AddGeneratorTarget(
  1255. cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
  1256. // Set FOLDER property on the timestamp target, so it appears in the
  1257. // appropriate folder in an IDE or in the file api.
  1258. if (!this->TargetsFolder.empty()) {
  1259. timestampTarget->SetProperty("FOLDER", this->TargetsFolder);
  1260. }
  1261. // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the
  1262. // moc and uic executables (whichever are enabled).
  1263. dependencies.clear();
  1264. dependencies.push_back(timestampTargetName);
  1265. AddAutogenExecutableToDependencies(this->Moc, dependencies);
  1266. AddAutogenExecutableToDependencies(this->Uic, dependencies);
  1267. // Create the custom command that outputs the timestamp file.
  1268. const char timestampFileName[] = "timestamp";
  1269. const std::string outputFile =
  1270. cmStrCat(this->Dir.Build, "/", timestampFileName);
  1271. this->AutogenTarget.DepFile = cmStrCat(this->Dir.Build, "/deps");
  1272. this->AutogenTarget.DepFileRuleName =
  1273. cmStrCat(this->Dir.RelativeBuild, "/", timestampFileName);
  1274. commandLines.push_back(cmMakeCommandLine(
  1275. { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
  1276. this->AddGeneratedSource(outputFile, this->Moc);
  1277. cc = cm::make_unique<cmCustomCommand>();
  1278. cc->SetOutputs(outputFile);
  1279. cc->SetByproducts(timestampByproducts);
  1280. cc->SetDepends(dependencies);
  1281. cc->SetCommandLines(commandLines);
  1282. cc->SetComment(autogenComment.c_str());
  1283. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1284. cc->SetEscapeOldStyle(false);
  1285. cc->SetDepfile(this->AutogenTarget.DepFile);
  1286. cc->SetStdPipesUTF8(stdPipesUTF8);
  1287. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1288. // Alter variables for the autogen target which now merely wraps the
  1289. // custom command
  1290. dependencies.clear();
  1291. dependencies.push_back(outputFile);
  1292. commandLines.clear();
  1293. autogenComment.clear();
  1294. }
  1295. // Create autogen target
  1296. auto cc = cm::make_unique<cmCustomCommand>();
  1297. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1298. cc->SetByproducts(autogenByproducts);
  1299. cc->SetDepends(dependencies);
  1300. cc->SetCommandLines(commandLines);
  1301. cc->SetEscapeOldStyle(false);
  1302. cc->SetComment(autogenComment.c_str());
  1303. cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand(
  1304. this->AutogenTarget.Name, true, std::move(cc));
  1305. // Create autogen generator target
  1306. this->LocalGen->AddGeneratorTarget(
  1307. cm::make_unique<cmGeneratorTarget>(autogenTarget, this->LocalGen));
  1308. // Forward origin utilities to autogen target
  1309. if (this->AutogenTarget.DependOrigin) {
  1310. for (BT<std::pair<std::string, bool>> const& depName :
  1311. this->GenTarget->GetUtilities()) {
  1312. autogenTarget->AddUtility(depName.Value.first, false, this->Makefile);
  1313. }
  1314. }
  1315. if (!useNinjaDepfile) {
  1316. // Add additional autogen target dependencies to autogen target
  1317. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  1318. autogenTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
  1319. }
  1320. }
  1321. // Set FOLDER property in autogen target
  1322. if (!this->TargetsFolder.empty()) {
  1323. autogenTarget->SetProperty("FOLDER", this->TargetsFolder);
  1324. }
  1325. // Add autogen target to the origin target dependencies
  1326. this->GenTarget->Target->AddUtility(this->AutogenTarget.Name, false,
  1327. this->Makefile);
  1328. // Add autogen target to the global autogen target dependencies
  1329. if (this->AutogenTarget.GlobalTarget) {
  1330. this->GlobalInitializer->AddToGlobalAutoGen(this->LocalGen,
  1331. this->AutogenTarget.Name);
  1332. }
  1333. }
  1334. return true;
  1335. }
  1336. bool cmQtAutoGenInitializer::InitRccTargets()
  1337. {
  1338. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1339. // Register info file as generated by CMake
  1340. this->Makefile->AddCMakeOutputFile(qrc.InfoFile);
  1341. // Register file at target
  1342. {
  1343. cmSourceFile* sf = this->AddGeneratedSource(qrc.OutputFile, this->Rcc);
  1344. sf->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "On");
  1345. }
  1346. std::vector<std::string> ccOutput;
  1347. ccOutput.push_back(qrc.OutputFile);
  1348. std::vector<std::string> ccDepends;
  1349. // Add the .qrc and info file to the custom command dependencies
  1350. ccDepends.push_back(qrc.QrcFile);
  1351. ccDepends.push_back(qrc.InfoFile);
  1352. cmCustomCommandLines commandLines;
  1353. if (this->MultiConfig) {
  1354. // Build for all configurations
  1355. for (std::string const& config : this->ConfigsList) {
  1356. commandLines.push_back(
  1357. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
  1358. "cmake_autorcc", qrc.InfoFile, config }));
  1359. }
  1360. } else {
  1361. commandLines.push_back(
  1362. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
  1363. "cmake_autorcc", qrc.InfoFile, "$<CONFIG>" }));
  1364. }
  1365. std::string ccComment =
  1366. cmStrCat("Automatic RCC for ",
  1367. FileProjectRelativePath(this->Makefile, qrc.QrcFile));
  1368. auto cc = cm::make_unique<cmCustomCommand>();
  1369. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1370. cc->SetCommandLines(commandLines);
  1371. cc->SetComment(ccComment.c_str());
  1372. cc->SetStdPipesUTF8(true);
  1373. if (qrc.Generated || this->Rcc.GlobalTarget) {
  1374. // Create custom rcc target
  1375. std::string ccName;
  1376. {
  1377. ccName = cmStrCat(this->GenTarget->GetName(), "_arcc_", qrc.QrcName);
  1378. if (!qrc.Unique) {
  1379. ccName += cmStrCat('_', qrc.QrcPathChecksum);
  1380. }
  1381. cc->SetByproducts(ccOutput);
  1382. cc->SetDepends(ccDepends);
  1383. cc->SetEscapeOldStyle(false);
  1384. cmTarget* autoRccTarget =
  1385. this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc));
  1386. // Create autogen generator target
  1387. this->LocalGen->AddGeneratorTarget(
  1388. cm::make_unique<cmGeneratorTarget>(autoRccTarget, this->LocalGen));
  1389. // Set FOLDER property in autogen target
  1390. if (!this->TargetsFolder.empty()) {
  1391. autoRccTarget->SetProperty("FOLDER", this->TargetsFolder);
  1392. }
  1393. if (!this->Rcc.ExecutableTargetName.empty()) {
  1394. autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, false,
  1395. this->Makefile);
  1396. }
  1397. }
  1398. // Add autogen target to the origin target dependencies
  1399. this->GenTarget->Target->AddUtility(ccName, false, this->Makefile);
  1400. // Add autogen target to the global autogen target dependencies
  1401. if (this->Rcc.GlobalTarget) {
  1402. this->GlobalInitializer->AddToGlobalAutoRcc(this->LocalGen, ccName);
  1403. }
  1404. } else {
  1405. // Create custom rcc command
  1406. {
  1407. std::vector<std::string> ccByproducts;
  1408. // Add the resource files to the dependencies
  1409. for (std::string const& fileName : qrc.Resources) {
  1410. // Add resource file to the custom command dependencies
  1411. ccDepends.push_back(fileName);
  1412. }
  1413. if (!this->Rcc.ExecutableTargetName.empty()) {
  1414. ccDepends.push_back(this->Rcc.ExecutableTargetName);
  1415. }
  1416. cc->SetOutputs(ccOutput);
  1417. cc->SetByproducts(ccByproducts);
  1418. cc->SetDepends(ccDepends);
  1419. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1420. }
  1421. // Reconfigure when .qrc file changes
  1422. this->Makefile->AddCMakeDependFile(qrc.QrcFile);
  1423. }
  1424. }
  1425. return true;
  1426. }
  1427. bool cmQtAutoGenInitializer::SetupCustomTargets()
  1428. {
  1429. // Create info directory on demand
  1430. if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
  1431. cmSystemTools::Error(cmStrCat("AutoGen: Could not create directory: ",
  1432. Quoted(this->Dir.Info)));
  1433. return false;
  1434. }
  1435. // Generate autogen target info file
  1436. if (this->MocOrUicEnabled()) {
  1437. // Write autogen target info files
  1438. if (!this->SetupWriteAutogenInfo()) {
  1439. return false;
  1440. }
  1441. }
  1442. // Write AUTORCC info files
  1443. return !this->Rcc.Enabled || this->SetupWriteRccInfo();
  1444. }
  1445. bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
  1446. {
  1447. // Utility lambdas
  1448. auto MfDef = [this](std::string const& key) {
  1449. return this->Makefile->GetSafeDefinition(key);
  1450. };
  1451. // Filtered headers and sources
  1452. std::set<std::string> moc_skip;
  1453. std::set<std::string> uic_skip;
  1454. std::vector<MUFile const*> headers;
  1455. std::vector<MUFile const*> sources;
  1456. // Filter headers
  1457. {
  1458. headers.reserve(this->AutogenTarget.Headers.size());
  1459. for (auto const& pair : this->AutogenTarget.Headers) {
  1460. MUFile const* const muf = pair.second.get();
  1461. if (muf->SkipMoc) {
  1462. moc_skip.insert(muf->FullPath);
  1463. }
  1464. if (muf->SkipUic) {
  1465. uic_skip.insert(muf->FullPath);
  1466. }
  1467. if (muf->Generated && !this->CMP0071Accept) {
  1468. continue;
  1469. }
  1470. if (muf->MocIt || muf->UicIt) {
  1471. headers.emplace_back(muf);
  1472. }
  1473. }
  1474. std::sort(headers.begin(), headers.end(),
  1475. [](MUFile const* a, MUFile const* b) {
  1476. return (a->FullPath < b->FullPath);
  1477. });
  1478. }
  1479. // Filter sources
  1480. {
  1481. sources.reserve(this->AutogenTarget.Sources.size());
  1482. for (auto const& pair : this->AutogenTarget.Sources) {
  1483. MUFile const* const muf = pair.second.get();
  1484. if (muf->Generated && !this->CMP0071Accept) {
  1485. continue;
  1486. }
  1487. if (muf->SkipMoc) {
  1488. moc_skip.insert(muf->FullPath);
  1489. }
  1490. if (muf->SkipUic) {
  1491. uic_skip.insert(muf->FullPath);
  1492. }
  1493. if (muf->MocIt || muf->UicIt) {
  1494. sources.emplace_back(muf);
  1495. }
  1496. }
  1497. std::sort(sources.begin(), sources.end(),
  1498. [](MUFile const* a, MUFile const* b) {
  1499. return (a->FullPath < b->FullPath);
  1500. });
  1501. }
  1502. // Info writer
  1503. InfoWriter info;
  1504. // General
  1505. info.SetBool("MULTI_CONFIG", this->MultiConfig);
  1506. info.SetUInt("PARALLEL", this->AutogenTarget.Parallel);
  1507. info.SetUInt("VERBOSITY", this->Verbosity);
  1508. // Directories
  1509. info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1510. info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1511. info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1512. info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1513. info.Set("BUILD_DIR", this->Dir.Build);
  1514. info.SetConfig("INCLUDE_DIR", this->Dir.Include);
  1515. info.SetUInt("QT_VERSION_MAJOR", this->QtVersion.Major);
  1516. info.SetUInt("QT_VERSION_MINOR", this->QtVersion.Minor);
  1517. info.Set("QT_MOC_EXECUTABLE", this->Moc.Executable);
  1518. info.Set("QT_UIC_EXECUTABLE", this->Uic.Executable);
  1519. info.Set("CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand());
  1520. info.SetConfig("SETTINGS_FILE", this->AutogenTarget.SettingsFile);
  1521. info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
  1522. info.Set("DEP_FILE", this->AutogenTarget.DepFile);
  1523. info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName);
  1524. info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles());
  1525. info.SetArray("HEADER_EXTENSIONS",
  1526. this->Makefile->GetCMakeInstance()->GetHeaderExtensions());
  1527. auto cfgArray = [this](std::vector<size_t> const& configs) -> Json::Value {
  1528. Json::Value value;
  1529. if (!configs.empty()) {
  1530. value = Json::arrayValue;
  1531. for (size_t ci : configs) {
  1532. value.append(this->ConfigsList[ci]);
  1533. }
  1534. }
  1535. return value;
  1536. };
  1537. info.SetArrayArray("HEADERS", headers,
  1538. [this, &cfgArray](Json::Value& jval, MUFile const* muf) {
  1539. jval.resize(4u);
  1540. jval[0u] = muf->FullPath;
  1541. jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm',
  1542. muf->UicIt ? 'U' : 'u');
  1543. jval[2u] = this->GetMocBuildPath(*muf);
  1544. jval[3u] = cfgArray(muf->Configs);
  1545. });
  1546. info.SetArrayArray(
  1547. "SOURCES", sources, [&cfgArray](Json::Value& jval, MUFile const* muf) {
  1548. jval.resize(3u);
  1549. jval[0u] = muf->FullPath;
  1550. jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm', muf->UicIt ? 'U' : 'u');
  1551. jval[2u] = cfgArray(muf->Configs);
  1552. });
  1553. // Write moc settings
  1554. if (this->Moc.Enabled) {
  1555. info.SetArray("MOC_SKIP", moc_skip);
  1556. info.SetConfigArray("MOC_DEFINITIONS", this->Moc.Defines);
  1557. info.SetConfigArray("MOC_INCLUDES", this->Moc.Includes);
  1558. info.SetArray("MOC_OPTIONS", this->Moc.Options);
  1559. info.SetBool("MOC_RELAXED_MODE", this->Moc.RelaxedMode);
  1560. info.SetBool("MOC_PATH_PREFIX", this->Moc.PathPrefix);
  1561. cmGeneratorExpressionDAGChecker dagChecker(
  1562. this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr, nullptr);
  1563. EvaluatedTargetPropertyEntries InterfaceAutoMocMacroNamesEntries;
  1564. AddInterfaceEntries(this->GenTarget, this->ConfigDefault,
  1565. "INTERFACE_AUTOMOC_MACRO_NAMES", "CXX", &dagChecker,
  1566. InterfaceAutoMocMacroNamesEntries,
  1567. IncludeRuntimeInterface::Yes);
  1568. for (auto const& entry : InterfaceAutoMocMacroNamesEntries.Entries) {
  1569. this->Moc.MacroNames.insert(this->Moc.MacroNames.end(),
  1570. entry.Values.begin(), entry.Values.end());
  1571. }
  1572. this->Moc.MacroNames.erase(cmRemoveDuplicates(this->Moc.MacroNames),
  1573. this->Moc.MacroNames.end());
  1574. info.SetArray("MOC_MACRO_NAMES", this->Moc.MacroNames);
  1575. info.SetArrayArray(
  1576. "MOC_DEPEND_FILTERS", this->Moc.DependFilters,
  1577. [](Json::Value& jval, std::pair<std::string, std::string> const& pair) {
  1578. jval.resize(2u);
  1579. jval[0u] = pair.first;
  1580. jval[1u] = pair.second;
  1581. });
  1582. info.SetConfig("MOC_COMPILATION_FILE", this->Moc.CompilationFile);
  1583. info.SetConfig("MOC_PREDEFS_FILE", this->Moc.PredefsFile);
  1584. cmStandardLevelResolver resolver{ this->Makefile };
  1585. auto CompileOptionFlag =
  1586. resolver.GetCompileOptionDef(this->GenTarget, "CXX", "");
  1587. auto CompileOptionValue =
  1588. this->GenTarget->Makefile->GetSafeDefinition(CompileOptionFlag);
  1589. if (!CompileOptionValue.empty()) {
  1590. if (this->Moc.PredefsCmd.size() >= 3) {
  1591. this->Moc.PredefsCmd.insert(this->Moc.PredefsCmd.begin() + 1,
  1592. CompileOptionValue);
  1593. }
  1594. }
  1595. info.SetArray("MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
  1596. }
  1597. // Write uic settings
  1598. if (this->Uic.Enabled) {
  1599. // Add skipped .ui files
  1600. uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end());
  1601. info.SetArray("UIC_SKIP", uic_skip);
  1602. info.SetArrayArray("UIC_UI_FILES", this->Uic.UiFilesWithOptions,
  1603. [](Json::Value& jval, UicT::UiFileT const& uiFile) {
  1604. jval.resize(2u);
  1605. jval[0u] = uiFile.first;
  1606. InfoWriter::MakeStringArray(jval[1u], uiFile.second);
  1607. });
  1608. info.SetConfigArray("UIC_OPTIONS", this->Uic.Options);
  1609. info.SetArray("UIC_SEARCH_PATHS", this->Uic.SearchPaths);
  1610. }
  1611. info.Save(this->AutogenTarget.InfoFile);
  1612. return true;
  1613. }
  1614. bool cmQtAutoGenInitializer::SetupWriteRccInfo()
  1615. {
  1616. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1617. // Utility lambdas
  1618. auto MfDef = [this](std::string const& key) {
  1619. return this->Makefile->GetSafeDefinition(key);
  1620. };
  1621. InfoWriter info;
  1622. // General
  1623. info.SetBool("MULTI_CONFIG", this->MultiConfig);
  1624. info.SetUInt("VERBOSITY", this->Verbosity);
  1625. // Files
  1626. info.Set("LOCK_FILE", qrc.LockFile);
  1627. info.SetConfig("SETTINGS_FILE", qrc.SettingsFile);
  1628. // Directories
  1629. info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1630. info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1631. info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1632. info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1633. info.Set("BUILD_DIR", this->Dir.Build);
  1634. info.SetConfig("INCLUDE_DIR", this->Dir.Include);
  1635. // rcc executable
  1636. info.Set("RCC_EXECUTABLE", this->Rcc.Executable);
  1637. info.SetArray("RCC_LIST_OPTIONS",
  1638. this->Rcc.ExecutableFeatures->ListOptions);
  1639. // qrc file
  1640. info.Set("SOURCE", qrc.QrcFile);
  1641. info.Set("OUTPUT_CHECKSUM", qrc.QrcPathChecksum);
  1642. info.Set("OUTPUT_NAME", cmSystemTools::GetFilenameName(qrc.OutputFile));
  1643. info.SetArray("OPTIONS", qrc.Options);
  1644. info.SetArray("INPUTS", qrc.Resources);
  1645. info.Save(qrc.InfoFile);
  1646. }
  1647. return true;
  1648. }
  1649. cmSourceFile* cmQtAutoGenInitializer::RegisterGeneratedSource(
  1650. std::string const& filename)
  1651. {
  1652. cmSourceFile* gFile = this->Makefile->GetOrCreateSource(filename, true);
  1653. gFile->MarkAsGenerated();
  1654. gFile->SetProperty("SKIP_AUTOGEN", "1");
  1655. return gFile;
  1656. }
  1657. cmSourceFile* cmQtAutoGenInitializer::AddGeneratedSource(
  1658. std::string const& filename, GenVarsT const& genVars, bool prepend)
  1659. {
  1660. // Register source at makefile
  1661. cmSourceFile* gFile = this->RegisterGeneratedSource(filename);
  1662. // Add source file to target
  1663. this->GenTarget->AddSource(filename, prepend);
  1664. // Add source file to source group
  1665. this->AddToSourceGroup(filename, genVars.GenNameUpper);
  1666. return gFile;
  1667. }
  1668. void cmQtAutoGenInitializer::AddGeneratedSource(ConfigString const& filename,
  1669. GenVarsT const& genVars,
  1670. bool prepend)
  1671. {
  1672. // XXX(xcode-per-cfg-src): Drop the Xcode-specific part of the condition
  1673. // when the Xcode generator supports per-config sources.
  1674. if (!this->MultiConfig || this->GlobalGen->IsXcode()) {
  1675. cmSourceFile* sf =
  1676. this->AddGeneratedSource(filename.Default, genVars, prepend);
  1677. handleSkipPch(sf);
  1678. return;
  1679. }
  1680. for (auto const& cfg : this->ConfigsList) {
  1681. std::string const& filenameCfg = filename.Config.at(cfg);
  1682. // Register source at makefile
  1683. cmSourceFile* sf = this->RegisterGeneratedSource(filenameCfg);
  1684. handleSkipPch(sf);
  1685. // Add source file to target for this configuration.
  1686. this->GenTarget->AddSource(
  1687. cmStrCat("$<$<CONFIG:"_s, cfg, ">:"_s, filenameCfg, ">"_s), prepend);
  1688. // Add source file to source group
  1689. this->AddToSourceGroup(filenameCfg, genVars.GenNameUpper);
  1690. }
  1691. }
  1692. void cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
  1693. cm::string_view genNameUpper)
  1694. {
  1695. cmSourceGroup* sourceGroup = nullptr;
  1696. // Acquire source group
  1697. {
  1698. std::string property;
  1699. std::string groupName;
  1700. {
  1701. // Prefer generator specific source group name
  1702. std::initializer_list<std::string> const props{
  1703. cmStrCat(genNameUpper, "_SOURCE_GROUP"), "AUTOGEN_SOURCE_GROUP"
  1704. };
  1705. for (std::string const& prop : props) {
  1706. cmValue propName = this->Makefile->GetState()->GetGlobalProperty(prop);
  1707. if (cmNonempty(propName)) {
  1708. groupName = *propName;
  1709. property = prop;
  1710. break;
  1711. }
  1712. }
  1713. }
  1714. // Generate a source group on demand
  1715. if (!groupName.empty()) {
  1716. sourceGroup = this->Makefile->GetOrCreateSourceGroup(groupName);
  1717. if (!sourceGroup) {
  1718. cmSystemTools::Error(
  1719. cmStrCat(genNameUpper, " error in ", property,
  1720. ": Could not find or create the source group ",
  1721. cmQtAutoGen::Quoted(groupName)));
  1722. }
  1723. }
  1724. }
  1725. if (sourceGroup) {
  1726. sourceGroup->AddGroupFile(fileName);
  1727. }
  1728. }
  1729. void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
  1730. {
  1731. this->GenTarget->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName);
  1732. }
  1733. void cmQtAutoGenInitializer::ConfigFileNames(ConfigString& configString,
  1734. cm::string_view prefix,
  1735. cm::string_view suffix)
  1736. {
  1737. configString.Default = cmStrCat(prefix, suffix);
  1738. if (this->MultiConfig) {
  1739. for (auto const& cfg : this->ConfigsList) {
  1740. configString.Config[cfg] = cmStrCat(prefix, '_', cfg, suffix);
  1741. }
  1742. }
  1743. }
  1744. void cmQtAutoGenInitializer::ConfigFileNamesAndGenex(
  1745. ConfigString& configString, std::string& genex, cm::string_view const prefix,
  1746. cm::string_view const suffix)
  1747. {
  1748. this->ConfigFileNames(configString, prefix, suffix);
  1749. if (this->MultiConfig) {
  1750. genex = cmStrCat(prefix, "_$<CONFIG>"_s, suffix);
  1751. } else {
  1752. genex = configString.Default;
  1753. }
  1754. }
  1755. void cmQtAutoGenInitializer::ConfigFileClean(ConfigString& configString)
  1756. {
  1757. this->AddCleanFile(configString.Default);
  1758. if (this->MultiConfig) {
  1759. for (auto const& pair : configString.Config) {
  1760. this->AddCleanFile(pair.second);
  1761. }
  1762. }
  1763. }
  1764. static cmQtAutoGen::IntegerVersion parseMocVersion(std::string str)
  1765. {
  1766. cmQtAutoGen::IntegerVersion result;
  1767. static const std::string prelude = "moc ";
  1768. size_t pos = str.find(prelude);
  1769. if (pos == std::string::npos) {
  1770. return result;
  1771. }
  1772. str.erase(0, prelude.size() + pos);
  1773. std::istringstream iss(str);
  1774. std::string major;
  1775. std::string minor;
  1776. if (!std::getline(iss, major, '.') || !std::getline(iss, minor, '.')) {
  1777. return result;
  1778. }
  1779. result.Major = static_cast<unsigned int>(std::stoi(major));
  1780. result.Minor = static_cast<unsigned int>(std::stoi(minor));
  1781. return result;
  1782. }
  1783. static cmQtAutoGen::IntegerVersion GetMocVersion(
  1784. const std::string& mocExecutablePath)
  1785. {
  1786. std::string capturedStdOut;
  1787. int exitCode;
  1788. if (!cmSystemTools::RunSingleCommand({ mocExecutablePath, "--version" },
  1789. &capturedStdOut, nullptr, &exitCode,
  1790. nullptr, cmSystemTools::OUTPUT_NONE)) {
  1791. return {};
  1792. }
  1793. if (exitCode != 0) {
  1794. return {};
  1795. }
  1796. return parseMocVersion(capturedStdOut);
  1797. }
  1798. static std::string FindMocExecutableFromMocTarget(cmMakefile* makefile,
  1799. unsigned int qtMajorVersion)
  1800. {
  1801. std::string result;
  1802. const std::string mocTargetName =
  1803. "Qt" + std::to_string(qtMajorVersion) + "::moc";
  1804. cmTarget* mocTarget = makefile->FindTargetToUse(mocTargetName);
  1805. if (mocTarget) {
  1806. result = mocTarget->GetSafeProperty("IMPORTED_LOCATION");
  1807. }
  1808. return result;
  1809. }
  1810. std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
  1811. cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target,
  1812. std::string mocExecutable)
  1813. {
  1814. // Converts a char ptr to an unsigned int value
  1815. auto toUInt = [](const char* const input) -> unsigned int {
  1816. unsigned long tmp = 0;
  1817. if (input && cmStrToULong(input, &tmp)) {
  1818. return static_cast<unsigned int>(tmp);
  1819. }
  1820. return 0u;
  1821. };
  1822. auto toUInt2 = [](cmValue input) -> unsigned int {
  1823. unsigned long tmp = 0;
  1824. if (input && cmStrToULong(*input, &tmp)) {
  1825. return static_cast<unsigned int>(tmp);
  1826. }
  1827. return 0u;
  1828. };
  1829. // Initialize return value to a default
  1830. std::pair<IntegerVersion, unsigned int> res(
  1831. IntegerVersion(),
  1832. toUInt(target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
  1833. "")));
  1834. // Acquire known Qt versions
  1835. std::vector<cmQtAutoGen::IntegerVersion> knownQtVersions;
  1836. {
  1837. // Qt version variable prefixes
  1838. static std::initializer_list<
  1839. std::pair<cm::string_view, cm::string_view>> const keys{
  1840. { "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
  1841. { "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
  1842. { "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
  1843. };
  1844. knownQtVersions.reserve(keys.size() * 2);
  1845. // Adds a version to the result (nullptr safe)
  1846. auto addVersion = [&knownQtVersions, &toUInt2](cmValue major,
  1847. cmValue minor) {
  1848. cmQtAutoGen::IntegerVersion ver(toUInt2(major), toUInt2(minor));
  1849. if (ver.Major != 0) {
  1850. knownQtVersions.emplace_back(ver);
  1851. }
  1852. };
  1853. // Read versions from variables
  1854. for (auto const& keyPair : keys) {
  1855. addVersion(target->Makefile->GetDefinition(std::string(keyPair.first)),
  1856. target->Makefile->GetDefinition(std::string(keyPair.second)));
  1857. }
  1858. // Read versions from directory properties
  1859. for (auto const& keyPair : keys) {
  1860. addVersion(target->Makefile->GetProperty(std::string(keyPair.first)),
  1861. target->Makefile->GetProperty(std::string(keyPair.second)));
  1862. }
  1863. }
  1864. // Evaluate known Qt versions
  1865. if (!knownQtVersions.empty()) {
  1866. if (res.second == 0) {
  1867. // No specific version was requested by the target:
  1868. // Use highest known Qt version.
  1869. res.first = knownQtVersions.at(0);
  1870. } else {
  1871. // Pick a version from the known versions:
  1872. for (auto it : knownQtVersions) {
  1873. if (it.Major == res.second) {
  1874. res.first = it;
  1875. break;
  1876. }
  1877. }
  1878. }
  1879. }
  1880. if (res.first.Major == 0) {
  1881. // We could not get the version number from variables or directory
  1882. // properties. This might happen if the find_package call for Qt is wrapped
  1883. // in a function. Try to find the moc executable path from the available
  1884. // targets and call "moc --version" to get the Qt version.
  1885. if (mocExecutable.empty()) {
  1886. mocExecutable =
  1887. FindMocExecutableFromMocTarget(target->Makefile, res.second);
  1888. }
  1889. if (!mocExecutable.empty()) {
  1890. res.first = GetMocVersion(mocExecutable);
  1891. }
  1892. }
  1893. return res;
  1894. }
  1895. std::string cmQtAutoGenInitializer::GetMocBuildPath(MUFile const& muf)
  1896. {
  1897. std::string res;
  1898. if (!muf.MocIt) {
  1899. return res;
  1900. }
  1901. std::string basePath =
  1902. cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_",
  1903. FileNameWithoutLastExtension(muf.FullPath));
  1904. res = cmStrCat(basePath, ".cpp");
  1905. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1906. return res;
  1907. }
  1908. // File name already emitted.
  1909. // Try appending the header suffix to the base path.
  1910. basePath = cmStrCat(basePath, '_', muf.SF->GetExtension());
  1911. res = cmStrCat(basePath, ".cpp");
  1912. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1913. return res;
  1914. }
  1915. // File name with header extension already emitted.
  1916. // Try adding a number to the base path.
  1917. constexpr std::size_t number_begin = 2;
  1918. constexpr std::size_t number_end = 256;
  1919. for (std::size_t ii = number_begin; ii != number_end; ++ii) {
  1920. res = cmStrCat(basePath, '_', ii, ".cpp");
  1921. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1922. return res;
  1923. }
  1924. }
  1925. // Output file name conflict (unlikely, but still...)
  1926. cmSystemTools::Error(
  1927. cmStrCat("moc output file name conflict for ", muf.FullPath));
  1928. return res;
  1929. }
  1930. bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
  1931. const std::string& executable,
  1932. bool ignoreMissingTarget) const
  1933. {
  1934. auto print_err = [this, &genVars](std::string const& err) {
  1935. cmSystemTools::Error(cmStrCat(genVars.GenNameUpper, " for target ",
  1936. this->GenTarget->GetName(), ": ", err));
  1937. };
  1938. // Custom executable
  1939. {
  1940. std::string const prop = cmStrCat(genVars.GenNameUpper, "_EXECUTABLE");
  1941. std::string const& val = this->GenTarget->Target->GetSafeProperty(prop);
  1942. if (!val.empty()) {
  1943. // Evaluate generator expression
  1944. {
  1945. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1946. cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt);
  1947. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
  1948. genVars.Executable = cge->Evaluate(this->LocalGen, "");
  1949. }
  1950. if (genVars.Executable.empty() && !ignoreMissingTarget) {
  1951. print_err(prop + " evaluates to an empty value");
  1952. return false;
  1953. }
  1954. // Create empty compiler features.
  1955. genVars.ExecutableFeatures =
  1956. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1957. return true;
  1958. }
  1959. }
  1960. // Find executable target
  1961. {
  1962. // Find executable target name
  1963. cm::string_view prefix;
  1964. if (this->QtVersion.Major == 4) {
  1965. prefix = "Qt4::";
  1966. } else if (this->QtVersion.Major == 5) {
  1967. prefix = "Qt5::";
  1968. } else if (this->QtVersion.Major == 6) {
  1969. prefix = "Qt6::";
  1970. }
  1971. std::string const targetName = cmStrCat(prefix, executable);
  1972. // Find target
  1973. cmGeneratorTarget* genTarget =
  1974. this->LocalGen->FindGeneratorTargetToUse(targetName);
  1975. if (genTarget) {
  1976. genVars.ExecutableTargetName = targetName;
  1977. genVars.ExecutableTarget = genTarget;
  1978. if (genTarget->IsImported()) {
  1979. genVars.Executable = genTarget->ImportedGetLocation("");
  1980. } else {
  1981. genVars.Executable = genTarget->GetLocation("");
  1982. }
  1983. } else {
  1984. if (ignoreMissingTarget) {
  1985. // Create empty compiler features.
  1986. genVars.ExecutableFeatures =
  1987. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1988. return true;
  1989. }
  1990. print_err(cmStrCat("Could not find ", executable, " executable target ",
  1991. targetName));
  1992. return false;
  1993. }
  1994. }
  1995. // Get executable features
  1996. {
  1997. std::string err;
  1998. genVars.ExecutableFeatures = this->GlobalInitializer->GetCompilerFeatures(
  1999. executable, genVars.Executable, err);
  2000. if (!genVars.ExecutableFeatures) {
  2001. print_err(err);
  2002. return false;
  2003. }
  2004. }
  2005. return true;
  2006. }
  2007. void cmQtAutoGenInitializer::handleSkipPch(cmSourceFile* sf)
  2008. {
  2009. bool skipPch = true;
  2010. for (auto const& pair : this->AutogenTarget.Sources) {
  2011. if (!pair.first->GetIsGenerated() &&
  2012. !pair.first->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  2013. skipPch = false;
  2014. }
  2015. }
  2016. if (skipPch) {
  2017. sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
  2018. }
  2019. }