hot reloading and friends
This commit is contained in:
@ -18,6 +18,8 @@ endif ()
|
||||
set(TOWNENGINE_TARGET townengine CACHE INTERNAL "")
|
||||
set(TOWNENGINE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
|
||||
|
||||
add_compile_options($<$<BOOL:${TOWNENGINE_HOT_RELOAD}>:-fPIC>)
|
||||
|
||||
set(PHYSFS_BUILD_SHARED FALSE)
|
||||
set(PHYSFS_DISABLE_INSTALL TRUE)
|
||||
set(PHYSFS_TARGETNAME_UNINSTALL "physfs_uninstall")
|
||||
@ -33,10 +35,11 @@ add_subdirectory(third-party/physfs)
|
||||
add_subdirectory(third-party/libxm)
|
||||
|
||||
|
||||
option(TOWNENGINE_HOT_RELOAD "Enable hot reloading support" TRUE)
|
||||
|
||||
|
||||
if(UNIX)
|
||||
set(SYSTEM_SOURCE_FILES
|
||||
townengine/system/linux/elf.c
|
||||
)
|
||||
set(SYSTEM_SOURCE_FILES townengine/system/linux/elf.c)
|
||||
else()
|
||||
set(SYSTEM_SOURCE_FILES)
|
||||
endif()
|
||||
@ -48,21 +51,25 @@ set(TOWNENGINE_SOURCE_FILES
|
||||
|
||||
townengine/main.c
|
||||
townengine/config.h
|
||||
townengine/context.c townengine/context.h
|
||||
townengine/audio.c townengine/audio.h
|
||||
townengine/context/context.c townengine/context.h
|
||||
townengine/audio/audio.c townengine/audio.h
|
||||
townengine/util.c townengine/util.h
|
||||
townengine/rendering.c townengine/rendering.h
|
||||
townengine/input.c townengine/input.h
|
||||
townengine/input/input.c townengine/input.h
|
||||
townengine/text.c townengine/text.h
|
||||
townengine/camera.c townengine/camera.h
|
||||
townengine/textures/textures.c
|
||||
|
||||
${SYSTEM_SOURCE_FILES}
|
||||
)
|
||||
${SYSTEM_SOURCE_FILES})
|
||||
|
||||
list(TRANSFORM TOWNENGINE_SOURCE_FILES PREPEND ${TOWNENGINE_DIR}/)
|
||||
|
||||
# base engine code, reused for games and tools
|
||||
add_library(${TOWNENGINE_TARGET} ${TOWNENGINE_SOURCE_FILES})
|
||||
if (TOWNENGINE_HOT_RELOAD)
|
||||
add_library(${TOWNENGINE_TARGET} SHARED ${TOWNENGINE_SOURCE_FILES})
|
||||
else ()
|
||||
add_library(${TOWNENGINE_TARGET} STATIC ${TOWNENGINE_SOURCE_FILES})
|
||||
endif ()
|
||||
source_group(TREE ${TOWNENGINE_DIR} FILES ${TOWNENGINE_SOURCE_FILES})
|
||||
|
||||
set_target_properties(${TOWNENGINE_TARGET} PROPERTIES
|
||||
@ -72,8 +79,7 @@ set_target_properties(${TOWNENGINE_TARGET} PROPERTIES
|
||||
|
||||
target_precompile_headers(${TOWNENGINE_TARGET} PRIVATE
|
||||
third-party/glad/include/glad/glad.h
|
||||
third-party/stb/stb_ds.h
|
||||
)
|
||||
third-party/stb/stb_ds.h)
|
||||
|
||||
# distribution definitions
|
||||
set(ORGANIZATION_NAME "wanp" CACHE STRING
|
||||
@ -156,11 +162,12 @@ function(give_options target)
|
||||
target_compile_definitions(${target} PRIVATE
|
||||
ORGANIZATION_NAME="${ORGANIZATION_NAME}"
|
||||
APP_NAME="${APP_NAME}"
|
||||
PACKAGE_EXTENSION="${PACKAGE_EXTENSION}")
|
||||
PACKAGE_EXTENSION="${PACKAGE_EXTENSION}"
|
||||
$<$<BOOL:${TOWNENGINE_HOT_RELOAD}>:HOT_RELOAD_SUPPORT>)
|
||||
endfunction()
|
||||
|
||||
|
||||
function(link_and_include_deps target)
|
||||
function(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)
|
||||
set(THIRD_PARTY_INCLUDES
|
||||
@ -169,57 +176,65 @@ function(link_and_include_deps target)
|
||||
third-party/libxm/include
|
||||
third-party/glad/include
|
||||
third-party/stb
|
||||
)
|
||||
third-party/x-watcher)
|
||||
|
||||
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 ${TOWNENGINE_DIR})
|
||||
|
||||
target_link_libraries(${target} PUBLIC
|
||||
SDL2::SDL2
|
||||
SDL2::SDL2main
|
||||
SDL2_image::SDL2_image
|
||||
SDL2_ttf::SDL2_ttf
|
||||
physfs-static
|
||||
xms
|
||||
)
|
||||
endfunction()
|
||||
|
||||
|
||||
function(use_townengine target sources)
|
||||
add_executable(${target} ${sources})
|
||||
|
||||
# system libraries
|
||||
find_library(MATH_LIBRARY m)
|
||||
if(MATH_LIBRARY)
|
||||
target_link_libraries(${target} PUBLIC ${MATH_LIBRARY})
|
||||
endif()
|
||||
|
||||
give_options(${target})
|
||||
link_and_include_deps(${target})
|
||||
|
||||
# third-party libraries
|
||||
function(link_deps target)
|
||||
target_link_libraries(${target} PUBLIC
|
||||
${TOWNENGINE_TARGET}
|
||||
SDL2::SDL2
|
||||
SDL2::SDL2main
|
||||
SDL2_image::SDL2_image
|
||||
SDL2_ttf::SDL2_ttf
|
||||
physfs-static
|
||||
xms
|
||||
)
|
||||
xms)
|
||||
endfunction()
|
||||
|
||||
|
||||
function(use_townengine target sources output_directory)
|
||||
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} ${CMAKE_SOURCE_DIR}/townengine/null.c)
|
||||
else ()
|
||||
add_executable(${target} ${sources})
|
||||
endif ()
|
||||
|
||||
# system libraries
|
||||
find_library(MATH_LIBRARY m)
|
||||
if (MATH_LIBRARY)
|
||||
target_link_libraries(${target} 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
|
||||
RUNTIME_OUTPUT_DIRECTORY ${output_directory})
|
||||
|
||||
# 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
|
||||
)
|
||||
COMMAND_EXPAND_LISTS)
|
||||
endfunction()
|
||||
|
||||
give_options(${TOWNENGINE_TARGET})
|
||||
link_and_include_deps(${TOWNENGINE_TARGET})
|
||||
include_deps(${TOWNENGINE_TARGET})
|
||||
link_deps(${TOWNENGINE_TARGET})
|
||||
|
||||
if (${CMAKE_PROJECT_NAME} MATCHES townengine)
|
||||
add_subdirectory(apps/testgame)
|
||||
|
Reference in New Issue
Block a user