cmQtAutoGeneratorInitializer.cxx 39 KB

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