forked from monero-project/kovri
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
215 lines (189 loc) · 7.52 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
cmake_minimum_required(VERSION 2.8.12)
project("kovri")
# Configurable options
option(KOVRI_DATA_PATH "The path to the kovri data folder")
option(WITH_BENCHMARKS "Build with benchmarks" OFF)
option(WITH_BINARY "Build binary" ON)
option(WITH_CRYPTOPP "Build with Crypto++" ON) # Default ON unless we switch libraries
option(WITH_DOXYGEN "Enable support for Doxygen" OFF)
option(WITH_HARDENING "Use hardening compiler flags" OFF)
option(WITH_LIBRARY "Build library" ON)
option(WITH_OPTIMIZE "Optimization flags" OFF)
option(WITH_STATIC "Static build" OFF)
option(WITH_SUPERCOP "Build Ed25519 using the ref10 implementation from SUPERCOP" ON) # Default ON unless we switch implementations
option(WITH_TESTS "Build unit tests" OFF)
option(WITH_UPNP "Include support for UPnP client" OFF)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Default build is Debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Compiler flags customization (by vendor)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Winvalid-pch -maes")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic")
# TODO: The following is incompatible with static build and enabled hardening
# for OpenWRT.
# Multiple definitions of __stack_chk_fail (libssp & libc)
set(CMAKE_CXX_FLAGS_MINSIZEREL
"${CMAKE_CXX_FLAGS_MINSIZEREL} -flto -s -ffunction-sections -fdata-sections")
# -flto is added from above
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,--gc-sections")
endif()
# Check for c++14 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" CXX14_SUPPORTED)
if(CXX14_SUPPORTED)
add_definitions("-std=c++14")
elseif(NOT MSVC)
message(SEND_ERROR "C++14 standard not supported by compiler. See building instructions for minimum requirements.")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(WITH_HARDENING)
add_definitions("-D_FORTIFY_SOURCE=2")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fstack-protector-strong -fPIE --param ssp-buffer-size=4 -z relro -z now")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(SEND_ERROR "Clang is currently not supported. See building instructions for minimum requirements.")
endif()
# Compiler flags customization (by system)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
# "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8
add_definitions("-D_GLIBCXX_USE_NANOSLEEP=1")
endif()
if(WITH_UPNP)
add_definitions(-DUSE_UPNP)
if(NOT MSVC)
set(DL_LIB ${CMAKE_DL_LIBS})
endif()
endif()
if(WITH_OPTIMIZE AND (NOT MSVC))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
# Libraries
# TODO: once CMake 3.1+ becomes mainstream, see e.g.
# http://stackoverflow.com/a/29871891/673826 use imported Threads::Threads
# instead
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG) # compile time flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
if(WITH_STATIC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BUILD_SHARED_LIBS OFF)
if(NOT WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
if(${CMAKE_CXX_COMPILER} MATCHES ".*-openwrt-.*")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_THREAD_LIBS_INIT
"gcc_eh -Wl,-u,pthread_create,-u,pthread_once,-u,pthread_mutex_lock,-u,pthread_mutex_unlock,-u,pthread_join,-u,pthread_equal,-u,pthread_detach,-u,pthread_cond_wait,-u,pthread_cond_signal,-u,pthread_cond_destroy,-u,pthread_cond_broadcast,-u,pthread_cancel")
endif()
endif()
if(NOT WIN32)
# TODO: Consider separate compilation for COMMON_SRC for library.
# No need in -fPIC overhead for binary if not interested in library
# HINT: revert c266cff CMakeLists.txt: compilation speed up
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
find_package(
Boost
COMPONENTS
chrono log
program_options date_time
thread system
filesystem regex
REQUIRED)
if(NOT Boost_FOUND)
message(SEND_ERROR "Boost not found, or version below 1.46. Please download Boost!")
else()
add_definitions(-DBOOST_ALL_DYN_LINK)
include_directories(${Boost_INCLUDE_DIRS})
endif()
if(WITH_CRYPTOPP)
find_package(CryptoPP REQUIRED)
if(NOT DEFINED CRYPTO++_INCLUDE_DIR)
message(SEND_ERROR "Could not find Crypto++. Please download and install it first!")
endif()
include_directories(${CRYPTO++_INCLUDE_DIR})
endif()
if(APPLE)
# If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
if (NOT OpenSSL_DIR)
execute_process (COMMAND brew --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
find_package(OpenSSL REQUIRED)
if(NOT DEFINED OPENSSL_INCLUDE_DIR)
message(SEND_ERROR "Could not find OpenSSL. Please download and install it first!")
else()
include_directories(${OPENSSL_INCLUDE_DIR})
endif()
find_package(MiniUPnPc)
if(NOT ${MINIUPNPC_FOUND})
set(WITH_UPNP OFF)
endif()
# Doxygen support
if(WITH_DOXYGEN)
include(UseDoxygen)
endif()
# Load remaining includes
include_directories(${CMAKE_SOURCE_DIR})
# Set default path
if(KOVRI_DATA_PATH)
set(KOVRI_DATA_DIR ${KOVRI_DATA_PATH})
# Using custom path, make sure the code knows about this
add_definitions(-DKOVRI_CUSTOM_DATA_PATH="${KOVRI_DATA_PATH}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(KOVRI_DATA_DIR "$ENV{APPDATA}\\kovri")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(KOVRI_DATA_DIR "$ENV{HOME}/Library/Application Support/kovri")
else()
set(KOVRI_DATA_DIR "$ENV{HOME}/.kovri")
endif()
# Show summary
message(STATUS "---------------------------------------")
message(STATUS "Build type : ${CMAKE_BUILD_TYPE}")
message(STATUS "Compiler vendor : ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "Compiler version : ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "Compiler path : ${CMAKE_CXX_COMPILER}")
message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Kovri data directory: ${KOVRI_DATA_DIR}")
message(STATUS "Options:")
message(STATUS " BENCHMARKS : ${WITH_BENCHMARKS}")
message(STATUS " BINARY : ${WITH_BINARY}")
message(STATUS " CRYPTOPP : ${WITH_CRYPTOPP}")
message(STATUS " DOXYGEN : ${WITH_DOXYGEN}")
message(STATUS " HARDENING : ${WITH_HARDENING}")
message(STATUS " LIBRARY : ${WITH_LIBRARY}")
message(STATUS " OPTIMIZATION : ${WITH_OPTIMIZE}")
message(STATUS " STATIC BUILD : ${WITH_STATIC}")
message(STATUS " SUPERCOP : ${WITH_SUPERCOP}")
message(STATUS " TESTS : ${WITH_TESTS}")
message(STATUS " UPnP : ${WITH_UPNP}")
message(STATUS "---------------------------------------")
# Handle paths nicely
include(GNUInstallDirs)
set(APP_NAME "${PROJECT_NAME}-app")
set(CLIENT_NAME "${PROJECT_NAME}-client")
set(CORE_NAME "${PROJECT_NAME}-core")
set(TESTS_NAME "${PROJECT_NAME}-tests")
set(BENCHMARKS_NAME "${PROJECT_NAME}-benchmarks")
add_subdirectory(src)
# Copy needed resources
if(WITH_BINARY)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/pkg/certificates" DESTINATION "${KOVRI_DATA_DIR}/")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/pkg/kovri.conf" DESTINATION "${KOVRI_DATA_DIR}/")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/pkg/tunnels.conf" DESTINATION "${KOVRI_DATA_DIR}/")
endif()
# vim: noai:ts=2:sw=2