application separation

This commit is contained in:
2024-07-30 01:20:30 +03:00
parent 922e521867
commit a99cb340d8
23 changed files with 147 additions and 34 deletions

View File

@ -7,14 +7,16 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# dependencies
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2 REQUIRED GLOBAL)
find_package(SDL2_image REQUIRED GLOBAL)
find_package(SDL2_ttf REQUIRED GLOBAL)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()
set(TOWNENGINE_TARGET townengine CACHE INTERNAL "")
set(TOWNENGINE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
set(PHYSFS_BUILD_SHARED FALSE)
set(PHYSFS_DISABLE_INSTALL TRUE)
@ -49,29 +51,16 @@ set(TOWNENGINE_SOURCE_FILES
${SYSTEM_SOURCE_FILES}
)
set(GAME_SOURCE_FILES
src/game_api.h
src/game/game.c src/game/game.h
src/game/state.h
src/game/player.c src/game/player.h
src/game/world.c src/game/world.h
src/game/scenes/scene.c src/game/scenes/scene.h
src/game/scenes/title.c src/game/scenes/title.h
src/game/scenes/ingame.c src/game/scenes/ingame.h
)
list(TRANSFORM TOWNENGINE_SOURCE_FILES PREPEND ${TOWNENGINE_DIR}/)
# base engine code, reused for games and tools
add_library(${PROJECT_NAME} ${TOWNENGINE_SOURCE_FILES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${TOWNENGINE_SOURCE_FILES})
add_library(${TOWNENGINE_TARGET} ${TOWNENGINE_SOURCE_FILES})
source_group(TREE ${TOWNENGINE_DIR} FILES ${TOWNENGINE_SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
C_EXTENSIONS ON) # extensions are required by stb_ds.h
set_target_properties(${TOWNENGINE_TARGET} PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
C_EXTENSIONS ON) # extensions are required by stb_ds.h
# distribution definitions
set(ORGANIZATION_NAME "wanp" CACHE STRING
@ -161,18 +150,18 @@ endfunction()
function(link_and_include_deps target)
# header-only libraries should be marked as "system includes"
# to suppress compiler warnings in their code (it's not my problem after all)
target_include_directories(${target}
SYSTEM
PRIVATE
set(THIRD_PARTY_INCLUDES
third-party/physfs/src
third-party/physfs/extras
third-party/libxm/include
third-party/glad/include
third-party/stb
)
list(TRANSFORM THIRD_PARTY_INCLUDES PREPEND ${TOWNENGINE_DIR}/)
target_include_directories(${target} SYSTEM PRIVATE ${THIRD_PARTY_INCLUDES})
# allow access to headers from any point in source tree
target_include_directories(${target} PRIVATE ./)
target_include_directories(${target} PRIVATE ${TOWNENGINE_DIR})
target_link_libraries(${target} PUBLIC
SDL2::SDL2
@ -197,7 +186,7 @@ function(use_townengine target)
# third-party libraries
target_link_libraries(${target} PUBLIC
${PROJECT_NAME}
${TOWNENGINE_TARGET}
SDL2::SDL2
SDL2::SDL2main
SDL2_image::SDL2_image
@ -214,11 +203,10 @@ function(use_townengine target)
)
endfunction()
give_options(${PROJECT_NAME})
link_and_include_deps(${PROJECT_NAME})
give_options(${TOWNENGINE_TARGET})
link_and_include_deps(${TOWNENGINE_TARGET})
add_executable(game ${GAME_SOURCE_FILES})
use_townengine(game)
add_subdirectory(apps/testgame)
# zip up assets
# currently, you must run cmake from the project root dir for this to work correctly