1
1
find_package (Filesystem REQUIRED COMPONENTS Experimental Final)
2
2
3
+ #######################################################
4
+ ### Library ###
5
+ #######################################################
3
6
add_library (matplot
4
7
matplot.h
5
8
@@ -84,77 +87,91 @@ add_library(matplot
84
87
freestanding/histcounts.cpp
85
88
freestanding/plot.h
86
89
)
90
+
91
+ # Target alias
87
92
add_library (Matplot++::matplot ALIAS matplot)
88
93
94
+ # Include dirs
89
95
target_include_directories (matplot
90
96
PUBLIC $<BUILD_INTERFACE:${MATPLOT_ROOT_DIR} /source >
91
97
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >)
92
98
93
- target_link_libraries_system(matplot
99
+ # Dependencies
100
+ target_link_libraries_system(matplot
94
101
PRIVATE cimg nodesoup std::filesystem)
95
102
103
+ # Required compiler features required
96
104
# https://cmake.org/cmake/help/v3.14/manual/cmake-compile-features.7.html#requiring-language-standards
97
105
target_compile_features (matplot PUBLIC cxx_std_17)
98
106
99
- # Definition to find the proper filesystem library
107
+ #######################################################
108
+ ### Compiler options ###
109
+ #######################################################
110
+ # Support MSVC
111
+ target_bigobj_options(matplot)
112
+ target_exception_options(matplot)
113
+ target_utf8_options(matplot)
114
+ target_disable_minmax(matplot)
115
+
116
+ # Warnings
117
+ maybe_target_pedantic_warnings(matplot)
118
+ target_msvc_compile_options(matplot PRIVATE /wd4305)
119
+
120
+ #######################################################
121
+ ### Definitions ###
122
+ #######################################################
123
+ # Use experimental filesystem if std::filesystem is not available yet
100
124
if (CXX_FILESYSTEM_IS_EXPERIMENTAL)
101
125
target_compile_definitions (matplot PRIVATE CXX_FILESYSTEM_IS_EXPERIMENTAL)
102
126
endif ()
103
127
104
- # Hacks to support MSVC
105
- if (MSVC )
106
- # World maps require this option because there is so much in the file
107
- target_compile_options (matplot PRIVATE /bigobj)
108
- target_compile_options (matplot PUBLIC /wd4305)
109
- # Fix compile error caused by utf8 character in line_spec.cpp
110
- target_compile_options (matplot PUBLIC /utf-8)
111
- # Allow exceptions
112
- target_compile_options (matplot PRIVATE /EHsc)
113
- endif ()
114
-
115
- include (CheckSymbolExists)
116
-
117
128
# Some hack to not depend on FILE* internals
118
129
# https://github.com/alandefreitas/matplotplusplus/issues/4
130
+ include (CheckSymbolExists)
119
131
check_symbol_exists(__fbufsize "stdio_ext.h" HAVE_FBUFSIZE)
120
132
if (HAVE_FBUFSIZE)
121
133
target_compile_definitions (matplot PRIVATE MATPLOT_HAS_FBUFSIZE)
122
134
endif ()
123
135
124
- # Another hack to check for min in Windows.h
125
- # http://www.suodenjoki.dk/us/archive/2010/min-max.htm
126
- check_symbol_exists(min "Windows.h" HAVE_WINDOWS_MINMAX)
127
- if (HAVE_WINDOWS_MINMAX)
128
- target_compile_definitions (matplot PUBLIC NOMINMAX)
129
- endif ()
130
-
136
+ # Build for documentation
131
137
if (BUILD_FOR_DOCUMENTATION_IMAGES)
132
138
message ("Building matplot for documentation images. wait() commands will be ignored. ~figure will save the files." )
133
139
target_compile_definitions (matplot PUBLIC MATPLOT_BUILD_FOR_DOCUMENTATION_IMAGES)
134
140
endif ()
135
141
142
+ # Include high-resolution world map in the binary
136
143
if (BUILD_HIGH_RESOLUTION_WORLD_MAP)
137
144
target_compile_definitions (matplot PUBLIC MATPLOT_BUILD_HIGH_RESOLUTION_WORLD_MAP)
138
145
else ()
139
146
message ("Not including the high resolution maps for geoplots" )
140
147
endif ()
141
148
142
- if (BUILD_WITH_PEDANTIC_WARNINGS)
143
- if (MSVC )
144
- target_compile_options (matplot PRIVATE /W4 /WX)
145
- else ()
146
- target_compile_options (matplot PRIVATE -Wall -Wextra -pedantic -Werror)
147
- # Allow the warnings related to the bundled CImg
148
- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
149
- target_compile_options (matplot PRIVATE -Wno-null-pointer-arithmetic -Wno-char-subscripts)
150
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
151
- target_compile_options (matplot PRIVATE -Wno-error=class-memaccess -Wno-class-memaccess)
152
- else ()
153
- message (ERROR "Cannot disable the relevant warnings for ${CMAKE_CXX_COMPILER_ID} " )
154
- endif ()
155
- endif ()
156
- endif ()
149
+ #######################################################
150
+ ### Library options ###
151
+ #######################################################
157
152
153
+ # Maybe add pedantic warning
154
+
155
+
156
+ #if (BUILD_WITH_PEDANTIC_WARNINGS)
157
+ # if (MSVC)
158
+ # target_compile_options(matplot PRIVATE /W4 /WX)
159
+ # else ()
160
+ # target_compile_options(matplot PRIVATE -Wall -Wextra -pedantic -Werror)
161
+ # # Allow the warnings related to the bundled CImg
162
+ # if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
163
+ # target_compile_options(matplot PRIVATE -Wno-null-pointer-arithmetic -Wno-char-subscripts)
164
+ # elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
165
+ # target_compile_options(matplot PRIVATE -Wno-error=class-memaccess -Wno-class-memaccess)
166
+ # else ()
167
+ # message(ERROR "Cannot disable the relevant warnings for ${CMAKE_CXX_COMPILER_ID}")
168
+ # endif ()
169
+ # endif ()
170
+ #endif ()
171
+
172
+ #######################################################
173
+ ### Experimental OpenGL backend ###
174
+ #######################################################
158
175
if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
159
176
# Library for the OpenGL example
160
177
# This is an example of what an OpenGL backend *could* look like.
@@ -192,7 +209,8 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
192
209
if (NOT GLAD_FOUND AND NOT TARGET glad)
193
210
# Use CPM only if not found, to avoid ODR violations
194
211
# find_package(GLAD REQUIRE) would suffice if it worked well
195
- CPMAddPackage(NAME glad GIT_REPOSITORY https://github.com/Dav1dde/glad GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9 VERSION 0.1.33)
212
+ FetchContent_Declare(glad GIT_REPOSITORY https://github.com/Dav1dde/glad.git GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9)
213
+ FetchContent_MakeAvailable(glad)
196
214
else ()
197
215
# FindGLAD does not usually create a target, so we create an interface target
198
216
if (NOT TARGET glad)
@@ -207,7 +225,8 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
207
225
if (NOT GLFW3_FOUND AND NOT TARGET glfw)
208
226
# Use CPM only if not found, to avoid ODR violations
209
227
# find_package(glfw3 REQUIRE) would suffice if it worked well
210
- CPMAddPackage(NAME glfw3 GIT_REPOSITORY https://github.com/glfw/glfw VERSION 3.3.2 GIT_TAG 3.3.2 OPTIONS "GLFW_BUILD_DOCS OFF" "GLFW_BUILD_EXAMPLES OFF" "GLFW_BUILD_TESTS OFF" "GLFW_INSTALL OFF" )
228
+ FetchContent_Declare(glfw3 GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.3.2)
229
+ FetchContent_MakeAvailable(glfw3)
211
230
endif ()
212
231
213
232
add_library (matplot_opengl
@@ -220,8 +239,9 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
220
239
target_link_libraries (matplot_opengl PUBLIC matplot glad glfw ${CMAKE_DL_LIBS} )
221
240
endif ()
222
241
223
-
224
- # Install
242
+ #######################################################
243
+ ### Installer ###
244
+ #######################################################
225
245
if (BUILD_INSTALLER)
226
246
# Install targets
227
247
install (TARGETS matplot
0 commit comments