cmQtAutoGenInitializer.cxx 56 KB

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