1
0

cmCommonTargetGenerator.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 "cmCommonTargetGenerator.h"
  4. #include <algorithm>
  5. #include <sstream>
  6. #include <type_traits>
  7. #include <utility>
  8. #include <cm/string_view>
  9. #include <cmext/string_view>
  10. #include "cmComputeLinkInformation.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmGeneratorExpressionDAGChecker.h"
  13. #include "cmGeneratorTarget.h"
  14. #include "cmGlobalCommonGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmList.h"
  17. #include "cmLocalCommonGenerator.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmMakefile.h"
  20. #include "cmMessageType.h"
  21. #include "cmOutputConverter.h"
  22. #include "cmRange.h"
  23. #include "cmSourceFile.h"
  24. #include "cmState.h"
  25. #include "cmStateTypes.h"
  26. #include "cmStringAlgorithms.h"
  27. #include "cmSystemTools.h"
  28. #include "cmValue.h"
  29. cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
  30. : GeneratorTarget(gt)
  31. , Makefile(gt->Makefile)
  32. , LocalCommonGenerator(
  33. static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
  34. , GlobalCommonGenerator(static_cast<cmGlobalCommonGenerator*>(
  35. gt->LocalGenerator->GetGlobalGenerator()))
  36. , ConfigNames(this->LocalCommonGenerator->GetConfigNames())
  37. {
  38. }
  39. cmCommonTargetGenerator::~cmCommonTargetGenerator() = default;
  40. std::vector<std::string> const& cmCommonTargetGenerator::GetConfigNames() const
  41. {
  42. return this->ConfigNames;
  43. }
  44. cmValue cmCommonTargetGenerator::GetFeature(const std::string& feature,
  45. const std::string& config)
  46. {
  47. return this->GeneratorTarget->GetFeature(feature, config);
  48. }
  49. void cmCommonTargetGenerator::AppendFortranFormatFlags(
  50. std::string& flags, cmSourceFile const& source)
  51. {
  52. const std::string srcfmt = source.GetSafeProperty("Fortran_FORMAT");
  53. cmOutputConverter::FortranFormat format =
  54. cmOutputConverter::GetFortranFormat(srcfmt);
  55. if (format == cmOutputConverter::FortranFormatNone) {
  56. std::string const& tgtfmt =
  57. this->GeneratorTarget->GetSafeProperty("Fortran_FORMAT");
  58. format = cmOutputConverter::GetFortranFormat(tgtfmt);
  59. }
  60. const char* var = nullptr;
  61. switch (format) {
  62. case cmOutputConverter::FortranFormatFixed:
  63. var = "CMAKE_Fortran_FORMAT_FIXED_FLAG";
  64. break;
  65. case cmOutputConverter::FortranFormatFree:
  66. var = "CMAKE_Fortran_FORMAT_FREE_FLAG";
  67. break;
  68. default:
  69. break;
  70. }
  71. if (var) {
  72. this->LocalCommonGenerator->AppendFlags(
  73. flags, this->Makefile->GetSafeDefinition(var));
  74. }
  75. }
  76. void cmCommonTargetGenerator::AppendFortranPreprocessFlags(
  77. std::string& flags, cmSourceFile const& source,
  78. PreprocessFlagsRequired requires_pp)
  79. {
  80. const std::string srcpp = source.GetSafeProperty("Fortran_PREPROCESS");
  81. cmOutputConverter::FortranPreprocess preprocess =
  82. cmOutputConverter::GetFortranPreprocess(srcpp);
  83. if (preprocess == cmOutputConverter::FortranPreprocess::Unset) {
  84. std::string const& tgtpp =
  85. this->GeneratorTarget->GetSafeProperty("Fortran_PREPROCESS");
  86. preprocess = cmOutputConverter::GetFortranPreprocess(tgtpp);
  87. }
  88. const char* var = nullptr;
  89. switch (preprocess) {
  90. case cmOutputConverter::FortranPreprocess::Needed:
  91. if (requires_pp == PreprocessFlagsRequired::YES) {
  92. var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON";
  93. }
  94. break;
  95. case cmOutputConverter::FortranPreprocess::NotNeeded:
  96. var = "CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF";
  97. break;
  98. default:
  99. break;
  100. }
  101. if (var) {
  102. this->LocalCommonGenerator->AppendCompileOptions(
  103. flags, this->Makefile->GetSafeDefinition(var));
  104. }
  105. }
  106. std::string cmCommonTargetGenerator::GetFlags(const std::string& l,
  107. const std::string& config,
  108. const std::string& arch)
  109. {
  110. const std::string key = config + arch;
  111. auto i = this->Configs[key].FlagsByLanguage.find(l);
  112. if (i == this->Configs[key].FlagsByLanguage.end()) {
  113. std::string flags;
  114. this->LocalCommonGenerator->GetTargetCompileFlags(this->GeneratorTarget,
  115. config, l, flags, arch);
  116. ByLanguageMap::value_type entry(l, flags);
  117. i = this->Configs[key].FlagsByLanguage.insert(entry).first;
  118. }
  119. return i->second;
  120. }
  121. std::string cmCommonTargetGenerator::GetDefines(const std::string& l,
  122. const std::string& config)
  123. {
  124. auto i = this->Configs[config].DefinesByLanguage.find(l);
  125. if (i == this->Configs[config].DefinesByLanguage.end()) {
  126. std::set<std::string> defines;
  127. this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget, config,
  128. l, defines);
  129. std::string definesString;
  130. this->LocalCommonGenerator->JoinDefines(defines, definesString, l);
  131. ByLanguageMap::value_type entry(l, definesString);
  132. i = this->Configs[config].DefinesByLanguage.insert(entry).first;
  133. }
  134. return i->second;
  135. }
  136. std::string cmCommonTargetGenerator::GetIncludes(std::string const& l,
  137. const std::string& config)
  138. {
  139. auto i = this->Configs[config].IncludesByLanguage.find(l);
  140. if (i == this->Configs[config].IncludesByLanguage.end()) {
  141. std::string includes;
  142. this->AddIncludeFlags(includes, l, config);
  143. ByLanguageMap::value_type entry(l, includes);
  144. i = this->Configs[config].IncludesByLanguage.insert(entry).first;
  145. }
  146. return i->second;
  147. }
  148. cmCommonTargetGenerator::LinkedTargetDirs
  149. cmCommonTargetGenerator::GetLinkedTargetDirectories(
  150. const std::string& lang, const std::string& config) const
  151. {
  152. LinkedTargetDirs dirs;
  153. std::set<cmGeneratorTarget const*> forward_emitted;
  154. std::set<cmGeneratorTarget const*> direct_emitted;
  155. cmGlobalCommonGenerator* const gg = this->GlobalCommonGenerator;
  156. enum class Forwarding
  157. {
  158. Yes,
  159. No
  160. };
  161. if (cmComputeLinkInformation* cli =
  162. this->GeneratorTarget->GetLinkInformation(config)) {
  163. auto addLinkedTarget =
  164. [this, &lang, &config, &dirs, &direct_emitted, &forward_emitted,
  165. gg](cmGeneratorTarget const* linkee, Forwarding forward) {
  166. if (linkee &&
  167. !linkee->IsImported()
  168. // Skip targets that build after this one in a static lib cycle.
  169. && gg->TargetOrderIndexLess(linkee, this->GeneratorTarget)
  170. // We can ignore the INTERFACE_LIBRARY items because
  171. // Target->GetLinkInformation already processed their
  172. // link interface and they don't have any output themselves.
  173. && (linkee->GetType() != cmStateEnums::INTERFACE_LIBRARY
  174. // Synthesized targets may have relevant rules.
  175. || linkee->IsSynthetic()) &&
  176. ((lang == "CXX"_s && linkee->HaveCxx20ModuleSources()) ||
  177. (lang == "Fortran"_s && linkee->HaveFortranSources(config)))) {
  178. cmLocalGenerator* lg = linkee->GetLocalGenerator();
  179. std::string di = cmStrCat(lg->GetCurrentBinaryDirectory(), '/',
  180. lg->GetTargetDirectory(linkee));
  181. if (lg->GetGlobalGenerator()->IsMultiConfig()) {
  182. di = cmStrCat(di, '/', config);
  183. }
  184. if (forward == Forwarding::Yes &&
  185. forward_emitted.insert(linkee).second) {
  186. dirs.Forward.push_back(di);
  187. }
  188. if (direct_emitted.insert(linkee).second) {
  189. dirs.Direct.emplace_back(di);
  190. }
  191. }
  192. };
  193. for (auto const& item : cli->GetItems()) {
  194. if (item.Target) {
  195. addLinkedTarget(item.Target, Forwarding::No);
  196. } else if (item.ObjectSource && lang == "Fortran"_s
  197. /* Object source files do not have a language associated with
  198. them. */
  199. /* && item.ObjectSource->GetLanguage() == "Fortran"_s*/) {
  200. // Fortran modules provided by `$<TARGET_OBJECTS>` as linked items
  201. // should be collated for use in this target.
  202. addLinkedTarget(this->LocalCommonGenerator->FindGeneratorTargetToUse(
  203. item.ObjectSource->GetObjectLibrary()),
  204. Forwarding::Yes);
  205. }
  206. }
  207. for (cmGeneratorTarget const* target : cli->GetExternalObjectTargets()) {
  208. addLinkedTarget(target, Forwarding::No);
  209. }
  210. if (lang == "Fortran"_s) {
  211. // Fortran modules provided by `$<TARGET_OBJECTS>` as sources should be
  212. // collated for use in this target.
  213. for (cmGeneratorTarget const* target :
  214. this->GeneratorTarget->GetSourceObjectLibraries(config)) {
  215. addLinkedTarget(target, Forwarding::Yes);
  216. }
  217. }
  218. }
  219. return dirs;
  220. }
  221. std::string cmCommonTargetGenerator::ComputeTargetCompilePDB(
  222. const std::string& config) const
  223. {
  224. std::string compilePdbPath;
  225. if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  226. return compilePdbPath;
  227. }
  228. compilePdbPath = this->GeneratorTarget->GetCompilePDBPath(config);
  229. if (compilePdbPath.empty()) {
  230. // Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`.
  231. // A trailing slash tells the toolchain to add its default file name.
  232. compilePdbPath = this->GeneratorTarget->GetSupportDirectory();
  233. if (this->GlobalCommonGenerator->IsMultiConfig()) {
  234. compilePdbPath += "/";
  235. compilePdbPath += config;
  236. }
  237. compilePdbPath += "/";
  238. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  239. // Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`.
  240. compilePdbPath += this->GeneratorTarget->GetName();
  241. compilePdbPath += ".pdb";
  242. }
  243. }
  244. return compilePdbPath;
  245. }
  246. std::string cmCommonTargetGenerator::GetManifests(const std::string& config)
  247. {
  248. std::vector<cmSourceFile const*> manifest_srcs;
  249. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  250. std::vector<std::string> manifests;
  251. manifests.reserve(manifest_srcs.size());
  252. std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
  253. std::string manifestFlag =
  254. this->Makefile->GetDefinition("CMAKE_" + lang + "_LINKER_MANIFEST_FLAG");
  255. for (cmSourceFile const* manifest_src : manifest_srcs) {
  256. manifests.push_back(manifestFlag +
  257. this->LocalCommonGenerator->ConvertToOutputFormat(
  258. this->LocalCommonGenerator->MaybeRelativeToWorkDir(
  259. manifest_src->GetFullPath()),
  260. cmOutputConverter::SHELL));
  261. }
  262. return cmJoin(manifests, " ");
  263. }
  264. std::string cmCommonTargetGenerator::GetAIXExports(std::string const&)
  265. {
  266. std::string aixExports;
  267. if (this->GeneratorTarget->IsAIX()) {
  268. if (cmValue exportAll =
  269. this->GeneratorTarget->GetProperty("AIX_EXPORT_ALL_SYMBOLS")) {
  270. if (exportAll.IsOff()) {
  271. aixExports = "-n";
  272. }
  273. }
  274. }
  275. return aixExports;
  276. }
  277. void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
  278. const std::string& lang,
  279. const char* name, bool so)
  280. {
  281. // Lookup the flag to specify the version.
  282. std::string fvar = cmStrCat("CMAKE_", lang, "_OSX_", name, "_VERSION_FLAG");
  283. cmValue flag = this->Makefile->GetDefinition(fvar);
  284. // Skip if no such flag.
  285. if (!flag) {
  286. return;
  287. }
  288. // Lookup the target version information.
  289. int major;
  290. int minor;
  291. int patch;
  292. std::string prop = cmStrCat("MACHO_", name, "_VERSION");
  293. std::string fallback_prop = so ? "SOVERSION" : "VERSION";
  294. this->GeneratorTarget->GetTargetVersionFallback(prop, fallback_prop, major,
  295. minor, patch);
  296. if (major > 0 || minor > 0 || patch > 0) {
  297. // Append the flag since a non-zero version is specified.
  298. std::ostringstream vflag;
  299. vflag << *flag << major << "." << minor << "." << patch;
  300. this->LocalCommonGenerator->AppendFlags(flags, vflag.str());
  301. }
  302. }
  303. std::string cmCommonTargetGenerator::GetCompilerLauncher(
  304. std::string const& lang, std::string const& config)
  305. {
  306. std::string compilerLauncher;
  307. if (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
  308. lang == "HIP" || lang == "ISPC" || lang == "OBJC" || lang == "OBJCXX") {
  309. std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
  310. cmValue clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
  311. std::string const evaluatedClauncher = cmGeneratorExpression::Evaluate(
  312. *clauncher, this->GeneratorTarget->GetLocalGenerator(), config,
  313. this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
  314. if (!evaluatedClauncher.empty()) {
  315. compilerLauncher = evaluatedClauncher;
  316. }
  317. }
  318. return compilerLauncher;
  319. }
  320. std::string cmCommonTargetGenerator::GenerateCodeCheckRules(
  321. cmSourceFile const& source, std::string& compilerLauncher,
  322. std::string const& cmakeCmd, std::string const& config,
  323. std::function<std::string(std::string const&)> const& pathConverter)
  324. {
  325. auto const lang = source.GetLanguage();
  326. std::string tidy;
  327. std::string iwyu;
  328. std::string cpplint;
  329. std::string cppcheck;
  330. auto evaluateProp = [&](std::string const& prop) -> std::string {
  331. auto const value = this->GeneratorTarget->GetProperty(prop);
  332. if (!value) {
  333. return std::string{};
  334. }
  335. auto evaluatedProp = cmGeneratorExpression::Evaluate(
  336. *value, this->GeneratorTarget->GetLocalGenerator(), config,
  337. this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
  338. return evaluatedProp;
  339. };
  340. std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
  341. tidy = evaluateProp(tidy_prop);
  342. if (lang == "C" || lang == "CXX") {
  343. std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
  344. iwyu = evaluateProp(iwyu_prop);
  345. std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
  346. cpplint = evaluateProp(cpplint_prop);
  347. std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
  348. cppcheck = evaluateProp(cppcheck_prop);
  349. }
  350. if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
  351. cmNonempty(cppcheck)) {
  352. std::string code_check = cmakeCmd + " -E __run_co_compile";
  353. if (!compilerLauncher.empty()) {
  354. // In __run_co_compile case the launcher command is supplied
  355. // via --launcher=<maybe-list> and consumed
  356. code_check += " --launcher=";
  357. code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  358. compilerLauncher);
  359. compilerLauncher.clear();
  360. }
  361. if (cmNonempty(iwyu)) {
  362. code_check += " --iwyu=";
  363. // Only add --driver-mode if it is not already specified, as adding
  364. // it unconditionally might override a user-specified driver-mode
  365. if (iwyu.find("--driver-mode=") == std::string::npos) {
  366. cmValue const p = this->Makefile->GetDefinition(
  367. cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
  368. std::string driverMode;
  369. if (cmNonempty(p)) {
  370. driverMode = *p;
  371. } else {
  372. driverMode = lang == "C" ? "gcc" : "g++";
  373. }
  374. code_check +=
  375. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  376. cmStrCat(iwyu, ";--driver-mode=", driverMode));
  377. } else {
  378. code_check +=
  379. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(iwyu);
  380. }
  381. }
  382. if (cmNonempty(tidy)) {
  383. code_check += " --tidy=";
  384. cmValue const p = this->Makefile->GetDefinition(
  385. "CMAKE_" + lang + "_CLANG_TIDY_DRIVER_MODE");
  386. std::string driverMode;
  387. if (cmNonempty(p)) {
  388. driverMode = *p;
  389. } else {
  390. driverMode = lang == "C" ? "gcc" : "g++";
  391. }
  392. auto const generatorName = this->GeneratorTarget->GetLocalGenerator()
  393. ->GetGlobalGenerator()
  394. ->GetName();
  395. auto const clangTidyExportFixedDir =
  396. this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang);
  397. auto fixesFile = this->GetClangTidyReplacementsFilePath(
  398. clangTidyExportFixedDir, source, config);
  399. std::string exportFixes;
  400. if (!clangTidyExportFixedDir.empty()) {
  401. this->GlobalCommonGenerator->AddClangTidyExportFixesDir(
  402. clangTidyExportFixedDir);
  403. }
  404. if (generatorName.find("Make") != std::string::npos) {
  405. if (!clangTidyExportFixedDir.empty()) {
  406. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  407. cmSystemTools::MakeDirectory(
  408. cmSystemTools::GetFilenamePath(fixesFile));
  409. fixesFile = this->GeneratorTarget->GetLocalGenerator()
  410. ->MaybeRelativeToCurBinDir(fixesFile);
  411. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  412. }
  413. code_check +=
  414. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  415. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  416. exportFixes));
  417. } else if (generatorName.find("Ninja") != std::string::npos) {
  418. if (!clangTidyExportFixedDir.empty()) {
  419. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  420. cmSystemTools::MakeDirectory(
  421. cmSystemTools::GetFilenamePath(fixesFile));
  422. if (!pathConverter) {
  423. fixesFile = pathConverter(fixesFile);
  424. }
  425. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  426. }
  427. code_check +=
  428. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  429. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  430. exportFixes));
  431. }
  432. }
  433. if (cmNonempty(cpplint)) {
  434. code_check += " --cpplint=";
  435. code_check +=
  436. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cpplint);
  437. }
  438. if (cmNonempty(cppcheck)) {
  439. code_check += " --cppcheck=";
  440. code_check +=
  441. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cppcheck);
  442. }
  443. if (cmNonempty(tidy) || (cmNonempty(cpplint)) || (cmNonempty(cppcheck))) {
  444. code_check += " --source=";
  445. code_check +=
  446. this->GeneratorTarget->GetLocalGenerator()->ConvertToOutputFormat(
  447. source.GetFullPath(), cmOutputConverter::SHELL);
  448. }
  449. code_check += " -- ";
  450. return code_check;
  451. }
  452. return "";
  453. }
  454. std::string cmCommonTargetGenerator::GetLinkerLauncher(
  455. const std::string& config)
  456. {
  457. std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
  458. std::string propName = lang + "_LINKER_LAUNCHER";
  459. cmValue launcherProp = this->GeneratorTarget->GetProperty(propName);
  460. if (cmNonempty(launcherProp)) {
  461. cmGeneratorExpressionDAGChecker dagChecker{
  462. this->GeneratorTarget, propName, nullptr, nullptr,
  463. this->LocalCommonGenerator, config,
  464. };
  465. std::string evaluatedLinklauncher = cmGeneratorExpression::Evaluate(
  466. *launcherProp, this->LocalCommonGenerator, config, this->GeneratorTarget,
  467. &dagChecker, this->GeneratorTarget, lang);
  468. // Convert ;-delimited list to single string
  469. cmList args{ evaluatedLinklauncher, cmList::EmptyElements::Yes };
  470. if (!args.empty()) {
  471. args[0] = this->LocalCommonGenerator->ConvertToOutputFormat(
  472. args[0], cmOutputConverter::SHELL);
  473. for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
  474. i = this->LocalCommonGenerator->EscapeForShell(i);
  475. }
  476. return cmJoin(args, " ");
  477. }
  478. }
  479. return std::string();
  480. }
  481. bool cmCommonTargetGenerator::HaveRequiredLanguages(
  482. const std::vector<cmSourceFile const*>& sources,
  483. std::set<std::string>& languagesNeeded) const
  484. {
  485. for (cmSourceFile const* sf : sources) {
  486. languagesNeeded.insert(sf->GetLanguage());
  487. }
  488. auto* makefile = this->Makefile;
  489. auto* state = makefile->GetState();
  490. auto unary = [&state, &makefile](const std::string& lang) -> bool {
  491. const bool valid = state->GetLanguageEnabled(lang);
  492. if (!valid) {
  493. makefile->IssueMessage(
  494. MessageType::FATAL_ERROR,
  495. cmStrCat("The language ", lang,
  496. " was requested for compilation but was not enabled."
  497. " To enable a language it needs to be specified in a"
  498. " 'project' or 'enable_language' command in the root"
  499. " CMakeLists.txt"));
  500. }
  501. return valid;
  502. };
  503. return std::all_of(languagesNeeded.cbegin(), languagesNeeded.cend(), unary);
  504. }