premake / premake-core

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

Properly filter .NET build events for configuration #2215

Open mendsley opened 1 month ago

mendsley commented 1 month ago

closes #2214

What does this PR do?

This change properly generates per-configuration conditions for build events with .NET projects rather than pulling build events from the project's "first" configuration

How does this PR change Premake's behavior?

Allows configuration filters to work as expected with .NET project generation

mendsley commented 1 month ago

It looks like the CI workflow failed due to a network issue. Is there a way to re-run it?

https://github.com/premake/premake-core/actions/runs/9273887065/job/25514966115?pr=2215

nickclark2016 commented 1 month ago

To keep parity in support between C# and C++ projects, would you mind adding support there and adding the corresponding unit tests?

mendsley commented 1 month ago

Hi @nickclark2016! I guess I was under the assumption this only affected C# project file generation. What did you have in mind for the C++ side?

nickclark2016 commented 1 month ago

I'm not 100% sure that C++ has the problem, but I'd expect the same behavior (allowing per config steps).

jsmrcina commented 1 month ago

It looks like C++ does not have this problem. The post build events are properly filtered. Minimal example is below using the same version of premake:

premake.lua

workspace "premaketest"
   configurations { "Debug", "Release" }
   platforms { "x64" }

project "premaketest"
   kind "ConsoleApp"
   language "C++"
   cppdialect "C++17"

   files { "*.h", "*.hpp", "*.cpp" }

   architecture "x86_64"

   filter "configurations:Debug"
      defines { "DEBUG" }

      postbuildcommands {
         "{ECHO} Debug",
      }

   filter "configurations:Release"
      defines { "NDEBUG", "__OPENCV_BUILD" }
      optimize "On"

      postbuildcommands {
         "{ECHO} Release",
      }

premaketest.vcxproj

   ... snip ...
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <PreprocessorDefinitions>DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <Optimization>Disabled</Optimization>
      <LanguageStandard>stdcpp17</LanguageStandard>
      <ExternalWarningLevel>Level3</ExternalWarningLevel>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
    </Link>
    <PostBuildEvent>
      <Command>echo Debug</Command>
    </PostBuildEvent>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <PreprocessorDefinitions>NDEBUG;__OPENCV_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <Optimization>Full</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <MinimalRebuild>false</MinimalRebuild>
      <StringPooling>true</StringPooling>
      <LanguageStandard>stdcpp17</LanguageStandard>
      <ExternalWarningLevel>Level3</ExternalWarningLevel>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <PostBuildEvent>
      <Command>echo Release</Command>
    </PostBuildEvent>
  </ItemDefinitionGroup>
   ... snip ...

Thanks!

mendsley commented 3 weeks ago

Just checking back in to see if there is anything remaining to be actioned on this