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