cmQtAutoGeneratorInitializer.cxx 39 KB

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