|
2 | 2 | # Licensed under and subject to the terms of the LICENSE file accompanying this distribution. |
3 | 3 | # Official repository: https://github.com/jimmyorourke/plotlypp |
4 | 4 |
|
5 | | -cmake_minimum_required(VERSION 3.13) |
6 | | -project(plotlypp LANGUAGES CXX) |
| 5 | +cmake_minimum_required(VERSION 3.14) |
| 6 | +project(plotlypp VERSION 0.1.0 LANGUAGES CXX) |
7 | 7 |
|
8 | 8 | set(MAIN_PROJECT OFF) |
9 | 9 | if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
@@ -33,22 +33,69 @@ else() |
33 | 33 | include(FetchContent) |
34 | 34 |
|
35 | 35 | set(FETCHCONTENT_BASE_DIR ${PLOTLYPP_FETCH_CONTENT_DIR}) |
| 36 | + # Enable nlohmann::json install targets. Otherwise the plotlypp install targets complain the "local" dependency |
| 37 | + # is not being exported. |
| 38 | + set(JSON_Install ON) |
36 | 39 | FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) |
37 | 40 | FetchContent_MakeAvailable(json) |
38 | 41 | endif() |
39 | 42 | set(JSON_TARGET nlohmann_json::nlohmann_json) |
40 | 43 |
|
41 | 44 | add_library(plotlypp INTERFACE) |
42 | | -# Add a namespaced alias |
| 45 | +# Add a namespaced alias for in-tree users. |
43 | 46 | add_library(plotlypp::plotlypp ALIAS plotlypp) |
| 47 | + |
44 | 48 | target_link_libraries(plotlypp INTERFACE ${JSON_TARGET}) |
| 49 | + |
45 | 50 | target_include_directories(plotlypp INTERFACE |
46 | 51 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
47 | 52 | $<INSTALL_INTERFACE:include> |
48 | 53 | ) |
| 54 | + |
49 | 55 | # Require at least C++17. Depending executables can override with a newer version. |
50 | 56 | target_compile_features(plotlypp INTERFACE cxx_std_17) |
51 | 57 |
|
| 58 | +include(GNUInstallDirs) |
| 59 | +include(CMakePackageConfigHelpers) |
| 60 | + |
| 61 | +# Install headers. |
| 62 | +install(DIRECTORY include/plotlypp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 63 | + |
| 64 | +# Register the target with the export set. |
| 65 | +install(TARGETS plotlypp |
| 66 | + EXPORT ${PROJECT_NAME}Targets |
| 67 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 68 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 69 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 70 | +) |
| 71 | + |
| 72 | +# Install/generate the cmake file for rebuilding the export set targets. |
| 73 | +install(EXPORT ${PROJECT_NAME}Targets |
| 74 | + FILE ${PROJECT_NAME}Targets.cmake |
| 75 | + NAMESPACE ${PROJECT_NAME}:: |
| 76 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} |
| 77 | +) |
| 78 | + |
| 79 | +# Write the find package config file. |
| 80 | +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 81 | +"include(CMakeFindDependencyMacro) |
| 82 | +find_dependency(nlohmann_json) |
| 83 | +include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")" |
| 84 | +) |
| 85 | + |
| 86 | +# Write the find package version file. |
| 87 | +write_basic_package_version_file( |
| 88 | + ${PROJECT_NAME}ConfigVersion.cmake |
| 89 | + VERSION ${PROJECT_VERSION} |
| 90 | + COMPATIBILITY AnyNewerVersion |
| 91 | +) |
| 92 | + |
| 93 | +# Install find package config files. |
| 94 | +install(FILES |
| 95 | + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake |
| 96 | + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
| 97 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} |
| 98 | +) |
52 | 99 |
|
53 | 100 | if(PLOTLYPP_BUILD_EXAMPLES) |
54 | 101 | add_subdirectory(examples) |
|
0 commit comments