Problem: CMAKE_REQUIRED_INCLUDES used in a wrong way, check_function_exists is problematic

Solution: use check_cxx_symbol_exists resp. check_type_size instead
This commit is contained in:
Simon Giesecke 2019-04-23 09:12:56 -04:00
parent 3e5843d073
commit 2d8ef84760

View File

@ -15,10 +15,9 @@ include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CMakeDependentOption)
include(CheckCXXSymbolExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(FindThreads)
include(GNUInstallDirs)
include(CheckFunctionExists)
include(CheckTypeSize)
include(CMakePackageConfigHelpers)
@ -154,21 +153,17 @@ set(POLLER "" CACHE STRING "Choose polling system for I/O threads. valid values
if(NOT MSVC)
if(POLLER STREQUAL "")
set(CMAKE_REQUIRED_INCLUDES sys/event.h)
check_function_exists(kqueue HAVE_KQUEUE)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(kqueue sys/event.h HAVE_KQUEUE)
if(HAVE_KQUEUE)
set(POLLER "kqueue")
endif()
endif()
if(POLLER STREQUAL "")
set(CMAKE_REQUIRED_INCLUDES sys/epoll.h)
check_function_exists(epoll_create HAVE_EPOLL)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(epoll_create sys/epoll.h HAVE_EPOLL)
if(HAVE_EPOLL)
set(POLLER "epoll")
check_function_exists(epoll_create1 HAVE_EPOLL_CLOEXEC)
check_cxx_symbol_exists(epoll_create1 sys/epoll.h HAVE_EPOLL_CLOEXEC)
if(HAVE_EPOLL_CLOEXEC)
set(ZMQ_IOTHREAD_POLLER_USE_EPOLL_CLOEXEC 1)
endif()
@ -176,27 +171,23 @@ if(NOT MSVC)
endif()
if(POLLER STREQUAL "")
set(CMAKE_REQUIRED_INCLUDES sys/devpoll.h)
set(CMAKE_EXTRA_INCLUDE_FILES sys/devpoll.h)
check_type_size("struct pollfd" DEVPOLL)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_EXTRA_INCLUDE_FILES)
if(HAVE_DEVPOLL)
set(POLLER "devpoll")
endif()
endif()
if(POLLER STREQUAL "")
set(CMAKE_REQUIRED_INCLUDES sys/pollset.h)
check_function_exists(pollset_create HAVE_POLLSET)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(pollset_create sys/pollset.h HAVE_POLLSET)
if(HAVE_POLLSET)
set(POLLER "pollset")
endif()
endif()
if(POLLER STREQUAL "")
set(CMAKE_REQUIRED_INCLUDES poll.h)
check_function_exists(poll HAVE_POLL)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(poll poll.h HAVE_POLL)
if(HAVE_POLL)
set(POLLER "poll")
endif()
@ -205,12 +196,9 @@ endif()
if(POLLER STREQUAL "")
if(WIN32)
set(CMAKE_REQUIRED_INCLUDES winsock2.h)
set(HAVE_SELECT 1)
else()
set(CMAKE_REQUIRED_INCLUDES sys/select.h)
check_function_exists(select HAVE_SELECT)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(select sys/select.h HAVE_SELECT)
endif()
if(HAVE_SELECT)
set(POLLER "select")
@ -358,13 +346,13 @@ endif()
if(ZMQ_HAVE_WINDOWS)
# Cannot use check_library_exists because the symbol is always declared as char(*)(void)
set(CMAKE_REQUIRED_LIBRARIES "ws2_32.lib")
check_symbol_exists(WSAStartup "winsock2.h" HAVE_WS2_32)
check_cxx_symbol_exists(WSAStartup "winsock2.h" HAVE_WS2_32)
set(CMAKE_REQUIRED_LIBRARIES "rpcrt4.lib")
check_symbol_exists(UuidCreateSequential "rpc.h" HAVE_RPCRT4)
check_cxx_symbol_exists(UuidCreateSequential "rpc.h" HAVE_RPCRT4)
set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib")
check_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI)
check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI)
set(CMAKE_REQUIRED_LIBRARIES "")
# TODO: This not the symbol we're looking for. What is the symbol?
@ -397,28 +385,14 @@ endif()
if(NOT MSVC)
set(CMAKE_REQUIRED_LIBRARIES rt)
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES unistd.h)
check_function_exists(fork HAVE_FORK)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES sys/time.h)
check_function_exists(gethrtime HAVE_GETHRTIME)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES stdlib.h)
check_function_exists(mkdtemp HAVE_MKDTEMP)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES sys/socket.h)
check_function_exists(accept4 HAVE_ACCEPT4)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES string.h)
check_function_exists(strnlen HAVE_STRNLEN)
set(CMAKE_REQUIRED_INCLUDES)
check_cxx_symbol_exists(fork unistd.h HAVE_FORK)
check_cxx_symbol_exists(gethrtimei sys/time.h HAVE_GETHRTIME)
check_cxx_symbol_exists(mkdtemp stdlib.h HAVE_MKDTEMP)
check_cxx_symbol_exists(accept4 sys/socket.h HAVE_ACCEPT4)
check_cxx_symbol_exists(strnlen string.h HAVE_STRNLEN)
endif()
add_definitions(-D_REENTRANT -D_THREAD_SAFE)