cmCommonTargetGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst 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(std::string const& feature,
  45. std::string const& config)
  46. {
  47. return this->GeneratorTarget->GetFeature(feature, config);
  48. }
  49. void cmCommonTargetGenerator::AppendFortranFormatFlags(
  50. std::string& flags, cmSourceFile const& source)
  51. {
  52. std::string const 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. char const* 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. std::string const 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. char const* 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(std::string const& l,
  107. std::string const& config,
  108. std::string const& arch)
  109. {
  110. std::string const 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(std::string const& l,
  122. std::string const& 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. std::string const& 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. std::string const& lang, std::string const& 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 = linkee->GetSupportDirectory();
  180. if (lg->GetGlobalGenerator()->IsMultiConfig()) {
  181. di = cmStrCat(di, '/', config);
  182. }
  183. if (forward == Forwarding::Yes &&
  184. forward_emitted.insert(linkee).second) {
  185. dirs.Forward.push_back(di);
  186. }
  187. if (direct_emitted.insert(linkee).second) {
  188. dirs.Direct.emplace_back(di);
  189. }
  190. }
  191. };
  192. for (auto const& item : cli->GetItems()) {
  193. if (item.Target) {
  194. addLinkedTarget(item.Target, Forwarding::No);
  195. } else if (item.ObjectSource && lang == "Fortran"_s
  196. /* Object source files do not have a language associated with
  197. them. */
  198. /* && item.ObjectSource->GetLanguage() == "Fortran"_s*/) {
  199. // Fortran modules provided by `$<TARGET_OBJECTS>` as linked items
  200. // should be collated for use in this target.
  201. addLinkedTarget(this->LocalCommonGenerator->FindGeneratorTargetToUse(
  202. item.ObjectSource->GetObjectLibrary()),
  203. Forwarding::Yes);
  204. }
  205. }
  206. for (cmGeneratorTarget const* target : cli->GetExternalObjectTargets()) {
  207. addLinkedTarget(target, Forwarding::No);
  208. }
  209. if (lang == "Fortran"_s) {
  210. // Fortran modules provided by `$<TARGET_OBJECTS>` as sources should be
  211. // collated for use in this target.
  212. for (cmGeneratorTarget const* target :
  213. this->GeneratorTarget->GetSourceObjectLibraries(config)) {
  214. addLinkedTarget(target, Forwarding::Yes);
  215. }
  216. }
  217. }
  218. return dirs;
  219. }
  220. std::string cmCommonTargetGenerator::ComputeTargetCompilePDB(
  221. std::string const& config) const
  222. {
  223. std::string compilePdbPath;
  224. if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  225. return compilePdbPath;
  226. }
  227. compilePdbPath = this->GeneratorTarget->GetCompilePDBPath(config);
  228. if (compilePdbPath.empty()) {
  229. // Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`.
  230. // A trailing slash tells the toolchain to add its default file name.
  231. compilePdbPath = this->GeneratorTarget->GetSupportDirectory();
  232. if (this->GlobalCommonGenerator->IsMultiConfig()) {
  233. compilePdbPath += "/";
  234. compilePdbPath += config;
  235. }
  236. compilePdbPath += "/";
  237. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  238. // Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`.
  239. compilePdbPath += this->GeneratorTarget->GetName();
  240. compilePdbPath += ".pdb";
  241. }
  242. }
  243. return compilePdbPath;
  244. }
  245. std::string cmCommonTargetGenerator::GetManifests(std::string const& config)
  246. {
  247. std::vector<cmSourceFile const*> manifest_srcs;
  248. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  249. std::vector<std::string> manifests;
  250. manifests.reserve(manifest_srcs.size());
  251. std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
  252. std::string manifestFlag =
  253. this->Makefile->GetDefinition("CMAKE_" + lang + "_LINKER_MANIFEST_FLAG");
  254. for (cmSourceFile const* manifest_src : manifest_srcs) {
  255. manifests.push_back(manifestFlag +
  256. this->LocalCommonGenerator->ConvertToOutputFormat(
  257. this->LocalCommonGenerator->MaybeRelativeToWorkDir(
  258. manifest_src->GetFullPath()),
  259. cmOutputConverter::SHELL));
  260. }
  261. return cmJoin(manifests, " ");
  262. }
  263. std::string cmCommonTargetGenerator::GetAIXExports(std::string const&)
  264. {
  265. std::string aixExports;
  266. if (this->GeneratorTarget->IsAIX()) {
  267. if (cmValue exportAll =
  268. this->GeneratorTarget->GetProperty("AIX_EXPORT_ALL_SYMBOLS")) {
  269. if (exportAll.IsOff()) {
  270. aixExports = "-n";
  271. }
  272. }
  273. }
  274. return aixExports;
  275. }
  276. void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
  277. std::string const& lang,
  278. char const* name, bool so)
  279. {
  280. // Lookup the flag to specify the version.
  281. std::string fvar = cmStrCat("CMAKE_", lang, "_OSX_", name, "_VERSION_FLAG");
  282. cmValue flag = this->Makefile->GetDefinition(fvar);
  283. // Skip if no such flag.
  284. if (!flag) {
  285. return;
  286. }
  287. // Lookup the target version information.
  288. int major;
  289. int minor;
  290. int patch;
  291. std::string prop = cmStrCat("MACHO_", name, "_VERSION");
  292. std::string fallback_prop = so ? "SOVERSION" : "VERSION";
  293. this->GeneratorTarget->GetTargetVersionFallback(prop, fallback_prop, major,
  294. minor, patch);
  295. if (major > 0 || minor > 0 || patch > 0) {
  296. // Append the flag since a non-zero version is specified.
  297. std::ostringstream vflag;
  298. vflag << *flag << major << "." << minor << "." << patch;
  299. this->LocalCommonGenerator->AppendFlags(flags, vflag.str());
  300. }
  301. }
  302. std::string cmCommonTargetGenerator::GetCompilerLauncher(
  303. std::string const& lang, std::string const& config)
  304. {
  305. std::string compilerLauncher;
  306. if (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
  307. lang == "HIP" || lang == "ISPC" || lang == "OBJC" || lang == "OBJCXX") {
  308. std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
  309. cmValue clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
  310. std::string const evaluatedClauncher = cmGeneratorExpression::Evaluate(
  311. *clauncher, this->GeneratorTarget->GetLocalGenerator(), config,
  312. this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
  313. if (!evaluatedClauncher.empty()) {
  314. compilerLauncher = evaluatedClauncher;
  315. }
  316. }
  317. return compilerLauncher;
  318. }
  319. std::string cmCommonTargetGenerator::GenerateCodeCheckRules(
  320. cmSourceFile const& source, std::string& compilerLauncher,
  321. std::string const& cmakeCmd, std::string const& config,
  322. std::function<std::string(std::string const&)> const& pathConverter)
  323. {
  324. auto const lang = source.GetLanguage();
  325. std::string tidy;
  326. std::string iwyu;
  327. std::string cpplint;
  328. std::string cppcheck;
  329. std::string icstat;
  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. std::string const icstat_prop = cmStrCat(lang, "_ICSTAT");
  350. icstat = evaluateProp(icstat_prop);
  351. }
  352. if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
  353. cmNonempty(cppcheck) || cmNonempty(icstat)) {
  354. std::string code_check = cmakeCmd + " -E __run_co_compile";
  355. if (!compilerLauncher.empty()) {
  356. // In __run_co_compile case the launcher command is supplied
  357. // via --launcher=<maybe-list> and consumed
  358. code_check += " --launcher=";
  359. code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  360. compilerLauncher);
  361. compilerLauncher.clear();
  362. }
  363. if (cmNonempty(iwyu)) {
  364. code_check += " --iwyu=";
  365. // Only add --driver-mode if it is not already specified, as adding
  366. // it unconditionally might override a user-specified driver-mode
  367. if (iwyu.find("--driver-mode=") == std::string::npos) {
  368. cmValue const p = this->Makefile->GetDefinition(
  369. cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
  370. std::string driverMode;
  371. if (cmNonempty(p)) {
  372. driverMode = *p;
  373. } else {
  374. driverMode = lang == "C" ? "gcc" : "g++";
  375. }
  376. code_check +=
  377. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  378. cmStrCat(iwyu, ";--driver-mode=", driverMode));
  379. } else {
  380. code_check +=
  381. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(iwyu);
  382. }
  383. }
  384. if (cmNonempty(tidy)) {
  385. code_check += " --tidy=";
  386. cmValue const p = this->Makefile->GetDefinition(
  387. "CMAKE_" + lang + "_CLANG_TIDY_DRIVER_MODE");
  388. std::string driverMode;
  389. if (cmNonempty(p)) {
  390. driverMode = *p;
  391. } else {
  392. driverMode = lang == "C" ? "gcc" : "g++";
  393. }
  394. auto const generatorName = this->GeneratorTarget->GetLocalGenerator()
  395. ->GetGlobalGenerator()
  396. ->GetName();
  397. auto const clangTidyExportFixedDir =
  398. this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang);
  399. auto fixesFile = this->GetClangTidyReplacementsFilePath(
  400. clangTidyExportFixedDir, source, config);
  401. std::string exportFixes;
  402. if (!clangTidyExportFixedDir.empty()) {
  403. this->GlobalCommonGenerator->AddClangTidyExportFixesDir(
  404. clangTidyExportFixedDir);
  405. }
  406. if (generatorName.find("Make") != std::string::npos) {
  407. if (!clangTidyExportFixedDir.empty()) {
  408. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  409. cmSystemTools::MakeDirectory(
  410. cmSystemTools::GetFilenamePath(fixesFile));
  411. fixesFile = this->GeneratorTarget->GetLocalGenerator()
  412. ->MaybeRelativeToCurBinDir(fixesFile);
  413. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  414. }
  415. code_check +=
  416. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  417. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  418. exportFixes));
  419. } else if (generatorName.find("Ninja") != std::string::npos) {
  420. if (!clangTidyExportFixedDir.empty()) {
  421. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  422. cmSystemTools::MakeDirectory(
  423. cmSystemTools::GetFilenamePath(fixesFile));
  424. if (!pathConverter) {
  425. fixesFile = pathConverter(fixesFile);
  426. }
  427. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  428. }
  429. code_check +=
  430. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  431. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  432. exportFixes));
  433. }
  434. }
  435. if (cmNonempty(cpplint)) {
  436. code_check += " --cpplint=";
  437. code_check +=
  438. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cpplint);
  439. }
  440. if (cmNonempty(cppcheck)) {
  441. code_check += " --cppcheck=";
  442. code_check +=
  443. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cppcheck);
  444. }
  445. if (cmNonempty(icstat)) {
  446. code_check += " --icstat=";
  447. std::string checksParam{};
  448. std::string dbParam{};
  449. // Set default values for mandatory parameters
  450. std::string checksFile{ "cstat_sel_checks.txt" };
  451. std::string dbFile{ "cstat.db" };
  452. // Populate the command line with C-STAT
  453. // mandatory parameters unless specified
  454. if (icstat.find("--checks=") == std::string::npos) {
  455. checksParam = cmStrCat(";--checks=", checksFile);
  456. }
  457. if (icstat.find("--db=") == std::string::npos) {
  458. dbParam = cmStrCat(";--db=", dbFile);
  459. }
  460. code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  461. cmStrCat(icstat, checksParam, dbParam));
  462. }
  463. if (cmNonempty(tidy) || (cmNonempty(cpplint)) || (cmNonempty(cppcheck))) {
  464. code_check += " --source=";
  465. code_check +=
  466. this->GeneratorTarget->GetLocalGenerator()->ConvertToOutputFormat(
  467. source.GetFullPath(), cmOutputConverter::SHELL);
  468. }
  469. code_check += " -- ";
  470. return code_check;
  471. }
  472. return "";
  473. }
  474. std::string cmCommonTargetGenerator::GetLinkerLauncher(
  475. std::string const& config)
  476. {
  477. std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
  478. std::string propName = lang + "_LINKER_LAUNCHER";
  479. cmValue launcherProp = this->GeneratorTarget->GetProperty(propName);
  480. if (cmNonempty(launcherProp)) {
  481. cmGeneratorExpressionDAGChecker dagChecker{
  482. this->GeneratorTarget, propName, nullptr, nullptr,
  483. this->LocalCommonGenerator, config,
  484. };
  485. std::string evaluatedLinklauncher = cmGeneratorExpression::Evaluate(
  486. *launcherProp, this->LocalCommonGenerator, config, this->GeneratorTarget,
  487. &dagChecker, this->GeneratorTarget, lang);
  488. // Convert ;-delimited list to single string
  489. cmList args{ evaluatedLinklauncher, cmList::EmptyElements::Yes };
  490. if (!args.empty()) {
  491. args[0] = this->LocalCommonGenerator->ConvertToOutputFormat(
  492. args[0], cmOutputConverter::SHELL);
  493. for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
  494. i = this->LocalCommonGenerator->EscapeForShell(i);
  495. }
  496. return cmJoin(args, " ");
  497. }
  498. }
  499. return std::string();
  500. }
  501. bool cmCommonTargetGenerator::HaveRequiredLanguages(
  502. std::vector<cmSourceFile const*> const& sources,
  503. std::set<std::string>& languagesNeeded) const
  504. {
  505. for (cmSourceFile const* sf : sources) {
  506. languagesNeeded.insert(sf->GetLanguage());
  507. }
  508. auto* makefile = this->Makefile;
  509. auto* state = makefile->GetState();
  510. auto unary = [&state, &makefile](std::string const& lang) -> bool {
  511. bool const valid = state->GetLanguageEnabled(lang);
  512. if (!valid) {
  513. makefile->IssueMessage(
  514. MessageType::FATAL_ERROR,
  515. cmStrCat("The language ", lang,
  516. " was requested for compilation but was not enabled."
  517. " To enable a language it needs to be specified in a"
  518. " 'project' or 'enable_language' command in the root"
  519. " CMakeLists.txt"));
  520. }
  521. return valid;
  522. };
  523. return std::all_of(languagesNeeded.cbegin(), languagesNeeded.cend(), unary);
  524. }