Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] fix the clean target #1322

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/msbuild2cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function(check_msys output)
set(${output} FALSE PARENT_SCOPE)
endfunction()

function(clean_project name path build_dir)
function(clean_project build_dir)
if(EXISTS ${build_dir})
message(STATUS "Removing ${build_dir}")
file(REMOVE_RECURSE ${build_dir})
Expand Down 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" BeforeTargets="CoreCompile">
<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" BeforeTargets="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>
24 changes: 19 additions & 5 deletions src/Native/NativeProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,29 @@
<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>
</PropertyGroup>

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

<!-- hdrgen, before compilation -->
<Target Name="RunHdrGen" BeforeTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="run_hdrgen" />
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="run_hdrgen" />
</Target>

<Target Name="InvokeCMake" AfterTargets="CoreCompile">
<MSBuild Projects="$(ProjectDir)..\BuildTargets\BuildTargets.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" Targets="nativeproxy_build" />
<!-- nativeproxy -->
<Target Name="NativeProxy" AfterTargets="CoreCompile">
<MSBuild Projects="$(ExtProject)" Properties="@(ExtProperties)" Targets="nativeproxy" />
</Target>
</Project>
24 changes: 15 additions & 9 deletions src/Native/reko.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ list(INSERT CMAKE_MODULE_PATH 0 "${REKO_SRC}/../cmake")

include(msbuild2cmake)

message(STATUS "Building native libraries")
invoke_cmake(
BUILD_DIR ${CMAKE_BINARY_DIR}/build/${REKO_PLATFORM}/${CMAKE_BUILD_TYPE}
DIRECTORY ${CMAKE_SOURCE_DIR}
GENERATOR ${REKO_COMPILER}
EXTRA_ARGUMENTS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DREKO_PLATFORM=${REKO_PLATFORM}
)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/build/${REKO_PLATFORM}/${CMAKE_BUILD_TYPE})

if(ACTION STREQUAL "clean")
clean_project(${BUILD_DIR})
else()
message(STATUS "Building native libraries")
invoke_cmake(
BUILD_DIR ${BUILD_DIR}
DIRECTORY ${CMAKE_SOURCE_DIR}
GENERATOR ${REKO_COMPILER}
EXTRA_ARGUMENTS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DREKO_PLATFORM=${REKO_PLATFORM}
)
endif()
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(path IN LISTS CANDIDATES)
if(NOT IS_DIRECTORY "${path}"
OR NOT path MATCHES "/(bin|obj)$")
continue()
endif()
rmrf("${path}")
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()
Loading