ref: 38d4fd5d16056cc02274c8718bc23169b9d5ba55
parent: 4147f3afe8d9a9801d87713a544faa81d526e239
author: Ralph Giles <giles@thaumas.net>
date: Fri Aug 8 04:53:24 EDT 2025
cmake: add -lsocket if necessary On OpenIndiana (Illumos) the cmake build fails with indirect symbol references to functions declared by `sys/socket.h`. To address this, check for `getsockopt` linkage, and if it fails try again with `-lsocket` which provides the symbols on that operating system. This doesn't seem to be necessary with the autotools build; perhaps libtool is passing something extra to the linker to have it accept the transitive dependencies. Fixes https://github.com/xiph/opusfile/issues/60 Fixes https://gitlab.xiph.org/xiph/opusfile/-/issues/2337
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,6 +103,13 @@
if(NOT OP_HAVE_SYS_SOCKET_H)
message(FATAL_ERROR "HTTP support requires a POSIX socket library")
endif()
+ check_symbol_exists(getsockopt "sys/socket.h" OP_HAVE_GETSOCKOPT)
+ if(NOT OP_HAVE_GETSOCKOPT)
+ cmake_push_check_state()
+ list(APPEND CMAKE_REQUIRED_LIBRARIES "socket")
+ check_symbol_exists(getsockopt "sys/socket.h" OP_NEED_SOCKET)
+ cmake_pop_check_state()
+ endif()
endif()
check_c_source_compiles(
"#include <time.h>
@@ -164,6 +171,7 @@
$<$<C_COMPILER_ID:MSVC>:ws2_32>
$<$<C_COMPILER_ID:MSVC>:crypt32>
$<$<BOOL:${OP_HAVE_LIBM}>:m>
+ $<$<BOOL:${OP_NEED_SOCKET}>:socket>
)
target_compile_options(opusurl
PRIVATE
--
⑨