summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2015-11-29 12:00:29 -0800
committerAlan Antonuk <alan.antonuk@gmail.com>2015-11-29 12:21:08 -0800
commitaf71eb238047899d5b69e6000d2f3c6590ffffb3 (patch)
treed9ede2a39ffcbd1bebfedc27cfd247e865070a56 /CMakeLists.txt
parente1cb55e69521dd862217ef1c6aed64897a11ede8 (diff)
downloadrabbitmq-c-af71eb238047899d5b69e6000d2f3c6590ffffb3.tar.gz
CMake: rework symbol checking to work with -Werror
Rework checking for existence of getaddrinfo, socket, poll and select so that it works when -DCMAKE_C_FLAGS="-Werror" is passed to CMake.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt74
1 files changed, 37 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 179630e..908f02f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,19 +39,6 @@ string(REGEX MATCH "[0-9]+" _API_VERSION_PATCH ${_API_VERSION_PATCH})
# VERSION to match what is in autotools
set(VERSION ${_API_VERSION_MAJOR}.${_API_VERSION_MINOR}.${_API_VERSION_PATCH})
-if (MSVC)
- set(CMAKE_C_FLAGS "/W4 /nologo ${CMAKE_C_FLAGS}")
-elseif (CMAKE_C_COMPILER_ID MATCHES ".*Clang")
- set(CMAKE_C_FLAGS "-Wall -Wextra -Wstrict-prototypes -Wno-unused-function -fno-common -fvisibility=hidden ${CMAKE_C_FLAGS}")
-elseif (CMAKE_COMPILER_IS_GNUCC)
- set(RMQ_C_FLAGS "-Wall -Wextra -Wstrict-prototypes -Wno-unused-function -fno-common")
- execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
- if (GCC_VERSION VERSION_GREATER 4.0 OR GCC_VERSION VERSION_EQUAL 4.0)
- set(RMQ_C_FLAGS "${RMQ_C_FLAGS} -fvisibility=hidden")
- endif()
- set(CMAKE_C_FLAGS "${RMQ_C_FLAGS} ${CMAKE_C_FLAGS}")
-endif ()
-
if (CMAKE_GENERATOR MATCHES ".*(Make|Ninja).*"
AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
@@ -59,23 +46,12 @@ if (CMAKE_GENERATOR MATCHES ".*(Make|Ninja).*"
endif()
include(TestCInline)
-include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CMakePushCheckState)
include(GNUInstallDirs)
include(CheckCCompilerFlag)
-CHECK_C_COMPILER_FLAG("-std=gnu90" HAVE_GNU90)
-if (HAVE_GNU90)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
-else()
- CHECK_C_COMPILER_FLAG("-std=c90" HAVE_C90)
- if (HAVE_C90)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
- endif()
-endif()
-
# Detect if we need to link against a socket library:
cmake_push_check_state()
if (WIN32)
@@ -83,13 +59,15 @@ if (WIN32)
set(SOCKET_LIBRARIES ws2_32)
else ()
# Is it in the default link?
- CHECK_FUNCTION_EXISTS(getaddrinfo HAVE_GETADDRINFO)
+ check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO)
if (NOT (HAVE_GETADDRINFO EQUAL 1))
- CHECK_LIBRARY_EXISTS(socket getaddrinfo "" HAVE_GETADDRINFO2)
+ SET(CMAKE_REQUIRED_LIBRARIES "socket")
+ check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO2)
if (HAVE_GETADDRINFO2 EQUAL 1)
set(SOCKET_LIBRARIES socket)
else ()
- CHECK_LIBRARY_EXISTS("socket;nsl" getaddrinfo "" HAVE_GETADDRINFO3)
+ SET(CMAKE_REQUIRED_LIBRARIES "socket;nsl")
+ check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO3)
if (HAVE_GETADDRINFO3 EQUAL 1)
set(SOCKET_LIBRARIES socket nsl)
else ()
@@ -99,13 +77,15 @@ else ()
endif ()
set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES})
- CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
+ check_symbol_exists(socket "sys/types.h;sys/socket.h" HAVE_SOCKET)
if (NOT HAVE_SOCKET EQUAL 1)
- CHECK_LIBRARY_EXISTS(socket socket "" HAVE_SOCKET2)
- if (NOT HAVE_SOCKET2 EQUAL 1)
+ set(CMAKE_REQUIRED_LIBRARIES socket ${SOCKET_LIBRARIES})
+ check_symbol_exists(socket "sys/types.h;sys/socket.h" HAVE_SOCKET2)
+ if (HAVE_SOCKET2 EQUAL 1)
set(SOCKET_LIBRARIES socket ${SOCKET_LIBRARIES})
else ()
- CHECK_LIBRARY_EXISTS("socket;nsl" socket "" HAVE_SOCKET3)
+ set(CMAKE_REQUIRED_LIBRARIES socket nsl ${SOCKET_LIBRARIES})
+ check_symbol_exists(socket "sys/types.h;sys/socket.h" HAVE_SOCKET3)
if (HAVE_SOCKET3 EQUAL 1)
set(SOCKET_LIBRARIES socket nsl ${SOCKET_LIBRARIES})
else ()
@@ -126,16 +106,13 @@ endif (WIN32)
cmake_pop_check_state()
cmake_push_check_state()
-set(CMAKE_REQUIRED_INCLUDES "poll.h")
-check_function_exists(poll HAVE_POLL)
-set(CMAKE_REQUIRED_INCLUDES )
+set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES})
+check_symbol_exists(poll poll.h HAVE_POLL)
if (NOT HAVE_POLL)
if (WIN32)
set(HAVE_SELECT 1)
else()
- set(CMAKE_REQUIRED_INCLUDES sys/select.h)
- check_function_exists(select HAVE_SELECT)
- set(CMAKE_REQUIRED_INCLUDES )
+ check_symbol_exists(select sys/select.h HAVE_SELECT)
endif()
if (NOT HAVE_SELECT)
message(FATAL_ERROR "rabbitmq-c requires poll() or select() to be available")
@@ -149,6 +126,29 @@ if (CLOCK_GETTIME_NEEDS_LIBRT OR POSIX_SPAWNP_NEEDS_LIBRT)
set(LIBRT rt)
endif()
+if (MSVC)
+ set(CMAKE_C_FLAGS "/W4 /nologo ${CMAKE_C_FLAGS}")
+elseif (CMAKE_C_COMPILER_ID MATCHES ".*Clang")
+ set(CMAKE_C_FLAGS "-Wall -Wextra -Wstrict-prototypes -Wno-unused-function -fno-common -fvisibility=hidden ${CMAKE_C_FLAGS}")
+elseif (CMAKE_COMPILER_IS_GNUCC)
+ set(RMQ_C_FLAGS "-Wall -Wextra -Wstrict-prototypes -Wno-unused-function -fno-common")
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
+ if (GCC_VERSION VERSION_GREATER 4.0 OR GCC_VERSION VERSION_EQUAL 4.0)
+ set(RMQ_C_FLAGS "${RMQ_C_FLAGS} -fvisibility=hidden")
+ endif()
+ set(CMAKE_C_FLAGS "${RMQ_C_FLAGS} ${CMAKE_C_FLAGS}")
+endif ()
+
+CHECK_C_COMPILER_FLAG("-std=gnu90" HAVE_GNU90)
+if (HAVE_GNU90)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
+else()
+ CHECK_C_COMPILER_FLAG("-std=c90" HAVE_C90)
+ if (HAVE_C90)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c90")
+ endif()
+endif()
+
option(REGENERATE_AMQP_FRAMING "Regenerate amqp_framing.h/amqp_framing.c sources (for developer use)" OFF)
mark_as_advanced(REGENERATE_AMQP_FRAMING)