Skip to content

Commit

Permalink
cmake: ensure we globally match on _GNU_SOURCE
Browse files Browse the repository at this point in the history
  • Loading branch information
m6w6 committed Feb 2, 2022
1 parent 43fa1d4 commit bcc1a6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
16 changes: 16 additions & 0 deletions CMake/_Include.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
include(_Configure)
configure_init(${CMAKE_BINARY_DIR}/mem_config.h)

add_compile_definitions(${GLOBAL_DEFINITIONS})
# list(TRANSFORM) requires >=3.12
string(REPLACE ";" " -D" GLOBAL_DEFINITION_FLAGS "${GLOBAL_DEFINITIONS}")
set(GLOBAL_DEFINITION_FLAGS -D${GLOBAL_DEFINITION_FLAGS})

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
Expand Down Expand Up @@ -32,6 +37,7 @@ macro(check_symbol NAME HEADER)
if(${ARGC} GREATER 1)
string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGV2}")
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_symbol_exists(${NAME} ${HEADER} ${HAVE})
cmake_pop_check_state()
endmacro()
Expand All @@ -43,6 +49,7 @@ macro(check_cxx_symbol NAME HEADER)
if(${ARGC} GREATER 1)
string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGN}")
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_cxx_symbol_exists(${NAME} ${HEADER} ${HAVE})
cmake_pop_check_state()
endmacro()
Expand All @@ -54,6 +61,7 @@ macro(check_include HEADER)
if(${ARGC} GREATER 1)
string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGN}")
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_include_file(${HEADER} ${HAVE})
cmake_pop_check_state()
endmacro()
Expand All @@ -65,6 +73,7 @@ macro(check_cxx_include HEADER)
if(${ARGC} GREATER 1)
string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGN}")
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_include_file_cxx(${HEADER} ${HAVE})
cmake_pop_check_state()
endmacro()
Expand All @@ -76,18 +85,25 @@ macro(check_type TYPE)
if(${ARGC} GREATER 1)
list(APPEND CMAKE_EXTRA_INCLUDE_FILES ${ARGN})
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_type_size(${TYPE} ${HAVE})
cmake_pop_check_state()
endmacro()
include(CheckCSourceCompiles)
macro(check_c_source SOURCE HAVE)
configure_define(${HAVE})
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_c_source_compiles("${SOURCE}" ${HAVE})
cmake_pop_check_state()
endmacro()
include(CheckCXXSourceCompiles)
macro(check_cxx_source SOURCE HAVE)
configure_define(${HAVE})
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
check_cxx_source_compiles("${SOURCE}" ${HAVE})
cmake_pop_check_state()
endmacro()

include(CheckBacktrace)
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set(PROJECT_CONTACT "Michael Wallner <[email protected]>")
set(CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(GLOBAL_DEFINITIONS _GNU_SOURCE)

include(CMakeConfig.txt)
include(GNUInstallDirs)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
Expand Down
1 change: 0 additions & 1 deletion contrib/bin/memaslap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
if(ENABLE_MEMASLAP AND CMAKE_USE_PTHREADS_INIT)
add_definitions(-D_GNU_SOURCE)

include(CheckAtomics)

Expand Down
2 changes: 0 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ configure_define_string(LIBMEMCACHED_WITH_SASL_CONF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
include(Catch)

add_definitions(-D_GNU_SOURCE)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol(pipe2 unistd.h)
check_symbol(SOCK_NONBLOCK sys/socket.h)
check_symbol(SOCK_CLOEXEC sys/socket.h)
Expand Down

0 comments on commit bcc1a6e

Please sign in to comment.