CMakeLists.txt 4.7 KB

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