cmQtAutoGenInitializer.cxx 74 KB

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