Skip to content

Commit 990c256

Browse files
committed
v1.0.4
Signed-off-by: soblin <hilo.soblin@gmail.com>
1 parent 53d8a15 commit 990c256

File tree

1 file changed

+70
-57
lines changed

1 file changed

+70
-57
lines changed

CMakeLists.txt

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
22

33
project(
44
"matplotlibcpp17"
5-
VERSION 1.0.0
5+
VERSION 1.0.4
66
DESCRIPTION
77
"A C++ header-only plotting library based on pybind11 and matplotlib, featuring more flexibility than matplotlibcpp"
88
HOMEPAGE_URL "https://soblin.github.io/matplotlibcpp17/")
@@ -13,13 +13,14 @@ find_package(
1313
REQUIRED)
1414
find_package(pybind11 2.4.3 REQUIRED)
1515

16-
# check matplotlib minor version
16+
# ##############################################################################
17+
# (1) check matplotlib minor version
18+
# ##############################################################################
1719
execute_process(
1820
COMMAND ${Python3_EXECUTABLE} "-c" "import matplotlib;
1921
print(str(matplotlib.__version__), end='')"
2022
RESULT_VARIABLE MATPLOTLIB_VERSION_CHECKING
2123
OUTPUT_VARIABLE MATPLOTLIB_VERSION)
22-
2324
if(NOT MATPLOTLIB_VERSION_CHECKING MATCHES 0)
2425
message(FATAL_ERROR "Could not check matplotlib.__version__")
2526
endif()
@@ -32,55 +33,15 @@ else()
3233
set(MATPLOTLIB_MINOR_VER_GTE_4 1)
3334
endif()
3435

