forked from eclipse-zenoh/zenoh-pico
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
297 lines (245 loc) · 11 KB
/
CMakeLists.txt
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#
# Copyright (c) 2022 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
cmake_minimum_required(VERSION 3.8)
project(libzenohpico VERSION 0.6.0 LANGUAGES C)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# while in development, use timestamp for patch version:
string(TIMESTAMP PROJECT_VERSION_PATCH "%Y%m%ddev")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# Use cmake .. -DCMAKE_BUILD_TYPE=DEBUG for debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}")
option (PACKAGING "Use option on Linux to produce Debian and RPM packages." OFF)
message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
option (BUILD_EXAMPLES "Use this to also build the examples." ON)
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
option (BUILD_TESTING "Use this to also build tests." ON)
message(STATUS "Build tests: ${BUILD_TESTING}")
option (BUILD_INTEGRATION "Use this to also build integration tests." OFF)
message(STATUS "Build integration: ${BUILD_INTEGRATION}")
option (ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0)
message(STATUS "Zenoh Level Log: ${ZENOH_DEBUG}")
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DZENOH_LINUX)
set(JNI_PLATFORM_NAME "linux")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions(-DZENOH_MACOS)
set(MACOSX_RPATH "ON")
set(JNI_PLATFORM_NAME "darwin")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
message(FATAL_ERROR "zenoh-pico is not yet available on Windows platform")
add_definitions(-DZENOH_WIN)
set(JNI_PLATFORM_NAME "win32")
endif()
add_definitions(-DZENOH_DEBUG=${ZENOH_DEBUG})
if (SKBUILD)
set(INSTALL_RPATH "zenoh")
set(INSTALL_NAME_DIR "zenoh")
set(INSTALL_INCLUDE_NAME_DIR "zenoh/include")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
add_compile_options(-c -Wall -Wextra -Werror -Wunused -Wstrict-prototypes -pipe -g -O0)
elseif (CMAKE_BUILD_TYPE MATCHES "RELEASE")
add_compile_options(-pipe -O3)
endif()
set(Libname "zenohpico")
file(GLOB PublicHeaders "include/*.h"
"include/zenoh-pico/*.h"
"include/zenoh-pico/api/*.h"
"include/zenoh-pico/collections/*.h"
"include/zenoh-pico/link/*.h"
"include/zenoh-pico/link/config/*.h"
"include/zenoh-pico/protocol/*.h"
"include/zenoh-pico/session/*.h"
"include/zenoh-pico/system/*.h"
"include/zenoh-pico/system/link/*.h"
"include/zenoh-pico/transport/*.h"
"include/zenoh-pico/utils/*.h"
)
include_directories(
${PROJECT_SOURCE_DIR}/include
)
if (UNIX)
file(GLOB Sources "src/*.c"
"src/api/*.c"
"src/collections/*.c"
"src/link/*.c"
"src/link/config/*.c"
"src/link/unicast/*.c"
"src/link/multicast/*.c"
"src/protocol/*.c"
"src/session/*.c"
"src/system/*.c"
"src/system/unix/*.c"
"src/transport/*.c"
"src/transport/common/*.c"
"src/transport/unicast/*.c"
"src/transport/unicast/link/*.c"
"src/transport/unicast/link/task/*.c"
"src/transport/multicast/*.c"
"src/transport/multicast/link/*.c"
"src/transport/multicast/link/task/*.c"
)
endif()
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
link_directories(${LIBRARY_OUTPUT_PATH})
add_library(${Libname} ${Sources})
target_link_libraries(${Libname} Threads::Threads)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${Libname} rt)
endif()
install(TARGETS ${Libname}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT Library
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico.h
DESTINATION include
COMPONENT Headers
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico
DESTINATION include
COMPONENT Headers
)
if (BUILD_EXAMPLES)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
add_executable(zn_write ${PROJECT_SOURCE_DIR}/examples/net/zn_write.c)
add_executable(zn_pub ${PROJECT_SOURCE_DIR}/examples/net/zn_pub.c)
add_executable(zn_sub ${PROJECT_SOURCE_DIR}/examples/net/zn_sub.c)
add_executable(zn_peer_sub ${PROJECT_SOURCE_DIR}/examples/net/zn_peer_sub.c)
add_executable(zn_peer_pub ${PROJECT_SOURCE_DIR}/examples/net/zn_peer_pub.c)
add_executable(zn_pull ${PROJECT_SOURCE_DIR}/examples/net/zn_pull.c)
add_executable(zn_query ${PROJECT_SOURCE_DIR}/examples/net/zn_query.c)
add_executable(zn_eval ${PROJECT_SOURCE_DIR}/examples/net/zn_eval.c)
add_executable(zn_info ${PROJECT_SOURCE_DIR}/examples/net/zn_info.c)
add_executable(zn_pub_thr ${PROJECT_SOURCE_DIR}/examples/net/zn_pub_thr.c)
add_executable(zn_sub_thr ${PROJECT_SOURCE_DIR}/examples/net/zn_sub_thr.c)
add_executable(zn_scout ${PROJECT_SOURCE_DIR}/examples/net/zn_scout.c)
target_link_libraries(zn_write ${Libname})
target_link_libraries(zn_pub ${Libname})
target_link_libraries(zn_sub ${Libname})
target_link_libraries(zn_peer_sub ${Libname})
target_link_libraries(zn_peer_pub ${Libname})
target_link_libraries(zn_pull ${Libname})
target_link_libraries(zn_query ${Libname})
target_link_libraries(zn_eval ${Libname})
target_link_libraries(zn_info ${Libname})
target_link_libraries(zn_pub_thr ${Libname})
target_link_libraries(zn_sub_thr ${Libname})
target_link_libraries(zn_scout ${Libname})
endif()
if(BUILD_TESTING)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
add_executable(z_endpoint_test ${PROJECT_SOURCE_DIR}/tests/z_endpoint_test.c)
add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
add_executable(zn_msgcodec_test ${PROJECT_SOURCE_DIR}/tests/zn_msgcodec_test.c)
add_executable(z_mvar_test ${PROJECT_SOURCE_DIR}/tests/z_mvar_test.c)
add_executable(zn_rname_test ${PROJECT_SOURCE_DIR}/tests/zn_rname_test.c)
target_link_libraries(z_data_struct_test ${Libname})
target_link_libraries(z_endpoint_test ${Libname})
target_link_libraries(z_iobuf_test ${Libname})
target_link_libraries(zn_msgcodec_test ${Libname})
target_link_libraries(z_mvar_test ${Libname})
target_link_libraries(zn_rname_test ${Libname})
enable_testing()
add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)
add_test(z_endpoint_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_endpoint_test)
add_test(z_iobuf_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_iobuf_test)
add_test(zn_msgcodec_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/zn_msgcodec_test)
add_test(zn_rname_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/zn_rname_test)
endif()
if(BUILD_MULTICAST)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_executable(zn_peer_multicast_test ${PROJECT_SOURCE_DIR}/tests/zn_peer_multicast_test.c)
target_link_libraries(zn_peer_multicast_test ${Libname})
configure_file(${PROJECT_SOURCE_DIR}/tests/multicast.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh COPYONLY)
enable_testing()
add_test(zn_client_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh zn_peer_multicast_test)
endif()
if(BUILD_INTEGRATION)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_executable(zn_client_test ${PROJECT_SOURCE_DIR}/tests/zn_client_test.c)
target_link_libraries(zn_client_test ${Libname})
configure_file(${PROJECT_SOURCE_DIR}/tests/routed.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh COPYONLY)
enable_testing()
add_test(zn_client_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh zn_client_test)
endif()
# For packaging
if (PACKAGING)
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages")
set(CPACK_COMPONENTS_ALL Library Headers)
set(CPACK_COMPONENT_LIBRARY_GROUP "lib")
set(CPACK_COMPONENT_HEADERS_GROUP "dev")
set(CPACK_COMPONENT_HEADERS_DEPENDS Library)
set(CPACK_PACKAGE_CHECKSUM MD5)
set(CPACK_PACKAGE_VENDOR "The Eclipse Foundation")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_COMPONENT_LIB_DESCRIPTION "The C client library for Eclipse zenoh targeting pico devices")
set(CPACK_COMPONENT_DEV_DESCRIPTION "${CPACK_COMPONENT_LIB_DESCRIPTION} - devel files")
# Sources package
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES "/.git/;/.github/;/build/;/crossbuilds/")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-src-${PROJECT_VERSION}")
if(PACKAGING MATCHES "DEB")
if(NOT DEBARCH)
set(DEBARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()
message(STATUS "Configure DEB packaging for Linux ${DEBARCH}")
if(CPACK_GENERATOR)
set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
else()
set(CPACK_GENERATOR "DEB")
endif()
# DEB package
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ADLINK zenoh team, <[email protected]>")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEBARCH})
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_LIB_PACKAGE_NAME ${PROJECT_NAME}) # avoid "-lib" suffix for "lib" package
set(CPACK_DEBIAN_LIB_PACKAGE_DEPENDS "libc6 (>=2.12)")
set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "${CPACK_DEBIAN_LIB_PACKAGE_NAME} (=${PROJECT_VERSION})")
endif()
if(PACKAGING MATCHES "RPM")
if(NOT RPMARCH)
set(RPMARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()
message(STATUS "Configure RPM packaging for Linux ${RPMARCH}")
if(CPACK_GENERATOR)
set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
else()
set(CPACK_GENERATOR "RPM")
endif()
# RPM package
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${RPMARCH})
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_LIB_PACKAGE_NAME ${PROJECT_NAME}) # avoid "-lib" suffix for "lib" package
set(CPACK_RPM_DEV_PACKAGE_REQUIRES "${CPACK_RPM_LIB_PACKAGE_NAME} = ${PROJECT_VERSION}")
endif()
include(CPack)
endif()