-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
306 lines (251 loc) Β· 9.84 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# Copyright (c) 2018, University of Oxford.
# All rights reserved.
#
# University of Oxford means the Chancellor, Masters and Scholars of the
# University of Oxford, having an administrative office at Wellington
# Square, Oxford OX1 2JD, UK.
#
# This file is part of the Oxford RSE C++ Template project.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required (VERSION 3.6)
project (trase)
set (CMAKE_DEBUG_POSTFIX d)
# ensure C++14
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
#export compiler flags for code completion engines
set (CMAKE_EXPORT_COMPILE_COMMANDS 1)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
if(CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$")
message(" * C++ compiler: Emscripten")
set(trase_Emscripten ON)
else()
message(" * C++ cimpiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
# Set global compiler warnings
if (MSVC)
set(common_options /W3 /WX)
set(debug_options ${common_options} /D_ITERATOR_DEBUG_LEVEL=0 /D_SCL_SECURE_NO_WARNINGS)
set(not_debug_options ${common_options} /D_ITERATOR_DEBUG_LEVEL=0 /D_SCL_SECURE_NO_WARNINGS)
add_compile_options(
"$<$<CONFIG:Debug>:${debug_options}>$<$<NOT:$<CONFIG:Debug>>:${not_debug_options}>"
)
else ()
add_compile_options (-Wall -pedantic)
endif ()
option (trase_BUILD_OPENGL "Build OpenGL backend and interactive test" ON)
if (NOT trase_Emscripten)
find_package (glfw3 3.2 QUIET)
if (NOT glfw3_FOUND AND trase_BUILD_OPENGL)
set(trase_BUILD_OPENGL OFF CACHE BOOL INTERNAL FORCE)
message("The glfw not found, the option trase_BUILD_OPENGL turned off")
endif ()
endif ()
if (trase_BUILD_OPENGL)
set (nanovg_dir third-party/nanovg)
set (nanovg_source
${nanovg_dir}/fontstash.h
${nanovg_dir}/nanovg.c
${nanovg_dir}/nanovg_gl.h
${nanovg_dir}/nanovg_gl_utils.h
${nanovg_dir}/nanovg.h
${nanovg_dir}/stb_image.h
${nanovg_dir}/stb_truetype.h
)
set (trase_gl_ext_headers
${nanovg_dir}/nanovg.h
)
if (NOT trase_Emscripten)
find_package (OpenGL REQUIRED)
else()
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(OPENGL_gl_LIBRARY "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0 -s USE_WEBGL2=1 -s FULL_ES2=1 -s USE_GLFW=3 -s WASM=1 --preload-file ${trase_SOURCE_DIR}/font")
endif()
add_library (nanovg ${nanovg_source})
target_include_directories (nanovg SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${nanovg_dir}>
$<INSTALL_INTERFACE:include>)
target_link_libraries (nanovg PUBLIC ${OPENGL_gl_LIBRARY} glfw dl)
endif (trase_BUILD_OPENGL)
find_package(CURL)
if (WIN32)
set (dirent_dir third-party/dirent)
set (dirent_headers ${dirent_dir}/dirent.h)
add_library (dirent INTERFACE)
#target_sources(dirent INTERFACE dirent/dirent.h)
target_include_directories (dirent INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${dirent_dir}>
$<INSTALL_INTERFACE:include>)
endif ()
set (trase_headers
src/trase.hpp
src/backend/Backend.hpp
src/backend/BackendSVG.hpp
src/frontend/Axis.hpp
src/frontend/Data.hpp
src/frontend/Drawable.hpp
src/frontend/Figure.hpp
src/frontend/Geometry.hpp
src/frontend/Transform.hpp
src/frontend/Line.hpp
src/frontend/Points.hpp
src/frontend/Rectangle.hpp
src/frontend/Histogram.hpp
src/frontend/Legend.hpp
src/util/ColumnIterator.hpp
src/util/BBox.hpp
src/util/Colors.hpp
src/util/Exception.hpp
src/util/Style.hpp
src/util/Vector.hpp
)
set (trase_source
src/backend/Backend.cpp
src/backend/BackendSVG.cpp
src/frontend/Axis.cpp
src/frontend/Data.cpp
src/frontend/Drawable.cpp
src/frontend/Figure.cpp
src/frontend/Geometry.cpp
src/frontend/Legend.cpp
src/frontend/Transform.cpp
src/util/Colors.cpp
src/util/Style.cpp
)
if (trase_BUILD_OPENGL)
list(APPEND trase_headers src/backend/BackendGL.hpp)
list(APPEND trase_source src/backend/BackendGL.cpp)
endif()
if (CURL_FOUND)
list(APPEND trase_headers src/util/CSVDownloader.hpp)
list(APPEND trase_source src/util/CSVDownloader.cpp)
endif (CURL_FOUND)
add_library (trase
${trase_source}
${trase_headers}
)
target_include_directories (trase PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)
if (WIN32)
target_link_libraries (trase PUBLIC dirent)
endif ()
target_compile_definitions (trase PRIVATE TRASE_SOURCE_DIR="${trase_SOURCE_DIR}" TRASE_INSTALL_DIR="${CMAKE_INSTALL_PREFIX}")
if (trase_BUILD_OPENGL)
target_compile_definitions (trase PUBLIC TRASE_BACKEND_GL)
target_link_libraries (trase PUBLIC nanovg)
endif ()
if (CURL_FOUND)
target_compile_definitions (trase PUBLIC TRASE_HAVE_CURL)
target_link_libraries (trase PUBLIC ${CURL_LIBRARIES})
message("The CURL path: " ${CURL_INCLUDE_DIRS})
target_include_directories(trase PUBLIC ${CURL_INCLUDE_DIRS})
endif (CURL_FOUND)
set (trase_fonts
font/entypo.ttf
font/NotoEmoji-Regular.ttf
font/Roboto-Bold.ttf
font/Roboto-Light.ttf
font/Roboto-Regular.ttf
)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
option (trase_BUILD_TESTS "Compiling trase with tests" ON)
option (trase_BUILD_EXAMPLES "Compiling trase with examples" ON)
option (trase_INSTALL "Install trase after compiling the library" ON)
option (trase_USE_CLANG_TIDY "Use clang tidy for static analysis" OFF)
option (trase_MEMCHECK "Use LLVM AddressSanitizer to detecting memory errors" OFF)
option (trase_ENABLE_COVERAGE "Enable coverage reporting for GCC or Clang" OFF)
endif ()
if (trase_BUILD_TESTS)
enable_testing ()
add_subdirectory(tests)
endif (trase_BUILD_TESTS)
if (trase_BUILD_EXAMPLES)
add_subdirectory(examples)
endif (trase_BUILD_EXAMPLES)
# Clang tidy as optional static analyzer
if (trase_USE_CLANG_TIDY)
find_program (CLANG_TIDY_EXE NAMES "clang-tidy" "clang-tidy-6.0" "clang-tidy-5.0" "clang-tidy-4.0"
DOC "Path to clang-tidy executable")
if (NOT CLANG_TIDY_EXE)
message (STATUS "clang-tidy not found.")
else ()
message (STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set_target_properties (trase PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif ()
endif ()
# LLVM AddressSanitizer to detecting memory errors
# Note that there are many other sanitizers in LLVM to help detect errors, see
# http://travistoptips.blogspot.co.uk/2015/11/sanitize-all-things.html
if (trase_MEMCHECK)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message (STATUS "Configuring with LLVM AddressSanitizer")
set (trase_MEMCHECK_FLAGS -fno-optimize-sibling-calls
-fsanitize=address
-fsanitize-address-use-after-scope
)
target_compile_options (trase PUBLIC -O1 -g -fno-omit-frame-pointer ${trase_MEMCHECK_FLAGS})
target_link_libraries (trase PUBLIC -g ${trase_MEMCHECK_FLAGS})
else ()
message (FATAL_ERROR "clang compiler required with trase_MEMCHECK: found ${CMAKE_CXX_COMPILER_ID}")
endif ()
endif ()
# Setup coverage testing for GCC or Clang
if (trase_ENABLE_COVERAGE)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
message (STATUS "Configuring with coverage")
target_compile_options (trase PUBLIC --coverage -O0)
target_link_libraries (trase PUBLIC --coverage)
else ()
message (FATAL_ERROR "GCC or Clang required with trase_ENABLE_COVERAGE: found ${CMAKE_CXX_COMPILER_ID}")
endif ()
endif ()
# install stuff
if (trase_INSTALL)
set (install-targets trase)
if (WIN32)
list (APPEND install-targets dirent)
endif ()
if (trase_BUILD_OPENGL)
list (APPEND install-targets nanovg)
endif ()
set (install-headers ${trase_headers} ${trase_svg_headers})
if (trase_BUILD_OPENGL)
list (APPEND install-headers ${trase_gl_headers} ${trase_gl_ext_headers})
endif ()
install (TARGETS ${install-targets}
EXPORT trase-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install (EXPORT trase-targets
FILE trase-config.cmake
DESTINATION lib/cmake/trase
)
install (FILES ${install-headers} DESTINATION include)
install (FILES ${trase_fonts} DESTINATION font)
endif (trase_INSTALL)