-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·256 lines (218 loc) · 9.34 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(krit)
cmake_policy(SET CMP0072 NEW)
cmake_policy(SET CMP0077 NEW)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
option(BUILD_WINDOWS "Cross-compile for Windows using mingw-w64" OFF)
option(KRIT_ENABLE_MULTISAMPLING "Whether to use multisampling for framebuffers" ON)
option(KRIT_ENABLE_THREADS "Whether task managers should use multiple threads" ON)
option(KRIT_ENABLE_TOOLS "Include imgui and devtools functionality" OFF)
option(KRIT_ENABLE_TRACY "Enable profiling hooks for Tracy" OFF)
option(KRIT_USE_GLEW "Whether to use glew instead of direct GL" ON)
option(KRIT_QUICKJS_DUMP_LEAKS "Dump any JS leaks on exit" OFF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -MMD -MF .obj/.d -Wno-array-bounds -Wno-format-truncation -D_GNU_SOURCE -DCONFIG_VERSION=\\\"2021-03-27\\\" -fno-omit-frame-pointer -fasynchronous-unwind-tables")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -O2")
set(CMAKE_C_FLAGS_PROF "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_PROF}")
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-parentheses -Wno-unused-result -Wno-c99-designator -Wall -ffunction-sections -fdata-sections -Os -fno-rtti -falign-functions=1 -fmerge-all-constants -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffunction-sections -fdata-sections -DKRIT_RELEASE")
set(CMAKE_CXX_FLAGS_PROF "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_PROF} -Wno-sometimes-uninitialized -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_ASAN} -fsanitize=address -fsanitize=undefined")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -rdynamic")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -lmcheck")
set(CMAKE_LINKER_FLAGS_ASAN "${CMAKE_LINKER_FLAGS_DEBUG} ${CMAKE_LINKER_FLAGS_ASAN} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
set(CMAKE_LINKER_FLAGS_PROF "${CMAKE_LINKER_FLAGS_RELEASE} ${CMAKE_LINKER_FLAGS_PROF}")
list(APPEND KRIT_LIBS)
list(APPEND KRIT_STATIC_LIBS)
if(KRIT_ENABLE_TOOLS)
message(STATUS "tools enabled")
add_definitions(-DKRIT_ENABLE_TOOLS)
file(GLOB_RECURSE TOOLS_FILES CONFIGURE_DEPENDS ${KRIT_DIR}/imgui/*.cpp)
include_directories(${KRIT_DIR}/imgui)
endif()
file(GLOB KRIT_SRC_FILES CONFIGURE_DEPENDS
${KRIT_DIR}/src/krit/*.cpp
${KRIT_DIR}/src/krit/asset/*.cpp
${KRIT_DIR}/src/krit/behavior/*.cpp
${KRIT_DIR}/src/krit/data/*.cpp
${KRIT_DIR}/src/krit/ecs/*.cpp
${KRIT_DIR}/src/krit/input/*.cpp
${KRIT_DIR}/src/krit/io/*.cpp
${KRIT_DIR}/src/krit/l12n/*.cpp
${KRIT_DIR}/src/krit/math/*.cpp
${KRIT_DIR}/src/krit/net/*.cpp
${KRIT_DIR}/src/krit/platform/*.cpp
${KRIT_DIR}/src/krit/render/*.cpp
${KRIT_DIR}/src/krit/renderer/*.cpp
${KRIT_DIR}/src/krit/sound/*.cpp
${KRIT_DIR}/src/krit/sprites/*.cpp
${KRIT_DIR}/src/krit/state/*.cpp
${KRIT_DIR}/src/krit/utils/*.cpp
)
file(GLOB_RECURSE KRIT_THIRDPARTY_FILES CONFIGURE_DEPENDS ${KRIT_DIR}/spine-runtimes/spine-cpp/spine-cpp/src/spine/*.cpp)
file(GLOB_RECURSE KRIT_SCRIPT_FILES CONFIGURE_DEPENDS
${KRIT_DIR}/src/krit/script/*.cpp
)
list(APPEND KRIT_SRC_FILES ${KRIT_SCRIPT_FILES})
if(KRIT_ENABLE_TRACY)
add_definitions(-DTRACY_ENABLE)
# list(APPEND KRIT_SRC_FILES ${KRIT_DIR}/tracy/public/TracyClient.cpp)
# include_directories(${KRIT_DIR}/tracy/public/)
list(APPEND KRIT_SRC_FILES ${KRIT_DIR}/tracy/TracyClient.cpp)
include_directories(${KRIT_DIR}/tracy)
endif()
if(KRIT_ENABLE_TOOLS)
file(GLOB_RECURSE KRIT_EDITOR_FILES CONFIGURE_DEPENDS
${KRIT_DIR}/src/krit/editor/*.cpp
)
list(APPEND KRIT_SRC_FILES ${KRIT_EDITOR_FILES})
endif()
if(BUILD_WINDOWS)
include(${KRIT_DIR}/toolchain/windows.cmake)
add_definitions(-DKRIT_WINDOWS)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
include(${KRIT_DIR}/toolchain/emscripten.cmake)
add_definitions(-DKRIT_EMSCRIPTEN)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
include(${KRIT_DIR}/toolchain/linux.cmake)
add_definitions(-DKRIT_LINUX)
else()
message(FATAL_ERROR "Unrecognized platform")
endif()
if(KRIT_USE_GLEW)
add_definitions(-DKRIT_USE_GLEW -DGLEW_STATIC)
list(APPEND KRIT_SRC_FILES ${KRIT_DIR}/src/GL/glew.c)
endif()
if(KRIT_BACKEND_IO STREQUAL "File")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/io/IoFile.cpp
)
elseif(KRIT_BACKEND_IO STREQUAL "Zip")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/io/IoZip.cpp
)
else()
message(FATAL_ERROR "unrecognized IO backend: ${KRIT_BACKEND_IO}")
endif()
if(KRIT_BACKEND_PLATFORM STREQUAL "Desktop")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/platform/PlatformDesktop.cpp
)
elseif(KRIT_BACKEND_PLATFORM STREQUAL "Web")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/platform/PlatformWeb.cpp
)
else()
message(FATAL_ERROR "unrecognized platform backend: ${KRIT_BACKEND_PLATFORM}")
endif()
if(KRIT_BACKEND_RENDERER STREQUAL "Gl")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/renderer/RendererGl.cpp
)
else()
message(FATAL_ERROR "unrecognized renderer backend: ${KRIT_BACKEND_RENDERER}")
endif()
if(KRIT_BACKEND_NET STREQUAL "Curl")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/net/NetCurl.cpp
)
elseif(KRIT_BACKEND_NET STREQUAL "Fetch")
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/backend/net/NetFetch.cpp
)
else()
message(FATAL_ERROR "unrecognized net backend: ${KRIT_BACKEND_NET}")
endif()
include_directories(${KRIT_INCLUDE_PATHS})
include_directories(${KRIT_DIR}/backend)
include_directories(${KRIT_DIR}/src)
include_directories(${KRIT_DIR}/spine-runtimes/spine-cpp/spine-cpp/include)
include_directories(${KRIT_DIR}/quickjs)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
# string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES)
file(GLOB_RECURSE KRIT_GENERATED_FILES
CONFIGURE_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/krit/script/ScriptBridge.cpp
${CMAKE_CURRENT_BINARY_DIR}/krit/script/ScriptClass.*.cpp
)
if(KRIT_QUICKJS_DUMP_LEAKS)
add_definitions(-DDUMP_LEAKS)
endif()
list(APPEND KRIT_SRC_FILES
${KRIT_DIR}/quickjs/quickjs.h
${KRIT_DIR}/quickjs/quickjs.c
${KRIT_DIR}/quickjs/libregexp.c
${KRIT_DIR}/quickjs/libunicode.c
${KRIT_DIR}/quickjs/libbf.c
${KRIT_DIR}/quickjs/cutils.c
)
add_library(${PROJECT_NAME} OBJECT
${KRIT_GENERATED_FILES}
${KRIT_SRC_FILES}
${KRIT_THIRDPARTY_FILES}
${TOOLS_FILES}
)
if(KRIT_ENABLE_THREADS)
add_definitions(-DKRIT_ENABLE_THREADS)
endif()
if(KRIT_ENABLE_MULTISAMPLING)
add_definitions(-DKRIT_ENABLE_MULTISAMPLING)
endif()
include_directories(${KRIT_DIR}/src)
include_directories(${KRIT_DIR}/spine-runtimes/spine-cpp/spine-cpp/include)
include_directories(${KRIT_DIR}/imgui)
include_directories(${KRIT_DIR}/quickjs)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
message(STATUS "toolchain library path:${TOOLCHAIN_LIB_PATH} prefixes:${CMAKE_FIND_LIBRARY_PREFIXES} suffixes:${CMAKE_FIND_LIBRARY_SUFFIXES}")
if(KRIT_ENABLE_THREADS)
list(APPEND KRIT_STATIC_LIBS "-lpthread")
endif()
message("==> static libs: ${KRIT_STATIC_LIBS}")
if(KRIT_ENABLE_TOOLS)
# find_library(NFD_LIB NAMES nfd HINTS "${TOOLCHAIN_LIB_PATH}" CMAKE_FIND_ROOT_PATH_BOTH)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
# list(APPEND KRIT_STATIC_LIBS ${NFD_LIB})
list(APPEND KRIT_LIBS ${GTK3_LIBRARIES})
endif()
target_link_libraries(${PROJECT_NAME}
PUBLIC
"-Wl,-Bdynamic"
${KRIT_LIBS}
${KRIT_STATIC}
${KRIT_STATIC_LIBS}
${KRIT_PLATFORM_STATIC_LIBS}
"-Wl,--gc-sections"
)
target_include_directories(${PROJECT_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS})
file(GLOB_RECURSE KRIT_EDITOR_FILES CONFIGURE_DEPENDS
${KRIT_DIR}/tools/tsbindgen/src/*.ts
)
add_custom_command(
OUTPUT ${KRIT_DIR}/tools/tsbindgen/dist/index.js
DEPENDS ${BINDGEN_SRC_FILES}
COMMAND cd ${KRIT_DIR}/tools/tsbindgen && npm install && npm run build
)
function(tsbindgen BRIDGE_SRC_DIR PREFIX NAMESPACE)
message("tsbindgen: ${BRIDGE_SRC_DIR}")
file(GLOB_RECURSE BRIDGE_TYPE_DEFS CONFIGURE_DEPENDS ${BRIDGE_SRC_DIR}/*.d.ts)
set(BRIDGE_OUTPUTS "")
foreach(BRIDGE ${BRIDGE_TYPE_DEFS})
file(RELATIVE_PATH BRIDGE_RELATIVE ${BRIDGE_SRC_DIR} ${BRIDGE})
set_directory_properties(PROPERTIES CMAKE_CONFIGURE_DEPENDS ${BRIDGE})
list(APPEND BRIDGE_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/${PREFIX}/${BRIDGE_RELATIVE}.ScriptClass.cpp")
endforeach()
get_property(CURRENT_BRIDGE_NAMESPACES GLOBAL PROPERTY BRIDGE_NAMESPACES)
message("cd ${KRIT_DIR}/tools/tsbindgen && node dist/index.js -n ${NAMESPACE}:${BRIDGE_SRC_DIR} ${CURRENT_BRIDGE_NAMESPACES} -s ${BRIDGE_SRC_DIR} -o ${CMAKE_CURRENT_BINARY_DIR}/${PREFIX}")
add_custom_command(
OUTPUT ${BRIDGE_OUTPUTS}
DEPENDS ${BRIDGE_TYPE_DEFS} ${KRIT_DIR}/tools/tsbindgen/dist/index.js ${KRIT_DIR}/tools/tsbindgen/templates/ScriptClass.cpp.njk
COMMAND cd ${KRIT_DIR}/tools/tsbindgen && node dist/index.js -n ${NAMESPACE}:${BRIDGE_SRC_DIR} ${CURRENT_BRIDGE_NAMESPACES} -s ${BRIDGE_SRC_DIR} -o "${CMAKE_CURRENT_BINARY_DIR}/${PREFIX}"
)
target_sources(${PROJECT_NAME} PRIVATE ${BRIDGE_OUTPUTS})
set_property(GLOBAL PROPERTY BRIDGE_NAMESPACES "${CURRENT_BRIDGE_NAMESPACES}" "-n" "${NAMESPACE}:${BRIDGE_SRC_DIR}")
endfunction()
tsbindgen(${KRIT_DIR}/src generated/krit krit)