This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
183 lines (151 loc) · 5.59 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
message("CMake version is : ${CMAKE_VERSION}")
project(ExperimEngine VERSION 0.0.1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Header configuration
configure_file(ExperimEngineConfig.h.in ExperimEngineConfig.h)
# Engine library target
set(ENGINE_LIB_TARGET_NAME LibExperimEngine)
add_library(${ENGINE_LIB_TARGET_NAME} STATIC "")
#####################
# Engine sources
#####################
add_subdirectory(src/engine)
add_subdirectory(src/engine/log)
add_subdirectory(src/engine/render)
add_subdirectory(src/engine/render/imgui/)
add_subdirectory(src/engine/render/imgui/lib)
add_subdirectory(src/engine/render/imgui/widgets)
add_subdirectory(src/engine/render/resources)
add_subdirectory(src/engine/utils)
if(WEB_TARGET)
add_subdirectory(src/engine/render/wgpu)
add_subdirectory(src/engine/render/wgpu/resources)
add_subdirectory(src/engine/render/imgui/wgpu)
else()
add_subdirectory(src/engine/render/vlk)
add_subdirectory(src/engine/render/vlk/resources)
add_subdirectory(src/engine/render/imgui/vlk)
endif()
# Here if needed : add external CMake build files :
# add_subdirectory(external/shaderc)
#####################
# Engine includes
#####################
# Common
target_include_directories(${ENGINE_LIB_TARGET_NAME} PUBLIC
${PROJECT_BINARY_DIR} # For CMake generated headers
${PROJECT_SOURCE_DIR}/includes
${PROJECT_SOURCE_DIR}/includes/lua
${PROJECT_SOURCE_DIR}/src
)
# Web-target
if(WEB_TARGET)
# Unused line below : can be used to generate the emscripten html wrapper, since a custom template is used
# set(CMAKE_EXECUTABLE_SUFFIX ".html")
target_include_directories(${ENGINE_LIB_TARGET_NAME} PUBLIC
"${EMSCRIPTEN_ROOT_PATH}/system/include" # Emscripten headers
)
# Native
else()
target_include_directories(${ENGINE_LIB_TARGET_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/includes/dawn
)
endif()
#####################
# Linking libraries to the engine
#####################
# Native specific
if(NOT WEB_TARGET)
# Link with libraries.
# TODO : x64/x86 flags
set(LIBS_DIR ${PROJECT_SOURCE_DIR}/libs)
target_link_libraries(${ENGINE_LIB_TARGET_NAME} PRIVATE
${LIBS_DIR}/lua/lua51.lib
${LIBS_DIR}/SDL2/x64/SDL2.lib
${LIBS_DIR}/SDL2/x64/SDL2main.lib
#${LIBS_DIR}/dawn/dawn_native.dll.lib
#${LIBS_DIR}/dawn/dawn_platform.dll.lib
# shaderc
)
endif()
#####################
# Compile definitions
#####################
if(WEB_TARGET)
# This is already defined by the toolchain, but redefined here so that Visual Studio/Intellisense can pick it up
target_compile_definitions(${ENGINE_LIB_TARGET_NAME} PUBLIC __EMSCRIPTEN__)
endif()
target_compile_definitions(${ENGINE_LIB_TARGET_NAME} PUBLIC __EXPERIMENGINE__)
#####################
# For engine applications
#####################
# Function that can be used by an Engine application to :
# - set the includes directories to access the engine API
# - set the appropriate link flags according to the target environment (Web, Win, Release, ...)
# - set the link dependency to the engine library
# argument 'engineTarget' should be the cmake target of the application
# argument 'engineRootPath' should be the path to the engine directory
function(add_experimengine_target engineTarget engineRootPath)
message("Added ExperimEngine target ${engineTarget}")
# Include directories to access the engine API
target_include_directories(${engineTarget} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/includes
${CMAKE_CURRENT_SOURCE_DIR}/includes/lua
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Common commands, pre-link for the virtual file system in web builds
add_custom_command(TARGET ${engineTarget} PRE_LINK
# Data files
COMMAND ${CMAKE_COMMAND} -E copy_directory ${engineRootPath}/data $<TARGET_FILE_DIR:${engineTarget}>/data
)
# Web-target properties
if(WEB_TARGET)
# Preload runtime files to a virtual file system
# TODO Expose files as an argument
set_target_properties(${engineTarget} PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGPU=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file ${CMAKE_CURRENT_BINARY_DIR}/data@/data")
# Native properties
else()
# Windows specific : linking
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL Release)
message("Console disabled in win32-release build")
set_target_properties(
${engineTarget} PROPERTIES
LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE"
LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
endif()
endif()
endif()
# Web-target commands
if(WEB_TARGET)
add_custom_command(TARGET ${engineTarget} POST_BUILD
# Web html template
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${engineRootPath}/tools/emscripten/index.html $<TARGET_FILE_DIR:${engineTarget}>
)
# Native commands
else()
add_custom_command(TARGET ${engineTarget} POST_BUILD
# Binaries
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${engineRootPath}/libs/lua/lua51.dll $<TARGET_FILE_DIR:${engineTarget}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${engineRootPath}/libs/SDL2/x64/SDL2.dll $<TARGET_FILE_DIR:${engineTarget}>
)
endif()
target_link_libraries(${engineTarget} LibExperimEngine)
endfunction()
#####################
# Build a test application
#####################
# If this is the main project, not if included through add_subdirectory
#if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message("Building sample application")
set(ENGINE_APP_BUILD_TARGET_NAME ExperimEngineTest)
add_executable(${ENGINE_APP_BUILD_TARGET_NAME} "")
add_subdirectory(src/tests)
if(NOT WEB_TARGET)
# Lua interpreter/jit not yet compiled to WASM
add_subdirectory(src/tests/lua)
endif()
add_experimengine_target(${ENGINE_APP_BUILD_TARGET_NAME} ${PROJECT_SOURCE_DIR})
#endif()