cmQtAutoGenInitializer.cxx 56 KB

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