| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734 |
- /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- file Copyright.txt or https://cmake.org/licensing for details. */
- #include "cmNinjaNormalTargetGenerator.h"
- #include <algorithm>
- #include <cassert>
- #include <iterator>
- #include <set>
- #include <sstream>
- #include <unordered_set>
- #include <utility>
- #include <cm/memory>
- #include <cm/optional>
- #include <cm/vector>
- #include "cmComputeLinkInformation.h"
- #include "cmCustomCommand.h" // IWYU pragma: keep
- #include "cmCustomCommandGenerator.h"
- #include "cmGeneratedFileStream.h"
- #include "cmGeneratorTarget.h"
- #include "cmGlobalNinjaGenerator.h"
- #include "cmLinkLineComputer.h"
- #include "cmLinkLineDeviceComputer.h"
- #include "cmList.h"
- #include "cmLocalCommonGenerator.h"
- #include "cmLocalGenerator.h"
- #include "cmLocalNinjaGenerator.h"
- #include "cmMakefile.h"
- #include "cmMessageType.h"
- #include "cmNinjaLinkLineDeviceComputer.h"
- #include "cmNinjaTypes.h"
- #include "cmOSXBundleGenerator.h"
- #include "cmOutputConverter.h"
- #include "cmRulePlaceholderExpander.h"
- #include "cmSourceFile.h"
- #include "cmState.h"
- #include "cmStateDirectory.h"
- #include "cmStateSnapshot.h"
- #include "cmStateTypes.h"
- #include "cmStringAlgorithms.h"
- #include "cmSystemTools.h"
- #include "cmValue.h"
- cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
- cmGeneratorTarget* target)
- : cmNinjaTargetGenerator(target)
- {
- if (target->GetType() != cmStateEnums::OBJECT_LIBRARY) {
- // on Windows the output dir is already needed at compile time
- // ensure the directory exists (OutDir test)
- for (auto const& config : this->GetConfigNames()) {
- this->EnsureDirectoryExists(target->GetDirectory(config));
- }
- }
- this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
- this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
- }
- cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() = default;
- void cmNinjaNormalTargetGenerator::Generate(const std::string& config)
- {
- if (this->GetGeneratorTarget()->GetType() !=
- cmStateEnums::INTERFACE_LIBRARY) {
- std::string lang = this->GeneratorTarget->GetLinkerLanguage(config);
- if (this->TargetLinkLanguage(config).empty()) {
- cmSystemTools::Error(
- cmStrCat("CMake can not determine linker language for target: ",
- this->GetGeneratorTarget()->GetName()));
- return;
- }
- }
- // Write the rules for each language.
- this->WriteLanguagesRules(config);
- // Write the build statements
- bool firstForConfig = true;
- for (auto const& fileConfig : this->GetConfigNames()) {
- if (!this->GetGlobalGenerator()
- ->GetCrossConfigs(fileConfig)
- .count(config)) {
- continue;
- }
- this->WriteObjectBuildStatements(config, fileConfig, firstForConfig);
- firstForConfig = false;
- }
- if (this->GetGeneratorTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- this->WriteObjectLibStatement(config);
- } else if (this->GetGeneratorTarget()->GetType() ==
- cmStateEnums::INTERFACE_LIBRARY) {
- bool haveCxxModuleSources = false;
- if (this->GetGeneratorTarget()->HaveCxx20ModuleSources()) {
- haveCxxModuleSources = true;
- }
- if (!haveCxxModuleSources) {
- cmSystemTools::Error(cmStrCat(
- "Ninja does not support INTERFACE libraries without C++ module "
- "sources as a normal target: ",
- this->GetGeneratorTarget()->GetName()));
- return;
- }
- firstForConfig = true;
- for (auto const& fileConfig : this->GetConfigNames()) {
- if (!this->GetGlobalGenerator()
- ->GetCrossConfigs(fileConfig)
- .count(config)) {
- continue;
- }
- if (haveCxxModuleSources) {
- this->WriteCxxModuleLibraryStatement(config, fileConfig,
- firstForConfig);
- }
- firstForConfig = false;
- }
- } else {
- firstForConfig = true;
- for (auto const& fileConfig : this->GetConfigNames()) {
- if (!this->GetGlobalGenerator()
- ->GetCrossConfigs(fileConfig)
- .count(config)) {
- continue;
- }
- // If this target has cuda language link inputs, and we need to do
- // device linking
- this->WriteDeviceLinkStatement(config, fileConfig, firstForConfig);
- this->WriteLinkStatement(config, fileConfig, firstForConfig);
- firstForConfig = false;
- }
- }
- if (this->GetGlobalGenerator()->EnableCrossConfigBuild()) {
- this->GetGlobalGenerator()->AddTargetAlias(
- this->GetTargetName(), this->GetGeneratorTarget(), "all");
- }
- // Find ADDITIONAL_CLEAN_FILES
- this->AdditionalCleanFiles(config);
- }
- void cmNinjaNormalTargetGenerator::WriteLanguagesRules(
- const std::string& config)
- {
- #ifdef NINJA_GEN_VERBOSE_FILES
- cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
- this->GetRulesFileStream()
- << "# Rules for each language for "
- << cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
- << " target " << this->GetTargetName() << "\n\n";
- #endif
- // Write rules for languages compiled in this target.
- {
- std::set<std::string> languages;
- std::vector<cmSourceFile const*> sourceFiles;
- this->GetGeneratorTarget()->GetObjectSources(sourceFiles, config);
- if (this->HaveRequiredLanguages(sourceFiles, languages)) {
- for (std::string const& language : languages) {
- this->WriteLanguageRules(language, config);
- }
- }
- }
- // Write rules for languages in BMI-only rules.
- {
- std::set<std::string> languages;
- std::vector<cmSourceFile const*> sourceFiles;
- this->GetGeneratorTarget()->GetCxxModuleSources(sourceFiles, config);
- if (this->HaveRequiredLanguages(sourceFiles, languages)) {
- for (std::string const& language : languages) {
- this->WriteLanguageRules(language, config);
- }
- }
- }
- }
- const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
- {
- switch (this->GetGeneratorTarget()->GetType()) {
- case cmStateEnums::STATIC_LIBRARY:
- return "static library";
- case cmStateEnums::SHARED_LIBRARY:
- return "shared library";
- case cmStateEnums::MODULE_LIBRARY:
- if (this->GetGeneratorTarget()->IsCFBundleOnApple()) {
- return "CFBundle shared module";
- } else {
- return "shared module";
- }
- case cmStateEnums::EXECUTABLE:
- return "executable";
- default:
- return nullptr;
- }
- }
- std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule(
- const std::string& config) const
- {
- return cmStrCat(
- this->TargetLinkLanguage(config), "_",
- cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()),
- "_LINKER__",
- cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName()),
- "_", config);
- }
- std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule(
- const std::string& config) const
- {
- return cmStrCat(
- this->TargetLinkLanguage(config), "_",
- cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()),
- "_DEVICE_LINKER__",
- cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName()),
- "_", config);
- }
- std::string cmNinjaNormalTargetGenerator::LanguageLinkerCudaDeviceRule(
- const std::string& config) const
- {
- return cmStrCat(
- this->TargetLinkLanguage(config), "_DEVICE_LINK__",
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
- '_', config);
- }
- std::string cmNinjaNormalTargetGenerator::LanguageLinkerCudaDeviceCompileRule(
- const std::string& config) const
- {
- return cmStrCat(
- this->TargetLinkLanguage(config), "_DEVICE_LINK_COMPILE__",
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
- '_', config);
- }
- std::string cmNinjaNormalTargetGenerator::LanguageLinkerCudaFatbinaryRule(
- const std::string& config) const
- {
- return cmStrCat(
- this->TargetLinkLanguage(config), "_FATBINARY__",
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
- '_', config);
- }
- std::string cmNinjaNormalTargetGenerator::TextStubsGeneratorRule(
- const std::string& config) const
- {
- return cmStrCat(
- "TEXT_STUBS_GENERATOR__",
- cmGlobalNinjaGenerator::EncodeRuleName(this->GeneratorTarget->GetName()),
- '_', config);
- }
- bool cmNinjaNormalTargetGenerator::CheckUseResponseFileForLibraries(
- const std::string& l) const
- {
- // Check for an explicit setting one way or the other.
- std::string const responseVar =
- "CMAKE_" + l + "_USE_RESPONSE_FILE_FOR_LIBRARIES";
- // If the option is defined, read it's value
- if (cmValue val = this->Makefile->GetDefinition(responseVar)) {
- return val.IsOn();
- }
- // Default to true
- return true;
- }
- struct cmNinjaRemoveNoOpCommands
- {
- bool operator()(std::string const& cmd)
- {
- return cmd.empty() || cmd[0] == ':';
- }
- };
- void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule(
- bool useResponseFile, const std::string& config)
- {
- cmNinjaRule rule(this->LanguageLinkerDeviceRule(config));
- if (!this->GetGlobalGenerator()->HasRule(rule.Name)) {
- cmRulePlaceholderExpander::RuleVariables vars;
- vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
- vars.CMTargetType =
- cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
- .c_str();
- vars.Language = "CUDA";
- std::string linker =
- this->GetGeneratorTarget()->GetLinkerTool("CUDA", config);
- vars.Linker = linker.c_str();
- // build response file name
- std::string responseFlag = this->GetMakefile()->GetSafeDefinition(
- "CMAKE_CUDA_RESPONSE_FILE_DEVICE_LINK_FLAG");
- if (!useResponseFile || responseFlag.empty()) {
- vars.Objects = "$in";
- vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
- } else {
- rule.RspFile = "$RSP_FILE";
- responseFlag += rule.RspFile;
- // build response file content
- if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
- rule.RspContent = "$in";
- } else {
- rule.RspContent = "$in_newline";
- }
- // add the link command in the file if necessary
- if (this->CheckUseResponseFileForLibraries("CUDA")) {
- rule.RspContent += " $LINK_LIBRARIES";
- vars.LinkLibraries = "";
- } else {
- vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
- }
- vars.Objects = responseFlag.c_str();
- }
- vars.ObjectDir = "$OBJECT_DIR";
- vars.Target = "$TARGET_FILE";
- vars.SONameFlag = "$SONAME_FLAG";
- vars.TargetSOName = "$SONAME";
- vars.TargetPDB = "$TARGET_PDB";
- vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
- vars.Flags = "$FLAGS";
- vars.LinkFlags = "$LINK_FLAGS";
- vars.Manifests = "$MANIFESTS";
- vars.LanguageCompileFlags = "$LANGUAGE_COMPILE_FLAGS";
- std::string launcher;
- std::string val = this->GetLocalGenerator()->GetRuleLauncher(
- this->GetGeneratorTarget(), "RULE_LAUNCH_LINK", config);
- if (cmNonempty(val)) {
- launcher = cmStrCat(val, ' ');
- }
- auto rulePlaceholderExpander =
- this->GetLocalGenerator()->CreateRulePlaceholderExpander();
- // Rule for linking library/executable.
- std::vector<std::string> linkCmds = this->ComputeDeviceLinkCmd();
- for (std::string& linkCmd : linkCmds) {
- linkCmd = cmStrCat(launcher, linkCmd);
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- linkCmd, vars);
- }
- // If there is no ranlib the command will be ":". Skip it.
- cm::erase_if(linkCmds, cmNinjaRemoveNoOpCommands());
- rule.Command =
- this->GetLocalGenerator()->BuildCommandLine(linkCmds, config, config);
- // Write the linker rule with response file if needed.
- rule.Comment =
- cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description =
- cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
- rule.Restat = "$RESTAT";
- this->GetGlobalGenerator()->AddRule(rule);
- }
- }
- void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
- const std::string& config)
- {
- const cmMakefile* mf = this->GetMakefile();
- cmNinjaRule rule(this->LanguageLinkerCudaDeviceRule(config));
- rule.Command = this->GetLocalGenerator()->BuildCommandLine(
- { cmStrCat(mf->GetRequiredDefinition("CMAKE_CUDA_DEVICE_LINKER"),
- " -arch=$ARCH $REGISTER -o=$out $in") },
- config, config);
- rule.Comment = "Rule for CUDA device linking.";
- rule.Description = "Linking CUDA $out";
- this->GetGlobalGenerator()->AddRule(rule);
- cmRulePlaceholderExpander::RuleVariables vars;
- vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
- vars.CMTargetType =
- cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()).c_str();
- vars.Language = "CUDA";
- vars.Object = "$out";
- vars.Fatbinary = "$FATBIN";
- vars.RegisterFile = "$REGISTER";
- vars.LinkFlags = "$LINK_FLAGS";
- std::string linker =
- this->GetGeneratorTarget()->GetLinkerTool("CUDA", config);
- vars.Linker = linker.c_str();
- std::string flags = this->GetFlags("CUDA", config);
- vars.Flags = flags.c_str();
- std::string compileCmd = this->GetMakefile()->GetRequiredDefinition(
- "CMAKE_CUDA_DEVICE_LINK_COMPILE");
- auto rulePlaceholderExpander =
- this->GetLocalGenerator()->CreateRulePlaceholderExpander();
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- compileCmd, vars);
- rule.Name = this->LanguageLinkerCudaDeviceCompileRule(config);
- rule.Command = this->GetLocalGenerator()->BuildCommandLine({ compileCmd },
- config, config);
- rule.Comment = "Rule for compiling CUDA device stubs.";
- rule.Description = "Compiling CUDA device stub $out";
- this->GetGlobalGenerator()->AddRule(rule);
- rule.Name = this->LanguageLinkerCudaFatbinaryRule(config);
- rule.Command = this->GetLocalGenerator()->BuildCommandLine(
- { cmStrCat(mf->GetRequiredDefinition("CMAKE_CUDA_FATBINARY"),
- " -64 -cmdline=--compile-only -compress-all -link "
- "--embedded-fatbin=$out $PROFILES") },
- config, config);
- rule.Comment = "Rule for CUDA fatbinaries.";
- rule.Description = "Creating fatbinary $out";
- this->GetGlobalGenerator()->AddRule(rule);
- }
- void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
- const std::string& config)
- {
- cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
- std::string linkRuleName = this->LanguageLinkerRule(config);
- if (!this->GetGlobalGenerator()->HasRule(linkRuleName)) {
- cmNinjaRule rule(std::move(linkRuleName));
- cmRulePlaceholderExpander::RuleVariables vars;
- vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
- vars.CMTargetType = cmState::GetTargetTypeName(targetType).c_str();
- std::string linker = this->GetGeneratorTarget()->GetLinkerTool(config);
- vars.Linker = linker.c_str();
- std::string lang = this->TargetLinkLanguage(config);
- vars.Language = lang.c_str();
- vars.AIXExports = "$AIX_EXPORTS";
- if (this->TargetLinkLanguage(config) == "Swift") {
- vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME";
- vars.SwiftModule = "$SWIFT_MODULE";
- vars.SwiftModuleName = "$SWIFT_MODULE_NAME";
- vars.SwiftSources = "$SWIFT_SOURCES";
- vars.Defines = "$DEFINES";
- vars.Flags = "$FLAGS";
- vars.Includes = "$INCLUDES";
- }
- std::string responseFlag;
- std::string cmakeVarLang =
- cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
- if (this->GeneratorTarget->HasLinkDependencyFile(config)) {
- auto DepFileFormat = this->GetMakefile()->GetDefinition(
- cmStrCat(cmakeVarLang, "_LINKER_DEPFILE_FORMAT"));
- rule.DepType = DepFileFormat;
- rule.DepFile = "$DEP_FILE";
- }
- // build response file name
- std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
- cmValue flag = this->GetMakefile()->GetDefinition(cmakeLinkVar);
- if (flag) {
- responseFlag = *flag;
- } else {
- responseFlag = "@";
- }
- if (!useResponseFile || responseFlag.empty()) {
- vars.Objects = "$in";
- vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
- } else {
- rule.RspFile = "$RSP_FILE";
- responseFlag += rule.RspFile;
- // build response file content
- if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
- rule.RspContent = "$in";
- } else {
- rule.RspContent = "$in_newline";
- }
- // If libraries in rsp is enable
- if (this->CheckUseResponseFileForLibraries(lang)) {
- rule.RspContent += " $LINK_PATH $LINK_LIBRARIES";
- vars.LinkLibraries = "";
- } else {
- vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
- }
- if (this->TargetLinkLanguage(config) == "Swift") {
- vars.SwiftSources = responseFlag.c_str();
- } else {
- vars.Objects = responseFlag.c_str();
- }
- }
- vars.ObjectDir = "$OBJECT_DIR";
- vars.Target = "$TARGET_FILE";
- vars.SONameFlag = "$SONAME_FLAG";
- vars.TargetSOName = "$SONAME";
- vars.TargetInstallNameDir = "$INSTALLNAME_DIR";
- vars.TargetPDB = "$TARGET_PDB";
- // Setup the target version.
- std::string targetVersionMajor;
- std::string targetVersionMinor;
- {
- std::ostringstream majorStream;
- std::ostringstream minorStream;
- int major;
- int minor;
- this->GetGeneratorTarget()->GetTargetVersion(major, minor);
- majorStream << major;
- minorStream << minor;
- targetVersionMajor = majorStream.str();
- targetVersionMinor = minorStream.str();
- }
- vars.TargetVersionMajor = targetVersionMajor.c_str();
- vars.TargetVersionMinor = targetVersionMinor.c_str();
- vars.Flags = "$FLAGS";
- vars.LinkFlags = "$LINK_FLAGS";
- vars.Manifests = "$MANIFESTS";
- std::string langFlags;
- if (targetType != cmStateEnums::EXECUTABLE) {
- langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
- vars.LanguageCompileFlags = langFlags.c_str();
- }
- std::string linkerLauncher = this->GetLinkerLauncher(config);
- if (cmNonempty(linkerLauncher)) {
- vars.Launcher = linkerLauncher.c_str();
- }
- std::string launcher;
- std::string val = this->GetLocalGenerator()->GetRuleLauncher(
- this->GetGeneratorTarget(), "RULE_LAUNCH_LINK", config);
- if (cmNonempty(val)) {
- launcher = cmStrCat(val, ' ');
- }
- auto rulePlaceholderExpander =
- this->GetLocalGenerator()->CreateRulePlaceholderExpander();
- // Rule for linking library/executable.
- std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
- for (std::string& linkCmd : linkCmds) {
- linkCmd = cmStrCat(launcher, linkCmd);
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- linkCmd, vars);
- }
- // If there is no ranlib the command will be ":". Skip it.
- cm::erase_if(linkCmds, cmNinjaRemoveNoOpCommands());
- linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
- linkCmds.emplace_back("$POST_BUILD");
- rule.Command =
- this->GetLocalGenerator()->BuildCommandLine(linkCmds, config, config);
- // Write the linker rule with response file if needed.
- rule.Comment =
- cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
- this->GetVisibleTypeName(), '.');
- rule.Description =
- cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
- this->GetVisibleTypeName(), " $TARGET_FILE");
- rule.Restat = "$RESTAT";
- this->GetGlobalGenerator()->AddRule(rule);
- }
- auto const tgtNames = this->TargetNames(config);
- if (tgtNames.Output != tgtNames.Real &&
- !this->GetGeneratorTarget()->IsFrameworkOnApple()) {
- std::string cmakeCommand =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- if (targetType == cmStateEnums::EXECUTABLE) {
- cmNinjaRule rule("CMAKE_SYMLINK_EXECUTABLE");
- {
- std::vector<std::string> cmd;
- cmd.push_back(cmakeCommand + " -E cmake_symlink_executable $in $out");
- cmd.emplace_back("$POST_BUILD");
- rule.Command =
- this->GetLocalGenerator()->BuildCommandLine(cmd, config, config);
- }
- rule.Description = "Creating executable symlink $out";
- rule.Comment = "Rule for creating executable symlink.";
- this->GetGlobalGenerator()->AddRule(rule);
- } else {
- cmNinjaRule rule("CMAKE_SYMLINK_LIBRARY");
- {
- std::vector<std::string> cmd;
- cmd.push_back(cmakeCommand +
- " -E cmake_symlink_library $in $SONAME $out");
- cmd.emplace_back("$POST_BUILD");
- rule.Command =
- this->GetLocalGenerator()->BuildCommandLine(cmd, config, config);
- }
- rule.Description = "Creating library symlink $out";
- rule.Comment = "Rule for creating library symlink.";
- this->GetGlobalGenerator()->AddRule(rule);
- }
- }
- if (this->GetGeneratorTarget()->IsApple() &&
- this->GetGeneratorTarget()->HasImportLibrary(config)) {
- cmNinjaRule rule(this->TextStubsGeneratorRule(config));
- rule.Comment = cmStrCat("Rule for generating text-based stubs for ",
- this->GetVisibleTypeName(), '.');
- rule.Description = "Creating text-based stubs $out";
- std::string cmd =
- this->GetMakefile()->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
- auto rulePlaceholderExpander =
- this->GetLocalGenerator()->CreateRulePlaceholderExpander();
- cmRulePlaceholderExpander::RuleVariables vars;
- vars.Target = "$in";
- rulePlaceholderExpander->SetTargetImpLib("$out");
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- cmd, vars);
- rule.Command =
- this->GetLocalGenerator()->BuildCommandLine({ cmd }, config, config);
- this->GetGlobalGenerator()->AddRule(rule);
- if (tgtNames.ImportOutput != tgtNames.ImportReal &&
- !this->GetGeneratorTarget()->IsFrameworkOnApple()) {
- cmNinjaRule slRule("CMAKE_SYMLINK_IMPORT_LIBRARY");
- {
- std::string cmakeCommand =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- std::string slCmd =
- cmStrCat(cmakeCommand, " -E cmake_symlink_library $in $SONAME $out");
- slRule.Command = this->GetLocalGenerator()->BuildCommandLine(
- { slCmd }, config, config);
- }
- slRule.Description = "Creating import library symlink $out";
- slRule.Comment = "Rule for creating import library symlink.";
- this->GetGlobalGenerator()->AddRule(slRule);
- }
- }
- }
- std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeDeviceLinkCmd()
- {
- cmList linkCmds;
- // this target requires separable cuda compilation
- // now build the correct command depending on if the target is
- // an executable or a dynamic library.
- switch (this->GetGeneratorTarget()->GetType()) {
- case cmStateEnums::STATIC_LIBRARY:
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY: {
- linkCmds.assign(
- this->GetMakefile()->GetDefinition("CMAKE_CUDA_DEVICE_LINK_LIBRARY"));
- } break;
- case cmStateEnums::EXECUTABLE: {
- linkCmds.assign(this->GetMakefile()->GetDefinition(
- "CMAKE_CUDA_DEVICE_LINK_EXECUTABLE"));
- } break;
- default:
- break;
- }
- return std::move(linkCmds.data());
- }
- std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd(
- const std::string& config)
- {
- cmList linkCmds;
- cmMakefile* mf = this->GetMakefile();
- {
- // If we have a rule variable prefer it. In the case of static libraries
- // this occurs when things like IPO is enabled, and we need to use the
- // CMAKE_<lang>_CREATE_STATIC_LIBRARY_IPO define instead.
- std::string linkCmdVar = this->GetGeneratorTarget()->GetCreateRuleVariable(
- this->TargetLinkLanguage(config), config);
- cmValue linkCmd = mf->GetDefinition(linkCmdVar);
- if (linkCmd) {
- std::string linkCmdStr = *linkCmd;
- if (this->GetGeneratorTarget()->HasImplibGNUtoMS(config)) {
- std::string ruleVar =
- cmStrCat("CMAKE_", this->GeneratorTarget->GetLinkerLanguage(config),
- "_GNUtoMS_RULE");
- if (cmValue rule = this->Makefile->GetDefinition(ruleVar)) {
- linkCmdStr += *rule;
- }
- }
- linkCmds.assign(linkCmdStr);
- if (this->UseLWYU) {
- cmValue lwyuCheck = mf->GetDefinition("CMAKE_LINK_WHAT_YOU_USE_CHECK");
- if (lwyuCheck) {
- std::string cmakeCommand = cmStrCat(
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL),
- " -E __run_co_compile --lwyu=");
- cmakeCommand +=
- this->GetLocalGenerator()->EscapeForShell(*lwyuCheck);
- std::string targetOutputReal =
- this->ConvertToNinjaPath(this->GetGeneratorTarget()->GetFullPath(
- config, cmStateEnums::RuntimeBinaryArtifact,
- /*realname=*/true));
- cmakeCommand += cmStrCat(" --source=", targetOutputReal);
- linkCmds.push_back(std::move(cmakeCommand));
- }
- }
- return std::move(linkCmds.data());
- }
- }
- switch (this->GetGeneratorTarget()->GetType()) {
- case cmStateEnums::STATIC_LIBRARY: {
- // We have archive link commands set. First, delete the existing archive.
- {
- std::string cmakeCommand =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- linkCmds.push_back(cmakeCommand + " -E rm -f $TARGET_FILE");
- }
- // TODO: Use ARCHIVE_APPEND for archives over a certain size.
- {
- std::string linkCmdVar = cmStrCat(
- "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_CREATE");
- linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage(config), config);
- std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
- linkCmds.append(linkCmd);
- }
- {
- std::string linkCmdVar = cmStrCat(
- "CMAKE_", this->TargetLinkLanguage(config), "_ARCHIVE_FINISH");
- linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
- linkCmdVar, this->TargetLinkLanguage(config), config);
- std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
- linkCmds.append(linkCmd);
- }
- #ifdef __APPLE__
- // On macOS ranlib truncates the fractional part of the static archive
- // file modification time. If the archive and at least one contained
- // object file were created within the same second this will make look
- // the archive older than the object file. On subsequent ninja runs this
- // leads to re-achiving and updating dependent targets.
- // As a work-around we touch the archive after ranlib (see #19222).
- {
- std::string cmakeCommand =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- linkCmds.push_back(cmakeCommand + " -E touch $TARGET_FILE");
- }
- #endif
- } break;
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::EXECUTABLE:
- break;
- default:
- assert(false && "Unexpected target type");
- }
- return std::move(linkCmds.data());
- }
- void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement(
- const std::string& config, const std::string& fileConfig,
- bool firstForConfig)
- {
- cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
- if (!globalGen->GetLanguageEnabled("CUDA")) {
- return;
- }
- cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
- bool requiresDeviceLinking = requireDeviceLinking(
- *this->GeneratorTarget, *this->GetLocalGenerator(), config);
- if (!requiresDeviceLinking) {
- return;
- }
- // First and very important step is to make sure while inside this
- // step our link language is set to CUDA
- std::string const& objExt =
- this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
- std::string targetOutputDir =
- cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget),
- globalGen->ConfigDirectory(config), "/");
- targetOutputDir = globalGen->ExpandCFGIntDir(targetOutputDir, config);
- std::string targetOutputReal =
- this->ConvertToNinjaPath(targetOutputDir + "cmake_device_link" + objExt);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal);
- }
- this->DeviceLinkObject = targetOutputReal;
- // Write comments.
- cmGlobalNinjaGenerator::WriteDivider(this->GetCommonFileStream());
- this->GetCommonFileStream()
- << "# Device Link build statements for "
- << cmState::GetTargetTypeName(genTarget->GetType()) << " target "
- << this->GetTargetName() << "\n\n";
- if (this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID") == "Clang") {
- std::string architecturesStr =
- this->GeneratorTarget->GetSafeProperty("CUDA_ARCHITECTURES");
- if (cmIsOff(architecturesStr)) {
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
- "CUDA_SEPARABLE_COMPILATION on Clang "
- "requires CUDA_ARCHITECTURES to be set.");
- return;
- }
- this->WriteDeviceLinkRules(config);
- this->WriteDeviceLinkStatements(config, cmList{ architecturesStr },
- targetOutputReal);
- } else {
- this->WriteNvidiaDeviceLinkStatement(config, fileConfig, targetOutputDir,
- targetOutputReal);
- }
- }
- void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatements(
- const std::string& config, const std::vector<std::string>& architectures,
- const std::string& output)
- {
- // Ensure there are no duplicates.
- const cmNinjaDeps explicitDeps = [&]() -> std::vector<std::string> {
- std::unordered_set<std::string> depsSet;
- const cmNinjaDeps linkDeps =
- this->ComputeLinkDeps(this->TargetLinkLanguage(config), config, true);
- const cmNinjaDeps objects = this->GetObjects(config);
- depsSet.insert(linkDeps.begin(), linkDeps.end());
- depsSet.insert(objects.begin(), objects.end());
- std::vector<std::string> deps;
- std::copy(depsSet.begin(), depsSet.end(), std::back_inserter(deps));
- return deps;
- }();
- cmGlobalNinjaGenerator* globalGen{ this->GetGlobalGenerator() };
- const std::string objectDir =
- cmStrCat(this->GeneratorTarget->GetSupportDirectory(),
- globalGen->ConfigDirectory(config));
- const std::string ninjaOutputDir = this->ConvertToNinjaPath(objectDir);
- cmNinjaBuild fatbinary(this->LanguageLinkerCudaFatbinaryRule(config));
- // Link device code for each architecture.
- for (const std::string& architectureKind : architectures) {
- // Clang always generates real code, so strip the specifier.
- const std::string architecture =
- architectureKind.substr(0, architectureKind.find('-'));
- const std::string cubin =
- cmStrCat(ninjaOutputDir, "/sm_", architecture, ".cubin");
- cmNinjaBuild dlink(this->LanguageLinkerCudaDeviceRule(config));
- dlink.ExplicitDeps = explicitDeps;
- dlink.Outputs = { cubin };
- dlink.Variables["ARCH"] = cmStrCat("sm_", architecture);
- // The generated register file contains macros that when expanded register
- // the device routines. Because the routines are the same for all
- // architectures the register file will be the same too. Thus generate it
- // only on the first invocation to reduce overhead.
- if (fatbinary.ExplicitDeps.empty()) {
- dlink.Variables["REGISTER"] = cmStrCat(
- "--register-link-binaries=", ninjaOutputDir, "/cmake_cuda_register.h");
- }
- fatbinary.Variables["PROFILES"] +=
- cmStrCat(" -im=profile=sm_", architecture, ",file=", cubin);
- fatbinary.ExplicitDeps.emplace_back(cubin);
- globalGen->WriteBuild(this->GetCommonFileStream(), dlink);
- }
- // Combine all architectures into a single fatbinary.
- fatbinary.Outputs = { cmStrCat(ninjaOutputDir, "/cmake_cuda_fatbin.h") };
- globalGen->WriteBuild(this->GetCommonFileStream(), fatbinary);
- // Compile the stub that registers the kernels and contains the fatbinaries.
- cmLocalNinjaGenerator* localGen{ this->GetLocalGenerator() };
- cmNinjaBuild dcompile(this->LanguageLinkerCudaDeviceCompileRule(config));
- dcompile.Outputs = { output };
- dcompile.ExplicitDeps = { cmStrCat(ninjaOutputDir, "/cmake_cuda_fatbin.h") };
- dcompile.Variables["FATBIN"] = localGen->ConvertToOutputFormat(
- cmStrCat(objectDir, "/cmake_cuda_fatbin.h"), cmOutputConverter::SHELL);
- dcompile.Variables["REGISTER"] = localGen->ConvertToOutputFormat(
- cmStrCat(objectDir, "/cmake_cuda_register.h"), cmOutputConverter::SHELL);
- cmNinjaLinkLineDeviceComputer linkLineComputer(
- localGen, localGen->GetStateSnapshot().GetDirectory(), globalGen);
- linkLineComputer.SetUseNinjaMulti(globalGen->IsMultiConfig());
- // Link libraries and paths are only used during the final executable/library
- // link.
- std::string frameworkPath;
- std::string linkPath;
- std::string linkLibs;
- localGen->GetDeviceLinkFlags(linkLineComputer, config, linkLibs,
- dcompile.Variables["LINK_FLAGS"], frameworkPath,
- linkPath, this->GetGeneratorTarget());
- globalGen->WriteBuild(this->GetCommonFileStream(), dcompile);
- }
- void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement(
- const std::string& config, const std::string& fileConfig,
- const std::string& outputDir, const std::string& output)
- {
- cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
- cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
- std::string targetOutputImplib = this->ConvertToNinjaPath(
- genTarget->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
- if (config != fileConfig) {
- std::string targetOutputFileConfigDir =
- cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget),
- globalGen->ConfigDirectory(fileConfig), "/");
- targetOutputFileConfigDir =
- globalGen->ExpandCFGIntDir(outputDir, fileConfig);
- if (outputDir == targetOutputFileConfigDir) {
- return;
- }
- if (!genTarget->GetFullName(config, cmStateEnums::ImportLibraryArtifact)
- .empty() &&
- !genTarget
- ->GetFullName(fileConfig, cmStateEnums::ImportLibraryArtifact)
- .empty() &&
- targetOutputImplib ==
- this->ConvertToNinjaPath(genTarget->GetFullPath(
- fileConfig, cmStateEnums::ImportLibraryArtifact))) {
- return;
- }
- }
- // Compute the comment.
- cmNinjaBuild build(this->LanguageLinkerDeviceRule(config));
- build.Comment =
- cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', output);
- cmNinjaVars& vars = build.Variables;
- // Compute outputs.
- build.Outputs.push_back(output);
- // Compute specific libraries to link with.
- build.ExplicitDeps = this->GetObjects(config);
- build.ImplicitDeps =
- this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
- std::string frameworkPath;
- std::string linkPath;
- std::string createRule =
- genTarget->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
- cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
- vars["TARGET_FILE"] =
- localGen.ConvertToOutputFormat(output, cmOutputConverter::SHELL);
- cmNinjaLinkLineDeviceComputer linkLineComputer(
- this->GetLocalGenerator(),
- this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), globalGen);
- linkLineComputer.SetUseNinjaMulti(globalGen->IsMultiConfig());
- localGen.GetDeviceLinkFlags(linkLineComputer, config, vars["LINK_LIBRARIES"],
- vars["LINK_FLAGS"], frameworkPath, linkPath,
- genTarget);
- this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);
- vars["MANIFESTS"] = this->GetManifests(config);
- vars["LINK_PATH"] = frameworkPath + linkPath;
- // Compute language specific link flags.
- std::string langFlags;
- localGen.AddLanguageFlagsForLinking(langFlags, genTarget, "CUDA", config);
- vars["LANGUAGE_COMPILE_FLAGS"] = langFlags;
- auto const tgtNames = this->TargetNames(config);
- if (genTarget->HasSOName(config)) {
- vars["SONAME_FLAG"] =
- this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage(config));
- vars["SONAME"] = localGen.ConvertToOutputFormat(tgtNames.SharedObject,
- cmOutputConverter::SHELL);
- if (genTarget->GetType() == cmStateEnums::SHARED_LIBRARY) {
- std::string install_dir =
- this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(config);
- if (!install_dir.empty()) {
- vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
- install_dir, cmOutputConverter::SHELL);
- }
- }
- }
- if (!tgtNames.ImportLibrary.empty()) {
- const std::string impLibPath = localGen.ConvertToOutputFormat(
- targetOutputImplib, cmOutputConverter::SHELL);
- vars["TARGET_IMPLIB"] = impLibPath;
- this->EnsureParentDirectoryExists(targetOutputImplib);
- }
- const std::string objPath =
- cmStrCat(this->GetGeneratorTarget()->GetSupportDirectory(),
- globalGen->ConfigDirectory(config));
- vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
- this->EnsureDirectoryExists(objPath);
- this->SetMsvcTargetPdbVariable(vars, config);
- std::string& linkLibraries = vars["LINK_LIBRARIES"];
- std::string& link_path = vars["LINK_PATH"];
- if (globalGen->IsGCCOnWindows()) {
- // ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
- std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
- std::replace(link_path.begin(), link_path.end(), '\\', '/');
- }
- // Device linking currently doesn't support response files so
- // do not check if the user has explicitly forced a response file.
- int const commandLineLengthLimit =
- static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen->GetRuleCmdLength(build.Rule);
- build.RspFile = this->ConvertToNinjaPath(
- cmStrCat("CMakeFiles/", genTarget->GetName(),
- globalGen->IsMultiConfig() ? cmStrCat('.', config) : "", ".rsp"));
- // Gather order-only dependencies.
- this->GetLocalGenerator()->AppendTargetDepends(
- this->GetGeneratorTarget(), build.OrderOnlyDeps, config, config,
- DependOnTargetArtifact);
- // Write the build statement for this target.
- bool usedResponseFile = false;
- globalGen->WriteBuild(this->GetCommonFileStream(), build,
- commandLineLengthLimit, &usedResponseFile);
- this->WriteNvidiaDeviceLinkRule(usedResponseFile, config);
- }
- /// Get the target property if it exists, or return a default
- static std::string GetTargetPropertyOrDefault(cmGeneratorTarget const* target,
- std::string const& property,
- std::string defaultValue)
- {
- if (cmValue name = target->GetProperty(property)) {
- return *name;
- }
- return defaultValue;
- }
- /// Compute the swift module name for target
- static std::string GetSwiftModuleName(cmGeneratorTarget const* target)
- {
- return GetTargetPropertyOrDefault(target, "Swift_MODULE_NAME",
- target->GetName());
- }
- /// Compute the swift module path for the target
- /// The returned path will need to be converted to the generator path
- static std::string GetSwiftModulePath(cmGeneratorTarget const* target)
- {
- std::string moduleName = GetSwiftModuleName(target);
- std::string moduleDirectory = GetTargetPropertyOrDefault(
- target, "Swift_MODULE_DIRECTORY",
- target->LocalGenerator->GetCurrentBinaryDirectory());
- std::string moduleFileName = GetTargetPropertyOrDefault(
- target, "Swift_MODULE", moduleName + ".swiftmodule");
- return moduleDirectory + "/" + moduleFileName;
- }
- void cmNinjaNormalTargetGenerator::WriteLinkStatement(
- const std::string& config, const std::string& fileConfig,
- bool firstForConfig)
- {
- cmMakefile* mf = this->GetMakefile();
- cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
- cmGeneratorTarget* gt = this->GetGeneratorTarget();
- std::string targetOutput = this->ConvertToNinjaPath(gt->GetFullPath(config));
- std::string targetOutputReal = this->ConvertToNinjaPath(
- gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact,
- /*realname=*/true));
- std::string targetOutputImplib = this->ConvertToNinjaPath(
- gt->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
- if (config != fileConfig) {
- if (targetOutput ==
- this->ConvertToNinjaPath(gt->GetFullPath(fileConfig))) {
- return;
- }
- if (targetOutputReal ==
- this->ConvertToNinjaPath(
- gt->GetFullPath(fileConfig, cmStateEnums::RuntimeBinaryArtifact,
- /*realname=*/true))) {
- return;
- }
- if (!gt->GetFullName(config, cmStateEnums::ImportLibraryArtifact)
- .empty() &&
- !gt->GetFullName(fileConfig, cmStateEnums::ImportLibraryArtifact)
- .empty() &&
- targetOutputImplib ==
- this->ConvertToNinjaPath(gt->GetFullPath(
- fileConfig, cmStateEnums::ImportLibraryArtifact))) {
- return;
- }
- }
- auto const tgtNames = this->TargetNames(config);
- if (gt->IsAppBundleOnApple()) {
- // Create the app bundle
- std::string outpath = gt->GetDirectory(config);
- this->OSXBundleGenerator->CreateAppBundle(tgtNames.Output, outpath,
- config);
- // Calculate the output path
- targetOutput = cmStrCat(outpath, '/', tgtNames.Output);
- targetOutput = this->ConvertToNinjaPath(targetOutput);
- targetOutputReal = cmStrCat(outpath, '/', tgtNames.Real);
- targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
- } else if (gt->IsFrameworkOnApple()) {
- // Create the library framework.
- cmOSXBundleGenerator::SkipParts bundleSkipParts;
- if (globalGen->GetName() == "Ninja Multi-Config") {
- const auto postFix = this->GeneratorTarget->GetFilePostfix(config);
- // Skip creating Info.plist when there are multiple configurations, and
- // the current configuration has a postfix. The non-postfix configuration
- // Info.plist can be used by all the other configurations.
- if (!postFix.empty()) {
- bundleSkipParts.InfoPlist = true;
- }
- }
- if (gt->HasImportLibrary(config)) {
- bundleSkipParts.TextStubs = false;
- }
- this->OSXBundleGenerator->CreateFramework(
- tgtNames.Output, gt->GetDirectory(config), config, bundleSkipParts);
- } else if (gt->IsCFBundleOnApple()) {
- // Create the core foundation bundle.
- this->OSXBundleGenerator->CreateCFBundle(tgtNames.Output,
- gt->GetDirectory(config), config);
- }
- // Write comments.
- cmGlobalNinjaGenerator::WriteDivider(this->GetImplFileStream(fileConfig));
- const cmStateEnums::TargetType targetType = gt->GetType();
- this->GetImplFileStream(fileConfig)
- << "# Link build statements for " << cmState::GetTargetTypeName(targetType)
- << " target " << this->GetTargetName() << "\n\n";
- cmNinjaBuild linkBuild(this->LanguageLinkerRule(config));
- cmNinjaVars& vars = linkBuild.Variables;
- if (this->GeneratorTarget->HasLinkDependencyFile(config)) {
- vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- this->ConvertToNinjaPath(
- this->GetLocalGenerator()->GetLinkDependencyFile(this->GeneratorTarget,
- config)),
- cmOutputConverter::SHELL);
- }
- // Compute the comment.
- linkBuild.Comment =
- cmStrCat("Link the ", this->GetVisibleTypeName(), ' ', targetOutputReal);
- // Compute outputs.
- linkBuild.Outputs.push_back(targetOutputReal);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal);
- }
- if (this->TargetLinkLanguage(config) == "Swift") {
- vars["SWIFT_LIBRARY_NAME"] = [this, config]() -> std::string {
- cmGeneratorTarget::Names targetNames =
- this->GetGeneratorTarget()->GetLibraryNames(config);
- return targetNames.Base;
- }();
- vars["SWIFT_MODULE_NAME"] = GetSwiftModuleName(gt);
- vars["SWIFT_MODULE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- this->ConvertToNinjaPath(GetSwiftModulePath(gt)),
- cmOutputConverter::SHELL);
- vars["SWIFT_SOURCES"] = [this, config]() -> std::string {
- std::vector<cmSourceFile const*> sources;
- std::stringstream oss;
- this->GetGeneratorTarget()->GetObjectSources(sources, config);
- cmLocalGenerator const* LocalGen = this->GetLocalGenerator();
- for (const auto& source : sources) {
- const std::string sourcePath = source->GetLanguage() == "Swift"
- ? this->GetCompiledSourceNinjaPath(source)
- : this->GetObjectFilePath(source, config);
- oss << " "
- << LocalGen->ConvertToOutputFormat(sourcePath,
- cmOutputConverter::SHELL);
- }
- return oss.str();
- }();
- // Since we do not perform object builds, compute the
- // defines/flags/includes here so that they can be passed along
- // appropriately.
- vars["DEFINES"] = this->GetDefines("Swift", config);
- vars["FLAGS"] = this->GetFlags("Swift", config);
- vars["INCLUDES"] = this->GetIncludes("Swift", config);
- this->GenerateSwiftOutputFileMap(config, vars["FLAGS"]);
- }
- // Compute specific libraries to link with.
- if (this->TargetLinkLanguage(config) == "Swift") {
- std::vector<cmSourceFile const*> sources;
- gt->GetObjectSources(sources, config);
- for (const auto& source : sources) {
- if (source->GetLanguage() == "Swift") {
- linkBuild.Outputs.push_back(
- this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)));
- linkBuild.ExplicitDeps.emplace_back(
- this->GetCompiledSourceNinjaPath(source));
- } else {
- linkBuild.ExplicitDeps.emplace_back(
- this->GetObjectFilePath(source, config));
- }
- }
- if (targetType != cmStateEnums::EXECUTABLE ||
- gt->IsExecutableWithExports()) {
- linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
- }
- } else {
- linkBuild.ExplicitDeps = this->GetObjects(config);
- }
- std::vector<std::string> extraISPCObjects =
- this->GetGeneratorTarget()->GetGeneratedISPCObjects(config);
- std::transform(extraISPCObjects.begin(), extraISPCObjects.end(),
- std::back_inserter(linkBuild.ExplicitDeps),
- this->MapToNinjaPath());
- linkBuild.ImplicitDeps =
- this->ComputeLinkDeps(this->TargetLinkLanguage(config), config);
- if (!this->DeviceLinkObject.empty()) {
- linkBuild.ExplicitDeps.push_back(this->DeviceLinkObject);
- }
- std::string frameworkPath;
- std::string linkPath;
- std::string createRule =
- gt->GetCreateRuleVariable(this->TargetLinkLanguage(config), config);
- bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE");
- cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
- vars["TARGET_FILE"] =
- localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL);
- std::unique_ptr<cmLinkLineComputer> linkLineComputer =
- globalGen->CreateLinkLineComputer(
- this->GetLocalGenerator(),
- this->GetLocalGenerator()->GetStateSnapshot().GetDirectory());
- linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
- linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig());
- localGen.GetTargetFlags(linkLineComputer.get(), config,
- vars["LINK_LIBRARIES"], vars["FLAGS"],
- vars["LINK_FLAGS"], frameworkPath, linkPath, gt);
- // Add OS X version flags, if any.
- if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
- this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
- this->AppendOSXVerFlag(vars["LINK_FLAGS"],
- this->TargetLinkLanguage(config), "COMPATIBILITY",
- true);
- this->AppendOSXVerFlag(vars["LINK_FLAGS"],
- this->TargetLinkLanguage(config), "CURRENT", false);
- }
- this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars);
- this->UseLWYU = this->GetLocalGenerator()->AppendLWYUFlags(
- vars["LINK_FLAGS"], this->GetGeneratorTarget(),
- this->TargetLinkLanguage(config));
- vars["MANIFESTS"] = this->GetManifests(config);
- vars["AIX_EXPORTS"] = this->GetAIXExports(config);
- vars["LINK_PATH"] = frameworkPath + linkPath;
- // Compute architecture specific link flags. Yes, these go into a different
- // variable for executables, probably due to a mistake made when duplicating
- // code between the Makefile executable and library generators.
- if (targetType == cmStateEnums::EXECUTABLE) {
- std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
- config);
- vars["FLAGS"] = t;
- } else {
- std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, gt, this->TargetLinkLanguage(config),
- config);
- vars["ARCH_FLAGS"] = t;
- t.clear();
- localGen.AddLanguageFlagsForLinking(
- t, gt, this->TargetLinkLanguage(config), config);
- vars["LANGUAGE_COMPILE_FLAGS"] = t;
- }
- if (gt->HasSOName(config)) {
- vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage(config));
- vars["SONAME"] = localGen.ConvertToOutputFormat(tgtNames.SharedObject,
- cmOutputConverter::SHELL);
- if (targetType == cmStateEnums::SHARED_LIBRARY) {
- std::string install_dir = gt->GetInstallNameDirForBuildTree(config);
- if (!install_dir.empty()) {
- vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
- install_dir, cmOutputConverter::SHELL);
- }
- }
- }
- cmGlobalNinjaGenerator::CCOutputs byproducts(this->GetGlobalGenerator());
- if (!gt->IsApple() && !tgtNames.ImportLibrary.empty()) {
- const std::string impLibPath = localGen.ConvertToOutputFormat(
- targetOutputImplib, cmOutputConverter::SHELL);
- vars["TARGET_IMPLIB"] = impLibPath;
- this->EnsureParentDirectoryExists(targetOutputImplib);
- if (gt->HasImportLibrary(config)) {
- // Some linkers may update a binary without touching its import lib.
- byproducts.ExplicitOuts.emplace_back(targetOutputImplib);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(
- targetOutputImplib);
- }
- }
- }
- if (!this->SetMsvcTargetPdbVariable(vars, config)) {
- // It is common to place debug symbols at a specific place,
- // so we need a plain target name in the rule available.
- cmGeneratorTarget::NameComponents const& components =
- gt->GetFullNameComponents(config);
- std::string dbg_suffix = ".dbg";
- // TODO: Where to document?
- if (cmValue d = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) {
- dbg_suffix = *d;
- }
- vars["TARGET_PDB"] = components.base + components.suffix + dbg_suffix;
- }
- const std::string objPath =
- cmStrCat(gt->GetSupportDirectory(), globalGen->ConfigDirectory(config));
- vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
- this->EnsureDirectoryExists(objPath);
- std::string& linkLibraries = vars["LINK_LIBRARIES"];
- std::string& link_path = vars["LINK_PATH"];
- if (globalGen->IsGCCOnWindows()) {
- // ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
- std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
- std::replace(link_path.begin(), link_path.end(), '\\', '/');
- }
- const std::vector<cmCustomCommand>* cmdLists[3] = {
- >->GetPreBuildCommands(), >->GetPreLinkCommands(),
- >->GetPostBuildCommands()
- };
- std::vector<std::string> preLinkCmdLines;
- std::vector<std::string> postBuildCmdLines;
- std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines,
- &preLinkCmdLines,
- &postBuildCmdLines };
- for (unsigned i = 0; i != 3; ++i) {
- for (cmCustomCommand const& cc : *cmdLists[i]) {
- if (config == fileConfig ||
- this->GetLocalGenerator()->HasUniqueByproducts(cc.GetByproducts(),
- cc.GetBacktrace())) {
- cmCustomCommandGenerator ccg(cc, fileConfig, this->GetLocalGenerator(),
- true, config);
- localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
- std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
- byproducts.Add(ccByproducts);
- std::transform(
- ccByproducts.begin(), ccByproducts.end(),
- std::back_inserter(globalGen->GetByproductsForCleanTarget()),
- this->MapToNinjaPath());
- }
- }
- }
- // maybe create .def file from list of objects
- cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- gt->GetModuleDefinitionInfo(config);
- if (mdi && mdi->DefFileGenerated) {
- std::string cmakeCommand =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- std::string cmd =
- cmStrCat(cmakeCommand, " -E __create_def ",
- this->GetLocalGenerator()->ConvertToOutputFormat(
- mdi->DefFile, cmOutputConverter::SHELL),
- ' ');
- std::string obj_list_file = mdi->DefFile + ".objs";
- cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
- obj_list_file, cmOutputConverter::SHELL);
- cmValue nm_executable = this->GetMakefile()->GetDefinition("CMAKE_NM");
- if (cmNonempty(nm_executable)) {
- cmd += " --nm=";
- cmd += this->LocalCommonGenerator->ConvertToOutputFormat(
- *nm_executable, cmOutputConverter::SHELL);
- }
- preLinkCmdLines.push_back(std::move(cmd));
- // create a list of obj files for the -E __create_def to read
- cmGeneratedFileStream fout(obj_list_file);
- if (mdi->WindowsExportAllSymbols) {
- cmNinjaDeps objs = this->GetObjects(config);
- for (std::string const& obj : objs) {
- if (cmHasLiteralSuffix(obj, ".obj")) {
- fout << obj << "\n";
- }
- }
- }
- for (cmSourceFile const* src : mdi->Sources) {
- fout << src->GetFullPath() << "\n";
- }
- }
- // If we have any PRE_LINK commands, we need to go back to CMAKE_BINARY_DIR
- // for the link commands.
- if (!preLinkCmdLines.empty()) {
- const std::string homeOutDir = localGen.ConvertToOutputFormat(
- localGen.GetBinaryDirectory(), cmOutputConverter::SHELL);
- preLinkCmdLines.push_back("cd " + homeOutDir);
- }
- vars["PRE_LINK"] = localGen.BuildCommandLine(
- preLinkCmdLines, config, fileConfig, "pre-link", this->GeneratorTarget);
- std::string postBuildCmdLine =
- localGen.BuildCommandLine(postBuildCmdLines, config, fileConfig,
- "post-build", this->GeneratorTarget);
- cmNinjaVars symlinkVars;
- bool const symlinkNeeded =
- (targetOutput != targetOutputReal && !gt->IsFrameworkOnApple());
- if (!symlinkNeeded) {
- vars["POST_BUILD"] = postBuildCmdLine;
- } else {
- vars["POST_BUILD"] = cmGlobalNinjaGenerator::SHELL_NOOP;
- symlinkVars["POST_BUILD"] = postBuildCmdLine;
- }
- std::string cmakeVarLang =
- cmStrCat("CMAKE_", this->TargetLinkLanguage(config));
- // build response file name
- std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
- cmValue flag = this->GetMakefile()->GetDefinition(cmakeLinkVar);
- bool const lang_supports_response =
- !(this->TargetLinkLanguage(config) == "RC" ||
- (this->TargetLinkLanguage(config) == "CUDA" && !flag));
- int commandLineLengthLimit = -1;
- if (!lang_supports_response || !this->ForceResponseFile()) {
- commandLineLengthLimit =
- static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen->GetRuleCmdLength(linkBuild.Rule);
- }
- linkBuild.RspFile = this->ConvertToNinjaPath(
- cmStrCat("CMakeFiles/", gt->GetName(),
- globalGen->IsMultiConfig() ? cmStrCat('.', config) : "", ".rsp"));
- // Gather order-only dependencies.
- this->GetLocalGenerator()->AppendTargetDepends(
- gt, linkBuild.OrderOnlyDeps, config, fileConfig, DependOnTargetArtifact);
- // Add order-only dependencies on versioning symlinks of shared libs we link.
- // If our target is not producing a runtime binary, it doesn't need the
- // symlinks (anything that links to the target might, but that consumer will
- // get its own order-only dependency).
- if (!gt->IsDLLPlatform() && gt->IsRuntimeBinary()) {
- if (cmComputeLinkInformation* cli = gt->GetLinkInformation(config)) {
- for (auto const& item : cli->GetItems()) {
- if (item.Target &&
- item.Target->GetType() == cmStateEnums::SHARED_LIBRARY &&
- !item.Target->IsFrameworkOnApple()) {
- std::string const& lib =
- this->ConvertToNinjaPath(item.Target->GetFullPath(config));
- if (std::find(linkBuild.ImplicitDeps.begin(),
- linkBuild.ImplicitDeps.end(),
- lib) == linkBuild.ImplicitDeps.end()) {
- linkBuild.OrderOnlyDeps.emplace_back(lib);
- }
- }
- }
- }
- }
- // Add dependencies on swiftmodule files when using the swift linker
- if (this->TargetLinkLanguage(config) == "Swift") {
- if (cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(config)) {
- for (auto const& dependency : cli->GetItems()) {
- // Both the current target and the linked target must be swift targets
- // in order for there to be a swiftmodule to depend on
- if (dependency.Target &&
- dependency.Target->GetLinkerLanguage(config) == "Swift") {
- std::string swiftmodule =
- this->ConvertToNinjaPath(GetSwiftModulePath(dependency.Target));
- linkBuild.ImplicitDeps.emplace_back(swiftmodule);
- }
- }
- }
- }
- // Ninja should restat after linking if and only if there are byproducts.
- vars["RESTAT"] = byproducts.ExplicitOuts.empty() ? "" : "1";
- linkBuild.Outputs.reserve(linkBuild.Outputs.size() +
- byproducts.ExplicitOuts.size());
- std::move(byproducts.ExplicitOuts.begin(), byproducts.ExplicitOuts.end(),
- std::back_inserter(linkBuild.Outputs));
- linkBuild.WorkDirOuts = std::move(byproducts.WorkDirOuts);
- // Write the build statement for this target.
- bool usedResponseFile = false;
- globalGen->WriteBuild(this->GetImplFileStream(fileConfig), linkBuild,
- commandLineLengthLimit, &usedResponseFile);
- this->WriteLinkRule(usedResponseFile, config);
- if (symlinkNeeded) {
- if (targetType == cmStateEnums::EXECUTABLE) {
- cmNinjaBuild build("CMAKE_SYMLINK_EXECUTABLE");
- build.Comment = "Create executable symlink " + targetOutput;
- build.Outputs.push_back(targetOutput);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(targetOutput);
- }
- build.ExplicitDeps.push_back(targetOutputReal);
- build.Variables = std::move(symlinkVars);
- globalGen->WriteBuild(this->GetImplFileStream(fileConfig), build);
- } else {
- cmNinjaBuild build("CMAKE_SYMLINK_LIBRARY");
- build.Comment = "Create library symlink " + targetOutput;
- std::string const soName = this->ConvertToNinjaPath(
- this->GetTargetFilePath(tgtNames.SharedObject, config));
- // If one link has to be created.
- if (targetOutputReal == soName || targetOutput == soName) {
- symlinkVars["SONAME"] =
- this->GetLocalGenerator()->ConvertToOutputFormat(
- soName, cmOutputConverter::SHELL);
- } else {
- symlinkVars["SONAME"].clear();
- build.Outputs.push_back(soName);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(soName);
- }
- }
- build.Outputs.push_back(targetOutput);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(targetOutput);
- }
- build.ExplicitDeps.push_back(targetOutputReal);
- build.Variables = std::move(symlinkVars);
- globalGen->WriteBuild(this->GetImplFileStream(fileConfig), build);
- }
- }
- // Add aliases for the file name and the target name.
- globalGen->AddTargetAlias(tgtNames.Output, gt, config);
- globalGen->AddTargetAlias(this->GetTargetName(), gt, config);
- if (this->GetGeneratorTarget()->IsApple() &&
- this->GetGeneratorTarget()->HasImportLibrary(config)) {
- auto dirTBD =
- gt->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
- auto targetTBD =
- this->ConvertToNinjaPath(cmStrCat(dirTBD, '/', tgtNames.ImportReal));
- this->EnsureParentDirectoryExists(targetTBD);
- cmNinjaBuild build(this->TextStubsGeneratorRule(config));
- build.Comment = cmStrCat("Generate the text-based stubs file ", targetTBD);
- build.Outputs.push_back(targetTBD);
- build.ExplicitDeps.push_back(targetOutputReal);
- globalGen->WriteBuild(this->GetImplFileStream(fileConfig), build);
- if (tgtNames.ImportOutput != tgtNames.ImportReal &&
- !this->GetGeneratorTarget()->IsFrameworkOnApple()) {
- auto outputTBD =
- this->ConvertToNinjaPath(cmStrCat(dirTBD, '/', tgtNames.ImportOutput));
- std::string const soNameTBD = this->ConvertToNinjaPath(
- cmStrCat(dirTBD, '/', tgtNames.ImportLibrary));
- cmNinjaBuild slBuild("CMAKE_SYMLINK_IMPORT_LIBRARY");
- slBuild.Comment = cmStrCat("Create import library symlink ", outputTBD);
- cmNinjaVars slVars;
- // If one link has to be created.
- if (targetTBD == soNameTBD || outputTBD == soNameTBD) {
- slVars["SONAME"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- soNameTBD, cmOutputConverter::SHELL);
- } else {
- slVars["SONAME"].clear();
- slBuild.Outputs.push_back(soNameTBD);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(soNameTBD);
- }
- }
- slBuild.Outputs.push_back(outputTBD);
- if (firstForConfig) {
- globalGen->GetByproductsForCleanTarget(config).push_back(outputTBD);
- }
- slBuild.ExplicitDeps.push_back(targetTBD);
- slBuild.Variables = std::move(slVars);
- globalGen->WriteBuild(this->GetImplFileStream(fileConfig), slBuild);
- }
- // Add alias for the import file name
- globalGen->AddTargetAlias(tgtNames.ImportOutput, gt, config);
- }
- }
- void cmNinjaNormalTargetGenerator::WriteObjectLibStatement(
- const std::string& config)
- {
- // Write a phony output that depends on all object files.
- {
- cmNinjaBuild build("phony");
- build.Comment = "Object library " + this->GetTargetName();
- this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- build.Outputs, config);
- this->GetLocalGenerator()->AppendTargetOutputs(
- this->GetGeneratorTarget(),
- this->GetGlobalGenerator()->GetByproductsForCleanTarget(config), config);
- build.ExplicitDeps = this->GetObjects(config);
- this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), build);
- }
- // Add aliases for the target name.
- this->GetGlobalGenerator()->AddTargetAlias(
- this->GetTargetName(), this->GetGeneratorTarget(), config);
- }
- void cmNinjaNormalTargetGenerator::WriteCxxModuleLibraryStatement(
- const std::string& config, const std::string& /*fileConfig*/,
- bool firstForConfig)
- {
- // TODO: How to use `fileConfig` properly?
- // Write a phony output that depends on the scanning output.
- {
- cmNinjaBuild build("phony");
- build.Comment =
- cmStrCat("Imported C++ module library ", this->GetTargetName());
- this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- build.Outputs, config);
- if (firstForConfig) {
- this->GetLocalGenerator()->AppendTargetOutputs(
- this->GetGeneratorTarget(),
- this->GetGlobalGenerator()->GetByproductsForCleanTarget(config),
- config);
- }
- build.ExplicitDeps.emplace_back(this->GetDyndepFilePath("CXX", config));
- this->GetGlobalGenerator()->WriteBuild(this->GetCommonFileStream(), build);
- }
- // Add aliases for the target name.
- this->GetGlobalGenerator()->AddTargetAlias(
- this->GetTargetName(), this->GetGeneratorTarget(), config);
- }
- cmGeneratorTarget::Names cmNinjaNormalTargetGenerator::TargetNames(
- const std::string& config) const
- {
- if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
- return this->GeneratorTarget->GetExecutableNames(config);
- }
- return this->GeneratorTarget->GetLibraryNames(config);
- }
- std::string cmNinjaNormalTargetGenerator::TargetLinkLanguage(
- const std::string& config) const
- {
- return this->GeneratorTarget->GetLinkerLanguage(config);
- }
|