forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
266 lines (238 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
find_package(Filesystem REQUIRED COMPONENTS Experimental Final)
#######################################################
### Library ###
#######################################################
add_library(matplot
matplot.h
backend/backend_interface.h
backend/backend_interface.cpp
backend/gnuplot.h
backend/gnuplot.cpp
backend/backend_registry.h
backend/backend_registry.cpp
core/axes_type.cpp
core/axes_type.h
core/axes_object.cpp
core/axes_object.h
core/axis_type.cpp
core/axis_type.h
core/figure_type.cpp
core/figure_type.h
core/figure_registry.cpp
core/figure_registry.h
core/legend.cpp
core/legend.h
core/line_spec.cpp
core/line_spec.h
util/colors.cpp
util/colors.h
util/common.cpp
util/common.h
util/concepts.h
util/contourc.cpp
util/contourc.h
util/geodata.h
util/handle_types.h
util/keywords.h
util/popen.h
util/type_traits.h
util/world_cities.cpp
util/world_map_10m.cpp
util/world_map_50m.cpp
util/world_map_110m.cpp
axes_objects/bars.cpp
axes_objects/bars.h
axes_objects/box_chart.cpp
axes_objects/box_chart.h
axes_objects/circles.cpp
axes_objects/circles.h
axes_objects/contours.cpp
axes_objects/contours.h
axes_objects/error_bar.cpp
axes_objects/error_bar.h
axes_objects/filled_area.cpp
axes_objects/filled_area.h
axes_objects/function_line.cpp
axes_objects/function_line.h
axes_objects/histogram.cpp
axes_objects/histogram.h
axes_objects/labels.cpp
axes_objects/labels.h
axes_objects/line.cpp
axes_objects/line.h
axes_objects/matrix.cpp
axes_objects/matrix.h
axes_objects/network.cpp
axes_objects/network.h
axes_objects/parallel_lines.cpp
axes_objects/parallel_lines.h
axes_objects/stair.cpp
axes_objects/stair.h
axes_objects/string_function.cpp
axes_objects/string_function.h
axes_objects/surface.cpp
axes_objects/surface.h
axes_objects/vectors.cpp
axes_objects/vectors.h
freestanding/axes_functions.cpp
freestanding/axes_functions.h
freestanding/axes_lim.h
freestanding/histcounts.h
freestanding/histcounts.cpp
freestanding/plot.h
)
# Target alias
add_library(Matplot++::matplot ALIAS matplot)
# Include dirs
target_include_directories(matplot
PUBLIC $<BUILD_INTERFACE:${MATPLOT_ROOT_DIR}/source>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# Dependencies
target_link_libraries_system(matplot
PRIVATE cimg nodesoup std::filesystem)
# Required compiler features required
# https://cmake.org/cmake/help/v3.14/manual/cmake-compile-features.7.html#requiring-language-standards
target_compile_features(matplot PUBLIC cxx_std_17)
#######################################################
### Compiler options ###
#######################################################
message("Setting matplotplusplus compiler options")
# Support MSVC
target_bigobj_options(matplot)
target_exception_options(matplot)
target_utf8_options(matplot)
target_nominmax_definition(matplot)
# Warnings
maybe_target_pedantic_warnings(matplot)
#######################################################
### Definitions ###
#######################################################
# Use experimental filesystem if std::filesystem is not available yet
if (CXX_FILESYSTEM_IS_EXPERIMENTAL)
target_compile_definitions(matplot PRIVATE CXX_FILESYSTEM_IS_EXPERIMENTAL)
endif()
# Some hack to not depend on FILE* internals
# https://github.com/alandefreitas/matplotplusplus/issues/4
include(CheckSymbolExists)
check_symbol_exists(__fbufsize "stdio_ext.h" HAVE_FBUFSIZE)
if (HAVE_FBUFSIZE)
target_compile_definitions(matplot PRIVATE MATPLOT_HAS_FBUFSIZE)
endif()
# Build for documentation
if (BUILD_FOR_DOCUMENTATION_IMAGES)
message("Building matplot for documentation images. wait() commands will be ignored. ~figure will save the files.")
target_compile_definitions(matplot PUBLIC MATPLOT_BUILD_FOR_DOCUMENTATION_IMAGES)
endif ()
# Include high-resolution world map in the binary
if (BUILD_HIGH_RESOLUTION_WORLD_MAP)
target_compile_definitions(matplot PUBLIC MATPLOT_BUILD_HIGH_RESOLUTION_WORLD_MAP)
else ()
message("Not including the high resolution maps for geoplots")
endif ()
#######################################################
### Library options ###
#######################################################
# Maybe add pedantic warning
#if (BUILD_WITH_PEDANTIC_WARNINGS)
# if (MSVC)
# target_compile_options(matplot PRIVATE /W4 /WX)
# else ()
# target_compile_options(matplot PRIVATE -Wall -Wextra -pedantic -Werror)
# # Allow the warnings related to the bundled CImg
# if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# target_compile_options(matplot PRIVATE -Wno-null-pointer-arithmetic -Wno-char-subscripts)
# elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# target_compile_options(matplot PRIVATE -Wno-error=class-memaccess -Wno-class-memaccess)
# else ()
# message(ERROR "Cannot disable the relevant warnings for ${CMAKE_CXX_COMPILER_ID}")
# endif ()
# endif ()
#endif ()
#######################################################
### Experimental OpenGL backend ###
#######################################################
if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
# Library for the OpenGL example
# This is an example of what an OpenGL backend *could* look like.
# The opengl backend is currently incomplete.
# There are two backends for OpenGL:
# - opengl_embed: you can put that inside your existing OpenGL
# application. You can then call draw() in your render loop
# to draw the plots on top of your application.
# - opengl: this backend will create it's own window and make
# plots there.
# Qt: If you're using Qt, opengl_embed allows you to create plots in your
# application. See https://doc.qt.io/qt-5/qtgui-index.html
# Web: If you're creating plots for the web, you can use emscripten to
# create efficient plots. See:
# https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html
# We are continuously making plot categories compatible with these backends.
# For each category, we need to adapt the axes objects to feed this backend
# with polygons and colors instead of commands.
# Feeding these commands is not a problem at all. The data is all prepared
# in the axes objects. Unlike an gnuplot backend, we don't have to convert
# this data to strings and do not have to worry about an external syntax.
# The biggest challenge is to actually create backends that can
# draw these polygons we feed them.
# We discuss some of these difficulties in the documentation
# and the backend_interface.h.
# The biggest pro of the OpenGL backend is that it is very efficient.
# Everything is happening on the GPU.
# The biggest con of the OpenGL backend is that it cannot open a window
# in another thread. All it can do is get in the middle of the render
# loop and draw the plot.
find_package(OpenGL REQUIRED)
# https://github.com/Dav1dde/glad
find_package(GLAD QUIET)
if (NOT GLAD_FOUND AND NOT TARGET glad)
# Use CPM only if not found, to avoid ODR violations
# find_package(GLAD REQUIRE) would suffice if it worked well
FetchContent_Declare(glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9)
FetchContent_MakeAvailable(glad)
else ()
# FindGLAD does not usually create a target, so we create an interface target
if (NOT TARGET glad)
add_library(glad INTERFACE)
target_include_directories(glad INTERFACE ${GLAD_INCLUDE_PATH})
target_link_libraries(glad INTERFACE ${GLAD_LIBRARIES})
endif ()
endif ()
# https://github.com/glfw/glfw
find_package(glfw3 QUIET)
if (NOT GLFW3_FOUND AND NOT TARGET glfw)
# Use CPM only if not found, to avoid ODR violations
# find_package(glfw3 REQUIRE) would suffice if it worked well
FetchContent_Declare(glfw3 GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.3.2)
FetchContent_MakeAvailable(glfw3)
endif ()
add_library(matplot_opengl
backend/opengl_embed.h
backend/opengl_embed.cpp
backend/opengl.h
backend/opengl.cpp
)
target_include_directories(matplot_opengl PUBLIC matplot)
target_link_libraries(matplot_opengl PUBLIC matplot glad glfw ${CMAKE_DL_LIBS})
endif()
#######################################################
### Installer ###
#######################################################
if (BUILD_INSTALLER)
# Install targets
install(TARGETS matplot
EXPORT Matplot++Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
# Install cmake script
install(EXPORT Matplot++Targets
FILE Matplot++Targets.cmake
NAMESPACE Matplot++::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++
)
endif()