diff --git a/CMakeLists.txt b/CMakeLists.txt index 862e7bd3..3be4afb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ 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) +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() @@ -307,7 +307,10 @@ set(toxcore_SOURCES toxcore/tox_unpack.h toxcore/util.c toxcore/util.h) -set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES}) +set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES}) +set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS}) +set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS}) +set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER}) set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium) set(toxcore_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox @@ -343,7 +346,10 @@ if(BUILD_TOXAV) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) + set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS}) + set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS}) + set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER}) set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx) endif() @@ -370,28 +376,28 @@ set(toxcore_API_HEADERS ${toxcore_API_HEADERS} # any potential libvpx linking. message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}") if(CMAKE_THREAD_LIBS_INIT) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${CMAKE_THREAD_LIBS_INIT}) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT}) endif() if(NSL_LIBRARIES) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${NSL_LIBRARIES}) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl) endif() if(RT_LIBRARIES) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${RT_LIBRARIES}) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${RT_LIBRARIES}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lrt) endif() if(SOCKET_LIBRARIES) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${SOCKET_LIBRARIES}) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${SOCKET_LIBRARIES}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket) endif() if(WIN32) - set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ws2_32 iphlpapi) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ws2_32 iphlpapi) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lws2_32 -liphlpapi) endif() @@ -406,10 +412,16 @@ add_module(toxcore ${toxcore_SOURCES}) # Link it to all dependencies. if(TARGET toxcore_static) - target_link_libraries(toxcore_static PRIVATE ${toxcore_LINK_MODULES}) + target_link_libraries(toxcore_static PRIVATE ${toxcore_LINK_LIBRARIES}) + target_link_directories(toxcore_static PUBLIC ${toxcore_LINK_DIRECTORIES}) + target_include_directories(toxcore_static SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES}) + target_compile_options(toxcore_static PRIVATE ${toxcore_COMPILE_OPTIONS}) endif() if(TARGET toxcore_shared) - target_link_libraries(toxcore_shared PRIVATE ${toxcore_LINK_MODULES}) + target_link_libraries(toxcore_shared PRIVATE ${toxcore_LINK_LIBRARIES}) + target_link_directories(toxcore_shared PUBLIC ${toxcore_LINK_DIRECTORIES}) + target_include_directories(toxcore_shared SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES}) + target_compile_options(toxcore_shared PRIVATE ${toxcore_COMPILE_OPTIONS}) endif() # Make version script (on systems that support it) to limit symbol visibility. diff --git a/auto_tests/CMakeLists.txt b/auto_tests/CMakeLists.txt index 287b06bb..ffdf8055 100644 --- a/auto_tests/CMakeLists.txt +++ b/auto_tests/CMakeLists.txt @@ -11,20 +11,18 @@ else() endif() 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_libraries(auto_${target}_test PRIVATE misc_tools auto_test_support) - if(TARGET toxcore_static) - target_link_libraries(auto_${target}_test PRIVATE toxcore_static) - else() - target_link_libraries(auto_${target}_test PRIVATE toxcore_shared) - endif() - 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() + add_executable(auto_${target}_test ${target}_test.c) + target_link_libraries(auto_${target}_test PRIVATE misc_tools auto_test_support) + if(TARGET toxcore_static) + target_link_libraries(auto_${target}_test PRIVATE toxcore_static) + else() + target_link_libraries(auto_${target}_test PRIVATE toxcore_shared) + endif() + 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() endfunction() @@ -79,17 +77,28 @@ auto_test(typing) auto_test(version) auto_test(save_compatibility) +target_include_directories(auto_encryptsave_test SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS}) + if(NON_HERMETIC_TESTS) auto_test(bootstrap) auto_test(tcp_relay) endif() if(BUILD_TOXAV) - auto_test(conference_av MSVC_DONT_BUILD) + auto_test(conference_av) auto_test(toxav_basic) auto_test(toxav_many) -endif() + target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES}) + target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS}) + target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) + target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER}) + + target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES}) + target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS}) + target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS}) + target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER}) +endif() if(PROXY_TEST) auto_test(proxy) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index fb49944e..6f2ec906 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -8,19 +8,25 @@ include(ModulePackage) find_package(Threads REQUIRED) -find_library(NSL_LIBRARIES nsl ) -find_library(RT_LIBRARIES rt ) -find_library(SOCKET_LIBRARIES socket ) +find_library(NSL_LIBRARIES nsl ) +find_library(RT_LIBRARIES rt ) +find_library(SOCKET_LIBRARIES socket) # For toxcore. -pkg_use_module(LIBSODIUM libsodium ) +pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET) # For toxav. -pkg_use_module(OPUS "opus;Opus" ) -pkg_use_module(VPX "vpx;libvpx" ) +pkg_search_module(OPUS opus IMPORTED_TARGET) +if(NOT OPUS_FOUND) + pkg_search_module(OPUS Opus IMPORTED_TARGET) +endif() +pkg_search_module(VPX vpx IMPORTED_TARGET) +if(NOT VPX_FOUND) + pkg_search_module(VPX libvpx IMPORTED_TARGET) +endif() # For tox-bootstrapd. -pkg_use_module(LIBCONFIG libconfig ) +pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET) ############################################################################### # diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake index 61f7228f..cbc62f41 100644 --- a/cmake/ModulePackage.cmake +++ b/cmake/ModulePackage.cmake @@ -21,41 +21,6 @@ endif() find_package(PkgConfig) -function(pkg_use_module mod pkgs) - foreach(pkg IN ITEMS ${pkgs}) - if(PKG_CONFIG_FOUND) - pkg_search_module(${mod} ${pkg} IMPORTED_TARGET) - endif() - if(NOT ${mod}_FOUND) - find_package(${pkg} QUIET) - # This is very very ugly, but the variables are sometimes used in this scope - # and sometimes in the parent scope, so we have to set them to both places. - set(${mod}_FOUND ${${pkg}_FOUND}) - set(${mod}_FOUND ${${pkg}_FOUND} PARENT_SCOPE) - set(${mod}_LIBRARIES ${${pkg}_LIBS}) - set(${mod}_LIBRARIES ${${pkg}_LIBS} PARENT_SCOPE) - set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS}) - set(${mod}_LIBRARY_DIRS ${${pkg}_LIBRARY_DIRS} PARENT_SCOPE) - set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS}) - set(${mod}_INCLUDE_DIRS ${${pkg}_INCLUDE_DIRS} PARENT_SCOPE) - endif() - if(${mod}_FOUND) - link_directories(${${mod}_LIBRARY_DIRS}) - include_directories(${${mod}_INCLUDE_DIRS}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) - - if(NOT MSVC) - foreach(dir ${${mod}_INCLUDE_DIRS}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE) - endforeach() - endif() - break() - endif() - endforeach() -endfunction() - function(add_module lib) set(${lib}_SOURCES ${ARGN} PARENT_SCOPE) diff --git a/other/bootstrap_daemon/CMakeLists.txt b/other/bootstrap_daemon/CMakeLists.txt index 260c72d2..52d8c5d6 100644 --- a/other/bootstrap_daemon/CMakeLists.txt +++ b/other/bootstrap_daemon/CMakeLists.txt @@ -20,6 +20,9 @@ add_executable(tox-bootstrapd ../bootstrap_node_packets.c ../bootstrap_node_packets.h) target_link_libraries(tox-bootstrapd PRIVATE ${LIBCONFIG_LIBRARIES}) +target_link_directories(tox-bootstrapd PRIVATE ${LIBCONFIG_LIBRARY_DIRS}) +target_include_directories(tox-bootstrapd SYSTEM PRIVATE ${LIBCONFIG_INCLUDE_DIRS}) +target_compile_options(tox-bootstrapd PRIVATE ${LIBCONFIG_CFLAGS_OTHER}) if(TARGET toxcore_static) target_link_libraries(tox-bootstrapd PRIVATE toxcore_static) else() diff --git a/other/docker/coverage/Dockerfile b/other/docker/coverage/Dockerfile index 51504b8d..56f88064 100644 --- a/other/docker/coverage/Dockerfile +++ b/other/docker/coverage/Dockerfile @@ -64,12 +64,12 @@ RUN /work/other/proxy/proxy_server \ WORKDIR /work/mallocfail RUN ["git", "clone", "--depth=1", "https://github.com/ralight/mallocfail", "/work/mallocfail"] -COPY syscall_funcs.c src/ +COPY other/docker/coverage/syscall_funcs.c src/ RUN gcc -fPIC -shared -O2 -g3 -Wall -Ideps/uthash -Ideps/sha3 deps/*/*.c src/*.c -o mallocfail.so -ldl -lbacktrace \ && install mallocfail.so /usr/local/lib/mallocfail.so WORKDIR /work/_build -COPY run_mallocfail /usr/local/bin/ +COPY other/docker/coverage/run_mallocfail /usr/local/bin/ RUN ["run_mallocfail", "--ctest=2", "--jobs=8"] RUN ["gcovr", \ "--sort-percentage", \ diff --git a/other/docker/coverage/run b/other/docker/coverage/run index d501252b..368d8429 100755 --- a/other/docker/coverage/run +++ b/other/docker/coverage/run @@ -5,5 +5,5 @@ set -eux read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))" docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . -docker build -t toxchat/c-toxcore:coverage other/docker/coverage +docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile . docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov -x "llvm-cov gcov" diff --git a/other/docker/coverage/serve b/other/docker/coverage/serve index 93145338..94a09d15 100755 --- a/other/docker/coverage/serve +++ b/other/docker/coverage/serve @@ -3,6 +3,6 @@ set -eux docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . -docker build -t toxchat/c-toxcore:coverage other/docker/coverage +docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile . docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/Dockerfile.nginx other/docker/coverage docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage-nginx diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 3ca9f88e..82f228bf 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,6 +8,10 @@ if(TARGET toxcore_static) else() target_link_libraries(misc_tools PRIVATE toxcore_shared) endif() +target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES}) +target_link_directories(misc_tools PUBLIC ${LIBSODIUM_LIBRARY_DIRS}) +target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS}) +target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER}) ################################################################################ #