Skip to content

Commit

Permalink
fixup! cmake: Check system symbols
Browse files Browse the repository at this point in the history
Fix configuration for Illumos/SmartOS.
  • Loading branch information
hebasto committed Jun 11, 2024
1 parent 8975005 commit 074d3c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
8 changes: 2 additions & 6 deletions cmake/introspection.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ endif()
check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
check_include_file_cxx(ifaddrs.h HAVE_IFADDRS_H)
if(HAVE_SYS_TYPES_H AND HAVE_IFADDRS_H)
check_cxx_symbol_exists(freeifaddrs "sys/types.h;ifaddrs.h" HAVE_DECL_FREEIFADDRS)
check_cxx_symbol_exists(getifaddrs "sys/types.h;ifaddrs.h" HAVE_DECL_GETIFADDRS)
if(HAVE_DECL_GETIFADDRS AND HAVE_DECL_FREEIFADDRS)
include(TestAppendRequiredLibraries)
test_append_socket_library(core_interface)
endif()
include(TestAppendRequiredLibraries)
test_append_socket_library(core_interface)
endif()

include(TestAppendRequiredLibraries)
Expand Down
22 changes: 12 additions & 10 deletions cmake/module/TestAppendRequiredLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ include_guard(GLOBAL)

# Illumos/SmartOS requires linking with -lsocket if
# using getifaddrs & freeifaddrs.
# See: https://github.com/bitcoin/bitcoin/pull/21486
# See:
# - https://github.com/bitcoin/bitcoin/pull/21486
# - https://smartos.org/man/3socket/getifaddrs
function(test_append_socket_library target)
if (NOT TARGET ${target})
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() called with non-existent target \"${target}\".")
Expand All @@ -25,16 +27,16 @@ function(test_append_socket_library target)

include(CheckSourceCompilesAndLinks)
check_cxx_source_links("${check_socket_source}" IFADDR_LINKS_WITHOUT_LIBSOCKET)
if(IFADDR_LINKS_WITHOUT_LIBSOCKET)
return()
endif()

check_cxx_source_links_with_libs(socket "${check_socket_source}" IFADDR_NEEDS_LINK_TO_LIBSOCKET)
if(IFADDR_NEEDS_LINK_TO_LIBSOCKET)
target_link_libraries(${target} INTERFACE socket)
else()
message(FATAL_ERROR "Cannot figure out how to use getifaddrs/freeifaddrs.")
if(NOT IFADDR_LINKS_WITHOUT_LIBSOCKET)
check_cxx_source_links_with_libs(socket "${check_socket_source}" IFADDR_NEEDS_LINK_TO_LIBSOCKET)
if(IFADDR_NEEDS_LINK_TO_LIBSOCKET)
target_link_libraries(${target} INTERFACE socket)
else()
message(FATAL_ERROR "Cannot figure out how to use getifaddrs/freeifaddrs.")
endif()
endif()
set(HAVE_DECL_GETIFADDRS TRUE PARENT_SCOPE)
set(HAVE_DECL_FREEIFADDRS TRUE PARENT_SCOPE)
endfunction()

# Clang, when building for 32-bit,
Expand Down

0 comments on commit 074d3c2

Please sign in to comment.