cmCommonTargetGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 = 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. std::string const& 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(std::string const& 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. std::string const& lang,
  279. char const* 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. std::string icstat;
  331. auto evaluateProp = [&](std::string const& prop) -> std::string {
  332. auto const value = this->GeneratorTarget->GetProperty(prop);
  333. if (!value) {
  334. return std::string{};
  335. }
  336. auto evaluatedProp = cmGeneratorExpression::Evaluate(
  337. *value, this->GeneratorTarget->GetLocalGenerator(), config,
  338. this->GeneratorTarget, nullptr, this->GeneratorTarget, lang);
  339. return evaluatedProp;
  340. };
  341. std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
  342. tidy = evaluateProp(tidy_prop);
  343. if (lang == "C" || lang == "CXX") {
  344. std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
  345. iwyu = evaluateProp(iwyu_prop);
  346. std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
  347. cpplint = evaluateProp(cpplint_prop);
  348. std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
  349. cppcheck = evaluateProp(cppcheck_prop);
  350. std::string const icstat_prop = cmStrCat(lang, "_ICSTAT");
  351. icstat = evaluateProp(icstat_prop);
  352. }
  353. if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
  354. cmNonempty(cppcheck) || cmNonempty(icstat)) {
  355. std::string code_check = cmakeCmd + " -E __run_co_compile";
  356. if (!compilerLauncher.empty()) {
  357. // In __run_co_compile case the launcher command is supplied
  358. // via --launcher=<maybe-list> and consumed
  359. code_check += " --launcher=";
  360. code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  361. compilerLauncher);
  362. compilerLauncher.clear();
  363. }
  364. if (cmNonempty(iwyu)) {
  365. code_check += " --iwyu=";
  366. // Only add --driver-mode if it is not already specified, as adding
  367. // it unconditionally might override a user-specified driver-mode
  368. if (iwyu.find("--driver-mode=") == std::string::npos) {
  369. cmValue const p = this->Makefile->GetDefinition(
  370. cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
  371. std::string driverMode;
  372. if (cmNonempty(p)) {
  373. driverMode = *p;
  374. } else {
  375. driverMode = lang == "C" ? "gcc" : "g++";
  376. }
  377. code_check +=
  378. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  379. cmStrCat(iwyu, ";--driver-mode=", driverMode));
  380. } else {
  381. code_check +=
  382. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(iwyu);
  383. }
  384. }
  385. if (cmNonempty(tidy)) {
  386. code_check += " --tidy=";
  387. cmValue const p = this->Makefile->GetDefinition(
  388. "CMAKE_" + lang + "_CLANG_TIDY_DRIVER_MODE");
  389. std::string driverMode;
  390. if (cmNonempty(p)) {
  391. driverMode = *p;
  392. } else {
  393. driverMode = lang == "C" ? "gcc" : "g++";
  394. }
  395. auto const generatorName = this->GeneratorTarget->GetLocalGenerator()
  396. ->GetGlobalGenerator()
  397. ->GetName();
  398. auto const clangTidyExportFixedDir =
  399. this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang);
  400. auto fixesFile = this->GetClangTidyReplacementsFilePath(
  401. clangTidyExportFixedDir, source, config);
  402. std::string exportFixes;
  403. if (!clangTidyExportFixedDir.empty()) {
  404. this->GlobalCommonGenerator->AddClangTidyExportFixesDir(
  405. clangTidyExportFixedDir);
  406. }
  407. if (generatorName.find("Make") != std::string::npos) {
  408. if (!clangTidyExportFixedDir.empty()) {
  409. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  410. cmSystemTools::MakeDirectory(
  411. cmSystemTools::GetFilenamePath(fixesFile));
  412. fixesFile = this->GeneratorTarget->GetLocalGenerator()
  413. ->MaybeRelativeToCurBinDir(fixesFile);
  414. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  415. }
  416. code_check +=
  417. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  418. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  419. exportFixes));
  420. } else if (generatorName.find("Ninja") != std::string::npos) {
  421. if (!clangTidyExportFixedDir.empty()) {
  422. this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
  423. cmSystemTools::MakeDirectory(
  424. cmSystemTools::GetFilenamePath(fixesFile));
  425. if (!pathConverter) {
  426. fixesFile = pathConverter(fixesFile);
  427. }
  428. exportFixes = cmStrCat(";--export-fixes=", fixesFile);
  429. }
  430. code_check +=
  431. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  432. cmStrCat(tidy, ";--extra-arg-before=--driver-mode=", driverMode,
  433. exportFixes));
  434. }
  435. }
  436. if (cmNonempty(cpplint)) {
  437. code_check += " --cpplint=";
  438. code_check +=
  439. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cpplint);
  440. }
  441. if (cmNonempty(cppcheck)) {
  442. code_check += " --cppcheck=";
  443. code_check +=
  444. this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(cppcheck);
  445. }
  446. if (cmNonempty(icstat)) {
  447. code_check += " --icstat=";
  448. std::string checksParam{};
  449. std::string dbParam{};
  450. // Set default values for mandatory parameters
  451. std::string checksFile{ "cstat_sel_checks.txt" };
  452. std::string dbFile{ "cstat.db" };
  453. // Populate the command line with C-STAT
  454. // mandatory parameters unless specified
  455. if (icstat.find("--checks=") == std::string::npos) {
  456. checksParam = cmStrCat(";--checks=", checksFile);
  457. }
  458. if (icstat.find("--db=") == std::string::npos) {
  459. dbParam = cmStrCat(";--db=", dbFile);
  460. }
  461. code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell(
  462. cmStrCat(icstat, checksParam, dbParam));
  463. }
  464. if (cmNonempty(tidy) || (cmNonempty(cpplint)) || (cmNonempty(cppcheck))) {
  465. code_check += " --source=";
  466. code_check +=
  467. this->GeneratorTarget->GetLocalGenerator()->ConvertToOutputFormat(
  468. source.GetFullPath(), cmOutputConverter::SHELL);
  469. }
  470. code_check += " -- ";
  471. return code_check;
  472. }
  473. return "";
  474. }
  475. std::string cmCommonTargetGenerator::GetLinkerLauncher(
  476. std::string const& config)
  477. {
  478. std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
  479. std::string propName = lang + "_LINKER_LAUNCHER";
  480. cmValue launcherProp = this->GeneratorTarget->GetProperty(propName);
  481. if (cmNonempty(launcherProp)) {
  482. cmGeneratorExpressionDAGChecker dagChecker{
  483. this->GeneratorTarget, propName, nullptr, nullptr,
  484. this->LocalCommonGenerator, config,
  485. };
  486. std::string evaluatedLinklauncher = cmGeneratorExpression::Evaluate(
  487. *launcherProp, this->LocalCommonGenerator, config, this->GeneratorTarget,
  488. &dagChecker, this->GeneratorTarget, lang);
  489. // Convert ;-delimited list to single string
  490. cmList args{ evaluatedLinklauncher, cmList::EmptyElements::Yes };
  491. if (!args.empty()) {
  492. args[0] = this->LocalCommonGenerator->ConvertToOutputFormat(
  493. args[0], cmOutputConverter::SHELL);
  494. for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
  495. i = this->LocalCommonGenerator->EscapeForShell(i);
  496. }
  497. return cmJoin(args, " ");
  498. }
  499. }
  500. return std::string();
  501. }
  502. bool cmCommonTargetGenerator::HaveRequiredLanguages(
  503. std::vector<cmSourceFile const*> const& sources,
  504. std::set<std::string>& languagesNeeded) const
  505. {
  506. for (cmSourceFile const* sf : sources) {
  507. languagesNeeded.insert(sf->GetLanguage());
  508. }
  509. auto* makefile = this->Makefile;
  510. auto* state = makefile->GetState();
  511. auto unary = [&state, &makefile](std::string const& lang) -> bool {
  512. bool const valid = state->GetLanguageEnabled(lang);
  513. if (!valid) {
  514. makefile->IssueMessage(
  515. MessageType::FATAL_ERROR,
  516. cmStrCat("The language ", lang,
  517. " was requested for compilation but was not enabled."
  518. " To enable a language it needs to be specified in a"
  519. " 'project' or 'enable_language' command in the root"
  520. " CMakeLists.txt"));
  521. }
  522. return valid;
  523. };
  524. return std::all_of(languagesNeeded.cbegin(), languagesNeeded.cend(), unary);
  525. }