-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
80 lines (63 loc) · 2.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
cmake_minimum_required(VERSION 3.21)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
# Determine version from the vcpkg json manifest
file(READ vcpkg.json VCPKG_MANIFEST)
string(JSON VCPKG_VERSION GET ${VCPKG_MANIFEST} "version")
project(toybox
VERSION ${VCPKG_VERSION}
DESCRIPTION "A personal game engine toybox project"
LANGUAGES C CXX)
option(TB_BUILD_SAMPLES "Compile samples" ON)
option(TB_BUILD_VIEWER "Build the viewer application" ON)
option(TB_FINAL "Compile with the intention to redistribute" OFF)
option(TB_PROFILE_TRACY "Compile with support for the tracy profiler" ON)
# Include Helpers
include(${CMAKE_MODULE_PATH}/tb_app.cmake)
include(${CMAKE_MODULE_PATH}/tb_cooking.cmake)
include(${CMAKE_MODULE_PATH}/tb_packages.cmake)
# Generate config header
execute_process(COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(tb_engine_config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config)
configure_file(source/tb_config.h.in ${tb_engine_config_include_dir}/tb_engine_config.h @ONLY)
# Setup toybox as an object library
file(GLOB_RECURSE lib_source CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.c" "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/source/*.h")
add_library(toybox OBJECT ${lib_source})
# Add default options
tb_options(toybox)
# Set include directories
target_include_directories(toybox PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include")
target_include_directories(toybox PUBLIC "source/" "${CGLTF_INCLUDE_DIRS}" "${tb_engine_config_include_dir}")
# Mingw generates warnings from generated shader headers. Include as a system directory to ignore
target_include_directories(toybox SYSTEM PUBLIC "${CMAKE_CFG_INTDIR_ABS}/shaders")
# Link libraries
target_link_libraries(toybox PUBLIC ${tb_library_list})
if(TB_PROFILE_TRACY)
target_link_libraries(toybox PUBLIC "Tracy::TracyClient")
endif()
if(TB_STATIC)
target_link_libraries(toybox PUBLIC SDL3::SDL3-static)
else()
target_link_libraries(toybox PUBLIC SDL3::SDL3)
endif()
target_link_libraries(toybox PUBLIC $<IF:$<TARGET_EXISTS:SDL3_mixer::SDL3_mixer>,SDL3_mixer::SDL3_mixer,SDL3_mixer::SDL3_mixer-static>)
# Cook engine shaders
tb_cook_shaders(tb_engine_shader_sources tb_engine_shader_headers)
add_custom_target(tb_engine_shaders ALL DEPENDS ${tb_engine_shader_headers})
target_sources(tb_engine_shaders PRIVATE ${tb_engine_shader_sources})
add_dependencies(toybox tb_engine_shaders)
# Cook engine assets
if(TB_COOK_ASSETS)
tb_cook_assets(toybox engine_assets_path)
endif()
# Add optional sub-projects
if(TB_BUILD_SAMPLES)
add_subdirectory(samples)
endif()
if(TB_BUILD_VIEWER)
add_subdirectory(viewer)
endif()
# Continue on to configure addons
include(${CMAKE_CURRENT_LIST_DIR}/addons/CMakeLists.txt)