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 "cmQtAutoGenInitializer.h"
7 #include <initializer_list>
10 #include <sstream> // for basic_ios, istringstream
12 #include <unordered_set>
16 #include <cm/algorithm>
17 #include <cm/iterator>
19 #include <cmext/algorithm>
20 #include <cmext/string_view>
22 #include <cm3p/json/value.h>
23 #include <cm3p/json/writer.h>
25 #include "cmsys/SystemInformation.hxx"
27 #include "cmAlgorithms.h"
28 #include "cmCustomCommand.h"
29 #include "cmCustomCommandLines.h"
30 #include "cmGeneratedFileStream.h"
31 #include "cmGeneratorExpression.h"
32 #include "cmGeneratorTarget.h"
33 #include "cmGlobalGenerator.h"
34 #include "cmLinkItem.h"
35 #include "cmListFileCache.h"
36 #include "cmLocalGenerator.h"
37 #include "cmMakefile.h"
38 #include "cmMessageType.h"
39 #include "cmPolicies.h"
40 #include "cmQtAutoGen.h"
41 #include "cmQtAutoGenGlobalInitializer.h"
42 #include "cmSourceFile.h"
43 #include "cmSourceFileLocationKind.h"
44 #include "cmSourceGroup.h"
46 #include "cmStateTypes.h"
47 #include "cmStringAlgorithms.h"
48 #include "cmSystemTools.h"
55 unsigned int GetParallelCPUCount()
57 static unsigned int count = 0;
58 // Detect only on the first call
60 cmsys::SystemInformation info;
63 cm::clamp(info.GetNumberOfPhysicalCPU(), 1u, cmQtAutoGen::ParallelMax);
68 std::string FileProjectRelativePath(cmMakefile* makefile,
69 std::string const& fileName)
73 std::string pSource = cmSystemTools::RelativePath(
74 makefile->GetCurrentSourceDirectory(), fileName);
75 std::string pBinary = cmSystemTools::RelativePath(
76 makefile->GetCurrentBinaryDirectory(), fileName);
77 if (pSource.size() < pBinary.size()) {
78 res = std::move(pSource);
79 } else if (pBinary.size() < fileName.size()) {
80 res = std::move(pBinary);
89 * Tests if targetDepend is a STATIC_LIBRARY and if any of its
90 * recursive STATIC_LIBRARY dependencies depends on targetOrigin
91 * (STATIC_LIBRARY cycle).
93 bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
94 cmGeneratorTarget const* targetDepend,
95 std::string const& config)
98 if ((targetOrigin->GetType() == cmStateEnums::STATIC_LIBRARY) &&
99 (targetDepend->GetType() == cmStateEnums::STATIC_LIBRARY)) {
100 std::set<cmGeneratorTarget const*> knownLibs;
101 std::deque<cmGeneratorTarget const*> testLibs;
103 // Insert initial static_library dependency
104 knownLibs.insert(targetDepend);
105 testLibs.push_back(targetDepend);
107 while (!testLibs.empty()) {
108 cmGeneratorTarget const* testTarget = testLibs.front();
109 testLibs.pop_front();
110 // Check if the test target is the origin target (cycle)
111 if (testTarget == targetOrigin) {
115 // Collect all static_library dependencies from the test target
116 cmLinkImplementationLibraries const* libs =
117 testTarget->GetLinkImplementationLibraries(
118 config, cmGeneratorTarget::LinkInterfaceFor::Link);
120 for (cmLinkItem const& item : libs->Libraries) {
121 cmGeneratorTarget const* depTarget = item.Target;
123 (depTarget->GetType() == cmStateEnums::STATIC_LIBRARY) &&
124 knownLibs.insert(depTarget).second) {
125 testLibs.push_back(depTarget);
134 /** Sanitizes file search paths. */
135 class SearchPathSanitizer
138 SearchPathSanitizer(cmMakefile* makefile)
139 : SourcePath_(makefile->GetCurrentSourceDirectory())
142 std::vector<std::string> operator()(
143 std::vector<std::string> const& paths) const;
146 std::string SourcePath_;
149 std::vector<std::string> SearchPathSanitizer::operator()(
150 std::vector<std::string> const& paths) const
152 std::vector<std::string> res;
153 res.reserve(paths.size());
154 for (std::string const& srcPath : paths) {
155 // Collapse relative paths
157 cmSystemTools::CollapseFullPath(srcPath, this->SourcePath_);
158 // Remove suffix slashes
159 while (cmHasSuffix(path, '/')) {
162 // Accept only non empty paths
164 res.emplace_back(std::move(path));
170 /** @brief Writes a CMake info file. */
175 void Set(std::string const& key, std::string const& value)
177 this->Value_[key] = value;
179 void SetConfig(std::string const& key,
180 cmQtAutoGenInitializer::ConfigString const& cfgStr);
181 void SetBool(std::string const& key, bool value)
183 this->Value_[key] = value;
185 void SetUInt(std::string const& key, unsigned int value)
187 this->Value_[key] = value;
191 template <typename CONT>
192 static bool MakeArray(Json::Value& jval, CONT const& container);
194 template <typename CONT>
195 static void MakeStringArray(Json::Value& jval, CONT const& container);
198 template <typename CONT>
199 void SetArray(std::string const& key, CONT const& container);
200 template <typename CONT>
202 std::string const& key,
203 cmQtAutoGenInitializer::ConfigStrings<CONT> const& cfgStr);
205 // -- Array of arrays
206 template <typename CONT, typename FUNC>
207 void SetArrayArray(std::string const& key, CONT const& container, FUNC func);
209 // -- Save to json file
210 bool Save(std::string const& filename);
216 void InfoWriter::SetConfig(std::string const& key,
217 cmQtAutoGenInitializer::ConfigString const& cfgStr)
219 this->Set(key, cfgStr.Default);
220 for (auto const& item : cfgStr.Config) {
221 this->Set(cmStrCat(key, '_', item.first), item.second);
225 template <typename CONT>
226 bool InfoWriter::MakeArray(Json::Value& jval, CONT const& container)
228 jval = Json::arrayValue;
229 std::size_t const listSize = cm::size(container);
233 jval.resize(static_cast<unsigned int>(listSize));
237 template <typename CONT>
238 void InfoWriter::MakeStringArray(Json::Value& jval, CONT const& container)
240 if (MakeArray(jval, container)) {
241 Json::ArrayIndex ii = 0;
242 for (std::string const& item : container) {
248 template <typename CONT>
249 void InfoWriter::SetArray(std::string const& key, CONT const& container)
251 MakeStringArray(this->Value_[key], container);
254 template <typename CONT, typename FUNC>
255 void InfoWriter::SetArrayArray(std::string const& key, CONT const& container,
258 Json::Value& jval = this->Value_[key];
259 if (MakeArray(jval, container)) {
260 Json::ArrayIndex ii = 0;
261 for (auto const& citem : container) {
262 Json::Value& aval = jval[ii++];
263 aval = Json::arrayValue;
269 template <typename CONT>
270 void InfoWriter::SetConfigArray(
271 std::string const& key,
272 cmQtAutoGenInitializer::ConfigStrings<CONT> const& cfgStr)
274 this->SetArray(key, cfgStr.Default);
275 for (auto const& item : cfgStr.Config) {
276 this->SetArray(cmStrCat(key, '_', item.first), item.second);
280 bool InfoWriter::Save(std::string const& filename)
282 cmGeneratedFileStream fileStream;
283 fileStream.SetCopyIfDifferent(true);
284 fileStream.Open(filename, false, true);
289 Json::StyledStreamWriter jsonWriter;
291 jsonWriter.write(fileStream, this->Value_);
296 return fileStream.Close();
299 void AddAutogenExecutableToDependencies(
300 cmQtAutoGenInitializer::GenVarsT const& genVars,
301 std::vector<std::string>& dependencies)
303 if (genVars.ExecutableTarget != nullptr) {
304 dependencies.push_back(genVars.ExecutableTarget->Target->GetName());
305 } else if (!genVars.Executable.empty()) {
306 dependencies.push_back(genVars.Executable);
310 } // End of unnamed namespace
312 cmQtAutoGenInitializer::cmQtAutoGenInitializer(
313 cmQtAutoGenGlobalInitializer* globalInitializer,
314 cmGeneratorTarget* genTarget, IntegerVersion const& qtVersion,
315 bool mocEnabled, bool uicEnabled, bool rccEnabled, bool globalAutogenTarget,
316 bool globalAutoRccTarget)
317 : GlobalInitializer(globalInitializer)
318 , GenTarget(genTarget)
319 , GlobalGen(genTarget->GetGlobalGenerator())
320 , LocalGen(genTarget->GetLocalGenerator())
321 , Makefile(genTarget->Makefile)
322 , PathCheckSum(genTarget->Makefile)
323 , QtVersion(qtVersion)
325 this->AutogenTarget.GlobalTarget = globalAutogenTarget;
326 this->Moc.Enabled = mocEnabled;
327 this->Uic.Enabled = uicEnabled;
328 this->Rcc.Enabled = rccEnabled;
329 this->Rcc.GlobalTarget = globalAutoRccTarget;
332 bool cmQtAutoGenInitializer::InitCustomTargets()
335 this->MultiConfig = this->GlobalGen->IsMultiConfig();
336 this->ConfigDefault = this->Makefile->GetDefaultConfiguration();
338 this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
343 this->Makefile->GetSafeDefinition("CMAKE_AUTOGEN_VERBOSE");
345 unsigned long iVerb = 0;
346 if (cmStrToULong(def, &iVerb)) {
348 this->Verbosity = static_cast<unsigned int>(iVerb);
350 // Non numeric verbosity
361 this->Makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
363 folder = this->Makefile->GetState()->GetGlobalProperty(
364 "AUTOGEN_TARGETS_FOLDER");
366 // Inherit FOLDER property from target (#13688)
368 folder = this->GenTarget->GetProperty("FOLDER");
371 this->TargetsFolder = *folder;
375 // Check status of policy CMP0071 regarding handling of GENERATED files
376 switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0071)) {
377 case cmPolicies::WARN:
378 // Ignore GENERATED files but warn
379 this->CMP0071Warn = true;
381 case cmPolicies::OLD:
382 // Ignore GENERATED files
384 case cmPolicies::REQUIRED_IF_USED:
385 case cmPolicies::REQUIRED_ALWAYS:
386 case cmPolicies::NEW:
387 // Process GENERATED files
388 this->CMP0071Accept = true;
392 // Check status of policy CMP0100 regarding handling of .hh headers
393 switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0100)) {
394 case cmPolicies::WARN:
395 // Ignore but .hh files but warn
396 this->CMP0100Warn = true;
398 case cmPolicies::OLD:
401 case cmPolicies::REQUIRED_IF_USED:
402 case cmPolicies::REQUIRED_ALWAYS:
403 case cmPolicies::NEW:
405 this->CMP0100Accept = true;
409 // Common directories
410 std::string relativeBuildDir;
412 // Collapsed current binary directory
413 std::string const cbd = cmSystemTools::CollapseFullPath(
414 std::string(), this->Makefile->GetCurrentBinaryDirectory());
417 this->Dir.Info = cmStrCat(cbd, "/CMakeFiles/", this->GenTarget->GetName(),
419 cmSystemTools::ConvertToUnixSlashes(this->Dir.Info);
422 this->Dir.Build = this->GenTarget->GetSafeProperty("AUTOGEN_BUILD_DIR");
423 if (this->Dir.Build.empty()) {
425 cmStrCat(cbd, '/', this->GenTarget->GetName(), "_autogen");
427 cmSystemTools::ConvertToUnixSlashes(this->Dir.Build);
428 this->Dir.RelativeBuild =
429 cmSystemTools::RelativePath(cbd, this->Dir.Build);
430 // Cleanup build directory
431 this->AddCleanFile(this->Dir.Build);
434 this->Dir.Work = cbd;
435 cmSystemTools::ConvertToUnixSlashes(this->Dir.Work);
438 this->ConfigFileNamesAndGenex(this->Dir.Include, this->Dir.IncludeGenExp,
439 cmStrCat(this->Dir.Build, "/include"), "");
442 // Moc, Uic and _autogen target settings
443 if (this->MocOrUicEnabled()) {
444 // Init moc specific settings
445 if (this->Moc.Enabled && !this->InitMoc()) {
449 // Init uic specific settings
450 if (this->Uic.Enabled && !this->InitUic()) {
454 // Autogen target name
455 this->AutogenTarget.Name =
456 cmStrCat(this->GenTarget->GetName(), "_autogen");
458 // Autogen target parallel processing
460 std::string const& prop =
461 this->GenTarget->GetSafeProperty("AUTOGEN_PARALLEL");
462 if (prop.empty() || (prop == "AUTO")) {
463 // Autodetect number of CPUs
464 this->AutogenTarget.Parallel = GetParallelCPUCount();
466 this->AutogenTarget.Parallel = 1;
470 // Autogen target info and settings files
473 this->AutogenTarget.InfoFile =
474 cmStrCat(this->Dir.Info, "/AutogenInfo.json");
476 // Used settings file
477 this->ConfigFileNames(this->AutogenTarget.SettingsFile,
478 cmStrCat(this->Dir.Info, "/AutogenUsed"), ".txt");
479 this->ConfigFileClean(this->AutogenTarget.SettingsFile);
482 this->ConfigFileNames(this->AutogenTarget.ParseCacheFile,
483 cmStrCat(this->Dir.Info, "/ParseCache"), ".txt");
484 this->ConfigFileClean(this->AutogenTarget.ParseCacheFile);
487 // Autogen target: Compute user defined dependencies
489 this->AutogenTarget.DependOrigin =
490 this->GenTarget->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
492 std::string const& deps =
493 this->GenTarget->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
495 for (std::string const& depName : cmExpandedList(deps)) {
496 // Allow target and file dependencies
497 auto* depTarget = this->Makefile->FindTargetToUse(depName);
499 this->AutogenTarget.DependTargets.insert(depTarget);
501 this->AutogenTarget.DependFiles.insert(depName);
507 if (this->Moc.Enabled) {
509 if (cmIsOn(this->GenTarget->GetProperty("AUTOMOC_PATH_PREFIX"))) {
510 this->Moc.PathPrefix = true;
513 // CMAKE_AUTOMOC_RELAXED_MODE
514 if (this->Makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE")) {
515 this->Moc.RelaxedMode = true;
516 this->Makefile->IssueMessage(
517 MessageType::AUTHOR_WARNING,
518 cmStrCat("AUTOMOC: CMAKE_AUTOMOC_RELAXED_MODE is "
519 "deprecated an will be removed in the future. Consider "
520 "disabling it and converting the target ",
521 this->GenTarget->GetName(), " to regular mode."));
525 cmExpandList(this->GenTarget->GetSafeProperty("AUTOMOC_MOC_OPTIONS"),
528 cmExpandList(this->GenTarget->GetSafeProperty("AUTOMOC_MACRO_NAMES"),
529 this->Moc.MacroNames);
530 this->Moc.MacroNames.erase(cmRemoveDuplicates(this->Moc.MacroNames),
531 this->Moc.MacroNames.end());
533 auto filterList = cmExpandedList(
534 this->GenTarget->GetSafeProperty("AUTOMOC_DEPEND_FILTERS"));
535 if ((filterList.size() % 2) != 0) {
536 cmSystemTools::Error(
537 cmStrCat("AutoMoc: AUTOMOC_DEPEND_FILTERS predefs size ",
538 filterList.size(), " is not a multiple of 2."));
541 this->Moc.DependFilters.reserve(1 + (filterList.size() / 2));
542 this->Moc.DependFilters.emplace_back(
544 "[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\("
545 "[^\\)]*FILE[ \t]*\"([^\"]+)\"");
546 for (std::size_t ii = 0; ii != filterList.size(); ii += 2) {
547 this->Moc.DependFilters.emplace_back(filterList[ii],
554 // Init rcc specific settings
555 if (this->Rcc.Enabled && !this->InitRcc()) {
559 // Add autogen include directory to the origin target INCLUDE_DIRECTORIES
560 if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) {
561 this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, true);
565 if (!this->InitScanFiles()) {
569 // Create autogen target
570 if (this->MocOrUicEnabled() && !this->InitAutogenTarget()) {
574 // Create rcc targets
575 if (this->Rcc.Enabled && !this->InitRccTargets()) {
582 bool cmQtAutoGenInitializer::InitMoc()
584 // Mocs compilation file
585 if (this->GlobalGen->IsXcode()) {
586 // XXX(xcode-per-cfg-src): Drop this Xcode-specific code path
587 // when the Xcode generator supports per-config sources.
588 this->Moc.CompilationFile.Default =
589 cmStrCat(this->Dir.Build, "/mocs_compilation.cpp");
590 this->Moc.CompilationFileGenex = this->Moc.CompilationFile.Default;
592 this->ConfigFileNamesAndGenex(
593 this->Moc.CompilationFile, this->Moc.CompilationFileGenex,
594 cmStrCat(this->Dir.Build, "/mocs_compilation"_s), ".cpp"_s);
598 if (this->GenTarget->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
599 (this->QtVersion >= IntegerVersion(5, 8))) {
601 this->Makefile->GetDefExpandList("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND",
602 this->Moc.PredefsCmd);
604 if (!this->Moc.PredefsCmd.empty()) {
605 this->ConfigFileNames(this->Moc.PredefsFile,
606 cmStrCat(this->Dir.Build, "/moc_predefs"), ".h");
612 SearchPathSanitizer sanitizer(this->Makefile);
614 [this, &sanitizer](std::string const& cfg) -> std::vector<std::string> {
615 // Get the include dirs for this target, without stripping the implicit
616 // include dirs off, see issue #13667.
617 std::vector<std::string> dirs;
618 bool const appendImplicit = (this->QtVersion.Major >= 5);
619 this->LocalGen->GetIncludeDirectoriesImplicit(
620 dirs, this->GenTarget, "CXX", cfg, false, appendImplicit);
621 return sanitizer(dirs);
624 // Default configuration include directories
625 this->Moc.Includes.Default = getDirs(this->ConfigDefault);
626 // Other configuration settings
627 if (this->MultiConfig) {
628 for (std::string const& cfg : this->ConfigsList) {
629 std::vector<std::string> dirs = getDirs(cfg);
630 if (dirs == this->Moc.Includes.Default) {
633 this->Moc.Includes.Config[cfg] = std::move(dirs);
638 // Moc compile definitions
640 auto getDefs = [this](std::string const& cfg) -> std::set<std::string> {
641 std::set<std::string> defines;
642 this->LocalGen->GetTargetDefines(this->GenTarget, cfg, "CXX", defines);
643 if (this->Moc.PredefsCmd.empty() &&
644 this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") ==
646 // Add WIN32 definition if we don't have a moc_predefs.h
647 defines.insert("WIN32");
652 // Default configuration defines
653 this->Moc.Defines.Default = getDefs(this->ConfigDefault);
654 // Other configuration defines
655 if (this->MultiConfig) {
656 for (std::string const& cfg : this->ConfigsList) {
657 std::set<std::string> defines = getDefs(cfg);
658 if (defines == this->Moc.Defines.Default) {
661 this->Moc.Defines.Config[cfg] = std::move(defines);
668 if (!this->GetQtExecutable(this->Moc, "moc", false)) {
671 // Let the _autogen target depend on the moc executable
672 if (this->Moc.ExecutableTarget) {
673 this->AutogenTarget.DependTargets.insert(
674 this->Moc.ExecutableTarget->Target);
681 bool cmQtAutoGenInitializer::InitUic()
685 std::string const& usp =
686 this->GenTarget->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
688 this->Uic.SearchPaths =
689 SearchPathSanitizer(this->Makefile)(cmExpandedList(usp));
692 // Uic target options
694 auto getOpts = [this](std::string const& cfg) -> std::vector<std::string> {
695 std::vector<std::string> opts;
696 this->GenTarget->GetAutoUicOptions(opts, cfg);
701 this->Uic.Options.Default = getOpts(this->ConfigDefault);
702 // Configuration specific options
703 if (this->MultiConfig) {
704 for (std::string const& cfg : this->ConfigsList) {
705 std::vector<std::string> options = getOpts(cfg);
706 if (options == this->Uic.Options.Default) {
709 this->Uic.Options.Config[cfg] = std::move(options);
716 if (!this->GetQtExecutable(this->Uic, "uic", true)) {
719 // Let the _autogen target depend on the uic executable
720 if (this->Uic.ExecutableTarget) {
721 this->AutogenTarget.DependTargets.insert(
722 this->Uic.ExecutableTarget->Target);
729 bool cmQtAutoGenInitializer::InitRcc()
733 if (!this->GetQtExecutable(this->Rcc, "rcc", false)) {
736 // Evaluate test output on demand
737 CompilerFeatures& features = *this->Rcc.ExecutableFeatures;
738 if (!features.Evaluated) {
739 // Look for list options
740 if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
741 if (features.HelpOutput.find("--list") != std::string::npos) {
742 features.ListOptions.emplace_back("--list");
743 } else if (features.HelpOutput.find("-list") != std::string::npos) {
744 features.ListOptions.emplace_back("-list");
747 // Evaluation finished
748 features.Evaluated = true;
755 bool cmQtAutoGenInitializer::InitScanFiles()
757 cmake const* cm = this->Makefile->GetCMakeInstance();
758 auto const& kw = this->GlobalInitializer->kw();
760 auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
761 std::vector<size_t> const& configs,
762 bool muIt) -> MUFileHandle {
763 MUFileHandle muf = cm::make_unique<MUFile>();
764 muf->FullPath = fullPath;
766 if (!configs.empty() && configs.size() != this->ConfigsList.size()) {
767 muf->Configs = configs;
769 muf->Generated = sf->GetIsGenerated();
770 bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
771 muf->SkipMoc = this->Moc.Enabled &&
772 (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOMOC));
773 muf->SkipUic = this->Uic.Enabled &&
774 (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
776 muf->MocIt = this->Moc.Enabled && !muf->SkipMoc;
777 muf->UicIt = this->Uic.Enabled && !muf->SkipUic;
782 auto addMUHeader = [this](MUFileHandle&& muf, cm::string_view extension) {
783 cmSourceFile* sf = muf->SF;
784 const bool muIt = (muf->MocIt || muf->UicIt);
785 if (this->CMP0100Accept || (extension != "hh")) {
787 if (muIt && muf->Generated) {
788 this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
790 this->AutogenTarget.Headers.emplace(sf, std::move(muf));
791 } else if (muIt && this->CMP0100Warn) {
792 // Store file for warning message
793 this->AutogenTarget.CMP0100HeadersWarn.push_back(sf);
797 auto addMUSource = [this](MUFileHandle&& muf) {
798 if ((muf->MocIt || muf->UicIt) && muf->Generated) {
799 this->AutogenTarget.FilesGenerated.emplace_back(muf.get());
801 this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf));
804 // Scan through target files
806 // Scan through target files
807 for (cmGeneratorTarget::AllConfigSource const& acs :
808 this->GenTarget->GetAllConfigSources()) {
809 std::string const& fullPath = acs.Source->GetFullPath();
810 std::string const& extLower =
811 cmSystemTools::LowerCase(acs.Source->GetExtension());
813 // Register files that will be scanned by moc or uic
814 if (this->MocOrUicEnabled()) {
815 if (cm->IsAHeaderExtension(extLower)) {
816 addMUHeader(makeMUFile(acs.Source, fullPath, acs.Configs, true),
818 } else if (cm->IsACLikeSourceExtension(extLower)) {
819 addMUSource(makeMUFile(acs.Source, fullPath, acs.Configs, true));
823 // Register rcc enabled files
824 if (this->Rcc.Enabled) {
825 if ((extLower == kw.qrc) &&
826 !acs.Source->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
827 !acs.Source->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
830 qrc.QrcFile = fullPath;
832 cmSystemTools::GetFilenameWithoutLastExtension(qrc.QrcFile);
833 qrc.Generated = acs.Source->GetIsGenerated();
836 std::string const& opts =
837 acs.Source->GetSafeProperty(kw.AUTORCC_OPTIONS);
839 cmExpandList(opts, qrc.Options);
842 this->Rcc.Qrcs.push_back(std::move(qrc));
847 // cmGeneratorTarget::GetAllConfigSources computes the target's
848 // sources meta data cache. Clear it so that OBJECT library targets that
849 // are AUTOGEN initialized after this target get their added
850 // mocs_compilation.cpp source acknowledged by this target.
851 this->GenTarget->ClearSourcesCache();
853 // For source files find additional headers and private headers
854 if (this->MocOrUicEnabled()) {
855 // Header search suffixes and extensions
856 static std::initializer_list<cm::string_view> const suffixes{ "", "_p" };
857 auto const& exts = cm->GetHeaderExtensions();
858 // Scan through sources
859 for (auto const& pair : this->AutogenTarget.Sources) {
860 MUFile const& muf = *pair.second;
861 if (muf.MocIt || muf.UicIt) {
862 // Search for the default header file and a private header
863 std::string const& srcFullPath = muf.SF->ResolveFullPath();
864 std::string basePath = cmStrCat(
865 cmQtAutoGen::SubDirPrefix(srcFullPath),
866 cmSystemTools::GetFilenameWithoutLastExtension(srcFullPath));
867 for (auto const& suffix : suffixes) {
868 std::string const suffixedPath = cmStrCat(basePath, suffix);
869 for (auto const& ext : exts) {
870 std::string fullPath = cmStrCat(suffixedPath, '.', ext);
872 auto constexpr locationKind = cmSourceFileLocationKind::Known;
874 this->Makefile->GetSource(fullPath, locationKind);
876 // Check if we know about this header already
877 if (cm::contains(this->AutogenTarget.Headers, sf)) {
880 // We only accept not-GENERATED files that do exist.
881 if (!sf->GetIsGenerated() &&
882 !cmSystemTools::FileExists(fullPath)) {
885 } else if (cmSystemTools::FileExists(fullPath)) {
886 // Create a new source file for the existing file
887 sf = this->Makefile->CreateSource(fullPath, false, locationKind);
891 auto eMuf = makeMUFile(sf, fullPath, muf.Configs, true);
892 // Only process moc/uic when the parent is processed as well
899 addMUHeader(std::move(eMuf), ext);
907 // Scan through all source files in the makefile to extract moc and uic
908 // parameters. Historically we support non target source file parameters.
909 // The reason is that their file names might be discovered from source files
910 // at generation time.
911 if (this->MocOrUicEnabled()) {
912 for (const auto& sf : this->Makefile->GetSourceFiles()) {
913 // sf->GetExtension() is only valid after sf->ResolveFullPath() ...
914 // Since we're iterating over source files that might be not in the
915 // target we need to check for path errors (not existing files).
916 std::string pathError;
917 std::string const& fullPath = sf->ResolveFullPath(&pathError);
918 if (!pathError.empty() || fullPath.empty()) {
921 std::string const& extLower =
922 cmSystemTools::LowerCase(sf->GetExtension());
924 if (cm->IsAHeaderExtension(extLower)) {
925 if (!cm::contains(this->AutogenTarget.Headers, sf.get())) {
926 auto muf = makeMUFile(sf.get(), fullPath, {}, false);
927 if (muf->SkipMoc || muf->SkipUic) {
928 addMUHeader(std::move(muf), extLower);
931 } else if (cm->IsACLikeSourceExtension(extLower)) {
932 if (!cm::contains(this->AutogenTarget.Sources, sf.get())) {
933 auto muf = makeMUFile(sf.get(), fullPath, {}, false);
934 if (muf->SkipMoc || muf->SkipUic) {
935 addMUSource(std::move(muf));
938 } else if (this->Uic.Enabled && (extLower == kw.ui)) {
940 bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
942 (skipAutogen || sf->GetPropertyAsBool(kw.SKIP_AUTOUIC));
944 // Check if the .ui file has uic options
945 std::string const uicOpts = sf->GetSafeProperty(kw.AUTOUIC_OPTIONS);
946 if (uicOpts.empty()) {
947 this->Uic.UiFilesNoOptions.emplace_back(fullPath);
949 this->Uic.UiFilesWithOptions.emplace_back(fullPath,
950 cmExpandedList(uicOpts));
953 auto uiHeaderRelativePath = cmSystemTools::RelativePath(
954 this->LocalGen->GetCurrentSourceDirectory(),
955 cmSystemTools::GetFilenamePath(fullPath));
957 // Avoid creating a path containing adjacent slashes
958 if (!uiHeaderRelativePath.empty() &&
959 uiHeaderRelativePath.back() != '/') {
960 uiHeaderRelativePath += '/';
963 auto uiHeaderFilePath = cmStrCat(
964 '/', uiHeaderRelativePath, "ui_"_s,
965 cmSystemTools::GetFilenameWithoutLastExtension(fullPath), ".h"_s);
967 ConfigString uiHeader;
968 std::string uiHeaderGenex;
969 this->ConfigFileNamesAndGenex(
970 uiHeader, uiHeaderGenex, cmStrCat(this->Dir.Build, "/include"_s),
973 this->Uic.UiHeaders.emplace_back(
974 std::make_pair(uiHeader, uiHeaderGenex));
976 // Register skipped .ui file
977 this->Uic.SkipUi.insert(fullPath);
983 // Process GENERATED sources and headers
984 if (this->MocOrUicEnabled() && !this->AutogenTarget.FilesGenerated.empty()) {
985 if (this->CMP0071Accept) {
986 // Let the autogen target depend on the GENERATED files
987 for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
988 this->AutogenTarget.DependFiles.insert(muf->FullPath);
990 } else if (this->CMP0071Warn) {
991 cm::string_view property;
992 if (this->Moc.Enabled && this->Uic.Enabled) {
993 property = "SKIP_AUTOGEN";
994 } else if (this->Moc.Enabled) {
995 property = "SKIP_AUTOMOC";
996 } else if (this->Uic.Enabled) {
997 property = "SKIP_AUTOUIC";
1000 for (MUFile* muf : this->AutogenTarget.FilesGenerated) {
1001 files += cmStrCat(" ", Quoted(muf->FullPath), '\n');
1003 this->Makefile->IssueMessage(
1004 MessageType::AUTHOR_WARNING,
1006 cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n',
1007 "For compatibility, CMake is excluding the GENERATED source "
1009 files, "from processing by ",
1010 cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
1011 ". If any of the files should be processed, set CMP0071 to NEW. "
1012 "If any of the files should not be processed, "
1013 "explicitly exclude them by setting the source file property ",
1014 property, ":\n set_property(SOURCE file.h PROPERTY ", property,
1019 // Generate CMP0100 warning
1020 if (this->MocOrUicEnabled() &&
1021 !this->AutogenTarget.CMP0100HeadersWarn.empty()) {
1022 cm::string_view property;
1023 if (this->Moc.Enabled && this->Uic.Enabled) {
1024 property = "SKIP_AUTOGEN";
1025 } else if (this->Moc.Enabled) {
1026 property = "SKIP_AUTOMOC";
1027 } else if (this->Uic.Enabled) {
1028 property = "SKIP_AUTOUIC";
1031 for (cmSourceFile* sf : this->AutogenTarget.CMP0100HeadersWarn) {
1032 files += cmStrCat(" ", Quoted(sf->GetFullPath()), '\n');
1034 this->Makefile->IssueMessage(
1035 MessageType::AUTHOR_WARNING,
1037 cmPolicies::GetPolicyWarning(cmPolicies::CMP0100), '\n',
1038 "For compatibility, CMake is excluding the header file(s):\n", files,
1039 "from processing by ",
1040 cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
1041 ". If any of the files should be processed, set CMP0100 to NEW. "
1042 "If any of the files should not be processed, "
1043 "explicitly exclude them by setting the source file property ",
1044 property, ":\n set_property(SOURCE file.hh PROPERTY ", property,
1048 // Process qrc files
1049 if (!this->Rcc.Qrcs.empty()) {
1050 const bool modernQt = (this->QtVersion.Major >= 5);
1051 // Target rcc options
1052 std::vector<std::string> optionsTarget =
1053 cmExpandedList(this->GenTarget->GetSafeProperty(kw.AUTORCC_OPTIONS));
1055 // Check if file name is unique
1056 for (Qrc& qrc : this->Rcc.Qrcs) {
1058 for (Qrc const& qrc2 : this->Rcc.Qrcs) {
1059 if ((&qrc != &qrc2) && (qrc.QrcName == qrc2.QrcName)) {
1065 // Path checksum and file names
1066 for (Qrc& qrc : this->Rcc.Qrcs) {
1068 qrc.QrcPathChecksum = this->PathCheckSum.getPart(qrc.QrcFile);
1070 qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum,
1071 "/qrc_", qrc.QrcName, ".cpp");
1072 std::string const base = cmStrCat(this->Dir.Info, "/AutoRcc_",
1073 qrc.QrcName, '_', qrc.QrcPathChecksum);
1074 qrc.LockFile = cmStrCat(base, "_Lock.lock");
1075 qrc.InfoFile = cmStrCat(base, "_Info.json");
1076 this->ConfigFileNames(qrc.SettingsFile, cmStrCat(base, "_Used"), ".txt");
1079 for (Qrc& qrc : this->Rcc.Qrcs) {
1081 std::vector<std::string> opts = optionsTarget;
1082 // Merge computed "-name XYZ" option
1084 std::string name = qrc.QrcName;
1085 // Replace '-' with '_'. The former is not valid for symbol names.
1086 std::replace(name.begin(), name.end(), '-', '_');
1088 name += cmStrCat('_', qrc.QrcPathChecksum);
1090 std::vector<std::string> nameOpts;
1091 nameOpts.emplace_back("-name");
1092 nameOpts.emplace_back(std::move(name));
1093 RccMergeOptions(opts, nameOpts, modernQt);
1095 // Merge file option
1096 RccMergeOptions(opts, qrc.Options, modernQt);
1097 qrc.Options = std::move(opts);
1100 for (Qrc& qrc : this->Rcc.Qrcs) {
1101 if (!qrc.Generated) {
1103 RccLister const lister(this->Rcc.Executable,
1104 this->Rcc.ExecutableFeatures->ListOptions);
1105 if (!lister.list(qrc.QrcFile, qrc.Resources, error)) {
1106 cmSystemTools::Error(error);
1116 bool cmQtAutoGenInitializer::InitAutogenTarget()
1118 // Register info file as generated by CMake
1119 this->Makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
1121 // Determine whether to use a depfile for the AUTOGEN target.
1122 const bool useNinjaDepfile = this->QtVersion >= IntegerVersion(5, 15) &&
1123 this->GlobalGen->GetName().find("Ninja") != std::string::npos;
1125 // Files provided by the autogen target
1126 std::vector<std::string> autogenByproducts;
1127 std::vector<std::string> timestampByproducts;
1128 if (this->Moc.Enabled) {
1129 this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true);
1130 if (useNinjaDepfile) {
1131 if (this->MultiConfig) {
1132 // Make all mocs_compilation_<CONFIG>.cpp files byproducts of the
1133 // ${target}_autogen/timestamp custom command.
1134 // We cannot just use Moc.CompilationFileGenex here, because that
1135 // custom command runs cmake_autogen for each configuration.
1136 for (const auto& p : this->Moc.CompilationFile.Config) {
1137 timestampByproducts.push_back(p.second);
1140 timestampByproducts.push_back(this->Moc.CompilationFileGenex);
1143 autogenByproducts.push_back(this->Moc.CompilationFileGenex);
1147 if (this->Uic.Enabled) {
1148 for (const auto& file : this->Uic.UiHeaders) {
1149 this->AddGeneratedSource(file.first, this->Uic);
1150 autogenByproducts.push_back(file.second);
1154 // Compose target comment
1155 std::string autogenComment;
1158 if (this->Moc.Enabled) {
1161 if (this->Uic.Enabled) {
1162 if (!tools.empty()) {
1167 autogenComment = cmStrCat("Automatic ", tools, " for target ",
1168 this->GenTarget->GetName());
1171 // Compose command lines
1172 // FIXME: Take advantage of our per-config mocs_compilation_$<CONFIG>.cpp
1173 // instead of fiddling with the include directories
1174 std::vector<std::string> configs;
1175 this->GlobalGen->GetQtAutoGenConfigs(configs);
1176 bool stdPipesUTF8 = true;
1177 cmCustomCommandLines commandLines;
1178 for (auto const& config : configs) {
1179 commandLines.push_back(cmMakeCommandLine(
1180 { cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
1181 this->AutogenTarget.InfoFile, config }));
1184 // Use PRE_BUILD on demand
1185 bool usePRE_BUILD = false;
1186 if (this->GlobalGen->GetName().find("Visual Studio") != std::string::npos) {
1187 // Under VS use a PRE_BUILD event instead of a separate target to
1188 // reduce the number of targets loaded into the IDE.
1189 // This also works around a VS 11 bug that may skip updating the target:
1190 // https://connect.microsoft.com/VisualStudio/feedback/details/769495
1191 usePRE_BUILD = true;
1193 // Disable PRE_BUILD in some cases
1195 // Cannot use PRE_BUILD with file depends
1196 if (!this->AutogenTarget.DependFiles.empty()) {
1197 usePRE_BUILD = false;
1199 // Cannot use PRE_BUILD when a global autogen target is in place
1200 if (this->AutogenTarget.GlobalTarget) {
1201 usePRE_BUILD = false;
1204 // Create the autogen target/command
1206 // Add additional autogen target dependencies to origin target
1207 for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
1208 this->GenTarget->Target->AddUtility(depTarget->GetName(), false,
1212 if (!this->Uic.UiFilesNoOptions.empty() ||
1213 !this->Uic.UiFilesWithOptions.empty()) {
1214 // Add a generated timestamp file
1215 ConfigString timestampFile;
1216 std::string timestampFileGenex;
1217 ConfigFileNamesAndGenex(timestampFile, timestampFileGenex,
1218 cmStrCat(this->Dir.Build, "/autouic"_s),
1220 this->AddGeneratedSource(timestampFile, this->Uic);
1222 // Add a step in the pre-build command to touch the timestamp file
1223 commandLines.push_back(
1224 cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E", "touch",
1225 timestampFileGenex }));
1227 // UIC needs to be re-run if any of the known UI files change or the
1228 // executable itself has been updated
1229 auto uicDependencies = this->Uic.UiFilesNoOptions;
1230 for (auto const& uiFile : this->Uic.UiFilesWithOptions) {
1231 uicDependencies.push_back(uiFile.first);
1233 AddAutogenExecutableToDependencies(this->Uic, uicDependencies);
1235 // Add a rule file to cause the target to build if a dependency has
1236 // changed, which will trigger the pre-build command to run autogen
1237 auto cc = cm::make_unique<cmCustomCommand>();
1238 cc->SetOutputs(timestampFileGenex);
1239 cc->SetDepends(uicDependencies);
1241 cc->SetWorkingDirectory(this->Dir.Work.c_str());
1242 cc->SetCMP0116Status(cmPolicies::NEW);
1243 cc->SetEscapeOldStyle(false);
1244 cc->SetStdPipesUTF8(stdPipesUTF8);
1245 this->LocalGen->AddCustomCommandToOutput(std::move(cc));
1248 // Add the pre-build command directly to bypass the OBJECT_LIBRARY
1249 // rejection in cmMakefile::AddCustomCommandToTarget because we know
1250 // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
1252 // PRE_BUILD does not support file dependencies!
1254 cc.SetByproducts(autogenByproducts);
1255 cc.SetCommandLines(commandLines);
1256 cc.SetComment(autogenComment.c_str());
1257 cc.SetBacktrace(this->Makefile->GetBacktrace());
1258 cc.SetWorkingDirectory(this->Dir.Work.c_str());
1259 cc.SetStdPipesUTF8(stdPipesUTF8);
1260 cc.SetEscapeOldStyle(false);
1261 cc.SetEscapeAllowMakeVars(true);
1262 this->GenTarget->Target->AddPreBuildCommand(std::move(cc));
1265 // Add link library target dependencies to the autogen target
1267 if (this->AutogenTarget.DependOrigin) {
1268 // add_dependencies/addUtility do not support generator expressions.
1269 // We depend only on the libraries found in all configs therefore.
1270 std::map<cmGeneratorTarget const*, std::size_t> commonTargets;
1271 for (std::string const& config : this->ConfigsList) {
1272 cmLinkImplementationLibraries const* libs =
1273 this->GenTarget->GetLinkImplementationLibraries(
1274 config, cmGeneratorTarget::LinkInterfaceFor::Link);
1276 for (cmLinkItem const& item : libs->Libraries) {
1277 cmGeneratorTarget const* libTarget = item.Target;
1279 !StaticLibraryCycle(this->GenTarget, libTarget, config)) {
1280 // Increment target config count
1281 commonTargets[libTarget]++;
1286 for (auto const& item : commonTargets) {
1287 if (item.second == this->ConfigsList.size()) {
1288 this->AutogenTarget.DependTargets.insert(item.first->Target);
1293 std::vector<std::string> dependencies(
1294 this->AutogenTarget.DependFiles.begin(),
1295 this->AutogenTarget.DependFiles.end());
1297 if (useNinjaDepfile) {
1298 // Create a custom command that generates a timestamp file and
1299 // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
1301 // Also create an additional '_autogen_timestamp_deps' that the custom
1302 // command will depend on. It will have no sources or commands to
1303 // execute, but it will have dependencies that would originally be
1304 // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will
1305 // serve as a list of order-only dependencies for the custom command,
1306 // without forcing the custom command to re-execute.
1308 // The dependency tree would then look like
1309 // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <-
1310 // '_autogen' target.
1311 const auto timestampTargetName =
1312 cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
1313 std::vector<std::string> timestampTargetProvides;
1314 cmCustomCommandLines timestampTargetCommandLines;
1316 // Add additional autogen target dependencies to
1317 // '_autogen_timestamp_deps'.
1318 for (const cmTarget* t : this->AutogenTarget.DependTargets) {
1319 std::string depname = t->GetName();
1320 if (t->IsImported()) {
1321 auto ttype = t->GetType();
1322 if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY ||
1323 ttype == cmStateEnums::TargetType::SHARED_LIBRARY ||
1324 ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) {
1325 depname = cmStrCat("$<TARGET_LINKER_FILE:", t->GetName(), ">");
1328 dependencies.push_back(depname);
1331 auto cc = cm::make_unique<cmCustomCommand>();
1332 cc->SetWorkingDirectory(this->Dir.Work.c_str());
1333 cc->SetByproducts(timestampTargetProvides);
1334 cc->SetDepends(dependencies);
1335 cc->SetCommandLines(timestampTargetCommandLines);
1336 cc->SetCMP0116Status(cmPolicies::NEW);
1337 cc->SetEscapeOldStyle(false);
1338 cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
1339 timestampTargetName, true, std::move(cc));
1340 this->LocalGen->AddGeneratorTarget(
1341 cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
1343 // Set FOLDER property on the timestamp target, so it appears in the
1344 // appropriate folder in an IDE or in the file api.
1345 if (!this->TargetsFolder.empty()) {
1346 timestampTarget->SetProperty("FOLDER", this->TargetsFolder);
1349 // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the
1350 // moc and uic executables (whichever are enabled).
1351 dependencies.clear();
1352 dependencies.push_back(timestampTargetName);
1354 AddAutogenExecutableToDependencies(this->Moc, dependencies);
1355 AddAutogenExecutableToDependencies(this->Uic, dependencies);
1357 // Create the custom command that outputs the timestamp file.
1358 const char timestampFileName[] = "timestamp";
1359 const std::string outputFile =
1360 cmStrCat(this->Dir.Build, "/", timestampFileName);
1361 this->AutogenTarget.DepFile = cmStrCat(this->Dir.Build, "/deps");
1362 this->AutogenTarget.DepFileRuleName =
1363 cmStrCat(this->Dir.RelativeBuild, "/", timestampFileName);
1364 commandLines.push_back(cmMakeCommandLine(
1365 { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
1367 this->AddGeneratedSource(outputFile, this->Moc);
1368 cc = cm::make_unique<cmCustomCommand>();
1369 cc->SetOutputs(outputFile);
1370 cc->SetByproducts(timestampByproducts);
1371 cc->SetDepends(dependencies);
1372 cc->SetCommandLines(commandLines);
1373 cc->SetComment(autogenComment.c_str());
1374 cc->SetWorkingDirectory(this->Dir.Work.c_str());
1375 cc->SetCMP0116Status(cmPolicies::NEW);
1376 cc->SetEscapeOldStyle(false);
1377 cc->SetDepfile(this->AutogenTarget.DepFile);
1378 cc->SetStdPipesUTF8(stdPipesUTF8);
1379 this->LocalGen->AddCustomCommandToOutput(std::move(cc));
1381 // Alter variables for the autogen target which now merely wraps the
1383 dependencies.clear();
1384 dependencies.push_back(outputFile);
1385 commandLines.clear();
1386 autogenComment.clear();
1389 // Create autogen target
1390 auto cc = cm::make_unique<cmCustomCommand>();
1391 cc->SetWorkingDirectory(this->Dir.Work.c_str());
1392 cc->SetByproducts(autogenByproducts);
1393 cc->SetDepends(dependencies);
1394 cc->SetCommandLines(commandLines);
1395 cc->SetCMP0116Status(cmPolicies::NEW);
1396 cc->SetEscapeOldStyle(false);
1397 cc->SetComment(autogenComment.c_str());
1398 cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand(
1399 this->AutogenTarget.Name, true, std::move(cc));
1400 // Create autogen generator target
1401 this->LocalGen->AddGeneratorTarget(
1402 cm::make_unique<cmGeneratorTarget>(autogenTarget, this->LocalGen));
1404 // Forward origin utilities to autogen target
1405 if (this->AutogenTarget.DependOrigin) {
1406 for (BT<std::pair<std::string, bool>> const& depName :
1407 this->GenTarget->GetUtilities()) {
1408 autogenTarget->AddUtility(depName.Value.first, false, this->Makefile);
1411 if (!useNinjaDepfile) {
1412 // Add additional autogen target dependencies to autogen target
1413 for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
1414 autogenTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
1418 // Set FOLDER property in autogen target
1419 if (!this->TargetsFolder.empty()) {
1420 autogenTarget->SetProperty("FOLDER", this->TargetsFolder);
1423 // Add autogen target to the origin target dependencies
1424 this->GenTarget->Target->AddUtility(this->AutogenTarget.Name, false,
1427 // Add autogen target to the global autogen target dependencies
1428 if (this->AutogenTarget.GlobalTarget) {
1429 this->GlobalInitializer->AddToGlobalAutoGen(this->LocalGen,
1430 this->AutogenTarget.Name);
1437 bool cmQtAutoGenInitializer::InitRccTargets()
1439 for (Qrc const& qrc : this->Rcc.Qrcs) {
1440 // Register info file as generated by CMake
1441 this->Makefile->AddCMakeOutputFile(qrc.InfoFile);
1442 // Register file at target
1444 cmSourceFile* sf = this->AddGeneratedSource(qrc.OutputFile, this->Rcc);
1445 sf->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "On");
1448 std::vector<std::string> ccOutput;
1449 ccOutput.push_back(qrc.OutputFile);
1451 std::vector<std::string> ccDepends;
1452 // Add the .qrc and info file to the custom command dependencies
1453 ccDepends.push_back(qrc.QrcFile);
1454 ccDepends.push_back(qrc.InfoFile);
1456 cmCustomCommandLines commandLines;
1457 if (this->MultiConfig) {
1458 // Build for all configurations
1459 for (std::string const& config : this->ConfigsList) {
1460 commandLines.push_back(
1461 cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
1462 "cmake_autorcc", qrc.InfoFile, config }));
1465 commandLines.push_back(
1466 cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
1467 "cmake_autorcc", qrc.InfoFile, "$<CONFIG>" }));
1469 std::string ccComment =
1470 cmStrCat("Automatic RCC for ",
1471 FileProjectRelativePath(this->Makefile, qrc.QrcFile));
1473 auto cc = cm::make_unique<cmCustomCommand>();
1474 cc->SetWorkingDirectory(this->Dir.Work.c_str());
1475 cc->SetCommandLines(commandLines);
1476 cc->SetCMP0116Status(cmPolicies::NEW);
1477 cc->SetComment(ccComment.c_str());
1478 cc->SetStdPipesUTF8(true);
1480 if (qrc.Generated || this->Rcc.GlobalTarget) {
1481 // Create custom rcc target
1484 ccName = cmStrCat(this->GenTarget->GetName(), "_arcc_", qrc.QrcName);
1486 ccName += cmStrCat('_', qrc.QrcPathChecksum);
1489 cc->SetByproducts(ccOutput);
1490 cc->SetDepends(ccDepends);
1491 cc->SetEscapeOldStyle(false);
1492 cmTarget* autoRccTarget =
1493 this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc));
1495 // Create autogen generator target
1496 this->LocalGen->AddGeneratorTarget(
1497 cm::make_unique<cmGeneratorTarget>(autoRccTarget, this->LocalGen));
1499 // Set FOLDER property in autogen target
1500 if (!this->TargetsFolder.empty()) {
1501 autoRccTarget->SetProperty("FOLDER", this->TargetsFolder);
1503 if (!this->Rcc.ExecutableTargetName.empty()) {
1504 autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, false,
1508 // Add autogen target to the origin target dependencies
1509 this->GenTarget->Target->AddUtility(ccName, false, this->Makefile);
1511 // Add autogen target to the global autogen target dependencies
1512 if (this->Rcc.GlobalTarget) {
1513 this->GlobalInitializer->AddToGlobalAutoRcc(this->LocalGen, ccName);
1516 // Create custom rcc command
1518 std::vector<std::string> ccByproducts;
1520 // Add the resource files to the dependencies
1521 for (std::string const& fileName : qrc.Resources) {
1522 // Add resource file to the custom command dependencies
1523 ccDepends.push_back(fileName);
1525 if (!this->Rcc.ExecutableTargetName.empty()) {
1526 ccDepends.push_back(this->Rcc.ExecutableTargetName);
1528 cc->SetOutputs(ccOutput);
1529 cc->SetByproducts(ccByproducts);
1530 cc->SetDepends(ccDepends);
1531 this->LocalGen->AddCustomCommandToOutput(std::move(cc));
1533 // Reconfigure when .qrc file changes
1534 this->Makefile->AddCMakeDependFile(qrc.QrcFile);
1541 bool cmQtAutoGenInitializer::SetupCustomTargets()
1543 // Create info directory on demand
1544 if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
1545 cmSystemTools::Error(cmStrCat("AutoGen: Could not create directory: ",
1546 Quoted(this->Dir.Info)));
1550 // Generate autogen target info file
1551 if (this->MocOrUicEnabled()) {
1552 // Write autogen target info files
1553 if (!this->SetupWriteAutogenInfo()) {
1558 // Write AUTORCC info files
1559 return !this->Rcc.Enabled || this->SetupWriteRccInfo();
1562 bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
1565 auto MfDef = [this](std::string const& key) {
1566 return this->Makefile->GetSafeDefinition(key);
1569 // Filtered headers and sources
1570 std::set<std::string> moc_skip;
1571 std::set<std::string> uic_skip;
1572 std::vector<MUFile const*> headers;
1573 std::vector<MUFile const*> sources;
1577 headers.reserve(this->AutogenTarget.Headers.size());
1578 for (auto const& pair : this->AutogenTarget.Headers) {
1579 MUFile const* const muf = pair.second.get();
1581 moc_skip.insert(muf->FullPath);
1584 uic_skip.insert(muf->FullPath);
1586 if (muf->Generated && !this->CMP0071Accept) {
1589 if (muf->MocIt || muf->UicIt) {
1590 headers.emplace_back(muf);
1593 std::sort(headers.begin(), headers.end(),
1594 [](MUFile const* a, MUFile const* b) {
1595 return (a->FullPath < b->FullPath);
1601 sources.reserve(this->AutogenTarget.Sources.size());
1602 for (auto const& pair : this->AutogenTarget.Sources) {
1603 MUFile const* const muf = pair.second.get();
1604 if (muf->Generated && !this->CMP0071Accept) {
1608 moc_skip.insert(muf->FullPath);
1611 uic_skip.insert(muf->FullPath);
1613 if (muf->MocIt || muf->UicIt) {
1614 sources.emplace_back(muf);
1617 std::sort(sources.begin(), sources.end(),
1618 [](MUFile const* a, MUFile const* b) {
1619 return (a->FullPath < b->FullPath);
1627 info.SetBool("MULTI_CONFIG", this->MultiConfig);
1628 info.SetUInt("PARALLEL", this->AutogenTarget.Parallel);
1629 info.SetUInt("VERBOSITY", this->Verbosity);
1632 info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
1633 info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
1634 info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
1635 info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
1636 info.Set("BUILD_DIR", this->Dir.Build);
1637 info.SetConfig("INCLUDE_DIR", this->Dir.Include);
1639 info.SetUInt("QT_VERSION_MAJOR", this->QtVersion.Major);
1640 info.SetUInt("QT_VERSION_MINOR", this->QtVersion.Minor);
1641 info.Set("QT_MOC_EXECUTABLE", this->Moc.Executable);
1642 info.Set("QT_UIC_EXECUTABLE", this->Uic.Executable);
1644 info.Set("CMAKE_EXECUTABLE", cmSystemTools::GetCMakeCommand());
1645 info.SetConfig("SETTINGS_FILE", this->AutogenTarget.SettingsFile);
1646 info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
1647 info.Set("DEP_FILE", this->AutogenTarget.DepFile);
1648 info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName);
1649 info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles());
1650 info.SetArray("HEADER_EXTENSIONS",
1651 this->Makefile->GetCMakeInstance()->GetHeaderExtensions());
1652 auto cfgArray = [this](std::vector<size_t> const& configs) -> Json::Value {
1654 if (!configs.empty()) {
1655 value = Json::arrayValue;
1656 for (size_t ci : configs) {
1657 value.append(this->ConfigsList[ci]);
1662 info.SetArrayArray("HEADERS", headers,
1663 [this, &cfgArray](Json::Value& jval, MUFile const* muf) {
1665 jval[0u] = muf->FullPath;
1666 jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm',
1667 muf->UicIt ? 'U' : 'u');
1668 jval[2u] = this->GetMocBuildPath(*muf);
1669 jval[3u] = cfgArray(muf->Configs);
1672 "SOURCES", sources, [&cfgArray](Json::Value& jval, MUFile const* muf) {
1674 jval[0u] = muf->FullPath;
1675 jval[1u] = cmStrCat(muf->MocIt ? 'M' : 'm', muf->UicIt ? 'U' : 'u');
1676 jval[2u] = cfgArray(muf->Configs);
1679 // Write moc settings
1680 if (this->Moc.Enabled) {
1681 info.SetArray("MOC_SKIP", moc_skip);
1682 info.SetConfigArray("MOC_DEFINITIONS", this->Moc.Defines);
1683 info.SetConfigArray("MOC_INCLUDES", this->Moc.Includes);
1684 info.SetArray("MOC_OPTIONS", this->Moc.Options);
1685 info.SetBool("MOC_RELAXED_MODE", this->Moc.RelaxedMode);
1686 info.SetBool("MOC_PATH_PREFIX", this->Moc.PathPrefix);
1687 info.SetArray("MOC_MACRO_NAMES", this->Moc.MacroNames);
1689 "MOC_DEPEND_FILTERS", this->Moc.DependFilters,
1690 [](Json::Value& jval, std::pair<std::string, std::string> const& pair) {
1692 jval[0u] = pair.first;
1693 jval[1u] = pair.second;
1695 info.SetConfig("MOC_COMPILATION_FILE", this->Moc.CompilationFile);
1696 info.SetArray("MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
1697 info.SetConfig("MOC_PREDEFS_FILE", this->Moc.PredefsFile);
1700 // Write uic settings
1701 if (this->Uic.Enabled) {
1702 // Add skipped .ui files
1703 uic_skip.insert(this->Uic.SkipUi.begin(), this->Uic.SkipUi.end());
1705 info.SetArray("UIC_SKIP", uic_skip);
1706 info.SetArrayArray("UIC_UI_FILES", this->Uic.UiFilesWithOptions,
1707 [](Json::Value& jval, UicT::UiFileT const& uiFile) {
1709 jval[0u] = uiFile.first;
1710 InfoWriter::MakeStringArray(jval[1u], uiFile.second);
1712 info.SetConfigArray("UIC_OPTIONS", this->Uic.Options);
1713 info.SetArray("UIC_SEARCH_PATHS", this->Uic.SearchPaths);
1716 info.Save(this->AutogenTarget.InfoFile);
1721 bool cmQtAutoGenInitializer::SetupWriteRccInfo()
1723 for (Qrc const& qrc : this->Rcc.Qrcs) {
1725 auto MfDef = [this](std::string const& key) {
1726 return this->Makefile->GetSafeDefinition(key);
1732 info.SetBool("MULTI_CONFIG", this->MultiConfig);
1733 info.SetUInt("VERBOSITY", this->Verbosity);
1736 info.Set("LOCK_FILE", qrc.LockFile);
1737 info.SetConfig("SETTINGS_FILE", qrc.SettingsFile);
1740 info.Set("CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
1741 info.Set("CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
1742 info.Set("CMAKE_CURRENT_SOURCE_DIR", MfDef("CMAKE_CURRENT_SOURCE_DIR"));
1743 info.Set("CMAKE_CURRENT_BINARY_DIR", MfDef("CMAKE_CURRENT_BINARY_DIR"));
1744 info.Set("BUILD_DIR", this->Dir.Build);
1745 info.SetConfig("INCLUDE_DIR", this->Dir.Include);
1748 info.Set("RCC_EXECUTABLE", this->Rcc.Executable);
1749 info.SetArray("RCC_LIST_OPTIONS",
1750 this->Rcc.ExecutableFeatures->ListOptions);
1753 info.Set("SOURCE", qrc.QrcFile);
1754 info.Set("OUTPUT_CHECKSUM", qrc.QrcPathChecksum);
1755 info.Set("OUTPUT_NAME", cmSystemTools::GetFilenameName(qrc.OutputFile));
1756 info.SetArray("OPTIONS", qrc.Options);
1757 info.SetArray("INPUTS", qrc.Resources);
1759 info.Save(qrc.InfoFile);
1765 cmSourceFile* cmQtAutoGenInitializer::RegisterGeneratedSource(
1766 std::string const& filename)
1768 cmSourceFile* gFile = this->Makefile->GetOrCreateSource(filename, true);
1769 gFile->MarkAsGenerated();
1770 gFile->SetProperty("SKIP_AUTOGEN", "1");
1774 cmSourceFile* cmQtAutoGenInitializer::AddGeneratedSource(
1775 std::string const& filename, GenVarsT const& genVars, bool prepend)
1777 // Register source at makefile
1778 cmSourceFile* gFile = this->RegisterGeneratedSource(filename);
1779 // Add source file to target
1780 this->GenTarget->AddSource(filename, prepend);
1782 // Add source file to source group
1783 this->AddToSourceGroup(filename, genVars.GenNameUpper);
1788 void cmQtAutoGenInitializer::AddGeneratedSource(ConfigString const& filename,
1789 GenVarsT const& genVars,
1792 // XXX(xcode-per-cfg-src): Drop the Xcode-specific part of the condition
1793 // when the Xcode generator supports per-config sources.
1794 if (!this->MultiConfig || this->GlobalGen->IsXcode()) {
1795 this->AddGeneratedSource(filename.Default, genVars, prepend);
1798 for (auto const& cfg : this->ConfigsList) {
1799 std::string const& filenameCfg = filename.Config.at(cfg);
1800 // Register source at makefile
1801 this->RegisterGeneratedSource(filenameCfg);
1802 // Add source file to target for this configuration.
1803 this->GenTarget->AddSource(
1804 cmStrCat("$<$<CONFIG:"_s, cfg, ">:"_s, filenameCfg, ">"_s), prepend);
1805 // Add source file to source group
1806 this->AddToSourceGroup(filenameCfg, genVars.GenNameUpper);
1810 void cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
1811 cm::string_view genNameUpper)
1813 cmSourceGroup* sourceGroup = nullptr;
1814 // Acquire source group
1816 std::string property;
1817 std::string groupName;
1819 // Prefer generator specific source group name
1820 std::initializer_list<std::string> const props{
1821 cmStrCat(genNameUpper, "_SOURCE_GROUP"), "AUTOGEN_SOURCE_GROUP"
1823 for (std::string const& prop : props) {
1824 cmValue propName = this->Makefile->GetState()->GetGlobalProperty(prop);
1825 if (cmNonempty(propName)) {
1826 groupName = *propName;
1832 // Generate a source group on demand
1833 if (!groupName.empty()) {
1834 sourceGroup = this->Makefile->GetOrCreateSourceGroup(groupName);
1836 cmSystemTools::Error(
1837 cmStrCat(genNameUpper, " error in ", property,
1838 ": Could not find or create the source group ",
1839 cmQtAutoGen::Quoted(groupName)));
1844 sourceGroup->AddGroupFile(fileName);
1848 void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
1850 this->GenTarget->Target->AppendProperty("ADDITIONAL_CLEAN_FILES", fileName,
1854 void cmQtAutoGenInitializer::ConfigFileNames(ConfigString& configString,
1855 cm::string_view prefix,
1856 cm::string_view suffix)
1858 configString.Default = cmStrCat(prefix, suffix);
1859 if (this->MultiConfig) {
1860 for (auto const& cfg : this->ConfigsList) {
1861 configString.Config[cfg] = cmStrCat(prefix, '_', cfg, suffix);
1866 void cmQtAutoGenInitializer::ConfigFileNamesAndGenex(
1867 ConfigString& configString, std::string& genex, cm::string_view const prefix,
1868 cm::string_view const suffix)
1870 this->ConfigFileNames(configString, prefix, suffix);
1871 if (this->MultiConfig) {
1872 genex = cmStrCat(prefix, "_$<CONFIG>"_s, suffix);
1874 genex = configString.Default;
1878 void cmQtAutoGenInitializer::ConfigFileClean(ConfigString& configString)
1880 this->AddCleanFile(configString.Default);
1881 if (this->MultiConfig) {
1882 for (auto const& pair : configString.Config) {
1883 this->AddCleanFile(pair.second);
1888 static cmQtAutoGen::IntegerVersion parseMocVersion(std::string str)
1890 cmQtAutoGen::IntegerVersion result;
1892 static const std::string prelude = "moc ";
1893 size_t pos = str.find(prelude);
1894 if (pos == std::string::npos) {
1898 str.erase(0, prelude.size() + pos);
1899 std::istringstream iss(str);
1902 if (!std::getline(iss, major, '.') || !std::getline(iss, minor, '.')) {
1906 result.Major = static_cast<unsigned int>(std::stoi(major));
1907 result.Minor = static_cast<unsigned int>(std::stoi(minor));
1911 static cmQtAutoGen::IntegerVersion GetMocVersion(
1912 const std::string& mocExecutablePath)
1914 std::string capturedStdOut;
1916 if (!cmSystemTools::RunSingleCommand({ mocExecutablePath, "--version" },
1917 &capturedStdOut, nullptr, &exitCode,
1918 nullptr, cmSystemTools::OUTPUT_NONE)) {
1922 if (exitCode != 0) {
1926 return parseMocVersion(capturedStdOut);
1929 static std::string FindMocExecutableFromMocTarget(cmMakefile* makefile,
1930 unsigned int qtMajorVersion)
1933 const std::string mocTargetName =
1934 "Qt" + std::to_string(qtMajorVersion) + "::moc";
1935 cmTarget* mocTarget = makefile->FindTargetToUse(mocTargetName);
1937 result = mocTarget->GetSafeProperty("IMPORTED_LOCATION");
1942 std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
1943 cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target,
1944 std::string mocExecutable)
1946 // Converts a char ptr to an unsigned int value
1947 auto toUInt = [](const char* const input) -> unsigned int {
1948 unsigned long tmp = 0;
1949 if (input && cmStrToULong(input, &tmp)) {
1950 return static_cast<unsigned int>(tmp);
1954 auto toUInt2 = [](cmValue input) -> unsigned int {
1955 unsigned long tmp = 0;
1956 if (input && cmStrToULong(*input, &tmp)) {
1957 return static_cast<unsigned int>(tmp);
1962 // Initialize return value to a default
1963 std::pair<IntegerVersion, unsigned int> res(
1965 toUInt(target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
1968 // Acquire known Qt versions
1969 std::vector<cmQtAutoGen::IntegerVersion> knownQtVersions;
1971 // Qt version variable prefixes
1972 static std::initializer_list<
1973 std::pair<cm::string_view, cm::string_view>> const keys{
1974 { "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
1975 { "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
1976 { "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
1979 knownQtVersions.reserve(keys.size() * 2);
1981 // Adds a version to the result (nullptr safe)
1982 auto addVersion = [&knownQtVersions, &toUInt2](cmValue major,
1984 cmQtAutoGen::IntegerVersion ver(toUInt2(major), toUInt2(minor));
1985 if (ver.Major != 0) {
1986 knownQtVersions.emplace_back(ver);
1990 // Read versions from variables
1991 for (auto const& keyPair : keys) {
1992 addVersion(target->Makefile->GetDefinition(std::string(keyPair.first)),
1993 target->Makefile->GetDefinition(std::string(keyPair.second)));
1996 // Read versions from directory properties
1997 for (auto const& keyPair : keys) {
1998 addVersion(target->Makefile->GetProperty(std::string(keyPair.first)),
1999 target->Makefile->GetProperty(std::string(keyPair.second)));
2003 // Evaluate known Qt versions
2004 if (!knownQtVersions.empty()) {
2005 if (res.second == 0) {
2006 // No specific version was requested by the target:
2007 // Use highest known Qt version.
2008 res.first = knownQtVersions.at(0);
2010 // Pick a version from the known versions:
2011 for (auto it : knownQtVersions) {
2012 if (it.Major == res.second) {
2020 if (res.first.Major == 0) {
2021 // We could not get the version number from variables or directory
2022 // properties. This might happen if the find_package call for Qt is wrapped
2023 // in a function. Try to find the moc executable path from the available
2024 // targets and call "moc --version" to get the Qt version.
2025 if (mocExecutable.empty()) {
2027 FindMocExecutableFromMocTarget(target->Makefile, res.second);
2029 if (!mocExecutable.empty()) {
2030 res.first = GetMocVersion(mocExecutable);
2037 std::string cmQtAutoGenInitializer::GetMocBuildPath(MUFile const& muf)
2044 std::string basePath =
2045 cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_",
2046 FileNameWithoutLastExtension(muf.FullPath));
2048 res = cmStrCat(basePath, ".cpp");
2049 if (this->Moc.EmittedBuildPaths.emplace(res).second) {
2053 // File name already emitted.
2054 // Try appending the header suffix to the base path.
2055 basePath = cmStrCat(basePath, '_', muf.SF->GetExtension());
2056 res = cmStrCat(basePath, ".cpp");
2057 if (this->Moc.EmittedBuildPaths.emplace(res).second) {
2061 // File name with header extension already emitted.
2062 // Try adding a number to the base path.
2063 constexpr std::size_t number_begin = 2;
2064 constexpr std::size_t number_end = 256;
2065 for (std::size_t ii = number_begin; ii != number_end; ++ii) {
2066 res = cmStrCat(basePath, '_', ii, ".cpp");
2067 if (this->Moc.EmittedBuildPaths.emplace(res).second) {
2072 // Output file name conflict (unlikely, but still...)
2073 cmSystemTools::Error(
2074 cmStrCat("moc output file name conflict for ", muf.FullPath));
2079 bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
2080 const std::string& executable,
2081 bool ignoreMissingTarget) const
2083 auto print_err = [this, &genVars](std::string const& err) {
2084 cmSystemTools::Error(cmStrCat(genVars.GenNameUpper, " for target ",
2085 this->GenTarget->GetName(), ": ", err));
2088 // Custom executable
2090 std::string const prop = cmStrCat(genVars.GenNameUpper, "_EXECUTABLE");
2091 std::string const& val = this->GenTarget->Target->GetSafeProperty(prop);
2093 // Evaluate generator expression
2095 cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
2096 cmGeneratorExpression ge(lfbt);
2097 std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
2098 genVars.Executable = cge->Evaluate(this->LocalGen, "");
2100 if (genVars.Executable.empty() && !ignoreMissingTarget) {
2101 print_err(prop + " evaluates to an empty value");
2105 // Create empty compiler features.
2106 genVars.ExecutableFeatures =
2107 std::make_shared<cmQtAutoGen::CompilerFeatures>();
2112 // Find executable target
2114 // Find executable target name
2115 cm::string_view prefix;
2116 if (this->QtVersion.Major == 4) {
2118 } else if (this->QtVersion.Major == 5) {
2120 } else if (this->QtVersion.Major == 6) {
2123 std::string const targetName = cmStrCat(prefix, executable);
2126 cmGeneratorTarget* genTarget =
2127 this->LocalGen->FindGeneratorTargetToUse(targetName);
2129 genVars.ExecutableTargetName = targetName;
2130 genVars.ExecutableTarget = genTarget;
2131 if (genTarget->IsImported()) {
2132 genVars.Executable = genTarget->ImportedGetLocation("");
2134 genVars.Executable = genTarget->GetLocation("");
2137 if (ignoreMissingTarget) {
2138 // Create empty compiler features.
2139 genVars.ExecutableFeatures =
2140 std::make_shared<cmQtAutoGen::CompilerFeatures>();
2143 print_err(cmStrCat("Could not find ", executable, " executable target ",
2149 // Get executable features
2152 genVars.ExecutableFeatures = this->GlobalInitializer->GetCompilerFeatures(
2153 executable, genVars.Executable, err);
2154 if (!genVars.ExecutableFeatures) {