twn_amalgam.c: a way for single unit compilation, controlled with -DTWN_USE_AMALGAM in cmake
This commit is contained in:
parent
9329d3c2be
commit
ed93072371
@ -24,6 +24,7 @@ set(TWN_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
|
|||||||
|
|
||||||
# feature configuration, set them with -DFEATURE=ON/OFF in cli
|
# feature configuration, set them with -DFEATURE=ON/OFF in cli
|
||||||
option(TWN_FEATURE_DYNLIB_GAME "Enable dynamic library loading support" ON)
|
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
|
# todo: figure out how to compile for dynamic linking instead
|
||||||
if(EMSCRIPTEN)
|
if(EMSCRIPTEN)
|
||||||
@ -88,7 +89,8 @@ set(TWN_THIRD_PARTY_SOURCE_FILES
|
|||||||
third-party/tomlc99/toml.c
|
third-party/tomlc99/toml.c
|
||||||
$<$<NOT:$<BOOL:${EMSCRIPTEN}>>:third-party/glad/src/glad.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_loop.c
|
||||||
src/twn_main.c
|
src/twn_main.c
|
||||||
src/twn_context.c include/twn_context.h
|
src/twn_context.c include/twn_context.h
|
||||||
@ -104,7 +106,10 @@ set(TWN_SOURCE_FILES
|
|||||||
src/rendering/twn_triangles.c
|
src/rendering/twn_triangles.c
|
||||||
src/rendering/twn_circles.c
|
src/rendering/twn_circles.c
|
||||||
src/rendering/twn_skybox.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
|
# for dynamic load based solution main is compiled in a separate target
|
||||||
$<$<NOT:$<BOOL:${TWN_FEATURE_DYNLIB_GAME}>>:src/twn_main.c
|
$<$<NOT:$<BOOL:${TWN_FEATURE_DYNLIB_GAME}>>:src/twn_main.c
|
||||||
@ -113,6 +118,7 @@ set(TWN_SOURCE_FILES
|
|||||||
${SYSTEM_SOURCE_FILES})
|
${SYSTEM_SOURCE_FILES})
|
||||||
|
|
||||||
list(TRANSFORM TWN_SOURCE_FILES PREPEND ${TWN_ROOT_DIR}/)
|
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})
|
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})
|
add_library(${TWN_TARGET} STATIC ${TWN_SOURCE_FILES} ${twn_third_parties})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
source_group(TREE ${TWN_ROOT_DIR} FILES ${TWN_SOURCE_FILES})
|
|
||||||
|
|
||||||
set_target_properties(${TWN_TARGET} PROPERTIES
|
set_target_properties(${TWN_TARGET} PROPERTIES
|
||||||
C_STANDARD 11
|
C_STANDARD 11
|
||||||
C_STANDARD_REQUIRED ON
|
C_STANDARD_REQUIRED ON
|
||||||
|
19
src/twn_amalgam.c
Normal file
19
src/twn_amalgam.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* a technique for faster compilation */
|
||||||
|
/* it includes all non-optional .c files directly in a single compilation unit */
|
||||||
|
|
||||||
|
#include "twn_audio.c"
|
||||||
|
#include "twn_camera.c"
|
||||||
|
#include "twn_context.c"
|
||||||
|
#include "twn_input.c"
|
||||||
|
#include "twn_loop.c"
|
||||||
|
#include "twn_main.c"
|
||||||
|
#include "twn_textures.c"
|
||||||
|
#include "twn_util.c"
|
||||||
|
|
||||||
|
#include "rendering/twn_circles.c"
|
||||||
|
#include "rendering/twn_draw.c"
|
||||||
|
#include "rendering/twn_fog.c"
|
||||||
|
#include "rendering/twn_skybox.c"
|
||||||
|
#include "rendering/twn_sprites.c"
|
||||||
|
#include "rendering/twn_text.c"
|
||||||
|
#include "rendering/twn_triangles.c"
|
24
src/twn_stb.c
Normal file
24
src/twn_stb.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* single compilation unit for every stb implementation */
|
||||||
|
|
||||||
|
#define STB_DS_IMPLEMENTATION
|
||||||
|
#define STBDS_ASSERT SDL_assert
|
||||||
|
#define STBDS_REALLOC(context,ptr,size) ((void)(context), SDL_realloc(ptr, size))
|
||||||
|
#define STBDS_FREE(context,ptr) ((void)(context), SDL_free(ptr))
|
||||||
|
#include <stb_ds.h>
|
||||||
|
|
||||||
|
#define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#define STBRP_SORT SDL_qsort
|
||||||
|
#define STBRP_ASSERT SDL_assert
|
||||||
|
#include <stb_rect_pack.h>
|
||||||
|
|
||||||
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
#define STBTT_malloc(x,u) ((void)(u), SDL_malloc(x))
|
||||||
|
#define STBTT_free(x,u) ((void)(u), SDL_free(x))
|
||||||
|
#define STBTT_assert(x) SDL_assert(x)
|
||||||
|
#define STBTT_strlen(x) SDL_strlen(x)
|
||||||
|
#define STBTT_memcpy SDL_memcpy
|
||||||
|
#define STBTT_memset SDL_memset
|
||||||
|
#include <stb_truetype.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include <stb_image.h>
|
@ -8,8 +8,6 @@
|
|||||||
#include <physfsrwops.h>
|
#include <physfsrwops.h>
|
||||||
#include <stb_ds.h>
|
#include <stb_ds.h>
|
||||||
#include <stb_rect_pack.h>
|
#include <stb_rect_pack.h>
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -4,23 +4,7 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <physfsrwops.h>
|
#include <physfsrwops.h>
|
||||||
#define STB_DS_IMPLEMENTATION
|
|
||||||
#define STBDS_ASSERT SDL_assert
|
|
||||||
#define STBDS_REALLOC(context,ptr,size) ((void)(context), SDL_realloc(ptr, size))
|
|
||||||
#define STBDS_FREE(context,ptr) ((void)(context), SDL_free(ptr))
|
|
||||||
#include <stb_ds.h>
|
#include <stb_ds.h>
|
||||||
#define STB_RECT_PACK_IMPLEMENTATION
|
|
||||||
#define STBRP_SORT SDL_qsort
|
|
||||||
#define STBRP_ASSERT SDL_assert
|
|
||||||
#include <stb_rect_pack.h>
|
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
|
||||||
#define STBTT_malloc(x,u) ((void)(u), SDL_malloc(x))
|
|
||||||
#define STBTT_free(x,u) ((void)(u), SDL_free(x))
|
|
||||||
#define STBTT_assert(x) SDL_assert(x)
|
|
||||||
#define STBTT_strlen(x) SDL_strlen(x)
|
|
||||||
#define STBTT_memcpy SDL_memcpy
|
|
||||||
#define STBTT_memset SDL_memset
|
|
||||||
#include <stb_truetype.h>
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user