Skip to content

Commit 999b9c2

Browse files
committed
do not build examples if not explicitly enabled
1 parent c2e1946 commit 999b9c2

1 file changed

Lines changed: 69 additions & 66 deletions

File tree

CMakeLists.txt

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(PACKAGE_NAME matplotlib_cpp)
66
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake)
77

88

9+
option(BUILD_EXAMPLES "Build examples" OFF)
10+
911
# Library target
1012
add_library(matplotlib_cpp INTERFACE)
1113
target_include_directories(matplotlib_cpp
@@ -36,72 +38,73 @@ install(
3638
)
3739

3840

39-
# Examples
40-
add_executable(minimal examples/minimal.cpp)
41-
target_link_libraries(minimal PRIVATE matplotlib_cpp)
42-
set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
43-
44-
add_executable(basic examples/basic.cpp)
45-
target_link_libraries(basic PRIVATE matplotlib_cpp)
46-
set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
47-
48-
add_executable(modern examples/modern.cpp)
49-
target_link_libraries(modern PRIVATE matplotlib_cpp)
50-
set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
51-
52-
add_executable(animation examples/animation.cpp)
53-
target_link_libraries(animation PRIVATE matplotlib_cpp)
54-
set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
55-
56-
add_executable(nonblock examples/nonblock.cpp)
57-
target_link_libraries(nonblock PRIVATE matplotlib_cpp)
58-
set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
59-
60-
add_executable(xkcd examples/xkcd.cpp)
61-
target_link_libraries(xkcd PRIVATE matplotlib_cpp)
62-
set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
63-
64-
add_executable(bar examples/bar.cpp)
65-
target_link_libraries(bar PRIVATE matplotlib_cpp)
66-
set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
67-
68-
add_executable(fill_inbetween examples/fill_inbetween.cpp)
69-
target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
70-
set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
71-
72-
add_executable(fill examples/fill.cpp)
73-
target_link_libraries(fill PRIVATE matplotlib_cpp)
74-
set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
75-
76-
add_executable(update examples/update.cpp)
77-
target_link_libraries(update PRIVATE matplotlib_cpp)
78-
set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
79-
80-
add_executable(subplot2grid examples/subplot2grid.cpp)
81-
target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
82-
set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
83-
84-
add_executable(lines3d examples/lines3d.cpp)
85-
target_link_libraries(lines3d PRIVATE matplotlib_cpp)
86-
set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
87-
88-
if(Python3_NumPy_FOUND)
89-
add_executable(surface examples/surface.cpp)
90-
target_link_libraries(surface PRIVATE matplotlib_cpp)
91-
set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
92-
93-
add_executable(colorbar examples/colorbar.cpp)
94-
target_link_libraries(colorbar PRIVATE matplotlib_cpp)
95-
set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
96-
add_executable(contour examples/contour.cpp)
97-
target_link_libraries(contour PRIVATE matplotlib_cpp)
98-
set_target_properties(contour PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
99-
100-
add_executable(spy examples/spy.cpp)
101-
target_link_libraries(spy PRIVATE matplotlib_cpp)
102-
set_target_properties(spy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
103-
endif()
104-
41+
if(BUILD_EXAMPLES)
42+
# Examples
43+
add_executable(minimal examples/minimal.cpp)
44+
target_link_libraries(minimal PRIVATE matplotlib_cpp)
45+
set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
46+
47+
add_executable(basic examples/basic.cpp)
48+
target_link_libraries(basic PRIVATE matplotlib_cpp)
49+
set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
50+
51+
add_executable(modern examples/modern.cpp)
52+
target_link_libraries(modern PRIVATE matplotlib_cpp)
53+
set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
54+
55+
add_executable(animation examples/animation.cpp)
56+
target_link_libraries(animation PRIVATE matplotlib_cpp)
57+
set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
58+
59+
add_executable(nonblock examples/nonblock.cpp)
60+
target_link_libraries(nonblock PRIVATE matplotlib_cpp)
61+
set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
62+
63+
add_executable(xkcd examples/xkcd.cpp)
64+
target_link_libraries(xkcd PRIVATE matplotlib_cpp)
65+
set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
66+
67+
add_executable(bar examples/bar.cpp)
68+
target_link_libraries(bar PRIVATE matplotlib_cpp)
69+
set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
70+
71+
add_executable(fill_inbetween examples/fill_inbetween.cpp)
72+
target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
73+
set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
74+
75+
add_executable(fill examples/fill.cpp)
76+
target_link_libraries(fill PRIVATE matplotlib_cpp)
77+
set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
78+
79+
add_executable(update examples/update.cpp)
80+
target_link_libraries(update PRIVATE matplotlib_cpp)
81+
set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
82+
83+
add_executable(subplot2grid examples/subplot2grid.cpp)
84+
target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
85+
set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
86+
87+
add_executable(lines3d examples/lines3d.cpp)
88+
target_link_libraries(lines3d PRIVATE matplotlib_cpp)
89+
set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
90+
91+
if(Python3_NumPy_FOUND)
92+
add_executable(surface examples/surface.cpp)
93+
target_link_libraries(surface PRIVATE matplotlib_cpp)
94+
set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
95+
96+
add_executable(colorbar examples/colorbar.cpp)
97+
target_link_libraries(colorbar PRIVATE matplotlib_cpp)
98+
set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
99+
add_executable(contour examples/contour.cpp)
100+
target_link_libraries(contour PRIVATE matplotlib_cpp)
101+
set_target_properties(contour PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
102+
103+
add_executable(spy examples/spy.cpp)
104+
target_link_libraries(spy PRIVATE matplotlib_cpp)
105+
set_target_properties(spy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
106+
endif()
107+
endif(BUILD_EXAMPLES)
105108

106109
# Install headers
107110
install(FILES

0 commit comments

Comments
 (0)