separate game and townengine builds for reuse in tools
This commit is contained in:
parent
ff077c5d0d
commit
09f2f82d27
234
CMakeLists.txt
234
CMakeLists.txt
@ -31,7 +31,7 @@ else()
|
|||||||
set(SYSTEM_SOURCE_FILES)
|
set(SYSTEM_SOURCE_FILES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(TOWNENGINE_SOURCE_FILES
|
||||||
third-party/physfs/extras/physfsrwops.c
|
third-party/physfs/extras/physfsrwops.c
|
||||||
third-party/stb/stb_vorbis.c
|
third-party/stb/stb_vorbis.c
|
||||||
third-party/glad/src/glad.c
|
third-party/glad/src/glad.c
|
||||||
@ -46,6 +46,11 @@ set(SOURCE_FILES
|
|||||||
src/input.c src/input.h
|
src/input.c src/input.h
|
||||||
src/text.c src/text.h
|
src/text.c src/text.h
|
||||||
src/camera.c src/camera.h
|
src/camera.c src/camera.h
|
||||||
|
|
||||||
|
${SYSTEM_SOURCE_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
|
set(GAME_SOURCE_FILES
|
||||||
src/game_api.h
|
src/game_api.h
|
||||||
|
|
||||||
src/game/game.c src/game/game.h
|
src/game/game.c src/game/game.h
|
||||||
@ -57,13 +62,11 @@ set(SOURCE_FILES
|
|||||||
src/game/scenes/scene.c src/game/scenes/scene.h
|
src/game/scenes/scene.c src/game/scenes/scene.h
|
||||||
src/game/scenes/title.c src/game/scenes/title.h
|
src/game/scenes/title.c src/game/scenes/title.h
|
||||||
src/game/scenes/ingame.c src/game/scenes/ingame.h
|
src/game/scenes/ingame.c src/game/scenes/ingame.h
|
||||||
|
|
||||||
${SYSTEM_SOURCE_FILES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# target
|
# base engine code, reused for games and tools
|
||||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
add_library(${PROJECT_NAME} ${TOWNENGINE_SOURCE_FILES})
|
||||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})
|
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${TOWNENGINE_SOURCE_FILES})
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
C_STANDARD 11
|
C_STANDARD 11
|
||||||
@ -78,116 +81,141 @@ set(APP_NAME "townengine" CACHE STRING
|
|||||||
set(PACKAGE_EXTENSION "btw" CACHE STRING
|
set(PACKAGE_EXTENSION "btw" CACHE STRING
|
||||||
"File extension used to look for data archives")
|
"File extension used to look for data archives")
|
||||||
|
|
||||||
# build options
|
function(give_options target)
|
||||||
# LTO will be used on release builds
|
if(MSVC)
|
||||||
if(MSVC)
|
# close enough i say
|
||||||
# close enough i say
|
target_compile_options(${target} PRIVATE
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
/W4
|
||||||
/W4
|
$<$<CONFIG:Release>:/GL>)
|
||||||
$<$<CONFIG:Release>:/GL>)
|
|
||||||
|
|
||||||
target_link_options(${PROJECT_NAME} PRIVATE
|
target_link_options(${target} PRIVATE
|
||||||
$<$<CONFIG:Release>:/LTCG>)
|
$<$<CONFIG:Release>:/LTCG>)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
set(WARNING_FLAGS_CLANG
|
set(WARNING_FLAGS_CLANG
|
||||||
-Weverything
|
-Weverything
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-declaration-after-statement
|
-Wno-declaration-after-statement
|
||||||
-Wno-unsafe-buffer-usage
|
-Wno-unsafe-buffer-usage
|
||||||
-Wno-unused-command-line-argument)
|
-Wno-unused-command-line-argument)
|
||||||
|
|
||||||
set(WARNING_FLAGS
|
set(WARNING_FLAGS
|
||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wpedantic
|
-Wpedantic
|
||||||
-Wshadow
|
-Wshadow
|
||||||
-Wdouble-promotion
|
-Wdouble-promotion
|
||||||
-Wconversion -Wno-sign-conversion
|
-Wconversion -Wno-sign-conversion
|
||||||
-Werror=vla
|
-Werror=vla
|
||||||
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-Wcast-align=strict>
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-Wcast-align=strict>
|
||||||
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>)
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>)
|
||||||
|
|
||||||
set(BUILD_FLAGS
|
set(BUILD_FLAGS
|
||||||
# these SHOULDN'T break anything...
|
# these SHOULDN'T break anything...
|
||||||
-fno-math-errno
|
-fno-math-errno
|
||||||
-ffp-contract=fast
|
-ffp-contract=fast
|
||||||
-fno-signed-zeros
|
-fno-signed-zeros
|
||||||
-fno-trapping-math
|
-fno-trapping-math
|
||||||
-freciprocal-math)
|
-freciprocal-math)
|
||||||
|
|
||||||
set(BUILD_FLAGS_RELEASE
|
set(BUILD_FLAGS_RELEASE
|
||||||
-O3
|
-O3
|
||||||
-flto
|
-flto
|
||||||
-mavx -mavx2
|
-mavx -mavx2
|
||||||
-Wl,--gc-sections
|
-Wl,--gc-sections
|
||||||
-fdata-sections
|
-fdata-sections
|
||||||
-ffunction-sections
|
-ffunction-sections
|
||||||
-funroll-loops
|
-funroll-loops
|
||||||
-fomit-frame-pointer
|
-fomit-frame-pointer
|
||||||
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-fallow-store-data-races>)
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-fallow-store-data-races>)
|
||||||
|
|
||||||
set(BUILD_FLAGS_DEBUG
|
set(BUILD_FLAGS_DEBUG
|
||||||
-O0
|
-O0
|
||||||
-g3
|
-g3
|
||||||
-gdwarf
|
-gdwarf
|
||||||
-fno-omit-frame-pointer
|
-fno-omit-frame-pointer
|
||||||
-fstack-protector-all
|
-fstack-protector-all
|
||||||
-fsanitize=undefined
|
-fsanitize=undefined
|
||||||
-fsanitize=address)
|
-fsanitize=address)
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
target_compile_options(${target} PRIVATE
|
||||||
${WARNING_FLAGS}
|
${WARNING_FLAGS}
|
||||||
${BUILD_FLAGS}
|
${BUILD_FLAGS}
|
||||||
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
||||||
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
||||||
|
|
||||||
target_link_options(${PROJECT_NAME} PRIVATE
|
target_link_options(${target} PRIVATE
|
||||||
${BUILD_FLAGS}
|
${BUILD_FLAGS}
|
||||||
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
||||||
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
target_compile_definitions(${target} PRIVATE
|
||||||
ORGANIZATION_NAME="${ORGANIZATION_NAME}"
|
ORGANIZATION_NAME="${ORGANIZATION_NAME}"
|
||||||
APP_NAME="${APP_NAME}"
|
APP_NAME="${APP_NAME}"
|
||||||
PACKAGE_EXTENSION="${PACKAGE_EXTENSION}")
|
PACKAGE_EXTENSION="${PACKAGE_EXTENSION}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# 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(${PROJECT_NAME}
|
|
||||||
SYSTEM
|
|
||||||
PRIVATE
|
|
||||||
third-party/physfs/src
|
|
||||||
third-party/physfs/extras
|
|
||||||
third-party/libxm/include
|
|
||||||
third-party/glad/include
|
|
||||||
third-party/stb
|
|
||||||
)
|
|
||||||
|
|
||||||
# system libraries
|
function(link_and_include_deps target)
|
||||||
find_library(MATH_LIBRARY m)
|
# header-only libraries should be marked as "system includes"
|
||||||
if(MATH_LIBRARY)
|
# to suppress compiler warnings in their code (it's not my problem after all)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${MATH_LIBRARY})
|
target_include_directories(${target}
|
||||||
endif()
|
SYSTEM
|
||||||
|
PRIVATE
|
||||||
|
third-party/physfs/src
|
||||||
|
third-party/physfs/extras
|
||||||
|
third-party/libxm/include
|
||||||
|
third-party/glad/include
|
||||||
|
third-party/stb
|
||||||
|
)
|
||||||
|
|
||||||
# third-party libraries
|
target_link_libraries(${target} PUBLIC
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
SDL2::SDL2
|
||||||
SDL2::SDL2
|
SDL2::SDL2main
|
||||||
SDL2::SDL2main
|
SDL2_image::SDL2_image
|
||||||
SDL2_image::SDL2_image
|
SDL2_ttf::SDL2_ttf
|
||||||
SDL2_ttf::SDL2_ttf
|
physfs-static
|
||||||
physfs-static
|
xms
|
||||||
xms
|
)
|
||||||
)
|
endfunction()
|
||||||
|
|
||||||
# copy dlls for baby windows
|
|
||||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
function(use_townengine target)
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${PROJECT_NAME}>
|
# system libraries
|
||||||
$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>
|
find_library(MATH_LIBRARY m)
|
||||||
COMMAND_EXPAND_LISTS
|
if(MATH_LIBRARY)
|
||||||
)
|
target_link_libraries(${target} PUBLIC ${MATH_LIBRARY})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
give_options(${target})
|
||||||
|
link_and_include_deps(${target})
|
||||||
|
|
||||||
|
# third-party libraries
|
||||||
|
target_link_libraries(${target} PUBLIC
|
||||||
|
${PROJECT_NAME}
|
||||||
|
SDL2::SDL2
|
||||||
|
SDL2::SDL2main
|
||||||
|
SDL2_image::SDL2_image
|
||||||
|
SDL2_ttf::SDL2_ttf
|
||||||
|
physfs-static
|
||||||
|
xms
|
||||||
|
)
|
||||||
|
|
||||||
|
# copy dlls for baby windows
|
||||||
|
add_custom_command(TARGET ${target} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${target}>
|
||||||
|
$<TARGET_RUNTIME_DLLS:${target}>
|
||||||
|
COMMAND_EXPAND_LISTS
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
give_options(${PROJECT_NAME})
|
||||||
|
link_and_include_deps(${PROJECT_NAME})
|
||||||
|
|
||||||
|
add_executable(game ${GAME_SOURCE_FILES})
|
||||||
|
use_townengine(game)
|
||||||
|
|
||||||
# zip up assets
|
# zip up assets
|
||||||
# currently, you must run cmake from the project root dir for this to work correctly
|
# currently, you must run cmake from the project root dir for this to work correctly
|
||||||
|
Loading…
Reference in New Issue
Block a user