cleanup: split CMakeLists.txt and add some missing targets

This commit is contained in:
sudden6 2022-02-23 17:00:53 +01:00
parent ac3e8fea63
commit bc006beb4e
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
9 changed files with 216 additions and 153 deletions

View File

@ -22,7 +22,9 @@ cmake -B_build -H. -GNinja \
-DSTRICT_ABI=ON \ -DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \ -DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \ -DUSE_IPV6=OFF \
-DAUTOTEST=ON -DAUTOTEST=ON \
-DBUILD_MISC_TESTS=ON \
-DBUILD_FUN_UTILS=ON
cd _build cd _build

View File

@ -21,7 +21,6 @@ project(toxcore)
list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
set_source_files_properties( set_source_files_properties(
other/bootstrap_daemon/src/tox-bootstrapd.c
toxcore/mono_time.c toxcore/mono_time.c
toxcore/network.c toxcore/network.c
toxcore/tox.c toxcore/tox.c
@ -102,8 +101,6 @@ if(MIN_LOGGER_LEVEL)
endif() endif()
endif() endif()
option(PROXY_TEST "Enable proxy test (needs HTTP/SOCKS5 proxy on port 8080/8081)" OFF)
option(USE_IPV6 "Use IPv6 in tests" ON) option(USE_IPV6 "Use IPv6 in tests" ON)
if(NOT USE_IPV6) if(NOT USE_IPV6)
add_definitions(-DUSE_IPV6=0) add_definitions(-DUSE_IPV6=0)
@ -114,11 +111,41 @@ if(USE_STDERR_LOGGER)
add_definitions(-DUSE_STDERR_LOGGER=1) add_definitions(-DUSE_STDERR_LOGGER=1)
endif() endif()
option(NON_HERMETIC_TESTS "Whether to build and run tests that depend on an internet connection" OFF) option(BUILD_MISC_TESTS "Build additional tests and utilities" OFF)
option(BUILD_FUN_UTILS "Build additional just for fun utilities" OFF)
option(AUTOTEST "Enable autotests (mainly for CI)" OFF)
if (AUTOTEST)
option(NON_HERMETIC_TESTS "Whether to build and run tests that depend on an internet connection" OFF)
option(PROXY_TEST "Enable proxy test (needs HTTP/SOCKS5 proxy on port 8080/8081)" OFF)
endif()
option(BUILD_TOXAV "Whether to build the tox AV library" ON) option(BUILD_TOXAV "Whether to build the tox AV library" ON)
option(MUST_BUILD_TOXAV "Fail the build if toxav cannot be built" OFF) option(MUST_BUILD_TOXAV "Fail the build if toxav cannot be built" OFF)
option(DHT_BOOTSTRAP "Enable building of DHT_bootstrap" ON)
option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
if(BOOTSTRAP_DAEMON AND WIN32)
message(WARNING "Building tox-bootstrapd for Windows is not supported, disabling")
set(BOOTSTRAP_DAEMON OFF)
endif()
# Enabling this breaks all other tests and no network connections will be possible
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
if(BUILD_FUZZ_TESTS)
message(STATUS "Building in fuzz testing mode, no network connection will be possible")
# Disable everything we can
set(AUTOTEST OFF)
set(BUILD_MISC_TESTS OFF)
set(BUILD_FUN_UTILS OFF)
set(ENABLE_SHARED OFF)
set(MUST_BUILD_TOXAV OFF)
set(BUILD_TOXAV OFF)
set(BOOTSTRAP_DAEMON OFF)
set(DHT_BOOTSTRAP OFF)
endif()
if(MSVC) if(MSVC)
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF) option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
if(MSVC_STATIC_SODIUM) if(MSVC_STATIC_SODIUM)
@ -416,93 +443,16 @@ unit_test(toxcore ping_array)
unit_test(toxcore tox) unit_test(toxcore tox)
unit_test(toxcore util) unit_test(toxcore util)
add_subdirectory(testing)
################################################################################ ################################################################################
# #
# :: Automated regression tests: create a tox network and run integration tests # :: Automated regression tests: create a tox network and run integration tests
# #
################################################################################ ################################################################################
set(misc_tools_SOURCES
testing/misc_tools.c
testing/misc_tools.h)
add_library(misc_tools ${misc_tools_SOURCES})
target_link_modules(misc_tools toxcore)
set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")
option(AUTOTEST "Enable autotests (mainly for CI)" OFF)
if(AUTOTEST) if(AUTOTEST)
add_library(auto_test_support add_subdirectory(auto_tests)
auto_tests/auto_test_support.c
auto_tests/auto_test_support.h)
target_link_modules(auto_test_support toxcore misc_tools)
endif()
function(auto_test target)
if(AUTOTEST AND NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
add_executable(auto_${target}_test auto_tests/${target}_test.c)
target_link_modules(auto_${target}_test toxcore misc_tools auto_test_support)
if(NOT ARGV1 STREQUAL "DONT_RUN")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
endif()
endif()
endfunction()
auto_test(TCP)
auto_test(conference)
auto_test(conference_double_invite)
auto_test(conference_invite_merge)
auto_test(conference_peer_nick)
auto_test(conference_simple)
auto_test(conference_two)
auto_test(crypto)
auto_test(dht_getnodes_api)
auto_test(encryptsave)
auto_test(file_transfer)
auto_test(file_saving)
auto_test(friend_connection)
auto_test(friend_request)
auto_test(friend_request_spam)
auto_test(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
auto_test(lossless_packet)
auto_test(lossy_packet)
auto_test(network)
auto_test(onion)
auto_test(overflow_recvq)
auto_test(overflow_sendq)
auto_test(reconnect)
auto_test(save_friend)
auto_test(save_load)
auto_test(send_message)
auto_test(set_name)
auto_test(set_status_message)
auto_test(tox_dispatch)
auto_test(tox_events)
auto_test(tox_many)
auto_test(tox_many_tcp)
auto_test(tox_strncasecmp)
auto_test(typing)
auto_test(version)
auto_test(save_compatibility)
if(PROXY_TEST)
auto_test(proxy)
endif()
if(NON_HERMETIC_TESTS)
auto_test(bootstrap)
auto_test(tcp_relay)
endif()
if(BUILD_TOXAV)
auto_test(conference_av MSVC_DONT_BUILD)
auto_test(toxav_basic)
auto_test(toxav_many)
endif() endif()
################################################################################ ################################################################################
@ -511,7 +461,6 @@ endif()
# #
################################################################################ ################################################################################
option(DHT_BOOTSTRAP "Enable building of DHT_bootstrap" ON)
if(DHT_BOOTSTRAP) if(DHT_BOOTSTRAP)
add_executable(DHT_bootstrap add_executable(DHT_bootstrap
other/DHT_bootstrap.c other/DHT_bootstrap.c
@ -520,79 +469,19 @@ if(DHT_BOOTSTRAP)
install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin) install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
endif() endif()
option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
if(BOOTSTRAP_DAEMON AND WIN32)
message(WARNING "Building tox-bootstrapd for Windows is not supported")
set(BOOTSTRAP_DAEMON OFF)
endif()
if(BOOTSTRAP_DAEMON) if(BOOTSTRAP_DAEMON)
if(NOT LIBCONFIG_FOUND) if(LIBCONFIG_FOUND)
add_subdirectory(other/bootstrap_daemon)
else()
message(WARNING "Option BOOTSTRAP_DAEMON is enabled but required library LIBCONFIG was not found.") message(WARNING "Option BOOTSTRAP_DAEMON is enabled but required library LIBCONFIG was not found.")
set(BOOTSTRAP_DAEMON OFF) set(BOOTSTRAP_DAEMON OFF)
else()
add_executable(tox-bootstrapd
other/bootstrap_daemon/src/command_line_arguments.c
other/bootstrap_daemon/src/command_line_arguments.h
other/bootstrap_daemon/src/config.c
other/bootstrap_daemon/src/config.h
other/bootstrap_daemon/src/config_defaults.h
other/bootstrap_daemon/src/global.h
other/bootstrap_daemon/src/log.c
other/bootstrap_daemon/src/log.h
other/bootstrap_daemon/src/log_backend_stdout.c
other/bootstrap_daemon/src/log_backend_stdout.h
other/bootstrap_daemon/src/log_backend_syslog.c
other/bootstrap_daemon/src/log_backend_syslog.h
other/bootstrap_daemon/src/tox-bootstrapd.c
other/bootstrap_node_packets.c
other/bootstrap_node_packets.h)
target_link_modules(tox-bootstrapd toxcore ${LIBCONFIG_LIBRARIES})
install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
install(FILES other/bootstrap_daemon/bash-completion/completions/tox-bootstrapd DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions")
endif() endif()
endif() endif()
################################################################################ if(BUILD_FUN_UTILS)
# add_subdirectory(other/fun)
# :: Test programs
#
################################################################################
option(BUILD_MISC_TESTS "Build additional tests" OFF)
if (BUILD_MISC_TESTS)
add_executable(Messenger_test testing/Messenger_test.c)
target_link_modules(Messenger_test toxcore misc_tools)
add_executable(random_testing testing/random_testing.cc)
target_link_modules(random_testing toxcore misc_tools)
add_executable(save-generator other/fun/save-generator.c)
target_link_modules(save-generator toxcore misc_tools)
if(NOT MSVC)
add_executable(cracker other/fun/cracker.c)
target_link_modules(cracker ${LIBSODIUM_LIBRARIES})
find_package(OpenMP)
if(OpenMP_C_FOUND)
target_link_libraries(cracker OpenMP::OpenMP_C)
endif()
endif()
endif() endif()
# Enabling this breaks all other tests and no network connections will be possible
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
if (BUILD_FUZZ_TESTS) if (BUILD_FUZZ_TESTS)
# For coverage tests add_subdirectory(testing/fuzzing)
target_compile_definitions(toxcore_static PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
# Override network and random functions
add_library(fuzz_adapter testing/fuzzing/fuzz_adapter.c)
# Fuzzes the toxsave API
add_executable(toxsave_fuzzer testing/fuzzing/toxsave_harness.cc)
target_link_libraries(toxsave_fuzzer toxcore_static fuzz_adapter -fsanitize=fuzzer)
# Fuzzes the bootstrap process
add_executable(bootstrap_fuzzer testing/fuzzing/bootstrap_harness.cc)
target_link_libraries(bootstrap_fuzzer toxcore_static fuzz_adapter -fsanitize=fuzzer)
endif() endif()

View File

@ -42,7 +42,7 @@ This repository, although called `toxcore`, in fact contains several libraries b
#### Secondary #### Secondary
There are some programs that are not plugged into the CMake build system which you might find interesting. You would need to build those programs yourself. These programs reside in [`other/fun`](other/fun) directory. There are some programs that are not built by default which you might find interesting. You need to pass `-DBUILD_FUN_UTILS=ON` to cmake to build them.
##### Vanity key generators ##### Vanity key generators
@ -107,6 +107,7 @@ There are some options that are available to configure the build.
| `BOOTSTRAP_DAEMON` | Enable building of tox-bootstrapd, the DHT bootstrap node daemon. For Unix-like systems only. | ON or OFF | ON | | `BOOTSTRAP_DAEMON` | Enable building of tox-bootstrapd, the DHT bootstrap node daemon. For Unix-like systems only. | ON or OFF | ON |
| `BUILD_FUZZ_TESTS` | Build fuzzing harnesses. | ON or OFF | OFF | | `BUILD_FUZZ_TESTS` | Build fuzzing harnesses. | ON or OFF | OFF |
| `BUILD_MISC_TESTS` | Build additional tests. | ON or OFF | OFF | | `BUILD_MISC_TESTS` | Build additional tests. | ON or OFF | OFF |
| `BUILD_FUN_UTILS` | Build additional funny utilities. | ON or OFF | OFF |
| `BUILD_TOXAV` | Whether to build the toxav library. | ON or OFF | ON | | `BUILD_TOXAV` | Whether to build the toxav library. | ON or OFF | ON |
| `CMAKE_INSTALL_PREFIX` | Path to where everything should be installed. | Directory path. | Platform-dependent. Refer to CMake documentation. | | `CMAKE_INSTALL_PREFIX` | Path to where everything should be installed. | Directory path. | Platform-dependent. Refer to CMake documentation. |
| `CMAKE_BUILD_TYPE` | Specifies the build type on single-configuration generators (e.g. make or ninja). | Debug, Release, RelWithDebInfo, MinSizeRel | Empty string. | | `CMAKE_BUILD_TYPE` | Specifies the build type on single-configuration generators (e.g. make or ninja). | Debug, Release, RelWithDebInfo, MinSizeRel | Empty string. |

75
auto_tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,75 @@
set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")
add_library(auto_test_support
auto_test_support.c
auto_test_support.h)
target_link_modules(auto_test_support toxcore misc_tools)
function(auto_test target)
if(AUTOTEST AND NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
add_executable(auto_${target}_test ${target}_test.c)
target_link_modules(auto_${target}_test toxcore misc_tools auto_test_support)
if(NOT ARGV1 STREQUAL "DONT_RUN")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
# add the source dir as environment variable, so the testdata can be found
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
endif()
endif()
endfunction()
auto_test(TCP)
auto_test(conference)
auto_test(conference_double_invite)
auto_test(conference_invite_merge)
auto_test(conference_peer_nick)
auto_test(conference_simple)
auto_test(conference_two)
auto_test(crypto)
#auto_test(dht) # Doesn't work with UNITY_BUILD.
auto_test(dht_getnodes_api)
auto_test(encryptsave)
auto_test(file_transfer)
auto_test(file_saving)
auto_test(friend_connection)
auto_test(friend_request)
auto_test(friend_request_spam)
auto_test(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
auto_test(lossless_packet)
auto_test(lossy_packet)
auto_test(network)
auto_test(onion)
auto_test(overflow_recvq)
auto_test(overflow_sendq)
auto_test(reconnect)
auto_test(save_friend)
auto_test(save_load)
auto_test(send_message)
auto_test(set_name)
auto_test(set_status_message)
auto_test(tox_dispatch)
auto_test(tox_events)
auto_test(tox_many)
auto_test(tox_many_tcp)
auto_test(tox_strncasecmp)
auto_test(typing)
auto_test(version)
auto_test(save_compatibility)
if(NON_HERMETIC_TESTS)
auto_test(bootstrap)
auto_test(tcp_relay)
endif()
if(BUILD_TOXAV)
auto_test(conference_av MSVC_DONT_BUILD)
auto_test(toxav_basic)
auto_test(toxav_many)
endif()
if(PROXY_TEST)
auto_test(proxy)
endif()

View File

@ -0,0 +1,24 @@
# Unity build broken because of _XOPEN_SOURCE macro
set_source_files_properties(
src/tox-bootstrapd.c
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
add_executable(tox-bootstrapd
src/command_line_arguments.c
src/command_line_arguments.h
src/config.c
src/config.h
src/config_defaults.h
src/global.h
src/log.c
src/log.h
src/log_backend_stdout.c
src/log_backend_stdout.h
src/log_backend_syslog.c
src/log_backend_syslog.h
src/tox-bootstrapd.c
../bootstrap_node_packets.c
../bootstrap_node_packets.h)
target_link_modules(tox-bootstrapd toxcore ${LIBCONFIG_LIBRARIES})
install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
install(FILES bash-completion/completions/tox-bootstrapd DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions")

View File

@ -31,6 +31,8 @@ COPY toxcore toxcore
COPY toxencryptsave toxencryptsave COPY toxencryptsave toxencryptsave
COPY third_party third_party COPY third_party third_party
COPY CMakeLists.txt so.version ./ COPY CMakeLists.txt so.version ./
COPY other/bootstrap_daemon/CMakeLists.txt other/bootstrap_daemon/CMakeLists.txt
COPY testing/CMakeLists.txt testing/CMakeLists.txt
RUN cmake -B_build -H. \ RUN cmake -B_build -H. \
-GNinja \ -GNinja \

30
other/fun/CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
add_executable(save-generator save-generator.c)
target_link_modules(save-generator toxcore misc_tools)
add_executable(strkey strkey.c)
target_link_modules(strkey toxcore ${LIBSODIUM_LIBRARIES})
add_executable(create_bootstrap_keys create_bootstrap_keys.c)
target_link_modules(create_bootstrap_keys ${LIBSODIUM_LIBRARIES})
add_executable(create_minimal_savedata create_minimal_savedata.c)
target_link_modules(create_minimal_savedata ${LIBSODIUM_LIBRARIES})
add_executable(create_savedata create_savedata.c)
target_link_modules(create_savedata toxcore ${LIBSODIUM_LIBRARIES})
add_executable(sign sign.c)
target_link_modules(sign ${LIBSODIUM_LIBRARIES} misc_tools)
add_executable(cracker_simple cracker_simple.c)
target_link_modules(cracker_simple ${LIBSODIUM_LIBRARIES} misc_tools)
# MSVC doesn't support OpenMP
if(NOT MSVC)
find_package(OpenMP)
if(OpenMP_C_FOUND)
add_executable(cracker cracker.c)
target_link_modules(cracker ${LIBSODIUM_LIBRARIES})
target_link_libraries(cracker OpenMP::OpenMP_C)
endif()
endif()

20
testing/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
# Helpful code for tests and other utilities
set(misc_tools_SOURCES
misc_tools.c
misc_tools.h)
add_library(misc_tools ${misc_tools_SOURCES})
target_link_modules(misc_tools toxcore)
################################################################################
#
# :: Test programs
#
################################################################################
if (BUILD_MISC_TESTS)
add_executable(Messenger_test Messenger_test.c)
target_link_modules(Messenger_test toxcore misc_tools)
add_executable(random_testing random_testing.cc)
target_link_modules(random_testing toxcore misc_tools)
endif()

View File

@ -0,0 +1,20 @@
# For coverage tests
target_compile_definitions(toxcore_static PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
# Override network and random functions
add_library(fuzz_adapter fuzz_adapter.c)
set(LIBFUZZER_LINKER_FLAGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer")
else()
message(SEND_ERROR "Compiler must be Clang to build fuzz targets")
endif()
# Fuzzes the toxsave API
add_executable(toxsave_fuzzer toxsave_harness.cc)
target_link_libraries(toxsave_fuzzer toxcore_static fuzz_adapter ${LIBFUZZER_LINKER_FLAGS})
# Fuzzes the bootstrap process
add_executable(bootstrap_fuzzer bootstrap_harness.cc)
target_link_libraries(bootstrap_fuzzer toxcore_static fuzz_adapter ${LIBFUZZER_LINKER_FLAGS})