Skip to content

Revert "Remove libbsd dependency for Linux" #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ check_function_exists(strlcpy HAVE_STRLCPY)
check_function_exists(sysconf HAVE_SYSCONF)
check_function_exists(arc4random HAVE_ARC4RANDOM)

if(NOT HAVE_STRLCPY AND NOT HAVE_GETPROGNAME)
include(FindPkgConfig)
pkg_check_modules(BSD_OVERLAY libbsd-overlay)
if(BSD_OVERLAY_FOUND)
set(HAVE_STRLCPY 1 CACHE INTERNAL "Have function strlcpy" FORCE)
set(HAVE_GETPROGNAME 1 CACHE INTERNAL "Have function getprogname" FORCE)
endif()
endif()

find_package(Threads REQUIRED)

check_include_files("TargetConditionals.h" HAVE_TARGETCONDITIONALS_H)
Expand Down
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
PRIVATE
-U_GNU_SOURCE)
endif()
if(BSD_OVERLAY_FOUND)
target_compile_options(dispatch
PRIVATE
${BSD_OVERLAY_CFLAGS})
endif()
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(dispatch
PRIVATE
Expand All @@ -226,6 +231,9 @@ else()
-fblocks
-momit-leaf-frame-pointer)
endif()
if(BSD_OVERLAY_FOUND)
target_link_libraries(dispatch PRIVATE ${BSD_OVERLAY_LDFLAGS})
endif()
if(LibRT_FOUND)
target_link_libraries(dispatch PRIVATE RT::rt)
endif()
Expand Down
4 changes: 1 addition & 3 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ upcast(dispatch_object_t dou)
#include <linux/sysctl.h>
#else
#include <sys/sysctl.h>
#endif /* __ANDROID__ */
#if !defined(__linux__)
#include <sys/queue.h>
#endif
#endif /* __ANDROID__ */
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/mman.h>
Expand Down
2 changes: 1 addition & 1 deletion src/shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "shims/generic_win_stubs.h"
#endif // defined(_WIN32)

#if defined(_WIN32) || defined(__linux__)
#if defined(_WIN32) || defined(__ANDROID__)
#include "shims/generic_sys_queue.h"
#endif

Expand Down
29 changes: 27 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ target_include_directories(bsdtests
PUBLIC
# bsdtests.h needs config_ac.h
${PROJECT_BINARY_DIR})
if(BSD_OVERLAY_FOUND)
target_compile_options(bsdtests
PRIVATE
${BSD_OVERLAY_CFLAGS})
endif()
if (WIN32)
target_sources(bsdtests
PRIVATE
Expand All @@ -53,13 +58,23 @@ target_include_directories(bsdtestharness
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR})
if(BSD_OVERLAY_FOUND)
target_compile_options(bsdtestharness
PRIVATE
${BSD_OVERLAY_CFLAGS})
endif()
target_link_libraries(bsdtestharness
PRIVATE
bsdtests
dispatch)
if(BSD_OVERLAY_FOUND)
target_link_libraries(bsdtestharness
PRIVATE
${BSD_OVERLAY_LDFLAGS})
endif()

function(add_unit_test name)
set(options DISABLED_TEST)
set(options DISABLED_TEST;NO_BSD_OVERLAY)
set(single_value_args)
set(multiple_value_args SOURCES)
cmake_parse_arguments(AUT "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
Expand All @@ -82,6 +97,11 @@ function(add_unit_test name)
target_include_directories(${name}
SYSTEM BEFORE PRIVATE
"${BlocksRuntime_INCLUDE_DIR}")
if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
target_compile_options(${name}
PRIVATE
${BSD_OVERLAY_CFLAGS})
endif()
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(${name} PRIVATE -Xclang -fblocks)
target_compile_options(${name} PRIVATE /W3 -Wno-deprecated-declarations)
Expand All @@ -95,6 +115,11 @@ function(add_unit_test name)
dispatch
Threads::Threads
BlocksRuntime::BlocksRuntime)
if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
target_link_libraries(${name}
PRIVATE
${BSD_OVERLAY_LDFLAGS})
endif()
target_link_libraries(${name} PRIVATE bsdtests)
add_test(NAME ${name}
COMMAND bsdtestharness $<TARGET_FILE:${name}>)
Expand Down Expand Up @@ -174,7 +199,7 @@ endforeach()
set_tests_properties(dispatch_io_pipe_close PROPERTIES TIMEOUT 5)

# test dispatch API for various C/CXX language variants
add_unit_test(dispatch_c99 SOURCES dispatch_c99.c)
add_unit_test(dispatch_c99 NO_BSD_OVERLAY SOURCES dispatch_c99.c)
add_unit_test(dispatch_plusplus SOURCES dispatch_plusplus.cpp)

# test-specific link options
Expand Down