File: EnvTests.cmake

package info (click to toggle)
lizardfs 3.12.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,064 kB
  • sloc: cpp: 91,899; sh: 9,341; python: 3,878; ansic: 3,109; pascal: 128; makefile: 57
file content (117 lines) | stat: -rw-r--r-- 4,348 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# comparing build config with (old) autotools build,
# refer to ced2e72776fd01e71f1c7eece9c4414b1fe23c54 / configure.ac

# discarded tests:
# keywords tests for inline, volatile and const

# functions marked here as required, that don't appear in the code: atexit strchr

# checking for fork and vfork, but vfork unused

# XXX(lamvak): didn't add check for strerror_r function compatible with
# AC_FUNC_STRERROR_R

include(CheckCXXCompilerFlag)
include(CheckCXXExpression)
include(CheckCXXSourceCompiles)
include(CheckFunctionExists)
include(CheckFunctions)
include(CheckIncludes)
include(CheckLibraryExists)
include(CheckMembers)
include(CheckStructHasMember)
include(CheckSymbolExists)
include(CheckTypeSize)
include(TestBigEndian)
include(SharedLibraries)

set(INCLUDES arpa/inet.h fcntl.h inttypes.h limits.h netdb.h
    netinet/in.h stddef.h stdlib.h string.h sys/mman.h
    sys/resource.h sys/rusage.h sys/socket.h sys/statvfs.h sys/time.h
    syslog.h unistd.h stdbool.h isa-l/erasure_code.h
)

if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
   set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include")
   include_directories("/usr/local/include")
endif()

check_includes("${INCLUDES}")

TEST_BIG_ENDIAN(BIG_ENDIAN)
if(BIG_ENDIAN)
  set(WORDS_BIGENDIAN 1)
endif()

set(TYPES_CHECKED int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t
    uint64_t uid_t mode_t off_t pid_t size_t)
set(CMAKE_EXTRA_INCLUDE_FILES stdint.h)
foreach(TYPE ${TYPES_CHECKED})
  string(TOUPPER ${TYPE} TYPE_SIZE_VAR)
  CHECK_TYPE_SIZE(${TYPE} ${TYPE_SIZE_VAR})
endforeach()
set(CMAKE_EXTRA_INCLUDE_FILES)
#XXX(lamvak): now handle possible missing types or different type sizes

set(ST_MEMBERS_CHECKED st_blocks st_rdev st_birthtime st_blksize st_flags)
check_members("struct stat" "${ST_MEMBERS_CHECKED}" "sys/stat.h")
check_members("struct tm" "tm_gmtoff" "time.h")
check_members("struct rusage" "ru_maxrss" "sys/resource.h")

CHECK_FUNCTION_EXISTS(fork     LIZARDFS_HAVE_WORKING_FORK)
CHECK_FUNCTION_EXISTS(vfork    LIZARDFS_HAVE_WORKING_VFORK)
CHECK_TEMPLATE_FUNCTION_EXISTS("string" "std::to_string(0)" LIZARDFS_HAVE_STD_TO_STRING)
CHECK_TEMPLATE_FUNCTION_EXISTS("string" "std::stoull(\"0\")" LIZARDFS_HAVE_STD_STOULL)

set(REQUIRED_FUNCTIONS atexit ftruncate gettimeofday memmove memset mkdir strchr strdup strtol
    strtoul ftello fseeko)
if(NOT MINGW)
  list(APPEND REQUIRED_FUNCTIONS getpass poll realpath)
endif()
check_functions("${REQUIRED_FUNCTIONS}" TRUE)

set(OPTIONAL_FUNCTIONS strerror perror pread pwrite readv writev getrusage
  setitimer posix_fadvise fallocate)
check_functions("${OPTIONAL_FUNCTIONS}" false)

CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" LIZARDFS_HAVE_CLOCK_GETTIME)

set(CMAKE_REQUIRED_INCLUDES "sys/mman.h")
set(OPTIONAL_FUNCTIONS2 dup2 mlockall getcwd)
check_functions("${OPTIONAL_FUNCTIONS2}" false)

set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_expression(::std::chrono::steady_clock::is_steady chrono LIZARDFS_HAVE_STD_CHRONO_STEADY_CLOCK)
check_cxx_expression("sizeof(::std::allocator_traits<std::allocator<int*>>::pointer)" memory LIZARDFS_HAVE_STD_ALLOCATOR_TRAITS)
check_cxx_source_compiles("thread_local int i; int main(){}" LIZARDFS_HAVE_THREAD_LOCAL)
unset(CMAKE_REQUIRED_FLAGS)

check_cxx_compiler_flag(-mcrc32    CXX_HAS_MCRC32)

set(_CHECK_CXX_CPU_CHECK_CODE "
__attribute__ ((target (\"default\"))) int test_default() { return 0; }
__attribute__ ((target (\"sse\"))) int test_sse() { return 1; }
__attribute__ ((target (\"ssse3\"))) int test_ssse3() { return 2; }
int main() { if (__builtin_cpu_supports(\"ssse3\")) return test_ssse3(); else return test_default(); }
")
check_cxx_source_compiles("${_CHECK_CXX_CPU_CHECK_CODE}" LIZARDFS_HAVE_CPU_CHECK)

if(APPLE)
    set(SOCKET_CONVERT_POLL_TO_SELECT 1)
endif()

set(CMAKE_REQUIRED_FLAGS "-D_GNU_SOURCE")
check_symbol_exists(FALLOC_FL_PUNCH_HOLE "fcntl.h" LIZARDFS_HAVE_FALLOC_FL_PUNCH_HOLE)
if(NOT LIZARDFS_HAVE_FALLOC_FL_PUNCH_HOLE)
    check_symbol_exists(FALLOC_FL_PUNCH_HOLE "linux/falloc.h" LIZARDFS_HAVE_FALLOC_FL_PUNCH_HOLE_IN_LINUX_FALLOC_H)
endif()
unset(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_FLAGS "-std=c++11")
set(_CHECK_CXX_STD_FUTURE_CODE "
#include <future>
std::future<void> test_future;
int main() { return 0; }
")
check_cxx_source_compiles("${_CHECK_CXX_STD_FUTURE_CODE}" LIZARDFS_HAVE_STD_FUTURE)
unset(CMAKE_REQUIRED_FLAGS)