twn_amalgam.c: a way for single unit compilation, controlled with -DTWN_USE_AMALGAM in cmake

This commit is contained in:
2024-10-13 19:04:23 +03:00
parent 9329d3c2be
commit ed93072371
5 changed files with 51 additions and 22 deletions

View File

@ -24,6 +24,7 @@ set(TWN_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
# feature configuration, set them with -DFEATURE=ON/OFF in cli
option(TWN_FEATURE_DYNLIB_GAME "Enable dynamic library loading support" ON)
option(TWN_USE_AMALGAM "Enable use of twn_amalgam.c as a single compilation unit" ON)
# todo: figure out how to compile for dynamic linking instead
if(EMSCRIPTEN)
@ -88,7 +89,8 @@ set(TWN_THIRD_PARTY_SOURCE_FILES
third-party/tomlc99/toml.c
$<$<NOT:$<BOOL:${EMSCRIPTEN}>>:third-party/glad/src/glad.c>)
set(TWN_SOURCE_FILES
set(TWN_NONOPT_SOURCE_FILES
src/twn_stb.c
src/twn_loop.c
src/twn_main.c
src/twn_context.c include/twn_context.h
@ -104,7 +106,10 @@ set(TWN_SOURCE_FILES
src/rendering/twn_triangles.c
src/rendering/twn_circles.c
src/rendering/twn_skybox.c
src/rendering/twn_fog.c
src/rendering/twn_fog.c)
set(TWN_SOURCE_FILES
$<IF:$<BOOL:${TWN_USE_AMALGAM}>,src/twn_amalgam.c src/twn_stb.c,${TWN_NONOPT_SOURCE_FILES}>
# for dynamic load based solution main is compiled in a separate target
$<$<NOT:$<BOOL:${TWN_FEATURE_DYNLIB_GAME}>>:src/twn_main.c
@ -113,6 +118,7 @@ set(TWN_SOURCE_FILES
${SYSTEM_SOURCE_FILES})
list(TRANSFORM TWN_SOURCE_FILES PREPEND ${TWN_ROOT_DIR}/)
source_group(TREE ${TWN_ROOT_DIR} FILES ${TWN_NONOPT_SOURCE_FILES})
add_library(twn_third_parties STATIC ${TWN_THIRD_PARTY_SOURCE_FILES})
@ -123,8 +129,6 @@ else()
add_library(${TWN_TARGET} STATIC ${TWN_SOURCE_FILES} ${twn_third_parties})
endif()
source_group(TREE ${TWN_ROOT_DIR} FILES ${TWN_SOURCE_FILES})
set_target_properties(${TWN_TARGET} PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON