summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-11 18:49:44 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-14 14:32:01 +0100
commitd1f16e27b8cc543f79e326713b6d40fce5c82acf (patch)
tree772356869cf49fbf1f90249cf28f66ea02e8d99a /CMakeLists.txt
parent45d28904b92c825d1ac88be9edae8baabcd4bba1 (diff)
Add option to build static libraries.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt156
1 files changed, 56 insertions, 100 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7e560198..e42527c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,7 @@ include(CTest)
6# versions in a synchronised way. 6# versions in a synchronised way.
7set(PROJECT_VERSION "0.0.0") 7set(PROJECT_VERSION "0.0.0")
8 8
9set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
9 10
10################################################################################ 11################################################################################
11# 12#
@@ -13,12 +14,19 @@ set(PROJECT_VERSION "0.0.0")
13# 14#
14################################################################################ 15################################################################################
15 16
17include(CheckCCompilerFlag)
18include(ModulePackage)
19
16set(CMAKE_MACOSX_RPATH ON) 20set(CMAKE_MACOSX_RPATH ON)
17 21
18option(DEBUG "Enable assertions and other debugging facilities" OFF) 22option(DEBUG "Enable assertions and other debugging facilities" OFF)
19if(DEBUG) 23if(DEBUG)
20 add_definitions(-DTOX_DEBUG=1) 24 add_definitions(-DTOX_DEBUG=1)
21 add_definitions(-DMIN_LOGGER_LEVEL=LOG_TRACE) 25 add_definitions(-DMIN_LOGGER_LEVEL=LOG_TRACE)
26 check_c_compiler_flag("-g3" HAVE_G3)
27 if(HAVE_G3)
28 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
29 endif()
22endif() 30endif()
23 31
24option(ASSOC_DHT "Enable module to store currently unused ID <=> IP associations" OFF) 32option(ASSOC_DHT "Enable module to store currently unused ID <=> IP associations" OFF)
@@ -28,76 +36,38 @@ endif()
28 36
29option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF) 37option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF)
30if(ASAN) 38if(ASAN)
31 include(CheckCCompilerFlag)
32 set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") 39 set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
33 set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address") 40 set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
34 check_c_compiler_flag("-fsanitize=address" HAVE_ASAN) 41 check_c_compiler_flag("-fsanitize=address" HAVE_ASAN)
35 if(HAVE_ASAN) 42 if(HAVE_ASAN)
36 set(CMAKE_C_FLAGS "-fsanitize=address") 43 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
37 endif() 44 endif()
38 set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") 45 set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")
39endif() 46endif()
40 47
41find_package(PkgConfig REQUIRED)
42find_package(Threads REQUIRED) 48find_package(Threads REQUIRED)
43 49
44find_library(UTIL_LIBRARIES util ) 50find_library(NCURSES_LIBRARIES ncurses )
45find_library(RT_LIBRARIES rt ) 51find_library(UTIL_LIBRARIES util )
52find_library(RT_LIBRARIES rt )
46 53
47# For toxcore. 54# For toxcore.
48pkg_search_module(LIBSODIUM REQUIRED libsodium ) 55pkg_use_module(LIBSODIUM REQUIRED libsodium )
49 56
50# For toxav. 57# For toxav.
51pkg_search_module(OPUS REQUIRED opus ) 58pkg_use_module(OPUS REQUIRED opus )
52pkg_search_module(VPX REQUIRED vpx ) 59pkg_use_module(VPX REQUIRED vpx )
53 60
54# For tox-bootstrapd. 61# For tox-bootstrapd.
55pkg_search_module(LIBCONFIG libconfig ) 62pkg_use_module(LIBCONFIG libconfig )
56 63
57# For auto tests. 64# For auto tests.
58pkg_search_module(CHECK check ) 65pkg_use_module(CHECK check )
59 66
60# For av_test. 67# For av_test.
61pkg_search_module(OPENCV opencv ) 68pkg_use_module(OPENCV opencv )
62pkg_search_module(PORTAUDIO portaudio-2.0) 69pkg_use_module(PORTAUDIO portaudio-2.0 )
63pkg_search_module(SNDFILE sndfile ) 70pkg_use_module(SNDFILE sndfile )
64
65# TODO(iphydf): fold the pkg_search_module call into this function.
66function(pkg_use_module mod)
67 if(${mod}_FOUND)
68 link_directories(${${mod}_LIBRARY_DIRS})
69 include_directories(${${mod}_INCLUDE_DIRS})
70 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}")
71 endif()
72endfunction()
73
74pkg_use_module(LIBSODIUM)
75
76pkg_use_module(OPUS)
77pkg_use_module(VPX)
78
79pkg_use_module(LIBCONFIG)
80
81pkg_use_module(CHECK)
82
83pkg_use_module(OPENCV)
84pkg_use_module(PORTAUDIO)
85pkg_use_module(SNDFILE)
86
87
88# Users can call cmake -DLIBTYPE=STATIC or -DLIBTYPE=SHARED to override this.
89if(NOT LIBTYPE)
90 if(WIN32)
91 # Our win32 builds are fully static, since we use the MXE cross compiling
92 # environment, which builds everything statically by default. Building
93 # shared libraries will result in multiple definition errors, since multiple
94 # tox libraries will link against libsodium and other libraries that are
95 # built statically in MXE.
96 set(LIBTYPE STATIC)
97 else()
98 set(LIBTYPE SHARED)
99 endif()
100endif()
101 71
102 72
103################################################################################ 73################################################################################
@@ -118,46 +88,46 @@ set(toxcore_PKGCONFIG_LIBS)
118 88
119# LAYER 1: Crypto core 89# LAYER 1: Crypto core
120# -------------------- 90# --------------------
121add_library(toxcrypto ${LIBTYPE} 91add_module(toxcrypto
122 toxcore/crypto_core.c) 92 toxcore/crypto_core.c)
123target_link_libraries(toxcrypto ${LIBSODIUM_LIBRARIES}) 93target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES})
124 94
125# LAYER 2: Basic networking 95# LAYER 2: Basic networking
126# ------------------------- 96# -------------------------
127add_library(toxnetwork ${LIBTYPE} 97add_module(toxnetwork
128 toxcore/logger.c 98 toxcore/logger.c
129 toxcore/network.c 99 toxcore/network.c
130 toxcore/util.c) 100 toxcore/util.c)
131target_link_libraries(toxnetwork toxcrypto) 101target_link_modules(toxnetwork toxcrypto)
132 102
133if(CMAKE_THREAD_LIBS_INIT) 103if(CMAKE_THREAD_LIBS_INIT)
134 target_link_libraries(toxnetwork ${CMAKE_THREAD_LIBS_INIT}) 104 target_link_modules(toxnetwork ${CMAKE_THREAD_LIBS_INIT})
135 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-l${CMAKE_THREAD_LIBS_INIT}") 105 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-l${CMAKE_THREAD_LIBS_INIT}")
136endif() 106endif()
137 107
138if(RT_LIBRARIES) 108if(RT_LIBRARIES)
139 target_link_libraries(toxnetwork ${RT_LIBRARIES}) 109 target_link_modules(toxnetwork ${RT_LIBRARIES})
140 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt") 110 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt")
141endif() 111endif()
142 112
143if(WIN32) 113if(WIN32)
144 target_link_libraries(toxnetwork ws2_32 iphlpapi) 114 target_link_modules(toxnetwork ws2_32 iphlpapi)
145 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi") 115 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
146endif() 116endif()
147 117
148# LAYER 3: Distributed Hash Table 118# LAYER 3: Distributed Hash Table
149# ------------------------------- 119# -------------------------------
150add_library(toxdht ${LIBTYPE} 120add_module(toxdht
151 toxcore/DHT.c 121 toxcore/DHT.c
152 toxcore/LAN_discovery.c 122 toxcore/LAN_discovery.c
153 toxcore/assoc.c 123 toxcore/assoc.c
154 toxcore/ping.c 124 toxcore/ping.c
155 toxcore/ping_array.c) 125 toxcore/ping_array.c)
156target_link_libraries(toxdht toxnetwork) 126target_link_modules(toxdht toxnetwork)
157 127
158# LAYER 4: Onion routing, TCP connections, crypto connections 128# LAYER 4: Onion routing, TCP connections, crypto connections
159# ----------------------------------------------------------- 129# -----------------------------------------------------------
160add_library(toxnetcrypto ${LIBTYPE} 130add_module(toxnetcrypto
161 toxcore/TCP_client.c 131 toxcore/TCP_client.c
162 toxcore/TCP_connection.c 132 toxcore/TCP_connection.c
163 toxcore/TCP_server.c 133 toxcore/TCP_server.c
@@ -166,33 +136,33 @@ add_library(toxnetcrypto ${LIBTYPE}
166 toxcore/onion.c 136 toxcore/onion.c
167 toxcore/onion_announce.c 137 toxcore/onion_announce.c
168 toxcore/onion_client.c) 138 toxcore/onion_client.c)
169target_link_libraries(toxnetcrypto toxdht) 139target_link_modules(toxnetcrypto toxdht)
170 140
171# LAYER 5: Friend requests and connections 141# LAYER 5: Friend requests and connections
172# ---------------------------------------- 142# ----------------------------------------
173add_library(toxfriends ${LIBTYPE} 143add_module(toxfriends
174 toxcore/friend_connection.c 144 toxcore/friend_connection.c
175 toxcore/friend_requests.c) 145 toxcore/friend_requests.c)
176target_link_libraries(toxfriends toxnetcrypto) 146target_link_modules(toxfriends toxnetcrypto)
177 147
178# LAYER 6: Tox messenger 148# LAYER 6: Tox messenger
179# ---------------------- 149# ----------------------
180add_library(toxmessenger ${LIBTYPE} 150add_module(toxmessenger
181 toxcore/Messenger.c) 151 toxcore/Messenger.c)
182target_link_libraries(toxmessenger toxfriends) 152target_link_modules(toxmessenger toxfriends)
183 153
184# LAYER 7: Group chats 154# LAYER 7: Group chats
185# -------------------- 155# --------------------
186add_library(toxgroup ${LIBTYPE} 156add_module(toxgroup
187 toxcore/group.c) 157 toxcore/group.c)
188target_link_libraries(toxgroup toxmessenger) 158target_link_modules(toxgroup toxmessenger)
189 159
190# LAYER 8: Public API 160# LAYER 8: Public API
191# ------------------- 161# -------------------
192add_library(toxcore ${LIBTYPE} 162add_module(toxcore
193 toxcore/tox.c 163 toxcore/tox.c
194 toxcore/tox_group.c) 164 toxcore/tox_group.c)
195target_link_libraries(toxcore toxgroup) 165target_link_modules(toxcore toxgroup)
196 166
197 167
198################################################################################ 168################################################################################
@@ -201,7 +171,7 @@ target_link_libraries(toxcore toxgroup)
201# 171#
202################################################################################ 172################################################################################
203 173
204add_library(toxav ${LIBTYPE} 174add_module(toxav
205 toxav/audio.c 175 toxav/audio.c
206 toxav/bwcontroller.c 176 toxav/bwcontroller.c
207 toxav/group.c 177 toxav/group.c
@@ -210,7 +180,7 @@ add_library(toxav ${LIBTYPE}
210 toxav/toxav.c 180 toxav/toxav.c
211 toxav/toxav_old.c 181 toxav/toxav_old.c
212 toxav/video.c) 182 toxav/video.c)
213target_link_libraries(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) 183target_link_modules(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
214 184
215 185
216################################################################################ 186################################################################################
@@ -219,13 +189,13 @@ target_link_libraries(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
219# 189#
220################################################################################ 190################################################################################
221 191
222add_library(toxdns ${LIBTYPE} 192add_module(toxdns
223 toxdns/toxdns.c) 193 toxdns/toxdns.c)
224target_link_libraries(toxdns toxcore) 194target_link_modules(toxdns toxcore)
225 195
226add_library(toxencryptsave ${LIBTYPE} 196add_module(toxencryptsave
227 toxencryptsave/toxencryptsave.c) 197 toxencryptsave/toxencryptsave.c)
228target_link_libraries(toxencryptsave toxcore) 198target_link_modules(toxencryptsave toxcore)
229 199
230 200
231################################################################################ 201################################################################################
@@ -240,7 +210,7 @@ add_test(format_test
240function(auto_test target) 210function(auto_test target)
241 if(CHECK_FOUND) 211 if(CHECK_FOUND)
242 add_executable(auto_${target} auto_tests/${target}.c) 212 add_executable(auto_${target} auto_tests/${target}.c)
243 target_link_libraries(auto_${target} 213 target_link_modules(auto_${target}
244 toxcore 214 toxcore
245 toxav 215 toxav
246 toxencryptsave 216 toxencryptsave
@@ -272,7 +242,7 @@ auto_test(toxav_many_test)
272add_executable(DHT_bootstrap 242add_executable(DHT_bootstrap
273 other/DHT_bootstrap.c 243 other/DHT_bootstrap.c
274 other/bootstrap_node_packets.c) 244 other/bootstrap_node_packets.c)
275target_link_libraries(DHT_bootstrap toxnetcrypto) 245target_link_modules(DHT_bootstrap toxnetcrypto)
276 246
277if(LIBCONFIG_FOUND) 247if(LIBCONFIG_FOUND)
278 add_executable(tox-bootstrapd 248 add_executable(tox-bootstrapd
@@ -287,8 +257,7 @@ if(LIBCONFIG_FOUND)
287 other/bootstrap_daemon/src/global.h 257 other/bootstrap_daemon/src/global.h
288 other/bootstrap_node_packets.c 258 other/bootstrap_node_packets.c
289 other/bootstrap_node_packets.h) 259 other/bootstrap_node_packets.h)
290 260 target_link_modules(tox-bootstrapd toxnetcrypto ${LIBCONFIG_LIBRARIES})
291 target_link_libraries(tox-bootstrapd toxnetcrypto ${LIBCONFIG_LIBRARIES})
292endif() 261endif()
293 262
294 263
@@ -300,7 +269,7 @@ endif()
300 269
301if(NOT WIN32 AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND) 270if(NOT WIN32 AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND)
302 add_executable(av_test testing/av_test.c) 271 add_executable(av_test testing/av_test.c)
303 target_link_libraries(av_test 272 target_link_modules(av_test
304 toxav 273 toxav
305 ${OPENCV_LIBRARIES} 274 ${OPENCV_LIBRARIES}
306 ${PORTAUDIO_LIBRARIES} 275 ${PORTAUDIO_LIBRARIES}
@@ -309,31 +278,31 @@ endif()
309 278
310if(NOT WIN32) 279if(NOT WIN32)
311 add_executable(nTox testing/nTox.c) 280 add_executable(nTox testing/nTox.c)
312 target_link_libraries(nTox toxcore ncurses) 281 target_link_modules(nTox toxcore ${NCURSES_LIBRARIES})
313endif() 282endif()
314 283
315add_executable(DHT_test testing/DHT_test.c) 284add_executable(DHT_test testing/DHT_test.c)
316target_link_libraries(DHT_test toxdht) 285target_link_modules(DHT_test toxdht)
317 286
318add_executable(Messenger_test testing/Messenger_test.c) 287add_executable(Messenger_test testing/Messenger_test.c)
319target_link_libraries(Messenger_test toxmessenger) 288target_link_modules(Messenger_test toxmessenger)
320 289
321add_executable(dns3_test testing/dns3_test.c) 290add_executable(dns3_test testing/dns3_test.c)
322target_link_libraries(dns3_test toxdns) 291target_link_modules(dns3_test toxdns)
323 292
324if(NOT WIN32) 293if(NOT WIN32)
325 add_executable(tox_sync testing/tox_sync.c) 294 add_executable(tox_sync testing/tox_sync.c)
326 target_link_libraries(tox_sync toxcore) 295 target_link_modules(tox_sync toxcore)
327endif() 296endif()
328 297
329if(UTIL_LIBRARIES) 298if(UTIL_LIBRARIES)
330 add_executable(tox_shell testing/tox_shell.c) 299 add_executable(tox_shell testing/tox_shell.c)
331 target_link_libraries(tox_shell toxcore ${UTIL_LIBRARIES}) 300 target_link_modules(tox_shell toxcore ${UTIL_LIBRARIES})
332endif() 301endif()
333 302
334if(NOT WIN32) 303if(NOT WIN32)
335 add_executable(irc_syncbot testing/irc_syncbot.c) 304 add_executable(irc_syncbot testing/irc_syncbot.c)
336 target_link_libraries(irc_syncbot toxcore) 305 target_link_modules(irc_syncbot toxcore)
337endif() 306endif()
338 307
339 308
@@ -374,19 +343,6 @@ install(FILES
374 ${CMAKE_BINARY_DIR}/toxdns.pc 343 ${CMAKE_BINARY_DIR}/toxdns.pc
375 ${CMAKE_BINARY_DIR}/toxencryptsave.pc 344 ${CMAKE_BINARY_DIR}/toxencryptsave.pc
376 DESTINATION "lib/pkgconfig") 345 DESTINATION "lib/pkgconfig")
377install(TARGETS
378 toxav
379 toxcore
380 toxcrypto
381 toxdht
382 toxdns
383 toxencryptsave
384 toxfriends
385 toxgroup
386 toxmessenger
387 toxnetcrypto
388 toxnetwork
389 DESTINATION "lib")
390install(FILES 346install(FILES
391 toxav/toxav.h 347 toxav/toxav.h
392 toxcore/tox.h 348 toxcore/tox.h