1
0

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