Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 249 lines (209 sloc) 7.681 kb
9aa22fe Offered permission to copy under gplv3 license.
cjdelisle authored
1 # You may redistribute this program and/or modify it under the terms of
2 # the GNU General Public License as published by the Free Software Foundation,
3 # either version 3 of the License, or (at your option) any later version.
4 #
5 # This program is distributed in the hope that it will be useful,
6 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 # GNU General Public License for more details.
9 #
10 # You should have received a copy of the GNU General Public License
11 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d475c9c First commit for cjdns.
cjdelisle authored
12 project(cjdns C)
13 cmake_minimum_required(VERSION 2.4)
14
666fb06 old cmake wowes
Caleb James DeLisle authored
15 message(${CMAKE_VERSION})
16
d9521b5 openwrt cmake.mk really wants to build in source.
Caleb James DeLisle authored
17 if(CMAKE_BINARY_DIR STREQUAL ${CMAKE_SOURCE_DIR} AND NOT OPENWRT)
18 message( FATAL_ERROR "type: git clean -df && mkdir build && cd build && cmake .. && make" )
19 endif()
d475c9c First commit for cjdns.
cjdelisle authored
20
21 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
22 ${CMAKE_SOURCE_DIR}/cmake/modules)
23
e419a1e Massive changeset. It builds and tests pass, that's about all I can be s...
cjdelisle authored
24 # validation
def16b2 warnings about unused results.
Caleb James DeLisle authored
25 add_definitions(-Wall -Wextra -std=c99 -Werror -pedantic)
26
8f51715 #91 bunch of little compatibility crap
Caleb James DeLisle authored
27 if(WIN32)
8ae8922 @stbuehler cmake: handle cross compile/win32 stuff in main CMakeLists.txt, improve ...
stbuehler authored
28 # ISO C does not support the ‘I64’ ms_printf length modifier
29 # but PRId64 is #defined as "I64d"
8f51715 #91 bunch of little compatibility crap
Caleb James DeLisle authored
30 add_definitions(-Wno-error)
8ae8922 @stbuehler cmake: handle cross compile/win32 stuff in main CMakeLists.txt, improve ...
stbuehler authored
31
32 # proceed with ifdef hell :(
33 add_definitions(-DWIN32)
34 set(PLATFORM_LIBRARIES
35 ws2_32
36 )
37
38 # BufferAllocator.c:1:0: error: -fPIC ignored for target (all code is position independent)
39 set(WITH_PIE OFF CACHE INTERNAL "" FORCE)
40 endif()
41
461716a better system type detection
Caleb James DeLisle authored
42 if(CMAKE_SYSTEM_NAME STREQUAL SunOS)
43 set(ILLUMOS TRUE)
44 elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
45 set(LINUX TRUE)
c32f1bf @jercos Added FreeBSD interface code
jercos authored
46 elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
47 set(FREEBSD TRUE)
461716a better system type detection
Caleb James DeLisle authored
48 endif()
49
8ae8922 @stbuehler cmake: handle cross compile/win32 stuff in main CMakeLists.txt, improve ...
stbuehler authored
50 if(CMAKE_C_COMPILER MATCHES "(.*)-gcc")
51 string(REGEX REPLACE "-gcc$" "" toolchain ${CMAKE_C_COMPILER})
52 string(REGEX REPLACE ".*/" "" toolchain ${toolchain})
53 message("detected toolchain ${toolchain}")
54 set(TOOLCHAIN ${toolchain} CACHE STRING "Toolchain for compiling (prefix for -gcc, ... binaries)")
55 else()
56 set(TOOLCHAIN "" CACHE STRING "Toolchain for compiling (prefix for -gcc, ... binaries)")
57 endif()
58
59 if(TOOLCHAIN AND NOT CMAKE_C_COMPILER)
60 set(CMAKE_C_COMPILER ${TOOLCHAIN}-gcc)
61 endif()
62
63 if(TOOLCHAIN AND NOT CMAKE_CXX_COMPILER)
64 set(CMAKE_C_COMPILER ${TOOLCHAIN}-g++)
65 endif()
66
67 if(WIN32 AND TOOLCHAIN AND NOT CMAKE_CXX_COMPILER)
68 set(CMAKE_C_COMPILER ${TOOLCHAIN}-windres)
69 endif()
70
71 message("c compiler: ${CMAKE_C_COMPILER}")
72 message("c++ compiler: ${CMAKE_CXX_COMPILER}")
73 if(WIN32)
74 message("rc compiler: ${CMAKE_RC_COMPILER}")
8f51715 #91 bunch of little compatibility crap
Caleb James DeLisle authored
75 endif()
76
e393817 more platform independent way of applying -Wno-unused-result
Caleb James DeLisle authored
77 # This breaks logging since loggers are passed to functions
78 # and only used if the log level is high.
79 add_definitions(-Wno-unused-parameter)
02de592 hardening
cjdelisle authored
80
e393817 more platform independent way of applying -Wno-unused-result
Caleb James DeLisle authored
81 include(CheckCCompilerFlag)
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
82
e393817 more platform independent way of applying -Wno-unused-result
Caleb James DeLisle authored
83 # There are a number of places in Admin where read() and write() are used
84 # and they fail silently if anything goes wrong so the result is unused.
416d458 derp
Caleb James DeLisle authored
85 check_c_compiler_flag(-Wno-unused-result HAS_NO_UNUSED_RESULT)
e393817 more platform independent way of applying -Wno-unused-result
Caleb James DeLisle authored
86 if(HAS_NO_UNUSED_RESULT)
87 add_definitions(-Wno-unused-result)
88 endif()
013919c @ianlevesque Functional on OS X. Passes all tests. Requires libevent and nacl to be...
ianlevesque authored
89
426f587 GCC uses a warning and not an error which breaks checking for flag suppo...
Caleb James DeLisle authored
90 # GCC only sends a warning and not an error if it can't compile with stack canaries.
91 set(CMAKE_REQUIRED_FLAGS "-Werror")
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
92 check_c_compiler_flag(-fstack-protector-all HAS_F_STACK_PROTECTOR)
93 if(NOT HAS_F_STACK_PROTECTOR)
94 message("WARNING: Stack Smashing Protector is not available on this target.")
95 message("SSP is an important security measure to minimize the risk of a vulnerability.")
426f587 GCC uses a warning and not an error which breaks checking for flag suppo...
Caleb James DeLisle authored
96 message("")
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
97 else()
98 add_definitions(
99 # Broken GCC patch makes -fstack-protector-all not work
100 # workaround is to give -fno-stack-protector first.
101 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
102 -fno-stack-protector
103 -fstack-protector-all
104 -Wstack-protector
105 )
106 endif()
e419a1e Massive changeset. It builds and tests pass, that's about all I can be s...
cjdelisle authored
107
0eb64da Added new experimental switch level ping, also major bug fixes.
Caleb James DeLisle authored
108 check_c_compiler_flag(-fcatch-undefined-behavior HAS_CATCH_UNDEFINED)
109 if(HAS_CATCH_UNDEFINED)
110 add_definitions(-fcatch-undefined-behavior)
111 endif()
112
bb32931 Replaced all calls to memcpy() with Bits_memcpy() and Bits_memcpyConst()...
Caleb James DeLisle authored
113 # __builtin_constant_p()
114 include(CheckCSourceCompiles)
115 check_c_source_compiles("int main() { return __builtin_constant_p(0);}" HAS_BUILTIN_CONSTANT_P)
116 if (HAS_BUILTIN_CONSTANT_P)
117 add_definitions("-D HAS_BUILTIN_CONSTANT_P")
118 endif()
119
aed1593 @stbuehler Use cmake style for setting options
stbuehler authored
120 OPTION(WITH_PIE "Build a position independent executable" ON)
c99a59e Accept NO_PIE via environment variable.
Caleb James DeLisle authored
121 if (NOT "$ENV{NO_PIE}" STREQUAL "")
122 set(WITH_PIE FALSE)
123 endif()
aed1593 @stbuehler Use cmake style for setting options
stbuehler authored
124 if(WITH_PIE)
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
125 message("Building a position independent executable (ASLR security enabled).")
126 message("NOTE: PIE executables cannot run in a debugger.")
426f587 GCC uses a warning and not an error which breaks checking for flag suppo...
Caleb James DeLisle authored
127 message("")
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
128 add_definitions(-fPIE)
30fe61d Trying to fix the build for apple.
Caleb James DeLisle authored
129 set(PIE "-pie")
130 else()
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
131 message("Building a position dependent executable (ASLR security disabled).")
30fe61d Trying to fix the build for apple.
Caleb James DeLisle authored
132 set(PIE "")
2f9e4ee Allow for targets where stack protector is unavailable.
Caleb James DeLisle authored
133
134 # debugging
135 add_definitions(-g)
30fe61d Trying to fix the build for apple.
Caleb James DeLisle authored
136 endif()
8f0924d Fixed static linking bug on amd64 and allowed for disabling pie from com...
Caleb James DeLisle authored
137
461716a better system type detection
Caleb James DeLisle authored
138 if(NOT DEFINED APPLE AND NOT WIN32 AND NOT ILLUMOS)
8f0924d Fixed static linking bug on amd64 and allowed for disabling pie from com...
Caleb James DeLisle authored
139 set(CMAKE_EXE_LINKER_FLAGS "${PIE} -Wl,-z,relro,-z,now,-z,noexecstack")
f49817e -lsocket was wrong
Caleb James DeLisle authored
140 elseif(ILLUMOS)
141 # TODO make this less ugly
142 set(CMAKE_EXE_LINKER_FLAGS "${PIE} -lsocket")
30fe61d Trying to fix the build for apple.
Caleb James DeLisle authored
143 else()
5b86718 solaris doesn't support security
Caleb James DeLisle authored
144 # apple seems to set noexecstack by default and not support relro.
30fe61d Trying to fix the build for apple.
Caleb James DeLisle authored
145 set(CMAKE_EXE_LINKER_FLAGS "${PIE}")
146 endif()
02de592 hardening
cjdelisle authored
147
bb32931 Replaced all calls to memcpy() with Bits_memcpy() and Bits_memcpyConst()...
Caleb James DeLisle authored
148 # logging
49a5d9c Set default logging back to DEBUG and continue to honer environment var.
Caleb James DeLisle authored
149 SET(Log_LEVEL DEBUG CACHE STRING "Log level (KEYS, DEBUG, INFO, WARN, ERROR, CRITICAL)")
150 if (NOT "$ENV{Log_LEVEL}" STREQUAL "")
151 set(Log_LEVEL "$ENV{Log_LEVEL}")
152 endif()
aed1593 @stbuehler Use cmake style for setting options
stbuehler authored
153 if (${Log_LEVEL} STREQUAL "KEYS")
154 message("\n\nEXPECT TO SEE PRIVATE KEYS PRINTED IN YOUR LOGS!\n\n")
155 endif (${Log_LEVEL} STREQUAL "KEYS")
156 add_definitions("-D Log_${Log_LEVEL}")
55fb7a7 Added KEYS logging level and made logging level choosable at build time.
cjdelisle authored
157
64ea89f Added option for GCC/gold link time optimization.
Caleb James DeLisle authored
158 # vrooooooom
8d29ead @stbuehler cmake: set build type RelWithDebInfo by default instead of forcing -O2
stbuehler authored
159 add_definitions(-funroll-loops)
160
161 IF(NOT CMAKE_BUILD_TYPE)
162 # default to RelWithDebInfo (-g -O2)
163 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
164 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
165 FORCE)
166 ENDIF(NOT CMAKE_BUILD_TYPE)
64ea89f Added option for GCC/gold link time optimization.
Caleb James DeLisle authored
167
aed1593 @stbuehler Use cmake style for setting options
stbuehler authored
168 OPTION(WITH_LTO "Building with link time optimization.")
169 if(WITH_LTO)
64ea89f Added option for GCC/gold link time optimization.
Caleb James DeLisle authored
170 add_definitions(-flto)
171 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -flto -fuse-linker-plugin -fwhole-program")
172 endif()
173
a96c403 Continued work on router module.
cjdelisle authored
174
2e890a3 Define CJDNS_MAX_PEERS in the top level CMakeLists.txt since NumberCompr...
Caleb James DeLisle authored
175 # Max direct connections to the switch.
176 SET(CJDNS_MAX_PEERS 256 CACHE STRING "maximum number of peers")
177 add_definitions("-D CJDNS_MAX_PEERS=${CJDNS_MAX_PEERS}")
178
179
78cea80 @stbuehler allow overwriting GIT_VERSION for building without git
stbuehler authored
180 if(NOT "$ENV{GIT_VERSION}" STREQUAL "")
181 SET(GIT_VERSION "$ENV{GIT_VERSION}")
182 elseif(EXISTS .git_commit)
183 FILE(READ .git_commit GIT_VERSION)
184 else()
185 find_package(Git)
186 execute_process(
187 COMMAND ${GIT_EXECUTABLE} log -n 1
188 OUTPUT_VARIABLE GIT_LOG
189 OUTPUT_STRIP_TRAILING_WHITESPACE
190 )
191 string(REGEX MATCH "[0-9a-f]*\n" GIT_VERSION "${GIT_LOG}")
192 string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
193 endif()
194 # GIT_VERSION is used in dht/dhtcore/CMakeLists.txt
195
d475c9c First commit for cjdns.
cjdelisle authored
196 include_directories(${CMAKE_SOURCE_DIR})
197
8d96d7e Shifted stuff around and removed unused code.
cjdelisle authored
198 find_package(Libevent2 REQUIRED)
199 include_directories(${LIBEVENT2_INCLUDE_DIRS})
200
201 find_package(NACL REQUIRED)
202 include_directories(${NACL_INCLUDE_DIRS})
203
970cabf Added administration interface
cjdelisle authored
204 add_subdirectory(admin)
2f8cb1d Refactoring and finished rewriting libbenc
cjdelisle authored
205 add_subdirectory(benc)
d475c9c First commit for cjdns.
cjdelisle authored
206 add_subdirectory(crypto)
207 add_subdirectory(dht)
970cabf Added administration interface
cjdelisle authored
208 add_subdirectory(interface)
209 add_subdirectory(io)
210 add_subdirectory(memory)
7c7005c Added rolling average utility.
cjdelisle authored
211 add_subdirectory(util)
1706066 Added switch core
cjdelisle authored
212 add_subdirectory(switch)
0eb64da Added new experimental switch level ping, also major bug fixes.
Caleb James DeLisle authored
213 add_subdirectory(net)
d475c9c First commit for cjdns.
cjdelisle authored
214
6ac4ca5 Got SwitchConnectorModule into a compilable state and removed some old s...
cjdelisle authored
215 add_executable(cjdroute cjdroute.c)
216 target_link_libraries(cjdroute
217 crypto
e796eaa need to link the benchmark library.
Caleb James DeLisle authored
218 crypto_benchmark
6ac4ca5 Got SwitchConnectorModule into a compilable state and removed some old s...
cjdelisle authored
219 interface
220 switch
221 dht
222 dhtcore
2f8cb1d Refactoring and finished rewriting libbenc
cjdelisle authored
223 cjdbenc
224 cjdbenc_JsonBencSerializer
17da216 Renamed libMemAllocator libcjdmemory
cjdelisle authored
225 cjdmemory
970cabf Added administration interface
cjdelisle authored
226 cjdadmin
0eb64da Added new experimental switch level ping, also major bug fixes.
Caleb James DeLisle authored
227 cjdnet
c3a908e debugging and bugfixes
cjdelisle authored
228 ${LIBEVENT2_LIBRARIES}
8f51715 #91 bunch of little compatibility crap
Caleb James DeLisle authored
229 ${PLATFORM_LIBRARIES}
6ac4ca5 Got SwitchConnectorModule into a compilable state and removed some old s...
cjdelisle authored
230 )
6baa018 Changed RouterModule to handle new address types, added Address.h, began...
cjdelisle authored
231
9fba0b8 @stbuehler cmake: Replace install_targets with install
stbuehler authored
232 INSTALL(TARGETS cjdroute RUNTIME DESTINATION bin)
181c74f A few changes to accomidate openwrt.
Caleb James DeLisle authored
233
aed1593 @stbuehler Use cmake style for setting options
stbuehler authored
234 OPTION(NO_CODESYTLE "No codestyle checks")
235
51cb337 Run codestyle check as part of build.
Caleb James DeLisle authored
236 # check codestyle
0adcdea NO_CODESTYLE disables codestyle check.
Caleb James DeLisle authored
237 if(NOT NO_CODESTYLE)
238 set(checker ${CMAKE_SOURCE_DIR}/cmake/modules/CheckCodestyle.cmake)
239 add_custom_command(OUTPUT check.codestyle
240 COMMAND ${CMAKE_COMMAND}
d0e4677 @stbuehler Check codestyle: ignore all *build* subdirectories
stbuehler authored
241 -DCSD=${CMAKE_SOURCE_DIR} -DSKIP=CMakeFiles -P ${checker}
0adcdea NO_CODESTYLE disables codestyle check.
Caleb James DeLisle authored
242 )
243 add_custom_target(check_output ALL DEPENDS check.codestyle)
244 endif()
51cb337 Run codestyle check as part of build.
Caleb James DeLisle authored
245
d475c9c First commit for cjdns.
cjdelisle authored
246 # Everything must be tested.
247 enable_testing()
80e0443 Fixed packet-of-death abort() bug and added basic integration / packet i...
Caleb James DeLisle authored
248 add_subdirectory(test)
Something went wrong with that request. Please try again.