cmQtAutoGeneratorInitializer.cxx 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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. // Mocs compilation file
  665. const std::string mocsComp =
  666. GetAutogenTargetBuildDir(target) + "/mocs_compilation.cpp";
  667. AddGeneratedSource(makefile, mocsComp, cmQtAutoGeneratorCommon::MOC);
  668. target->AddSource(mocsComp);
  669. }
  670. }
  671. void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
  672. cmLocalGenerator* lg, cmGeneratorTarget* target)
  673. {
  674. cmMakefile* makefile = target->Target->GetMakefile();
  675. // Create a custom target for running generators at buildtime
  676. const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC");
  677. const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC");
  678. const bool rccEnabled = target->GetPropertyAsBool("AUTORCC");
  679. const bool multiConfig = IsMultiConfig(target->GetGlobalGenerator());
  680. const std::string autogenTargetName = GetAutogenTargetName(target);
  681. const std::string autogenBuildDir = GetAutogenTargetBuildDir(target);
  682. const std::string workingDirectory =
  683. cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory());
  684. const std::string qtMajorVersion = GetQtMajorVersion(target);
  685. const std::string rccCommand = RccGetExecutable(target, qtMajorVersion);
  686. const std::vector<std::string> suffixes = GetConfigurationSuffixes(makefile);
  687. std::set<std::string> autogenDependsSet;
  688. std::vector<std::string> autogenProvides;
  689. // Remove build directories on cleanup
  690. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
  691. autogenBuildDir.c_str(), false);
  692. // Remove old settings on cleanup
  693. {
  694. std::string base = GetAutogenTargetFilesDir(target);
  695. for (std::vector<std::string>::const_iterator it = suffixes.begin();
  696. it != suffixes.end(); ++it) {
  697. std::string fname = base + "/AutogenOldSettings" + *it + ".cmake";
  698. makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fname.c_str(),
  699. false);
  700. }
  701. }
  702. // Compose command lines
  703. cmCustomCommandLines commandLines;
  704. {
  705. cmCustomCommandLine currentLine;
  706. currentLine.push_back(cmSystemTools::GetCMakeCommand());
  707. currentLine.push_back("-E");
  708. currentLine.push_back("cmake_autogen");
  709. currentLine.push_back(GetAutogenTargetFilesDir(target));
  710. currentLine.push_back("$<CONFIGURATION>");
  711. commandLines.push_back(currentLine);
  712. }
  713. // Compose target comment
  714. std::string autogenComment;
  715. {
  716. std::vector<std::string> toolNames;
  717. if (mocEnabled) {
  718. toolNames.push_back("MOC");
  719. }
  720. if (uicEnabled) {
  721. toolNames.push_back("UIC");
  722. }
  723. if (rccEnabled) {
  724. toolNames.push_back("RCC");
  725. }
  726. std::string tools = toolNames[0];
  727. toolNames.erase(toolNames.begin());
  728. while (toolNames.size() > 1) {
  729. tools += ", " + toolNames[0];
  730. toolNames.erase(toolNames.begin());
  731. }
  732. if (toolNames.size() == 1) {
  733. tools += " and " + toolNames[0];
  734. }
  735. autogenComment = "Automatic " + tools + " for target " + target->GetName();
  736. }
  737. // Add moc compilation to generated files list
  738. if (mocEnabled) {
  739. const std::string mocsComp = autogenBuildDir + "/mocs_compilation.cpp";
  740. autogenProvides.push_back(mocsComp);
  741. }
  742. // Add autogen includes directory to the origin target INCLUDE_DIRECTORIES
  743. if (mocEnabled || uicEnabled) {
  744. if (multiConfig) {
  745. target->AddIncludeDirectory(autogenBuildDir + "/include_$<CONFIG>",
  746. true);
  747. } else {
  748. target->AddIncludeDirectory(autogenBuildDir + "/include", true);
  749. }
  750. }
  751. #if defined(_WIN32) && !defined(__CYGWIN__)
  752. bool usePRE_BUILD = false;
  753. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  754. if (gg->GetName().find("Visual Studio") != std::string::npos) {
  755. // Under VS use a PRE_BUILD event instead of a separate target to
  756. // reduce the number of targets loaded into the IDE.
  757. // This also works around a VS 11 bug that may skip updating the target:
  758. // https://connect.microsoft.com/VisualStudio/feedback/details/769495
  759. usePRE_BUILD = true;
  760. }
  761. #endif
  762. // Initialize autogen target dependencies
  763. if (const char* deps = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) {
  764. std::vector<std::string> extraDepends;
  765. cmSystemTools::ExpandListArgument(deps, extraDepends);
  766. autogenDependsSet.insert(extraDepends.begin(), extraDepends.end());
  767. }
  768. // Add other target dependencies autogen dependencies
  769. {
  770. const std::set<std::string>& utils = target->Target->GetUtilities();
  771. for (std::set<std::string>::const_iterator it = utils.begin();
  772. it != utils.end(); ++it) {
  773. const std::string& targetName = *it;
  774. if (makefile->FindTargetToUse(targetName) != CM_NULLPTR) {
  775. autogenDependsSet.insert(targetName);
  776. }
  777. }
  778. }
  779. // Add link library targets to the autogen dependencies
  780. {
  781. const cmTarget::LinkLibraryVectorType& libVec =
  782. target->Target->GetOriginalLinkLibraries();
  783. for (cmTarget::LinkLibraryVectorType::const_iterator it = libVec.begin();
  784. it != libVec.end(); ++it) {
  785. const std::string& libName = it->first;
  786. if (makefile->FindTargetToUse(libName) != CM_NULLPTR) {
  787. autogenDependsSet.insert(libName);
  788. }
  789. }
  790. }
  791. {
  792. cmFilePathChecksum fpathCheckSum(makefile);
  793. // Iterate over all source files
  794. std::vector<cmSourceFile*> srcFiles;
  795. target->GetConfigCommonSourceFiles(srcFiles);
  796. for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
  797. fileIt != srcFiles.end(); ++fileIt) {
  798. cmSourceFile* sf = *fileIt;
  799. if (!PropertyEnabled(sf, "SKIP_AUTOGEN")) {
  800. std::string const& ext = sf->GetExtension();
  801. // Add generated file that will be scanned by moc or uic to
  802. // the dependencies
  803. if (mocEnabled || uicEnabled) {
  804. const cmSystemTools::FileFormat fileType =
  805. cmSystemTools::GetFileFormat(ext.c_str());
  806. if ((fileType == cmSystemTools::CXX_FILE_FORMAT) ||
  807. (fileType == cmSystemTools::HEADER_FILE_FORMAT)) {
  808. if (PropertyEnabled(sf, "GENERATED")) {
  809. if ((mocEnabled && !PropertyEnabled(sf, "SKIP_AUTOMOC")) ||
  810. (uicEnabled && !PropertyEnabled(sf, "SKIP_AUTOUIC"))) {
  811. autogenDependsSet.insert(
  812. cmsys::SystemTools::GetRealPath(sf->GetFullPath()));
  813. #if defined(_WIN32) && !defined(__CYGWIN__)
  814. // Cannot use PRE_BUILD with generated files
  815. usePRE_BUILD = false;
  816. #endif
  817. }
  818. }
  819. }
  820. }
  821. // Process rcc enabled files
  822. if (rccEnabled && (ext == "qrc") &&
  823. !PropertyEnabled(sf, "SKIP_AUTORCC")) {
  824. const std::string absFile =
  825. cmsys::SystemTools::GetRealPath(sf->GetFullPath());
  826. // Compose rcc output file name
  827. {
  828. std::string rccOutBase = autogenBuildDir + "/";
  829. rccOutBase += fpathCheckSum.getPart(absFile);
  830. rccOutBase += "/qrc_";
  831. rccOutBase +=
  832. cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
  833. // Register rcc ouput file as generated
  834. for (std::vector<std::string>::const_iterator it =
  835. suffixes.begin();
  836. it != suffixes.end(); ++it) {
  837. std::string rccOutCfg = rccOutBase;
  838. rccOutCfg += *it;
  839. rccOutCfg += ".cpp";
  840. AddGeneratedSource(makefile, rccOutCfg,
  841. cmQtAutoGeneratorCommon::RCC);
  842. autogenProvides.push_back(rccOutCfg);
  843. }
  844. // Add rcc output file to origin target sources
  845. if (multiConfig) {
  846. target->AddSource(rccOutBase + "_$<CONFIG>.cpp");
  847. } else {
  848. target->AddSource(rccOutBase + ".cpp");
  849. }
  850. }
  851. if (PropertyEnabled(sf, "GENERATED")) {
  852. // Add generated qrc file to the dependencies
  853. autogenDependsSet.insert(absFile);
  854. } else {
  855. // Run cmake again when .qrc file changes
  856. makefile->AddCMakeDependFile(absFile);
  857. // Add the qrc input files to the dependencies
  858. {
  859. std::string error;
  860. std::vector<std::string> extraDepends;
  861. if (cmQtAutoGeneratorCommon::RccListInputs(
  862. qtMajorVersion, rccCommand, absFile, extraDepends,
  863. &error)) {
  864. autogenDependsSet.insert(extraDepends.begin(),
  865. extraDepends.end());
  866. } else {
  867. cmSystemTools::Error(error.c_str());
  868. }
  869. }
  870. }
  871. #if defined(_WIN32) && !defined(__CYGWIN__)
  872. // Cannot use PRE_BUILD because the resource files themselves
  873. // may not be sources within the target so VS may not know the
  874. // target needs to re-build at all.
  875. usePRE_BUILD = false;
  876. #endif
  877. }
  878. }
  879. }
  880. }
  881. // Convert std::set to std::vector
  882. const std::vector<std::string> autogenDepends(autogenDependsSet.begin(),
  883. autogenDependsSet.end());
  884. #if defined(_WIN32) && !defined(__CYGWIN__)
  885. if (usePRE_BUILD) {
  886. // If the autogen target depends on an other target don't use PRE_BUILD
  887. for (std::vector<std::string>::const_iterator it = autogenDepends.begin();
  888. it != autogenDepends.end(); ++it) {
  889. if (makefile->FindTargetToUse(*it) != CM_NULLPTR) {
  890. usePRE_BUILD = false;
  891. break;
  892. }
  893. }
  894. }
  895. if (usePRE_BUILD) {
  896. // Add the pre-build command directly to bypass the OBJECT_LIBRARY
  897. // rejection in cmMakefile::AddCustomCommandToTarget because we know
  898. // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
  899. std::vector<std::string> no_output;
  900. cmCustomCommand cc(makefile, no_output, autogenProvides, autogenDepends,
  901. commandLines, autogenComment.c_str(),
  902. workingDirectory.c_str());
  903. cc.SetEscapeOldStyle(false);
  904. cc.SetEscapeAllowMakeVars(true);
  905. target->Target->AddPreBuildCommand(cc);
  906. } else
  907. #endif
  908. {
  909. cmTarget* autogenTarget = makefile->AddUtilityCommand(
  910. autogenTargetName, true, workingDirectory.c_str(),
  911. /*byproducts=*/autogenProvides, autogenDepends, commandLines, false,
  912. autogenComment.c_str());
  913. cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
  914. lg->AddGeneratorTarget(gt);
  915. // Set target folder
  916. const char* autogenFolder =
  917. makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
  918. if (!autogenFolder) {
  919. autogenFolder =
  920. makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
  921. }
  922. if (autogenFolder && *autogenFolder) {
  923. autogenTarget->SetProperty("FOLDER", autogenFolder);
  924. } else {
  925. // inherit FOLDER property from target (#13688)
  926. utilCopyTargetProperty(gt->Target, target->Target, "FOLDER");
  927. }
  928. target->Target->AddUtility(autogenTargetName);
  929. }
  930. }
  931. void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
  932. cmGeneratorTarget const* target)
  933. {
  934. cmMakefile* makefile = target->Target->GetMakefile();
  935. // forget the variables added here afterwards again:
  936. cmMakefile::ScopePushPop varScope(makefile);
  937. static_cast<void>(varScope);
  938. // Get configurations
  939. std::string config;
  940. const std::vector<std::string> configs(GetConfigurations(makefile, &config));
  941. // Configurations settings buffers
  942. std::map<std::string, std::string> configSuffix;
  943. std::map<std::string, std::string> configMocIncludes;
  944. std::map<std::string, std::string> configMocDefines;
  945. std::map<std::string, std::string> configUicOptions;
  946. // Configuration suffix
  947. if (IsMultiConfig(target->GetGlobalGenerator())) {
  948. for (std::vector<std::string>::const_iterator it = configs.begin();
  949. it != configs.end(); ++it) {
  950. configSuffix[*it] = "_" + *it;
  951. }
  952. }
  953. // Basic setup
  954. {
  955. const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC");
  956. const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC");
  957. const bool rccEnabled = target->GetPropertyAsBool("AUTORCC");
  958. const std::string autogenTargetName = GetAutogenTargetName(target);
  959. const std::string qtMajorVersion = GetQtMajorVersion(target);
  960. std::vector<std::string> sources;
  961. std::vector<std::string> headers;
  962. if (mocEnabled || uicEnabled || rccEnabled) {
  963. std::vector<std::string> mocSkipList;
  964. std::vector<std::string> uicSkipList;
  965. AcquireScanFiles(target, sources, headers, mocSkipList, uicSkipList);
  966. if (mocEnabled) {
  967. MocSetupAutoTarget(target, autogenTargetName, qtMajorVersion, config,
  968. configs, mocSkipList, configMocIncludes,
  969. configMocDefines);
  970. }
  971. if (uicEnabled) {
  972. UicSetupAutoTarget(target, qtMajorVersion, config, configs,
  973. uicSkipList, configUicOptions);
  974. }
  975. if (rccEnabled) {
  976. RccSetupAutoTarget(target, qtMajorVersion);
  977. }
  978. }
  979. AddDefinitionEscaped(makefile, "_autogen_build_dir",
  980. GetAutogenTargetBuildDir(target));
  981. AddDefinitionEscaped(makefile, "_qt_version_major", qtMajorVersion);
  982. AddDefinitionEscaped(makefile, "_sources", sources);
  983. AddDefinitionEscaped(makefile, "_headers", headers);
  984. }
  985. // Generate info file
  986. std::string infoFile = GetAutogenTargetFilesDir(target);
  987. infoFile += "/AutogenInfo.cmake";
  988. {
  989. std::string inf = cmSystemTools::GetCMakeRoot();
  990. inf += "/Modules/AutogenInfo.cmake.in";
  991. makefile->ConfigureFile(inf.c_str(), infoFile.c_str(), false, true, false);
  992. }
  993. // Append custom definitions to info file on demand
  994. if (!configSuffix.empty() || !configMocDefines.empty() ||
  995. !configMocIncludes.empty() || !configUicOptions.empty()) {
  996. // Ensure we have write permission in case .in was read-only.
  997. mode_t perm = 0;
  998. #if defined(_WIN32) && !defined(__CYGWIN__)
  999. mode_t mode_write = S_IWRITE;
  1000. #else
  1001. mode_t mode_write = S_IWUSR;
  1002. #endif
  1003. cmSystemTools::GetPermissions(infoFile, perm);
  1004. if (!(perm & mode_write)) {
  1005. cmSystemTools::SetPermissions(infoFile, perm | mode_write);
  1006. }
  1007. // Open and write file
  1008. cmsys::ofstream ofs(infoFile.c_str(), std::ios::app);
  1009. if (ofs) {
  1010. ofs << "# Configuration specific options\n";
  1011. for (std::map<std::string, std::string>::iterator
  1012. it = configSuffix.begin(),
  1013. end = configSuffix.end();
  1014. it != end; ++it) {
  1015. ofs << "set(AM_CONFIG_SUFFIX_" << it->first << " " << it->second
  1016. << ")\n";
  1017. }
  1018. for (std::map<std::string, std::string>::iterator
  1019. it = configMocDefines.begin(),
  1020. end = configMocDefines.end();
  1021. it != end; ++it) {
  1022. ofs << "set(AM_MOC_DEFINITIONS_" << it->first << " " << it->second
  1023. << ")\n";
  1024. }
  1025. for (std::map<std::string, std::string>::iterator
  1026. it = configMocIncludes.begin(),
  1027. end = configMocIncludes.end();
  1028. it != end; ++it) {
  1029. ofs << "set(AM_MOC_INCLUDES_" << it->first << " " << it->second
  1030. << ")\n";
  1031. }
  1032. for (std::map<std::string, std::string>::iterator
  1033. it = configUicOptions.begin(),
  1034. end = configUicOptions.end();
  1035. it != end; ++it) {
  1036. ofs << "set(AM_UIC_TARGET_OPTIONS_" << it->first << " " << it->second
  1037. << ")\n";
  1038. }
  1039. } else {
  1040. // File open error
  1041. std::string error = "Internal CMake error when trying to open file: ";
  1042. error += cmQtAutoGeneratorCommon::Quoted(infoFile);
  1043. error += " for writing.";
  1044. cmSystemTools::Error(error.c_str());
  1045. }
  1046. }
  1047. }