cmQtAutoGenInitializer.cxx 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219
  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::size_type ii = 0; ii != filterList.size(); ii += 2) {
  508. this->Moc.DependFilters.emplace_back(filterList[ii],
  509. filterList[ii + 1]);
  510. }
  511. }
  512. }
  513. }
  514. // Init rcc specific settings
  515. if (this->Rcc.Enabled && !this->InitRcc()) {
  516. return false;
  517. }
  518. // Add autogen include directory to the origin target INCLUDE_DIRECTORIES
  519. if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) {
  520. this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, true);
  521. }
  522. // Scan files
  523. if (!this->InitScanFiles()) {
  524. return false;
  525. }
  526. // Create autogen target
  527. if (this->MocOrUicEnabled() && !this->InitAutogenTarget()) {
  528. return false;
  529. }
  530. // Create rcc targets
  531. if (this->Rcc.Enabled && !this->InitRccTargets()) {
  532. return false;
  533. }
  534. return true;
  535. }
  536. bool cmQtAutoGenInitializer::InitMoc()
  537. {
  538. // Mocs compilation file
  539. if (this->GlobalGen->IsXcode()) {
  540. // XXX(xcode-per-cfg-src): Drop this Xcode-specific code path
  541. // when the Xcode generator supports per-config sources.
  542. this->Moc.CompilationFile.Default =
  543. cmStrCat(this->Dir.Build, "/mocs_compilation.cpp");
  544. this->Moc.CompilationFileGenex = this->Moc.CompilationFile.Default;
  545. } else {
  546. this->ConfigFileNamesAndGenex(
  547. this->Moc.CompilationFile, this->Moc.CompilationFileGenex,
  548. cmStrCat(this->Dir.Build, "/mocs_compilation"_s), ".cpp"_s);
  549. }
  550. // Moc predefs
  551. if (this->GenTarget->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
  552. (this->QtVersion >= IntegerVersion(5, 8))) {
  553. // Command
  554. this->Makefile->GetDefExpandList("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND",
  555. this->Moc.PredefsCmd);
  556. // Header
  557. if (!this->Moc.PredefsCmd.empty()) {
  558. this->ConfigFileNames(this->Moc.PredefsFile,
  559. cmStrCat(this->Dir.Build, "/moc_predefs"), ".h");
  560. }
  561. }
  562. // Moc includes
  563. {
  564. SearchPathSanitizer sanitizer(this->Makefile);
  565. auto getDirs =
  566. [this, &sanitizer](std::string const& cfg) -> std::vector<std::string> {
  567. // Get the include dirs for this target, without stripping the implicit
  568. // include dirs off, see issue #13667.
  569. std::vector<std::string> dirs;
  570. bool const appendImplicit = (this->QtVersion.Major >= 5);
  571. this->LocalGen->GetIncludeDirectoriesImplicit(
  572. dirs, this->GenTarget, "CXX", cfg, false, appendImplicit);
  573. return sanitizer(dirs);
  574. };
  575. // Default configuration include directories
  576. this->Moc.Includes.Default = getDirs(this->ConfigDefault);
  577. // Other configuration settings
  578. if (this->MultiConfig) {
  579. for (std::string const& cfg : this->ConfigsList) {
  580. std::vector<std::string> dirs = getDirs(cfg);
  581. if (dirs == this->Moc.Includes.Default) {
  582. continue;
  583. }
  584. this->Moc.Includes.Config[cfg] = std::move(dirs);
  585. }
  586. }
  587. }
  588. // Moc compile definitions
  589. {
  590. auto getDefs = [this](std::string const& cfg) -> std::set<std::string> {
  591. std::set<std::string> defines;
  592. this->LocalGen->GetTargetDefines(this->GenTarget, cfg, "CXX", defines);
  593. if (this->Moc.PredefsCmd.empty() &&
  594. this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") ==
  595. "Windows") {
  596. // Add WIN32 definition if we don't have a moc_predefs.h
  597. defines.insert("WIN32");
  598. }
  599. return defines;
  600. };
  601. // Default configuration defines
  602. this->Moc.Defines.Default = getDefs(this->ConfigDefault);
  603. // Other configuration defines
  604. if (this->MultiConfig) {
  605. for (std::string const& cfg : this->ConfigsList) {
  606. std::set<std::string> defines = getDefs(cfg);
  607. if (defines == this->Moc.Defines.Default) {
  608. continue;
  609. }
  610. this->Moc.Defines.Config[cfg] = std::move(defines);
  611. }
  612. }
  613. }
  614. // Moc executable
  615. {
  616. if (!this->GetQtExecutable(this->Moc, "moc", false)) {
  617. return false;
  618. }
  619. // Let the _autogen target depend on the moc executable
  620. if (this->Moc.ExecutableTarget) {
  621. this->AutogenTarget.DependTargets.insert(
  622. this->Moc.ExecutableTarget->Target);
  623. }
  624. }
  625. return true;
  626. }
  627. bool cmQtAutoGenInitializer::InitUic()
  628. {
  629. // Uic search paths
  630. {
  631. std::string const& usp =
  632. this->GenTarget->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
  633. if (!usp.empty()) {
  634. this->Uic.SearchPaths =
  635. SearchPathSanitizer(this->Makefile)(cmList{ usp });
  636. }
  637. }
  638. // Uic target options
  639. {
  640. auto getOpts = [this](std::string const& cfg) -> std::vector<std::string> {
  641. std::vector<std::string> opts;
  642. this->GenTarget->GetAutoUicOptions(opts, cfg);
  643. return opts;
  644. };
  645. // Default options
  646. this->Uic.Options.Default = getOpts(this->ConfigDefault);
  647. // Configuration specific options
  648. if (this->MultiConfig) {
  649. for (std::string const& cfg : this->ConfigsList) {
  650. std::vector<std::string> options = getOpts(cfg);
  651. if (options == this->Uic.Options.Default) {
  652. continue;
  653. }
  654. this->Uic.Options.Config[cfg] = std::move(options);
  655. }
  656. }
  657. }
  658. // Uic executable
  659. {
  660. if (!this->GetQtExecutable(this->Uic, "uic", true)) {
  661. return false;
  662. }
  663. // Let the _autogen target depend on the uic executable
  664. if (this->Uic.ExecutableTarget) {
  665. this->AutogenTarget.DependTargets.insert(
  666. this->Uic.ExecutableTarget->Target);
  667. }
  668. }
  669. return true;
  670. }
  671. bool cmQtAutoGenInitializer::InitRcc()
  672. {
  673. // Rcc executable
  674. {
  675. if (!this->GetQtExecutable(this->Rcc, "rcc", false)) {
  676. return false;
  677. }
  678. // Evaluate test output on demand
  679. CompilerFeatures& features = *this->Rcc.ExecutableFeatures;
  680. if (!features.Evaluated) {
  681. // Look for list options
  682. if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
  683. if (features.HelpOutput.find("--list") != std::string::npos) {
  684. features.ListOptions.emplace_back("--list");
  685. } else if (features.HelpOutput.find("-list") != std::string::npos) {
  686. features.ListOptions.emplace_back("-list");
  687. }
  688. }
  689. // Evaluation finished
  690. features.Evaluated = true;
  691. }
  692. }
  693. return true;
  694. }
  695. bool cmQtAutoGenInitializer::InitScanFiles()
  696. {
  697. cmake const* cm = this->Makefile->GetCMakeInstance();
  698. auto const& kw = this->GlobalInitializer->kw();
  699. auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
  700. std::vector<size_t> const& configs,
  701. bool muIt) -> MUFileHandle {
  702. MUFileHandle muf = cm::make_unique<MUFile>();
  703. muf->FullPath = fullPath;
  704. muf->SF = sf;
  705. if (!configs.empty() && configs.size() != this->ConfigsList.size()) {
  706. muf->Configs = configs;
  707. }
  708. muf->Generated = sf->GetIsGenerated();
  709. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  710. muf->SkipMoc = this->Moc.Enabled &&
  711. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC));
  712. muf->SkipUic = this->Uic.Enabled &&
  713. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  714. if (muIt) {
  715. muf->MocIt = this->Moc.Enabled && !muf->SkipMoc;
  716. muf->UicIt = this->Uic.Enabled && !muf->SkipUic;
  717. }
  718. return muf;
  719. };
  720. auto addMUHeader = [this](MUFileHandle&& muf, cm::string_view extension) {
  721. cmSourceFile* sf = muf->SF;
  722. const bool muIt = (muf->MocIt || muf->UicIt);
  723. if (this->CMP0100Accept || (extension != "hh")) {
  724. // Accept
  725. if (muIt && muf->Generated) {
  726. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  727. }
  728. this->AutogenTarget.Headers.emplace(sf, std::move(muf));
  729. } else if (muIt && this->CMP0100Warn) {
  730. // Store file for warning message
  731. this->AutogenTarget.CMP0100HeadersWarn.push_back(sf);
  732. }
  733. };
  734. auto addMUSource = [this](MUFileHandle&& muf) {
  735. if ((muf->MocIt || muf->UicIt) && muf->Generated) {
  736. this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
  737. }
  738. this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf));
  739. };
  740. // Scan through target files
  741. {
  742. // Scan through target files
  743. for (cmGeneratorTarget::AllConfigSource const& acs :
  744. this->GenTarget->GetAllConfigSources()) {
  745. std::string const& fullPath = acs.Source->GetFullPath();
  746. std::string const& extLower =
  747. cmSystemTools::LowerCase(acs.Source->GetExtension());
  748. // Register files that will be scanned by moc or uic
  749. if (this->MocOrUicEnabled()) {
  750. if (cm->IsAHeaderExtension(extLower)) {
  751. addMUHeader(makeMUFile(acs.Source, fullPath, acs.Configs, true),
  752. extLower);
  753. } else if (cm->IsACLikeSourceExtension(extLower)) {
  754. addMUSource(makeMUFile(acs.Source, fullPath, acs.Configs, true));
  755. }
  756. }
  757. // Register rcc enabled files
  758. if (this->Rcc.Enabled) {
  759. if ((extLower == kw.qrc) &&
  760. !acs.Source->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
  761. !acs.Source->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
  762. // Register qrc file
  763. Qrc qrc;
  764. qrc.QrcFile = fullPath;
  765. qrc.QrcName =
  766. cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile);
  767. qrc.Generated = acs.Source->GetIsGenerated();
  768. // RCC options
  769. {
  770. std::string const& opts =
  771. acs.Source->GetSafeProperty(kw.AUTORCC_OPTIONS);
  772. if (!opts.empty()) {
  773. cmExpandList(opts, qrc.Options);
  774. }
  775. }
  776. this->Rcc.Qrcs.push_back(std::move(qrc));
  777. }
  778. }
  779. }
  780. }
  781. // cmGeneratorTarget::GetAllConfigSources computes the target's
  782. // sources meta data cache. Clear it so that OBJECT library targets that
  783. // are AUTOGEN initialized after this target get their added
  784. // mocs_compilation.cpp source acknowledged by this target.
  785. this->GenTarget->ClearSourcesCache();
  786. // For source files find additional headers and private headers
  787. if (this->MocOrUicEnabled()) {
  788. // Header search suffixes and extensions
  789. static std::initializer_list<cm::string_view> const suffixes{ "", "_p" };
  790. auto const& exts = cm->GetHeaderExtensions();
  791. // Scan through sources
  792. for (auto const& pair : this->AutogenTarget.Sources) {
  793. MUFile const& muf = *pair.second;
  794. if (muf.MocIt || muf.UicIt) {
  795. // Search for the default header file and a private header
  796. std::string const& srcFullPath = muf.SF->ResolveFullPath();
  797. std::string basePath = cmStrCat(
  798. cmQtAutoGen::SubDirPrefix(srcFullPath),
  799. cmSystemTools::GetFilenameWithoutLastExtension(srcFullPath));
  800. for (auto const& suffix : suffixes) {
  801. std::string const suffixedPath = cmStrCat(basePath, suffix);
  802. for (auto const& ext : exts) {
  803. std::string fullPath = cmStrCat(suffixedPath, '.', ext);
  804. auto constexpr locationKind = cmSourceFileLocationKind::Known;
  805. cmSourceFile* sf =
  806. this->Makefile->GetSource(fullPath, locationKind);
  807. if (sf) {
  808. // Check if we know about this header already
  809. if (cm::contains(this->AutogenTarget.Headers, sf)) {
  810. continue;
  811. }
  812. // We only accept not-GENERATED files that do exist.
  813. if (!sf->GetIsGenerated() &&
  814. !cmSystemTools::FileExists(fullPath)) {
  815. continue;
  816. }
  817. } else if (cmSystemTools::FileExists(fullPath)) {
  818. // Create a new source file for the existing file
  819. sf = this->Makefile->CreateSource(fullPath, false, locationKind);
  820. }
  821. if (sf) {
  822. auto eMuf = makeMUFile(sf, fullPath, muf.Configs, true);
  823. // Only process moc/uic when the parent is processed as well
  824. if (!muf.MocIt) {
  825. eMuf->MocIt = false;
  826. }
  827. if (!muf.UicIt) {
  828. eMuf->UicIt = false;
  829. }
  830. addMUHeader(std::move(eMuf), ext);
  831. }
  832. }
  833. }
  834. }
  835. }
  836. }
  837. // Scan through all source files in the makefile to extract moc and uic
  838. // parameters. Historically we support non target source file parameters.
  839. // The reason is that their file names might be discovered from source files
  840. // at generation time.
  841. if (this->MocOrUicEnabled()) {
  842. for (const auto& sf : this->Makefile->GetSourceFiles()) {
  843. // sf->GetExtension() is only valid after sf->ResolveFullPath() ...
  844. // Since we're iterating over source files that might be not in the
  845. // target we need to check for path errors (not existing files).
  846. std::string pathError;
  847. std::string const& fullPath = sf->ResolveFullPath(&pathError);
  848. if (!pathError.empty() || fullPath.empty()) {
  849. continue;
  850. }
  851. std::string const& extLower =
  852. cmSystemTools::LowerCase(sf->GetExtension());
  853. if (cm->IsAHeaderExtension(extLower)) {
  854. if (!cm::contains(this->AutogenTarget.Headers, sf.get())) {
  855. auto muf = makeMUFile(sf.get(), fullPath, {}, false);
  856. if (muf->SkipMoc || muf->SkipUic) {
  857. addMUHeader(std::move(muf), extLower);
  858. }
  859. }
  860. } else if (cm->IsACLikeSourceExtension(extLower)) {
  861. if (!cm::contains(this->AutogenTarget.Sources, sf.get())) {
  862. auto muf = makeMUFile(sf.get(), fullPath, {}, false);
  863. if (muf->SkipMoc || muf->SkipUic) {
  864. addMUSource(std::move(muf));
  865. }
  866. }
  867. } else if (this->Uic.Enabled && (extLower == kw.ui)) {
  868. // .ui file
  869. bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
  870. bool const skipUic =
  871. (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
  872. if (!skipUic) {
  873. // Check if the .ui file has uic options
  874. std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS);
  875. if (uicOpts.empty()) {
  876. this->Uic.UiFilesNoOptions.emplace_back(fullPath);
  877. } else {
  878. this->Uic.UiFilesWithOptions.emplace_back(
  879. fullPath, std::move(cmList{ uicOpts }.data()));
  880. }
  881. auto uiHeaderRelativePath = cmSystemTools::RelativePath(
  882. this->LocalGen->GetCurrentSourceDirectory(),
  883. cmSystemTools::GetFilenamePath(fullPath));
  884. // Avoid creating a path containing adjacent slashes
  885. if (!uiHeaderRelativePath.empty() &&
  886. uiHeaderRelativePath.back() != '/') {
  887. uiHeaderRelativePath += '/';
  888. }
  889. auto uiHeaderFilePath = cmStrCat(
  890. '/', uiHeaderRelativePath, "ui_"_s,
  891. cmSystemTools::GetFilenameWithoutLastExtension(fullPath), ".h"_s);
  892. ConfigString uiHeader;
  893. std::string uiHeaderGenex;
  894. this->ConfigFileNamesAndGenex(
  895. uiHeader, uiHeaderGenex, cmStrCat(this->Dir.Build, "/include"_s),
  896. uiHeaderFilePath);
  897. this->Uic.UiHeaders.emplace_back(uiHeader, uiHeaderGenex);
  898. } else {
  899. // Register skipped .ui file
  900. this->Uic.SkipUi.insert(fullPath);
  901. }
  902. }
  903. }
  904. }
  905. // Process GENERATED sources and headers
  906. if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) {
  907. if (this->CMP0071Accept) {
  908. // Let the autogen target depend on the GENERATED files
  909. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  910. this->AutogenTarget.DependFiles.insert(muf->FullPath);
  911. }
  912. } else if (this->CMP0071Warn) {
  913. cm::string_view property;
  914. if (this->Moc.Enabled && this->Uic.Enabled) {
  915. property = "SKIP_AUTOGEN";
  916. } else if (this->Moc.Enabled) {
  917. property = "SKIP_AUTOMOC";
  918. } else if (this->Uic.Enabled) {
  919. property = "SKIP_AUTOUIC";
  920. }
  921. std::string files;
  922. for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
  923. files += cmStrCat(" ", Quoted(muf->FullPath), '\n');
  924. }
  925. this->Makefile->IssueMessage(
  926. MessageType::AUTHOR_WARNING,
  927. cmStrCat(
  928. cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n',
  929. "For compatibility, CMake is excluding the GENERATED source "
  930. "file(s):\n",
  931. files, "from processing by ",
  932. cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
  933. ". If any of the files should be processed, set CMP0071 to NEW. "
  934. "If any of the files should not be processed, "
  935. "explicitly exclude them by setting the source file property ",
  936. property, ":\n set_property(SOURCE file.h PROPERTY ", property,
  937. " ON)\n"));
  938. }
  939. }
  940. // Generate CMP0100 warning
  941. if (this->MocOrUicEnabled() &&
  942. !this->AutogenTarget.CMP0100HeadersWarn.empty()) {
  943. cm::string_view property;
  944. if (this->Moc.Enabled && this->Uic.Enabled) {
  945. property = "SKIP_AUTOGEN";
  946. } else if (this->Moc.Enabled) {
  947. property = "SKIP_AUTOMOC";
  948. } else if (this->Uic.Enabled) {
  949. property = "SKIP_AUTOUIC";
  950. }
  951. std::string files;
  952. for (cmSourceFile* sf : this->AutogenTarget.CMP0100HeadersWarn) {
  953. files += cmStrCat(" ", Quoted(sf->GetFullPath()), '\n');
  954. }
  955. this->Makefile->IssueMessage(
  956. MessageType::AUTHOR_WARNING,
  957. cmStrCat(
  958. cmPolicies::GetPolicyWarning(cmPolicies::CMP0100), '\n',
  959. "For compatibility, CMake is excluding the header file(s):\n", files,
  960. "from processing by ",
  961. cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
  962. ". If any of the files should be processed, set CMP0100 to NEW. "
  963. "If any of the files should not be processed, "
  964. "explicitly exclude them by setting the source file property ",
  965. property, ":\n set_property(SOURCE file.hh PROPERTY ", property,
  966. " ON)\n"));
  967. }
  968. // Process qrc files
  969. if (!this->Rcc.Qrcs.empty()) {
  970. const bool modernQt = (this->QtVersion.Major >= 5);
  971. // Target rcc options
  972. cmList optionsTarget{ this->GenTarget->GetSafeProperty(
  973. kw.AUTORCC_OPTIONS) };
  974. // Check if file name is unique
  975. for (Qrc& qrc : this->Rcc.Qrcs) {
  976. qrc.Unique = true;
  977. for (Qrc const& qrc2 : this->Rcc.Qrcs) {
  978. if ((&qrc != &qrc2) && (qrc.QrcName == qrc2.QrcName)) {
  979. qrc.Unique = false;
  980. break;
  981. }
  982. }
  983. }
  984. // Path checksum and file names
  985. for (Qrc& qrc : this->Rcc.Qrcs) {
  986. // Path checksum
  987. qrc.QrcPathChecksum = this->PathCheckSum.getPart(qrc.QrcFile);
  988. // Output file name
  989. qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum,
  990. "/qrc_", qrc.QrcName, ".cpp");
  991. std::string const base = cmStrCat(this->Dir.Info, "/AutoRcc_",
  992. qrc.QrcName, '_', qrc.QrcPathChecksum);
  993. qrc.LockFile = cmStrCat(base, "_Lock.lock");
  994. qrc.InfoFile = cmStrCat(base, "_Info.json");
  995. this->ConfigFileNames(qrc.SettingsFile, cmStrCat(base, "_Used"), ".txt");
  996. }
  997. // rcc options
  998. for (Qrc& qrc : this->Rcc.Qrcs) {
  999. // Target options
  1000. std::vector<std::string> opts = optionsTarget;
  1001. // Merge computed "-name XYZ" option
  1002. {
  1003. std::string name = qrc.QrcName;
  1004. // Replace '-' with '_'. The former is not valid for symbol names.
  1005. std::replace(name.begin(), name.end(), '-', '_');
  1006. if (!qrc.Unique) {
  1007. name += cmStrCat('_', qrc.QrcPathChecksum);
  1008. }
  1009. std::vector<std::string> nameOpts;
  1010. nameOpts.emplace_back("-name");
  1011. nameOpts.emplace_back(std::move(name));
  1012. RccMergeOptions(opts, nameOpts, modernQt);
  1013. }
  1014. // Merge file option
  1015. RccMergeOptions(opts, qrc.Options, modernQt);
  1016. qrc.Options = std::move(opts);
  1017. }
  1018. // rcc resources
  1019. for (Qrc& qrc : this->Rcc.Qrcs) {
  1020. if (!qrc.Generated) {
  1021. std::string error;
  1022. RccLister const lister(this->Rcc.Executable,
  1023. this->Rcc.ExecutableFeatures->ListOptions);
  1024. if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
  1025. cmSystemTools::Error(error);
  1026. return false;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. return true;
  1032. }
  1033. bool cmQtAutoGenInitializer::InitAutogenTarget()
  1034. {
  1035. // Register info file as generated by CMake
  1036. this->Makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
  1037. // Determine whether to use a depfile for the AUTOGEN target.
  1038. const bool useNinjaDepfile = this->QtVersion >= IntegerVersion(5, 15) &&
  1039. this->GlobalGen->GetName().find("Ninja") != std::string::npos;
  1040. // Files provided by the autogen target
  1041. std::vector<std::string> autogenByproducts;
  1042. std::vector<std::string> timestampByproducts;
  1043. if (this->Moc.Enabled) {
  1044. this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true);
  1045. if (useNinjaDepfile) {
  1046. if (this->MultiConfig) {
  1047. // Make all mocs_compilation_<CONFIG>.cpp files byproducts of the
  1048. // ${target}_autogen/timestamp custom command.
  1049. // We cannot just use Moc.CompilationFileGenex here, because that
  1050. // custom command runs cmake_autogen for each configuration.
  1051. for (const auto& p : this->Moc.CompilationFile.Config) {
  1052. timestampByproducts.push_back(p.second);
  1053. }
  1054. } else {
  1055. timestampByproducts.push_back(this->Moc.CompilationFileGenex);
  1056. }
  1057. } else {
  1058. autogenByproducts.push_back(this->Moc.CompilationFileGenex);
  1059. }
  1060. }
  1061. if (this->Uic.Enabled) {
  1062. for (const auto& file : this->Uic.UiHeaders) {
  1063. this->AddGeneratedSource(file.first, this->Uic);
  1064. autogenByproducts.push_back(file.second);
  1065. }
  1066. }
  1067. // Compose target comment
  1068. std::string autogenComment;
  1069. {
  1070. std::string tools;
  1071. if (this->Moc.Enabled) {
  1072. tools += "MOC";
  1073. }
  1074. if (this->Uic.Enabled) {
  1075. if (!tools.empty()) {
  1076. tools += " and ";
  1077. }
  1078. tools += "UIC";
  1079. }
  1080. autogenComment = cmStrCat("Automatic ", tools, " for target ",
  1081. this->GenTarget->GetName());
  1082. }
  1083. // Compose command lines
  1084. // FIXME: Take advantage of our per-config mocs_compilation_$<CONFIG>.cpp
  1085. // instead of fiddling with the include directories
  1086. std::vector<std::string> configs;
  1087. this->GlobalGen->GetQtAutoGenConfigs(configs);
  1088. bool stdPipesUTF8 = true;
  1089. cmCustomCommandLines commandLines;
  1090. for (auto const& config : configs) {
  1091. commandLines.push_back(cmMakeCommandLine(
  1092. { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
  1093. this->AutogenTarget.InfoFile, config }));
  1094. }
  1095. // Use PRE_BUILD on demand
  1096. bool usePRE_BUILD = false;
  1097. if (this->GlobalGen->GetName().find("Visual Studio") != std::string::npos) {
  1098. // Under VS use a PRE_BUILD event instead of a separate target to
  1099. // reduce the number of targets loaded into the IDE.
  1100. // This also works around a VS 11 bug that may skip updating the target:
  1101. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  1102. usePRE_BUILD = true;
  1103. }
  1104. // Disable PRE_BUILD in some cases
  1105. if (usePRE_BUILD) {
  1106. // Cannot use PRE_BUILD with file depends
  1107. if (!this->AutogenTarget.DependFiles.empty()) {
  1108. usePRE_BUILD = false;
  1109. }
  1110. // Cannot use PRE_BUILD when a global autogen target is in place
  1111. if (this->AutogenTarget.GlobalTarget) {
  1112. usePRE_BUILD = false;
  1113. }
  1114. }
  1115. // Create the autogen target/command
  1116. if (usePRE_BUILD) {
  1117. // Add additional autogen target dependencies to origin target
  1118. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  1119. this->GenTarget->Target->AddUtility(depTarget->GetName(), false,
  1120. this->Makefile);
  1121. }
  1122. if (!this->Uic.UiFilesNoOptions.empty() ||
  1123. !this->Uic.UiFilesWithOptions.empty()) {
  1124. // Add a generated timestamp file
  1125. ConfigString timestampFile;
  1126. std::string timestampFileGenex;
  1127. ConfigFileNamesAndGenex(timestampFile, timestampFileGenex,
  1128. cmStrCat(this->Dir.Build, "/autouic"_s),
  1129. ".stamp"_s);
  1130. this->AddGeneratedSource(timestampFile, this->Uic);
  1131. // Add a step in the pre-build command to touch the timestamp file
  1132. commandLines.push_back(
  1133. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", "touch",
  1134. timestampFileGenex }));
  1135. // UIC needs to be re-run if any of the known UI files change or the
  1136. // executable itself has been updated
  1137. auto uicDependencies = this->Uic.UiFilesNoOptions;
  1138. for (auto const& uiFile : this->Uic.UiFilesWithOptions) {
  1139. uicDependencies.push_back(uiFile.first);
  1140. }
  1141. AddAutogenExecutableToDependencies(this->Uic, uicDependencies);
  1142. // Add a rule file to cause the target to build if a dependency has
  1143. // changed, which will trigger the pre-build command to run autogen
  1144. auto cc = cm::make_unique<cmCustomCommand>();
  1145. cc->SetOutputs(timestampFileGenex);
  1146. cc->SetDepends(uicDependencies);
  1147. cc->SetComment("");
  1148. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1149. cc->SetEscapeOldStyle(false);
  1150. cc->SetStdPipesUTF8(stdPipesUTF8);
  1151. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1152. }
  1153. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  1154. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  1155. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  1156. //
  1157. // PRE_BUILD does not support file dependencies!
  1158. cmCustomCommand cc;
  1159. cc.SetByproducts(autogenByproducts);
  1160. cc.SetCommandLines(commandLines);
  1161. cc.SetComment(autogenComment.c_str());
  1162. cc.SetBacktrace(this->Makefile->GetBacktrace());
  1163. cc.SetWorkingDirectory(this->Dir.Work.c_str());
  1164. cc.SetStdPipesUTF8(stdPipesUTF8);
  1165. cc.SetEscapeOldStyle(false);
  1166. cc.SetEscapeAllowMakeVars(true);
  1167. this->GenTarget->Target->AddPreBuildCommand(std::move(cc));
  1168. } else {
  1169. // Add link library target dependencies to the autogen target
  1170. // dependencies
  1171. if (this->AutogenTarget.DependOrigin) {
  1172. // add_dependencies/addUtility do not support generator expressions.
  1173. // We depend only on the libraries found in all configs therefore.
  1174. std::map<cmGeneratorTarget const*, std::size_t> commonTargets;
  1175. for (std::string const& config : this->ConfigsList) {
  1176. cmLinkImplementationLibraries const* libs =
  1177. this->GenTarget->GetLinkImplementationLibraries(
  1178. config, cmGeneratorTarget::LinkInterfaceFor::Link);
  1179. if (libs) {
  1180. for (cmLinkItem const& item : libs->Libraries) {
  1181. cmGeneratorTarget const* libTarget = item.Target;
  1182. if (libTarget &&
  1183. !StaticLibraryCycle(this->GenTarget, libTarget, config)) {
  1184. // Increment target config count
  1185. commonTargets[libTarget]++;
  1186. }
  1187. }
  1188. }
  1189. }
  1190. for (auto const& item : commonTargets) {
  1191. if (item.second == this->ConfigsList.size()) {
  1192. this->AutogenTarget.DependTargets.insert(item.first->Target);
  1193. }
  1194. }
  1195. }
  1196. std::vector<std::string> dependencies(
  1197. this->AutogenTarget.DependFiles.begin(),
  1198. this->AutogenTarget.DependFiles.end());
  1199. if (useNinjaDepfile) {
  1200. // Create a custom command that generates a timestamp file and
  1201. // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
  1202. //
  1203. // Also create an additional '_autogen_timestamp_deps' that the custom
  1204. // command will depend on. It will have no sources or commands to
  1205. // execute, but it will have dependencies that would originally be
  1206. // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will
  1207. // serve as a list of order-only dependencies for the custom command,
  1208. // without forcing the custom command to re-execute.
  1209. //
  1210. // The dependency tree would then look like
  1211. // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <-
  1212. // '_autogen' target.
  1213. const auto timestampTargetName =
  1214. cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
  1215. std::vector<std::string> timestampTargetProvides;
  1216. cmCustomCommandLines timestampTargetCommandLines;
  1217. // Add additional autogen target dependencies to
  1218. // '_autogen_timestamp_deps'.
  1219. for (const cmTarget* t : this->AutogenTarget.DependTargets) {
  1220. std::string depname = t->GetName();
  1221. if (t->IsImported()) {
  1222. auto ttype = t->GetType();
  1223. if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY ||
  1224. ttype == cmStateEnums::TargetType::SHARED_LIBRARY ||
  1225. ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) {
  1226. depname = cmStrCat("$<TARGET_LINKER_FILE:", t->GetName(), ">");
  1227. }
  1228. }
  1229. dependencies.push_back(depname);
  1230. }
  1231. auto cc = cm::make_unique<cmCustomCommand>();
  1232. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1233. cc->SetByproducts(timestampTargetProvides);
  1234. cc->SetDepends(dependencies);
  1235. cc->SetCommandLines(timestampTargetCommandLines);
  1236. cc->SetEscapeOldStyle(false);
  1237. cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
  1238. timestampTargetName, true, std::move(cc));
  1239. this->LocalGen->AddGeneratorTarget(
  1240. cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
  1241. // Set FOLDER property on the timestamp target, so it appears in the
  1242. // appropriate folder in an IDE or in the file api.
  1243. if (!this->TargetsFolder.empty()) {
  1244. timestampTarget->SetProperty("FOLDER", this->TargetsFolder);
  1245. }
  1246. // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the
  1247. // moc and uic executables (whichever are enabled).
  1248. dependencies.clear();
  1249. dependencies.push_back(timestampTargetName);
  1250. AddAutogenExecutableToDependencies(this->Moc, dependencies);
  1251. AddAutogenExecutableToDependencies(this->Uic, dependencies);
  1252. // Create the custom command that outputs the timestamp file.
  1253. const char timestampFileName[] = "timestamp";
  1254. const std::string outputFile =
  1255. cmStrCat(this->Dir.Build, "/", timestampFileName);
  1256. this->AutogenTarget.DepFile = cmStrCat(this->Dir.Build, "/deps");
  1257. this->AutogenTarget.DepFileRuleName =
  1258. cmStrCat(this->Dir.RelativeBuild, "/", timestampFileName);
  1259. commandLines.push_back(cmMakeCommandLine(
  1260. { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
  1261. this->AddGeneratedSource(outputFile, this->Moc);
  1262. cc = cm::make_unique<cmCustomCommand>();
  1263. cc->SetOutputs(outputFile);
  1264. cc->SetByproducts(timestampByproducts);
  1265. cc->SetDepends(dependencies);
  1266. cc->SetCommandLines(commandLines);
  1267. cc->SetComment(autogenComment.c_str());
  1268. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1269. cc->SetEscapeOldStyle(false);
  1270. cc->SetDepfile(this->AutogenTarget.DepFile);
  1271. cc->SetStdPipesUTF8(stdPipesUTF8);
  1272. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1273. // Alter variables for the autogen target which now merely wraps the
  1274. // custom command
  1275. dependencies.clear();
  1276. dependencies.push_back(outputFile);
  1277. commandLines.clear();
  1278. autogenComment.clear();
  1279. }
  1280. // Create autogen target
  1281. auto cc = cm::make_unique<cmCustomCommand>();
  1282. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1283. cc->SetByproducts(autogenByproducts);
  1284. cc->SetDepends(dependencies);
  1285. cc->SetCommandLines(commandLines);
  1286. cc->SetEscapeOldStyle(false);
  1287. cc->SetComment(autogenComment.c_str());
  1288. cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand(
  1289. this->AutogenTarget.Name, true, std::move(cc));
  1290. // Create autogen generator target
  1291. this->LocalGen->AddGeneratorTarget(
  1292. cm::make_unique<cmGeneratorTarget>(autogenTarget, this->LocalGen));
  1293. // Forward origin utilities to autogen target
  1294. if (this->AutogenTarget.DependOrigin) {
  1295. for (BT<std::pair<std::string, bool>> const& depName :
  1296. this->GenTarget->GetUtilities()) {
  1297. autogenTarget->AddUtility(depName.Value.first, false, this->Makefile);
  1298. }
  1299. }
  1300. if (!useNinjaDepfile) {
  1301. // Add additional autogen target dependencies to autogen target
  1302. for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
  1303. autogenTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
  1304. }
  1305. }
  1306. // Set FOLDER property in autogen target
  1307. if (!this->TargetsFolder.empty()) {
  1308. autogenTarget->SetProperty("FOLDER", this->TargetsFolder);
  1309. }
  1310. // Add autogen target to the origin target dependencies
  1311. this->GenTarget->Target->AddUtility(this->AutogenTarget.Name, false,
  1312. this->Makefile);
  1313. // Add autogen target to the global autogen target dependencies
  1314. if (this->AutogenTarget.GlobalTarget) {
  1315. this->GlobalInitializer->AddToGlobalAutoGen(this->LocalGen,
  1316. this->AutogenTarget.Name);
  1317. }
  1318. }
  1319. return true;
  1320. }
  1321. bool cmQtAutoGenInitializer::InitRccTargets()
  1322. {
  1323. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1324. // Register info file as generated by CMake
  1325. this->Makefile->AddCMakeOutputFile(qrc.InfoFile);
  1326. // Register file at target
  1327. {
  1328. cmSourceFile* sf = this->AddGeneratedSource(qrc.OutputFile, this->Rcc);
  1329. sf->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "On");
  1330. }
  1331. std::vector<std::string> ccOutput;
  1332. ccOutput.push_back(qrc.OutputFile);
  1333. std::vector<std::string> ccDepends;
  1334. // Add the .qrc and info file to the custom command dependencies
  1335. ccDepends.push_back(qrc.QrcFile);
  1336. ccDepends.push_back(qrc.InfoFile);
  1337. cmCustomCommandLines commandLines;
  1338. if (this->MultiConfig) {
  1339. // Build for all configurations
  1340. for (std::string const& config : this->ConfigsList) {
  1341. commandLines.push_back(
  1342. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
  1343. "cmake_autorcc", qrc.InfoFile, config }));
  1344. }
  1345. } else {
  1346. commandLines.push_back(
  1347. cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
  1348. "cmake_autorcc", qrc.InfoFile, "$<CONFIG>" }));
  1349. }
  1350. std::string ccComment =
  1351. cmStrCat("Automatic RCC for ",
  1352. FileProjectRelativePath(this->Makefile, qrc.QrcFile));
  1353. auto cc = cm::make_unique<cmCustomCommand>();
  1354. cc->SetWorkingDirectory(this->Dir.Work.c_str());
  1355. cc->SetCommandLines(commandLines);
  1356. cc->SetComment(ccComment.c_str());
  1357. cc->SetStdPipesUTF8(true);
  1358. if (qrc.Generated || this->Rcc.GlobalTarget) {
  1359. // Create custom rcc target
  1360. std::string ccName;
  1361. {
  1362. ccName = cmStrCat(this->GenTarget->GetName(), "_arcc_", qrc.QrcName);
  1363. if (!qrc.Unique) {
  1364. ccName += cmStrCat('_', qrc.QrcPathChecksum);
  1365. }
  1366. cc->SetByproducts(ccOutput);
  1367. cc->SetDepends(ccDepends);
  1368. cc->SetEscapeOldStyle(false);
  1369. cmTarget* autoRccTarget =
  1370. this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc));
  1371. // Create autogen generator target
  1372. this->LocalGen->AddGeneratorTarget(
  1373. cm::make_unique<cmGeneratorTarget>(autoRccTarget, this->LocalGen));
  1374. // Set FOLDER property in autogen target
  1375. if (!this->TargetsFolder.empty()) {
  1376. autoRccTarget->SetProperty("FOLDER", this->TargetsFolder);
  1377. }
  1378. if (!this->Rcc.ExecutableTargetName.empty()) {
  1379. autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, false,
  1380. this->Makefile);
  1381. }
  1382. }
  1383. // Add autogen target to the origin target dependencies
  1384. this->GenTarget->Target->AddUtility(ccName, false, this->Makefile);
  1385. // Add autogen target to the global autogen target dependencies
  1386. if (this->Rcc.GlobalTarget) {
  1387. this->GlobalInitializer->AddToGlobalAutoRcc(this->LocalGen, ccName);
  1388. }
  1389. } else {
  1390. // Create custom rcc command
  1391. {
  1392. std::vector<std::string> ccByproducts;
  1393. // Add the resource files to the dependencies
  1394. for (std::string const& fileName : qrc.Resources) {
  1395. // Add resource file to the custom command dependencies
  1396. ccDepends.push_back(fileName);
  1397. }
  1398. if (!this->Rcc.ExecutableTargetName.empty()) {
  1399. ccDepends.push_back(this->Rcc.ExecutableTargetName);
  1400. }
  1401. cc->SetOutputs(ccOutput);
  1402. cc->SetByproducts(ccByproducts);
  1403. cc->SetDepends(ccDepends);
  1404. this->LocalGen->AddCustomCommandToOutput(std::move(cc));
  1405. }
  1406. // Reconfigure when .qrc file changes
  1407. this->Makefile->AddCMakeDependFile(qrc.QrcFile);
  1408. }
  1409. }
  1410. return true;
  1411. }
  1412. bool cmQtAutoGenInitializer::SetupCustomTargets()
  1413. {
  1414. // Create info directory on demand
  1415. if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
  1416. cmSystemTools::Error(cmStrCat("AutoGen: Could not create directory: ",
  1417. Quoted(this->Dir.Info)));
  1418. return false;
  1419. }
  1420. // Generate autogen target info file
  1421. if (this->MocOrUicEnabled()) {
  1422. // Write autogen target info files
  1423. if (!this->SetupWriteAutogenInfo()) {
  1424. return false;
  1425. }
  1426. }
  1427. // Write AUTORCC info files
  1428. return !this->Rcc.Enabled || this->SetupWriteRccInfo();
  1429. }
  1430. bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
  1431. {
  1432. // Utility lambdas
  1433. auto MfDef = [this](std::string const& key) {
  1434. return this->Makefile->GetSafeDefinition(key);
  1435. };
  1436. // Filtered headers and sources
  1437. std::set<std::string> moc_skip;
  1438. std::set<std::string> uic_skip;
  1439. std::vector<MUFile const*> headers;
  1440. std::vector<MUFile const*> sources;
  1441. // Filter headers
  1442. {
  1443. headers.reserve(this->AutogenTarget.Headers.size());
  1444. for (auto const& pair : this->AutogenTarget.Headers) {
  1445. MUFile const* const muf = pair.second.get();
  1446. if (muf->SkipMoc) {
  1447. moc_skip.insert(muf->FullPath);
  1448. }
  1449. if (muf->SkipUic) {
  1450. uic_skip.insert(muf->FullPath);
  1451. }
  1452. if (muf->Generated && !this->CMP0071Accept) {
  1453. continue;
  1454. }
  1455. if (muf->MocIt || muf->UicIt) {
  1456. headers.emplace_back(muf);
  1457. }
  1458. }
  1459. std::sort(headers.begin(), headers.end(),
  1460. [](MUFile const* a, MUFile const* b) {
  1461. return (a->FullPath < b->FullPath);
  1462. });
  1463. }
  1464. // Filter sources
  1465. {
  1466. sources.reserve(this->AutogenTarget.Sources.size());
  1467. for (auto const& pair : this->AutogenTarget.Sources) {
  1468. MUFile const* const muf = pair.second.get();
  1469. if (muf->Generated && !this->CMP0071Accept) {
  1470. continue;
  1471. }
  1472. if (muf->SkipMoc) {
  1473. moc_skip.insert(muf->FullPath);
  1474. }
  1475. if (muf->SkipUic) {
  1476. uic_skip.insert(muf->FullPath);
  1477. }
  1478. if (muf->MocIt || muf->UicIt) {
  1479. sources.emplace_back(muf);
  1480. }
  1481. }
  1482. std::sort(sources.begin(), sources.end(),
  1483. [](MUFile const* a, MUFile const* b) {
  1484. return (a->FullPath < b->FullPath);
  1485. });
  1486. }
  1487. // Info writer
  1488. InfoWriter info;
  1489. // General
  1490. info.SetBool("MULTI_CONFIG", this->MultiConfig);
  1491. info.SetUInt("PARALLEL", this->AutogenTarget.Parallel);
  1492. info.SetUInt("VERBOSITY", this->Verbosity);
  1493. // Directories
  1494. info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1495. info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1496. info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1497. info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1498. info.Set("BUILD_DIR", this->Dir.Build);
  1499. info.SetConfig("INCLUDE_DIR", this->Dir.Include);
  1500. info.SetUInt("QT_VERSION_MAJOR", this->QtVersion.Major);
  1501. info.SetUInt("QT_VERSION_MINOR", this->QtVersion.Minor);
  1502. info.Set("QT_MOC_EXECUTABLE", this->Moc.Executable);
  1503. info.Set("QT_UIC_EXECUTABLE", this->Uic.Executable);
  1504. info.Set("CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand());
  1505. info.SetConfig("SETTINGS_FILE", this->AutogenTarget.SettingsFile);
  1506. info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
  1507. info.Set("DEP_FILE", this->AutogenTarget.DepFile);
  1508. info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName);
  1509. info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles());
  1510. info.SetArray("HEADER_EXTENSIONS",
  1511. this->Makefile->GetCMakeInstance()->GetHeaderExtensions());
  1512. auto cfgArray = [this](std::vector<size_t> const& configs) -> Json::Value {
  1513. Json::Value value;
  1514. if (!configs.empty()) {
  1515. value = Json::arrayValue;
  1516. for (size_t ci : configs) {
  1517. value.append(this->ConfigsList[ci]);
  1518. }
  1519. }
  1520. return value;
  1521. };
  1522. info.SetArrayArray("HEADERS", headers,
  1523. [this, &cfgArray](Json::Value& jval, MUFile const* muf) {
  1524. jval.resize(4u);
  1525. jval[0u] = muf->FullPath;
  1526. jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm',
  1527. muf->UicIt ? 'U' : 'u');
  1528. jval[2u] = this->GetMocBuildPath(*muf);
  1529. jval[3u] = cfgArray(muf->Configs);
  1530. });
  1531. info.SetArrayArray(
  1532. "SOURCES", sources, [&cfgArray](Json::Value& jval, MUFile const* muf) {
  1533. jval.resize(3u);
  1534. jval[0u] = muf->FullPath;
  1535. jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm', muf->UicIt ? 'U' : 'u');
  1536. jval[2u] = cfgArray(muf->Configs);
  1537. });
  1538. // Write moc settings
  1539. if (this->Moc.Enabled) {
  1540. info.SetArray("MOC_SKIP", moc_skip);
  1541. info.SetConfigArray("MOC_DEFINITIONS", this->Moc.Defines);
  1542. info.SetConfigArray("MOC_INCLUDES", this->Moc.Includes);
  1543. info.SetArray("MOC_OPTIONS", this->Moc.Options);
  1544. info.SetBool("MOC_RELAXED_MODE", this->Moc.RelaxedMode);
  1545. info.SetBool("MOC_PATH_PREFIX", this->Moc.PathPrefix);
  1546. cmGeneratorExpressionDAGChecker dagChecker(
  1547. this->GenTarget, "AUTOMOC_MACRO_NAMES", nullptr, nullptr);
  1548. EvaluatedTargetPropertyEntries InterfaceAutoMocMacroNamesEntries;
  1549. AddInterfaceEntries(this->GenTarget, this->ConfigDefault,
  1550. "INTERFACE_AUTOMOC_MACRO_NAMES", "CXX", &dagChecker,
  1551. InterfaceAutoMocMacroNamesEntries,
  1552. IncludeRuntimeInterface::Yes);
  1553. for (auto const& entry : InterfaceAutoMocMacroNamesEntries.Entries) {
  1554. this->Moc.MacroNames.insert(this->Moc.MacroNames.end(),
  1555. entry.Values.begin(), entry.Values.end());
  1556. }
  1557. this->Moc.MacroNames.erase(cmRemoveDuplicates(this->Moc.MacroNames),
  1558. this->Moc.MacroNames.end());
  1559. info.SetArray("MOC_MACRO_NAMES", this->Moc.MacroNames);
  1560. info.SetArrayArray(
  1561. "MOC_DEPEND_FILTERS", this->Moc.DependFilters,
  1562. [](Json::Value& jval, std::pair<std::string, std::string> const& pair) {
  1563. jval.resize(2u);
  1564. jval[0u] = pair.first;
  1565. jval[1u] = pair.second;
  1566. });
  1567. info.SetConfig("MOC_COMPILATION_FILE", this->Moc.CompilationFile);
  1568. info.SetConfig("MOC_PREDEFS_FILE", this->Moc.PredefsFile);
  1569. cmStandardLevelResolver resolver{ this->Makefile };
  1570. auto CompileOptionFlag =
  1571. resolver.GetCompileOptionDef(this->GenTarget, "CXX", "");
  1572. auto CompileOptionValue =
  1573. this->GenTarget->Makefile->GetSafeDefinition(CompileOptionFlag);
  1574. if (!CompileOptionValue.empty()) {
  1575. if (this->Moc.PredefsCmd.size() >= 3) {
  1576. this->Moc.PredefsCmd.insert(this->Moc.PredefsCmd.begin() + 1,
  1577. CompileOptionValue);
  1578. }
  1579. }
  1580. info.SetArray("MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
  1581. }
  1582. // Write uic settings
  1583. if (this->Uic.Enabled) {
  1584. // Add skipped .ui files
  1585. uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end());
  1586. info.SetArray("UIC_SKIP", uic_skip);
  1587. info.SetArrayArray("UIC_UI_FILES", this->Uic.UiFilesWithOptions,
  1588. [](Json::Value& jval, UicT::UiFileT const& uiFile) {
  1589. jval.resize(2u);
  1590. jval[0u] = uiFile.first;
  1591. InfoWriter::MakeStringArray(jval[1u], uiFile.second);
  1592. });
  1593. info.SetConfigArray("UIC_OPTIONS", this->Uic.Options);
  1594. info.SetArray("UIC_SEARCH_PATHS", this->Uic.SearchPaths);
  1595. }
  1596. info.Save(this->AutogenTarget.InfoFile);
  1597. return true;
  1598. }
  1599. bool cmQtAutoGenInitializer::SetupWriteRccInfo()
  1600. {
  1601. for (Qrc const& qrc : this->Rcc.Qrcs) {
  1602. // Utility lambdas
  1603. auto MfDef = [this](std::string const& key) {
  1604. return this->Makefile->GetSafeDefinition(key);
  1605. };
  1606. InfoWriter info;
  1607. // General
  1608. info.SetBool("MULTI_CONFIG", this->MultiConfig);
  1609. info.SetUInt("VERBOSITY", this->Verbosity);
  1610. // Files
  1611. info.Set("LOCK_FILE", qrc.LockFile);
  1612. info.SetConfig("SETTINGS_FILE", qrc.SettingsFile);
  1613. // Directories
  1614. info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
  1615. info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
  1616. info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
  1617. info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
  1618. info.Set("BUILD_DIR", this->Dir.Build);
  1619. info.SetConfig("INCLUDE_DIR", this->Dir.Include);
  1620. // rcc executable
  1621. info.Set("RCC_EXECUTABLE", this->Rcc.Executable);
  1622. info.SetArray("RCC_LIST_OPTIONS",
  1623. this->Rcc.ExecutableFeatures->ListOptions);
  1624. // qrc file
  1625. info.Set("SOURCE", qrc.QrcFile);
  1626. info.Set("OUTPUT_CHECKSUM", qrc.QrcPathChecksum);
  1627. info.Set("OUTPUT_NAME", cmSystemTools::GetFilenameName(qrc.OutputFile));
  1628. info.SetArray("OPTIONS", qrc.Options);
  1629. info.SetArray("INPUTS", qrc.Resources);
  1630. info.Save(qrc.InfoFile);
  1631. }
  1632. return true;
  1633. }
  1634. cmSourceFile* cmQtAutoGenInitializer::RegisterGeneratedSource(
  1635. std::string const& filename)
  1636. {
  1637. cmSourceFile* gFile = this->Makefile->GetOrCreateSource(filename, true);
  1638. gFile->MarkAsGenerated();
  1639. gFile->SetProperty("SKIP_AUTOGEN", "1");
  1640. return gFile;
  1641. }
  1642. cmSourceFile* cmQtAutoGenInitializer::AddGeneratedSource(
  1643. std::string const& filename, GenVarsT const& genVars, bool prepend)
  1644. {
  1645. // Register source at makefile
  1646. cmSourceFile* gFile = this->RegisterGeneratedSource(filename);
  1647. // Add source file to target
  1648. this->GenTarget->AddSource(filename, prepend);
  1649. // Add source file to source group
  1650. this->AddToSourceGroup(filename, genVars.GenNameUpper);
  1651. return gFile;
  1652. }
  1653. void cmQtAutoGenInitializer::AddGeneratedSource(ConfigString const& filename,
  1654. GenVarsT const& genVars,
  1655. bool prepend)
  1656. {
  1657. // XXX(xcode-per-cfg-src): Drop the Xcode-specific part of the condition
  1658. // when the Xcode generator supports per-config sources.
  1659. if (!this->MultiConfig || this->GlobalGen->IsXcode()) {
  1660. cmSourceFile* sf =
  1661. this->AddGeneratedSource(filename.Default, genVars, prepend);
  1662. handleSkipPch(sf);
  1663. return;
  1664. }
  1665. for (auto const& cfg : this->ConfigsList) {
  1666. std::string const& filenameCfg = filename.Config.at(cfg);
  1667. // Register source at makefile
  1668. cmSourceFile* sf = this->RegisterGeneratedSource(filenameCfg);
  1669. handleSkipPch(sf);
  1670. // Add source file to target for this configuration.
  1671. this->GenTarget->AddSource(
  1672. cmStrCat("$<$<CONFIG:"_s, cfg, ">:"_s, filenameCfg, ">"_s), prepend);
  1673. // Add source file to source group
  1674. this->AddToSourceGroup(filenameCfg, genVars.GenNameUpper);
  1675. }
  1676. }
  1677. void cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
  1678. cm::string_view genNameUpper)
  1679. {
  1680. cmSourceGroup* sourceGroup = nullptr;
  1681. // Acquire source group
  1682. {
  1683. std::string property;
  1684. std::string groupName;
  1685. {
  1686. // Prefer generator specific source group name
  1687. std::initializer_list<std::string> const props{
  1688. cmStrCat(genNameUpper, "_SOURCE_GROUP"), "AUTOGEN_SOURCE_GROUP"
  1689. };
  1690. for (std::string const& prop : props) {
  1691. cmValue propName = this->Makefile->GetState()->GetGlobalProperty(prop);
  1692. if (cmNonempty(propName)) {
  1693. groupName = *propName;
  1694. property = prop;
  1695. break;
  1696. }
  1697. }
  1698. }
  1699. // Generate a source group on demand
  1700. if (!groupName.empty()) {
  1701. sourceGroup = this->Makefile->GetOrCreateSourceGroup(groupName);
  1702. if (!sourceGroup) {
  1703. cmSystemTools::Error(
  1704. cmStrCat(genNameUpper, " error in ", property,
  1705. ": Could not find or create the source group ",
  1706. cmQtAutoGen::Quoted(groupName)));
  1707. }
  1708. }
  1709. }
  1710. if (sourceGroup) {
  1711. sourceGroup->AddGroupFile(fileName);
  1712. }
  1713. }
  1714. void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
  1715. {
  1716. this->GenTarget->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName);
  1717. }
  1718. void cmQtAutoGenInitializer::ConfigFileNames(ConfigString& configString,
  1719. cm::string_view prefix,
  1720. cm::string_view suffix)
  1721. {
  1722. configString.Default = cmStrCat(prefix, suffix);
  1723. if (this->MultiConfig) {
  1724. for (auto const& cfg : this->ConfigsList) {
  1725. configString.Config[cfg] = cmStrCat(prefix, '_', cfg, suffix);
  1726. }
  1727. }
  1728. }
  1729. void cmQtAutoGenInitializer::ConfigFileNamesAndGenex(
  1730. ConfigString& configString, std::string& genex, cm::string_view const prefix,
  1731. cm::string_view const suffix)
  1732. {
  1733. this->ConfigFileNames(configString, prefix, suffix);
  1734. if (this->MultiConfig) {
  1735. genex = cmStrCat(prefix, "_$<CONFIG>"_s, suffix);
  1736. } else {
  1737. genex = configString.Default;
  1738. }
  1739. }
  1740. void cmQtAutoGenInitializer::ConfigFileClean(ConfigString& configString)
  1741. {
  1742. this->AddCleanFile(configString.Default);
  1743. if (this->MultiConfig) {
  1744. for (auto const& pair : configString.Config) {
  1745. this->AddCleanFile(pair.second);
  1746. }
  1747. }
  1748. }
  1749. static cmQtAutoGen::IntegerVersion parseMocVersion(std::string str)
  1750. {
  1751. cmQtAutoGen::IntegerVersion result;
  1752. static const std::string prelude = "moc ";
  1753. size_t pos = str.find(prelude);
  1754. if (pos == std::string::npos) {
  1755. return result;
  1756. }
  1757. str.erase(0, prelude.size() + pos);
  1758. std::istringstream iss(str);
  1759. std::string major;
  1760. std::string minor;
  1761. if (!std::getline(iss, major, '.') || !std::getline(iss, minor, '.')) {
  1762. return result;
  1763. }
  1764. result.Major = static_cast<unsigned int>(std::stoi(major));
  1765. result.Minor = static_cast<unsigned int>(std::stoi(minor));
  1766. return result;
  1767. }
  1768. static cmQtAutoGen::IntegerVersion GetMocVersion(
  1769. const std::string& mocExecutablePath)
  1770. {
  1771. std::string capturedStdOut;
  1772. int exitCode;
  1773. if (!cmSystemTools::RunSingleCommand({ mocExecutablePath, "--version" },
  1774. &capturedStdOut, nullptr, &exitCode,
  1775. nullptr, cmSystemTools::OUTPUT_NONE)) {
  1776. return {};
  1777. }
  1778. if (exitCode != 0) {
  1779. return {};
  1780. }
  1781. return parseMocVersion(capturedStdOut);
  1782. }
  1783. static std::string FindMocExecutableFromMocTarget(cmMakefile* makefile,
  1784. unsigned int qtMajorVersion)
  1785. {
  1786. std::string result;
  1787. const std::string mocTargetName =
  1788. "Qt" + std::to_string(qtMajorVersion) + "::moc";
  1789. cmTarget* mocTarget = makefile->FindTargetToUse(mocTargetName);
  1790. if (mocTarget) {
  1791. result = mocTarget->GetSafeProperty("IMPORTED_LOCATION");
  1792. }
  1793. return result;
  1794. }
  1795. std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
  1796. cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target,
  1797. std::string mocExecutable)
  1798. {
  1799. // Converts a char ptr to an unsigned int value
  1800. auto toUInt = [](const char* const input) -> unsigned int {
  1801. unsigned long tmp = 0;
  1802. if (input && cmStrToULong(input, &tmp)) {
  1803. return static_cast<unsigned int>(tmp);
  1804. }
  1805. return 0u;
  1806. };
  1807. auto toUInt2 = [](cmValue input) -> unsigned int {
  1808. unsigned long tmp = 0;
  1809. if (input && cmStrToULong(*input, &tmp)) {
  1810. return static_cast<unsigned int>(tmp);
  1811. }
  1812. return 0u;
  1813. };
  1814. // Initialize return value to a default
  1815. std::pair<IntegerVersion, unsigned int> res(
  1816. IntegerVersion(),
  1817. toUInt(target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
  1818. "")));
  1819. // Acquire known Qt versions
  1820. std::vector<cmQtAutoGen::IntegerVersion> knownQtVersions;
  1821. {
  1822. // Qt version variable prefixes
  1823. static std::initializer_list<
  1824. std::pair<cm::string_view, cm::string_view>> const keys{
  1825. { "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
  1826. { "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
  1827. { "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
  1828. };
  1829. knownQtVersions.reserve(keys.size() * 2);
  1830. // Adds a version to the result (nullptr safe)
  1831. auto addVersion = [&knownQtVersions, &toUInt2](cmValue major,
  1832. cmValue minor) {
  1833. cmQtAutoGen::IntegerVersion ver(toUInt2(major), toUInt2(minor));
  1834. if (ver.Major != 0) {
  1835. knownQtVersions.emplace_back(ver);
  1836. }
  1837. };
  1838. // Read versions from variables
  1839. for (auto const& keyPair : keys) {
  1840. addVersion(target->Makefile->GetDefinition(std::string(keyPair.first)),
  1841. target->Makefile->GetDefinition(std::string(keyPair.second)));
  1842. }
  1843. // Read versions from directory properties
  1844. for (auto const& keyPair : keys) {
  1845. addVersion(target->Makefile->GetProperty(std::string(keyPair.first)),
  1846. target->Makefile->GetProperty(std::string(keyPair.second)));
  1847. }
  1848. }
  1849. // Evaluate known Qt versions
  1850. if (!knownQtVersions.empty()) {
  1851. if (res.second == 0) {
  1852. // No specific version was requested by the target:
  1853. // Use highest known Qt version.
  1854. res.first = knownQtVersions.at(0);
  1855. } else {
  1856. // Pick a version from the known versions:
  1857. for (auto it : knownQtVersions) {
  1858. if (it.Major == res.second) {
  1859. res.first = it;
  1860. break;
  1861. }
  1862. }
  1863. }
  1864. }
  1865. if (res.first.Major == 0) {
  1866. // We could not get the version number from variables or directory
  1867. // properties. This might happen if the find_package call for Qt is wrapped
  1868. // in a function. Try to find the moc executable path from the available
  1869. // targets and call "moc --version" to get the Qt version.
  1870. if (mocExecutable.empty()) {
  1871. mocExecutable =
  1872. FindMocExecutableFromMocTarget(target->Makefile, res.second);
  1873. }
  1874. if (!mocExecutable.empty()) {
  1875. res.first = GetMocVersion(mocExecutable);
  1876. }
  1877. }
  1878. return res;
  1879. }
  1880. std::string cmQtAutoGenInitializer::GetMocBuildPath(MUFile const& muf)
  1881. {
  1882. std::string res;
  1883. if (!muf.MocIt) {
  1884. return res;
  1885. }
  1886. std::string basePath =
  1887. cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_",
  1888. FileNameWithoutLastExtension(muf.FullPath));
  1889. res = cmStrCat(basePath, ".cpp");
  1890. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1891. return res;
  1892. }
  1893. // File name already emitted.
  1894. // Try appending the header suffix to the base path.
  1895. basePath = cmStrCat(basePath, '_', muf.SF->GetExtension());
  1896. res = cmStrCat(basePath, ".cpp");
  1897. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1898. return res;
  1899. }
  1900. // File name with header extension already emitted.
  1901. // Try adding a number to the base path.
  1902. constexpr std::size_t number_begin = 2;
  1903. constexpr std::size_t number_end = 256;
  1904. for (std::size_t ii = number_begin; ii != number_end; ++ii) {
  1905. res = cmStrCat(basePath, '_', ii, ".cpp");
  1906. if (this->Moc.EmittedBuildPaths.emplace(res).second) {
  1907. return res;
  1908. }
  1909. }
  1910. // Output file name conflict (unlikely, but still...)
  1911. cmSystemTools::Error(
  1912. cmStrCat("moc output file name conflict for ", muf.FullPath));
  1913. return res;
  1914. }
  1915. bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
  1916. const std::string& executable,
  1917. bool ignoreMissingTarget) const
  1918. {
  1919. auto print_err = [this, &genVars](std::string const& err) {
  1920. cmSystemTools::Error(cmStrCat(genVars.GenNameUpper, " for target ",
  1921. this->GenTarget->GetName(), ": ", err));
  1922. };
  1923. // Custom executable
  1924. {
  1925. std::string const prop = cmStrCat(genVars.GenNameUpper, "_EXECUTABLE");
  1926. std::string const& val = this->GenTarget->Target->GetSafeProperty(prop);
  1927. if (!val.empty()) {
  1928. // Evaluate generator expression
  1929. {
  1930. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1931. cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt);
  1932. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
  1933. genVars.Executable = cge->Evaluate(this->LocalGen, "");
  1934. }
  1935. if (genVars.Executable.empty() && !ignoreMissingTarget) {
  1936. print_err(prop + " evaluates to an empty value");
  1937. return false;
  1938. }
  1939. // Create empty compiler features.
  1940. genVars.ExecutableFeatures =
  1941. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1942. return true;
  1943. }
  1944. }
  1945. // Find executable target
  1946. {
  1947. // Find executable target name
  1948. cm::string_view prefix;
  1949. if (this->QtVersion.Major == 4) {
  1950. prefix = "Qt4::";
  1951. } else if (this->QtVersion.Major == 5) {
  1952. prefix = "Qt5::";
  1953. } else if (this->QtVersion.Major == 6) {
  1954. prefix = "Qt6::";
  1955. }
  1956. std::string const targetName = cmStrCat(prefix, executable);
  1957. // Find target
  1958. cmGeneratorTarget* genTarget =
  1959. this->LocalGen->FindGeneratorTargetToUse(targetName);
  1960. if (genTarget) {
  1961. genVars.ExecutableTargetName = targetName;
  1962. genVars.ExecutableTarget = genTarget;
  1963. if (genTarget->IsImported()) {
  1964. genVars.Executable = genTarget->ImportedGetLocation("");
  1965. } else {
  1966. genVars.Executable = genTarget->GetLocation("");
  1967. }
  1968. } else {
  1969. if (ignoreMissingTarget) {
  1970. // Create empty compiler features.
  1971. genVars.ExecutableFeatures =
  1972. std::make_shared<cmQtAutoGen::CompilerFeatures>();
  1973. return true;
  1974. }
  1975. print_err(cmStrCat("Could not find ", executable, " executable target ",
  1976. targetName));
  1977. return false;
  1978. }
  1979. }
  1980. // Get executable features
  1981. {
  1982. std::string err;
  1983. genVars.ExecutableFeatures = this->GlobalInitializer->GetCompilerFeatures(
  1984. executable, genVars.Executable, err);
  1985. if (!genVars.ExecutableFeatures) {
  1986. print_err(err);
  1987. return false;
  1988. }
  1989. }
  1990. return true;
  1991. }
  1992. void cmQtAutoGenInitializer::handleSkipPch(cmSourceFile* sf)
  1993. {
  1994. bool skipPch = true;
  1995. for (auto const& pair : this->AutogenTarget.Sources) {
  1996. if (!pair.first->GetIsGenerated() &&
  1997. !pair.first->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  1998. skipPch = false;
  1999. }
  2000. }
  2001. if (skipPch) {
  2002. sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
  2003. }
  2004. }