]> git.proxmox.com Git - ceph.git/blob - ceph/cmake/modules/CephChecks.cmake
ca86dcbc73de8f7082d4da6eaa91c6fbacf3cd0e
[ceph.git] / ceph / cmake / modules / CephChecks.cmake
1 if(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()
5 endif()
6
7 #Check Includes
8 include(CheckIncludeFiles)
9 include(CheckIncludeFileCXX)
10 include(CheckFunctionExists)
11
12 check_function_exists(fallocate CEPH_HAVE_FALLOCATE)
13 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
14 check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE)
15 check_function_exists(syncfs HAVE_SYS_SYNCFS)
16 check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
17 check_function_exists(pwritev HAVE_PWRITEV)
18 check_function_exists(splice CEPH_HAVE_SPLICE)
19 check_function_exists(getgrouplist HAVE_GETGROUPLIST)
20 if(NOT APPLE)
21 check_function_exists(fdatasync HAVE_FDATASYNC)
22 endif()
23 check_function_exists(strerror_r HAVE_Strerror_R)
24 check_function_exists(name_to_handle_at HAVE_NAME_TO_HANDLE_AT)
25 check_function_exists(pipe2 HAVE_PIPE2)
26 check_function_exists(accept4 HAVE_ACCEPT4)
27 check_function_exists(sigdescr_np HAVE_SIGDESCR_NP)
28
29 include(CMakePushCheckState)
30 cmake_push_check_state(RESET)
31 set(CMAKE_REQUIRED_LIBRARIES pthread)
32 check_function_exists(pthread_spin_init HAVE_PTHREAD_SPINLOCK)
33 check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
34 check_function_exists(pthread_get_name_np HAVE_PTHREAD_GET_NAME_NP)
35 check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
36 check_function_exists(pthread_getname_np HAVE_PTHREAD_GETNAME_NP)
37 check_function_exists(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP)
38 cmake_pop_check_state()
39
40 check_function_exists(eventfd HAVE_EVENTFD)
41 check_function_exists(getprogname HAVE_GETPROGNAME)
42 check_function_exists(gettid HAVE_GETTID)
43
44 CHECK_INCLUDE_FILES("linux/types.h" HAVE_LINUX_TYPES_H)
45 CHECK_INCLUDE_FILES("linux/version.h" HAVE_LINUX_VERSION_H)
46 CHECK_INCLUDE_FILES("arpa/nameser_compat.h" HAVE_ARPA_NAMESER_COMPAT_H)
47 CHECK_INCLUDE_FILES("sys/mount.h" HAVE_SYS_MOUNT_H)
48 CHECK_INCLUDE_FILES("sys/param.h" HAVE_SYS_PARAM_H)
49 CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H)
50 CHECK_INCLUDE_FILES("sys/vfs.h" HAVE_SYS_VFS_H)
51 CHECK_INCLUDE_FILES("sys/prctl.h" HAVE_SYS_PRCTL_H)
52 CHECK_INCLUDE_FILES("execinfo.h" HAVE_EXECINFO_H)
53 if(LINUX)
54 CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED)
55 endif()
56 CHECK_INCLUDE_FILES("valgrind/helgrind.h" HAVE_VALGRIND_HELGRIND_H)
57
58 include(CheckTypeSize)
59 set(CMAKE_EXTRA_INCLUDE_FILES "linux/types.h")
60 CHECK_TYPE_SIZE(__u8 __U8)
61 CHECK_TYPE_SIZE(__u16 __U16)
62 CHECK_TYPE_SIZE(__u32 __U32)
63 CHECK_TYPE_SIZE(__u64 __U64)
64 CHECK_TYPE_SIZE(__s8 __S8)
65 CHECK_TYPE_SIZE(__s16 __S16)
66 CHECK_TYPE_SIZE(__s32 __S32)
67 CHECK_TYPE_SIZE(__s64 __S64)
68 unset(CMAKE_EXTRA_INCLUDE_FILES)
69
70 include(CheckSymbolExists)
71 cmake_push_check_state(RESET)
72 set(CMAKE_REQUIRED_LIBRARIES rt)
73 check_symbol_exists(_POSIX_TIMERS "unistd.h;time.h" HAVE_POSIX_TIMERS)
74 cmake_pop_check_state()
75 if(HAVE_POSIX_TIMERS)
76 find_library(RT_LIBRARY NAMES rt)
77 endif()
78 check_symbol_exists(res_nquery "resolv.h" HAVE_RES_NQUERY)
79 check_symbol_exists(F_SETPIPE_SZ "linux/fcntl.h" CEPH_HAVE_SETPIPE_SZ)
80 check_symbol_exists(__func__ "" HAVE_FUNC)
81 check_symbol_exists(__PRETTY_FUNCTION__ "" HAVE_PRETTY_FUNC)
82 check_symbol_exists(getentropy "unistd.h" HAVE_GETENTROPY)
83
84 include(CheckCXXSourceCompiles)
85 check_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
90 include(CheckStructHasMember)
91 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
92 HAVE_STAT_ST_MTIM_TV_NSEC LANGUAGE C)
93 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
94 HAVE_STAT_ST_MTIMESPEC_TV_NSEC LANGUAGE C)
95
96 if(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
114 uint32_t load(char* p, size_t offset)
115 {
116 return *reinterpret_cast<uint32_t*>(p + offset);
117 }
118
119 bool good(uint32_t lhs, uint32_t big_endian)
120 {
121 return lhs == ntohl(big_endian);
122 }
123
124 int 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()
142 else(NOT CMAKE_CROSSCOMPILING)
143 message(STATUS "Assuming unaligned access is supported")
144 endif(NOT CMAKE_CROSSCOMPILING)
145
146 # should use LINK_OPTIONS instead of LINK_LIBRARIES, if we can use cmake v3.14+
147 try_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
152 try_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")