-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
220 lines (190 loc) · 6.72 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
# -----------------------------------------------------------------------------
# CMake configuration file
#
# -----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.2.0)
project(sparkle VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
# -----------------------------------------------------------------------------
# CMake options.
# -----------------------------------------------------------------------------
# GLEW is optional and not provided, by default extensions are loaded manually.
option(USE_GLEW OFF)
# -----------------------------------------------------------------------------
# CMake includes.
# -----------------------------------------------------------------------------
# CMake module path.
set(MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${MODULE_PATH})
# Custom CMake helpers.
include(Helpers)
# -----------------------------------------------------------------------------
# Build parameters.
# -----------------------------------------------------------------------------
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(DEBUG TRUE)
else()
set(DEBUG FALSE)
endif()
# -----------------------------------------------------------------------------
# Paths.
# -----------------------------------------------------------------------------
# Project's paths.
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
set(SHADERS_DIR ${SOURCE_DIR}/shaders)
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin)
set(THIRDPARTY ${CMAKE_SOURCE_DIR}/thirdparty)
set(THIRDPARTY_INCLUDE ${THIRDPARTY}/include)
set(TOOLS ${CMAKE_SOURCE_DIR}/tools)
# -----------------------------------------------------------------------------
# Compiler settings.
# -----------------------------------------------------------------------------
# Used to bypass MSVC settings.
set_global_output_directory(${OUTPUT_DIR})
# Check the compiler version.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
find_gcc(5.3.1)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (MSVC_VERSION LESS 1900)
message(FATAL_ERROR
"Your version of MSVC is too low, please upgrade to version 14.x+"
)
endif()
endif()
# Compiler and linker flags.
if( (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
list(APPEND CXX_FLAGS
-Wall -Wextra -Wpedantic -Wformat
-Wnon-virtual-dtor -Woverloaded-virtual
-Wuseless-cast -Wcast-align
#-Wold-style-cast
#-Wshadow
-Wlogical-op
-Wno-unused-function -Wno-unused-parameter -Wno-missing-field-initializers
-fvisibility=hidden -fno-strict-aliasing -fno-builtin-memcmp
)
list(APPEND CXX_FLAGS_RELEASE -O2)
list(APPEND CXX_FLAGS_DEBUG -g -O0)# -Wconversion)
#list(APPEND LINK_FLAGS -Wl,--no-undefined)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND CXX_FLAGS
/W4
/MP /EHsc-
)
list(APPEND CXX_FLAGS_DEBUG /Zi)
list(APPEND CXX_FLAGS_RELEASE /W0 /Ox /INCREMENTAL:NO /DEBUG:NONE /DNDEBUG)
list(APPEND Definitions
NOMINMAX
WIN32
_WINDOWS
_CRT_SECURE_NO_WARNINGS
_USE_MATH_DEFINES
)
else()
message(WARNING "The compiler ${CMAKE_CXX_COMPILER_ID} has not been tested yet.")
endif()
# -----------------------------------------------------------------------------
# Thirdparties dependencies.
# -----------------------------------------------------------------------------
find_package(OpenGL REQUIRED)
# Extensions loader.
if(USE_GLEW)
find_package(GLEW 1.13 REQUIRED)
if(${GLEW_FOUND})
list(APPEND Definitions -DUSE_GLEW)
endif()
else()
# Automatically generate header to load OpenGL extensions.
find_package(PythonInterp)
if(PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE)
set(GLEXTGEN_PATH "${TOOLS}/glextgen")
set(GLEXTGEN_OUTPUT_DIR "${SOURCE_DIR}/ext")
list(APPEND GLEXTGEN_OUTPUTS
${GLEXTGEN_OUTPUT_DIR}/_extensions.h
${GLEXTGEN_OUTPUT_DIR}/_extensions.inl
)
add_custom_command(
OUTPUT
${GLEXTGEN_OUTPUTS}
COMMAND
${PYTHON_EXECUTABLE} "${GLEXTGEN_PATH}/main.py"
"${GLEXTGEN_PATH}/extensions"
"${GLEXTGEN_OUTPUT_DIR}"
DEPENDS
"${GLEXTGEN_PATH}/main.py"
"${GLEXTGEN_PATH}/extensions"
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Generate OpenGL extensions headers !!" VERBATIM
)
add_custom_target(OpenGLExtensionGenerator
ALL
DEPENDS
${GLEXTGEN_OUTPUTS}
SOURCES
"${GLEXTGEN_PATH}/main.py"
"${GLEXTGEN_PATH}/extensions"
)
else()
message(FATAL_ERROR "You need either the Python interpreter "
"or the GLEW library to handle OpenGL extensions.")
endif()
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES "${GLEXTGEN_OUTPUT_DIR}")
endif(USE_GLEW)
# -----------------------------------------------------------------------------
# Thirdparties Submodule dependencies.
# -----------------------------------------------------------------------------
# GLFW, as window manager.
set(GLFW_ROOT ${THIRDPARTY}/glfw)
set(GLFW_LIBRARY glfw)
set(GLFW_INCLUDE_DIR ${GLFW_ROOT}/include)
if(NOT EXISTS ${GLFW_INCLUDE_DIR})
message(FATAL_ERROR "You need to initialize git submodules via the command : \n"
"git submodule init\n"
"git submodule update"
)
endif()
set(BUILD_SHARED_LIBS TRUE CACHE BOOL "Build GLFW as shared library.")
set(GLFW_BUILD_EXAMPLES FALSE CACHE BOOL "Do not build GLFW examples.")
set(GLFW_BUILD_TESTS FALSE CACHE BOOL "Do not run GLFW tests.")
set(GLFW_BUILD_DOCS FALSE CACHE BOOL "Do not build GLFW documentation.")
add_subdirectory(${GLFW_ROOT} glfw EXCLUDE_FROM_ALL)
# GLM, as math library.
set(GLM_INCLUDE_DIR ${THIRDPARTY}/glm)
# imgui, as user interface.
set(IMGUI_INCLUDE_DIR ${THIRDPARTY}/imgui)
list(APPEND IMGUI_SOURCES
${IMGUI_INCLUDE_DIR}/imgui.cpp
${IMGUI_INCLUDE_DIR}/imgui_draw.cpp
)
# -----------------------------------------------------------------------------
# Compilation settings.
# -----------------------------------------------------------------------------
# Definitions
list(APPEND Definitions
-DSHADERS_DIR="${SHADERS_DIR}"
)
# Include directories
list(APPEND IncludeDirs
${SOURCE_DIR}
${SHADERS_DIR}
${THIRDPARTY_INCLUDE}
${GLFW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${GLM_INCLUDE_DIR}
${IMGUI_INCLUDE_DIR}
)
# Libraries
list(APPEND Libs
${GLFW_LIBRARY}
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
)
# -----------------------------------------------------------------------------
# Files
# -----------------------------------------------------------------------------
add_subdirectory(${SOURCE_DIR})
# -----------------------------------------------------------------------------