cmQtAutoGenerators.cxx 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2004-2011 Kitware, Inc.
  4. Copyright 2011 Alexander Neundorf ([email protected])
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. #include "cmGlobalGenerator.h"
  12. #include "cmLocalGenerator.h"
  13. #include "cmMakefile.h"
  14. #include "cmSourceFile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmState.h"
  17. #include "cmAlgorithms.h"
  18. #if defined(_WIN32) && !defined(__CYGWIN__)
  19. # include "cmGlobalVisualStudioGenerator.h"
  20. #endif
  21. #include <sys/stat.h>
  22. #include <cmsys/Terminal.h>
  23. #include <cmsys/ios/sstream>
  24. #include <cmsys/FStream.hxx>
  25. #include <assert.h>
  26. #include <string.h>
  27. #if defined(__APPLE__)
  28. #include <unistd.h>
  29. #endif
  30. #include "cmQtAutoGenerators.h"
  31. static bool requiresMocing(const std::string& text, std::string &macroName)
  32. {
  33. // this simple check is much much faster than the regexp
  34. if (strstr(text.c_str(), "Q_OBJECT") == NULL
  35. && strstr(text.c_str(), "Q_GADGET") == NULL)
  36. {
  37. return false;
  38. }
  39. cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
  40. if (qObjectRegExp.find(text))
  41. {
  42. macroName = "Q_OBJECT";
  43. return true;
  44. }
  45. cmsys::RegularExpression qGadgetRegExp("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]");
  46. if (qGadgetRegExp.find(text))
  47. {
  48. macroName = "Q_GADGET";
  49. return true;
  50. }
  51. return false;
  52. }
  53. static std::string findMatchingHeader(const std::string& absPath,
  54. const std::string& mocSubDir,
  55. const std::string& basename,
  56. const std::vector<std::string>& headerExtensions)
  57. {
  58. std::string header;
  59. for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
  60. ext != headerExtensions.end();
  61. ++ext)
  62. {
  63. std::string sourceFilePath = absPath + basename + "." + (*ext);
  64. if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
  65. {
  66. header = sourceFilePath;
  67. break;
  68. }
  69. if (!mocSubDir.empty())
  70. {
  71. sourceFilePath = mocSubDir + basename + "." + (*ext);
  72. if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
  73. {
  74. header = sourceFilePath;
  75. break;
  76. }
  77. }
  78. }
  79. return header;
  80. }
  81. static std::string extractSubDir(const std::string& absPath,
  82. const std::string& currentMoc)
  83. {
  84. std::string subDir;
  85. if (currentMoc.find_first_of('/') != std::string::npos)
  86. {
  87. subDir = absPath
  88. + cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
  89. }
  90. return subDir;
  91. }
  92. static void copyTargetProperty(cmTarget* destinationTarget,
  93. cmTarget* sourceTarget,
  94. const std::string& propertyName)
  95. {
  96. const char* propertyValue = sourceTarget->GetProperty(propertyName);
  97. if (propertyValue)
  98. {
  99. destinationTarget->SetProperty(propertyName, propertyValue);
  100. }
  101. }
  102. static std::string ReadAll(const std::string& filename)
  103. {
  104. cmsys::ifstream file(filename.c_str());
  105. cmsys_ios::stringstream stream;
  106. stream << file.rdbuf();
  107. file.close();
  108. return stream.str();
  109. }
  110. cmQtAutoGenerators::cmQtAutoGenerators()
  111. :Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0)
  112. ,ColorOutput(true)
  113. ,RunMocFailed(false)
  114. ,RunUicFailed(false)
  115. ,RunRccFailed(false)
  116. ,GenerateAll(false)
  117. {
  118. std::string colorEnv = "";
  119. cmsys::SystemTools::GetEnv("COLOR", colorEnv);
  120. if(!colorEnv.empty())
  121. {
  122. if(cmSystemTools::IsOn(colorEnv.c_str()))
  123. {
  124. this->ColorOutput = true;
  125. }
  126. else
  127. {
  128. this->ColorOutput = false;
  129. }
  130. }
  131. }
  132. static std::string getAutogenTargetName(cmTarget const* target)
  133. {
  134. std::string autogenTargetName = target->GetName();
  135. autogenTargetName += "_automoc";
  136. return autogenTargetName;
  137. }
  138. static std::string getAutogenTargetDir(cmTarget const* target)
  139. {
  140. cmMakefile* makefile = target->GetMakefile();
  141. std::string targetDir = makefile->GetCurrentBinaryDirectory();
  142. targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
  143. targetDir += "/";
  144. targetDir += getAutogenTargetName(target);
  145. targetDir += ".dir/";
  146. return targetDir;
  147. }
  148. static std::string cmQtAutoGeneratorsStripCR(std::string const& line)
  149. {
  150. // Strip CR characters rcc may have printed (possibly more than one!).
  151. std::string::size_type cr = line.find('\r');
  152. if (cr != line.npos)
  153. {
  154. return line.substr(0, cr);
  155. }
  156. return line;
  157. }
  158. std::string cmQtAutoGenerators::ListQt5RccInputs(cmSourceFile* sf,
  159. cmTarget const* target,
  160. std::vector<std::string>& depends)
  161. {
  162. std::string rccCommand = this->GetRccExecutable(target);
  163. std::vector<std::string> qrcEntries;
  164. std::vector<std::string> command;
  165. command.push_back(rccCommand);
  166. command.push_back("--list");
  167. std::string absFile = cmsys::SystemTools::GetRealPath(
  168. sf->GetFullPath());
  169. command.push_back(absFile);
  170. std::string rccStdOut;
  171. std::string rccStdErr;
  172. int retVal = 0;
  173. bool result = cmSystemTools::RunSingleCommand(
  174. command, &rccStdOut, &rccStdErr,
  175. &retVal, 0, cmSystemTools::OUTPUT_NONE);
  176. if (!result || retVal)
  177. {
  178. std::cerr << "AUTOGEN: error: Rcc list process for " << sf->GetFullPath()
  179. << " failed:\n" << rccStdOut << "\n" << rccStdErr << std::endl;
  180. return std::string();
  181. }
  182. {
  183. std::istringstream ostr(rccStdOut);
  184. std::string oline;
  185. while(std::getline(ostr, oline))
  186. {
  187. oline = cmQtAutoGeneratorsStripCR(oline);
  188. if(!oline.empty())
  189. {
  190. qrcEntries.push_back(oline);
  191. }
  192. }
  193. }
  194. {
  195. std::istringstream estr(rccStdErr);
  196. std::string eline;
  197. while(std::getline(estr, eline))
  198. {
  199. eline = cmQtAutoGeneratorsStripCR(eline);
  200. if (cmHasLiteralPrefix(eline, "RCC: Error in"))
  201. {
  202. static std::string searchString = "Cannot find file '";
  203. std::string::size_type pos = eline.find(searchString);
  204. if (pos == std::string::npos)
  205. {
  206. std::cerr << "AUTOGEN: error: Rcc lists unparsable output "
  207. << eline << std::endl;
  208. return std::string();
  209. }
  210. pos += searchString.length();
  211. std::string::size_type sz = eline.size() - pos - 1;
  212. qrcEntries.push_back(eline.substr(pos, sz));
  213. }
  214. }
  215. }
  216. depends.insert(depends.end(), qrcEntries.begin(), qrcEntries.end());
  217. return cmJoin(qrcEntries, "@list_sep@");
  218. }
  219. std::string cmQtAutoGenerators::ListQt4RccInputs(cmSourceFile* sf,
  220. std::vector<std::string>& depends)
  221. {
  222. const std::string qrcContents = ReadAll(sf->GetFullPath());
  223. cmsys::RegularExpression fileMatchRegex("(<file[^<]+)");
  224. std::string entriesList;
  225. const char* sep = "";
  226. size_t offset = 0;
  227. while (fileMatchRegex.find(qrcContents.c_str() + offset))
  228. {
  229. std::string qrcEntry = fileMatchRegex.match(1);
  230. offset += qrcEntry.size();
  231. cmsys::RegularExpression fileReplaceRegex("(^<file[^>]*>)");
  232. fileReplaceRegex.find(qrcEntry);
  233. std::string tag = fileReplaceRegex.match(1);
  234. qrcEntry = qrcEntry.substr(tag.size());
  235. if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str()))
  236. {
  237. qrcEntry = sf->GetLocation().GetDirectory() + "/" + qrcEntry;
  238. }
  239. entriesList += sep;
  240. entriesList += qrcEntry;
  241. sep = "@list_sep@";
  242. depends.push_back(qrcEntry);
  243. }
  244. return entriesList;
  245. }
  246. bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
  247. {
  248. cmMakefile* makefile = target->GetMakefile();
  249. // don't do anything if there is no Qt4 or Qt5Core (which contains moc):
  250. std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
  251. if (qtMajorVersion == "")
  252. {
  253. qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
  254. }
  255. if (qtMajorVersion != "4" && qtMajorVersion != "5")
  256. {
  257. return false;
  258. }
  259. if (target->GetPropertyAsBool("AUTOMOC"))
  260. {
  261. std::string automocTargetName = getAutogenTargetName(target);
  262. std::string mocCppFile = makefile->GetCurrentBinaryDirectory();
  263. mocCppFile += "/";
  264. mocCppFile += automocTargetName;
  265. mocCppFile += ".cpp";
  266. makefile->GetOrCreateSource(mocCppFile, true);
  267. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
  268. mocCppFile.c_str(), false);
  269. target->AddSource(mocCppFile);
  270. }
  271. // create a custom target for running generators at buildtime:
  272. std::string autogenTargetName = getAutogenTargetName(target);
  273. std::string targetDir = getAutogenTargetDir(target);
  274. cmCustomCommandLine currentLine;
  275. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  276. currentLine.push_back("-E");
  277. currentLine.push_back("cmake_autogen");
  278. currentLine.push_back(targetDir);
  279. currentLine.push_back("$<CONFIGURATION>");
  280. cmCustomCommandLines commandLines;
  281. commandLines.push_back(currentLine);
  282. std::string workingDirectory = cmSystemTools::CollapseFullPath(
  283. "", makefile->GetCurrentBinaryDirectory());
  284. std::vector<std::string> depends;
  285. if (const char *autogenDepends =
  286. target->GetProperty("AUTOGEN_TARGET_DEPENDS"))
  287. {
  288. cmSystemTools::ExpandListArgument(autogenDepends, depends);
  289. }
  290. std::vector<std::string> toolNames;
  291. if (target->GetPropertyAsBool("AUTOMOC"))
  292. {
  293. toolNames.push_back("moc");
  294. }
  295. if (target->GetPropertyAsBool("AUTOUIC"))
  296. {
  297. toolNames.push_back("uic");
  298. }
  299. if (target->GetPropertyAsBool("AUTORCC"))
  300. {
  301. toolNames.push_back("rcc");
  302. }
  303. std::string tools = toolNames[0];
  304. toolNames.erase(toolNames.begin());
  305. while (toolNames.size() > 1)
  306. {
  307. tools += ", " + toolNames[0];
  308. toolNames.erase(toolNames.begin());
  309. }
  310. if (toolNames.size() == 1)
  311. {
  312. tools += " and " + toolNames[0];
  313. }
  314. std::string autogenComment = "Automatic " + tools + " for target ";
  315. autogenComment += target->GetName();
  316. #if defined(_WIN32) && !defined(__CYGWIN__)
  317. bool usePRE_BUILD = false;
  318. cmLocalGenerator* localGen = makefile->GetLocalGenerator();
  319. cmGlobalGenerator* gg = localGen->GetGlobalGenerator();
  320. if(gg->GetName().find("Visual Studio") != std::string::npos)
  321. {
  322. cmGlobalVisualStudioGenerator* vsgg =
  323. static_cast<cmGlobalVisualStudioGenerator*>(gg);
  324. // Under VS >= 7 use a PRE_BUILD event instead of a separate target to
  325. // reduce the number of targets loaded into the IDE.
  326. // This also works around a VS 11 bug that may skip updating the target:
  327. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  328. usePRE_BUILD = vsgg->GetVersion() >= cmGlobalVisualStudioGenerator::VS7;
  329. if(usePRE_BUILD)
  330. {
  331. for (std::vector<std::string>::iterator it = depends.begin();
  332. it != depends.end(); ++it)
  333. {
  334. if(!makefile->FindTargetToUse(it->c_str()))
  335. {
  336. usePRE_BUILD = false;
  337. break;
  338. }
  339. }
  340. }
  341. }
  342. #endif
  343. std::vector<std::string> rcc_output;
  344. bool const isNinja =
  345. makefile->GetGlobalGenerator()->GetName() == "Ninja";
  346. if(isNinja
  347. #if defined(_WIN32) && !defined(__CYGWIN__)
  348. || usePRE_BUILD
  349. #endif
  350. )
  351. {
  352. std::vector<cmSourceFile*> srcFiles;
  353. target->GetConfigCommonSourceFiles(srcFiles);
  354. for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  355. fileIt != srcFiles.end();
  356. ++fileIt)
  357. {
  358. cmSourceFile* sf = *fileIt;
  359. std::string absFile = cmsys::SystemTools::GetRealPath(
  360. sf->GetFullPath());
  361. std::string ext = sf->GetExtension();
  362. if (target->GetPropertyAsBool("AUTORCC"))
  363. {
  364. if (ext == "qrc"
  365. && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
  366. {
  367. std::string basename = cmsys::SystemTools::
  368. GetFilenameWithoutLastExtension(absFile);
  369. std::string rcc_output_dir = target->GetSupportDirectory();
  370. cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
  371. std::string rcc_output_file = rcc_output_dir;
  372. rcc_output_file += "/qrc_" + basename + ".cpp";
  373. rcc_output.push_back(rcc_output_file);
  374. if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
  375. {
  376. if (qtMajorVersion == "5")
  377. {
  378. this->ListQt5RccInputs(sf, target, depends);
  379. }
  380. else
  381. {
  382. this->ListQt4RccInputs(sf, depends);
  383. }
  384. #if defined(_WIN32) && !defined(__CYGWIN__)
  385. // Cannot use PRE_BUILD because the resource files themselves
  386. // may not be sources within the target so VS may not know the
  387. // target needs to re-build at all.
  388. usePRE_BUILD = false;
  389. #endif
  390. }
  391. }
  392. }
  393. }
  394. }
  395. #if defined(_WIN32) && !defined(__CYGWIN__)
  396. if(usePRE_BUILD)
  397. {
  398. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  399. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  400. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  401. std::vector<std::string> no_output;
  402. std::vector<std::string> no_byproducts;
  403. cmCustomCommand cc(makefile, no_output, no_byproducts, depends,
  404. commandLines, autogenComment.c_str(),
  405. workingDirectory.c_str());
  406. cc.SetEscapeOldStyle(false);
  407. cc.SetEscapeAllowMakeVars(true);
  408. target->AddPreBuildCommand(cc);
  409. }
  410. else
  411. #endif
  412. {
  413. cmTarget* autogenTarget = makefile->AddUtilityCommand(
  414. autogenTargetName, true,
  415. workingDirectory.c_str(),
  416. /*byproducts=*/rcc_output, depends,
  417. commandLines, false, autogenComment.c_str());
  418. // Set target folder
  419. const char* autogenFolder = makefile->GetState()
  420. ->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  421. if (!autogenFolder)
  422. {
  423. autogenFolder = makefile->GetState()
  424. ->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
  425. }
  426. if (autogenFolder && *autogenFolder)
  427. {
  428. autogenTarget->SetProperty("FOLDER", autogenFolder);
  429. }
  430. else
  431. {
  432. // inherit FOLDER property from target (#13688)
  433. copyTargetProperty(autogenTarget, target, "FOLDER");
  434. }
  435. target->AddUtility(autogenTargetName);
  436. }
  437. return true;
  438. }
  439. static void GetCompileDefinitionsAndDirectories(cmTarget const* target,
  440. const std::string& config,
  441. std::string &incs,
  442. std::string &defs)
  443. {
  444. cmMakefile* makefile = target->GetMakefile();
  445. cmLocalGenerator* localGen = makefile->GetLocalGenerator();
  446. std::vector<std::string> includeDirs;
  447. cmGeneratorTarget *gtgt = localGen->GetGlobalGenerator()
  448. ->GetGeneratorTarget(target);
  449. // Get the include dirs for this target, without stripping the implicit
  450. // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667
  451. localGen->GetIncludeDirectories(includeDirs, gtgt, "CXX", config, false);
  452. incs = cmJoin(includeDirs, ";");
  453. std::set<std::string> defines;
  454. localGen->AddCompileDefinitions(defines, target, config, "CXX");
  455. defs += cmJoin(defines, ";");
  456. }
  457. void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget const* target)
  458. {
  459. cmMakefile* makefile = target->GetMakefile();
  460. // forget the variables added here afterwards again:
  461. cmMakefile::ScopePushPop varScope(makefile);
  462. static_cast<void>(varScope);
  463. // create a custom target for running generators at buildtime:
  464. std::string autogenTargetName = getAutogenTargetName(target);
  465. makefile->AddDefinition("_moc_target_name",
  466. cmOutputConverter::EscapeForCMake(autogenTargetName).c_str());
  467. makefile->AddDefinition("_origin_target_name",
  468. cmOutputConverter::EscapeForCMake(target->GetName()).c_str());
  469. std::string targetDir = getAutogenTargetDir(target);
  470. const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
  471. if (!qtVersion)
  472. {
  473. qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
  474. }
  475. if (const char *targetQtVersion =
  476. target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""))
  477. {
  478. qtVersion = targetQtVersion;
  479. }
  480. if (qtVersion)
  481. {
  482. makefile->AddDefinition("_target_qt_version", qtVersion);
  483. }
  484. std::map<std::string, std::string> configIncludes;
  485. std::map<std::string, std::string> configDefines;
  486. std::map<std::string, std::string> configUicOptions;
  487. if (target->GetPropertyAsBool("AUTOMOC")
  488. || target->GetPropertyAsBool("AUTOUIC")
  489. || target->GetPropertyAsBool("AUTORCC"))
  490. {
  491. this->SetupSourceFiles(target);
  492. }
  493. makefile->AddDefinition("_cpp_files",
  494. cmOutputConverter::EscapeForCMake(this->Sources).c_str());
  495. if (target->GetPropertyAsBool("AUTOMOC"))
  496. {
  497. this->SetupAutoMocTarget(target, autogenTargetName,
  498. configIncludes, configDefines);
  499. }
  500. if (target->GetPropertyAsBool("AUTOUIC"))
  501. {
  502. this->SetupAutoUicTarget(target, configUicOptions);
  503. }
  504. if (target->GetPropertyAsBool("AUTORCC"))
  505. {
  506. this->SetupAutoRccTarget(target);
  507. }
  508. const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT");
  509. std::string inputFile = cmakeRoot;
  510. inputFile += "/Modules/AutogenInfo.cmake.in";
  511. std::string outputFile = targetDir;
  512. outputFile += "/AutogenInfo.cmake";
  513. makefile->AddDefinition("_qt_rcc_inputs",
  514. makefile->GetDefinition("_qt_rcc_inputs_" + target->GetName()));
  515. makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
  516. false, true, false);
  517. // Ensure we have write permission in case .in was read-only.
  518. mode_t perm = 0;
  519. #if defined(_WIN32) && !defined(__CYGWIN__)
  520. mode_t mode_write = S_IWRITE;
  521. #else
  522. mode_t mode_write = S_IWUSR;
  523. #endif
  524. cmSystemTools::GetPermissions(outputFile, perm);
  525. if (!(perm & mode_write))
  526. {
  527. cmSystemTools::SetPermissions(outputFile, perm | mode_write);
  528. }
  529. if (!configDefines.empty()
  530. || !configIncludes.empty()
  531. || !configUicOptions.empty())
  532. {
  533. cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app);
  534. if ( !infoFile )
  535. {
  536. std::string error = "Internal CMake error when trying to open file: ";
  537. error += outputFile.c_str();
  538. error += " for writing.";
  539. cmSystemTools::Error(error.c_str());
  540. return;
  541. }
  542. if (!configDefines.empty())
  543. {
  544. for (std::map<std::string, std::string>::iterator
  545. it = configDefines.begin(), end = configDefines.end();
  546. it != end; ++it)
  547. {
  548. infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first <<
  549. " " << it->second << ")\n";
  550. }
  551. }
  552. if (!configIncludes.empty())
  553. {
  554. for (std::map<std::string, std::string>::iterator
  555. it = configIncludes.begin(), end = configIncludes.end();
  556. it != end; ++it)
  557. {
  558. infoFile << "set(AM_MOC_INCLUDES_" << it->first <<
  559. " " << it->second << ")\n";
  560. }
  561. }
  562. if (!configUicOptions.empty())
  563. {
  564. for (std::map<std::string, std::string>::iterator
  565. it = configUicOptions.begin(), end = configUicOptions.end();
  566. it != end; ++it)
  567. {
  568. infoFile << "set(AM_UIC_TARGET_OPTIONS_" << it->first <<
  569. " " << it->second << ")\n";
  570. }
  571. }
  572. }
  573. }
  574. void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target)
  575. {
  576. cmMakefile* makefile = target->GetMakefile();
  577. const char* sepFiles = "";
  578. const char* sepHeaders = "";
  579. std::vector<cmSourceFile*> srcFiles;
  580. target->GetConfigCommonSourceFiles(srcFiles);
  581. const char *skipMocSep = "";
  582. const char *skipUicSep = "";
  583. std::vector<std::string> newRccFiles;
  584. for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  585. fileIt != srcFiles.end();
  586. ++fileIt)
  587. {
  588. cmSourceFile* sf = *fileIt;
  589. std::string absFile = cmsys::SystemTools::GetRealPath(
  590. sf->GetFullPath());
  591. bool skipMoc = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
  592. bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
  593. if(cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")))
  594. {
  595. this->SkipUic += skipUicSep;
  596. this->SkipUic += absFile;
  597. skipUicSep = ";";
  598. }
  599. std::string ext = sf->GetExtension();
  600. if (target->GetPropertyAsBool("AUTORCC"))
  601. {
  602. if (ext == "qrc"
  603. && !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")))
  604. {
  605. std::string basename = cmsys::SystemTools::
  606. GetFilenameWithoutLastExtension(absFile);
  607. std::string rcc_output_dir = target->GetSupportDirectory();
  608. cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
  609. std::string rcc_output_file = rcc_output_dir;
  610. rcc_output_file += "/qrc_" + basename + ".cpp";
  611. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
  612. rcc_output_file.c_str(), false);
  613. makefile->GetOrCreateSource(rcc_output_file, true);
  614. newRccFiles.push_back(rcc_output_file);
  615. }
  616. }
  617. if (!generated)
  618. {
  619. if (skipMoc)
  620. {
  621. this->SkipMoc += skipMocSep;
  622. this->SkipMoc += absFile;
  623. skipMocSep = ";";
  624. }
  625. else
  626. {
  627. cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
  628. ext.c_str());
  629. if (fileType == cmSystemTools::CXX_FILE_FORMAT)
  630. {
  631. this->Sources += sepFiles;
  632. this->Sources += absFile;
  633. sepFiles = ";";
  634. }
  635. else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
  636. {
  637. this->Headers += sepHeaders;
  638. this->Headers += absFile;
  639. sepHeaders = ";";
  640. }
  641. }
  642. }
  643. }
  644. for(std::vector<std::string>::const_iterator fileIt = newRccFiles.begin();
  645. fileIt != newRccFiles.end();
  646. ++fileIt)
  647. {
  648. const_cast<cmTarget*>(target)->AddSource(*fileIt);
  649. }
  650. }
  651. void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget const* target,
  652. const std::string &autogenTargetName,
  653. std::map<std::string, std::string> &configIncludes,
  654. std::map<std::string, std::string> &configDefines)
  655. {
  656. cmMakefile* makefile = target->GetMakefile();
  657. const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
  658. std::string _moc_options = (tmp!=0 ? tmp : "");
  659. makefile->AddDefinition("_moc_options",
  660. cmOutputConverter::EscapeForCMake(_moc_options).c_str());
  661. makefile->AddDefinition("_skip_moc",
  662. cmOutputConverter::EscapeForCMake(this->SkipMoc).c_str());
  663. makefile->AddDefinition("_moc_headers",
  664. cmOutputConverter::EscapeForCMake(this->Headers).c_str());
  665. bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
  666. makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
  667. std::string _moc_incs;
  668. std::string _moc_compile_defs;
  669. std::vector<std::string> configs;
  670. const std::string& config = makefile->GetConfigurations(configs);
  671. GetCompileDefinitionsAndDirectories(target, config,
  672. _moc_incs, _moc_compile_defs);
  673. makefile->AddDefinition("_moc_incs",
  674. cmOutputConverter::EscapeForCMake(_moc_incs).c_str());
  675. makefile->AddDefinition("_moc_compile_defs",
  676. cmOutputConverter::EscapeForCMake(_moc_compile_defs).c_str());
  677. for (std::vector<std::string>::const_iterator li = configs.begin();
  678. li != configs.end(); ++li)
  679. {
  680. std::string config_moc_incs;
  681. std::string config_moc_compile_defs;
  682. GetCompileDefinitionsAndDirectories(target, *li,
  683. config_moc_incs,
  684. config_moc_compile_defs);
  685. if (config_moc_incs != _moc_incs)
  686. {
  687. configIncludes[*li] =
  688. cmOutputConverter::EscapeForCMake(config_moc_incs);
  689. if(_moc_incs.empty())
  690. {
  691. _moc_incs = config_moc_incs;
  692. }
  693. }
  694. if (config_moc_compile_defs != _moc_compile_defs)
  695. {
  696. configDefines[*li] =
  697. cmOutputConverter::EscapeForCMake(config_moc_compile_defs);
  698. if(_moc_compile_defs.empty())
  699. {
  700. _moc_compile_defs = config_moc_compile_defs;
  701. }
  702. }
  703. }
  704. const char *qtVersion = makefile->GetDefinition("_target_qt_version");
  705. if (strcmp(qtVersion, "5") == 0)
  706. {
  707. cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc");
  708. if (!qt5Moc)
  709. {
  710. cmSystemTools::Error("Qt5::moc target not found ",
  711. autogenTargetName.c_str());
  712. return;
  713. }
  714. makefile->AddDefinition("_qt_moc_executable", qt5Moc->GetLocation(""));
  715. }
  716. else if (strcmp(qtVersion, "4") == 0)
  717. {
  718. cmTarget *qt4Moc = makefile->FindTargetToUse("Qt4::moc");
  719. if (!qt4Moc)
  720. {
  721. cmSystemTools::Error("Qt4::moc target not found ",
  722. autogenTargetName.c_str());
  723. return;
  724. }
  725. makefile->AddDefinition("_qt_moc_executable", qt4Moc->GetLocation(""));
  726. }
  727. else
  728. {
  729. cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
  730. "Qt 5 ", autogenTargetName.c_str());
  731. }
  732. }
  733. void cmQtAutoGenerators::MergeUicOptions(std::vector<std::string> &opts,
  734. const std::vector<std::string> &fileOpts,
  735. bool isQt5)
  736. {
  737. static const char* valueOptions[] = {
  738. "tr",
  739. "translate",
  740. "postfix",
  741. "generator",
  742. "include", // Since Qt 5.3
  743. "g"
  744. };
  745. std::vector<std::string> extraOpts;
  746. for(std::vector<std::string>::const_iterator it = fileOpts.begin();
  747. it != fileOpts.end(); ++it)
  748. {
  749. std::vector<std::string>::iterator existingIt
  750. = std::find(opts.begin(), opts.end(), *it);
  751. if (existingIt != opts.end())
  752. {
  753. const char *o = it->c_str();
  754. if (*o == '-')
  755. {
  756. ++o;
  757. }
  758. if (isQt5 && *o == '-')
  759. {
  760. ++o;
  761. }
  762. if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
  763. cmStrCmp(*it)) != cmArrayEnd(valueOptions))
  764. {
  765. assert(existingIt + 1 != opts.end());
  766. *(existingIt + 1) = *(it + 1);
  767. ++it;
  768. }
  769. }
  770. else
  771. {
  772. extraOpts.push_back(*it);
  773. }
  774. }
  775. opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
  776. }
  777. static void GetUicOpts(cmTarget const* target, const std::string& config,
  778. std::string &optString)
  779. {
  780. std::vector<std::string> opts;
  781. target->GetAutoUicOptions(opts, config);
  782. optString = cmJoin(opts, ";");
  783. }
  784. void cmQtAutoGenerators::SetupAutoUicTarget(cmTarget const* target,
  785. std::map<std::string, std::string> &configUicOptions)
  786. {
  787. cmMakefile *makefile = target->GetMakefile();
  788. std::set<std::string> skipped;
  789. std::vector<std::string> skipVec;
  790. cmSystemTools::ExpandListArgument(this->SkipUic, skipVec);
  791. skipped.insert(skipVec.begin(), skipVec.end());
  792. makefile->AddDefinition("_skip_uic",
  793. cmOutputConverter::EscapeForCMake(this->SkipUic).c_str());
  794. std::vector<cmSourceFile*> uiFilesWithOptions
  795. = makefile->GetQtUiFilesWithOptions();
  796. const char *qtVersion = makefile->GetDefinition("_target_qt_version");
  797. std::string _uic_opts;
  798. std::vector<std::string> configs;
  799. const std::string& config = makefile->GetConfigurations(configs);
  800. GetUicOpts(target, config, _uic_opts);
  801. if (!_uic_opts.empty())
  802. {
  803. _uic_opts = cmOutputConverter::EscapeForCMake(_uic_opts);
  804. makefile->AddDefinition("_uic_target_options", _uic_opts.c_str());
  805. }
  806. for (std::vector<std::string>::const_iterator li = configs.begin();
  807. li != configs.end(); ++li)
  808. {
  809. std::string config_uic_opts;
  810. GetUicOpts(target, *li, config_uic_opts);
  811. if (config_uic_opts != _uic_opts)
  812. {
  813. configUicOptions[*li] =
  814. cmOutputConverter::EscapeForCMake(config_uic_opts);
  815. if(_uic_opts.empty())
  816. {
  817. _uic_opts = config_uic_opts;
  818. }
  819. }
  820. }
  821. std::string uiFileFiles;
  822. std::string uiFileOptions;
  823. const char* sep = "";
  824. for(std::vector<cmSourceFile*>::const_iterator fileIt =
  825. uiFilesWithOptions.begin();
  826. fileIt != uiFilesWithOptions.end();
  827. ++fileIt)
  828. {
  829. cmSourceFile* sf = *fileIt;
  830. std::string absFile = cmsys::SystemTools::GetRealPath(
  831. sf->GetFullPath());
  832. if (!skipped.insert(absFile).second)
  833. {
  834. continue;
  835. }
  836. uiFileFiles += sep;
  837. uiFileFiles += absFile;
  838. uiFileOptions += sep;
  839. std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
  840. cmSystemTools::ReplaceString(opts, ";", "@list_sep@");
  841. uiFileOptions += opts;
  842. sep = ";";
  843. }
  844. makefile->AddDefinition("_qt_uic_options_files",
  845. cmOutputConverter::EscapeForCMake(uiFileFiles).c_str());
  846. makefile->AddDefinition("_qt_uic_options_options",
  847. cmOutputConverter::EscapeForCMake(uiFileOptions).c_str());
  848. std::string targetName = target->GetName();
  849. if (strcmp(qtVersion, "5") == 0)
  850. {
  851. cmTarget *qt5Uic = makefile->FindTargetToUse("Qt5::uic");
  852. if (!qt5Uic)
  853. {
  854. // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
  855. }
  856. else
  857. {
  858. makefile->AddDefinition("_qt_uic_executable", qt5Uic->GetLocation(""));
  859. }
  860. }
  861. else if (strcmp(qtVersion, "4") == 0)
  862. {
  863. cmTarget *qt4Uic = makefile->FindTargetToUse("Qt4::uic");
  864. if (!qt4Uic)
  865. {
  866. cmSystemTools::Error("Qt4::uic target not found ",
  867. targetName.c_str());
  868. return;
  869. }
  870. makefile->AddDefinition("_qt_uic_executable", qt4Uic->GetLocation(""));
  871. }
  872. else
  873. {
  874. cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
  875. "Qt 5 ", targetName.c_str());
  876. }
  877. }
  878. void cmQtAutoGenerators::MergeRccOptions(std::vector<std::string> &opts,
  879. const std::vector<std::string> &fileOpts,
  880. bool isQt5)
  881. {
  882. static const char* valueOptions[] = {
  883. "name",
  884. "root",
  885. "compress",
  886. "threshold"
  887. };
  888. std::vector<std::string> extraOpts;
  889. for(std::vector<std::string>::const_iterator it = fileOpts.begin();
  890. it != fileOpts.end(); ++it)
  891. {
  892. std::vector<std::string>::iterator existingIt
  893. = std::find(opts.begin(), opts.end(), *it);
  894. if (existingIt != opts.end())
  895. {
  896. const char *o = it->c_str();
  897. if (*o == '-')
  898. {
  899. ++o;
  900. }
  901. if (isQt5 && *o == '-')
  902. {
  903. ++o;
  904. }
  905. if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
  906. cmStrCmp(*it)) != cmArrayEnd(valueOptions))
  907. {
  908. assert(existingIt + 1 != opts.end());
  909. *(existingIt + 1) = *(it + 1);
  910. ++it;
  911. }
  912. }
  913. else
  914. {
  915. extraOpts.push_back(*it);
  916. }
  917. }
  918. opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
  919. }
  920. void cmQtAutoGenerators::SetupAutoRccTarget(cmTarget const* target)
  921. {
  922. std::string _rcc_files;
  923. const char* sepRccFiles = "";
  924. cmMakefile *makefile = target->GetMakefile();
  925. std::vector<cmSourceFile*> srcFiles;
  926. target->GetConfigCommonSourceFiles(srcFiles);
  927. std::string qrcInputs;
  928. const char* qrcInputsSep = "";
  929. std::string rccFileFiles;
  930. std::string rccFileOptions;
  931. const char *optionSep = "";
  932. const char *qtVersion = makefile->GetDefinition("_target_qt_version");
  933. std::vector<std::string> rccOptions;
  934. if (const char* opts = target->GetProperty("AUTORCC_OPTIONS"))
  935. {
  936. cmSystemTools::ExpandListArgument(opts, rccOptions);
  937. }
  938. std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
  939. if (qtMajorVersion == "")
  940. {
  941. qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
  942. }
  943. for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  944. fileIt != srcFiles.end();
  945. ++fileIt)
  946. {
  947. cmSourceFile* sf = *fileIt;
  948. std::string ext = sf->GetExtension();
  949. if (ext == "qrc")
  950. {
  951. std::string absFile = cmsys::SystemTools::GetRealPath(
  952. sf->GetFullPath());
  953. bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"));
  954. if (!skip)
  955. {
  956. _rcc_files += sepRccFiles;
  957. _rcc_files += absFile;
  958. sepRccFiles = ";";
  959. if (const char *prop = sf->GetProperty("AUTORCC_OPTIONS"))
  960. {
  961. std::vector<std::string> optsVec;
  962. cmSystemTools::ExpandListArgument(prop, optsVec);
  963. this->MergeRccOptions(rccOptions, optsVec,
  964. strcmp(qtVersion, "5") == 0);
  965. }
  966. if (!rccOptions.empty())
  967. {
  968. rccFileFiles += optionSep;
  969. rccFileFiles += absFile;
  970. rccFileOptions += optionSep;
  971. }
  972. const char *listSep = "";
  973. for(std::vector<std::string>::const_iterator it = rccOptions.begin();
  974. it != rccOptions.end();
  975. ++it)
  976. {
  977. rccFileOptions += listSep;
  978. rccFileOptions += *it;
  979. listSep = "@list_sep@";
  980. }
  981. optionSep = ";";
  982. std::vector<std::string> depends;
  983. std::string entriesList;
  984. if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")))
  985. {
  986. if (qtMajorVersion == "5")
  987. {
  988. entriesList = this->ListQt5RccInputs(sf, target, depends);
  989. }
  990. else
  991. {
  992. entriesList = this->ListQt4RccInputs(sf, depends);
  993. }
  994. if (entriesList.empty())
  995. {
  996. return;
  997. }
  998. }
  999. qrcInputs += qrcInputsSep;
  1000. qrcInputs += entriesList;
  1001. qrcInputsSep = ";";
  1002. }
  1003. }
  1004. }
  1005. makefile->AddDefinition("_qt_rcc_inputs_" + target->GetName(),
  1006. cmOutputConverter::EscapeForCMake(qrcInputs).c_str());
  1007. makefile->AddDefinition("_rcc_files",
  1008. cmOutputConverter::EscapeForCMake(_rcc_files).c_str());
  1009. makefile->AddDefinition("_qt_rcc_options_files",
  1010. cmOutputConverter::EscapeForCMake(rccFileFiles).c_str());
  1011. makefile->AddDefinition("_qt_rcc_options_options",
  1012. cmOutputConverter::EscapeForCMake(rccFileOptions).c_str());
  1013. makefile->AddDefinition("_qt_rcc_executable",
  1014. this->GetRccExecutable(target).c_str());
  1015. }
  1016. std::string cmQtAutoGenerators::GetRccExecutable(cmTarget const* target)
  1017. {
  1018. cmMakefile *makefile = target->GetMakefile();
  1019. const char *qtVersion = makefile->GetDefinition("_target_qt_version");
  1020. if (!qtVersion)
  1021. {
  1022. qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
  1023. if (!qtVersion)
  1024. {
  1025. qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
  1026. }
  1027. if (const char *targetQtVersion =
  1028. target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
  1029. ""))
  1030. {
  1031. qtVersion = targetQtVersion;
  1032. }
  1033. }
  1034. std::string targetName = target->GetName();
  1035. if (strcmp(qtVersion, "5") == 0)
  1036. {
  1037. cmTarget *qt5Rcc = makefile->FindTargetToUse("Qt5::rcc");
  1038. if (!qt5Rcc)
  1039. {
  1040. cmSystemTools::Error("Qt5::rcc target not found ",
  1041. targetName.c_str());
  1042. return std::string();
  1043. }
  1044. return qt5Rcc->GetLocation("");
  1045. }
  1046. else if (strcmp(qtVersion, "4") == 0)
  1047. {
  1048. cmTarget *qt4Rcc = makefile->FindTargetToUse("Qt4::rcc");
  1049. if (!qt4Rcc)
  1050. {
  1051. cmSystemTools::Error("Qt4::rcc target not found ",
  1052. targetName.c_str());
  1053. return std::string();
  1054. }
  1055. return qt4Rcc->GetLocation("");
  1056. }
  1057. cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
  1058. "Qt 5 ", targetName.c_str());
  1059. return std::string();
  1060. }
  1061. bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
  1062. const std::string& config)
  1063. {
  1064. bool success = true;
  1065. cmake cm;
  1066. cm.SetHomeOutputDirectory(targetDirectory);
  1067. cm.SetHomeDirectory(targetDirectory);
  1068. cmGlobalGenerator gg(&cm);
  1069. cmLocalGenerator* lg = gg.MakeLocalGenerator();
  1070. lg->GetMakefile()->SetCurrentBinaryDirectory(targetDirectory);
  1071. lg->GetMakefile()->SetCurrentSourceDirectory(targetDirectory);
  1072. gg.SetCurrentMakefile(lg->GetMakefile());
  1073. this->ReadAutogenInfoFile(lg->GetMakefile(), targetDirectory, config);
  1074. this->ReadOldMocDefinitionsFile(lg->GetMakefile(), targetDirectory);
  1075. this->Init();
  1076. if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5")
  1077. {
  1078. success = this->RunAutogen(lg->GetMakefile());
  1079. }
  1080. this->WriteOldMocDefinitionsFile(targetDirectory);
  1081. delete lg;
  1082. return success;
  1083. }
  1084. bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile,
  1085. const std::string& targetDirectory,
  1086. const std::string& config)
  1087. {
  1088. std::string filename(
  1089. cmSystemTools::CollapseFullPath(targetDirectory));
  1090. cmSystemTools::ConvertToUnixSlashes(filename);
  1091. filename += "/AutogenInfo.cmake";
  1092. if (!makefile->ReadListFile(filename.c_str()))
  1093. {
  1094. cmSystemTools::Error("Error processing file: ", filename.c_str());
  1095. return false;
  1096. }
  1097. this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR");
  1098. if (this->QtMajorVersion == "")
  1099. {
  1100. this->QtMajorVersion = makefile->GetSafeDefinition(
  1101. "AM_Qt5Core_VERSION_MAJOR");
  1102. }
  1103. this->Sources = makefile->GetSafeDefinition("AM_SOURCES");
  1104. {
  1105. std::string rccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES");
  1106. cmSystemTools::ExpandListArgument(rccSources, this->RccSources);
  1107. }
  1108. this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC");
  1109. this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC");
  1110. this->Headers = makefile->GetSafeDefinition("AM_HEADERS");
  1111. this->IncludeProjectDirsBefore = makefile->IsOn(
  1112. "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE");
  1113. this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR");
  1114. this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR");
  1115. this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE");
  1116. this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE");
  1117. this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE");
  1118. {
  1119. std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS";
  1120. std::string compileDefsProp = compileDefsPropOrig;
  1121. if(!config.empty())
  1122. {
  1123. compileDefsProp += "_";
  1124. compileDefsProp += config;
  1125. }
  1126. const char *compileDefs = makefile->GetDefinition(compileDefsProp);
  1127. this->MocCompileDefinitionsStr = compileDefs ? compileDefs
  1128. : makefile->GetSafeDefinition(compileDefsPropOrig);
  1129. }
  1130. {
  1131. std::string includesPropOrig = "AM_MOC_INCLUDES";
  1132. std::string includesProp = includesPropOrig;
  1133. if(!config.empty())
  1134. {
  1135. includesProp += "_";
  1136. includesProp += config;
  1137. }
  1138. const char *includes = makefile->GetDefinition(includesProp);
  1139. this->MocIncludesStr = includes ? includes
  1140. : makefile->GetSafeDefinition(includesPropOrig);
  1141. }
  1142. this->MocOptionsStr = makefile->GetSafeDefinition("AM_MOC_OPTIONS");
  1143. this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR");
  1144. this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR");
  1145. this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME");
  1146. this->OriginTargetName
  1147. = makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME");
  1148. {
  1149. const char *uicOptionsFiles
  1150. = makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES");
  1151. std::string uicOptionsPropOrig = "AM_UIC_TARGET_OPTIONS";
  1152. std::string uicOptionsProp = uicOptionsPropOrig;
  1153. if(!config.empty())
  1154. {
  1155. uicOptionsProp += "_";
  1156. uicOptionsProp += config;
  1157. }
  1158. const char *uicTargetOptions
  1159. = makefile->GetSafeDefinition(uicOptionsProp);
  1160. cmSystemTools::ExpandListArgument(
  1161. uicTargetOptions ? uicTargetOptions
  1162. : makefile->GetSafeDefinition(uicOptionsPropOrig),
  1163. this->UicTargetOptions);
  1164. const char *uicOptionsOptions
  1165. = makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS");
  1166. std::vector<std::string> uicFilesVec;
  1167. cmSystemTools::ExpandListArgument(uicOptionsFiles, uicFilesVec);
  1168. std::vector<std::string> uicOptionsVec;
  1169. cmSystemTools::ExpandListArgument(uicOptionsOptions, uicOptionsVec);
  1170. if (uicFilesVec.size() != uicOptionsVec.size())
  1171. {
  1172. return false;
  1173. }
  1174. for (std::vector<std::string>::iterator fileIt = uicFilesVec.begin(),
  1175. optionIt = uicOptionsVec.begin();
  1176. fileIt != uicFilesVec.end();
  1177. ++fileIt, ++optionIt)
  1178. {
  1179. cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
  1180. this->UicOptions[*fileIt] = *optionIt;
  1181. }
  1182. }
  1183. {
  1184. const char *rccOptionsFiles
  1185. = makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES");
  1186. const char *rccOptionsOptions
  1187. = makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS");
  1188. std::vector<std::string> rccFilesVec;
  1189. cmSystemTools::ExpandListArgument(rccOptionsFiles, rccFilesVec);
  1190. std::vector<std::string> rccOptionsVec;
  1191. cmSystemTools::ExpandListArgument(rccOptionsOptions, rccOptionsVec);
  1192. if (rccFilesVec.size() != rccOptionsVec.size())
  1193. {
  1194. return false;
  1195. }
  1196. for (std::vector<std::string>::iterator fileIt = rccFilesVec.begin(),
  1197. optionIt = rccOptionsVec.begin();
  1198. fileIt != rccFilesVec.end();
  1199. ++fileIt, ++optionIt)
  1200. {
  1201. cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
  1202. this->RccOptions[*fileIt] = *optionIt;
  1203. }
  1204. const char *rccInputs = makefile->GetSafeDefinition("AM_RCC_INPUTS");
  1205. std::vector<std::string> rccInputLists;
  1206. cmSystemTools::ExpandListArgument(rccInputs, rccInputLists);
  1207. if (this->RccSources.size() != rccInputLists.size())
  1208. {
  1209. cmSystemTools::Error("Error processing file: ", filename.c_str());
  1210. return false;
  1211. }
  1212. for (std::vector<std::string>::iterator fileIt = this->RccSources.begin(),
  1213. inputIt = rccInputLists.begin();
  1214. fileIt != this->RccSources.end();
  1215. ++fileIt, ++inputIt)
  1216. {
  1217. cmSystemTools::ReplaceString(*inputIt, "@list_sep@", ";");
  1218. std::vector<std::string> rccInputFiles;
  1219. cmSystemTools::ExpandListArgument(*inputIt, rccInputFiles);
  1220. this->RccInputs[*fileIt] = rccInputFiles;
  1221. }
  1222. }
  1223. this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile);
  1224. this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE");
  1225. return true;
  1226. }
  1227. std::string cmQtAutoGenerators::MakeCompileSettingsString(cmMakefile* makefile)
  1228. {
  1229. std::string s;
  1230. s += makefile->GetSafeDefinition("AM_MOC_COMPILE_DEFINITIONS");
  1231. s += " ~~~ ";
  1232. s += makefile->GetSafeDefinition("AM_MOC_INCLUDES");
  1233. s += " ~~~ ";
  1234. s += makefile->GetSafeDefinition("AM_MOC_OPTIONS");
  1235. s += " ~~~ ";
  1236. s += makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE") ? "TRUE"
  1237. : "FALSE";
  1238. s += " ~~~ ";
  1239. return s;
  1240. }
  1241. bool cmQtAutoGenerators::ReadOldMocDefinitionsFile(cmMakefile* makefile,
  1242. const std::string& targetDirectory)
  1243. {
  1244. std::string filename(
  1245. cmSystemTools::CollapseFullPath(targetDirectory));
  1246. cmSystemTools::ConvertToUnixSlashes(filename);
  1247. filename += "/AutomocOldMocDefinitions.cmake";
  1248. if (makefile->ReadListFile(filename.c_str()))
  1249. {
  1250. this->OldCompileSettingsStr =
  1251. makefile->GetSafeDefinition("AM_OLD_COMPILE_SETTINGS");
  1252. }
  1253. return true;
  1254. }
  1255. void
  1256. cmQtAutoGenerators::WriteOldMocDefinitionsFile(
  1257. const std::string& targetDirectory)
  1258. {
  1259. std::string filename(
  1260. cmSystemTools::CollapseFullPath(targetDirectory));
  1261. cmSystemTools::ConvertToUnixSlashes(filename);
  1262. filename += "/AutomocOldMocDefinitions.cmake";
  1263. cmsys::ofstream outfile;
  1264. outfile.open(filename.c_str(),
  1265. std::ios::trunc);
  1266. outfile << "set(AM_OLD_COMPILE_SETTINGS "
  1267. << cmOutputConverter::EscapeForCMake(
  1268. this->CurrentCompileSettingsStr) << ")\n";
  1269. outfile.close();
  1270. }
  1271. void cmQtAutoGenerators::Init()
  1272. {
  1273. this->OutMocCppFilename = this->Builddir;
  1274. this->OutMocCppFilename += this->TargetName;
  1275. this->OutMocCppFilename += ".cpp";
  1276. std::vector<std::string> cdefList;
  1277. cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList);
  1278. for(std::vector<std::string>::const_iterator it = cdefList.begin();
  1279. it != cdefList.end();
  1280. ++it)
  1281. {
  1282. this->MocDefinitions.push_back("-D" + (*it));
  1283. }
  1284. cmSystemTools::ExpandListArgument(this->MocOptionsStr, this->MocOptions);
  1285. std::vector<std::string> incPaths;
  1286. cmSystemTools::ExpandListArgument(this->MocIncludesStr, incPaths);
  1287. std::set<std::string> frameworkPaths;
  1288. for(std::vector<std::string>::const_iterator it = incPaths.begin();
  1289. it != incPaths.end();
  1290. ++it)
  1291. {
  1292. const std::string &path = *it;
  1293. this->MocIncludes.push_back("-I" + path);
  1294. if (cmHasLiteralSuffix(path, ".framework/Headers"))
  1295. {
  1296. // Go up twice to get to the framework root
  1297. std::vector<std::string> pathComponents;
  1298. cmsys::SystemTools::SplitPath(path, pathComponents);
  1299. std::string frameworkPath =cmsys::SystemTools::JoinPath(
  1300. pathComponents.begin(), pathComponents.end() - 2);
  1301. frameworkPaths.insert(frameworkPath);
  1302. }
  1303. }
  1304. for (std::set<std::string>::const_iterator it = frameworkPaths.begin();
  1305. it != frameworkPaths.end(); ++it)
  1306. {
  1307. this->MocIncludes.push_back("-F");
  1308. this->MocIncludes.push_back(*it);
  1309. }
  1310. if (this->IncludeProjectDirsBefore)
  1311. {
  1312. const std::string binDir = "-I" + this->ProjectBinaryDir;
  1313. const std::string srcDir = "-I" + this->ProjectSourceDir;
  1314. std::list<std::string> sortedMocIncludes;
  1315. std::list<std::string>::iterator it = this->MocIncludes.begin();
  1316. while (it != this->MocIncludes.end())
  1317. {
  1318. if (this->StartsWith(*it, binDir))
  1319. {
  1320. sortedMocIncludes.push_back(*it);
  1321. it = this->MocIncludes.erase(it);
  1322. }
  1323. else
  1324. {
  1325. ++it;
  1326. }
  1327. }
  1328. it = this->MocIncludes.begin();
  1329. while (it != this->MocIncludes.end())
  1330. {
  1331. if (this->StartsWith(*it, srcDir))
  1332. {
  1333. sortedMocIncludes.push_back(*it);
  1334. it = this->MocIncludes.erase(it);
  1335. }
  1336. else
  1337. {
  1338. ++it;
  1339. }
  1340. }
  1341. sortedMocIncludes.insert(sortedMocIncludes.end(),
  1342. this->MocIncludes.begin(), this->MocIncludes.end());
  1343. this->MocIncludes = sortedMocIncludes;
  1344. }
  1345. }
  1346. bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
  1347. {
  1348. if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str())
  1349. || (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr))
  1350. {
  1351. this->GenerateAll = true;
  1352. }
  1353. // the program goes through all .cpp files to see which moc files are
  1354. // included. It is not really interesting how the moc file is named, but
  1355. // what file the moc is created from. Once a moc is included the same moc
  1356. // may not be included in the _automoc.cpp file anymore. OTOH if there's a
  1357. // header containing Q_OBJECT where no corresponding moc file is included
  1358. // anywhere a moc_<filename>.cpp file is created and included in
  1359. // the _automoc.cpp file.
  1360. // key = moc source filepath, value = moc output filepath
  1361. std::map<std::string, std::string> includedMocs;
  1362. // collect all headers which may need to be mocced
  1363. std::set<std::string> headerFiles;
  1364. std::vector<std::string> sourceFiles;
  1365. cmSystemTools::ExpandListArgument(this->Sources, sourceFiles);
  1366. const std::vector<std::string>& headerExtensions =
  1367. makefile->GetHeaderExtensions();
  1368. std::map<std::string, std::vector<std::string> > includedUis;
  1369. std::map<std::string, std::vector<std::string> > skippedUis;
  1370. std::vector<std::string> uicSkipped;
  1371. cmSystemTools::ExpandListArgument(this->SkipUic, uicSkipped);
  1372. for (std::vector<std::string>::const_iterator it = sourceFiles.begin();
  1373. it != sourceFiles.end();
  1374. ++it)
  1375. {
  1376. const bool skipUic = std::find(uicSkipped.begin(), uicSkipped.end(), *it)
  1377. != uicSkipped.end();
  1378. std::map<std::string, std::vector<std::string> >& uiFiles
  1379. = skipUic ? skippedUis : includedUis;
  1380. const std::string &absFilename = *it;
  1381. if (this->Verbose)
  1382. {
  1383. std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
  1384. }
  1385. if (this->RelaxedMode)
  1386. {
  1387. this->ParseCppFile(absFilename, headerExtensions, includedMocs,
  1388. uiFiles);
  1389. }
  1390. else
  1391. {
  1392. this->StrictParseCppFile(absFilename, headerExtensions, includedMocs,
  1393. uiFiles);
  1394. }
  1395. this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles);
  1396. }
  1397. {
  1398. std::vector<std::string> mocSkipped;
  1399. cmSystemTools::ExpandListArgument(this->SkipMoc, mocSkipped);
  1400. for (std::vector<std::string>::const_iterator it = mocSkipped.begin();
  1401. it != mocSkipped.end();
  1402. ++it)
  1403. {
  1404. if (std::find(uicSkipped.begin(), uicSkipped.end(), *it)
  1405. != uicSkipped.end())
  1406. {
  1407. const std::string &absFilename = *it;
  1408. if (this->Verbose)
  1409. {
  1410. std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
  1411. }
  1412. this->ParseForUic(absFilename, includedUis);
  1413. }
  1414. }
  1415. }
  1416. std::vector<std::string> headerFilesVec;
  1417. cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec);
  1418. headerFiles.insert(headerFilesVec.begin(), headerFilesVec.end());
  1419. // key = moc source filepath, value = moc output filename
  1420. std::map<std::string, std::string> notIncludedMocs;
  1421. this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis);
  1422. // run moc on all the moc's that are #included in source files
  1423. for(std::map<std::string, std::string>::const_iterator
  1424. it = includedMocs.begin();
  1425. it != includedMocs.end();
  1426. ++it)
  1427. {
  1428. this->GenerateMoc(it->first, it->second);
  1429. }
  1430. for(std::map<std::string, std::vector<std::string> >::const_iterator
  1431. it = includedUis.begin();
  1432. it != includedUis.end();
  1433. ++it)
  1434. {
  1435. for (std::vector<std::string>::const_iterator nit = it->second.begin();
  1436. nit != it->second.end();
  1437. ++nit)
  1438. {
  1439. this->GenerateUi(it->first, *nit);
  1440. }
  1441. }
  1442. if(!this->RccExecutable.empty())
  1443. {
  1444. this->GenerateQrc();
  1445. }
  1446. cmsys_ios::stringstream outStream;
  1447. outStream << "/* This file is autogenerated, do not edit*/\n";
  1448. bool automocCppChanged = false;
  1449. if (notIncludedMocs.empty())
  1450. {
  1451. outStream << "enum some_compilers { need_more_than_nothing };\n";
  1452. }
  1453. else
  1454. {
  1455. // run moc on the remaining headers and include them in
  1456. // the _automoc.cpp file
  1457. for(std::map<std::string, std::string>::const_iterator
  1458. it = notIncludedMocs.begin();
  1459. it != notIncludedMocs.end();
  1460. ++it)
  1461. {
  1462. bool mocSuccess = this->GenerateMoc(it->first, it->second);
  1463. if (mocSuccess)
  1464. {
  1465. automocCppChanged = true;
  1466. }
  1467. outStream << "#include \"" << it->second << "\"\n";
  1468. }
  1469. }
  1470. if (this->RunMocFailed)
  1471. {
  1472. std::cerr << "moc failed..." << std::endl;
  1473. return false;
  1474. }
  1475. if (this->RunUicFailed)
  1476. {
  1477. std::cerr << "uic failed..." << std::endl;
  1478. return false;
  1479. }
  1480. if (this->RunRccFailed)
  1481. {
  1482. std::cerr << "rcc failed..." << std::endl;
  1483. return false;
  1484. }
  1485. outStream.flush();
  1486. std::string automocSource = outStream.str();
  1487. if (!automocCppChanged)
  1488. {
  1489. // compare contents of the _automoc.cpp file
  1490. const std::string oldContents = ReadAll(this->OutMocCppFilename);
  1491. if (oldContents == automocSource)
  1492. {
  1493. // nothing changed: don't touch the _automoc.cpp file
  1494. return true;
  1495. }
  1496. }
  1497. // source file that includes all remaining moc files (_automoc.cpp file)
  1498. cmsys::ofstream outfile;
  1499. outfile.open(this->OutMocCppFilename.c_str(),
  1500. std::ios::trunc);
  1501. outfile << automocSource;
  1502. outfile.close();
  1503. return true;
  1504. }
  1505. void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
  1506. const std::vector<std::string>& headerExtensions,
  1507. std::map<std::string, std::string>& includedMocs,
  1508. std::map<std::string, std::vector<std::string> > &includedUis)
  1509. {
  1510. cmsys::RegularExpression mocIncludeRegExp(
  1511. "[\n][ \t]*#[ \t]*include[ \t]+"
  1512. "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
  1513. const std::string contentsString = ReadAll(absFilename);
  1514. if (contentsString.empty())
  1515. {
  1516. std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
  1517. << std::endl;
  1518. return;
  1519. }
  1520. this->ParseForUic(absFilename, contentsString, includedUis);
  1521. if (this->MocExecutable.empty())
  1522. {
  1523. return;
  1524. }
  1525. const std::string absPath = cmsys::SystemTools::GetFilenamePath(
  1526. cmsys::SystemTools::GetRealPath(absFilename)) + '/';
  1527. const std::string scannedFileBasename = cmsys::SystemTools::
  1528. GetFilenameWithoutLastExtension(absFilename);
  1529. std::string macroName;
  1530. const bool requiresMoc = requiresMocing(contentsString, macroName);
  1531. bool dotMocIncluded = false;
  1532. bool mocUnderscoreIncluded = false;
  1533. std::string ownMocUnderscoreFile;
  1534. std::string ownDotMocFile;
  1535. std::string ownMocHeaderFile;
  1536. std::string::size_type matchOffset = 0;
  1537. // first a simple string check for "moc" is *much* faster than the regexp,
  1538. // and if the string search already fails, we don't have to try the
  1539. // expensive regexp
  1540. if ((strstr(contentsString.c_str(), "moc") != NULL)
  1541. && (mocIncludeRegExp.find(contentsString)))
  1542. {
  1543. // for every moc include in the file
  1544. do
  1545. {
  1546. const std::string currentMoc = mocIncludeRegExp.match(1);
  1547. //std::cout << "found moc include: " << currentMoc << std::endl;
  1548. std::string basename = cmsys::SystemTools::
  1549. GetFilenameWithoutLastExtension(currentMoc);
  1550. const bool moc_style = cmHasLiteralPrefix(basename, "moc_");
  1551. // If the moc include is of the moc_foo.cpp style we expect
  1552. // the Q_OBJECT class declaration in a header file.
  1553. // If the moc include is of the foo.moc style we need to look for
  1554. // a Q_OBJECT macro in the current source file, if it contains the
  1555. // macro we generate the moc file from the source file.
  1556. // Q_OBJECT
  1557. if (moc_style)
  1558. {
  1559. // basename should be the part of the moc filename used for
  1560. // finding the correct header, so we need to remove the moc_ part
  1561. basename = basename.substr(4);
  1562. std::string mocSubDir = extractSubDir(absPath, currentMoc);
  1563. std::string headerToMoc = findMatchingHeader(
  1564. absPath, mocSubDir, basename, headerExtensions);
  1565. if (!headerToMoc.empty())
  1566. {
  1567. includedMocs[headerToMoc] = currentMoc;
  1568. if (basename == scannedFileBasename)
  1569. {
  1570. mocUnderscoreIncluded = true;
  1571. ownMocUnderscoreFile = currentMoc;
  1572. ownMocHeaderFile = headerToMoc;
  1573. }
  1574. }
  1575. else
  1576. {
  1577. std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
  1578. << "includes the moc file \"" << currentMoc << "\", "
  1579. << "but could not find header \"" << basename
  1580. << '{' << this->Join(headerExtensions, ',') << "}\" ";
  1581. if (mocSubDir.empty())
  1582. {
  1583. std::cerr << "in " << absPath << "\n" << std::endl;
  1584. }
  1585. else
  1586. {
  1587. std::cerr << "neither in " << absPath
  1588. << " nor in " << mocSubDir << "\n" << std::endl;
  1589. }
  1590. ::exit(EXIT_FAILURE);
  1591. }
  1592. }
  1593. else
  1594. {
  1595. std::string fileToMoc = absFilename;
  1596. if ((basename != scannedFileBasename) || (requiresMoc==false))
  1597. {
  1598. std::string mocSubDir = extractSubDir(absPath, currentMoc);
  1599. std::string headerToMoc = findMatchingHeader(
  1600. absPath, mocSubDir, basename, headerExtensions);
  1601. if (!headerToMoc.empty())
  1602. {
  1603. // this is for KDE4 compatibility:
  1604. fileToMoc = headerToMoc;
  1605. if ((requiresMoc==false) &&(basename==scannedFileBasename))
  1606. {
  1607. std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
  1608. "includes the moc file \"" << currentMoc <<
  1609. "\", but does not contain a " << macroName
  1610. << " macro. Running moc on "
  1611. << "\"" << headerToMoc << "\" ! Include \"moc_"
  1612. << basename << ".cpp\" for a compatiblity with "
  1613. "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
  1614. << std::endl;
  1615. }
  1616. else
  1617. {
  1618. std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
  1619. "includes the moc file \"" << currentMoc <<
  1620. "\" instead of \"moc_" << basename << ".cpp\". "
  1621. "Running moc on "
  1622. << "\"" << headerToMoc << "\" ! Include \"moc_"
  1623. << basename << ".cpp\" for compatiblity with "
  1624. "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
  1625. << std::endl;
  1626. }
  1627. }
  1628. else
  1629. {
  1630. std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
  1631. "includes the moc file \"" << currentMoc <<
  1632. "\", which seems to be the moc file from a different "
  1633. "source file. CMake also could not find a matching "
  1634. "header.\n" << std::endl;
  1635. ::exit(EXIT_FAILURE);
  1636. }
  1637. }
  1638. else
  1639. {
  1640. dotMocIncluded = true;
  1641. ownDotMocFile = currentMoc;
  1642. }
  1643. includedMocs[fileToMoc] = currentMoc;
  1644. }
  1645. matchOffset += mocIncludeRegExp.end();
  1646. } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
  1647. }
  1648. // In this case, check whether the scanned file itself contains a Q_OBJECT.
  1649. // If this is the case, the moc_foo.cpp should probably be generated from
  1650. // foo.cpp instead of foo.h, because otherwise it won't build.
  1651. // But warn, since this is not how it is supposed to be used.
  1652. if ((dotMocIncluded == false) && (requiresMoc == true))
  1653. {
  1654. if (mocUnderscoreIncluded == true)
  1655. {
  1656. // this is for KDE4 compatibility:
  1657. std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
  1658. << "contains a " << macroName << " macro, but does not "
  1659. "include "
  1660. << "\"" << scannedFileBasename << ".moc\", but instead "
  1661. "includes "
  1662. << "\"" << ownMocUnderscoreFile << "\". Running moc on "
  1663. << "\"" << absFilename << "\" ! Better include \""
  1664. << scannedFileBasename << ".moc\" for compatiblity with "
  1665. "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
  1666. << std::endl;
  1667. includedMocs[absFilename] = ownMocUnderscoreFile;
  1668. includedMocs.erase(ownMocHeaderFile);
  1669. }
  1670. else
  1671. {
  1672. // otherwise always error out since it will not compile:
  1673. std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
  1674. << "contains a " << macroName << " macro, but does not "
  1675. "include "
  1676. << "\"" << scannedFileBasename << ".moc\" !\n"
  1677. << std::endl;
  1678. ::exit(EXIT_FAILURE);
  1679. }
  1680. }
  1681. }
  1682. void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
  1683. const std::vector<std::string>& headerExtensions,
  1684. std::map<std::string, std::string>& includedMocs,
  1685. std::map<std::string, std::vector<std::string> >& includedUis)
  1686. {
  1687. cmsys::RegularExpression mocIncludeRegExp(
  1688. "[\n][ \t]*#[ \t]*include[ \t]+"
  1689. "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]");
  1690. const std::string contentsString = ReadAll(absFilename);
  1691. if (contentsString.empty())
  1692. {
  1693. std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
  1694. << std::endl;
  1695. return;
  1696. }
  1697. this->ParseForUic(absFilename, contentsString, includedUis);
  1698. if (this->MocExecutable.empty())
  1699. {
  1700. return;
  1701. }
  1702. const std::string absPath = cmsys::SystemTools::GetFilenamePath(
  1703. cmsys::SystemTools::GetRealPath(absFilename)) + '/';
  1704. const std::string scannedFileBasename = cmsys::SystemTools::
  1705. GetFilenameWithoutLastExtension(absFilename);
  1706. bool dotMocIncluded = false;
  1707. std::string::size_type matchOffset = 0;
  1708. // first a simple string check for "moc" is *much* faster than the regexp,
  1709. // and if the string search already fails, we don't have to try the
  1710. // expensive regexp
  1711. if ((strstr(contentsString.c_str(), "moc") != NULL)
  1712. && (mocIncludeRegExp.find(contentsString)))
  1713. {
  1714. // for every moc include in the file
  1715. do
  1716. {
  1717. const std::string currentMoc = mocIncludeRegExp.match(1);
  1718. std::string basename = cmsys::SystemTools::
  1719. GetFilenameWithoutLastExtension(currentMoc);
  1720. const bool mocUnderscoreStyle = cmHasLiteralPrefix(basename, "moc_");
  1721. // If the moc include is of the moc_foo.cpp style we expect
  1722. // the Q_OBJECT class declaration in a header file.
  1723. // If the moc include is of the foo.moc style we need to look for
  1724. // a Q_OBJECT macro in the current source file, if it contains the
  1725. // macro we generate the moc file from the source file.
  1726. if (mocUnderscoreStyle)
  1727. {
  1728. // basename should be the part of the moc filename used for
  1729. // finding the correct header, so we need to remove the moc_ part
  1730. basename = basename.substr(4);
  1731. std::string mocSubDir = extractSubDir(absPath, currentMoc);
  1732. std::string headerToMoc = findMatchingHeader(
  1733. absPath, mocSubDir, basename, headerExtensions);
  1734. if (!headerToMoc.empty())
  1735. {
  1736. includedMocs[headerToMoc] = currentMoc;
  1737. }
  1738. else
  1739. {
  1740. std::cerr << "AUTOGEN: error: " << absFilename << " The file "
  1741. << "includes the moc file \"" << currentMoc << "\", "
  1742. << "but could not find header \"" << basename
  1743. << '{' << this->Join(headerExtensions, ',') << "}\" ";
  1744. if (mocSubDir.empty())
  1745. {
  1746. std::cerr << "in " << absPath << "\n" << std::endl;
  1747. }
  1748. else
  1749. {
  1750. std::cerr << "neither in " << absPath
  1751. << " nor in " << mocSubDir << "\n" << std::endl;
  1752. }
  1753. ::exit(EXIT_FAILURE);
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if (basename != scannedFileBasename)
  1759. {
  1760. std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
  1761. "includes the moc file \"" << currentMoc <<
  1762. "\", which seems to be the moc file from a different "
  1763. "source file. This is not supported. "
  1764. "Include \"" << scannedFileBasename << ".moc\" to run "
  1765. "moc on this source file.\n" << std::endl;
  1766. ::exit(EXIT_FAILURE);
  1767. }
  1768. dotMocIncluded = true;
  1769. includedMocs[absFilename] = currentMoc;
  1770. }
  1771. matchOffset += mocIncludeRegExp.end();
  1772. } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
  1773. }
  1774. // In this case, check whether the scanned file itself contains a Q_OBJECT.
  1775. // If this is the case, the moc_foo.cpp should probably be generated from
  1776. // foo.cpp instead of foo.h, because otherwise it won't build.
  1777. // But warn, since this is not how it is supposed to be used.
  1778. std::string macroName;
  1779. if ((dotMocIncluded == false) && (requiresMocing(contentsString,
  1780. macroName)))
  1781. {
  1782. // otherwise always error out since it will not compile:
  1783. std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
  1784. << "contains a " << macroName << " macro, but does not include "
  1785. << "\"" << scannedFileBasename << ".moc\" !\n"
  1786. << std::endl;
  1787. ::exit(EXIT_FAILURE);
  1788. }
  1789. }
  1790. void cmQtAutoGenerators::ParseForUic(const std::string& absFilename,
  1791. std::map<std::string, std::vector<std::string> >& includedUis)
  1792. {
  1793. if (this->UicExecutable.empty())
  1794. {
  1795. return;
  1796. }
  1797. const std::string contentsString = ReadAll(absFilename);
  1798. if (contentsString.empty())
  1799. {
  1800. std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
  1801. << std::endl;
  1802. return;
  1803. }
  1804. this->ParseForUic(absFilename, contentsString, includedUis);
  1805. }
  1806. void cmQtAutoGenerators::ParseForUic(const std::string& absFilename,
  1807. const std::string& contentsString,
  1808. std::map<std::string, std::vector<std::string> >& includedUis)
  1809. {
  1810. if (this->UicExecutable.empty())
  1811. {
  1812. return;
  1813. }
  1814. cmsys::RegularExpression uiIncludeRegExp(
  1815. "[\n][ \t]*#[ \t]*include[ \t]+"
  1816. "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
  1817. std::string::size_type matchOffset = 0;
  1818. const std::string realName =
  1819. cmsys::SystemTools::GetRealPath(absFilename);
  1820. matchOffset = 0;
  1821. if ((strstr(contentsString.c_str(), "ui_") != NULL)
  1822. && (uiIncludeRegExp.find(contentsString)))
  1823. {
  1824. do
  1825. {
  1826. const std::string currentUi = uiIncludeRegExp.match(1);
  1827. std::string basename = cmsys::SystemTools::
  1828. GetFilenameWithoutLastExtension(currentUi);
  1829. // basename should be the part of the ui filename used for
  1830. // finding the correct header, so we need to remove the ui_ part
  1831. basename = basename.substr(3);
  1832. includedUis[realName].push_back(basename);
  1833. matchOffset += uiIncludeRegExp.end();
  1834. } while(uiIncludeRegExp.find(contentsString.c_str() + matchOffset));
  1835. }
  1836. }
  1837. void
  1838. cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename,
  1839. const std::vector<std::string>& headerExtensions,
  1840. std::set<std::string>& absHeaders)
  1841. {
  1842. // search for header files and private header files we may need to moc:
  1843. const std::string basename =
  1844. cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
  1845. const std::string absPath = cmsys::SystemTools::GetFilenamePath(
  1846. cmsys::SystemTools::GetRealPath(absFilename)) + '/';
  1847. for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
  1848. ext != headerExtensions.end();
  1849. ++ext)
  1850. {
  1851. const std::string headerName = absPath + basename + "." + (*ext);
  1852. if (cmsys::SystemTools::FileExists(headerName.c_str()))
  1853. {
  1854. absHeaders.insert(headerName);
  1855. break;
  1856. }
  1857. }
  1858. for(std::vector<std::string>::const_iterator ext = headerExtensions.begin();
  1859. ext != headerExtensions.end();
  1860. ++ext)
  1861. {
  1862. const std::string privateHeaderName = absPath+basename+"_p."+(*ext);
  1863. if (cmsys::SystemTools::FileExists(privateHeaderName.c_str()))
  1864. {
  1865. absHeaders.insert(privateHeaderName);
  1866. break;
  1867. }
  1868. }
  1869. }
  1870. void cmQtAutoGenerators::ParseHeaders(const std::set<std::string>& absHeaders,
  1871. const std::map<std::string, std::string>& includedMocs,
  1872. std::map<std::string, std::string>& notIncludedMocs,
  1873. std::map<std::string, std::vector<std::string> >& includedUis)
  1874. {
  1875. for(std::set<std::string>::const_iterator hIt=absHeaders.begin();
  1876. hIt!=absHeaders.end();
  1877. ++hIt)
  1878. {
  1879. const std::string& headerName = *hIt;
  1880. const std::string contents = ReadAll(headerName);
  1881. if (!this->MocExecutable.empty()
  1882. && includedMocs.find(headerName) == includedMocs.end())
  1883. {
  1884. if (this->Verbose)
  1885. {
  1886. std::cout << "AUTOGEN: Checking " << headerName << std::endl;
  1887. }
  1888. const std::string basename = cmsys::SystemTools::
  1889. GetFilenameWithoutLastExtension(headerName);
  1890. const std::string currentMoc = "moc_" + basename + ".cpp";
  1891. std::string macroName;
  1892. if (requiresMocing(contents, macroName))
  1893. {
  1894. //std::cout << "header contains Q_OBJECT macro";
  1895. notIncludedMocs[headerName] = currentMoc;
  1896. }
  1897. }
  1898. this->ParseForUic(headerName, contents, includedUis);
  1899. }
  1900. }
  1901. bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
  1902. const std::string& mocFileName)
  1903. {
  1904. const std::string mocFilePath = this->Builddir + mocFileName;
  1905. int sourceNewerThanMoc = 0;
  1906. bool success = cmsys::SystemTools::FileTimeCompare(sourceFile,
  1907. mocFilePath,
  1908. &sourceNewerThanMoc);
  1909. if (this->GenerateAll || !success || sourceNewerThanMoc >= 0)
  1910. {
  1911. // make sure the directory for the resulting moc file exists
  1912. std::string mocDir = mocFilePath.substr(0, mocFilePath.rfind('/'));
  1913. if (!cmsys::SystemTools::FileExists(mocDir.c_str(), false))
  1914. {
  1915. cmsys::SystemTools::MakeDirectory(mocDir.c_str());
  1916. }
  1917. std::string msg = "Generating ";
  1918. msg += mocFileName;
  1919. cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
  1920. |cmsysTerminal_Color_ForegroundBold,
  1921. msg.c_str(), true, this->ColorOutput);
  1922. std::vector<std::string> command;
  1923. command.push_back(this->MocExecutable);
  1924. command.insert(command.end(),
  1925. this->MocIncludes.begin(), this->MocIncludes.end());
  1926. command.insert(command.end(),
  1927. this->MocDefinitions.begin(), this->MocDefinitions.end());
  1928. command.insert(command.end(),
  1929. this->MocOptions.begin(), this->MocOptions.end());
  1930. #ifdef _WIN32
  1931. command.push_back("-DWIN32");
  1932. #endif
  1933. command.push_back("-o");
  1934. command.push_back(mocFilePath);
  1935. command.push_back(sourceFile);
  1936. if (this->Verbose)
  1937. {
  1938. for(std::vector<std::string>::const_iterator cmdIt = command.begin();
  1939. cmdIt != command.end();
  1940. ++cmdIt)
  1941. {
  1942. std::cout << *cmdIt << " ";
  1943. }
  1944. std::cout << std::endl;
  1945. }
  1946. std::string output;
  1947. int retVal = 0;
  1948. bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
  1949. &retVal);
  1950. if (!result || retVal)
  1951. {
  1952. std::cerr << "AUTOGEN: error: process for " << mocFilePath <<" failed:\n"
  1953. << output << std::endl;
  1954. this->RunMocFailed = true;
  1955. cmSystemTools::RemoveFile(mocFilePath);
  1956. }
  1957. return true;
  1958. }
  1959. return false;
  1960. }
  1961. bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
  1962. const std::string& uiFileName)
  1963. {
  1964. if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false))
  1965. {
  1966. cmsys::SystemTools::MakeDirectory(this->Builddir.c_str());
  1967. }
  1968. const std::string path = cmsys::SystemTools::GetFilenamePath(
  1969. realName) + '/';
  1970. std::string ui_output_file = "ui_" + uiFileName + ".h";
  1971. std::string ui_input_file = path + uiFileName + ".ui";
  1972. int sourceNewerThanUi = 0;
  1973. bool success = cmsys::SystemTools::FileTimeCompare(ui_input_file,
  1974. this->Builddir + ui_output_file,
  1975. &sourceNewerThanUi);
  1976. if (this->GenerateAll || !success || sourceNewerThanUi >= 0)
  1977. {
  1978. std::string msg = "Generating ";
  1979. msg += ui_output_file;
  1980. cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
  1981. |cmsysTerminal_Color_ForegroundBold,
  1982. msg.c_str(), true, this->ColorOutput);
  1983. std::vector<std::string> command;
  1984. command.push_back(this->UicExecutable);
  1985. std::vector<std::string> opts = this->UicTargetOptions;
  1986. std::map<std::string, std::string>::const_iterator optionIt
  1987. = this->UicOptions.find(ui_input_file);
  1988. if (optionIt != this->UicOptions.end())
  1989. {
  1990. std::vector<std::string> fileOpts;
  1991. cmSystemTools::ExpandListArgument(optionIt->second, fileOpts);
  1992. this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5");
  1993. }
  1994. command.insert(command.end(), opts.begin(), opts.end());
  1995. command.push_back("-o");
  1996. command.push_back(this->Builddir + ui_output_file);
  1997. command.push_back(ui_input_file);
  1998. if (this->Verbose)
  1999. {
  2000. for(std::vector<std::string>::const_iterator cmdIt = command.begin();
  2001. cmdIt != command.end();
  2002. ++cmdIt)
  2003. {
  2004. std::cout << *cmdIt << " ";
  2005. }
  2006. std::cout << std::endl;
  2007. }
  2008. std::string output;
  2009. int retVal = 0;
  2010. bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
  2011. &retVal);
  2012. if (!result || retVal)
  2013. {
  2014. std::cerr << "AUTOUIC: error: process for " << ui_output_file <<
  2015. " needed by\n \"" << realName << "\"\nfailed:\n" << output
  2016. << std::endl;
  2017. this->RunUicFailed = true;
  2018. cmSystemTools::RemoveFile(ui_output_file);
  2019. return false;
  2020. }
  2021. return true;
  2022. }
  2023. return false;
  2024. }
  2025. bool cmQtAutoGenerators::InputFilesNewerThanQrc(const std::string& qrcFile,
  2026. const std::string& rccOutput)
  2027. {
  2028. std::vector<std::string> const& files = this->RccInputs[qrcFile];
  2029. for (std::vector<std::string>::const_iterator it = files.begin();
  2030. it != files.end(); ++it)
  2031. {
  2032. int inputNewerThanQrc = 0;
  2033. bool success = cmsys::SystemTools::FileTimeCompare(*it,
  2034. rccOutput,
  2035. &inputNewerThanQrc);
  2036. if (!success || inputNewerThanQrc >= 0)
  2037. {
  2038. return true;
  2039. }
  2040. }
  2041. return false;
  2042. }
  2043. bool cmQtAutoGenerators::GenerateQrc()
  2044. {
  2045. for(std::vector<std::string>::const_iterator si = this->RccSources.begin();
  2046. si != this->RccSources.end(); ++si)
  2047. {
  2048. std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
  2049. if (ext != ".qrc")
  2050. {
  2051. continue;
  2052. }
  2053. std::vector<std::string> command;
  2054. command.push_back(this->RccExecutable);
  2055. std::string basename = cmsys::SystemTools::
  2056. GetFilenameWithoutLastExtension(*si);
  2057. std::string rcc_output_file = this->Builddir
  2058. + "CMakeFiles/" + this->OriginTargetName
  2059. + ".dir/qrc_" + basename + ".cpp";
  2060. int sourceNewerThanQrc = 0;
  2061. bool generateQrc = !cmsys::SystemTools::FileTimeCompare(*si,
  2062. rcc_output_file,
  2063. &sourceNewerThanQrc);
  2064. generateQrc = generateQrc || (sourceNewerThanQrc >= 0);
  2065. generateQrc = generateQrc || this->InputFilesNewerThanQrc(*si,
  2066. rcc_output_file);
  2067. if (this->GenerateAll || generateQrc)
  2068. {
  2069. std::map<std::string, std::string>::const_iterator optionIt
  2070. = this->RccOptions.find(*si);
  2071. if (optionIt != this->RccOptions.end())
  2072. {
  2073. cmSystemTools::ExpandListArgument(optionIt->second, command);
  2074. }
  2075. command.push_back("-name");
  2076. command.push_back(basename);
  2077. command.push_back("-o");
  2078. command.push_back(rcc_output_file);
  2079. command.push_back(*si);
  2080. if (this->Verbose)
  2081. {
  2082. for(std::vector<std::string>::const_iterator cmdIt = command.begin();
  2083. cmdIt != command.end();
  2084. ++cmdIt)
  2085. {
  2086. std::cout << *cmdIt << " ";
  2087. }
  2088. std::cout << std::endl;
  2089. }
  2090. std::string output;
  2091. int retVal = 0;
  2092. bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
  2093. &retVal);
  2094. if (!result || retVal)
  2095. {
  2096. std::cerr << "AUTORCC: error: process for " << rcc_output_file <<
  2097. " failed:\n" << output << std::endl;
  2098. this->RunRccFailed = true;
  2099. cmSystemTools::RemoveFile(rcc_output_file);
  2100. return false;
  2101. }
  2102. }
  2103. }
  2104. return true;
  2105. }
  2106. std::string cmQtAutoGenerators::Join(const std::vector<std::string>& lst,
  2107. char separator)
  2108. {
  2109. if (lst.empty())
  2110. {
  2111. return "";
  2112. }
  2113. std::string result;
  2114. for (std::vector<std::string>::const_iterator it = lst.begin();
  2115. it != lst.end();
  2116. ++it)
  2117. {
  2118. result += "." + (*it) + separator;
  2119. }
  2120. result.erase(result.end() - 1);
  2121. return result;
  2122. }
  2123. bool cmQtAutoGenerators::StartsWith(const std::string& str,
  2124. const std::string& with)
  2125. {
  2126. return (str.substr(0, with.length()) == with);
  2127. }
  2128. bool cmQtAutoGenerators::EndsWith(const std::string& str,
  2129. const std::string& with)
  2130. {
  2131. if (with.length() > (str.length()))
  2132. {
  2133. return false;
  2134. }
  2135. return (str.substr(str.length() - with.length(), with.length()) == with);
  2136. }