forked from cjdelisle/cjdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
131 lines (111 loc) · 3.97 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
# You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
project(cjdns C)
cmake_minimum_required(VERSION 2.4)
if(CMAKE_BINARY_DIR STREQUAL ${CMAKE_SOURCE_DIR} AND NOT OPENWRT)
message( FATAL_ERROR "type: git clean -df && mkdir build && cd build && cmake .. && make" )
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake/modules)
# validation
add_definitions(-Wall -Wextra -std=c99 -Werror -pedantic)
# This breaks logging since loggers are passed to functions
# and only used if the log level is high.
add_definitions(-Wno-unused-parameter)
include(CheckCCompilerFlag)
# There are a number of places in Admin where read() and write() are used
# and they fail silently if anything goes wrong so the result is unused.
check_c_compiler_flag(-Wno-unused-result HAS_NO_UNUSED_RESULT)
if(HAS_NO_UNUSED_RESULT)
add_definitions(-Wno-unused-result)
endif()
# GCC only sends a warning and not an error if it can't compile with stack canaries.
set(CMAKE_REQUIRED_FLAGS "-Werror")
check_c_compiler_flag(-fstack-protector-all HAS_F_STACK_PROTECTOR)
if(NOT HAS_F_STACK_PROTECTOR)
message("WARNING: Stack Smashing Protector is not available on this target.")
message("SSP is an important security measure to minimize the risk of a vulnerability.")
message("")
else()
add_definitions(
# Broken GCC patch makes -fstack-protector-all not work
# workaround is to give -fno-stack-protector first.
# see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
-fno-stack-protector
-fstack-protector-all
-Wstack-protector
)
endif()
# allow position independent executable to be turned off with NO_PIE cmake ..
if(NOT "$ENV{NO_PIE}" STREQUAL "")
set(NO_PIE TRUE)
endif()
if(NOT NO_PIE)
message("Building a position independent executable (ASLR security enabled).")
message("NOTE: PIE executables cannot run in a debugger.")
message("")
add_definitions(-fPIE)
set(PIE "-pie")
else()
message("Building a position dependent executable (ASLR security disabled).")
set(PIE "")
# debugging
add_definitions(-g)
endif()
if(NOT DEFINED APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${PIE} -Wl,-z,relro,-z,now,-z,noexecstack")
else()
# apple seems to set noexecstack by defualt and not support relro.
set(CMAKE_EXE_LINKER_FLAGS "${PIE}")
endif()
if(NOT $ENV{Log_LEVEL} STREQUAL "")
string(TOUPPER $ENV{Log_LEVEL} LEVEL)
message("Log_LEVEL = ${LEVEL}")
if ($ENV{Log_LEVEL} STREQUAL "KEYS")
message("\n\nEXPECT TO SEE PRIVATE KEYS PRINTED IN YOUR LOGS!\n\n")
endif ($ENV{Log_LEVEL} STREQUAL "KEYS")
add_definitions("-D Log_${LEVEL}")
else()
add_definitions("-D Log_DEBUG")
endif()
#add_definitions(-O3 -funroll-loops)
include_directories(${CMAKE_SOURCE_DIR})
find_package(Libevent2 REQUIRED)
include_directories(${LIBEVENT2_INCLUDE_DIRS})
find_package(NACL REQUIRED)
include_directories(${NACL_INCLUDE_DIRS})
add_subdirectory(admin)
add_subdirectory(benc)
add_subdirectory(crypto)
add_subdirectory(dht)
add_subdirectory(interface)
add_subdirectory(io)
add_subdirectory(memory)
add_subdirectory(util)
add_subdirectory(switch)
add_executable(cjdroute cjdroute.c)
target_link_libraries(cjdroute
crypto
interface
switch
dht
dhtcore
cjdbenc
cjdbenc_JsonBencSerializer
cjdmemory
cjdadmin
${LIBEVENT2_LIBRARIES}
)
install_targets(/bin cjdroute)
# Everything must be tested.
enable_testing()
add_subdirectory(test)