-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
253 lines (221 loc) · 8.4 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
#================================
# Project setup.
#================================
cmake_minimum_required(VERSION 3.24)
project(atlas VERSION 3.0.0 LANGUAGES CXX C)
if (APPLE)
message(ERROR "Support for Apple has been deprecated")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(ATLAS_VERSION_MAJOR "3")
set(ATLAS_VERSION_MINOR "0")
set(ATLAS_VERSION_PATCH "0")
set(ATLAS_VERSION_EXTRA "")
set(ATLAS_VERSION "${ATLAS_VERSION_MAJOR}.${ATLAS_VERSION_MINOR}")
set(ATLAS_VERSION_FULL
"${ATLAS_VERSION}.${ATLAS_VERSION_PATCH}${ATLAS_VERSION_EXTRA}")
#================================
# Option variables.
#================================
option(ATLAS_BUILD_TESTS "Build Atlas test" ON)
option(ATLAS_BUILD_GL_TEST "Build Atlas OpenGL tests" ON)
option(ATLAS_BUILD_GUI_TEST "Build Atlas GUI tests" ON)
# Make sure Zeus does not make the clang-format target and disable the
# unit tests for it.
set(ZEUS_CLANG_FORMAT_TARGET OFF CACHE INTERNAL "")
set(ZEUS_BUILD_TESTS OFF CACHE INTERNAL "")
#================================
# Directory variables.
#================================
set(ATLAS_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(ATLAS_SOURCE_ROOT ${ATLAS_SOURCE_DIR}/src)
set(ATLAS_TEST_ROOT ${ATLAS_SOURCE_DIR}/test)
set(ATLAS_CMAKE_ROOT ${ATLAS_SOURCE_DIR}/cmake)
set(ATLAS_EXTERNAL_ROOT ${ATLAS_SOURCE_DIR}/external)
#================================
# Add subdirectories.
#================================
add_subdirectory(${ATLAS_EXTERNAL_ROOT}/imgui)
add_subdirectory(${ATLAS_EXTERNAL_ROOT}/stb)
add_subdirectory(${ATLAS_SOURCE_ROOT})
if (ATLAS_BUILD_TESTS)
add_subdirectory(${ATLAS_TEST_ROOT})
endif()
#================================
# Source groups.
#================================
source_group("include" FILES)
source_group("include\\atlas" FILES ${ATLAS_INCLUDE_ROOT_GROUP})
source_group("include\\atlas\\math" FILES ${ATLAS_INCLUDE_MATH_GROUP})
source_group("include\\atlas\\glx" FILES ${ATLAS_INCLUDE_GLX_GROUP})
source_group("include\\atlas\\gui" FILES ${ATLAS_INCLUDE_GUI_GROUP})
source_group("include\\atlas\\gui\\widgets" FILES
${ATLAS_INCLUDE_GUI_WIDGETS_GROUP})
source_group("include\\atlas\\hlr" FILES ${ATLAS_INCLUDE_HLR_GROUP})
source_group("include\\atlas\\utils" FILES ${ATLAS_INCLUDE_UTILS_GROUP})
source_group("source" FILES)
source_group("source\\atlas" FILES)
source_group("source\\atlas\\glx" FILES ${ATLAS_SOURCE_GLX_GROUP})
source_group("source\\atlas\\gui" FILES ${ATLAS_SOURCE_GUI_GROUP})
source_group("source\\atlas\\gui\\widgets" FILES
${ATLAS_SOURCE_GUI_WIDGETS_GROUP})
source_group("source\\atlas\\hlr" FILES ${ATLAS_SOURCE_HLR_GROUP})
source_group("source\\atlas\\utils" FILES ${ATLAS_SOURCE_UTILS_GROUP})
#================================
# Find Packages.
#================================
include(FetchContent)
# Declare fetch content for all packages.
# Zeus always set to latest version.
FetchContent_Declare(
zeus
GIT_REPOSITORY https://github.com/marovira/zeus
GIT_TAG 79280d3cfbe70e74029d6f14c874f358d17431f5
)
# Move to latest version that has the INSTALL target
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG cc98465e3508535ba8c7f6208df934c156a018dc
)
# Version 3.3.7
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 45ce5ddd197d5c58f50fdd3296a5131c894e5527
)
FetchContent_Declare(
gl3w
GIT_REPOSITORY https://github.com/marovira/gl3w.git
GIT_TAG 03afb4623bf5117a577b4b6dff7739ef677a56cd
)
# Latest version
FetchContent_Declare(
tinyobjloader
GIT_REPOSITORY https://github.com/syoyo/tinyobjloader.git
GIT_TAG 0ed6c38f20c63b996fbb9fa949569b2acb213a3d
)
find_package(zeus QUIET)
find_package(glm QUIET)
find_package(glfw3 QUIET)
find_package(gl3w QUIET)
find_package(tinyobjloader QUIET)
find_package(OpenGL REQUIRED QUIET)
if (NOT zeus_FOUND AND NOT zeus_POPULATED)
FetchContent_Populate(zeus)
add_subdirectory(${zeus_SOURCE_DIR} ${zeus_BINARY_DIR})
endif()
if (NOT glm_FOUND AND NOT glm_POPULATED)
FetchContent_Populate(glm)
add_subdirectory(${glm_SOURCE_DIR} ${glm_BINARY_DIR})
endif()
if (NOT glfw3_FOUND AND NOT glfw_POPULATED)
FetchContent_Populate(glfw)
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif()
if (NOT gl3w_FOUND AND NOT gl3w_POPULATED)
FetchContent_Populate(gl3w)
add_subdirectory(${gl3w_SOURCE_DIR} ${gl3w_BINARY_DIR})
endif()
set(TINYOBJLOADER_LIB "tinyobjloader::tinyobjloader")
if (NOT tinyobjloader_FOUND AND NOT tinyobjloader_POPULATED)
FetchContent_Populate(tinyobjloader)
add_subdirectory(${tinyobjloader_SOURCE_DIR} ${tinyobjloader_BINARY_DIR})
set(TINYOBJLOADER_LIB "tinyobjloader")
endif()
#================================
# Math module.
#================================
add_library(atlas_math INTERFACE)
target_include_directories(atlas_math INTERFACE ${ATLAS_SOURCE_ROOT})
target_link_libraries(atlas_math INTERFACE glm::glm zeus::zeus)
target_compile_features(atlas_math INTERFACE cxx_std_20)
if (MSVC)
add_custom_target(_atlas_math SOURCES ${ATLAS_INCLUDE_MATH_GROUP})
set_target_properties(_atlas_math PROPERTIES FOLDER "atlas")
endif()
add_library(atlas::math ALIAS atlas_math)
#================================
# GLX module.
#================================
add_library(atlas_glx ${ATLAS_INCLUDE_GLX_GROUP} ${ATLAS_SOURCE_GLX_GROUP})
target_include_directories(atlas_glx PUBLIC ${ATLAS_SOURCE_ROOT})
target_link_libraries(atlas_glx PUBLIC OpenGL::GL glfw gl3w::gl3w zeus::zeus)
add_library(atlas::glx ALIAS atlas_glx)
set_target_properties(atlas_glx PROPERTIES FOLDER "atlas")
#================================
# GUI module.
#================================
add_library(atlas_gui
${ATLAS_INCLUDE_GUI_GROUP}
${ATLAS_INCLUDE_GUI_WIDGETS_GROUP}
${ATLAS_SOURCE_GUI_GROUP}
${ATLAS_SOURCE_GUI_WIDGETS_GROUP}
)
target_include_directories(atlas_gui PUBLIC ${ATLAS_SOURCE_ROOT})
target_link_libraries(atlas_gui PUBLIC imgui atlas_glx zeus::zeus)
add_library(atlas::gui ALIAS atlas_gui)
set_target_properties(atlas_gui PROPERTIES FOLDER "atlas")
#================================
# Utils module.
#================================
add_library(atlas_utils ${ATLAS_INCLUDE_UTILS_GROUP}
${ATLAS_SOURCE_UTILS_GROUP})
target_include_directories(atlas_utils PUBLIC ${ATLAS_SOURCE_ROOT})
target_link_libraries(atlas_utils PUBLIC atlas_math ${TINYOBJLOADER_LIB}
zeus::zeus stb)
add_library(atlas::utils ALIAS atlas_utils)
set_target_properties(atlas_utils PROPERTIES FOLDER "atlas")
#================================
# Main Atlas library.
#================================
add_library(atlas ${ATLAS_SOURCE_ROOT_GROUP})
target_include_directories(atlas PUBLIC ${ATLAS_SOURCE_ROOT})
target_link_libraries(atlas PUBLIC zeus::zeus atlas_math atlas_glx atlas_gui
atlas_utils)
add_library(atlas::atlas ALIAS atlas)
set_target_properties(atlas PROPERTIES FOLDER "atlas")
#================================
# Build the tests.
#================================
if (ATLAS_BUILD_TESTS)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 97c48e0c343d26d50764fafdc90b1e630fbd10ce
)
find_package(Catch2 3 QUIET)
if (NOT Catch2_FOUND AND NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${catch2_SOURCE_DIR}/extras")
endif()
source_group("include" FILES ${ATLAS_TEST_HEADER_GROUP})
source_group("source" FILES ${ATLAS_TEST_TOP_GROUP})
source_group("source\\glx" FILES ${ATLAS_TEST_GLX_GROUP})
source_group("source\\gui" FILES ${ATLAS_TEST_GUI_GROUP})
source_group("source\\hlr" FILES ${ATLAS_TEST_HLR_GROUP})
source_group("source\\math" FILES ${ATLAS_TEST_MATH_GROUP})
add_executable(atlas_test ${ATLAS_TEST_LIST})
target_include_directories(atlas_test PRIVATE ${ATLAS_TEST_ROOT})
target_link_libraries(atlas_test
atlas_math
atlas_glx
atlas_gui
atlas_utils
Catch2::Catch2WithMain)
if (ATLAS_BUILD_GL_TEST)
if (MSVC)
target_compile_definitions(atlas_test PUBLIC -DATLAS_BUILD_GL_TESTS)
endif()
endif()
if (ATLAS_BUILD_GUI_TEST)
if (MSVC)
target_compile_definitions(atlas_test PUBLIC -DATLAS_BUILD_GUI_TESTS)
endif()
endif()
set_target_properties(atlas_test PROPERTIES FOLDER "atlas")
include(CTest)
include(Catch)
catch_discover_tests(atlas_test)
endif()