-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
150 lines (140 loc) · 5.45 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
cmake_minimum_required(VERSION 3.12)
project(
"matplotlibcpp17"
VERSION 1.0.4
DESCRIPTION
"A C++ header-only plotting library based on pybind11 and matplotlib, featuring more flexibility than matplotlibcpp"
HOMEPAGE_URL "https://soblin.github.io/matplotlibcpp17/")
find_package(
Python3
COMPONENTS Interpreter Development
REQUIRED)
find_package(pybind11 2.4.3 REQUIRED)
# ##############################################################################
# (1) check matplotlib minor version
# ##############################################################################
execute_process(
COMMAND ${Python3_EXECUTABLE} "-c" "import matplotlib;
print(str(matplotlib.__version__), end='')"
RESULT_VARIABLE MATPLOTLIB_VERSION_CHECKING
OUTPUT_VARIABLE MATPLOTLIB_VERSION)
if(NOT MATPLOTLIB_VERSION_CHECKING MATCHES 0)
message(FATAL_ERROR "Could not check matplotlib.__version__")
endif()
message(STATUS "Detected matplotlib version is ${MATPLOTLIB_VERSION}")
if(${MATPLOTLIB_VERSION} VERSION_LESS 3.4)
message(WARNING "Detected matplotlib version is < 3.4.0")
set(MATPLOTLIB_MINOR_VER_GTE_4 0)
else()
message(STATUS "Detected matplotlib version is >= 3.4.0")
set(MATPLOTLIB_MINOR_VER_GTE_4 1)
endif()
# ##############################################################################
# (2) for add_subdirectory
# ##############################################################################
add_library(matplotlibcpp17::matplotlibcpp17 INTERFACE IMPORTED GLOBAL)
set_property(
TARGET matplotlibcpp17::matplotlibcpp17
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include
${Python3_INCLUDE_DIRS})
set_property(
TARGET matplotlibcpp17::matplotlibcpp17
PROPERTY INTERFACE_LINK_LIBRARIES ${Python3_LIBRARIES} pybind11::embed)
# ##############################################################################
# (3) install
# ##############################################################################
# https://dominikberner.ch/cmake-interface-lib/
include(GNUInstallDirs)
# header-only library(INTERFACE)
add_library(${PROJECT_NAME} INTERFACE)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME})
# to /share/cmake/matplotlibcpp17
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME})
# to /share/cmake/matplotlibcpp17
install(
EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME})
# to /include/matplotlibcpp17
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}
DESTINATION include)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
# create .deb
include("${PROJECT_SOURCE_DIR}/cmake/package.cmake")
target_include_directories(
${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
# ##############################################################################
# (4) uninstall
# ##############################################################################
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
if(NOT TARGET uninstall)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
endif()
# ##############################################################################
# (5) gallery
# ##############################################################################
if(NOT DEFINED USE_GUI)
set(USE_GUI 0)
message(STATUS "set USE_GUI = OFF")
endif()
if(NOT DEFINED ADD_DEMO)
set(ADD_DEMO 0)
message(STATUS "set ADD_DEMO = OFF")
endif()
if(USE_GUI)
message(STATUS "USE_GUI = ON")
else()
message(STATUS "USE_GUI = OFF")
endif()
if(ADD_DEMO)
message(STATUS "ADD_DEMO = ON")
else()
message(STATUS "ADD_DEMO = OFF")
endif()
function(add_demo name path)
add_executable(${name} ${path})
target_link_libraries(${name} xtensor matplotlibcpp17::matplotlibcpp17)
endfunction()
if(${ADD_DEMO})
find_package(
Python3
COMPONENTS NumPy
REQUIRED)
find_package(xtensor 0.24.0 REQUIRED)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS
"-Wall -g -DUSE_GUI=${USE_GUI} -DMATPLOTLIB_MINOR_VER_GTE_4=${MATPLOTLIB_MINOR_VER_GTE_4}"
)
add_subdirectory(gallery/tests)
add_subdirectory(gallery/lines_bars_and_markers)
add_subdirectory(gallery/subplots_axes_and_figures)
add_subdirectory(gallery/statistics)
add_subdirectory(gallery/images_contours_and_fields)
add_subdirectory(gallery/shapes_and_collections)
add_subdirectory(gallery/artist_animation)
add_subdirectory(gallery/mplot3d)
add_subdirectory(gallery/scales)
endif()