forked from eclipse-zenoh/zenoh-pico
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
291 lines (244 loc) · 9.91 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
#
# Copyright (c) 2017, 2020 ADLINK Technology Inc.
#
# 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:
# ADLINK zenoh team, <[email protected]>
#
cmake_minimum_required(VERSION 3.8)
project(libzenohpico VERSION 0.5.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}")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
if(NOT BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}")
if(NOT BUILD_TESTING)
set(BUILD_TESTING ON)
endif()
option (PACKAGING "Use option on Linux to produce Debian and RPM packages." OFF)
option (EXAMPLES "Use this to also build the examples." ON)
option (SWIG_JAVA "Use this to build the zenohpico_java library, assuming the Swig generated C files in zenoh-pico/src/ ." OFF)
# Configure the transport to use with the following variables
set (ZENOH_TRANSPORT_TCP "ON")
set (ZENOH_TRANSPORT_UDP "OFF")
set (ZENOH_TRANSPORT_BLE "OFF")
set (ZENOH_TRANSPORT_I2C "OFF")
# Use cmake .. -DCMAKE_BUILD_TYPE=Debug for debug / Release
# Configure the debug level
#
# ZENOH_DEBUG :
# - 2 : ERROR + DEBUG
# - 1 : ERROR
# - 0 : NOTHING
if (DEFINED ZENOH_DEBUG)
set(ZENOH_DEBUG_OPT "-DZENOH_DEBUG=${ZENOH_DEBUG}")
else()
set(ZENOH_DEBUG_OPT "-DZENOH_DEBUG=1")
endif()
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()
if (SKBUILD)
set(INSTALL_RPATH "zenoh")
set(INSTALL_NAME_DIR "zenoh")
set(INSTALL_INCLUDE_NAME_DIR "zenoh/include")
endif()
if (ZENOH_TRANSPORT_TCP STREQUAL "ON")
set (ZENOH_TRANSPORT_OPT "-DZENOH_TRANSPORT_TCP_IP")
endif()
if (ZENOH_TRANSPORT_UDP STREQUAL "ON")
set (ZENOH_TRANSPORT_OPT "${ZENOH_TRANSPORT_OPT} -DZENOH_TRANSPORT_UDP_IP")
endif()
if (ZENOH_TRANSPORT_BLE STREQUAL "ON")
set (ZENOH_TRANSPORT_OPT "${ZENOH_TRANSPORT_OPT} -DZENOH_TRANSPORT_BLE")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DNDEBUG)
else()
add_definitions(${ZENOH_DEBUG_OPT} -DZENOH_DEBUG=1)
endif()
add_compile_options(
$<$<CONFIG:RELEASE>:-pipe -O3>
$<$<CONFIG:DEBUG>:-Wall -Wextra -Werror -Wpedantic -Wunused -Wstrict-prototypes -pipe -g -O0>
)
endif()
if (NOT SWIG_JAVA)
set(Libname "zenohpico")
file(GLOB PublicHeaders "include/*.h" "include/zenoh/*.h" "include/zenoh/net/*.h")
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include/net
)
else()
set(Libname "zenohpico_java")
if (NOT JNI_INCLUDE_HOME)
message(STATUS "Looking for local JDK with JNI")
find_package(JNI REQUIRED)
else()
message(STATUS "Using JNI headers from ${JNI_INCLUDE_HOME}")
get_filename_component(JNI_INCL_PATH1 "${JNI_INCLUDE_HOME}" ABSOLUTE)
get_filename_component(JNI_INCL_PATH2 "${JNI_INCLUDE_HOME}/${JNI_PLATFORM_NAME}" ABSOLUTE)
set(JNI_INCLUDE_DIRS "${JNI_INCL_PATH1};${JNI_INCL_PATH2}")
endif()
message(STATUS "Using JNI include paths: ${JNI_INCLUDE_DIRS}")
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include/net
${JNI_INCLUDE_DIRS}
)
endif()
if (UNIX)
file(GLOB Sources "src/*.c" "src/net/*.c" "src/net/unix/*.c")
endif()
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/libs)
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()
if (NOT SWIG_JAVA)
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
)
endif()
if (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_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_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(EXAMPLES)
if(BUILD_TESTING)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_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)
add_executable(zn_client_test ${PROJECT_SOURCE_DIR}/tests/zn_client_test.c)
add_executable(zn_msgcodec_test ${PROJECT_SOURCE_DIR}/tests/zn_msgcodec_test.c)
target_link_libraries(z_iobuf_test ${Libname})
target_link_libraries(z_data_struct_test ${Libname})
target_link_libraries(z_mvar_test ${Libname})
target_link_libraries(zn_rname_test ${Libname})
target_link_libraries(zn_client_test ${Libname})
target_link_libraries(zn_msgcodec_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)
add_test(z_iobuf_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_iobuf_test)
add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)
add_test(zn_rname_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/zn_rname_test)
add_test(zn_msgcodec_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/zn_msgcodec_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()