-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (229 loc) · 8.5 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
cmake_minimum_required(VERSION 3.5)
project(rterm)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Modules
list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/third_party/sdl2-cmake-scripts
${PROJECT_SOURCE_DIR}/third_party/cmake-conan
${PROJECT_SOURCE_DIR}/cmake
)
# Configuration
option(RTERM_DISABLE_SDL "Diable SDL renderer" OFF)
option(RTERM_DISABLE_OGL "Disable OpenGL renderer" OFF)
option(RTERM_BUILD_TESTS "Build tests" OFF)
option(RTERM_SANITIZERS "librterm built with ASan; skip all dlclose calls" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
set(RTERM_EXTERNAL_LIBS
"system"
CACHE STRING
"Where to get external libraries: from the system, conan, build automatically or setup cmake targets manually")
set_property(CACHE RTERM_EXTERNAL_LIBS PROPERTY STRINGS system conan local manual)
set(RTERM_HAS_SDL ON)
set(RTERM_HAS_OGL OFF)
# Output binary directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Sanitizers build type
include(Sanitizers)
file(
GLOB SOURCES
src/rasterizer/glyph_cache.cpp
src/rasterizer/tilefont.cpp
src/rasterizer/ttfont.cpp
src/renderer/software_texture.cpp
src/term/term.cpp
src/term/virtualconsole.cpp
src/util/char.cpp
src/util/color.cpp
src/util/error.cpp
src/util/framerate_counter.cpp
src/util/logger.cpp
src/util/sdl/sdl_loader.cpp
src/window/event.cpp
src/window/event_system.cpp
src/window/key.cpp
src/window/window.cpp
)
file(
GLOB HEADERS
include/rterm/rterm.h
include/rterm/rasterizer/font.h
include/rterm/rasterizer/glyph_cache.h
include/rterm/rasterizer/tilefont.h
include/rterm/rasterizer/ttfont.h
include/rterm/renderer/gl_hardware_texture.tpp
include/rterm/renderer/gl_renderer.tpp
include/rterm/renderer/hardware_texture.h
include/rterm/renderer/renderer.h
include/rterm/renderer/screen_view.h
include/rterm/renderer/sdl_hardware_texture.tpp
include/rterm/renderer/sdl_renderer.tpp
include/rterm/renderer/software_texture.h
include/rterm/renderer/texture_view.h
include/rterm/term/term.h
include/rterm/term/term.tpp
include/rterm/term/term_format.h
include/rterm/term/virtualconsole.h
include/rterm/util/api.h
include/rterm/util/char.h
include/rterm/util/color.h
include/rterm/util/error.h
include/rterm/util/framerate_counter.h
include/rterm/util/logger.h
include/rterm/util/rect.h
include/rterm/util/sdl/sdl_loader.h
include/rterm/util/sdl/sdl_ptr.h
include/rterm/util/span.h
include/rterm/util/util.h
include/rterm/window/event.h
include/rterm/window/event_system.h
include/rterm/window/key.h
include/rterm/window/keycode.h
include/rterm/window/mouse.h
include/rterm/window/window.h
)
# Main library
add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
add_library(rterm::rterm ALIAS ${PROJECT_NAME})
# Warnings
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
set_target_properties(
${PROJECT_NAME}
PROPERTIES
COMPILE_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow"
)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
set_target_properties(
${PROJECT_NAME}
PROPERTIES
COMPILE_FLAGS
"${CMAKE_CXX_FLAGS} /W4"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
## Dependencies ##
set(RTERM_PRIVATE_LIBS)
set(RTERM_PRIVATE_HEADERS)
set(RTERM_PUBLIC_LIBS)
set(RTERM_PUBLIC_HEADERS)
list(APPEND RTERM_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/)
find_package(Threads REQUIRED)
list(APPEND RTERM_PUBLIC_LIBS Threads::Threads)
if (MINGW)
list(APPEND RTERM_PUBLIC_LIBS -lmingw32)
endif()
if (RTERM_EXTERNAL_LIBS STREQUAL system)
# Poor windows users
# Conan is better btw
if(DEFINED RTERM_SDL2_PATH)
set(SDL2_PATH ${RTERM_SDL2_PATH})
set(SDL2_TTF_PATH ${RTERM_SDL2_PATH})
endif()
find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)
list(APPEND RTERM_PUBLIC_LIBS ${SDL2_LIBRARY} ${SDL2_TTF_LIBRARIES})
list(APPEND RTERM_PUBLIC_HEADERS ${SDL2_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIRS})
elseif (RTERM_EXTERNAL_LIBS STREQUAL conan)
set(CACHED_BUILD_TYPE ${CMAKE_BUILD_TYPE})
if (CMAKE_BUILD_TYPE STREQUAL Sanitizers)
# Temporary enable Debug build type
set(CMAKE_BUILD_TYPE Debug)
endif()
include(conan)
conan_check(REQUIRED)
conan_add_remote(NAME bincrafters INDEX 1 URL https://api.bintray.com/conan/bincrafters/public-conan)
conan_cmake_run(CONANFILE conanfile.py BASIC_SETUP CMAKE_TARGETS BUILD missing)
set(CMAKE_BUILD_TYPE ${CACHED_BUILD_TYPE})
list(APPEND RTERM_PUBLIC_LIBS CONAN_PKG::sdl2 CONAN_PKG::sdl2_ttf)
elseif (RTERM_EXTERNAL_LIBS STREQUAL local)
# We need to find git to patch SDL2 & SDL2_ttf
find_package(Git REQUIRED)
include(FetchContent)
FetchContent_Declare(
sdl2
URL https://github.com/SDL-mirror/SDL/archive/release-2.0.9.tar.gz
PATCH_COMMAND ${GIT_EXECUTABLE} init && ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_LIST_DIR}/third_party/patch/sdl2.patch
)
FetchContent_GetProperties(sdl2)
if(NOT sdl2_POPULATED)
FetchContent_Populate(sdl2)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(
Freetype
URL https://download.savannah.gnu.org/releases/freetype/freetype-2.10.0.tar.gz
)
FetchContent_GetProperties(Freetype)
if(NOT Freetype_POPULATED)
set(CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz TRUE)
set(CMAKE_DISABLE_FIND_PACKAGE_BZip2 TRUE)
set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB TRUE)
set(CMAKE_DISABLE_FIND_PACKAGE_PNG TRUE)
FetchContent_Populate(Freetype)
add_subdirectory(${freetype_SOURCE_DIR} ${freetype_BINARY_DIR} EXCLUDE_FROM_ALL)
add_library(Freetype::Freetype ALIAS freetype)
endif()
FetchContent_Declare(
sdl2-ttf
URL https://github.com/SDL-mirror/SDL_ttf/archive/release-2.0.15.tar.gz
PATCH_COMMAND ${GIT_EXECUTABLE} init && ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_LIST_DIR}/third_party/patch/sdl2-ttf.patch
)
FetchContent_GetProperties(sdl2-ttf)
if(NOT sdl2-ttf_POPULATED)
FetchContent_Populate(sdl2-ttf)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
add_subdirectory(${sdl2-ttf_SOURCE_DIR} ${sdl2-ttf_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
add_library(SDL2::SDL2 ALIAS SDL2-static)
list(APPEND RTERM_PUBLIC_LIBS freetype SDL2main SDL2-static SDL2_ttf)
list(APPEND RTERM_PUBLIC_HEADERS ${sdl2-ttf_SOURCE_DIR})
elseif(RTERM_EXTERNAL_LIBS STREQUAL manual)
list(APPEND RTERM_PUBLIC_LIBS ${RTERM_MANUAL_LIBS})
list(APPEND RTERM_PUBLIC_HEADERS ${RTERM_MANUAL_HEADERS})
else()
message(FATAL_ERROR
"Invalid RTERM_EXTERNAL_LIBS value: ${RTERM_EXTERNAL_LIBS}, should be one 'system', 'conan', 'local' or 'manual'")
endif()
# STB_Image
add_subdirectory(third_party/stb)
list(APPEND RTERM_PRIVATE_LIBS stb_image)
# utfcpp
set(UTF8_TESTS OFF CACHE BOOL "" FORCE)
set(UTF8_SAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(third_party/utfcpp EXCLUDE_FROM_ALL)
list(APPEND RTERM_PRIVATE_LIBS utf8::cpp)
# OpenGL
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if (OPENGL_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad)
set(RTERM_HAS_OGL ON)
list(APPEND RTERM_PRIVATE_LIBS glad)
list(APPEND RTERM_PUBLIC_LIBS OpenGL::GL)
list(APPEND RTERM_PRIVATE_HEADERS OPENGL_INCLUDE_DIRS)
endif(OPENGL_FOUND)
target_include_directories(${PROJECT_NAME}
PRIVATE ${RTERM_PRIVATE_HEADERS}
PUBLIC ${RTERM_PUBLIC_HEADERS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${RTERM_PRIVATE_LIBS}
PUBLIC ${RTERM_PUBLIC_LIBS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADERS}")
# RTERM_ENABLE_XXX = !RTERM_DISABLE_XXX && RTERM_HAS_XXX
target_compile_definitions(
${PROJECT_NAME} PUBLIC
RTERM_ENABLE_SDL=$<AND:$<NOT:$<BOOL:${RTERM_DISABLE_SDL}>>,$<BOOL:${RTERM_HAS_SDL}$>>
RTERM_ENABLE_OGL=$<AND:$<NOT:$<BOOL:${RTERM_DISABLE_OGL}>>,$<BOOL:${RTERM_HAS_OGL}$>>
RTERM_SANITIZERS=$<BOOL:${RTERM_SANITIZERS}>
)
if (RTERM_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif(RTERM_BUILD_TESTS)