summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt141
-rw-r--r--cmake/CompileGTest.cmake9
-rw-r--r--cmake/ModulePackage.cmake10
3 files changed, 40 insertions, 120 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9acb97d2..a16c1220 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,7 +211,7 @@ endif()
211# LAYER 1: Crypto core 211# LAYER 1: Crypto core
212# -------------------- 212# --------------------
213apidsl(toxcore/crypto_core.api.h) 213apidsl(toxcore/crypto_core.api.h)
214add_submodule(toxcore toxcrypto 214set(toxcore_SOURCES ${toxcore_SOURCES}
215 toxcore/ccompat.h 215 toxcore/ccompat.h
216 toxcore/crypto_core.c 216 toxcore/crypto_core.c
217 toxcore/crypto_core.h 217 toxcore/crypto_core.h
@@ -219,34 +219,33 @@ add_submodule(toxcore toxcrypto
219include(CheckFunctionExists) 219include(CheckFunctionExists)
220check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) 220check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
221check_function_exists(memset_s HAVE_MEMSET_S) 221check_function_exists(memset_s HAVE_MEMSET_S)
222target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES}) 222set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES})
223set(toxcrypto_PKGCONFIG_REQUIRES ${toxcrypto_PKGCONFIG_REQUIRES} libsodium) 223set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} libsodium)
224 224
225# LAYER 2: Basic networking 225# LAYER 2: Basic networking
226# ------------------------- 226# -------------------------
227add_submodule(toxcore toxnetwork 227set(toxcore_SOURCES ${toxcore_SOURCES}
228 toxcore/logger.c 228 toxcore/logger.c
229 toxcore/logger.h 229 toxcore/logger.h
230 toxcore/network.c 230 toxcore/network.c
231 toxcore/network.h 231 toxcore/network.h
232 toxcore/util.c 232 toxcore/util.c
233 toxcore/util.h) 233 toxcore/util.h)
234target_link_modules(toxnetwork toxcrypto)
235 234
236message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}") 235message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}")
237if(CMAKE_THREAD_LIBS_INIT) 236if(CMAKE_THREAD_LIBS_INIT)
238 target_link_modules(toxnetwork ${CMAKE_THREAD_LIBS_INIT}) 237 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${CMAKE_THREAD_LIBS_INIT})
239 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 238 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
240endif() 239endif()
241 240
242if(RT_LIBRARIES) 241if(RT_LIBRARIES)
243 target_link_modules(toxnetwork ${RT_LIBRARIES}) 242 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${RT_LIBRARIES})
244 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lrt") 243 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt")
245endif() 244endif()
246 245
247if(WIN32) 246if(WIN32)
248 target_link_modules(toxnetwork ws2_32 iphlpapi) 247 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ws2_32 iphlpapi)
249 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi") 248 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
250endif() 249endif()
251 250
252# LAYER 3: Distributed Hash Table 251# LAYER 3: Distributed Hash Table
@@ -254,7 +253,7 @@ endif()
254apidsl(toxcore/LAN_discovery.api.h) 253apidsl(toxcore/LAN_discovery.api.h)
255apidsl(toxcore/ping.api.h) 254apidsl(toxcore/ping.api.h)
256apidsl(toxcore/ping_array.api.h) 255apidsl(toxcore/ping_array.api.h)
257add_submodule(toxcore toxdht 256set(toxcore_SOURCES ${toxcore_SOURCES}
258 toxcore/DHT.c 257 toxcore/DHT.c
259 toxcore/DHT.h 258 toxcore/DHT.h
260 toxcore/LAN_discovery.c 259 toxcore/LAN_discovery.c
@@ -263,11 +262,10 @@ add_submodule(toxcore toxdht
263 toxcore/ping.h 262 toxcore/ping.h
264 toxcore/ping_array.c 263 toxcore/ping_array.c
265 toxcore/ping_array.h) 264 toxcore/ping_array.h)
266target_link_modules(toxdht toxnetwork)
267 265
268# LAYER 4: Onion routing, TCP connections, crypto connections 266# LAYER 4: Onion routing, TCP connections, crypto connections
269# ----------------------------------------------------------- 267# -----------------------------------------------------------
270add_submodule(toxcore toxnetcrypto 268set(toxcore_SOURCES ${toxcore_SOURCES}
271 toxcore/TCP_client.c 269 toxcore/TCP_client.c
272 toxcore/TCP_client.h 270 toxcore/TCP_client.h
273 toxcore/TCP_connection.c 271 toxcore/TCP_connection.c
@@ -284,40 +282,35 @@ add_submodule(toxcore toxnetcrypto
284 toxcore/onion_announce.h 282 toxcore/onion_announce.h
285 toxcore/onion_client.c 283 toxcore/onion_client.c
286 toxcore/onion_client.h) 284 toxcore/onion_client.h)
287target_link_modules(toxnetcrypto toxdht)
288 285
289# LAYER 5: Friend requests and connections 286# LAYER 5: Friend requests and connections
290# ---------------------------------------- 287# ----------------------------------------
291add_submodule(toxcore toxfriends 288set(toxcore_SOURCES ${toxcore_SOURCES}
292 toxcore/friend_connection.c 289 toxcore/friend_connection.c
293 toxcore/friend_connection.h 290 toxcore/friend_connection.h
294 toxcore/friend_requests.c 291 toxcore/friend_requests.c
295 toxcore/friend_requests.h) 292 toxcore/friend_requests.h)
296target_link_modules(toxfriends toxnetcrypto)
297 293
298# LAYER 6: Tox messenger 294# LAYER 6: Tox messenger
299# ---------------------- 295# ----------------------
300add_submodule(toxcore toxmessenger 296set(toxcore_SOURCES ${toxcore_SOURCES}
301 toxcore/Messenger.c 297 toxcore/Messenger.c
302 toxcore/Messenger.h) 298 toxcore/Messenger.h)
303target_link_modules(toxmessenger toxfriends)
304 299
305# LAYER 7: Group chats 300# LAYER 7: Group chats
306# -------------------- 301# --------------------
307add_submodule(toxcore toxgroup 302set(toxcore_SOURCES ${toxcore_SOURCES}
308 toxcore/group.c 303 toxcore/group.c
309 toxcore/group.h) 304 toxcore/group.h)
310target_link_modules(toxgroup toxmessenger)
311 305
312# LAYER 8: Public API 306# LAYER 8: Public API
313# ------------------- 307# -------------------
314apidsl(toxcore/tox.api.h) 308apidsl(toxcore/tox.api.h)
315add_submodule(toxcore toxapi 309set(toxcore_SOURCES ${toxcore_SOURCES}
316 toxcore/tox_api.c 310 toxcore/tox_api.c
317 toxcore/tox.c 311 toxcore/tox.c
318 toxcore/tox.h) 312 toxcore/tox.h)
319target_link_modules(toxapi toxgroup) 313set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
320set(toxapi_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
321 314
322################################################################################ 315################################################################################
323# 316#
@@ -327,7 +320,7 @@ set(toxapi_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
327 320
328if(BUILD_TOXAV) 321if(BUILD_TOXAV)
329 apidsl(toxav/toxav.api.h) 322 apidsl(toxav/toxav.api.h)
330 add_submodule(toxcore toxav 323 set(toxcore_SOURCES ${toxcore_SOURCES}
331 toxav/audio.c 324 toxav/audio.c
332 toxav/audio.h 325 toxav/audio.h
333 toxav/bwcontroller.c 326 toxav/bwcontroller.c
@@ -345,11 +338,10 @@ if(BUILD_TOXAV)
345 toxav/toxav_old.c 338 toxav/toxav_old.c
346 toxav/video.c 339 toxav/video.c
347 toxav/video.h) 340 toxav/video.h)
348 target_link_modules(toxav toxgroup ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) 341 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
349 set(toxav_PKGCONFIG_REQUIRES ${toxav_PKGCONFIG_REQUIRES} opus vpx) 342 set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
350 343
351 set(toxav_API_HEADERS ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav) 344 set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
352 make_version_script(toxav ${toxav_API_HEADERS})
353endif() 345endif()
354 346
355################################################################################ 347################################################################################
@@ -359,11 +351,10 @@ endif()
359################################################################################ 351################################################################################
360 352
361apidsl(toxencryptsave/toxencryptsave.api.h) 353apidsl(toxencryptsave/toxencryptsave.api.h)
362add_submodule(toxcore toxencryptsave 354set(toxcore_SOURCES ${toxcore_SOURCES}
363 toxencryptsave/toxencryptsave.c 355 toxencryptsave/toxencryptsave.c
364 toxencryptsave/toxencryptsave.h) 356 toxencryptsave/toxencryptsave.h)
365target_link_modules(toxencryptsave toxcrypto) 357set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
366set(toxencryptsave_API_HEADERS ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
367 358
368################################################################################ 359################################################################################
369# 360#
@@ -375,26 +366,8 @@ set(toxencryptsave_API_HEADERS ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsa
375add_module(toxcore ${toxcore_SOURCES}) 366add_module(toxcore ${toxcore_SOURCES})
376 367
377# Link it to all dependencies. 368# Link it to all dependencies.
378foreach(sublib ${toxcore_SUBLIBS})
379 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${${sublib}_LINK_MODULES})
380endforeach()
381target_link_modules(toxcore ${toxcore_LINK_MODULES}) 369target_link_modules(toxcore ${toxcore_LINK_MODULES})
382 370
383# Concatenate all the pkg-config Libs: lines.
384foreach(sublib ${toxcore_SUBLIBS})
385 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${${sublib}_PKGCONFIG_LIBS})
386endforeach()
387
388# Concatenate all the pkg-config Requires: lines.
389foreach(sublib ${toxcore_SUBLIBS})
390 set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} ${${sublib}_PKGCONFIG_REQUIRES})
391endforeach()
392
393# Collect all API headers.
394foreach(sublib ${toxcore_SUBLIBS})
395 set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${${sublib}_API_HEADERS})
396endforeach()
397
398# Make version script (on systems that support it) to limit symbol visibility. 371# Make version script (on systems that support it) to limit symbol visibility.
399make_version_script(toxcore ${toxcore_API_HEADERS}) 372make_version_script(toxcore ${toxcore_API_HEADERS})
400 373
@@ -404,59 +377,12 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
404 377
405################################################################################ 378################################################################################
406# 379#
407# :: Tox specification tests
408#
409################################################################################
410
411# find_program(SPECTEST NAMES
412# tox-spectest
413# ../.stack-work/install/x86_64-linux/lts-2.22/7.8.4/bin/tox-spectest)
414#
415# if(NOT SPECTEST)
416# find_program(STACK NAMES stack)
417# if(STACK)
418# set(SPECTEST
419# ${STACK} --stack-yaml ${toxcore_SOURCE_DIR}/../stack.yaml exec --
420# tox-spectest)
421# endif()
422# endif()
423#
424# if(MSGPACK_FOUND)
425# add_executable(toxcore-sut
426# testing/hstox/binary_decode.c
427# testing/hstox/binary_encode.c
428# testing/hstox/driver.c
429# testing/hstox/methods.c
430# testing/hstox/packet_kinds.c
431# testing/hstox/test_main.c
432# testing/hstox/util.c)
433# target_link_modules(toxcore-sut
434# toxcore
435# toxdht
436# toxnetcrypto
437# ${MSGPACK_LIBRARIES})
438# if(SPECTEST)
439# add_test(NAME spectest COMMAND ${SPECTEST} $<TARGET_FILE:toxcore-sut>)
440# endif()
441# endif()
442
443################################################################################
444#
445# :: Unit tests: no networking, just pure function calls. 380# :: Unit tests: no networking, just pure function calls.
446# 381#
447################################################################################ 382################################################################################
448 383
449include(CompileGTest) 384include(CompileGTest)
450 385
451function(unit_test subdir target)
452 if(HAVE_GTEST)
453 add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
454 target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
455 set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
456 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
457 endif()
458endfunction()
459
460# The actual unit tests follow. 386# The actual unit tests follow.
461# 387#
462unit_test(toxav rtp) 388unit_test(toxav rtp)
@@ -488,11 +414,7 @@ endif()
488function(auto_test target) 414function(auto_test target)
489 if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD")) 415 if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
490 add_executable(auto_${target}_test auto_tests/${target}_test.c) 416 add_executable(auto_${target}_test auto_tests/${target}_test.c)
491 target_link_modules(auto_${target}_test 417 target_link_modules(auto_${target}_test toxcore)
492 toxcore
493 toxcrypto
494 toxmessenger
495 toxnetcrypto)
496 if(NOT ARGV1 STREQUAL "DONT_RUN") 418 if(NOT ARGV1 STREQUAL "DONT_RUN")
497 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test) 419 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
498 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") 420 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
@@ -505,12 +427,7 @@ if(BUILD_TOXAV)
505 add_executable(auto_monolith_test 427 add_executable(auto_monolith_test
506 auto_tests/monolith_test.cpp 428 auto_tests/monolith_test.cpp
507 ${ANDROID_CPU_FEATURES}) 429 ${ANDROID_CPU_FEATURES})
508 target_link_modules(auto_monolith_test 430 target_link_libraries(auto_monolith_test ${toxcore_LINK_MODULES})
509 ${LIBSODIUM_LIBRARIES}
510 ${OPUS_LIBRARIES}
511 ${VPX_LIBRARIES}
512 ${toxcore_PKGCONFIG_LIBS}
513 )
514 add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test) 431 add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
515 432
516 if(ANDROID_CPU_FEATURES) 433 if(ANDROID_CPU_FEATURES)
@@ -560,7 +477,7 @@ if(DHT_BOOTSTRAP)
560 add_executable(DHT_bootstrap 477 add_executable(DHT_bootstrap
561 other/DHT_bootstrap.c 478 other/DHT_bootstrap.c
562 other/bootstrap_node_packets.c) 479 other/bootstrap_node_packets.c)
563 target_link_modules(DHT_bootstrap toxnetcrypto) 480 target_link_modules(DHT_bootstrap toxcore)
564endif() 481endif()
565 482
566option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON) 483option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
@@ -586,7 +503,7 @@ if(BOOTSTRAP_DAEMON)
586 other/bootstrap_daemon/src/tox-bootstrapd.c 503 other/bootstrap_daemon/src/tox-bootstrapd.c
587 other/bootstrap_node_packets.c 504 other/bootstrap_node_packets.c
588 other/bootstrap_node_packets.h) 505 other/bootstrap_node_packets.h)
589 target_link_modules(tox-bootstrapd toxfriends ${LIBCONFIG_LIBRARIES}) 506 target_link_modules(tox-bootstrapd toxcore ${LIBCONFIG_LIBRARIES})
590 install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin) 507 install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
591 endif() 508 endif()
592endif() 509endif()
@@ -615,7 +532,7 @@ if(NOT WIN32
615endif() 532endif()
616 533
617add_executable(DHT_test testing/DHT_test.c) 534add_executable(DHT_test testing/DHT_test.c)
618target_link_modules(DHT_test toxdht) 535target_link_modules(DHT_test toxcore)
619 536
620add_executable(Messenger_test testing/Messenger_test.c) 537add_executable(Messenger_test testing/Messenger_test.c)
621target_link_modules(Messenger_test toxmessenger) 538target_link_modules(Messenger_test toxcore)
diff --git a/cmake/CompileGTest.cmake b/cmake/CompileGTest.cmake
index 520ca06a..1974901e 100644
--- a/cmake/CompileGTest.cmake
+++ b/cmake/CompileGTest.cmake
@@ -47,3 +47,12 @@ if(GTEST_ALL_CC)
47 endif() 47 endif()
48 endif() 48 endif()
49endif() 49endif()
50
51function(unit_test subdir target)
52 if(HAVE_GTEST)
53 add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
54 target_link_modules(unit_${target}_test toxcore gtest)
55 set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
56 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
57 endif()
58endfunction()
diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake
index 8ee8d6d7..f0eef7c9 100644
--- a/cmake/ModulePackage.cmake
+++ b/cmake/ModulePackage.cmake
@@ -28,12 +28,6 @@ function(pkg_use_module mod pkg)
28 endif() 28 endif()
29endfunction() 29endfunction()
30 30
31macro(add_submodule super lib)
32 add_module(${lib} ${ARGN})
33 set(${super}_SUBLIBS ${${super}_SUBLIBS} ${lib})
34 set(${super}_SOURCES ${${super}_SOURCES} ${${lib}_SOURCES})
35endmacro()
36
37function(add_module lib) 31function(add_module lib)
38 set(${lib}_SOURCES ${ARGN} PARENT_SCOPE) 32 set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
39 33
@@ -132,8 +126,8 @@ function(target_link_modules target)
132 set(_targets ${_targets} ${target}) 126 set(_targets ${_targets} ${target})
133 # Executables preferably link against static libraries, so they are 127 # Executables preferably link against static libraries, so they are
134 # standalone and can be shipped without any external dependencies. As a 128 # standalone and can be shipped without any external dependencies. As a
135 # frame of reference: tests become roughly 1-1.5M binaries instead of 129 # frame of reference: tests become roughly 600-800K binaries instead of
136 # 100-200K on x86_64 Linux. 130 # 50-100K on x86_64 Linux.
137 set(${target}_primary static) 131 set(${target}_primary static)
138 set(${target}_secondary shared) 132 set(${target}_secondary shared)
139 endif() 133 endif()