|
| 1 | +cmake_minimum_required(VERSION 3.8 FATAL_ERROR) |
| 2 | +project(matplotlib_cpp LANGUAGES CXX) |
| 3 | + |
| 4 | +include(GNUInstallDirs) |
| 5 | +set(PACKAGE_NAME matplotlib_cpp) |
| 6 | +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake) |
| 7 | + |
| 8 | + |
| 9 | +# Library target |
| 10 | +add_library(matplotlib_cpp INTERFACE) |
| 11 | +target_include_directories(matplotlib_cpp |
| 12 | + INTERFACE |
| 13 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/examples> |
| 14 | + $<INSTALL_INTERFACE:include> |
| 15 | +) |
| 16 | +target_compile_features(matplotlib_cpp INTERFACE |
| 17 | + cxx_std_11 |
| 18 | +) |
| 19 | +find_package(Python3 COMPONENTS Interpreter Development REQUIRED) |
| 20 | +target_link_libraries(matplotlib_cpp INTERFACE |
| 21 | + Python3::Python |
| 22 | + Python3::Module |
| 23 | +) |
| 24 | +find_package(Python3 COMPONENTS NumPy) |
| 25 | +if(Python3_NumPy_FOUND) |
| 26 | + target_link_libraries(matplotlib_cpp INTERFACE |
| 27 | + Python3::NumPy |
| 28 | + ) |
| 29 | +else() |
| 30 | + target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY) |
| 31 | +endif() |
| 32 | +install( |
| 33 | + TARGETS matplotlib_cpp |
| 34 | + EXPORT install_targets |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | +# Examples |
| 39 | +add_executable(minimal examples/minimal.cpp) |
| 40 | +target_link_libraries(minimal PRIVATE matplotlib_cpp) |
| 41 | +set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 42 | + |
| 43 | +add_executable(basic examples/basic.cpp) |
| 44 | +target_link_libraries(basic PRIVATE matplotlib_cpp) |
| 45 | +set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 46 | + |
| 47 | +add_executable(modern examples/modern.cpp) |
| 48 | +target_link_libraries(modern PRIVATE matplotlib_cpp) |
| 49 | +set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 50 | + |
| 51 | +add_executable(animation examples/animation.cpp) |
| 52 | +target_link_libraries(animation PRIVATE matplotlib_cpp) |
| 53 | +set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 54 | + |
| 55 | +add_executable(nonblock examples/nonblock.cpp) |
| 56 | +target_link_libraries(nonblock PRIVATE matplotlib_cpp) |
| 57 | +set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 58 | + |
| 59 | +add_executable(xkcd examples/xkcd.cpp) |
| 60 | +target_link_libraries(xkcd PRIVATE matplotlib_cpp) |
| 61 | +set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 62 | + |
| 63 | +add_executable(bar examples/bar.cpp) |
| 64 | +target_link_libraries(bar PRIVATE matplotlib_cpp) |
| 65 | +set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 66 | + |
| 67 | +add_executable(fill_inbetween examples/fill_inbetween.cpp) |
| 68 | +target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp) |
| 69 | +set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 70 | + |
| 71 | +add_executable(fill examples/fill.cpp) |
| 72 | +target_link_libraries(fill PRIVATE matplotlib_cpp) |
| 73 | +set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 74 | + |
| 75 | +add_executable(update examples/update.cpp) |
| 76 | +target_link_libraries(update PRIVATE matplotlib_cpp) |
| 77 | +set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 78 | + |
| 79 | +add_executable(subplot2grid examples/subplot2grid.cpp) |
| 80 | +target_link_libraries(subplot2grid PRIVATE matplotlib_cpp) |
| 81 | +set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 82 | + |
| 83 | +add_executable(lines3d examples/lines3d.cpp) |
| 84 | +target_link_libraries(lines3d PRIVATE matplotlib_cpp) |
| 85 | +set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 86 | + |
| 87 | +if(Python3_NumPy_FOUND) |
| 88 | + add_executable(surface examples/surface.cpp) |
| 89 | + target_link_libraries(surface PRIVATE matplotlib_cpp) |
| 90 | + set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 91 | + |
| 92 | + add_executable(colorbar examples/colorbar.cpp) |
| 93 | + target_link_libraries(colorbar PRIVATE matplotlib_cpp) |
| 94 | + set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") |
| 95 | +endif() |
| 96 | + |
| 97 | + |
| 98 | +# Install headers |
| 99 | +install(FILES |
| 100 | + "${PROJECT_SOURCE_DIR}/matplotlibcpp.h" |
| 101 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 102 | + |
| 103 | + |
| 104 | +# Install targets file |
| 105 | +install(EXPORT install_targets |
| 106 | + FILE |
| 107 | + ${PACKAGE_NAME}Targets.cmake |
| 108 | + NAMESPACE |
| 109 | + ${PACKAGE_NAME}:: |
| 110 | + DESTINATION |
| 111 | + ${INSTALL_CONFIGDIR} |
| 112 | +) |
| 113 | + |
| 114 | + |
| 115 | +# Install matplotlib_cppConfig.cmake |
| 116 | +include(CMakePackageConfigHelpers) |
| 117 | +configure_package_config_file( |
| 118 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PACKAGE_NAME}Config.cmake.in |
| 119 | + ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake |
| 120 | + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} |
| 121 | +) |
| 122 | +install(FILES |
| 123 | + ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake |
| 124 | + DESTINATION ${INSTALL_CONFIGDIR} |
| 125 | +) |
0 commit comments