Skip to content

Commit d415fc3

Browse files
committed
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. Fixes #60
1 parent 4147f3a commit d415fc3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ if(NOT OP_DISABLE_HTTP)
103103
if(NOT OP_HAVE_SYS_SOCKET_H)
104104
message(FATAL_ERROR "HTTP support requires a POSIX socket library")
105105
endif()
106+
check_symbol_exists(getsockopt "sys/socket.h" OP_HAVE_GETSOCKOPT)
107+
if(NOT OP_HAVE_GETSOCKOPT)
108+
cmake_push_check_state()
109+
list(APPEND CMAKE_REQUIRED_LIBRARIES "socket")
110+
check_symbol_exists(getsockopt "sys/socket.h" OP_NEED_SOCKET)
111+
cmake_pop_check_state()
112+
endif()
106113
endif()
107114
check_c_source_compiles(
108115
"#include <time.h>
@@ -164,6 +171,7 @@ target_link_libraries(opusurl
164171
$<$<C_COMPILER_ID:MSVC>:ws2_32>
165172
$<$<C_COMPILER_ID:MSVC>:crypt32>
166173
$<$<BOOL:${OP_HAVE_LIBM}>:m>
174+
$<$<BOOL:${OP_NEED_SOCKET}>:socket>
167175
)
168176
target_compile_options(opusurl
169177
PRIVATE

0 commit comments

Comments
 (0)