-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
257 lines (221 loc) · 7.7 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
257
cmake_minimum_required(VERSION 3.16)
include(cmake/utilities.cmake)
# ALIA_IS_MAIN_PROJECT defines whether we are building alia as the main
# project or as a dependency of another project.
if(NOT DEFINED ALIA_IS_MAIN_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(ALIA_IS_MAIN_PROJECT ON)
else()
set(ALIA_IS_MAIN_PROJECT OFF)
endif()
endif()
alia_detect_emscripten()
# Set VCPKG target triplet to support the Skia build.
if (ALIA_IS_MAIN_PROJECT AND WIN32)
# This assumes we're doing a 64-bit build. It seems impossible to verify
# that at this point in the CMake execution - it's possible after the call
# to `project()`, but we need to set these variables before that - but we
# could add an option to support 32-bit builds.
set(VCPKG_TARGET_TRIPLET x64-windows-mixed)
set(VCPKG_HOST_TRIPLET x64-windows-mixed)
endif()
# Define our options...
# As we define the options, we also add the corresponding vcpkg options.
option(
ALIA_ENABLE_TESTING
"Generate targets for testing alia"
${ALIA_IS_MAIN_PROJECT})
if(ALIA_ENABLE_TESTING)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()
include(CMakeDependentOption)
option(
ALIA_ENABLE_UI
"Enable the UI library"
ON)
if(ALIA_ENABLE_UI)
list(APPEND VCPKG_MANIFEST_FEATURES "ui")
endif()
cmake_dependent_option(
ALIA_ENABLE_GLFW
"Enable the GLFW backend for the UI library"
ON
"ALIA_ENABLE_UI"
OFF)
if(ALIA_ENABLE_GLFW)
list(APPEND VCPKG_MANIFEST_FEATURES "glfw")
endif()
cmake_dependent_option(
ALIA_ENABLE_SDL
"Enable the SDL backend for the UI library"
ON
"ALIA_ENABLE_UI"
OFF)
if(ALIA_ENABLE_SDL)
list(APPEND VCPKG_MANIFEST_FEATURES "sdl")
endif()
cmake_dependent_option(
ALIA_BUILD_DOCS
"Build the docs"
${ALIA_IS_MAIN_PROJECT}
"IS_EMSCRIPTEN"
OFF)
option(
ALIA_BUILD_EXAMPLES
"Build examples"
${ALIA_IS_MAIN_PROJECT})
cmake_dependent_option(
ALIA_ENABLE_HTML
"Enable integration with HTML5"
${ALIA_IS_MAIN_PROJECT}
"IS_EMSCRIPTEN"
OFF)
if(ALIA_ENABLE_HTML)
list(APPEND VCPKG_MANIFEST_FEATURES "html")
endif()
# We can only declare the project after we've set the vcpkg manifest features.
project(alia)
alia_detect_compiler()
# If alia is the main project, set some global development flags.
if (ALIA_IS_MAIN_PROJECT)
alia_set_development_warning_flags()
if (IS_MSVC)
# Use EditAndContinue-style debug info for MSVC.
# TODO: Use CMAKE_MSVC_DEBUG_INFORMATION_FORMAT once it's more widely
# supported:
# set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
# "$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>")
# string(REGEX REPLACE "/Zi" "/ZI"
# CMAKE_CXX_FLAGS_RELWITHDEBINFO
# "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE "/Zi" "/ZI"
CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG}")
# Enable profiling.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /PROFILE")
# Use full optimizations for profiling.
string(REGEX REPLACE "/Ob1" "/Ob2"
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# Use absolute paths for error messages.
add_compile_options(/FC)
endif()
endif()
# If we're testing, set the build options for instrumenting test coverage.
if(ALIA_ENABLE_TESTING)
enable_testing()
if(IS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling gcov support")
add_compile_options(-DLLVM_USE_LINKER=gold -fprofile-instr-generate
-fcoverage-mapping)
string(APPEND CMAKE_EXE_LINKER_FLAGS
" -fprofile-instr-generate -fcoverage-mapping")
endif()
endif()
# Add the core library.
include_directories(src)
if (ALIA_IS_MAIN_PROJECT)
set(ALIA_GLOB_OPTIONS "CONFIGURE_DEPENDS")
else()
set(ALIA_GLOB_OPTIONS "")
endif()
file(GLOB_RECURSE ALIA_CORE_SRC_FILES ${ALIA_GLOB_OPTIONS}
"src/alia/core/*.cpp")
add_library(alia_core STATIC ${ALIA_CORE_SRC_FILES})
target_include_directories(alia_core PUBLIC src)
target_compile_features(alia_core PUBLIC cxx_std_20)
# Add the UI library.
if (ALIA_ENABLE_UI)
find_package(unofficial-skia CONFIG REQUIRED)
include(FetchContent)
FetchContent_Declare(dmilos_color
GIT_REPOSITORY https://github.com/dmilos/color.git
GIT_TAG 84dc0512cb5fcf6536d79f0bee2530e678c01b03)
FetchContent_Populate(dmilos_color)
file(GLOB_RECURSE ALIA_UI_SOURCES ${ALIA_GLOB_OPTIONS}
"src/alia/ui/*.cpp")
foreach(file ${ALIA_UI_SOURCES})
if(${file} MATCHES "/ui/backends/")
list(REMOVE_ITEM ALIA_UI_SOURCES ${file})
endif()
endforeach()
add_library(alia_ui STATIC ${ALIA_UI_SOURCES})
target_include_directories(alia_ui PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(alia_ui PUBLIC
alia_core
unofficial::skia::skia
unofficial::skia::modules::skshaper)
# unofficial::skia::modules::svg)
if (IS_EMSCRIPTEN)
target_link_options(alia_ui PUBLIC
"-sFULL_ES3"
"-sTOTAL_MEMORY=64MB")
# TODO...
# target_compile_options(alia_ui PUBLIC "-fwasm-exceptions")
# target_link_options(alia_ui PUBLIC "-fwasm-exceptions")
# Restore pre-3.1.27 stack size for Emscripten.
target_link_options(alia_ui PUBLIC "-sSTACK_SIZE=5MB")
# target_compile_options(alia_core PUBLIC "-fwasm-exceptions")
# target_link_options(alia_core PUBLIC "-fwasm-exceptions")
target_link_options(alia_core PUBLIC "-sSTACK_SIZE=5MB")
# Set various other Emscripten options...
target_link_options(alia_ui PUBLIC
"-sENVIRONMENT=web")
target_link_options(alia_ui PUBLIC
"-sWASM=1")
target_link_options(alia_ui PUBLIC
"--bind")
target_link_options(alia_ui PUBLIC
"-sMIN_WEBGL_VERSION=2")
target_link_options(alia_ui PUBLIC
"-sMAX_WEBGL_VERSION=2")
target_link_options(alia_ui PUBLIC
"-Oz"
"-sELIMINATE_DUPLICATE_FUNCTIONS=1")
add_library(alia_emscripten_ui STATIC "src/alia/ui/backends/emscripten.cpp")
target_include_directories(alia_emscripten_ui PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(alia_emscripten_ui PUBLIC alia_ui)
target_link_options(alia_emscripten_ui PUBLIC "-sERROR_ON_UNDEFINED_SYMBOLS=0")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
target_include_directories(alia_ui PUBLIC
"${dmilos_color_SOURCE_DIR}/src")
target_precompile_headers(alia_ui PUBLIC
src/alia/ui.hpp)
endif()
# Add the GLFW3 backend.
if (ALIA_ENABLE_GLFW)
find_package(glfw3 3.3 CONFIG REQUIRED)
add_library(alia_glfw STATIC "src/alia/ui/backends/glfw.cpp")
target_include_directories(alia_glfw PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(alia_glfw PUBLIC alia_ui glfw)
endif()
# Add the SDL backend.
if (ALIA_ENABLE_SDL)
find_package(SDL2 CONFIG REQUIRED)
add_library(alia_sdl STATIC "src/alia/ui/backends/sdl.cpp")
target_include_directories(alia_sdl PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(alia_sdl PUBLIC alia_ui
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>)
endif()
# Add the tests.
if (ALIA_ENABLE_TESTING)
add_subdirectory("tests")
endif()
# Add the examples.
if (ALIA_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Add alia/HTML.
if (ALIA_ENABLE_HTML)
add_subdirectory("integrations/html")
endif()
# Add the docs.
if (ALIA_BUILD_DOCS)
add_subdirectory(docs)
endif()