Skip to content

Commit

Permalink
buildscript: Add arptool as dependency for Rust targets
Browse files Browse the repository at this point in the history
  • Loading branch information
caseif committed Dec 27, 2024
1 parent 1872980 commit d483adb
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions cmake/ConfigureModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,31 @@ function(_argus_configure_module MODULE_PROJECT_DIR ROOT_DIR
set(res_dir "${MODULE_PROJECT_DIR}/res")
set(res_pack_target "pack_resources_${PROJECT_NAME}")
set(res_gen_target "gen_resources_${PROJECT_NAME}")
if(EXISTS "${res_dir}" AND NOT ${IS_EXTERNAL})
set(arp_out_dir "${MODULE_GENERATED_DIR}/res/arp")
set(arp_out_name "resources_${PROJECT_NAME}")
set(arp_out_path "${arp_out_dir}/${arp_out_name}.arp")
set(supp_mappings_path "${ROOT_PROJECT_DIR}/res/arp_custom_mappings.csv")

file(MAKE_DIRECTORY "${arp_out_dir}")

file(GLOB_RECURSE res_files "${res_dir}/*")
add_custom_command(OUTPUT "${arp_out_path}"
COMMAND "${ARPTOOL_EXE_PATH}" "pack" "${res_dir}"
"--namespace" "argus"
"--output" "${arp_out_dir}"
"--name" "${arp_out_name}"
"--compression" "deflate"
"--mappings" "${supp_mappings_path}"
"--quiet"
DEPENDS "${res_files}")

add_custom_target("${res_pack_target}" DEPENDS "arptool" "${arp_out_path}")

# generated sources are not supported for external projects at the moment
if(EXISTS "${res_dir}")
set(has_resources 1)
# Rust crates handle their own codegen, just add arptool as a dependency
# to ensure proper build ordering
if(NOT ${IS_EXTERNAL})
set(arp_out_dir "${MODULE_GENERATED_DIR}/res/arp")
set(arp_out_name "resources_${PROJECT_NAME}")
set(arp_out_path "${arp_out_dir}/${arp_out_name}.arp")
set(supp_mappings_path "${ROOT_PROJECT_DIR}/res/arp_custom_mappings.csv")

file(MAKE_DIRECTORY "${arp_out_dir}")

file(GLOB_RECURSE res_files "${res_dir}/*")
add_custom_command(OUTPUT "${arp_out_path}"
COMMAND "${ARPTOOL_EXE_PATH}" "pack" "${res_dir}"
"--namespace" "argus"
"--output" "${arp_out_dir}"
"--name" "${arp_out_name}"
"--compression" "deflate"
"--mappings" "${supp_mappings_path}"
"--quiet"
DEPENDS "${res_files}")

add_custom_target("${res_pack_target}" DEPENDS "arptool" "${arp_out_path}")

set(abacus_out_dir "${CMAKE_BINARY_DIR}/res/abacus")
set(h_out_dir_base "${MODULE_GENERATED_DIR}/${INCLUDE_DIR_NAME}")
set(h_out_dir "${h_out_dir_base}/internal/${PROJECT_NAME}")
Expand Down Expand Up @@ -479,10 +481,16 @@ function(_argus_configure_module MODULE_PROJECT_DIR ROOT_DIR
set_property(GLOBAL PROPERTY COMBINED_TARGET_LINKER_DEPS "${COMBINED_TARGET_LINKER_DEPS}")
endif()

if(TARGET ${res_gen_target})
add_dependencies("${PROJECT_NAME}" "${res_gen_target}")
elseif(TARGET ${res_pack_target})
add_dependencies("${PROJECT_NAME}" "${res_pack_target}")
if(${IS_EXTERNAL})
if(${has_resources})
add_dependencies("${PROJECT_NAME}" "arptool")
endif()
else()
if(TARGET ${res_gen_target})
add_dependencies("${PROJECT_NAME}" "${res_gen_target}")
elseif(TARGET ${res_pack_target})
add_dependencies("${PROJECT_NAME}" "${res_pack_target}")
endif()
endif()

# todo: work out how to pass compile definitions to Rust projects
Expand Down

0 comments on commit d483adb

Please sign in to comment.