mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-14 02:57:47 +01:00
Merge pull request #3496 from sigiesec/cleanup-cmakelists
Some cleanup in CMakeLists.txt
This commit is contained in:
commit
f41f51461f
125
CMakeLists.txt
125
CMakeLists.txt
@ -7,7 +7,29 @@ else()
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
endif()
|
||||
|
||||
option(ENABLE_ASAN "Build with address sanitizer)" OFF)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCSourceRuns)
|
||||
include(CMakeDependentOption)
|
||||
include(CheckCXXSymbolExists)
|
||||
include(CheckTypeSize)
|
||||
include(FindThreads)
|
||||
include(GNUInstallDirs)
|
||||
include(CheckTypeSize)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
|
||||
list(APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR})
|
||||
|
||||
include(TestZMQVersion)
|
||||
include(ZMQSourceRunChecks)
|
||||
include(ZMQSupportMacros)
|
||||
|
||||
option(ENABLE_ASAN "Build with address sanitizer" OFF)
|
||||
if(ENABLE_ASAN)
|
||||
message(STATUS "Instrumenting with Address Sanitizer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
|
||||
@ -22,11 +44,6 @@ if (ENABLE_INTRINSICS)
|
||||
add_definitions(-DZMQ_HAVE_ATOMIC_INTRINSICS)
|
||||
endif()
|
||||
|
||||
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
|
||||
list(APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR})
|
||||
|
||||
include(GNUInstallDirs)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
|
||||
# Find more information: https://cmake.org/Wiki/CMake_RPATH_handling
|
||||
|
||||
@ -43,19 +60,15 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
endif()
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
|
||||
endif()
|
||||
include(CheckCCompilerFlag)
|
||||
check_c_compiler_flag("-std=gnu11" COMPILER_SUPPORTS_C11)
|
||||
if(COMPILER_SUPPORTS_C11)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
|
||||
endif()
|
||||
|
||||
include(ZMQSupportMacros)
|
||||
|
||||
if(NOT MSVC)
|
||||
# clang 6 has a warning that does not make sense on multi-platform code
|
||||
check_cxx_compiler_flag("-Wno-tautological-constant-compare" CXX_HAS_TAUT_WARNING)
|
||||
@ -138,26 +151,19 @@ set(API_POLLER "" CACHE STRING "Choose polling system for zmq_poll(er)_*. valid
|
||||
set(POLLER "" CACHE STRING "Choose polling system for I/O threads. valid values are
|
||||
kqueue, epoll, devpoll, pollset, poll or select [default=autodetect]")
|
||||
|
||||
include(CheckFunctionExists)
|
||||
include(CheckTypeSize)
|
||||
|
||||
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()
|
||||
@ -165,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()
|
||||
@ -194,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")
|
||||
@ -239,19 +238,6 @@ message(STATUS "Using polling method in zmq_poll(er)_* API: ${API_POLLER}")
|
||||
string(TOUPPER ${API_POLLER} UPPER_API_POLLER)
|
||||
set(ZMQ_POLL_BASED_ON_${UPPER_API_POLLER} 1)
|
||||
|
||||
include(TestZMQVersion)
|
||||
include(ZMQSourceRunChecks)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCSourceRuns)
|
||||
include(CMakeDependentOption)
|
||||
include(CheckCXXSymbolExists)
|
||||
include(CheckSymbolExists)
|
||||
include(FindThreads)
|
||||
|
||||
execute_process(COMMAND getconf LEVEL1_DCACHE_LINESIZE OUTPUT_VARIABLE CACHELINE_SIZE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(CACHELINE_SIZE STREQUAL "" OR CACHELINE_SIZE EQUAL 0 OR CACHELINE_SIZE EQUAL -1)
|
||||
set(ZMQ_CACHELINE_SIZE 64)
|
||||
@ -350,11 +336,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND CMAKE_SYSTEM_VERSION STREQUAL "
|
||||
endif()
|
||||
if(NOT MSVC)
|
||||
check_include_files(ifaddrs.h ZMQ_HAVE_IFADDRS)
|
||||
message("ZMQ_HAVE_IFADDRS: ${ZMQ_HAVE_IFADDRS}")
|
||||
check_include_files(sys/uio.h ZMQ_HAVE_UIO)
|
||||
message("ZMQ_HAVE_UIO: ${ZMQ_HAVE_UIO}")
|
||||
check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD)
|
||||
message("ZMQ_HAVE_EVENTFD: ${ZMQ_HAVE_EVENTFD}")
|
||||
if(ZMQ_HAVE_EVENTFD AND NOT CMAKE_CROSSCOMPILING)
|
||||
zmq_check_efd_cloexec()
|
||||
endif()
|
||||
@ -363,22 +346,20 @@ 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?
|
||||
check_library_exists(ws2 fopen "" HAVE_WS2)
|
||||
else()
|
||||
check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED)
|
||||
message("ZMQ_HAVE_SO_PEERCRED: ${ZMQ_HAVE_SO_PEERCRED}")
|
||||
check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)
|
||||
message("ZMQ_HAVE_LOCAL_PEERCRED: ${ZMQ_HAVE_LOCAL_PEERCRED}")
|
||||
endif()
|
||||
|
||||
find_library(RT_LIBRARY rt)
|
||||
@ -404,35 +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)
|
||||
message("HAVE_CLOCK_GETTIME: ${HAVE_CLOCK_GETTIME}")
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES unistd.h)
|
||||
check_function_exists(fork HAVE_FORK)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
message("HAVE_FORK: ${HAVE_FORK}")
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES sys/time.h)
|
||||
check_function_exists(gethrtime HAVE_GETHRTIME)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
message("HAVE_GETHRTIME: ${HAVE_GETHRTIME}")
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES stdlib.h)
|
||||
check_function_exists(mkdtemp HAVE_MKDTEMP)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
message("HAVE_MKDTEMP: ${HAVE_MKDTEMP}")
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES sys/socket.h)
|
||||
check_function_exists(accept4 HAVE_ACCEPT4)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
message("HAVE_ACCEPT4: ${HAVE_ACCEPT4}")
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES string.h)
|
||||
check_function_exists(strnlen HAVE_STRNLEN)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
message("HAVE_STRNLEN: ${HAVE_STRNLEN}")
|
||||
|
||||
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)
|
||||
@ -542,7 +502,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" OR CM
|
||||
} \
|
||||
"
|
||||
HAVE_ATOMIC_H)
|
||||
message("HAVE_ATOMIC_H: ${HAVE_ATOMIC_H}")
|
||||
|
||||
if(NOT HAVE_ATOMIC_H)
|
||||
set(ZMQ_FORCE_MUTEXES 1)
|
||||
endif()
|
||||
@ -1431,8 +1391,6 @@ if(WITH_DOC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
if(WIN32)
|
||||
set(ZEROMQ_CMAKECONFIG_INSTALL_DIR "CMake" CACHE STRING "install path for ZeroMQConfig.cmake")
|
||||
else()
|
||||
@ -1560,4 +1518,5 @@ if(MSVC_VERSION EQUAL 1600)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# this cannot be moved, as it does not only contain function/macro definitions
|
||||
include(ClangFormat)
|
||||
|
@ -16,5 +16,5 @@ set(CMAKE_ASM_DEFINE_FLAG "-Wa,--defsym,")
|
||||
set(CMAKE_RANLIB $ENV{QNX_HOST}/usr/bin/nto${ntoarch}-ranlib
|
||||
CACHE PATH "QNX ranlib Program" FORCE)
|
||||
set(CMAKE_AR $ENV{QNX_HOST}/usr/bin/nto${ntoarch}-ar
|
||||
CACHE PATH "QNX qr Program" FORCE)
|
||||
CACHE PATH "QNX ar Program" FORCE)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user