-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathCMakeLists.txt
194 lines (154 loc) · 6.3 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
cmake_minimum_required(VERSION 2.8)
project(pelikan C)
enable_testing()
# detect platform
macro(set_platform system_name)
if(${system_name} MATCHES "Darwin")
set(OS_PLATFORM "OS_DARWIN")
elseif(${system_name} MATCHES "Linux")
set(OS_PLATFORM "OS_LINUX")
else()
set(OS_PLATFORM "OS_UNSUPPORTED")
endif()
endmacro(set_platform)
set_platform(${CMAKE_SYSTEM_NAME})
if(OS_PLATFORM STREQUAL "OS_UNSUPPORTED")
message(FATAL_ERROR "unsupported operating system")
endif()
# the following sections work with config.h(.in): version, compile variables
# config.h.in has to include entries set/tested here for them to have effect
# version info
set(${PROJECT_NAME}_VERSION_MAJOR 0)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_PATCH 1)
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH})
# flags => compile-time variables: use modules/macros
option(HAVE_ASSERT_LOG "assert_log enabled by default" ON)
option(HAVE_ASSERT_PANIC "assert_panic disabled by default" OFF)
option(HAVE_LOGGING "logging enabled by default" ON)
option(HAVE_STATS "stats enabled by default" ON)
option(TARGET_PINGSERVER "build pingserver binary" ON)
option(TARGET_REDIS "build redis binary" ON)
option(TARGET_SLIMREDIS "build slimredis binary" ON)
option(TARGET_SLIMCACHE "build slimcache binary" ON)
option(TARGET_TWEMCACHE "build twemcache binary" ON)
option(TARGET_CDB "build cdb binary" ON)
option(TARGET_RESPCLI "build resp-cli binary" ON)
option(RUST_USE_MUSL "build rust deps against musl" OFF)
option(COVERAGE "code coverage" OFF)
# Note: duplicate custom targets only works with Makefile generators, will break XCode & VS
# reference: http://public.kitware.com/Bug/view.php?id=6348
set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
set(CMAKE_MACOSX_RPATH 1)
# "Always full RPATH"
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
#
if(USE_FULL_RPATH)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
elseif(DEFAULT_RPATH)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH "")
# don't add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
endif()
include(CheckSymbolExists)
check_symbol_exists(sys_signame signal.h HAVE_SIGNAME)
include(CheckFunctionExists)
check_function_exists(backtrace HAVE_BACKTRACE)
include(TestBigEndian)
test_big_endian(HAVE_BIG_ENDIAN)
# how to use config.h.in to generate config.h
# this has to be set _after_ the above checks
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_BINARY_DIR}/config.h")
# set compiler flags
# string concat is easier in 3.0, but older versions don't have the concat subcommand
# so we are using list as input until we move to new version
# TODO once we add build types, we should also set flags such as "-O2 "
add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64)
#add_definitions(-D_GNU_SOURCE )
add_definitions()
set(CFLAGS_LIST
"-std=c11 "
"-ggdb3 -O0 "
"-Wall -Wshadow -Winline "
"-Wstrict-prototypes -Wmissing-prototypes "
"-Wmissing-declarations -Wredundant-decls "
"-Wunused-function -Wunused-value -Wunused-variable "
"-fno-strict-aliasing ")
if(${OS_PLATFORM} MATCHES "OS_LINUX")
set(CFLAGS_LIST "${CFLAGS_LIST} -lrt")
endif()
string(REPLACE "" "" LOCAL_CFLAGS ${CFLAGS_LIST})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LOCAL_CFLAGS}")
if (COVERAGE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
endif(COVERAGE)
# build dependencies
# dependency: libccommon
set(CCOMMON_SOURCE_DIR "${PROJECT_SOURCE_DIR}/deps/ccommon" CACHE PATH "Path to the ccommon")
add_subdirectory(${CCOMMON_SOURCE_DIR} ${PROJECT_BINARY_DIR}/ccommon)
# other dependencies
include(FindPackageHandleStandardArgs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(Check)
if(NOT CHECK_FOUND)
message(WARNING "Check is required to build and run tests")
endif(NOT CHECK_FOUND)
if(CHECK_FOUND)
check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING)
if(NOT CHECK_WORKING)
message(WARNING "Check version too old to build tests")
endif(NOT CHECK_WORKING)
endif(CHECK_FOUND)
find_package(Threads)
enable_language(Rust)
include(CMakeCargo)
#set(CMAKE_INCLUDE_CURRENT_DIR)
include_directories(${include_directories}
"${PROJECT_BINARY_DIR}"
"${CCOMMON_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src")
# server & (cli) client
add_subdirectory(src)
# tests: always build last
if(CHECK_WORKING)
include_directories(${include_directories} "${CHECK_INCLUDES}")
add_subdirectory(test)
endif(CHECK_WORKING)
# print a summary
message(STATUS "PLATFORM: " ${OS_PLATFORM})
message(STATUS "CPPFLAGS: " ${CMAKE_CPP_FLAGS})
message(STATUS "CFLAGS: " ${CMAKE_C_FLAGS})
message(STATUS "HAVE_SIGNAME: " ${HAVE_SIGNAME})
message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE})
message(STATUS "HAVE_BIG_ENDIAN: " ${HAVE_BIG_ENDIAN})
if(DUMP_ALL)
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endif()
# Note: to uninstall targets, run:
# xargs rm < install_manifest.txt