From dfba904178a84c2f2cbdfd9d4bb555fe8cdcda0b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 28 May 2025 17:24:48 +0200 Subject: [PATCH] Ninja: populate the `TARGET_SUPPORT_DIR` replacement variable --- Source/cmNinjaNormalTargetGenerator.cxx | 16 ++++++++++++ Source/cmNinjaTargetGenerator.cxx | 34 +++++++++++++++++-------- Source/cmNinjaTargetGenerator.h | 11 ++++---- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 2389cbe738..99bc91a8c4 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -332,6 +332,7 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule( } vars.ObjectDir = "$OBJECT_DIR"; + vars.TargetSupportDir = "$TARGET_SUPPORT_DIR"; vars.Target = "$TARGET_FILE"; @@ -532,6 +533,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule( } vars.ObjectDir = "$OBJECT_DIR"; + vars.TargetSupportDir = "$TARGET_SUPPORT_DIR"; vars.Target = "$TARGET_FILE"; @@ -1075,6 +1077,14 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL); this->EnsureDirectoryExists(objPath); + std::string const targetSupportPath = + this->GetGeneratorTarget()->GetCMFSupportDirectory(); + + vars["TARGET_SUPPORT_DIR"] = + this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(targetSupportPath), cmOutputConverter::SHELL); + this->EnsureDirectoryExists(targetSupportPath); + this->SetMsvcTargetPdbVariable(vars, config); std::string& linkLibraries = vars["LINK_LIBRARIES"]; @@ -1397,6 +1407,12 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL); this->EnsureDirectoryExists(objPath); + std::string const targetSupportPath = gt->GetCMFSupportDirectory(); + vars["TARGET_SUPPORT_DIR"] = + this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(targetSupportPath), cmOutputConverter::SHELL); + this->EnsureDirectoryExists(targetSupportPath); + std::string& linkLibraries = vars["LINK_LIBRARIES"]; std::string& link_path = vars["LINK_PATH"]; if (globalGen->IsGCCOnWindows()) { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 40e057e645..11ff6a7cfc 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -666,6 +666,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(std::string const& lang, vars.TargetPDB = "$TARGET_PDB"; vars.TargetCompilePDB = "$TARGET_COMPILE_PDB"; vars.ObjectDir = "$OBJECT_DIR"; + vars.TargetSupportDir = "$TARGET_SUPPORT_DIR"; vars.ObjectFileDir = "$OBJECT_FILE_DIR"; vars.CudaCompileMode = "$CUDA_COMPILE_MODE"; vars.ISPCHeader = "$ISPC_HEADER_FILE"; @@ -1377,6 +1378,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( { std::string const language = source->GetLanguage(); std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source); + std::string const targetSupportDir = + this->ConvertToNinjaPath(this->GeneratorTarget->GetCMFSupportDirectory()); std::string const objectDir = this->ConvertToNinjaPath(this->GetObjectFileDir(config)); std::string const objectFileName = @@ -1460,8 +1463,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (firstForConfig) { this->ExportObjectCompileCommand( - language, sourceFilePath, objectDir, objectFileName, objectFileDir, - vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"], + language, sourceFilePath, objectDir, targetSupportDir, objectFileName, + objectFileDir, vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"], vars["TARGET_COMPILE_PDB"], vars["TARGET_PDB"], config, withScanning); } @@ -1635,6 +1638,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( objectDir, cmOutputConverter::SHELL); + vars["TARGET_SUPPORT_DIR"] = + this->GetLocalGenerator()->ConvertToOutputFormat(targetSupportDir, + cmOutputConverter::SHELL); vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( objectFileDir, cmOutputConverter::SHELL); @@ -1748,6 +1754,8 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement( } std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source); + std::string const targetSupportDir = + this->ConvertToNinjaPath(this->GeneratorTarget->GetCMFSupportDirectory()); std::string const bmiDir = this->ConvertToNinjaPath( cmStrCat(this->GeneratorTarget->GetSupportDirectory(), this->GetGlobalGenerator()->ConfigDirectory(config))); @@ -1799,9 +1807,10 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement( if (firstForConfig) { this->ExportObjectCompileCommand( - language, sourceFilePath, bmiDir, bmiFileName, bmiFileDir, vars["FLAGS"], - vars["DEFINES"], vars["INCLUDES"], vars["TARGET_COMPILE_PDB"], - vars["TARGET_PDB"], config, WithScanning::Yes); + language, sourceFilePath, bmiDir, targetSupportDir, bmiFileName, + bmiFileDir, vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"], + vars["TARGET_COMPILE_PDB"], vars["TARGET_PDB"], config, + WithScanning::Yes); } bmiBuild.Outputs.push_back(bmiFileName); @@ -1860,6 +1869,9 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement( vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( bmiDir, cmOutputConverter::SHELL); + vars["TARGET_SUPPORT_DIR"] = + this->GetLocalGenerator()->ConvertToOutputFormat(targetSupportDir, + cmOutputConverter::SHELL); vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat( bmiFileDir, cmOutputConverter::SHELL); @@ -2203,11 +2215,12 @@ void cmNinjaTargetGenerator::EmitSwiftDependencyInfo( void cmNinjaTargetGenerator::ExportObjectCompileCommand( std::string const& language, std::string const& sourceFileName, - std::string const& objectDir, std::string const& objectFileName, - std::string const& objectFileDir, std::string const& flags, - std::string const& defines, std::string const& includes, - std::string const& targetCompilePdb, std::string const& targetPdb, - std::string const& outputConfig, WithScanning withScanning) + std::string const& objectDir, std::string const& targetSupportDir, + std::string const& objectFileName, std::string const& objectFileDir, + std::string const& flags, std::string const& defines, + std::string const& includes, std::string const& targetCompilePdb, + std::string const& targetPdb, std::string const& outputConfig, + WithScanning withScanning) { if (!this->GeneratorTarget->GetPropertyAsBool("EXPORT_COMPILE_COMMANDS")) { return; @@ -2254,6 +2267,7 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( cmOutputConverter::SHELL); compileObjectVars.Object = escapedObjectFileName.c_str(); compileObjectVars.ObjectDir = objectDir.c_str(); + compileObjectVars.TargetSupportDir = targetSupportDir.c_str(); compileObjectVars.ObjectFileDir = objectFileDir.c_str(); compileObjectVars.Flags = fullFlags.c_str(); compileObjectVars.Defines = defines.c_str(); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index b5c9d50886..c4dc51f930 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -193,11 +193,12 @@ protected: void ExportObjectCompileCommand( std::string const& language, std::string const& sourceFileName, - std::string const& objectDir, std::string const& objectFileName, - std::string const& objectFileDir, std::string const& flags, - std::string const& defines, std::string const& includes, - std::string const& targetCompilePdb, std::string const& targetPdb, - std::string const& outputConfig, WithScanning withScanning); + std::string const& objectDir, std::string const& targetSupportDir, + std::string const& objectFileName, std::string const& objectFileDir, + std::string const& flags, std::string const& defines, + std::string const& includes, std::string const& targetCompilePdb, + std::string const& targetPdb, std::string const& outputConfig, + WithScanning withScanning); void ExportSwiftObjectCompileCommand( std::vector const& moduleSourceFiles,