cmQtAutoGeneratorInitializer.cxx 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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 "cmQtAutoGeneratorInitializer.h"
  4. #include "cmQtAutoGeneratorCommon.h"
  5. #include "cmAlgorithms.h"
  6. #include "cmCustomCommandLines.h"
  7. #include "cmFilePathChecksum.h"
  8. #include "cmGeneratorTarget.h"
  9. #include "cmGlobalGenerator.h"
  10. #include "cmLocalGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmOutputConverter.h"
  13. #include "cmPolicies.h"
  14. #include "cmSourceFile.h"
  15. #include "cmSourceGroup.h"
  16. #include "cmState.h"
  17. #include "cmSystemTools.h"
  18. #include "cmTarget.h"
  19. #include "cm_sys_stat.h"
  20. #include "cmake.h"
  21. #if defined(_WIN32) && !defined(__CYGWIN__)
  22. #include "cmGlobalVisualStudioGenerator.h"
  23. #endif
  24. #include "cmConfigure.h"
  25. #include "cmsys/FStream.hxx"
  26. #include <algorithm>
  27. #include <map>
  28. #include <set>
  29. #include <sstream>
  30. #include <string>
  31. #include <utility>
  32. #include <vector>
  33. static void utilCopyTargetProperty(cmTarget* destinationTarget,
  34. cmTarget* sourceTarget,
  35. const std::string& propertyName)
  36. {
  37. const char* propertyValue = sourceTarget->GetProperty(propertyName);
  38. if (propertyValue) {
  39. destinationTarget->SetProperty(propertyName, propertyValue);
  40. }
  41. }
  42. inline static bool PropertyEnabled(cmSourceFile* sourceFile, const char* key)
  43. {
  44. return cmSystemTools::IsOn(sourceFile->GetPropertyForUser(key));
  45. }
  46. static std::string GetSafeProperty(cmGeneratorTarget const* target,
  47. const char* key)
  48. {
  49. const char* tmp = target->GetProperty(key);
  50. return std::string((tmp != CM_NULLPTR) ? tmp : "");
  51. }
  52. static std::string GetAutogenTargetName(cmGeneratorTarget const* target)
  53. {
  54. std::string autogenTargetName = target->GetName();
  55. autogenTargetName += "_autogen";
  56. return autogenTargetName;
  57. }
  58. static std::string GetAutogenTargetFilesDir(cmGeneratorTarget const* target)
  59. {
  60. cmMakefile* makefile = target->Target->GetMakefile();
  61. std::string targetDir = makefile->GetCurrentBinaryDirectory();
  62. targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
  63. targetDir += "/";
  64. targetDir += GetAutogenTargetName(target);
  65. targetDir += ".dir";
  66. return targetDir;
  67. }
  68. static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target)
  69. {
  70. std::string targetDir = GetSafeProperty(target, "AUTOGEN_BUILD_DIR");
  71. if (targetDir.empty()) {
  72. cmMakefile* makefile = target->Target->GetMakefile();
  73. targetDir = makefile->GetCurrentBinaryDirectory();
  74. targetDir += "/";
  75. targetDir += GetAutogenTargetName(target);
  76. }
  77. return targetDir;
  78. }
  79. static std::string GetQtMajorVersion(cmGeneratorTarget const* target)
  80. {
  81. cmMakefile* makefile = target->Target->GetMakefile();
  82. std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
  83. if (qtMajorVersion.empty()) {
  84. qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
  85. }
  86. const char* targetQtVersion =
  87. target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "");
  88. if (targetQtVersion != CM_NULLPTR) {
  89. qtMajorVersion = targetQtVersion;
  90. }
  91. return qtMajorVersion;
  92. }
  93. static std::string GetQtMinorVersion(cmGeneratorTarget const* target,
  94. const std::string& qtMajorVersion)
  95. {
  96. cmMakefile* makefile = target->Target->GetMakefile();
  97. std::string qtMinorVersion;
  98. if (qtMajorVersion == "5") {
  99. qtMinorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR");
  100. }
  101. if (qtMinorVersion.empty()) {
  102. qtMinorVersion = makefile->GetSafeDefinition("QT_VERSION_MINOR");
  103. }
  104. const char* targetQtVersion =
  105. target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION", "");
  106. if (targetQtVersion != CM_NULLPTR) {
  107. qtMinorVersion = targetQtVersion;
  108. }
  109. return qtMinorVersion;
  110. }
  111. static bool QtVersionGreaterOrEqual(const std::string& major,
  112. const std::string& minor,
  113. unsigned long requestMajor,
  114. unsigned long requestMinor)
  115. {
  116. unsigned long majorUL(0);
  117. unsigned long minorUL(0);
  118. if (cmSystemTools::StringToULong(major.c_str(), &majorUL) &&
  119. cmSystemTools::StringToULong(minor.c_str(), &minorUL)) {
  120. return (majorUL > requestMajor) ||
  121. (majorUL == requestMajor && minorUL >= requestMinor);
  122. }
  123. return false;
  124. }
  125. static void GetCompileDefinitionsAndDirectories(
  126. cmGeneratorTarget const* target, const std::string& config,
  127. std::string& incs, std::string& defs)
  128. {
  129. cmLocalGenerator* localGen = target->GetLocalGenerator();
  130. {
  131. std::vector<std::string> includeDirs;
  132. // Get the include dirs for this target, without stripping the implicit
  133. // include dirs off, see
  134. // https://gitlab.kitware.com/cmake/cmake/issues/13667
  135. localGen->GetIncludeDirectories(includeDirs, target, "CXX", config, false);
  136. incs = cmJoin(includeDirs, ";");
  137. }
  138. {
  139. std::set<std::string> defines;
  140. localGen->AddCompileDefinitions(defines, target, config, "CXX");
  141. defs += cmJoin(defines, ";");
  142. }
  143. }
  144. static bool IsMultiConfig(cmGlobalGenerator* globalGen)
  145. {
  146. return globalGen->IsMultiConfig();
  147. }
  148. static std::vector<std::string> GetConfigurations(
  149. cmMakefile* makefile, std::string* config = CM_NULLPTR)
  150. {
  151. std::vector<std::string> configs;
  152. {
  153. std::string cfg = makefile->GetConfigurations(configs);
  154. if (config != CM_NULLPTR) {
  155. *config = cfg;
  156. }
  157. }
  158. // Add empty configuration on demand
  159. if (configs.empty()) {
  160. configs.push_back("");
  161. }
  162. return configs;
  163. }
  164. static std::vector<std::string> GetConfigurationSuffixes(cmMakefile* makefile)
  165. {
  166. std::vector<std::string> suffixes;
  167. if (IsMultiConfig(makefile->GetGlobalGenerator())) {
  168. makefile->GetConfigurations(suffixes);
  169. for (std::vector<std::string>::iterator it = suffixes.begin();
  170. it != suffixes.end(); ++it) {
  171. it->insert(0, "_");
  172. }
  173. }
  174. if (suffixes.empty()) {
  175. suffixes.push_back("");
  176. }
  177. return suffixes;
  178. }
  179. static void AddDefinitionEscaped(cmMakefile* makefile, const char* key,
  180. const std::string& value)
  181. {
  182. makefile->AddDefinition(key,
  183. cmOutputConverter::EscapeForCMake(value).c_str());
  184. }
  185. static void AddDefinitionEscaped(cmMakefile* makefile, const char* key,
  186. const std::vector<std::string>& values)
  187. {
  188. makefile->AddDefinition(
  189. key, cmOutputConverter::EscapeForCMake(cmJoin(values, ";")).c_str());
  190. }
  191. static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName,
  192. cmQtAutoGeneratorCommon::GeneratorType genType)
  193. {
  194. cmSourceGroup* sourceGroup = CM_NULLPTR;
  195. // Acquire source group
  196. {
  197. const char* groupName = CM_NULLPTR;
  198. // Use generator specific group name
  199. switch (genType) {
  200. case cmQtAutoGeneratorCommon::MOC:
  201. groupName =
  202. makefile->GetState()->GetGlobalProperty("AUTOMOC_SOURCE_GROUP");
  203. break;
  204. case cmQtAutoGeneratorCommon::RCC:
  205. groupName =
  206. makefile->GetState()->GetGlobalProperty("AUTORCC_SOURCE_GROUP");
  207. break;
  208. default:
  209. break;
  210. }
  211. // Use default group name on demand
  212. if ((groupName == CM_NULLPTR) || (*groupName == 0)) {
  213. groupName =
  214. makefile->GetState()->GetGlobalProperty("AUTOGEN_SOURCE_GROUP");
  215. }
  216. // Generate a source group on demand
  217. if ((groupName != CM_NULLPTR) && (*groupName != 0)) {
  218. {
  219. const char* delimiter =
  220. makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
  221. if (delimiter == CM_NULLPTR) {
  222. delimiter = "\\";
  223. }
  224. std::vector<std::string> folders =
  225. cmSystemTools::tokenize(groupName, delimiter);
  226. sourceGroup = makefile->GetSourceGroup(folders);
  227. if (sourceGroup == CM_NULLPTR) {
  228. makefile->AddSourceGroup(folders);
  229. sourceGroup = makefile->GetSourceGroup(folders);
  230. }
  231. }
  232. if (sourceGroup == CM_NULLPTR) {
  233. cmSystemTools::Error(
  234. "Autogen: Could not create or find source group: ",
  235. cmQtAutoGeneratorCommon::Quoted(groupName).c_str());
  236. return false;
  237. }
  238. }
  239. }
  240. if (sourceGroup != CM_NULLPTR) {
  241. sourceGroup->AddGroupFile(fileName);
  242. }
  243. return true;
  244. }
  245. static void AddGeneratedSource(cmMakefile* makefile,
  246. const std::string& filename,
  247. cmQtAutoGeneratorCommon::GeneratorType genType)
  248. {
  249. cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true);
  250. gFile->SetProperty("GENERATED", "1");
  251. gFile->SetProperty("SKIP_AUTOGEN", "On");
  252. AddToSourceGroup(makefile, filename, genType);
  253. }
  254. static void AcquireScanFiles(cmGeneratorTarget const* target,
  255. std::vector<std::string>& mocUicSources,
  256. std::vector<std::string>& mocUicHeaders,
  257. std::vector<std::string>& mocSkipList,
  258. std::vector<std::string>& uicSkipList)
  259. {
  260. const bool mocTarget = target->GetPropertyAsBool("AUTOMOC");
  261. const bool uicTarget = target->GetPropertyAsBool("AUTOUIC");
  262. const cmPolicies::PolicyStatus CMP0071_status =
  263. target->Makefile->GetPolicyStatus(cmPolicies::CMP0071);
  264. std::vector<cmSourceFile*> srcFiles;
  265. target->GetConfigCommonSourceFiles(srcFiles);
  266. for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  267. fileIt != srcFiles.end(); ++fileIt) {
  268. cmSourceFile* sf = *fileIt;
  269. const cmSystemTools::FileFormat fileType =
  270. cmSystemTools::GetFileFormat(sf->GetExtension().c_str());
  271. if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) &&
  272. !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) {
  273. continue;
  274. }
  275. const std::string absFile =
  276. cmsys::SystemTools::GetRealPath(sf->GetFullPath());
  277. // Skip flags
  278. const bool skipAll = PropertyEnabled(sf, "SKIP_AUTOGEN");
  279. const bool mocSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOMOC");
  280. const bool uicSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOUIC");
  281. const bool accept = (mocTarget && !mocSkip) || (uicTarget && !uicSkip);
  282. // For GENERATED files check status of policy CMP0071
  283. if (accept && PropertyEnabled(sf, "GENERATED")) {
  284. bool policyAccept = false;
  285. switch (CMP0071_status) {
  286. case cmPolicies::WARN: {
  287. std::ostringstream ost;
  288. ost << cmPolicies::GetPolicyWarning(cmPolicies::CMP0071) << "\n";
  289. ost << "AUTOMOC/AUTOUIC: Ignoring GENERATED source file:\n";
  290. ost << " " << cmQtAutoGeneratorCommon::Quoted(absFile) << "\n";
  291. target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, ost.str());
  292. }
  293. CM_FALLTHROUGH;
  294. case cmPolicies::OLD:
  295. // Ignore GENERATED file
  296. break;
  297. case cmPolicies::REQUIRED_IF_USED:
  298. case cmPolicies::REQUIRED_ALWAYS:
  299. case cmPolicies::NEW:
  300. // Process GENERATED file
  301. policyAccept = true;
  302. break;
  303. }
  304. if (!policyAccept) {
  305. continue;
  306. }
  307. }
  308. // Add file name to skip lists.
  309. // Do this even when the file is not added to the sources/headers lists
  310. // because the file name may be extracted from an other file when
  311. // processing
  312. if (mocSkip) {
  313. mocSkipList.push_back(absFile);
  314. }
  315. if (uicSkip) {
  316. uicSkipList.push_back(absFile);
  317. }
  318. if (accept) {
  319. // Add file name to sources or headers list
  320. switch (fileType) {
  321. case cmSystemTools::CXX_FILE_FORMAT:
  322. mocUicSources.push_back(absFile);
  323. break;
  324. case cmSystemTools::HEADER_FILE_FORMAT:
  325. mocUicHeaders.push_back(absFile);
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. }
  332. }
  333. static void MocSetupAutoTarget(
  334. cmGeneratorTarget const* target, const std::string& autogenTargetName,
  335. std::string const& qtMajorVersion, std::string const& config,
  336. std::vector<std::string> const& configs,
  337. std::vector<std::string> const& mocSkipList,
  338. std::map<std::string, std::string>& configMocIncludes,
  339. std::map<std::string, std::string>& configMocDefines)
  340. {
  341. cmLocalGenerator* lg = target->GetLocalGenerator();
  342. cmMakefile* makefile = target->Target->GetMakefile();
  343. AddDefinitionEscaped(makefile, "_moc_options",
  344. GetSafeProperty(target, "AUTOMOC_MOC_OPTIONS"));
  345. AddDefinitionEscaped(makefile, "_moc_skip", mocSkipList);
  346. AddDefinitionEscaped(makefile, "_moc_relaxed_mode",
  347. makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE") ? "TRUE"
  348. : "FALSE");
  349. AddDefinitionEscaped(makefile, "_moc_depend_filters",
  350. GetSafeProperty(target, "AUTOMOC_DEPEND_FILTERS"));
  351. if (QtVersionGreaterOrEqual(
  352. qtMajorVersion, GetQtMinorVersion(target, qtMajorVersion), 5, 8)) {
  353. AddDefinitionEscaped(
  354. makefile, "_moc_predefs_cmd",
  355. makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND"));
  356. }
  357. // Moc includes and compile definitions
  358. {
  359. // Default settings
  360. std::string incs;
  361. std::string compileDefs;
  362. GetCompileDefinitionsAndDirectories(target, config, incs, compileDefs);
  363. AddDefinitionEscaped(makefile, "_moc_incs", incs);
  364. AddDefinitionEscaped(makefile, "_moc_compile_defs", compileDefs);
  365. // Configuration specific settings
  366. for (std::vector<std::string>::const_iterator li = configs.begin();
  367. li != configs.end(); ++li) {
  368. std::string configIncs;
  369. std::string configCompileDefs;
  370. GetCompileDefinitionsAndDirectories(target, *li, configIncs,
  371. configCompileDefs);
  372. if (configIncs != incs) {
  373. configMocIncludes[*li] = cmOutputConverter::EscapeForCMake(configIncs);
  374. }
  375. if (configCompileDefs != compileDefs) {
  376. configMocDefines[*li] =
  377. cmOutputConverter::EscapeForCMake(configCompileDefs);
  378. }
  379. }
  380. }
  381. // Moc executable
  382. {
  383. std::string err;
  384. const char* mocExec = CM_NULLPTR;
  385. if (qtMajorVersion == "5") {
  386. cmGeneratorTarget* qt5Moc = lg->FindGeneratorTargetToUse("Qt5::moc");
  387. if (qt5Moc != CM_NULLPTR) {
  388. mocExec = qt5Moc->ImportedGetLocation("");
  389. } else {
  390. err = "Qt5::moc target not found " + autogenTargetName;
  391. }
  392. } else if (qtMajorVersion == "4") {
  393. cmGeneratorTarget* qt4Moc = lg->FindGeneratorTargetToUse("Qt4::moc");
  394. if (qt4Moc != CM_NULLPTR) {
  395. mocExec = qt4Moc->ImportedGetLocation("");
  396. } else {
  397. err = "Qt4::moc target not found " + autogenTargetName;
  398. }
  399. } else {
  400. err = "The CMAKE_AUTOMOC feature supports only Qt 4 and Qt 5 ";
  401. err += autogenTargetName;
  402. }
  403. // Add definition or error
  404. if (err.empty()) {
  405. AddDefinitionEscaped(makefile, "_qt_moc_executable",
  406. mocExec ? mocExec : "");
  407. } else {
  408. cmSystemTools::Error(err.c_str());
  409. }
  410. }
  411. }
  412. static void UicGetOpts(cmGeneratorTarget const* target,
  413. const std::string& config, std::string& optString)
  414. {
  415. std::vector<std::string> opts;
  416. target->GetAutoUicOptions(opts, config);
  417. optString = cmJoin(opts, ";");
  418. }
  419. static void UicSetupAutoTarget(
  420. cmGeneratorTarget const* target, std::string const& qtMajorVersion,
  421. std::string const& config, std::vector<std::string> const& configs,
  422. std::vector<std::string> const& uicSkipList,
  423. std::map<std::string, std::string>& configUicOptions)
  424. {
  425. cmLocalGenerator* lg = target->GetLocalGenerator();
  426. cmMakefile* makefile = target->Target->GetMakefile();
  427. AddDefinitionEscaped(makefile, "_uic_skip", uicSkipList);
  428. // Uic search paths
  429. {
  430. std::vector<std::string> uicSearchPaths;
  431. cmSystemTools::ExpandListArgument(
  432. GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"), uicSearchPaths);
  433. const std::string srcDir = makefile->GetCurrentSourceDirectory();
  434. for (std::vector<std::string>::iterator it = uicSearchPaths.begin();
  435. it != uicSearchPaths.end(); ++it) {
  436. *it = cmSystemTools::CollapseFullPath(*it, srcDir);
  437. }
  438. AddDefinitionEscaped(makefile, "_uic_search_paths", uicSearchPaths);
  439. }
  440. // Uic target options
  441. {
  442. // Default settings
  443. std::string uicOpts;
  444. UicGetOpts(target, config, uicOpts);
  445. AddDefinitionEscaped(makefile, "_uic_target_options", uicOpts);
  446. // Configuration specific settings
  447. for (std::vector<std::string>::const_iterator li = configs.begin();
  448. li != configs.end(); ++li) {
  449. std::string configUicOpts;
  450. UicGetOpts(target, *li, configUicOpts);
  451. if (configUicOpts != uicOpts) {
  452. configUicOptions[*li] =
  453. cmOutputConverter::EscapeForCMake(configUicOpts);
  454. }
  455. }
  456. }
  457. // Uic files options
  458. {
  459. std::vector<std::string> uiFileFiles;
  460. std::vector<std::string> uiFileOptions;
  461. {
  462. std::set<std::string> skipped;
  463. skipped.insert(uicSkipList.begin(), uicSkipList.end());
  464. const std::vector<cmSourceFile*> uiFilesWithOptions =
  465. makefile->GetQtUiFilesWithOptions();
  466. for (std::vector<cmSourceFile*>::const_iterator fileIt =
  467. uiFilesWithOptions.begin();
  468. fileIt != uiFilesWithOptions.end(); ++fileIt) {
  469. cmSourceFile* sf = *fileIt;
  470. const std::string absFile =
  471. cmsys::SystemTools::GetRealPath(sf->GetFullPath());
  472. if (skipped.insert(absFile).second) {
  473. // The file wasn't skipped
  474. uiFileFiles.push_back(absFile);
  475. {
  476. std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
  477. cmSystemTools::ReplaceString(opts, ";",
  478. cmQtAutoGeneratorCommon::listSep);
  479. uiFileOptions.push_back(opts);
  480. }
  481. }
  482. }
  483. }
  484. AddDefinitionEscaped(makefile, "_qt_uic_options_files", uiFileFiles);
  485. AddDefinitionEscaped(makefile, "_qt_uic_options_options", uiFileOptions);
  486. }
  487. // Uic executable
  488. {
  489. std::string err;
  490. const char* uicExec = CM_NULLPTR;
  491. if (qtMajorVersion == "5") {
  492. cmGeneratorTarget* qt5Uic = lg->FindGeneratorTargetToUse("Qt5::uic");
  493. if (qt5Uic != CM_NULLPTR) {
  494. uicExec = qt5Uic->ImportedGetLocation("");
  495. } else {
  496. // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
  497. }
  498. } else if (qtMajorVersion == "4") {
  499. cmGeneratorTarget* qt4Uic = lg->FindGeneratorTargetToUse("Qt4::uic");
  500. if (qt4Uic != CM_NULLPTR) {
  501. uicExec = qt4Uic->ImportedGetLocation("");
  502. } else {
  503. err = "Qt4::uic target not found " + target->GetName();
  504. }
  505. } else {
  506. err = "The CMAKE_AUTOUIC feature supports only Qt 4 and Qt 5 ";
  507. err += target->GetName();
  508. }
  509. // Add definition or error
  510. if (err.empty()) {
  511. AddDefinitionEscaped(makefile, "_qt_uic_executable",
  512. uicExec ? uicExec : "");
  513. } else {
  514. cmSystemTools::Error(err.c_str());
  515. }
  516. }
  517. }
  518. static std::string RccGetExecutable(cmGeneratorTarget const* target,
  519. const std::string& qtMajorVersion)
  520. {
  521. std::string rccExec;
  522. cmLocalGenerator* lg = target->GetLocalGenerator();
  523. if (qtMajorVersion == "5") {
  524. cmGeneratorTarget* qt5Rcc = lg->FindGeneratorTargetToUse("Qt5::rcc");
  525. if (qt5Rcc != CM_NULLPTR) {
  526. rccExec = qt5Rcc->ImportedGetLocation("");
  527. } else {
  528. cmSystemTools::Error("Qt5::rcc target not found ",
  529. target->GetName().c_str());
  530. }
  531. } else if (qtMajorVersion == "4") {
  532. cmGeneratorTarget* qt4Rcc = lg->FindGeneratorTargetToUse("Qt4::rcc");
  533. if (qt4Rcc != CM_NULLPTR) {
  534. rccExec = qt4Rcc->ImportedGetLocation("");
  535. } else {
  536. cmSystemTools::Error("Qt4::rcc target not found ",
  537. target->GetName().c_str());
  538. }
  539. } else {
  540. cmSystemTools::Error(
  541. "The CMAKE_AUTORCC feature supports only Qt 4 and Qt 5 ",
  542. target->GetName().c_str());
  543. }
  544. return rccExec;
  545. }
  546. static void RccMergeOptions(std::vector<std::string>& opts,
  547. const std::vector<std::string>& fileOpts,
  548. bool isQt5)
  549. {
  550. static const char* valueOptions[] = { "name", "root", "compress",
  551. "threshold" };
  552. std::vector<std::string> extraOpts;
  553. for (std::vector<std::string>::const_iterator fit = fileOpts.begin();
  554. fit != fileOpts.end(); ++fit) {
  555. std::vector<std::string>::iterator existingIt =
  556. std::find(opts.begin(), opts.end(), *fit);
  557. if (existingIt != opts.end()) {
  558. const char* optName = fit->c_str();
  559. if (*optName == '-') {
  560. ++optName;
  561. if (isQt5 && *optName == '-') {
  562. ++optName;
  563. }
  564. }
  565. // Test if this is a value option and change the existing value
  566. if ((optName != fit->c_str()) &&
  567. std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
  568. cmStrCmp(optName)) != cmArrayEnd(valueOptions)) {
  569. const std::vector<std::string>::iterator existValueIt(existingIt + 1);
  570. const std::vector<std::string>::const_iterator fileValueIt(fit + 1);
  571. if ((existValueIt != opts.end()) && (fileValueIt != fileOpts.end())) {
  572. *existValueIt = *fileValueIt;
  573. ++fit;
  574. }
  575. }
  576. } else {
  577. extraOpts.push_back(*fit);
  578. }
  579. }
  580. opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
  581. }
  582. static void RccSetupAutoTarget(cmGeneratorTarget const* target,
  583. const std::string& qtMajorVersion)
  584. {
  585. cmMakefile* makefile = target->Target->GetMakefile();
  586. const bool qtMajorVersion5 = (qtMajorVersion == "5");
  587. const std::string rccCommand = RccGetExecutable(target, qtMajorVersion);
  588. std::vector<std::string> _rcc_files;
  589. std::vector<std::string> _rcc_inputs;
  590. std::vector<std::string> rccFileFiles;
  591. std::vector<std::string> rccFileOptions;
  592. std::vector<std::string> rccOptionsTarget;
  593. if (const char* opts = target->GetProperty("AUTORCC_OPTIONS")) {
  594. cmSystemTools::ExpandListArgument(opts, rccOptionsTarget);
  595. }
  596. std::vector<cmSourceFile*> srcFiles;
  597. target->GetConfigCommonSourceFiles(srcFiles);
  598. for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  599. fileIt != srcFiles.end(); ++fileIt) {
  600. cmSourceFile* sf = *fileIt;
  601. if ((sf->GetExtension() == "qrc") &&
  602. !PropertyEnabled(sf, "SKIP_AUTOGEN") &&
  603. !PropertyEnabled(sf, "SKIP_AUTORCC")) {
  604. const std::string absFile =
  605. cmsys::SystemTools::GetRealPath(sf->GetFullPath());
  606. // qrc file
  607. _rcc_files.push_back(absFile);
  608. // qrc file entries
  609. {
  610. std::string entriesList = "{";
  611. // Read input file list only for non generated .qrc files.
  612. if (!PropertyEnabled(sf, "GENERATED")) {
  613. std::string error;
  614. std::vector<std::string> files;
  615. if (cmQtAutoGeneratorCommon::RccListInputs(
  616. qtMajorVersion, rccCommand, absFile, files, &error)) {
  617. entriesList += cmJoin(files, cmQtAutoGeneratorCommon::listSep);
  618. } else {
  619. cmSystemTools::Error(error.c_str());
  620. }
  621. }
  622. entriesList += "}";
  623. _rcc_inputs.push_back(entriesList);
  624. }
  625. // rcc options for this qrc file
  626. {
  627. // Merged target and file options
  628. std::vector<std::string> rccOptions(rccOptionsTarget);
  629. if (const char* prop = sf->GetProperty("AUTORCC_OPTIONS")) {
  630. std::vector<std::string> optsVec;
  631. cmSystemTools::ExpandListArgument(prop, optsVec);
  632. RccMergeOptions(rccOptions, optsVec, qtMajorVersion5);
  633. }
  634. // Only store non empty options lists
  635. if (!rccOptions.empty()) {
  636. rccFileFiles.push_back(absFile);
  637. rccFileOptions.push_back(
  638. cmJoin(rccOptions, cmQtAutoGeneratorCommon::listSep));
  639. }
  640. }
  641. }
  642. }
  643. AddDefinitionEscaped(makefile, "_qt_rcc_executable", rccCommand);
  644. AddDefinitionEscaped(makefile, "_rcc_files", _rcc_files);
  645. AddDefinitionEscaped(makefile, "_rcc_inputs", _rcc_inputs);
  646. AddDefinitionEscaped(makefile, "_rcc_options_files", rccFileFiles);
  647. AddDefinitionEscaped(makefile, "_rcc_options_options", rccFileOptions);
  648. }
  649. void cmQtAutoGeneratorInitializer::InitializeAutogenSources(
  650. cmGeneratorTarget* target)
  651. {
  652. if (target->GetPropertyAsBool("AUTOMOC")) {
  653. cmMakefile* makefile = target->Target->GetMakefile();
  654. // Mocs compilation file
  655. const std::string mocsComp =
  656. GetAutogenTargetBuildDir(target) + "/mocs_compilation.cpp";
  657. AddGeneratedSource(makefile, mocsComp, cmQtAutoGeneratorCommon::MOC);
  658. target->AddSource(mocsComp);
  659. }
  660. }
  661. void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
  662. cmLocalGenerator* lg, cmGeneratorTarget* target)
  663. {
  664. cmMakefile* makefile = target->Target->GetMakefile();
  665. // Create a custom target for running generators at buildtime
  666. const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC");
  667. const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC");
  668. const bool rccEnabled = target->GetPropertyAsBool("AUTORCC");
  669. const bool multiConfig = IsMultiConfig(target->GetGlobalGenerator());
  670. const std::string autogenTargetName = GetAutogenTargetName(target);
  671. const std::string autogenBuildDir = GetAutogenTargetBuildDir(target);
  672. const std::string workingDirectory =
  673. cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory());
  674. const std::string qtMajorVersion = GetQtMajorVersion(target);
  675. const std::string rccCommand = RccGetExecutable(target, qtMajorVersion);
  676. const std::vector<std::string> suffixes = GetConfigurationSuffixes(makefile);
  677. std::set<std::string> autogenDependsSet;
  678. std::vector<std::string> autogenProvides;
  679. // Remove build directories on cleanup
  680. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
  681. autogenBuildDir.c_str(), false);
  682. // Remove old settings on cleanup
  683. {
  684. std::string base = GetAutogenTargetFilesDir(target);
  685. for (std::vector<std::string>::const_iterator it = suffixes.begin();
  686. it != suffixes.end(); ++it) {
  687. std::string fname = base + "/AutogenOldSettings" + *it + ".cmake";
  688. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fname.c_str(),
  689. false);
  690. }
  691. }
  692. // Compose command lines
  693. cmCustomCommandLines commandLines;
  694. {
  695. cmCustomCommandLine currentLine;
  696. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  697. currentLine.push_back("-E");
  698. currentLine.push_back("cmake_autogen");
  699. currentLine.push_back(GetAutogenTargetFilesDir(target));
  700. currentLine.push_back("$<CONFIGURATION>");
  701. commandLines.push_back(currentLine);
  702. }
  703. // Compose target comment
  704. std::string autogenComment;
  705. {
  706. std::vector<std::string> toolNames;
  707. if (mocEnabled) {
  708. toolNames.push_back("MOC");
  709. }
  710. if (uicEnabled) {
  711. toolNames.push_back("UIC");
  712. }
  713. if (rccEnabled) {
  714. toolNames.push_back("RCC");
  715. }
  716. std::string tools = toolNames[0];
  717. toolNames.erase(toolNames.begin());
  718. while (toolNames.size() > 1) {
  719. tools += ", " + toolNames[0];
  720. toolNames.erase(toolNames.begin());
  721. }
  722. if (toolNames.size() == 1) {
  723. tools += " and " + toolNames[0];
  724. }
  725. autogenComment = "Automatic " + tools + " for target " + target->GetName();
  726. }
  727. // Add moc compilation to generated files list
  728. if (mocEnabled) {
  729. const std::string mocsComp = autogenBuildDir + "/mocs_compilation.cpp";
  730. autogenProvides.push_back(mocsComp);
  731. }
  732. // Add autogen includes directory to the origin target INCLUDE_DIRECTORIES
  733. if (mocEnabled || uicEnabled) {
  734. std::string includeDir = autogenBuildDir + "/include";
  735. if (multiConfig) {
  736. includeDir += "_$<CONFIG>";
  737. }
  738. target->AddIncludeDirectory(includeDir, true);
  739. }
  740. #if defined(_WIN32) && !defined(__CYGWIN__)
  741. bool usePRE_BUILD = false;
  742. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  743. if (gg->GetName().find("Visual Studio") != std::string::npos) {
  744. // Under VS use a PRE_BUILD event instead of a separate target to
  745. // reduce the number of targets loaded into the IDE.
  746. // This also works around a VS 11 bug that may skip updating the target:
  747. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  748. usePRE_BUILD = true;
  749. }
  750. #endif
  751. // Initialize autogen target dependencies
  752. if (const char* deps = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) {
  753. std::vector<std::string> extraDepends;
  754. cmSystemTools::ExpandListArgument(deps, extraDepends);
  755. autogenDependsSet.insert(extraDepends.begin(), extraDepends.end());
  756. }
  757. // Add other target dependencies autogen dependencies
  758. {
  759. const std::set<std::string>& utils = target->Target->GetUtilities();
  760. for (std::set<std::string>::const_iterator it = utils.begin();
  761. it != utils.end(); ++it) {
  762. const std::string& targetName = *it;
  763. if (makefile->FindTargetToUse(targetName) != CM_NULLPTR) {
  764. autogenDependsSet.insert(targetName);
  765. }
  766. }
  767. }
  768. // Add link library targets to the autogen dependencies
  769. {
  770. const cmTarget::LinkLibraryVectorType& libVec =
  771. target->Target->GetOriginalLinkLibraries();
  772. for (cmTarget::LinkLibraryVectorType::const_iterator it = libVec.begin();
  773. it != libVec.end(); ++it) {
  774. const std::string& libName = it->first;
  775. if (makefile->FindTargetToUse(libName) != CM_NULLPTR) {
  776. autogenDependsSet.insert(libName);
  777. }
  778. }
  779. }
  780. {
  781. cmFilePathChecksum fpathCheckSum(makefile);
  782. // Iterate over all source files
  783. std::vector<cmSourceFile*> srcFiles;
  784. target->GetConfigCommonSourceFiles(srcFiles);
  785. for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  786. fileIt != srcFiles.end(); ++fileIt) {
  787. cmSourceFile* sf = *fileIt;
  788. if (!PropertyEnabled(sf, "SKIP_AUTOGEN")) {
  789. std::string const& ext = sf->GetExtension();
  790. // Add generated file that will be scanned by moc or uic to
  791. // the dependencies
  792. if (mocEnabled || uicEnabled) {
  793. const cmSystemTools::FileFormat fileType =
  794. cmSystemTools::GetFileFormat(ext.c_str());
  795. if ((fileType == cmSystemTools::CXX_FILE_FORMAT) ||
  796. (fileType == cmSystemTools::HEADER_FILE_FORMAT)) {
  797. if (PropertyEnabled(sf, "GENERATED")) {
  798. if ((mocEnabled && !PropertyEnabled(sf, "SKIP_AUTOMOC")) ||
  799. (uicEnabled && !PropertyEnabled(sf, "SKIP_AUTOUIC"))) {
  800. autogenDependsSet.insert(
  801. cmsys::SystemTools::GetRealPath(sf->GetFullPath()));
  802. #if defined(_WIN32) && !defined(__CYGWIN__)
  803. // Cannot use PRE_BUILD with generated files
  804. usePRE_BUILD = false;
  805. #endif
  806. }
  807. }
  808. }
  809. }
  810. // Process rcc enabled files
  811. if (rccEnabled && (ext == "qrc") &&
  812. !PropertyEnabled(sf, "SKIP_AUTORCC")) {
  813. const std::string absFile =
  814. cmsys::SystemTools::GetRealPath(sf->GetFullPath());
  815. // Compose rcc output file name
  816. {
  817. std::string rccBuildFile = autogenBuildDir + "/";
  818. rccBuildFile += fpathCheckSum.getPart(absFile);
  819. rccBuildFile += "/qrc_";
  820. rccBuildFile +=
  821. cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
  822. rccBuildFile += ".cpp";
  823. // Register rcc ouput file as generated
  824. AddGeneratedSource(makefile, rccBuildFile,
  825. cmQtAutoGeneratorCommon::RCC);
  826. // Add rcc output file to origin target sources
  827. target->AddSource(rccBuildFile);
  828. // Register rcc ouput file as generated by the _autogen target
  829. autogenProvides.push_back(rccBuildFile);
  830. }
  831. if (PropertyEnabled(sf, "GENERATED")) {
  832. // Add generated qrc file to the dependencies
  833. autogenDependsSet.insert(absFile);
  834. } else {
  835. // Run cmake again when .qrc file changes
  836. makefile->AddCMakeDependFile(absFile);
  837. // Add the qrc input files to the dependencies
  838. {
  839. std::string error;
  840. std::vector<std::string> extraDepends;
  841. if (cmQtAutoGeneratorCommon::RccListInputs(
  842. qtMajorVersion, rccCommand, absFile, extraDepends,
  843. &error)) {
  844. autogenDependsSet.insert(extraDepends.begin(),
  845. extraDepends.end());
  846. } else {
  847. cmSystemTools::Error(error.c_str());
  848. }
  849. }
  850. }
  851. #if defined(_WIN32) && !defined(__CYGWIN__)
  852. // Cannot use PRE_BUILD because the resource files themselves
  853. // may not be sources within the target so VS may not know the
  854. // target needs to re-build at all.
  855. usePRE_BUILD = false;
  856. #endif
  857. }
  858. }
  859. }
  860. }
  861. // cmGeneratorTarget::GetConfigCommonSourceFiles computes the target's
  862. // sources meta data cache. Clear it so that OBJECT library targets that
  863. // are AUTOGEN initialized after this target get their added
  864. // mocs_compilation.cpp source acknowledged by this target.
  865. target->ClearSourcesCache();
  866. // Convert std::set to std::vector
  867. const std::vector<std::string> autogenDepends(autogenDependsSet.begin(),
  868. autogenDependsSet.end());
  869. #if defined(_WIN32) && !defined(__CYGWIN__)
  870. if (usePRE_BUILD) {
  871. // If the autogen target depends on an other target don't use PRE_BUILD
  872. for (std::vector<std::string>::const_iterator it = autogenDepends.begin();
  873. it != autogenDepends.end(); ++it) {
  874. if (makefile->FindTargetToUse(*it) != CM_NULLPTR) {
  875. usePRE_BUILD = false;
  876. break;
  877. }
  878. }
  879. }
  880. if (usePRE_BUILD) {
  881. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  882. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  883. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  884. std::vector<std::string> no_output;
  885. cmCustomCommand cc(makefile, no_output, autogenProvides, autogenDepends,
  886. commandLines, autogenComment.c_str(),
  887. workingDirectory.c_str());
  888. cc.SetEscapeOldStyle(false);
  889. cc.SetEscapeAllowMakeVars(true);
  890. target->Target->AddPreBuildCommand(cc);
  891. } else
  892. #endif
  893. {
  894. cmTarget* autogenTarget = makefile->AddUtilityCommand(
  895. autogenTargetName, true, workingDirectory.c_str(),
  896. /*byproducts=*/autogenProvides, autogenDepends, commandLines, false,
  897. autogenComment.c_str());
  898. cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
  899. lg->AddGeneratorTarget(gt);
  900. // Set target folder
  901. const char* autogenFolder =
  902. makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  903. if (!autogenFolder) {
  904. autogenFolder =
  905. makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
  906. }
  907. if (autogenFolder && *autogenFolder) {
  908. autogenTarget->SetProperty("FOLDER", autogenFolder);
  909. } else {
  910. // inherit FOLDER property from target (#13688)
  911. utilCopyTargetProperty(gt->Target, target->Target, "FOLDER");
  912. }
  913. target->Target->AddUtility(autogenTargetName);
  914. }
  915. }
  916. void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
  917. cmGeneratorTarget const* target)
  918. {
  919. cmMakefile* makefile = target->Target->GetMakefile();
  920. // forget the variables added here afterwards again:
  921. cmMakefile::ScopePushPop varScope(makefile);
  922. static_cast<void>(varScope);
  923. // Get configurations
  924. std::string config;
  925. const std::vector<std::string> configs(GetConfigurations(makefile, &config));
  926. // Configurations settings buffers
  927. std::map<std::string, std::string> configSuffix;
  928. std::map<std::string, std::string> configMocIncludes;
  929. std::map<std::string, std::string> configMocDefines;
  930. std::map<std::string, std::string> configUicOptions;
  931. // Configuration suffix
  932. if (IsMultiConfig(target->GetGlobalGenerator())) {
  933. for (std::vector<std::string>::const_iterator it = configs.begin();
  934. it != configs.end(); ++it) {
  935. configSuffix[*it] = cmOutputConverter::EscapeForCMake("_" + *it);
  936. }
  937. }
  938. // Basic setup
  939. {
  940. const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC");
  941. const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC");
  942. const bool rccEnabled = target->GetPropertyAsBool("AUTORCC");
  943. const std::string autogenTargetName = GetAutogenTargetName(target);
  944. const std::string qtMajorVersion = GetQtMajorVersion(target);
  945. std::vector<std::string> sources;
  946. std::vector<std::string> headers;
  947. if (mocEnabled || uicEnabled || rccEnabled) {
  948. std::vector<std::string> mocSkipList;
  949. std::vector<std::string> uicSkipList;
  950. AcquireScanFiles(target, sources, headers, mocSkipList, uicSkipList);
  951. if (mocEnabled) {
  952. MocSetupAutoTarget(target, autogenTargetName, qtMajorVersion, config,
  953. configs, mocSkipList, configMocIncludes,
  954. configMocDefines);
  955. }
  956. if (uicEnabled) {
  957. UicSetupAutoTarget(target, qtMajorVersion, config, configs,
  958. uicSkipList, configUicOptions);
  959. }
  960. if (rccEnabled) {
  961. RccSetupAutoTarget(target, qtMajorVersion);
  962. }
  963. }
  964. AddDefinitionEscaped(makefile, "_autogen_build_dir",
  965. GetAutogenTargetBuildDir(target));
  966. AddDefinitionEscaped(makefile, "_qt_version_major", qtMajorVersion);
  967. AddDefinitionEscaped(makefile, "_sources", sources);
  968. AddDefinitionEscaped(makefile, "_headers", headers);
  969. }
  970. // Generate info file
  971. std::string infoFile = GetAutogenTargetFilesDir(target);
  972. infoFile += "/AutogenInfo.cmake";
  973. {
  974. std::string inf = cmSystemTools::GetCMakeRoot();
  975. inf += "/Modules/AutogenInfo.cmake.in";
  976. makefile->ConfigureFile(inf.c_str(), infoFile.c_str(), false, true, false);
  977. }
  978. // Append custom definitions to info file on demand
  979. if (!configSuffix.empty() || !configMocDefines.empty() ||
  980. !configMocIncludes.empty() || !configUicOptions.empty()) {
  981. // Ensure we have write permission in case .in was read-only.
  982. mode_t perm = 0;
  983. #if defined(_WIN32) && !defined(__CYGWIN__)
  984. mode_t mode_write = S_IWRITE;
  985. #else
  986. mode_t mode_write = S_IWUSR;
  987. #endif
  988. cmSystemTools::GetPermissions(infoFile, perm);
  989. if (!(perm & mode_write)) {
  990. cmSystemTools::SetPermissions(infoFile, perm | mode_write);
  991. }
  992. // Open and write file
  993. cmsys::ofstream ofs(infoFile.c_str(), std::ios::app);
  994. if (ofs) {
  995. ofs << "# Configuration specific options\n";
  996. for (std::map<std::string, std::string>::iterator
  997. it = configSuffix.begin(),
  998. end = configSuffix.end();
  999. it != end; ++it) {
  1000. ofs << "set(AM_CONFIG_SUFFIX_" << it->first << " " << it->second
  1001. << ")\n";
  1002. }
  1003. for (std::map<std::string, std::string>::iterator
  1004. it = configMocDefines.begin(),
  1005. end = configMocDefines.end();
  1006. it != end; ++it) {
  1007. ofs << "set(AM_MOC_DEFINITIONS_" << it->first << " " << it->second
  1008. << ")\n";
  1009. }
  1010. for (std::map<std::string, std::string>::iterator
  1011. it = configMocIncludes.begin(),
  1012. end = configMocIncludes.end();
  1013. it != end; ++it) {
  1014. ofs << "set(AM_MOC_INCLUDES_" << it->first << " " << it->second
  1015. << ")\n";
  1016. }
  1017. for (std::map<std::string, std::string>::iterator
  1018. it = configUicOptions.begin(),
  1019. end = configUicOptions.end();
  1020. it != end; ++it) {
  1021. ofs << "set(AM_UIC_TARGET_OPTIONS_" << it->first << " " << it->second
  1022. << ")\n";
  1023. }
  1024. } else {
  1025. // File open error
  1026. std::string error = "Internal CMake error when trying to open file: ";
  1027. error += cmQtAutoGeneratorCommon::Quoted(infoFile);
  1028. error += " for writing.";
  1029. cmSystemTools::Error(error.c_str());
  1030. }
  1031. }
  1032. }