ubisoft / Sharpmake

Sharpmake is an open-source C#-based solution for generating project definition files, such as Visual Studio projects and solutions, GNU makefiles, Xcode projects, etc.
Apache License 2.0
927 stars 171 forks source link

Question: How to copy files into a sub-dir of TargetCopyFilesPath #268

Closed ChemistAion closed 1 year ago

ChemistAion commented 1 year ago

I need to copy some bin-files into a sub-dir of TargetCopyFilesPath, namely: d3d12 This sub-dir should be visible within working-dir of a target exec

I am aware of EventPreBuild and TargetCopyCommandCreator/CreateTargetCopyCommand, that works under PostConfigureAll(...) but I am somehow stuck with no full examples/test on how to use these in VS ...unfortunately, this linux-one does not move me forward: sharpmake\samples\HelloLinux\HelloLinux.CommonProject.sharpmake.cs

I have managed to create a sub-dir within PostConfigureAll(...) by conf.EventPreBuild.Add($"mkdir {packageDir}"); but that's all what I can achieve for now...

Could you please point me out/provide an example how to copy into d3d12 as a target sub-dir?

ChemistAion commented 1 year ago

If someone will stuck with similar issue here is what I did:

public override void PostConfigureAll(Configuration conf, CustomTarget target)
{
    string packageDir = "$(TargetDir)d3d12";
    conf.EventPreBuild.Add(string.Format(@"mkdir ""{0}"" >nul", packageDir));

    conf.EventPreBuild.Add(conf.CreateTargetCopyCommand(@"[project.SharpmakeCsPath]\packages\agilitysdk\build\native\bin\x64\d3d12core.dll", $"{packageDir}", ""));
    conf.EventPreBuild.Add(conf.CreateTargetCopyCommand(@"[project.SharpmakeCsPath]\packages\agilitysdk\build\native\bin\x64\d3d12SDKLayers.dll", $"{packageDir}", ""));
}

Common macros for MSBuild commands and properties: https://learn.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=msvc-170

I will leave this issue open for now, until someone from sharpmake team would confirm that I am doing THIS correctly.

belkiss commented 1 year ago

Just use conf.TargetCopyFilesToSubDirectory :)

https://github.com/ubisoft/Sharpmake/blob/ed18b134a628bd83f64c080fd9d5ceaeb7bfd924/Sharpmake/Project.Configuration.cs#L1828

(not part of sharpmake team anymore though :D)

ChemistAion commented 1 year ago

Perfect, thanks for pointing out that one.

ChemistAion commented 1 year ago

@belkiss (or someone from the Sharpmake team)

...ehh, could you please assist me with this? After some trials, I am unsure about how to properly utilize conf.TargetCopyFilesToSubDirectory (possibly due to my limited C# skills).

As mentioned earlier, here is my use case: https://github.com/ubisoft/Sharpmake/issues/268#issuecomment-1509116417

Please note that I also require the creation of the d3d12 directory during the process. Is it possible to achieve this in a single step?

ChemistAion commented 1 year ago

Solution:

using System;
using System.Collections.Generic;
///
public override void PostConfigureAll(Configuration conf, CustomTarget target)
{           
    conf.TargetCopyFiles.Add(@"[project.SharpmakeCsPath]\packages\pix\bin\x64\winpixeventruntime.dll");
    conf.TargetCopyFiles.Add(@"[project.SharpmakeCsPath]\externals\rps\tools\rps_hlslc\win-x64\rps-jit.dll");

    conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(@"[project.SharpmakeCsPath]\packages\agilitysdk\build\native\bin\x64\d3d12core.*", "d3d12"));
    conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(@"[project.SharpmakeCsPath]\packages\agilitysdk\build\native\bin\x64\d3d12sdklayers.*", "d3d12"));

    conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(@"[project.SharpmakeCsPath]\externals\rps\tools\rps_hlslc\win-x64\dxcompiler.dll", "rps_hlslc"));
    conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(@"[project.SharpmakeCsPath]\externals\rps\tools\rps_hlslc\win-x64\dxil.dll", "rps_hlslc"));
    conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(@"[project.SharpmakeCsPath]\externals\rps\tools\rps_hlslc\win-x64\rps-hlslc.exe", "rps_hlslc"));
}