-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
179 lines (174 loc) · 4.52 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
cmake_minimum_required(VERSION 3.21)
project(hellotext VERSION 0.0.1)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Group CMake targets inside a folder
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json for language servers
include(FetchContent)
if (NOT EMSCRIPTEN)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)
option(GLFW_BUILD_DOCS OFF)
option(GLFW_INSTALL OFF)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.3.8
)
list(APPEND FETCH_CONTENTS glfw)
FetchContent_Declare(
glad
GIT_REPOSITORY https://github.com/mononerv/glad.git
GIT_TAG 3e150fcc529c089476ebbb7b4a2fe924828be916
)
list(APPEND FETCH_CONTENTS glad)
endif()
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.1.0
)
list(APPEND FETCH_CONTENTS fmt)
FetchContent_Declare(
freetype
GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG VER-2-13-0
)
list(APPEND FETCH_CONTENTS freetype)
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 0.9.9.8
)
list(APPEND FETCH_CONTENTS glm)
FetchContent_Declare(
utf8cpp
GIT_REPOSITORY https://github.com/nemtrif/utfcpp.git
GIT_TAG v3.2.4
)
list(APPEND FETCH_CONTENTS utf8cpp)
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/mononerv/stb.git
GIT_TAG 698c6fb9889c71494b49c9187d249af5fc87b211
)
list(APPEND FETCH_CONTENTS stb)
FetchContent_MakeAvailable(${FETCH_CONTENTS})
# Group dependencies in Visual Studio and Xcode
if (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode")
set_target_properties(fmt PROPERTIES FOLDER deps)
set_target_properties(freetype PROPERTIES FOLDER deps)
set_target_properties(glad PROPERTIES FOLDER deps)
set_target_properties(stb PROPERTIES FOLDER deps)
set_target_properties(update_mappings PROPERTIES FOLDER "deps/GLFW3")
set_target_properties(glfw PROPERTIES FOLDER "deps/GLFW3")
endif()
if (APPLE)
set(PLATFORM_LINK_LIBRARIES
"-framework Cocoa"
"-framework IOKit"
"-framework CoreVideo"
"-framework OpenGL"
)
elseif (UNIX AND NOT APPLE AND NOT EMSCRIPTEN) # Linux, BSD, Solaris, Minix
set(PLATFORM_LINK_LIBRARIES
"dl"
"m"
"GL"
"X11"
)
elseif (WIN32)
set(PLATFORM_LINK_LIBRARIES "OpenGL32.lib")
elseif(EMSCRIPTEN)
# Emscripten build
add_compile_definitions(
"GL_GLEXT_PROTOTYPES"
"GL3_PROTOTYPES"
)
add_compile_options("-pthread" "-fexceptions")
add_link_options(
"-sLEGACY_GL_EMULATION=0"
"-sUSE_WEBGL2=1"
"-sFULL_ES3=1"
"-fexceptions"
)
else()
message(FATAL_ERROR "Unkown platform!")
endif()
# Compiler specific options
if (NOT MSVC)
set(BASE_OPTIONS
"-Wall"
"-Wextra"
"-Wconversion"
"-Wpedantic"
"-Wshadow"
"-Werror"
# fmt warnings
"-Wno-unknown-attributes"
# glad warnings
"-Wno-language-extension-token"
# glm warnings
"-Wno-nested-anon-types"
"-Wno-gnu-anonymous-struct"
)
if (EMSCRIPTEN)
list(APPEND BASE_OPTIONS
# fmt warnings
"-Wno-deprecated-literal-operator"
)
endif()
else()
set(BASE_OPTIONS
"/W4"
"/WX"
"/utf-8"
"/Zc:__cplusplus"
"/wd4201"
#"/fsanitize=address" # Doesn't work without Visual Studio
)
endif()
if (NOT EMSCRIPTEN)
set(BASE_LIBRARIES
glfw
glad::glad
)
endif()
set(HEADERS
txt/buffer.hpp
txt/event.hpp
txt/fonts.hpp
txt/image.hpp
txt/input.hpp
txt/renderer.hpp
txt/shader.hpp
txt/text_engine.hpp
txt/texture.hpp
txt/utility.hpp
txt/window.hpp
)
set(SOURCES
txt/buffer.cpp
txt/fonts.cpp
txt/image.cpp
txt/input.cpp
txt/renderer.cpp
txt/shader.cpp
txt/text_engine.cpp
txt/texture.cpp
txt/window.cpp
hellotext.cpp
)
add_executable(hellotext ${HEADERS} ${SOURCES})
target_include_directories(hellotext PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_features(hellotext PRIVATE cxx_std_20)
target_compile_options(hellotext PRIVATE ${BASE_OPTIONS})
target_link_libraries(hellotext
PRIVATE
${PLATFORM_LINK_LIBRARIES}
${BASE_LIBRARIES}
freetype
fmt
glm
utf8::cpp
stb::stb
)
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES})