CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
  17. target_link_libraries(matplotlib_cpp INTERFACE
  18. Python3::Python
  19. Python3::Module
  20. )
  21. find_package(Python3 COMPONENTS NumPy)
  22. if(Python3_NumPy_FOUND)
  23. target_link_libraries(matplotlib_cpp INTERFACE
  24. Python3::NumPy
  25. )
  26. else()
  27. target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
  28. endif()
  29. install(
  30. TARGETS matplotlib_cpp
  31. EXPORT install_targets
  32. )
  33. # Examples
  34. add_executable(minimal examples/minimal.cpp)
  35. target_link_libraries(minimal PRIVATE matplotlib_cpp)
  36. set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  37. add_executable(basic examples/basic.cpp)
  38. target_link_libraries(basic PRIVATE matplotlib_cpp)
  39. set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  40. add_executable(modern examples/modern.cpp)
  41. target_link_libraries(modern PRIVATE matplotlib_cpp)
  42. set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  43. add_executable(animation examples/animation.cpp)
  44. target_link_libraries(animation PRIVATE matplotlib_cpp)
  45. set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  46. add_executable(nonblock examples/nonblock.cpp)
  47. target_link_libraries(nonblock PRIVATE matplotlib_cpp)
  48. set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  49. add_executable(xkcd examples/xkcd.cpp)
  50. target_link_libraries(xkcd PRIVATE matplotlib_cpp)
  51. set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  52. add_executable(bar examples/bar.cpp)
  53. target_link_libraries(bar PRIVATE matplotlib_cpp)
  54. set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  55. add_executable(fill_inbetween examples/fill_inbetween.cpp)
  56. target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
  57. set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  58. add_executable(fill examples/fill.cpp)
  59. target_link_libraries(fill PRIVATE matplotlib_cpp)
  60. set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  61. add_executable(update examples/update.cpp)
  62. target_link_libraries(update PRIVATE matplotlib_cpp)
  63. set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  64. add_executable(subplot2grid examples/subplot2grid.cpp)
  65. target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
  66. set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  67. add_executable(lines3d examples/lines3d.cpp)
  68. target_link_libraries(lines3d PRIVATE matplotlib_cpp)
  69. set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  70. if(Python3_NumPy_FOUND)
  71. add_executable(surface examples/surface.cpp)
  72. target_link_libraries(surface PRIVATE matplotlib_cpp)
  73. set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  74. add_executable(colorbar examples/colorbar.cpp)
  75. target_link_libraries(colorbar PRIVATE matplotlib_cpp)
  76. set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  77. endif()
  78. # Install headers
  79. install(FILES
  80. "${PROJECT_SOURCE_DIR}/matplotlibcpp.h"
  81. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  82. # Install targets file
  83. install(EXPORT install_targets
  84. FILE
  85. ${PACKAGE_NAME}Targets.cmake
  86. NAMESPACE
  87. ${PACKAGE_NAME}::
  88. DESTINATION
  89. ${INSTALL_CONFIGDIR}
  90. )
  91. # Install matplotlib_cppConfig.cmake
  92. include(CMakePackageConfigHelpers)
  93. configure_package_config_file(
  94. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PACKAGE_NAME}Config.cmake.in
  95. ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
  96. INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
  97. )
  98. install(FILES
  99. ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
  100. DESTINATION ${INSTALL_CONFIGDIR}
  101. )