Skip to content

Commit

Permalink
build: generalize handling of "clean" actions, add manual "distclean"…
Browse files Browse the repository at this point in the history
… target

wire up remaining clean actions for targets defined in BuildTargets.csproj
  • Loading branch information
smx-smx committed Jan 27, 2024
1 parent b4d3a44 commit 7b60d77
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 50 deletions.
1 change: 1 addition & 0 deletions cmake/msbuild2cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ message("=> Build Type: ${CMAKE_BUILD_TYPE}")
message("=> Generator : ${REKO_COMPILER}")
message("=> Platform : ${REKO_PLATFORM}")
message("=> Target : ${TARGET}")
message("=> Action : ${ACTION}")
message("")

set(REKO_SRC ${CMAKE_CURRENT_LIST_DIR}/../src)
17 changes: 10 additions & 7 deletions src/BuildTargets/BuildTargets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
<CMakeFlags Include="-DCMAKE_BUILD_TYPE=$(Configuration)" />
<CMakeFlags Include="-DREKO_PLATFORM=$(Platform)" />
<CMakeFlags Include="-DREKO_SRC=$(ProjectDir)../" />
<CMakeFlags Include="-DACTION=$(Action)" />
</ItemGroup>

<PropertyGroup>
<!-- this is needed to have a consistent and normalized path (or it will not work on Unix) -->
<RekoCMake>$([System.IO.Path]::Combine($(ProjectDir), ..\reko.cmake))</RekoCMake>
<RekoDistClean>$([System.IO.Path]::Combine($(ProjectDir), ..\distclean.cmake))</RekoDistClean>

<CMakeVS>$([System.IO.Path]::Combine($(VSAPPIDDIR), CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe))</CMakeVS>
<CMake>cmake</CMake>
<!-- build the arguments string by joining <CMakeFlags> items by space -->
Expand Down Expand Up @@ -86,14 +89,9 @@
<Exec Command="$(CMake) $(CMakeArguments) -DTARGET=run_hdrgen -P $(RekoCMake)" />
</Target>

<!-- Deletes any cmake and build process junk in the native directory. -->
<Target Name="nativeproxy_clean">
<Exec Command="$(CMake) $(CMakeArguments) -DTARGET=nativeproxy_clean -P $(RekoCMake)" />
</Target>

<!-- Builds the native code components of Reko -->
<Target Name="nativeproxy_build">
<Exec Command="$(CMake) $(CMakeArguments) -DTARGET=nativeproxy_build -P $(RekoCMake)" />
<Target Name="nativeproxy">
<Exec Command="$(CMake) $(CMakeArguments) -DTARGET=nativeproxy -P $(RekoCMake)" />
</Target>

<!-- Deploys ZIP files containing all the build outputs (including executables, metadata files, and nupkg)-->
Expand All @@ -105,4 +103,9 @@
<Target Name="reko_all"
DependsOnTargets="build_solution;run_unit_tests;run_regressions;create_runtime_nupkg;create_msi_wix;create_release">
</Target>

<!-- wipes all build and object folders -->
<Target Name="distclean">
<Exec Command="$(CMake) -P $(RekoDistClean)" />
</Target>
</Project>
20 changes: 3 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,26 +380,11 @@ elseif("${TARGET}" STREQUAL "gen_c2xml_sysv")
add_c2xml_target_sysv(gen_c2xml_sysv libc.so)
add_c2xml_target_sysv(gen_c2xml_sysv Xlib)
add_c2xml_target_sysv(gen_c2xml_sysv opengl)
elseif("${TARGET}" STREQUAL "nativeproxy_clean")
#
# Create a new target to clean NativeProxy
#
add_custom_target(nativeproxy_clean
COMMENT "Cleaning NativeProxy..."
WORKING_DIRECTORY ${REKO_SRC}/Native
COMMAND ${CMAKE_COMMAND}
-DREKO_SRC=${REKO_SRC}
-DREKO_ROOT=${REKO_SRC}/../
-DREKO_PLATFORM=${REKO_PLATFORM}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DACTION=clean
-P ${REKO_SRC}/Native/reko.cmake
)
elseif("${TARGET}" STREQUAL "nativeproxy_build")
elseif("${TARGET}" STREQUAL "nativeproxy")
#
# Create a new target to build NativeProxy
#
add_custom_target(nativeproxy_build
add_custom_target(nativeproxy
COMMENT "Building NativeProxy ..."
WORKING_DIRECTORY ${REKO_SRC}/Native
COMMAND ${CMAKE_COMMAND}
Expand All @@ -409,6 +394,7 @@ elseif("${TARGET}" STREQUAL "nativeproxy_build")
-DREKO_ROOT=${REKO_SRC}/../
-DREKO_PLATFORM=${REKO_PLATFORM}
-DREKO_COMPILER=${REKO_COMPILER}
-DACTION=${ACTION}
-P ${REKO_SRC}/Native/reko.cmake
)
elseif("${TARGET}" STREQUAL "git_hash")
Expand Down
21 changes: 19 additions & 2 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@
</ItemGroup>

<!-- Regenerates CustomAssemblyInfoFile, if the git hash changed -->
<Target Name="UpdateGitHash" BeforeTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform);CustomAssemblyInfoFile=$(CustomAssemblyInfoFile)" Targets="git_hash" />
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
<ExtProperties Include="CustomAssemblyInfoFile=$(CustomAssemblyInfoFile)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>git_hash</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="CmakeCompile" AfterTargets="Compile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>