35-
# gallery
36-
if(NOT DEFINED USE_GUI)
37-
set(USE_GUI 0)
38-
message(STATUS "set USE_GUI = OFF")
39-
endif()
40-
if(NOT DEFINED ADD_DEMO)
41-
set(ADD_DEMO 0)
42-
message(STATUS "set ADD_DEMO = OFF")
43-
endif()
44-
if(USE_GUI)
45-
message(STATUS "USE_GUI = ON")
46-
else()
47-
message(STATUS "USE_GUI = OFF")
48-
endif()
49-
if(ADD_DEMO)
50-
message(STATUS "ADD_DEMO = ON")
51-
else()
52-
message(STATUS "ADD_DEMO = OFF")
53-
endif()
54-
55-
function(add_demo name path)
56-
add_executable(${name} ${path})
57-
target_include_directories(${name} PUBLIC ${Python3_INCLUDE_DIRS}
58-
${matplotlibcpp17_INCLUDE_DIRS})
59-
target_link_libraries(${name} ${Python3_LIBRARIES} pybind11::embed xtensor)
60-
endfunction()
61-
62-
if(${ADD_DEMO})
63-
find_package(
64-
Python3
65-
COMPONENTS NumPy
66-
REQUIRED)
67-
find_package(xtensor 0.24.0 REQUIRED)
68-
set(CMAKE_CXX_STANDARD 17)
69-
set(CMAKE_CXX_FLAGS
70-
"-Wall -g -DUSE_GUI=${USE_GUI} -DMATPLOTLIB_MINOR_VER_GTE_4=${MATPLOTLIB_MINOR_VER_GTE_4}"
71-
)
72-
add_subdirectory(gallery/tests)
73-
add_subdirectory(gallery/lines_bars_and_markers)
74-
add_subdirectory(gallery/subplots_axes_and_figures)
75-
add_subdirectory(gallery/statistics)
76-
add_subdirectory(gallery/images_contours_and_fields)
77-
add_subdirectory(gallery/shapes_and_collections)
78-
add_subdirectory(gallery/artist_animation)
79-
add_subdirectory(gallery/mplot3d)
80-
add_subdirectory(gallery/scales)
81-
endif()
36+
target_include_directories(
37+
${PROJECT_NAME}
38+
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
39+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
40+
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
8241

83-
# for add_subdirectory
42+
# ##############################################################################
43+
# (2) for add_subdirectory
44+
# ##############################################################################
8445
add_library(matplotlibcpp17::matplotlibcpp17 INTERFACE IMPORTED GLOBAL)
8546
set_property(
8647
TARGET matplotlibcpp17::matplotlibcpp17
@@ -90,14 +51,13 @@ set_property(
9051
TARGET matplotlibcpp17::matplotlibcpp17
9152
PROPERTY INTERFACE_LINK_LIBRARIES ${Python3_LIBRARIES} pybind11::embed)
9253

93-
# install https://dominikberner.ch/cmake-interface-lib/
54+
# ##############################################################################
55+
# (3) install
56+
# ##############################################################################
57+
# https://dominikberner.ch/cmake-interface-lib/
9458
include(GNUInstallDirs)
59+
# header-only library(INTERFACE)
9560
add_library(${PROJECT_NAME} INTERFACE)
96-
target_include_directories(
97-
${PROJECT_NAME}
98-
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
99-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
100-
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
10161
install(
10262
TARGETS ${PROJECT_NAME}
10363
EXPORT ${PROJECT_NAME}_Targets
@@ -129,6 +89,9 @@ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
12989
# create .deb
13090
include("${PROJECT_SOURCE_DIR}/cmake/package.cmake")
13191

92+
# ##############################################################################
93+
# (4) uninstall
94+
# ##############################################################################
13295
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
13396
if(NOT TARGET uninstall)
13497
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
@@ -137,3 +100,53 @@ if(NOT TARGET uninstall)
137100
uninstall COMMAND ${CMAKE_COMMAND} -P
138101
${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
139102
endif()
103+
104+
# ##############################################################################
105+
# (5) gallery
106+
# ##############################################################################
107+
if(NOT DEFINED USE_GUI)
108+
set(USE_GUI 0)
109+
message(STATUS "set USE_GUI = OFF")
110+
endif()
111+
if(NOT DEFINED ADD_DEMO)
112+
set(ADD_DEMO 0)
113+
message(STATUS "set ADD_DEMO = OFF")
114+
endif()
115+
if(USE_GUI)
116+
message(STATUS "USE_GUI = ON")
117+
else()
118+
message(STATUS "USE_GUI = OFF")
119+
endif()
120+
if(ADD_DEMO)
121+
message(STATUS "ADD_DEMO = ON")
122+
else()
123+
message(STATUS "ADD_DEMO = OFF")
124+
endif()
125+
126+
function(add_demo name path)
127+
add_executable(${name} ${path})
128+
target_include_directories(${name} PUBLIC ${Python3_INCLUDE_DIRS}
129+
${matplotlibcpp17_INCLUDE_DIRS})
130+
target_link_libraries(${name} ${Python3_LIBRARIES} pybind11::embed xtensor)
131+
endfunction()
132+
133+
if(${ADD_DEMO})
134+
find_package(
135+
Python3
136+
COMPONENTS NumPy
137+
REQUIRED)
138+
find_package(xtensor 0.24.0 REQUIRED)
139+
set(CMAKE_CXX_STANDARD 17)
140+
set(CMAKE_CXX_FLAGS
141+
"-Wall -g -DUSE_GUI=${USE_GUI} -DMATPLOTLIB_MINOR_VER_GTE_4=${MATPLOTLIB_MINOR_VER_GTE_4}"
142+
)
143+
add_subdirectory(gallery/tests)
144+
add_subdirectory(gallery/lines_bars_and_markers)
145+
add_subdirectory(gallery/subplots_axes_and_figures)
146+
add_subdirectory(gallery/statistics)
147+
add_subdirectory(gallery/images_contours_and_fields)
148+
add_subdirectory(gallery/shapes_and_collections)
149+
add_subdirectory(gallery/artist_animation)
150+
add_subdirectory(gallery/mplot3d)
151+
add_subdirectory(gallery/scales)
152+
endif()

0 commit comments

Comments
 (0)