Skip to content

Commit

Permalink
Avoid pulling in sio.c that is not used by lwipovpn
Browse files Browse the repository at this point in the history
sio.c is problematic on FreeBSD (and OpenBSD).

Also add hacky workaround for OpenBSD to compile by ignoring macro
redefinitions.
  • Loading branch information
schwabe committed Sep 16, 2024
1 parent 0286b72 commit 07eb3e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
33 changes: 28 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,26 @@ set(LWIP_OVPN_INCLUDE_DIRS
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# Have a warning about missing FreeBSD support until the PR get merged and we update our submodule
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
message(INFO "Note for FreeBSD support manually apply/checkout https://github.com/lwip-tcpip/lwip/pull/46 to the lwip submodule")
# add a variant of lwipcontribportunix that does not include the probelmatic sio.c and to avoid pulling in unneeded sources
add_library(lwipcontribunixsys EXCLUDE_FROM_ALL ${lwipcontribportunix_SRCS})
target_include_directories(lwipcontribunixsys PRIVATE ${LWIP_INCLUDE_DIRS} ${LWIP_MBEDTLS_INCLUDE_DIRS})
target_compile_options(lwipcontribunixsys PRIVATE ${LWIP_COMPILER_FLAGS})
target_compile_definitions(lwipcontribunixsys PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_DEFINITIONS})
target_link_libraries(lwipcontribunixsys PUBLIC ${LWIP_MBEDTLS_LINK_LIBRARIES})
target_link_libraries(lwipcontribunixsys PUBLIC Threads::Threads)

# Avoid format specifies type 'unsigned long' but the argument has type 'clock_t' (aka 'int') warning
target_compile_options(lwipcontribunixsys PRIVATE -Wno-format)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_library(LIBUTIL util)
find_library(LIBRT rt)
target_link_libraries(lwipcontribunixsys PUBLIC ${LIBUTIL} ${LIBPTHREAD} ${LIBRT})
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(LIBUTIL util)
target_link_libraries(lwipcontribunixsys PUBLIC ${LIBUTIL})
endif()


Expand All @@ -72,5 +89,11 @@ target_compile_definitions(lwipovpn PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_D
if (NOT "${HAVE_ARC4RANDOM}")
target_compile_definitions(lwipovpn PRIVATE -DARC4RANDOM_MISSING)
endif()
target_link_libraries(lwipovpn PRIVATE ${LWIP_SANITIZER_LIBS} lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribportunix lwipcore lwipmbedtls)
target_link_libraries(lwipovpn PRIVATE Threads::Threads)
target_link_libraries(lwipovpn PRIVATE ${LWIP_SANITIZER_LIBS} lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribunixsys lwipcore lwipmbedtls)


# Ignore htons redefined error
if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_compile_options(lwipcontribunixsys PRIVATE -Wno-macro-redefined)
target_compile_options(lwipovpn PRIVATE -Wno-macro-redefined)
endif ()
7 changes: 1 addition & 6 deletions netif/unixaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <stdbool.h>


#include "lwip/opt.h"

#include "lwip/debug.h"
Expand All @@ -47,7 +43,6 @@
#include "lwip/snmp.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "netif/etharp.h"
#include "lwip/ethip6.h"

Expand Down
2 changes: 2 additions & 0 deletions netif/unixaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef LWIP_UNIXAF_H
#define LWIP_UNIXAF_H

#include <stdbool.h>

#include "lwip/netif.h"

#ifdef __cplusplus
Expand Down

0 comments on commit 07eb3e6

Please sign in to comment.