Expand Down
20 changes: 18 additions & 2 deletions src/Environments/OS2/OS2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>

<Target Name="RunC2Xml" AfterTargets="Compile">
<MSBuild Projects="$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="gen_c2xml_os2" />
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>gen_c2xml_os2</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="CmakeCompile" AfterTargets="Compile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>
</Project>
20 changes: 18 additions & 2 deletions src/Environments/SysV/SysV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>

<Target Name="RunC2Xml" AfterTargets="Compile">
<MSBuild Projects="$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="gen_c2xml_sysv" />
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>gen_c2xml_sysv</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="CmakeCompile" AfterTargets="Compile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>
</Project>
20 changes: 18 additions & 2 deletions src/Environments/Windows/Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@
<ProjectReference Include="..\..\Libraries\Libc\Libc.csproj" />
</ItemGroup>

<Target Name="RunC2Xml" AfterTargets="Compile">
<MSBuild Projects="$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="gen_c2xml_windows" />
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>gen_c2xml_windows</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="CmakeCompile" AfterTargets="Compile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>
</Project>
20 changes: 18 additions & 2 deletions src/Installers/Runtime/Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,24 @@
<Message Importance="high" Text="NuspecProperties: $(NuspecProperties)" />
</Target>

<Target Name="SetNuspecFiles" BeforeTargets="GenerateNuspec">
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>update_runtime_nuspec</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="CmakeCompile" AfterTargets="GenerateNuspec">
<Message Importance="high" Text="Updating nuspec &quot;$(NuspecFile)&quot;..." />
<MSBuild Projects="$(ProjectDir)..\..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="update_runtime_nuspec" />
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>
</Project>
28 changes: 22 additions & 6 deletions src/Native/NativeProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

<Target Name="CleanCMake" AfterTargets="Clean">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="nativeproxy_clean" />
<ItemGroup>
<ExtProperties Include="Configuration=$(Configuration)" />
<ExtProperties Include="Platform=$(Platform)" />
</ItemGroup>
<PropertyGroup>
<ExtProject>$(ProjectDir)..\BuildTargets\BuildTargets.csproj</ExtProject>
<ExtTarget>gen_c2xml_sysv</ExtTarget>
</PropertyGroup>

<Target Name="CmakeClean" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="$(ExtTarget)" />
</Target>

<Target Name="RunHdrGen" BeforeTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="run_hdrgen" />
<Target Name="CleanCMake" AfterTargets="Clean">
<ItemGroup>
<ExtProperties Include="Action=clean" />
</ItemGroup>
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)"
Targets="nativeproxy;run_hdrgen" />
</Target>

<Target Name="InvokeCMake" AfterTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="nativeproxy_build" />
<Target Name="RunHdrGen" BeforeTargets="CoreCompile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="run_hdrgen;nativeproxy" />
</Target>
</Project>
2 changes: 0 additions & 2 deletions src/Native/reko.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ include(msbuild2cmake)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/build/${REKO_PLATFORM}/${CMAKE_BUILD_TYPE})

if(ACTION STREQUAL "clean")
message(STATUS "Cleaning native libraries")
message(STATUS "deleting ${BUILD_DIR}")
clean_project(${BUILD_DIR})
else()
message(STATUS "Building native libraries")
Expand Down
34 changes: 34 additions & 0 deletions src/distclean.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set(REKO_SRC ${CMAKE_CURRENT_LIST_DIR})
list(INSERT CMAKE_MODULE_PATH 0 "${REKO_SRC}/../cmake")
include(FindDotNet)

macro(rmrf path)
message("=> rm -r ${path}")
file(REMOVE_RECURSE "${path}")
endmacro()

execute_process(
COMMAND ${DOTNET_EXE} clean
COMMAND_ERROR_IS_FATAL ANY
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

file(GLOB_RECURSE CANDIDATES
LIST_DIRECTORIES TRUE
${REKO_SRC}/**/bin
${REKO_SRC}/**/obj
)

foreach(p IN LISTS CANDIDATES)
if(NOT IS_DIRECTORY "${p}"
OR NOT p MATCHES "/(bin|obj)$")
continue()
endif()
rmrf("${p}")
endforeach()

set(REKO_CMAKE_BUILD_TARGETS ${REKO_SRC}/BuildTargets/build)

if(IS_DIRECTORY ${REKO_CMAKE_BUILD_TARGETS})
rmrf(${REKO_CMAKE_BUILD_TARGETS})
endif()
22 changes: 14 additions & 8 deletions src/reko.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ if("${TARGET}" STREQUAL "git_hash")
endif()


invoke_cmake(
BUILD_DIR ${CMAKE_BINARY_DIR}/build/${TARGET}
DIRECTORY ${REKO_SRC}/../
TARGET ${TARGET}
GENERATOR ${REKO_COMPILER}
# variables needed by CMakeLists.txt, that must be forwarded
EXTRA_ARGUMENTS ${cmake_arguments}
)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/build/${TARGET})

if(ACTION STREQUAL clean)
clean_project(${BUILD_DIR})
else()
invoke_cmake(
BUILD_DIR ${BUILD_DIR}
DIRECTORY ${REKO_SRC}/../
TARGET ${TARGET}
GENERATOR ${REKO_COMPILER}
# variables needed by CMakeLists.txt, that must be forwarded
EXTRA_ARGUMENTS ${cmake_arguments}
)
endif()

0 comments on commit 7b60d77

Please sign in to comment.