premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.23k stars 621 forks source link

Add support for CopyToOutputDirectory for VS C++ projects #2046

Open MaximeLussier opened 1 year ago

MaximeLussier commented 1 year ago

What problem will this solve? Projects using DLL not present in the system will not load them if not copied alongside the executable

What might be a solution? Add a flag to enable "CopyToOutputDirectory" or add it always

What other alternatives have you already considered? Currently, we SED the vcxproj after generation

Anything else we should know? This:

  <ItemGroup>
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_AVX.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSE2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSE4_2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSSE3.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_AVX.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSE2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSE4_2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSSE3.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_AVX.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSE2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSE4_2.dll" />
    <None Include="..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSSE3.dll" />
  </ItemGroup>

vs

<ItemGroup>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_AVX.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSE2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSE4_2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264com_SSSE3.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_AVX.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSE2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSE4_2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264dec_SSSE3.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_AVX.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSE2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSE4_2.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include=".\..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win\h264enc_SSSE3.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
samsinsane commented 1 year ago

Does buildaction "Copy" do what you're after? It was added in this PR #1978 it's not CopyToOutputDirectory, but it might work, otherwise it's a UWP-specific element and we'll need to add CopyToOutputDirectory for Windows.

MaximeLussier commented 1 year ago

Not really. The buildaction "copy" would require us to manually specify the source files and destination directory! The CopyToOutputDirectory automatically does it for the required libraries.

samsinsane commented 1 year ago

I think you're thinking of something else, the PR I linked shows an example through a unit test. https://github.com/premake/premake-core/blob/d150691d1eabfcc6e523a2649e367d11b129dfbf/modules/vstudio/tests/vc2010/test_files.lua#L110 https://github.com/premake/premake-core/blob/d150691d1eabfcc6e523a2649e367d11b129dfbf/modules/vstudio/tests/vc2010/test_files.lua#L115-L116 https://github.com/premake/premake-core/blob/d150691d1eabfcc6e523a2649e367d11b129dfbf/modules/vstudio/tests/vc2010/test_files.lua#L128-L133

MaximeLussier commented 1 year ago

Ah, we will need to take a look at that. But I believe we only specify the directory path of the libraries in the lua file (e.g ..\SourcesMeiWebRtc\ExternalCodecs\h264_lib\lib_win) and all the .dll are added to the vcxproj... The CopyToOutputDirectory was generated by GYP which we stopped using.