-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
132 lines (103 loc) · 3.6 KB
/
CMakeLists.txt
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#
# Cmake configuration file for liblcb.
# Just add: include(liblcb/CMakeLists.txt) in CMakeLists.txt to use this lib.
# To enable tests: -DENABLE_LIBLCB_TESTS=1
#
############################# INITIAL SECTION ##########################
cmake_minimum_required(VERSION 3.20)
############################# OPTIONS SECTION ##########################
############################# INCLUDE SECTION ##########################
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckCCompilerFlag)
find_library(PTHREAD_LIBRARY pthread)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARY})
############################# MACRO SECTION ############################
macro(try_c_flag prop flag)
# Try flag once on the C compiler
check_c_compiler_flag("-Werror ${flag}" C_FLAG_${prop})
if (C_FLAG_${prop})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endif()
endmacro()
macro(chk_include_files incfile prop)
string(TOUPPER HAVE_${prop} __tmp)
check_include_files(${incfile} ${__tmp})
if (${__tmp})
add_definitions(-D${__tmp})
endif()
endmacro()
macro(chk_function_exists func)
string(TOUPPER HAVE_${func} __tmp)
check_function_exists(${func} ${__tmp})
if (${__tmp})
add_definitions(-D${__tmp})
endif()
endmacro()
macro(chk_symbol_exists incfile symbol)
string(TOUPPER HAVE_${symbol} __tmp)
check_symbol_exists(${symbol} ${incfile} ${__tmp})
if (${__tmp})
add_definitions(-D${__tmp})
endif()
endmacro()
############################# CONFIG SECTION ###########################
# Prefer local include dirs to system ones.
include_directories("${CMAKE_CURRENT_LIST_DIR}/include")
message(STATUS "liblcb configuring...")
# Platform specific configuration.
if (CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly")
add_definitions(-D_BSD_SOURCE -DFREEBSD)
include_directories("/usr/local/include")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-D_BSD_SOURCE -DDARWIN)
include_directories("/usr/local/include")
endif()
if (APPLE)
# For IPV6_PKTINFO.
add_definitions(-D__APPLE_USE_RFC_3542)
include_directories("/usr/local/include")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-D_GNU_SOURCE -DLINUX -D__USE_GNU=1)
if (BUILD_CPU_MODE STREQUAL "32")
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES rt)
endif()
# Check platform specific includes.
#chk_include_files(sys/types.h SYS_TYPES_H)
# Check platform API.
chk_function_exists(explicit_bzero)
chk_function_exists(timingsafe_bcmp)
chk_function_exists(memrchr)
chk_function_exists(memmem)
chk_function_exists(strlcpy)
chk_function_exists(strncasecmp)
chk_function_exists(reallocarray)
chk_function_exists(freezero)
chk_function_exists(pipe2)
chk_function_exists(accept4)
chk_function_exists(kqueuex)
chk_function_exists(rtprio)
chk_function_exists(pthread_setname_np)
chk_function_exists(pthread_set_name_np)
chk_function_exists(posix_spawn_file_actions_addclosefrom_np)
# Check macros.
chk_symbol_exists(sys/socket.h SOCK_CLOEXEC)
chk_symbol_exists(sys/socket.h SOCK_NONBLOCK)
# Disable some warnings.
try_c_flag(WSWITCHDEFAULT "-Wno-switch-default")
try_c_flag(WUNUSED_RESULT "-Wno-unused-result")
try_c_flag(WUNSAFE_BUFFER_USAGE "-Wno-unsafe-buffer-usage")
message(STATUS "liblcb configuring done!")
################################ SUBDIRS SECTION #######################
if (ENABLE_LIBLCB_TESTS)
# Enable testing functionality.
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
endif()
############################ TARGETS SECTION ###########################
##################### INSTALLATION #####################################