|
1 | 1 | cmake_minimum_required(VERSION 3.15)
|
2 |
| -project(FoxgloveWebSocket CXX) |
| 2 | +project(FoxgloveWebSocket VERSION 0.0.1 LANGUAGES CXX) |
3 | 3 |
|
4 | 4 | find_package(nlohmann_json REQUIRED)
|
5 | 5 | find_package(websocketpp REQUIRED)
|
6 | 6 |
|
7 |
| -add_library(foxglove_websocket src/base64.cpp src/parameter.cpp src/serialization.cpp src/server_factory.cpp) |
| 7 | +add_library(foxglove_websocket STATIC src/base64.cpp src/parameter.cpp src/serialization.cpp src/server_factory.cpp) |
| 8 | +add_library(foxglove-websocket::foxglove-websocket ALIAS foxglove_websocket) |
| 9 | + |
| 10 | +# Separate SYSTEM include directories from other include directories |
| 11 | +target_include_directories(foxglove_websocket |
| 12 | + PUBLIC |
| 13 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 14 | + $<INSTALL_INTERFACE:include> |
| 15 | +) |
| 16 | + |
8 | 17 | target_include_directories(foxglove_websocket
|
9 |
| - PUBLIC include |
10 |
| - SYSTEM |
11 |
| - ${nlohmann_json_INCLUDE_DIRS} |
12 |
| - ${websocketpp_INCLUDE_DIRS} |
| 18 | + SYSTEM PUBLIC |
| 19 | + ${nlohmann_json_INCLUDE_DIRS} |
| 20 | + ${websocketpp_INCLUDE_DIRS} |
| 21 | +) |
| 22 | + |
| 23 | +target_link_libraries(foxglove_websocket |
| 24 | + PUBLIC |
| 25 | + nlohmann_json::nlohmann_json |
| 26 | + websocketpp::websocketpp |
| 27 | +) |
| 28 | + |
| 29 | +set_target_properties(foxglove_websocket PROPERTIES |
| 30 | + CXX_STANDARD 17 |
| 31 | + CXX_STANDARD_REQUIRED ON |
13 | 32 | )
|
14 |
| -target_link_libraries(foxglove_websocket nlohmann_json::nlohmann_json websocketpp::websocketpp) |
15 |
| -set_target_properties(foxglove_websocket PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) |
16 | 33 |
|
17 | 34 | if (MSVC)
|
18 | 35 | target_compile_options(foxglove_websocket PRIVATE /W4)
|
19 | 36 | else()
|
20 | 37 | target_compile_options(foxglove_websocket PRIVATE -Wall -Wextra -Wpedantic -Wold-style-cast -Wfloat-equal)
|
21 | 38 | endif()
|
22 | 39 |
|
23 |
| -install(TARGETS foxglove_websocket) |
24 |
| -INSTALL (DIRECTORY ${CMAKE_SOURCE_DIR}/include/ |
25 |
| - DESTINATION include) |
26 |
| -install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${CMAKE_INSTALL_PREFIX}/licenses/) |
| 40 | +# Installation |
| 41 | +include(GNUInstallDirs) |
| 42 | + |
| 43 | +install(TARGETS foxglove_websocket |
| 44 | + EXPORT foxglove_websocketTargets |
| 45 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 46 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 47 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # For Windows DLLs |
| 48 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 49 | +) |
| 50 | + |
| 51 | +install(DIRECTORY include/ |
| 52 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 53 | +) |
| 54 | + |
| 55 | +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE |
| 56 | + DESTINATION ${CMAKE_INSTALL_PREFIX}/licenses/ |
| 57 | +) |
| 58 | + |
| 59 | +# Export the targets to a file |
| 60 | +install(EXPORT foxglove_websocketTargets |
| 61 | + FILE foxglove_websocketTargets.cmake |
| 62 | + NAMESPACE foxglove-websocket:: |
| 63 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/foxglove_websocket |
| 64 | +) |
| 65 | + |
| 66 | +# Create a version file |
| 67 | +include(CMakePackageConfigHelpers) |
| 68 | +write_basic_package_version_file( |
| 69 | + "${CMAKE_CURRENT_BINARY_DIR}/foxglove_websocketConfigVersion.cmake" |
| 70 | + VERSION ${PROJECT_VERSION} |
| 71 | + COMPATIBILITY AnyNewerVersion |
| 72 | +) |
| 73 | + |
| 74 | +# Config file |
| 75 | +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/foxglove_websocketConfig.cmake.in |
| 76 | + "${CMAKE_CURRENT_BINARY_DIR}/foxglove_websocketConfig.cmake" |
| 77 | + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/foxglove_websocket |
| 78 | +) |
| 79 | + |
| 80 | +# Install the config files |
| 81 | +install(FILES |
| 82 | + "${CMAKE_CURRENT_BINARY_DIR}/foxglove_websocketConfig.cmake" |
| 83 | + "${CMAKE_CURRENT_BINARY_DIR}/foxglove_websocketConfigVersion.cmake" |
| 84 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/foxglove_websocket |
| 85 | +) |
| 86 | + |
| 87 | +# Export from the build tree |
| 88 | +export(EXPORT foxglove_websocketTargets |
| 89 | + FILE "${CMAKE_CURRENT_BINARY_DIR}/foxglove_websocketTargets.cmake" |
| 90 | + NAMESPACE foxglove-websocket:: |
| 91 | +) |
| 92 | +export(PACKAGE foxglove_websocket) |
0 commit comments