diff --git a/CMakeLists.txt b/CMakeLists.txt index 3958e8f..475ee01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,50 +196,67 @@ function(link_deps target) endfunction() -function(use_townengine target sources output_directory) +function(use_townengine target sources output_directory data_dir) if (TOWNENGINE_HOT_RELOAD) - add_library(${target}_shared SHARED ${sources}) - set_target_properties(${target}_shared PROPERTIES - OUTPUT_NAME game - LIBRARY_OUTPUT_DIRECTORY ${output_directory}) - give_options(${target}_shared) - include_deps(${target}_shared) - target_link_libraries(${target}_shared PUBLIC SDL2::SDL2) - add_executable(${target} ${TOWNENGINE_DIR}/townengine/null.c) - set_target_properties(${target}_shared PROPERTIES - OUTPUT_NAME game - LIBRARY_OUTPUT_DIRECTORY ${output_directory}) + # game shared library, for reloading + add_library(${target}_game SHARED ${sources}) + set_target_properties(${target}_game PROPERTIES + OUTPUT_NAME game + LIBRARY_OUTPUT_DIRECTORY ${output_directory}) + give_options(${target}_game) + include_deps(${target}_game) + target_link_libraries(${target}_game PUBLIC SDL2::SDL2) + + # launcher binary, loads game and engine shared library + add_executable(${target}_app ${TOWNENGINE_DIR}/townengine/null.c) + set_target_properties(${target}_app PROPERTIES + OUTPUT_NAME launcher + LIBRARY_OUTPUT_DIRECTORY ${output_directory}) + + # put libtownengine.so alongside the binary set_target_properties(${TOWNENGINE_TARGET} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${output_directory}) + LIBRARY_OUTPUT_DIRECTORY ${output_directory}) else () - add_executable(${target} ${sources}) + add_executable(${target}_app ${sources}) endif () # system libraries find_library(MATH_LIBRARY m) if (MATH_LIBRARY) - target_link_libraries(${target} PUBLIC ${MATH_LIBRARY}) + target_link_libraries(${target}_app PUBLIC ${MATH_LIBRARY}) endif () - give_options(${target}) - include_deps(${target}) - link_deps(${target}) - target_link_libraries(${target} PUBLIC ${TOWNENGINE_TARGET}) - - set_target_properties(${target} PROPERTIES + give_options(${target}_app) + include_deps(${target}_app) + link_deps(${target}_app) + target_link_libraries(${target}_app PUBLIC ${TOWNENGINE_TARGET}) + set_target_properties(${target}_app PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${output_directory}) # copy dlls for baby windows - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy -t $ - $ + add_custom_command(TARGET ${target}_app POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy -t $ + $ COMMAND_EXPAND_LISTS) + + if (UNIX) + # create a bootstrapping script + string(JOIN "\n" TOWNENGINE_BOOTSTRAP + "#!/bin/env sh" + "cd \"$(dirname \"$0\")\"" + "./launcher --data-dir ${data_dir}") + + FILE(GENERATE OUTPUT ${output_directory}/${target} + CONTENT "${TOWNENGINE_BOOTSTRAP}" + FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ) + endif () endfunction() give_options(${TOWNENGINE_TARGET}) include_deps(${TOWNENGINE_TARGET}) link_deps(${TOWNENGINE_TARGET}) +# build the testgame if this cmake list is built directly if (${CMAKE_PROJECT_NAME} MATCHES townengine) add_subdirectory(apps/testgame) endif () diff --git a/apps/template/CMakeLists.txt b/apps/template/CMakeLists.txt index eb299c9..3a34666 100644 --- a/apps/template/CMakeLists.txt +++ b/apps/template/CMakeLists.txt @@ -16,4 +16,4 @@ set(SOURCE_FILES state.h ) -use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR}) +use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ../../data) diff --git a/apps/testgame/CMakeLists.txt b/apps/testgame/CMakeLists.txt index 59e2170..39a162d 100644 --- a/apps/testgame/CMakeLists.txt +++ b/apps/testgame/CMakeLists.txt @@ -23,4 +23,4 @@ set(SOURCE_FILES scenes/ingame.c scenes/ingame.h ) -use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR}) +use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR} ../../data)