-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
161 lines (126 loc) · 3.93 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
cmake_minimum_required(VERSION 3.22)
if(CLANG)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
elseif()
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
endif()
project(xbft)
set(PROJECT_VERSION 1.0.0)
if(NOT DEFINED COMPILE_3RD)
option(COMPILE_3RD "Compile 3rd" ON)
endif()
message(STATUS "COMPILE_3RD=" ${COMPILE_3RD})
if(COMPILE_3RD)
set(XBFT_3RD_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd)
if(NOT EXISTS ${XBFT_3RD_SRC_DIR})
message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init")
endif()
endif()
set(XBFT_3RD_LIB /home/xbft-3rd)
set(XBFT_DEPEND_LIB "-lpthread -ldl -lz -lstdc++fs")
set(XBFT_DEPENDS_LIBS
gtest
gmock
protobuf
ssl
crypto
ed25519
glog
yaml-cpp
)
add_compile_options(-Wall -Werror -fpermissive -Woverloaded-virtual -D_GLIBCXX_USE_CXX11_ABI=0 -DASIO_STANDALONE)
# for debug or release flag
if(NOT DEFINED RELEASE)
option(RELEASE "For Release" OFF)
endif()
if(RELEASE)
add_compile_options(-O3)
else()
add_compile_options(-O0 -g)
endif()
set(CODE_COVER ON)
if(NOT DEFINED CODE_COVER)
option(CODE_COVER "Use gcov " ON)
endif()
message(STATUS CODE_COVER=${CODE_COVER})
IF(CODE_COVER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
ENDIF()
if(NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
endif()
if(NOT BUILD_SHARED_LIBS)
option (BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
if (NOT BUILD_STATIC_LIBS)
option (BUILD_STATIC_LIBS "Build static libraries" ON)
endif()
if(NOT DEFINED SANITIZER)
option(SANITIZER "option for sannitizer tool" OFF)
endif()
if(SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
if(NOT DEFINED CODECHECK)
option(CODECHECK "option for codecheck tool clang-tidy" OFF)
endif()
set(CODECHECK ON)
message(STATUS "CODECHECK:${CODECHECK}")
message(STATUS "CODE_COVER:${CODE_COVER}")
if(RELEASE)
set(CODECHECK FALSE)
set(SANITIZER FALSE)
message(STATUS "CODECHECK and SANITIZER forced to FALSE because Debug type is Release")
endif()
if(COMPILE_3RD)
include(cmake/3rd.cmake)
endif()
#include(cmake/clang-tidy.cmake)
include(cmake/proto.cmake)
if(NOT EXISTS ${XBFT_3RD_LIB})
message(FATAL_ERROR "${XBFT_3RD_LIB} not exist...")
endif()
if(NOT DEFINED GLOG_CUSTOM_PREFIX_SUPPORT)
option(GLOG_CUSTOM_PREFIX_SUPPORT "option for GLOG_CUSTOM_PREFIX_SUPPORT" ON)
endif()
if(GLOG_CUSTOM_PREFIX_SUPPORT)
add_definitions(-DGLOG_CUSTOM_PREFIX_SUPPORT)
message(STATUS "-DGLOG_CUSTOM_PREFIX_SUPPORT=" ${GLOG_CUSTOM_PREFIX_SUPPORT})
endif(GLOG_CUSTOM_PREFIX_SUPPORT)
if(NOT DEFINED BUILD_UNIT_TESTS_OPT)
option(BUILD_UNIT_TESTS_OPT "Build unit tests" ON)
endif()
if(NOT DEFINED BUILD_SAMPLE_OPT)
option(BUILD_SAMPLE_OPT "Build sample" ON)
endif()
# c++17
add_definitions(-std=c++1z)
set(XBFT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(XBFT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(XBFT_ROOT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(XBFT_INCLUDE_DIR
${XBFT_3RD_LIB}/include
${XBFT_ROOT_DIR}/include
${XBFT_ROOT_DIR}/include/utils
)
set(INSTALL_LIB_PATH ${CMAKE_INSTALL_PREFIX}/lib)
set(INSTALL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/include/xbft)
set(INSTALL_SAMPLE_PATH ${CMAKE_INSTALL_PREFIX}/test/sample)
set(INSTALL_UNITTEST_PATH ${CMAKE_INSTALL_PREFIX}/test/unittest)
link_directories(
${XBFT_3RD_LIB}/lib64
${XBFT_3RD_LIB}/lib
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib)
if(BUILD_UNIT_TESTS_OPT)
set(UNITTEST_SRC_DIR ${XBFT_ROOT_DIR}/test/unittest)
add_subdirectory(${UNITTEST_SRC_DIR})
endif()
if(BUILD_SAMPLE_OPT)
set(SAMPLE_SRC_DIR ${XBFT_ROOT_DIR}/test/sample)
add_subdirectory(${SAMPLE_SRC_DIR})
endif()