Don't build all the small sub-libraries.

This caused us to build everything 2-4 times, now we only build it 1-2
times (depending on selection of static/shared builds). The disadvantage
is that now it's more up to the reviewer to ensure modularity (we still
catch it in the bazel build, though).
This commit is contained in:
iphydf 2018-02-14 23:21:57 +00:00
parent 83f7beacc5
commit 13706de14b
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
3 changed files with 40 additions and 120 deletions

View File

@ -211,7 +211,7 @@ endif()
# LAYER 1: Crypto core # LAYER 1: Crypto core
# -------------------- # --------------------
apidsl(toxcore/crypto_core.api.h) apidsl(toxcore/crypto_core.api.h)
add_submodule(toxcore toxcrypto set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/ccompat.h toxcore/ccompat.h
toxcore/crypto_core.c toxcore/crypto_core.c
toxcore/crypto_core.h toxcore/crypto_core.h
@ -219,34 +219,33 @@ add_submodule(toxcore toxcrypto
include(CheckFunctionExists) include(CheckFunctionExists)
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
check_function_exists(memset_s HAVE_MEMSET_S) check_function_exists(memset_s HAVE_MEMSET_S)
target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES}) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES})
set(toxcrypto_PKGCONFIG_REQUIRES ${toxcrypto_PKGCONFIG_REQUIRES} libsodium) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} libsodium)
# LAYER 2: Basic networking # LAYER 2: Basic networking
# ------------------------- # -------------------------
add_submodule(toxcore toxnetwork set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/logger.c toxcore/logger.c
toxcore/logger.h toxcore/logger.h
toxcore/network.c toxcore/network.c
toxcore/network.h toxcore/network.h
toxcore/util.c toxcore/util.c
toxcore/util.h) toxcore/util.h)
target_link_modules(toxnetwork toxcrypto)
message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}") message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}")
if(CMAKE_THREAD_LIBS_INIT) if(CMAKE_THREAD_LIBS_INIT)
target_link_modules(toxnetwork ${CMAKE_THREAD_LIBS_INIT}) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${CMAKE_THREAD_LIBS_INIT})
set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif() endif()
if(RT_LIBRARIES) if(RT_LIBRARIES)
target_link_modules(toxnetwork ${RT_LIBRARIES}) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${RT_LIBRARIES})
set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lrt") set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt")
endif() endif()
if(WIN32) if(WIN32)
target_link_modules(toxnetwork ws2_32 iphlpapi) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ws2_32 iphlpapi)
set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi") set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
endif() endif()
# LAYER 3: Distributed Hash Table # LAYER 3: Distributed Hash Table
@ -254,7 +253,7 @@ endif()
apidsl(toxcore/LAN_discovery.api.h) apidsl(toxcore/LAN_discovery.api.h)
apidsl(toxcore/ping.api.h) apidsl(toxcore/ping.api.h)
apidsl(toxcore/ping_array.api.h) apidsl(toxcore/ping_array.api.h)
add_submodule(toxcore toxdht set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/DHT.c toxcore/DHT.c
toxcore/DHT.h toxcore/DHT.h
toxcore/LAN_discovery.c toxcore/LAN_discovery.c
@ -263,11 +262,10 @@ add_submodule(toxcore toxdht
toxcore/ping.h toxcore/ping.h
toxcore/ping_array.c toxcore/ping_array.c
toxcore/ping_array.h) toxcore/ping_array.h)
target_link_modules(toxdht toxnetwork)
# LAYER 4: Onion routing, TCP connections, crypto connections # LAYER 4: Onion routing, TCP connections, crypto connections
# ----------------------------------------------------------- # -----------------------------------------------------------
add_submodule(toxcore toxnetcrypto set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/TCP_client.c toxcore/TCP_client.c
toxcore/TCP_client.h toxcore/TCP_client.h
toxcore/TCP_connection.c toxcore/TCP_connection.c
@ -284,40 +282,35 @@ add_submodule(toxcore toxnetcrypto
toxcore/onion_announce.h toxcore/onion_announce.h
toxcore/onion_client.c toxcore/onion_client.c
toxcore/onion_client.h) toxcore/onion_client.h)
target_link_modules(toxnetcrypto toxdht)
# LAYER 5: Friend requests and connections # LAYER 5: Friend requests and connections
# ---------------------------------------- # ----------------------------------------
add_submodule(toxcore toxfriends set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/friend_connection.c toxcore/friend_connection.c
toxcore/friend_connection.h toxcore/friend_connection.h
toxcore/friend_requests.c toxcore/friend_requests.c
toxcore/friend_requests.h) toxcore/friend_requests.h)
target_link_modules(toxfriends toxnetcrypto)
# LAYER 6: Tox messenger # LAYER 6: Tox messenger
# ---------------------- # ----------------------
add_submodule(toxcore toxmessenger set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/Messenger.c toxcore/Messenger.c
toxcore/Messenger.h) toxcore/Messenger.h)
target_link_modules(toxmessenger toxfriends)
# LAYER 7: Group chats # LAYER 7: Group chats
# -------------------- # --------------------
add_submodule(toxcore toxgroup set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/group.c toxcore/group.c
toxcore/group.h) toxcore/group.h)
target_link_modules(toxgroup toxmessenger)
# LAYER 8: Public API # LAYER 8: Public API
# ------------------- # -------------------
apidsl(toxcore/tox.api.h) apidsl(toxcore/tox.api.h)
add_submodule(toxcore toxapi set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/tox_api.c toxcore/tox_api.c
toxcore/tox.c toxcore/tox.c
toxcore/tox.h) toxcore/tox.h)
target_link_modules(toxapi toxgroup) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
set(toxapi_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
################################################################################ ################################################################################
# #
@ -327,7 +320,7 @@ set(toxapi_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
if(BUILD_TOXAV) if(BUILD_TOXAV)
apidsl(toxav/toxav.api.h) apidsl(toxav/toxav.api.h)
add_submodule(toxcore toxav set(toxcore_SOURCES ${toxcore_SOURCES}
toxav/audio.c toxav/audio.c
toxav/audio.h toxav/audio.h
toxav/bwcontroller.c toxav/bwcontroller.c
@ -345,11 +338,10 @@ if(BUILD_TOXAV)
toxav/toxav_old.c toxav/toxav_old.c
toxav/video.c toxav/video.c
toxav/video.h) toxav/video.h)
target_link_modules(toxav toxgroup ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
set(toxav_PKGCONFIG_REQUIRES ${toxav_PKGCONFIG_REQUIRES} opus vpx) set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
set(toxav_API_HEADERS ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
make_version_script(toxav ${toxav_API_HEADERS})
endif() endif()
################################################################################ ################################################################################
@ -359,11 +351,10 @@ endif()
################################################################################ ################################################################################
apidsl(toxencryptsave/toxencryptsave.api.h) apidsl(toxencryptsave/toxencryptsave.api.h)
add_submodule(toxcore toxencryptsave set(toxcore_SOURCES ${toxcore_SOURCES}
toxencryptsave/toxencryptsave.c toxencryptsave/toxencryptsave.c
toxencryptsave/toxencryptsave.h) toxencryptsave/toxencryptsave.h)
target_link_modules(toxencryptsave toxcrypto) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
set(toxencryptsave_API_HEADERS ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
################################################################################ ################################################################################
# #
@ -375,26 +366,8 @@ set(toxencryptsave_API_HEADERS ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsa
add_module(toxcore ${toxcore_SOURCES}) add_module(toxcore ${toxcore_SOURCES})
# Link it to all dependencies. # Link it to all dependencies.
foreach(sublib ${toxcore_SUBLIBS})
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${${sublib}_LINK_MODULES})
endforeach()
target_link_modules(toxcore ${toxcore_LINK_MODULES}) target_link_modules(toxcore ${toxcore_LINK_MODULES})
# Concatenate all the pkg-config Libs: lines.
foreach(sublib ${toxcore_SUBLIBS})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${${sublib}_PKGCONFIG_LIBS})
endforeach()
# Concatenate all the pkg-config Requires: lines.
foreach(sublib ${toxcore_SUBLIBS})
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} ${${sublib}_PKGCONFIG_REQUIRES})
endforeach()
# Collect all API headers.
foreach(sublib ${toxcore_SUBLIBS})
set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${${sublib}_API_HEADERS})
endforeach()
# Make version script (on systems that support it) to limit symbol visibility. # Make version script (on systems that support it) to limit symbol visibility.
make_version_script(toxcore ${toxcore_API_HEADERS}) make_version_script(toxcore ${toxcore_API_HEADERS})
@ -402,44 +375,6 @@ make_version_script(toxcore ${toxcore_API_HEADERS})
# "${CMAKE_INSTALL_INCLUDEDIR}/tox". # "${CMAKE_INSTALL_INCLUDEDIR}/tox".
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox) install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
################################################################################
#
# :: Tox specification tests
#
################################################################################
# find_program(SPECTEST NAMES
# tox-spectest
# ../.stack-work/install/x86_64-linux/lts-2.22/7.8.4/bin/tox-spectest)
#
# if(NOT SPECTEST)
# find_program(STACK NAMES stack)
# if(STACK)
# set(SPECTEST
# ${STACK} --stack-yaml ${toxcore_SOURCE_DIR}/../stack.yaml exec --
# tox-spectest)
# endif()
# endif()
#
# if(MSGPACK_FOUND)
# add_executable(toxcore-sut
# testing/hstox/binary_decode.c
# testing/hstox/binary_encode.c
# testing/hstox/driver.c
# testing/hstox/methods.c
# testing/hstox/packet_kinds.c
# testing/hstox/test_main.c
# testing/hstox/util.c)
# target_link_modules(toxcore-sut
# toxcore
# toxdht
# toxnetcrypto
# ${MSGPACK_LIBRARIES})
# if(SPECTEST)
# add_test(NAME spectest COMMAND ${SPECTEST} $<TARGET_FILE:toxcore-sut>)
# endif()
# endif()
################################################################################ ################################################################################
# #
# :: Unit tests: no networking, just pure function calls. # :: Unit tests: no networking, just pure function calls.
@ -448,15 +383,6 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
include(CompileGTest) include(CompileGTest)
function(unit_test subdir target)
if(HAVE_GTEST)
add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
endif()
endfunction()
# The actual unit tests follow. # The actual unit tests follow.
# #
unit_test(toxav rtp) unit_test(toxav rtp)
@ -488,11 +414,7 @@ endif()
function(auto_test target) function(auto_test target)
if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD")) if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
add_executable(auto_${target}_test auto_tests/${target}_test.c) add_executable(auto_${target}_test auto_tests/${target}_test.c)
target_link_modules(auto_${target}_test target_link_modules(auto_${target}_test toxcore)
toxcore
toxcrypto
toxmessenger
toxnetcrypto)
if(NOT ARGV1 STREQUAL "DONT_RUN") if(NOT ARGV1 STREQUAL "DONT_RUN")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test) add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
@ -505,12 +427,7 @@ if(BUILD_TOXAV)
add_executable(auto_monolith_test add_executable(auto_monolith_test
auto_tests/monolith_test.cpp auto_tests/monolith_test.cpp
${ANDROID_CPU_FEATURES}) ${ANDROID_CPU_FEATURES})
target_link_modules(auto_monolith_test target_link_libraries(auto_monolith_test ${toxcore_LINK_MODULES})
${LIBSODIUM_LIBRARIES}
${OPUS_LIBRARIES}
${VPX_LIBRARIES}
${toxcore_PKGCONFIG_LIBS}
)
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test) add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
if(ANDROID_CPU_FEATURES) if(ANDROID_CPU_FEATURES)
@ -560,7 +477,7 @@ if(DHT_BOOTSTRAP)
add_executable(DHT_bootstrap add_executable(DHT_bootstrap
other/DHT_bootstrap.c other/DHT_bootstrap.c
other/bootstrap_node_packets.c) other/bootstrap_node_packets.c)
target_link_modules(DHT_bootstrap toxnetcrypto) target_link_modules(DHT_bootstrap toxcore)
endif() endif()
option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON) option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
@ -586,7 +503,7 @@ if(BOOTSTRAP_DAEMON)
other/bootstrap_daemon/src/tox-bootstrapd.c other/bootstrap_daemon/src/tox-bootstrapd.c
other/bootstrap_node_packets.c other/bootstrap_node_packets.c
other/bootstrap_node_packets.h) other/bootstrap_node_packets.h)
target_link_modules(tox-bootstrapd toxfriends ${LIBCONFIG_LIBRARIES}) target_link_modules(tox-bootstrapd toxcore ${LIBCONFIG_LIBRARIES})
install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin) install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
endif() endif()
endif() endif()
@ -615,7 +532,7 @@ if(NOT WIN32
endif() endif()
add_executable(DHT_test testing/DHT_test.c) add_executable(DHT_test testing/DHT_test.c)
target_link_modules(DHT_test toxdht) target_link_modules(DHT_test toxcore)
add_executable(Messenger_test testing/Messenger_test.c) add_executable(Messenger_test testing/Messenger_test.c)
target_link_modules(Messenger_test toxmessenger) target_link_modules(Messenger_test toxcore)

View File

@ -47,3 +47,12 @@ if(GTEST_ALL_CC)
endif() endif()
endif() endif()
endif() endif()
function(unit_test subdir target)
if(HAVE_GTEST)
add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
target_link_modules(unit_${target}_test toxcore gtest)
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
endif()
endfunction()

View File

@ -28,12 +28,6 @@ function(pkg_use_module mod pkg)
endif() endif()
endfunction() endfunction()
macro(add_submodule super lib)
add_module(${lib} ${ARGN})
set(${super}_SUBLIBS ${${super}_SUBLIBS} ${lib})
set(${super}_SOURCES ${${super}_SOURCES} ${${lib}_SOURCES})
endmacro()
function(add_module lib) function(add_module lib)
set(${lib}_SOURCES ${ARGN} PARENT_SCOPE) set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
@ -132,8 +126,8 @@ function(target_link_modules target)
set(_targets ${_targets} ${target}) set(_targets ${_targets} ${target})
# Executables preferably link against static libraries, so they are # Executables preferably link against static libraries, so they are
# standalone and can be shipped without any external dependencies. As a # standalone and can be shipped without any external dependencies. As a
# frame of reference: tests become roughly 1-1.5M binaries instead of # frame of reference: tests become roughly 600-800K binaries instead of
# 100-200K on x86_64 Linux. # 50-100K on x86_64 Linux.
set(${target}_primary static) set(${target}_primary static)
set(${target}_secondary shared) set(${target}_secondary shared)
endif() endif()