-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
137 lines (130 loc) · 4.05 KB
/
Copy pathCMakeLists.txt
File metadata and controls
137 lines (130 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
cmake_minimum_required(VERSION 3.22)
project(
waterlinkedsonar
VERSION 0.1.0
LANGUAGES CXX
DESCRIPTION "C++ client library for the Water Linked Sonar 3D-15"
HOMEPAGE_URL "https://github.com/BumblebeeAS/waterlinkedsonar"
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
option(
WATERLINKEDSONAR_BUILD_EXAMPLES
"Build the example programs"
${PROJECT_IS_TOP_LEVEL}
)
if(PROJECT_IS_TOP_LEVEL)
include(CTest)
endif()
# Protobuf >= 4.22 links against Abseil, and only protobuf's own config
# package declares that dependency; CMake's FindProtobuf module hands out a
# bare protobuf::libprotobuf that fails to link against it. Prefer config
# mode and fall back to the module for the pre-4.x protobuf that Ubuntu ships.
find_package(Protobuf CONFIG QUIET)
if(NOT Protobuf_FOUND)
find_package(Protobuf MODULE REQUIRED)
endif()
find_package(CURL REQUIRED)
find_package(Snappy REQUIRED)
find_package(ZLIB REQUIRED)
find_package(nlohmann_json REQUIRED)
set(proto_file
${CMAKE_CURRENT_SOURCE_DIR}/proto/WaterLinkedSonarIntegrationProtocol.proto
)
set(proto_out_dir ${CMAKE_CURRENT_BINARY_DIR}/generated)
set(proto_gen_cc ${proto_out_dir}/WaterLinkedSonarIntegrationProtocol.pb.cc)
set(proto_gen_h ${proto_out_dir}/WaterLinkedSonarIntegrationProtocol.pb.h)
add_custom_command(
OUTPUT ${proto_gen_cc} ${proto_gen_h}
COMMAND ${CMAKE_COMMAND} -E make_directory ${proto_out_dir}
COMMAND
protobuf::protoc --cpp_out=${proto_out_dir} -I
${CMAKE_CURRENT_SOURCE_DIR}/proto ${proto_file}
DEPENDS ${proto_file}
COMMENT "Generating protobuf sources"
)
# Tests that construct protobuf messages depend on this target so the
# generated header exists before their objects compile.
add_custom_target(
waterlinkedsonar_proto_gen
DEPENDS ${proto_gen_cc} ${proto_gen_h}
)
add_library(waterlinkedsonar SHARED)
add_library(waterlinkedsonar::waterlinkedsonar ALIAS waterlinkedsonar)
target_sources(
waterlinkedsonar
PRIVATE
src/client.cpp
src/conversions.cpp
src/curl_transport.cpp
src/receiver.cpp
src/rip.cpp
src/semver.cpp
src/sntp.cpp
src/types.cpp
src/udp_socket.cpp
${proto_gen_cc}
)
target_include_directories(
waterlinkedsonar
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${proto_out_dir}
)
target_compile_features(waterlinkedsonar PUBLIC cxx_std_17)
target_compile_options(
waterlinkedsonar
PRIVATE $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall;-Wextra;-Wpedantic>
)
target_link_libraries(
waterlinkedsonar
PRIVATE
protobuf::libprotobuf
CURL::libcurl
Snappy::snappy
ZLIB::ZLIB
nlohmann_json::nlohmann_json
)
set_target_properties(
waterlinkedsonar
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
)
install(
TARGETS waterlinkedsonar
EXPORT waterlinkedsonarTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
)
install(
EXPORT waterlinkedsonarTargets
NAMESPACE waterlinkedsonar::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/waterlinkedsonar
)
configure_package_config_file(
cmake/waterlinkedsonarConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/waterlinkedsonarConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/waterlinkedsonar
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/waterlinkedsonarConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/waterlinkedsonarConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/waterlinkedsonarConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/waterlinkedsonar
)
if(WATERLINKEDSONAR_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
add_subdirectory(test)
endif()