From b028fea59a3160f8124287498ff105bb8b93295b Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sat, 2 Sep 2023 20:14:52 +0300 Subject: [PATCH] build: make targets properly rebuild when templates or compiler changed --- CMakeLists.txt | 17 ++++++++++++----- examples/code/C/CMakeLists.txt | 2 +- examples/code/asm/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 14 ++++++++++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7426528..1e29ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,8 @@ else() endif() # the tests include the entire ASM but we still want to rebuild when they change -file(GLOB x86templates ${PROJECT_SOURCE_DIR}/templates/amd64-386/*.asm) -file(GLOB wasmtemplates ${PROJECT_SOURCE_DIR}/templates/wasm/*.wat) +file(GLOB x86templates "${PROJECT_SOURCE_DIR}/vm/compiler/templates/amd64-386/*.asm") +file(GLOB wasmtemplates "${PROJECT_SOURCE_DIR}/vm/compiler/templates/wasm/*.wat") file(GLOB sointusrc "${PROJECT_SOURCE_DIR}/*.go") file(GLOB compilersrc "${PROJECT_SOURCE_DIR}/compiler/*.go") file(GLOB compilecmdsrc "${PROJECT_SOURCE_DIR}/cmd/sointu-compile/*.go") @@ -83,16 +83,23 @@ set(sointuasm sointu.asm) # Build sointu-cli only once because go run has everytime quite a bit of delay when # starting +add_custom_command( + OUTPUT + "${compilecmd}" + COMMAND + ${GO} build -o "${compilecmd}" ${PROJECT_SOURCE_DIR}/cmd/sointu-compile/main.go + DEPENDS ${x86templates} ${wasmtemplates} ${sointusrc} ${compilersrc} ${compilecmdsrc} +) + add_custom_target( sointu-compiler - COMMAND ${GO} build -o ${compilecmd} ${PROJECT_SOURCE_DIR}/cmd/sointu-compile/main.go - SOURCES "${sointusrc}" "${compilersrc}" "${compilecmdsrc}" + DEPENDS ${compilecmd} ) add_custom_command( OUTPUT ${sointuasm} COMMAND ${compilecmd} -arch=${arch} -a -o ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS "${templates}" sointu-compiler + DEPENDS ${compilecmd} ) add_library(${STATICLIB} ${sointuasm}) diff --git a/examples/code/C/CMakeLists.txt b/examples/code/C/CMakeLists.txt index a9bfa8e..f9bd8a6 100644 --- a/examples/code/C/CMakeLists.txt +++ b/examples/code/C/CMakeLists.txt @@ -12,6 +12,7 @@ add_custom_command( ${CMAKE_CURRENT_BINARY_DIR} DEPENDS "${PROJECT_SOURCE_DIR}/examples/patches/physics_girl_st.yml" + ${compilecmd} OUTPUT physics_girl_st.asm physics_girl_st.h @@ -21,7 +22,6 @@ add_custom_command( ) add_library(physics_girl_st physics_girl_st.asm) -add_dependencies(physics_girl_st sointu-compiler) if(WIN32) add_executable(cplay-winmm diff --git a/examples/code/asm/CMakeLists.txt b/examples/code/asm/CMakeLists.txt index 7dee6c9..32019d3 100644 --- a/examples/code/asm/CMakeLists.txt +++ b/examples/code/asm/CMakeLists.txt @@ -15,6 +15,7 @@ function(add_asm_example identifier songfile architecture sizeof_void_ptr window ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${songfile} + ${compilecmd} OUTPUT ${songprefix}_${architecture}.asm ${songprefix}_${architecture}.h @@ -50,7 +51,6 @@ function(add_asm_example identifier songfile architecture sizeof_void_ptr window target_compile_definitions(${identifier}-${architecture} PRIVATE TRACK_INCLUDE="${songprefix}_${architecture}.inc") # Set up dependencies - add_dependencies(${identifier}-${architecture} sointu-compiler) add_dependencies(examples ${identifier}-${architecture}) endfunction() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b33299..0dcb899 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,7 @@ function(regression_test testname) add_custom_command( OUTPUT ${asmfile} COMMAND ${compilecmd} ${ARGV4} -arch=${arch} -o ${CMAKE_CURRENT_BINARY_DIR}/${asmfile} ${CMAKE_CURRENT_SOURCE_DIR}/${source} - DEPENDS ${source} ${x86templates} sointu-compiler + DEPENDS ${source} ${x86templates} ${compilecmd} ) add_executable(${testname} test_renderer.c ${asmfile}) @@ -26,11 +26,17 @@ function(regression_test testname) set(wasmfile ${CMAKE_CURRENT_BINARY_DIR}/${testname}.wasm) set(watfile ${CMAKE_CURRENT_BINARY_DIR}/${testname}.wat) set(wasmtarget wasm_${testname}) - add_custom_target(${wasmtarget} ALL + add_custom_command( + OUTPUT ${wasmfile} COMMAND ${compilecmd} ${ARGV4} -arch=wasm -o ${watfile} ${CMAKE_CURRENT_SOURCE_DIR}/${source} && ${WAT2WASM} -o ${wasmfile} ${watfile} - SOURCES "${source}" "${wasmtemplates}" - DEPENDS sointu-compiler + DEPENDS ${source} ${wasmtemplates} ${compilecmd} ) + + add_custom_target(${wasmtarget} ALL + SOURCES "${source}" "${wasmtemplates}" + DEPENDS ${wasmfile} + ) + add_test(${wasmtarget} ${NODE} ${CMAKE_CURRENT_SOURCE_DIR}/wasm_test_renderer.es6 ${wasmfile} ${CMAKE_CURRENT_SOURCE_DIR}/expected_output/${testname}.raw) endif() endif()