Skip to content

Commit 486eb41

Browse files
committed
Remove CPM from 3rd_party dependencies
1 parent 2732c3f commit 486eb41

File tree

2 files changed

+68
-43
lines changed

2 files changed

+68
-43
lines changed

source/3rd_party/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Add nodesoup library
1+
#######################################################
2+
### NodeSoup ###
3+
#######################################################
24
if(WITH_SYSTEM_NODESOUP)
35
find_path(NODESOUP_INCLUDE_DIR nodesoup.hpp REQUIRED)
46
find_library(NODESOUP_LIB nodesoup REQUIRED)
@@ -45,14 +47,17 @@ if(MASTER_PROJECT AND NOT BUILD_SHARED_LIBS)
4547
endif()
4648

4749

48-
# Add CImg library
50+
#######################################################
51+
### CImg ###
52+
#######################################################
4953
add_library(cimg INTERFACE)
5054
if(WITH_SYSTEM_CIMG)
5155
find_path(CIMG_INCLUDE_DIR CImg.h REQUIRED)
5256
else()
5357
set(CIMG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cimg)
5458
endif()
5559
target_include_directories(cimg INTERFACE $<BUILD_INTERFACE:${CIMG_INCLUDE_DIR}>)
60+
target_compile_options(cimg INTERFACE -Wno-deprecated-declarations)
5661

5762

5863
find_package(PkgConfig)

source/matplot/CMakeLists.txt

+61-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
find_package(Filesystem REQUIRED COMPONENTS Experimental Final)
22

3+
#######################################################
4+
### Library ###
5+
#######################################################
36
add_library(matplot
47
matplot.h
58

@@ -84,77 +87,91 @@ add_library(matplot
8487
freestanding/histcounts.cpp
8588
freestanding/plot.h
8689
)
90+
91+
# Target alias
8792
add_library(Matplot++::matplot ALIAS matplot)
8893

94+
# Include dirs
8995
target_include_directories(matplot
9096
PUBLIC $<BUILD_INTERFACE:${MATPLOT_ROOT_DIR}/source>
9197
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
9298

93-
target_link_libraries_system(matplot
99+
# Dependencies
100+
target_link_libraries_system(matplot
94101
PRIVATE cimg nodesoup std::filesystem)
95102

103+
# Required compiler features required
96104
# https://cmake.org/cmake/help/v3.14/manual/cmake-compile-features.7.html#requiring-language-standards
97105
target_compile_features(matplot PUBLIC cxx_std_17)
98106

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
100124
if (CXX_FILESYSTEM_IS_EXPERIMENTAL)
101125
target_compile_definitions(matplot PRIVATE CXX_FILESYSTEM_IS_EXPERIMENTAL)
102126
endif()
103127

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-
117128
# Some hack to not depend on FILE* internals
118129
# https://github.com/alandefreitas/matplotplusplus/issues/4
130+
include(CheckSymbolExists)
119131
check_symbol_exists(__fbufsize "stdio_ext.h" HAVE_FBUFSIZE)
120132
if (HAVE_FBUFSIZE)
121133
target_compile_definitions(matplot PRIVATE MATPLOT_HAS_FBUFSIZE)
122134
endif()
123135

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
131137
if (BUILD_FOR_DOCUMENTATION_IMAGES)
132138
message("Building matplot for documentation images. wait() commands will be ignored. ~figure will save the files.")
133139
target_compile_definitions(matplot PUBLIC MATPLOT_BUILD_FOR_DOCUMENTATION_IMAGES)
134140
endif ()
135141

142+
# Include high-resolution world map in the binary
136143
if (BUILD_HIGH_RESOLUTION_WORLD_MAP)
137144
target_compile_definitions(matplot PUBLIC MATPLOT_BUILD_HIGH_RESOLUTION_WORLD_MAP)
138145
else ()
139146
message("Not including the high resolution maps for geoplots")
140147
endif ()
141148

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+
#######################################################
157152

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+
#######################################################
158175
if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
159176
# Library for the OpenGL example
160177
# This is an example of what an OpenGL backend *could* look like.
@@ -192,7 +209,8 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
192209
if (NOT GLAD_FOUND AND NOT TARGET glad)
193210
# Use CPM only if not found, to avoid ODR violations
194211
# 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)
196214
else ()
197215
# FindGLAD does not usually create a target, so we create an interface target
198216
if (NOT TARGET glad)
@@ -207,7 +225,8 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
207225
if (NOT GLFW3_FOUND AND NOT TARGET glfw)
208226
# Use CPM only if not found, to avoid ODR violations
209227
# 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)
211230
endif ()
212231

213232
add_library(matplot_opengl
@@ -220,8 +239,9 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
220239
target_link_libraries(matplot_opengl PUBLIC matplot glad glfw ${CMAKE_DL_LIBS})
221240
endif()
222241

223-
224-
# Install
242+
#######################################################
243+
### Installer ###
244+
#######################################################
225245
if (BUILD_INSTALLER)
226246
# Install targets
227247
install(TARGETS matplot

0 commit comments

Comments
 (0)