diff --git a/CMakeLists.txt b/CMakeLists.txt index f211207794..d5cbbbdb0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,7 +352,9 @@ set(toxcore_SOURCES toxcore/tox_unpack.h toxcore/util.c toxcore/util.h) -if(TARGET unofficial-sodium::sodium) +if(TARGET libsodium::libsodium) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} libsodium::libsodium) +elseif(TARGET unofficial-sodium::sodium) set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium) else() set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES}) @@ -399,7 +401,9 @@ if(BUILD_TOXAV) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav) - if(MSVC) + if(TARGET Opus::opus AND TARGET libvpx::libvpx) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Opus::opus libvpx::libvpx) + elseif(TARGET PkgConfig::OPUS AND TARGET PkgConfig::VPX) set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX) else() set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) @@ -452,7 +456,9 @@ if(SOCKET_LIBRARIES) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket) endif() -if(TARGET PThreads4W::PThreads4W) +if(TARGET pthreads4w::pthreads4w) + set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} pthreads4w::pthreads4w) +elseif(TARGET PThreads4W::PThreads4W) set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads) @@ -510,17 +516,19 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox) # ################################################################################ -add_library(test_util STATIC - toxcore/DHT_test_util.cc - toxcore/DHT_test_util.hh - toxcore/crypto_core_test_util.cc - toxcore/crypto_core_test_util.hh - toxcore/mem_test_util.cc - toxcore/mem_test_util.hh - toxcore/network_test_util.cc - toxcore/network_test_util.hh - toxcore/test_util.cc - toxcore/test_util.hh) +if(UNITTEST) + add_library(test_util STATIC + toxcore/DHT_test_util.cc + toxcore/DHT_test_util.hh + toxcore/crypto_core_test_util.cc + toxcore/crypto_core_test_util.hh + toxcore/mem_test_util.cc + toxcore/mem_test_util.hh + toxcore/network_test_util.cc + toxcore/network_test_util.hh + toxcore/test_util.cc + toxcore/test_util.hh) +endif() function(unit_test subdir target) add_executable(unit_${target}_test ${subdir}/${target}_test.cc) @@ -530,6 +538,13 @@ function(unit_test subdir target) else() target_link_libraries(unit_${target}_test PRIVATE toxcore_shared) endif() + if(TARGET pthreads4w::pthreads4w) + target_link_libraries(unit_${target}_test PRIVATE pthreads4w::pthreads4w) + elseif(TARGET PThreads4W::PThreads4W) + target_link_libraries(unit_${target}_test PRIVATE PThreads4W::PThreads4W) + elseif(TARGET Threads::Threads) + target_link_libraries(unit_${target}_test PRIVATE Threads::Threads) + endif() target_link_libraries(unit_${target}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock) set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}") add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test) @@ -583,10 +598,14 @@ if(DHT_BOOTSTRAP) target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared) endif() target_link_libraries(DHT_bootstrap PRIVATE misc_tools) - if(TARGET unofficial-sodium::sodium) + if(TARGET libsodium::libsodium) + target_link_libraries(DHT_bootstrap PRIVATE libsodium::libsodium) + elseif(TARGET unofficial-sodium::sodium) target_link_libraries(DHT_bootstrap PRIVATE unofficial-sodium::sodium) endif() - if(TARGET PThreads4W::PThreads4W) + if(TARGET pthreads4w::pthreads4w) + target_link_libraries(DHT_bootstrap PRIVATE pthreads4w::pthreads4w) + elseif(TARGET PThreads4W::PThreads4W) target_link_libraries(DHT_bootstrap PRIVATE PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) target_link_libraries(DHT_bootstrap PRIVATE Threads::Threads) diff --git a/auto_tests/CMakeLists.txt b/auto_tests/CMakeLists.txt index d891ba122b..87b45d66b1 100644 --- a/auto_tests/CMakeLists.txt +++ b/auto_tests/CMakeLists.txt @@ -9,7 +9,9 @@ if(TARGET toxcore_static) else() target_link_libraries(auto_test_support PRIVATE toxcore_shared) endif() -if(TARGET PThreads4W::PThreads4W) +if(TARGET pthreads4w::pthreads4w) + target_link_libraries(auto_test_support PRIVATE pthreads4w::pthreads4w) +elseif(TARGET PThreads4W::PThreads4W) target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) target_link_libraries(auto_test_support PRIVATE Threads::Threads) @@ -23,11 +25,18 @@ function(auto_test target) else() target_link_libraries(auto_${target}_test PRIVATE toxcore_shared) endif() - if(TARGET PThreads4W::PThreads4W) + if(TARGET pthreads4w::pthreads4w) + target_link_libraries(auto_${target}_test PRIVATE pthreads4w::pthreads4w) + elseif(TARGET PThreads4W::PThreads4W) target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) target_link_libraries(auto_${target}_test PRIVATE Threads::Threads) endif() + if(TARGET libsodium::libsodium) + target_link_libraries(auto_${target}_test PRIVATE libsodium::libsodium) + elseif(TARGET unofficial-sodium::sodium) + target_link_libraries(auto_${target}_test PRIVATE unofficial-sodium::sodium) + endif() 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 @@ -98,7 +107,10 @@ if(BUILD_TOXAV) auto_test(toxav_basic) auto_test(toxav_many) - if(MSVC) + if(TARGET libvpx::libvpx) + target_link_libraries(auto_toxav_basic_test PRIVATE libvpx::libvpx) + target_link_libraries(auto_toxav_many_test PRIVATE libvpx::libvpx) + elseif(TARGET PkgConfig::VPX) target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX) target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX) else() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 941bc33158..c222a2b587 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ jobs: shared: conan.shared: "True" steps: - - bash: python -m pip install conan==1.59.0 + - bash: python -m pip install conan - bash: git submodule update --init --recursive - - bash: conan install -if _build -o with_tests=True -o shared=$(conan.shared) . - - bash: CONAN_CPU_COUNT=50 CTEST_OUTPUT_ON_FAILURE=1 conan build -bf _build -if _build . || true + - bash: conan profile detect + - bash: conan build -o with_tests=True -o shared=$(conan.shared) . diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 900e9b185a..4c552c2271 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -12,14 +12,20 @@ find_library(SOCKET_LIBRARIES socket) find_package(pthreads QUIET) if(NOT TARGET PThreads4W::PThreads4W) + find_package(pthreads4w QUIET) +endif() +if(NOT TARGET PThreads4W::PThreads4W AND NOT TARGET pthreads4w::pthreads4w) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) endif() # For toxcore. -pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET REQUIRED) +pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET) if(MSVC) - find_package(unofficial-sodium REQUIRED) + find_package(libsodium) + if(NOT TARGET libsodium::libsodium) + find_package(unofficial-sodium REQUIRED) + endif() endif() # For toxav. @@ -27,10 +33,23 @@ pkg_search_module(OPUS opus IMPORTED_TARGET) if(NOT OPUS_FOUND) pkg_search_module(OPUS Opus IMPORTED_TARGET) endif() +if(NOT OPUS_FOUND) + find_package(Opus) + if(TARGET Opus::opus) + set(OPUS_FOUND TRUE) + endif() +endif() + pkg_search_module(VPX vpx IMPORTED_TARGET) if(NOT VPX_FOUND) pkg_search_module(VPX libvpx IMPORTED_TARGET) endif() +if(NOT VPX_FOUND) + find_package(libvpx) + if(TARGET libvpx::libvpx) + set(VPX_FOUND TRUE) + endif() +endif() # For tox-bootstrapd. pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET) diff --git a/conanfile.py b/conanfile.py index e9af70b5c9..553b90d17c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,21 +1,16 @@ # pylint: disable=not-callable -import os -import re - -from conans import CMake -from conans import ConanFile -from conans.tools import collect_libs -from conans.tools import load +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps class ToxConan(ConanFile): name = "c-toxcore" + version = "0.2.20" url = "https://tox.chat" description = "The future of online communications." license = "GPL-3.0-only" settings = "os", "compiler", "build_type", "arch" - requires = "libsodium/1.0.18", "opus/1.3.1", "libvpx/1.9.0" - generators = "cmake_find_package" + requires = "libsodium/1.0.20", "opus/1.5.2", "libvpx/1.14.1", "pthreads4w/3.0.0", "gtest/1.15.0" scm = {"type": "git", "url": "auto", "revision": "auto"} options = { @@ -27,61 +22,36 @@ class ToxConan(ConanFile): "with_tests": False, } - _cmake = None - - def _create_cmake(self): - if self._cmake is not None: - return self._cmake - - self._cmake = CMake(self) - self._cmake.definitions["AUTOTEST"] = self.options.with_tests - self._cmake.definitions["BUILD_MISC_TESTS"] = self.options.with_tests - self._cmake.definitions["TEST_TIMEOUT_SECONDS"] = "300" + exports_sources = "CMakeLists.txt", "toxav/*", "toxcore/*" - self._cmake.definitions[ - "CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared - self._cmake.definitions["ENABLE_SHARED"] = self.options.shared - self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared - self._cmake.definitions["MUST_BUILD_TOXAV"] = True - if self.settings.compiler == "Visual Studio": - self._cmake.definitions["MSVC_STATIC_SODIUM"] = True - self._cmake.definitions[ - "FLAT_OUTPUT_STRUCTURE"] = self.options.shared + def layout(self): + cmake_layout(self) - self._cmake.configure() - return self._cmake + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.variables["AUTOTEST"] = self.options.with_tests + tc.variables["BUILD_MISC_TESTS"] = self.options.with_tests + tc.variables["UNITTEST"] = self.options.with_tests + tc.variables["TEST_TIMEOUT_SECONDS"] = "300" - def set_version(self): - content = load(os.path.join(self.recipe_folder, "CMakeLists.txt")) - version_major = re.search(r"set\(PROJECT_VERSION_MAJOR \"(.*)\"\)", - content).group(1) - version_minor = re.search(r"set\(PROJECT_VERSION_MINOR \"(.*)\"\)", - content).group(1) - version_patch = re.search(r"set\(PROJECT_VERSION_PATCH \"(.*)\"\)", - content).group(1) - self.version = "%s.%s.%s" % ( - version_major.strip(), - version_minor.strip(), - version_patch.strip(), - ) - - def requirements(self): - if self.settings.os == "Windows": - self.requires("pthreads4w/3.0.0") + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared + tc.variables["ENABLE_SHARED"] = self.options.shared + tc.variables["ENABLE_STATIC"] = not self.options.shared + tc.variables["MUST_BUILD_TOXAV"] = True + tc.generate() def build(self): - cmake = self._create_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() - if self.options.with_tests: - cmake.test(output_on_failure=True) + cmake.test() def package(self): - cmake = self._create_cmake() + cmake = CMake(self) cmake.install() def package_info(self): - self.cpp_info.libs = collect_libs(self) - - if self.settings.os == "Windows": - self.cpp_info.system_libs = ["Ws2_32", "Iphlpapi"] + self.cpp_info.libs = ["hello"] diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index d664c0fa86..5ae7a7c8d0 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,7 +8,9 @@ if(TARGET toxcore_static) else() target_link_libraries(misc_tools PRIVATE toxcore_shared) endif() -if(TARGET unofficial-sodium::sodium) +if(TARGET libsodium::libsodium) + target_link_libraries(misc_tools PRIVATE libsodium::libsodium) +elseif(TARGET unofficial-sodium::sodium) target_link_libraries(misc_tools PRIVATE unofficial-sodium::sodium) else() target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES}) @@ -16,7 +18,9 @@ else() target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS}) target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER}) endif() -if(TARGET PThreads4W::PThreads4W) +if(TARGET pthreads4w::pthreads4w) + target_link_libraries(misc_tools PRIVATE pthreads4w::pthreads4w) +elseif(TARGET PThreads4W::PThreads4W) target_link_libraries(misc_tools PRIVATE PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) target_link_libraries(misc_tools PRIVATE Threads::Threads) @@ -36,7 +40,9 @@ if(BUILD_MISC_TESTS) else() target_link_libraries(Messenger_test PRIVATE toxcore_shared) endif() - if(TARGET PThreads4W::PThreads4W) + if(TARGET pthreads4w::pthreads4w) + target_link_libraries(Messenger_test PRIVATE pthreads4w::pthreads4w) + elseif(TARGET PThreads4W::PThreads4W) target_link_libraries(Messenger_test PRIVATE PThreads4W::PThreads4W) elseif(TARGET Threads::Threads) target_link_libraries(Messenger_test PRIVATE Threads::Threads)