cmQtAutoGenInitializer.cxx 74 KB

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