]> git.proxmox.com Git - ceph.git/blame - ceph/cmake/modules/CephChecks.cmake
import 15.2.9
[ceph.git] / ceph / cmake / modules / CephChecks.cmake
CommitLineData
9f95a23c
TL
1if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
2 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
3 message(FATAL_ERROR "GCC 7+ required due to C++17 requirements")
4 endif()
5endif()
6
7#Check Includes
8include(CheckIncludeFiles)
9include(CheckIncludeFileCXX)
10include(CheckFunctionExists)
11
12check_function_exists(fallocate CEPH_HAVE_FALLOCATE)
13check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
14check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE)
15check_function_exists(syncfs HAVE_SYS_SYNCFS)
16check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
17check_function_exists(pwritev HAVE_PWRITEV)
18check_function_exists(splice CEPH_HAVE_SPLICE)
19check_function_exists(getgrouplist HAVE_GETGROUPLIST)
20if(NOT APPLE)
21 check_function_exists(fdatasync HAVE_FDATASYNC)
22endif()
23check_function_exists(strerror_r HAVE_Strerror_R)
24check_function_exists(name_to_handle_at HAVE_NAME_TO_HANDLE_AT)
25check_function_exists(pipe2 HAVE_PIPE2)
26check_function_exists(accept4 HAVE_ACCEPT4)
adb31ebb 27check_function_exists(sigdescr_np HAVE_SIGDESCR_NP)
9f95a23c
TL
28
29include(CMakePushCheckState)
30cmake_push_check_state(RESET)
31set(CMAKE_REQUIRED_LIBRARIES pthread)
32check_function_exists(pthread_spin_init HAVE_PTHREAD_SPINLOCK)
33check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
34check_function_exists(pthread_get_name_np HAVE_PTHREAD_GET_NAME_NP)
35check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
36check_function_exists(pthread_getname_np HAVE_PTHREAD_GETNAME_NP)
37check_function_exists(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP)
38cmake_pop_check_state()
39
40check_function_exists(eventfd HAVE_EVENTFD)
41check_function_exists(getprogname HAVE_GETPROGNAME)
42check_function_exists(gettid HAVE_GETTID)
43
44CHECK_INCLUDE_FILES("linux/types.h" HAVE_LINUX_TYPES_H)
45CHECK_INCLUDE_FILES("linux/version.h" HAVE_LINUX_VERSION_H)
46CHECK_INCLUDE_FILES("arpa/nameser_compat.h" HAVE_ARPA_NAMESER_COMPAT_H)
47CHECK_INCLUDE_FILES("sys/mount.h" HAVE_SYS_MOUNT_H)
48CHECK_INCLUDE_FILES("sys/param.h" HAVE_SYS_PARAM_H)
49CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H)
50CHECK_INCLUDE_FILES("sys/vfs.h" HAVE_SYS_VFS_H)
51CHECK_INCLUDE_FILES("sys/prctl.h" HAVE_SYS_PRCTL_H)
52CHECK_INCLUDE_FILES("execinfo.h" HAVE_EXECINFO_H)
53if(LINUX)
54 CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED)
55endif()
56CHECK_INCLUDE_FILES("valgrind/helgrind.h" HAVE_VALGRIND_HELGRIND_H)
57
58include(CheckTypeSize)
59set(CMAKE_EXTRA_INCLUDE_FILES "linux/types.h")
60CHECK_TYPE_SIZE(__u8 __U8)
61CHECK_TYPE_SIZE(__u16 __U16)
62CHECK_TYPE_SIZE(__u32 __U32)
63CHECK_TYPE_SIZE(__u64 __U64)
64CHECK_TYPE_SIZE(__s8 __S8)
65CHECK_TYPE_SIZE(__s16 __S16)
66CHECK_TYPE_SIZE(__s32 __S32)
67CHECK_TYPE_SIZE(__s64 __S64)
68unset(CMAKE_EXTRA_INCLUDE_FILES)
69
70include(CheckSymbolExists)
71cmake_push_check_state(RESET)
72set(CMAKE_REQUIRED_LIBRARIES rt)
73check_symbol_exists(_POSIX_TIMERS "unistd.h;time.h" HAVE_POSIX_TIMERS)
74cmake_pop_check_state()
75if(HAVE_POSIX_TIMERS)
76 find_library(RT_LIBRARY NAMES rt)
77endif()
78check_symbol_exists(res_nquery "resolv.h" HAVE_RES_NQUERY)
79check_symbol_exists(F_SETPIPE_SZ "linux/fcntl.h" CEPH_HAVE_SETPIPE_SZ)
80check_symbol_exists(__func__ "" HAVE_FUNC)
81check_symbol_exists(__PRETTY_FUNCTION__ "" HAVE_PRETTY_FUNC)
82check_symbol_exists(getentropy "unistd.h" HAVE_GETENTROPY)
83
84include(CheckCXXSourceCompiles)
85check_cxx_source_compiles("
86 #include <string.h>
87 int main() { char x = *strerror_r(0, &x, sizeof(x)); return 0; }
88 " STRERROR_R_CHAR_P)
89
90include(CheckStructHasMember)
91CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
92 HAVE_STAT_ST_MTIM_TV_NSEC LANGUAGE C)
93CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
94 HAVE_STAT_ST_MTIMESPEC_TV_NSEC LANGUAGE C)
95
96if(NOT CMAKE_CROSSCOMPILING)
97 include(CheckCXXSourceRuns)
98 cmake_push_check_state()
99 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++17")
100 if(WIN32)
101 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
102 endif()
103
104 check_cxx_source_runs("
105#include <cstdint>
106#include <iterator>
107
108#ifdef _WIN32
109#include <winsock2.h>
110#else
111#include <arpa/inet.h>
112#endif
113
114uint32_t load(char* p, size_t offset)
115{
116 return *reinterpret_cast<uint32_t*>(p + offset);
117}
118
119bool good(uint32_t lhs, uint32_t big_endian)
120{
121 return lhs == ntohl(big_endian);
122}
123
124int main(int argc, char **argv)
125{
126 char a1[] = \"ABCDEFG\";
127 uint32_t a2[] = {0x41424344,
128 0x42434445,
129 0x43444546,
130 0x44454647};
131 for (size_t i = 0; i < std::size(a2); i++) {
132 if (!good(load(a1, i), a2[i])) {
133 return 1;
134 }
135 }
136}"
137 HAVE_UNALIGNED_ACCESS)
138 cmake_pop_check_state()
139 if(NOT HAVE_UNALIGNED_ACCESS)
140 message(FATAL_ERROR "Unaligned access is required")
141 endif()
142else(NOT CMAKE_CROSSCOMPILING)
143 message(STATUS "Assuming unaligned access is supported")
144endif(NOT CMAKE_CROSSCOMPILING)
145
146# should use LINK_OPTIONS instead of LINK_LIBRARIES, if we can use cmake v3.14+
147try_compile(HAVE_LINK_VERSION_SCRIPT
148 ${CMAKE_CURRENT_BINARY_DIR}
149 SOURCES ${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.c
150 LINK_LIBRARIES "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.map")
151
152try_compile(HAVE_LINK_EXCLUDE_LIBS
153 ${CMAKE_CURRENT_BINARY_DIR}
154 SOURCES ${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.c
155 LINK_LIBRARIES "-Wl,--exclude-libs,ALL")