Skip to content

Commit

Permalink
cleanup: split CMakeLists.txt and add some missing targets
Browse files Browse the repository at this point in the history
  • Loading branch information
sudden6 committed Feb 23, 2022
1 parent 0ac930e commit ac2726e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 150 deletions.
186 changes: 37 additions & 149 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,40 @@ if(USE_STDERR_LOGGER)
add_definitions(-DUSE_STDERR_LOGGER=1)
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 addtional 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)
endif()

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(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)
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
if(MSVC_STATIC_SODIUM)
Expand Down Expand Up @@ -408,91 +437,16 @@ unit_test(toxcore mono_time)
unit_test(toxcore ping_array)
unit_test(toxcore util)

add_subdirectory(testing)

################################################################################
#
# :: 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)
add_library(auto_test_support
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) # 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(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
auto_test(lossless_packet)
auto_test(lossy_packet)
auto_test(messenger)
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_one)
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)
add_subdirectory(auto_tests)
endif()

################################################################################
Expand All @@ -501,7 +455,6 @@ endif()
#
################################################################################

option(DHT_BOOTSTRAP "Enable building of DHT_bootstrap" ON)
if(DHT_BOOTSTRAP)
add_executable(DHT_bootstrap
other/DHT_bootstrap.c
Expand All @@ -510,79 +463,14 @@ if(DHT_BOOTSTRAP)
install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
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(NOT LIBCONFIG_FOUND)
message(WARNING "Option BOOTSTRAP_DAEMON is enabled but required library LIBCONFIG was not found.")
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()
add_subdirectory(other/bootstrap_daemon)
endif()

################################################################################
#
# :: 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()
if(BUILD_FUN_UTILS)
add_subdirectory(other/fun)
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)
# For coverage tests
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)
add_subdirectory(testing/fuzzing)
endif()
3 changes: 2 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This repository, although called `toxcore`, in fact contains several libraries b

#### 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

Expand Down Expand Up @@ -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 |
| `BUILD_FUZZ_TESTS` | Build fuzzing harnesses. | 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 |
| `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. |
Expand Down
70 changes: 70 additions & 0 deletions auto_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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}")
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) # 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(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
auto_test(lossless_packet)
auto_test(lossy_packet)
auto_test(messenger)
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_one)
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()
24 changes: 24 additions & 0 deletions other/bootstrap_daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(NOT LIBCONFIG_FOUND)
message(WARNING "Option BOOTSTRAP_DAEMON is enabled but required library LIBCONFIG was not found.")
set(BOOTSTRAP_DAEMON OFF)
else()
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")
endif()
30 changes: 30 additions & 0 deletions other/fun/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
add_executable(cracker cracker.c)
target_link_modules(cracker ${LIBSODIUM_LIBRARIES})
find_package(OpenMP)
if(OpenMP_C_FOUND)
target_link_libraries(cracker OpenMP::OpenMP_C)
endif()
endif()
20 changes: 20 additions & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Loading

0 comments on commit ac2726e

Please sign in to comment.