From bf3ad3f9e4d1fda68c30ca1c9a9c538390e43010 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 6 Jun 2022 21:51:44 +0200 Subject: [PATCH] CMakeLists.txt: build host tools as ExternalProject --- CMakeLists.txt | 7 +++++++ res/CMakeLists.txt | 9 ++++++--- tools/CMakeLists.txt | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f26a5..fb20912 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,13 @@ elseif(WIN9X_BUILD) include("cmake/win9x-toolchain.cmake") endif() +set(TOOLS_PREFIX ${CMAKE_BINARY_DIR}/tools) +include(ExternalProject) +ExternalProject_Add(tools + SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools + CMAKE_ARGS + -D CMAKE_INSTALL_PREFIX=${TOOLS_PREFIX}) + project(rts) add_executable(${PROJECT_NAME} "src/main.c") diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index 5ecf3c5..2b8b00c 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -29,12 +29,13 @@ function(sprite) endif() add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SPRITE_NAME} - COMMAND add-header ${trans} ${SPRITE_NAME}_24.bmp ${CMAKE_CURRENT_BINARY_DIR}/${SPRITE_NAME} + COMMAND ${TOOLS_PREFIX}/bin/add-header ${trans} ${SPRITE_NAME}_24.bmp ${CMAKE_CURRENT_BINARY_DIR}/${SPRITE_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${SPRITE_NAME}_24.bmp VERBATIM) add_custom_target(${SPRITE_NAME}_img DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SPRITE_NAME}) + add_dependencies(${SPRITE_NAME}_img tools) endif() endfunction() @@ -66,12 +67,13 @@ function(sound) # Reference: https://gist.github.com/socantre/7ee63133a0a3a08f3990 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SOUND_NAME} - COMMAND add-header ${loop} ${SOUND_NAME}.wav ${CMAKE_CURRENT_BINARY_DIR}/${SOUND_NAME} + COMMAND ${TOOLS_PREFIX}/bin/add-header ${loop} ${SOUND_NAME}.wav ${CMAKE_CURRENT_BINARY_DIR}/${SOUND_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${SOUND_NAME}.wav VERBATIM) add_custom_target(${SOUND_NAME}_snd DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SOUND_NAME}) + add_dependencies(${SOUND_NAME}_snd tools) endif() endfunction() @@ -83,7 +85,7 @@ function(container) "${multiValueArgs}" ${ARGN}) add_custom_command(OUTPUT ${cdroot}/${CONTAINER_NAME}.cnt - COMMAND container ${CONTAINER_SPRITES} ${CONTAINER_SOUNDS} + COMMAND ${TOOLS_PREFIX}/bin/container ${CONTAINER_SPRITES} ${CONTAINER_SOUNDS} ${cdroot}/${CONTAINER_NAME}.cnt WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM) @@ -91,6 +93,7 @@ function(container) add_custom_target(${CONTAINER_NAME}_container DEPENDS ${cdroot}/${CONTAINER_NAME}.cnt) add_dependencies(${PROJECT_NAME} ${CONTAINER_NAME}_container) + add_dependencies(${CONTAINER_NAME}_container tools) foreach(sprite ${CONTAINER_SPRITES}) add_dependencies(${CONTAINER_NAME}_container ${sprite}_img) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 843301d..14d2b0e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -5,3 +5,4 @@ add_executable(add-header "add-header.c") set(cflags -Wall -g3) target_compile_options(container PUBLIC ${cflags}) target_compile_options(add-header PUBLIC ${cflags}) +install(TARGETS container add-header DESTINATION bin)