Skip to content

Commit

Permalink
Add POSIX target for small posix based RTOS's i.e. NuttX
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervdPerk-NXP committed Apr 25, 2023
1 parent e9165d1 commit ef41809
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.13)

project(libzenohpico VERSION 0.7.0.1 LANGUAGES C)

Expand Down Expand Up @@ -63,6 +63,9 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definition(ZENOH_LINUX)
set(CHECK_THREADS "ON")
elseif(POSIX_COMPATIBLE)
add_definition(ZENOH_LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "BSD")
add_definition(ZENOH_BSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down Expand Up @@ -99,7 +102,9 @@ if(SKBUILD)
endif()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CHECK_THREADS)
find_package(Threads REQUIRED)
endif()

if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(UNIX)
Expand Down Expand Up @@ -160,7 +165,7 @@ file(GLOB Sources "src/*.c"
if(WITH_ZEPHYR)
file (GLOB Sources_Zephyr "src/system/zephyr/*.c")
list(APPEND Sources ${Sources_Zephyr})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
file (GLOB Sources_Unix "src/system/unix/*.c")
list(APPEND Sources ${Sources_Unix})
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
Expand All @@ -176,7 +181,9 @@ link_directories(${LIBRARY_OUTPUT_PATH})

target_sources(${Libname} PRIVATE ${Sources})

target_link_libraries(${Libname} Threads::Threads)
if(CHECK_THREADS)
target_link_libraries(${Libname} Threads::Threads)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${Libname} rt)
Expand All @@ -196,6 +203,7 @@ option(BUILD_EXAMPLES "Use this to also build the examples." ON)
option(BUILD_TOOLS "Use this to also build the tools." OFF)
option(BUILD_TESTING "Use this to also build tests." ON)
option(BUILD_INTEGRATION "Use this to also build integration tests." OFF)
option(CHECK_THREADS "Check Threads library" ON)

message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
Expand Down
2 changes: 2 additions & 0 deletions src/system/unix/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin
ret = _Z_ERR_GENERIC;
}

#ifndef UNIX_NO_MULTICAST_IF
if (lsockaddr->sa_family == AF_INET) {
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_fd, IPPROTO_IP, IP_MULTICAST_IF, &((struct sockaddr_in *)lsockaddr)->sin_addr,
Expand All @@ -331,6 +332,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin
} else {
ret = _Z_ERR_GENERIC;
}
#endif

// Create lep endpoint
if (ret == _Z_RES_OK) {
Expand Down

0 comments on commit ef41809

Please sign in to comment.