Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
162 lines (137 loc) · 5.84 KB
/
Copy pathCMakeLists.txt
File metadata and controls
162 lines (137 loc) · 5.84 KB
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
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(matplotlib_cpp LANGUAGES CXX)
include(GNUInstallDirs)
set(PACKAGE_NAME matplotlib_cpp)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake)
option(USING_PYTHON3 "Build against Python 3 (set OFF to use Python 2)" ON)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(_mpl_top ON)
else()
set(_mpl_top OFF)
endif()
option(MATPLOTLIB_CPP_BUILD_EXAMPLES "Build the examples" ${_mpl_top})
# Library target
add_library(matplotlib_cpp INTERFACE)
target_include_directories(matplotlib_cpp
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_compile_features(matplotlib_cpp INTERFACE
cxx_std_11
)
# TODO: Use `Development.Embed` component when requiring cmake >= 3.18
if(USING_PYTHON3)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
target_link_libraries(matplotlib_cpp INTERFACE
Python3::Python
Python3::Module
)
find_package(Python3 COMPONENTS NumPy)
if(Python3_NumPy_FOUND)
target_link_libraries(matplotlib_cpp INTERFACE
Python3::NumPy
)
else()
target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
endif()
else()
find_package(Python2 COMPONENTS Interpreter Development REQUIRED)
target_link_libraries(matplotlib_cpp INTERFACE
Python2::Python
Python2::Module
)
find_package(Python2 COMPONENTS NumPy)
if(Python2_NumPy_FOUND)
target_link_libraries(matplotlib_cpp INTERFACE
Python2::NumPy
)
else()
target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
endif()
endif()
install(
TARGETS matplotlib_cpp
EXPORT install_targets
)
# Examples
if(MATPLOTLIB_CPP_BUILD_EXAMPLES)
add_executable(minimal examples/minimal.cpp)
target_link_libraries(minimal PRIVATE matplotlib_cpp)
set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(basic examples/basic.cpp)
target_link_libraries(basic PRIVATE matplotlib_cpp)
set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(modern examples/modern.cpp)
target_link_libraries(modern PRIVATE matplotlib_cpp)
set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(animation examples/animation.cpp)
target_link_libraries(animation PRIVATE matplotlib_cpp)
set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(nonblock examples/nonblock.cpp)
target_link_libraries(nonblock PRIVATE matplotlib_cpp)
set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(xkcd examples/xkcd.cpp)
target_link_libraries(xkcd PRIVATE matplotlib_cpp)
set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(bar examples/bar.cpp)
target_link_libraries(bar PRIVATE matplotlib_cpp)
set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(fill_inbetween examples/fill_inbetween.cpp)
target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(fill examples/fill.cpp)
target_link_libraries(fill PRIVATE matplotlib_cpp)
set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(update examples/update.cpp)
target_link_libraries(update PRIVATE matplotlib_cpp)
set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(subplot2grid examples/subplot2grid.cpp)
target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(lines3d examples/lines3d.cpp)
target_link_libraries(lines3d PRIVATE matplotlib_cpp)
set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
if((USING_PYTHON3 AND Python3_NumPy_FOUND) OR (NOT USING_PYTHON3 AND Python2_NumPy_FOUND))
add_executable(surface examples/surface.cpp)
target_link_libraries(surface PRIVATE matplotlib_cpp)
set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(colorbar examples/colorbar.cpp)
target_link_libraries(colorbar PRIVATE matplotlib_cpp)
set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(contour examples/contour.cpp)
target_link_libraries(contour PRIVATE matplotlib_cpp)
set_target_properties(contour PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(contourf examples/contourf.cpp)
target_link_libraries(contourf PRIVATE matplotlib_cpp)
set_target_properties(contourf PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(spy examples/spy.cpp)
target_link_libraries(spy PRIVATE matplotlib_cpp)
set_target_properties(spy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
endif()
# Install headers
install(FILES
"${PROJECT_SOURCE_DIR}/matplotlibcpp.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install targets file
install(EXPORT install_targets
FILE
${PACKAGE_NAME}Targets.cmake
NAMESPACE
${PACKAGE_NAME}::
DESTINATION
${INSTALL_CONFIGDIR}
)
# Install matplotlib_cppConfig.cmake
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PACKAGE_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
add_library(matplotlib_cpp::matplotlib_cpp ALIAS matplotlib_cpp)