Skip to content

Commit 22684e6

Browse files
committed
cmake UPDATE flexible compat definitions
1 parent 0bcb75e commit 22684e6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

CMakeModules/UseCompat.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ endif()
2323

2424
macro(USE_COMPAT)
2525
# compatibility checks
26-
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
26+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
2727
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
2828
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
29-
set(CMAKE_REQUIRED_LIBRARIES pthread)
3029

3130
check_symbol_exists(_POSIX_TIMERS "unistd.h" HAVE_CLOCK)
3231
if(NOT HAVE_CLOCK)
3332
message(FATAL_ERROR "Missing support for clock_gettime() and similar functions!")
3433
endif()
3534

35+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
36+
find_package(Threads)
37+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
38+
3639
check_symbol_exists(pthread_mutex_timedlock "pthread.h" HAVE_PTHREAD_MUTEX_TIMEDLOCK)
3740
check_symbol_exists(pthread_mutex_clocklock "pthread.h" HAVE_PTHREAD_MUTEX_CLOCKLOCK)
3841
check_symbol_exists(pthread_rwlock_timedrdlock "pthread.h" HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK)
@@ -74,12 +77,14 @@ macro(USE_COMPAT)
7477
endif()
7578
check_symbol_exists(crypt_r "crypt.h" HAVE_CRYPT_R)
7679

77-
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
80+
test_big_endian(IS_BIG_ENDIAN)
7881

7982
check_include_file("stdatomic.h" HAVE_STDATOMIC)
8083

81-
unset(CMAKE_REQUIRED_DEFINITIONS)
82-
unset(CMAKE_REQUIRED_LIBRARIES)
84+
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
85+
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
86+
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
87+
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
8388

8489
# header and source file (adding the source directly allows for hiding its symbols)
8590
configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat/compat.h @ONLY)

0 commit comments

Comments
 (0)