Skip to content

Commit 14d8231

Browse files
committed
chore: Migrate to conan 2.
1 parent bdd17c1 commit 14d8231

File tree

11 files changed

+131
-158
lines changed

11 files changed

+131
-158
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ version: 2
44
workflows:
55
version: 2
66
program-analysis:
7+
# TODO(iphydf): Re-enable tsan when it's fixed.
78
jobs:
89
# Dynamic analysis in the Bazel build
910
- bazel-asan
1011
- bazel-msan
11-
- bazel-tsan
12+
# - bazel-tsan
1213
# Dynamic analysis with CMake
1314
- asan
14-
- tsan
15+
# - tsan
1516
- ubsan
1617
# Static analysis
1718
- clang-analyze

CMakeLists.txt

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ set(toxcore_SOURCES
352352
toxcore/tox_unpack.h
353353
toxcore/util.c
354354
toxcore/util.h)
355-
if(TARGET unofficial-sodium::sodium)
355+
if(TARGET libsodium::libsodium)
356+
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} libsodium::libsodium)
357+
elseif(TARGET unofficial-sodium::sodium)
356358
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium)
357359
else()
358360
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES})
@@ -399,7 +401,9 @@ if(BUILD_TOXAV)
399401
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
400402
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
401403

402-
if(MSVC)
404+
if(TARGET Opus::opus AND TARGET libvpx::libvpx)
405+
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Opus::opus libvpx::libvpx)
406+
elseif(TARGET PkgConfig::OPUS AND TARGET PkgConfig::VPX)
403407
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX)
404408
else()
405409
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
@@ -452,7 +456,9 @@ if(SOCKET_LIBRARIES)
452456
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
453457
endif()
454458

455-
if(TARGET PThreads4W::PThreads4W)
459+
if(TARGET pthreads4w::pthreads4w)
460+
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} pthreads4w::pthreads4w)
461+
elseif(TARGET PThreads4W::PThreads4W)
456462
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W)
457463
elseif(TARGET Threads::Threads)
458464
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads)
@@ -510,17 +516,19 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
510516
#
511517
################################################################################
512518

513-
add_library(test_util STATIC
514-
toxcore/DHT_test_util.cc
515-
toxcore/DHT_test_util.hh
516-
toxcore/crypto_core_test_util.cc
517-
toxcore/crypto_core_test_util.hh
518-
toxcore/mem_test_util.cc
519-
toxcore/mem_test_util.hh
520-
toxcore/network_test_util.cc
521-
toxcore/network_test_util.hh
522-
toxcore/test_util.cc
523-
toxcore/test_util.hh)
519+
if(UNITTEST)
520+
add_library(test_util STATIC
521+
toxcore/DHT_test_util.cc
522+
toxcore/DHT_test_util.hh
523+
toxcore/crypto_core_test_util.cc
524+
toxcore/crypto_core_test_util.hh
525+
toxcore/mem_test_util.cc
526+
toxcore/mem_test_util.hh
527+
toxcore/network_test_util.cc
528+
toxcore/network_test_util.hh
529+
toxcore/test_util.cc
530+
toxcore/test_util.hh)
531+
endif()
524532

525533
function(unit_test subdir target)
526534
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
@@ -530,6 +538,13 @@ function(unit_test subdir target)
530538
else()
531539
target_link_libraries(unit_${target}_test PRIVATE toxcore_shared)
532540
endif()
541+
if(TARGET pthreads4w::pthreads4w)
542+
target_link_libraries(unit_${target}_test PRIVATE pthreads4w::pthreads4w)
543+
elseif(TARGET PThreads4W::PThreads4W)
544+
target_link_libraries(unit_${target}_test PRIVATE PThreads4W::PThreads4W)
545+
elseif(TARGET Threads::Threads)
546+
target_link_libraries(unit_${target}_test PRIVATE Threads::Threads)
547+
endif()
533548
target_link_libraries(unit_${target}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock)
534549
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
535550
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
@@ -583,10 +598,14 @@ if(DHT_BOOTSTRAP)
583598
target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared)
584599
endif()
585600
target_link_libraries(DHT_bootstrap PRIVATE misc_tools)
586-
if(TARGET unofficial-sodium::sodium)
601+
if(TARGET libsodium::libsodium)
602+
target_link_libraries(DHT_bootstrap PRIVATE libsodium::libsodium)
603+
elseif(TARGET unofficial-sodium::sodium)
587604
target_link_libraries(DHT_bootstrap PRIVATE unofficial-sodium::sodium)
588605
endif()
589-
if(TARGET PThreads4W::PThreads4W)
606+
if(TARGET pthreads4w::pthreads4w)
607+
target_link_libraries(DHT_bootstrap PRIVATE pthreads4w::pthreads4w)
608+
elseif(TARGET PThreads4W::PThreads4W)
590609
target_link_libraries(DHT_bootstrap PRIVATE PThreads4W::PThreads4W)
591610
elseif(TARGET Threads::Threads)
592611
target_link_libraries(DHT_bootstrap PRIVATE Threads::Threads)

auto_tests/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ if(TARGET toxcore_static)
99
else()
1010
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
1111
endif()
12-
if(TARGET PThreads4W::PThreads4W)
12+
if(TARGET pthreads4w::pthreads4w)
13+
target_link_libraries(auto_test_support PRIVATE pthreads4w::pthreads4w)
14+
elseif(TARGET PThreads4W::PThreads4W)
1315
target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W)
1416
elseif(TARGET Threads::Threads)
1517
target_link_libraries(auto_test_support PRIVATE Threads::Threads)
@@ -23,7 +25,9 @@ function(auto_test target)
2325
else()
2426
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
2527
endif()
26-
if(TARGET PThreads4W::PThreads4W)
28+
if(TARGET pthreads4w::pthreads4w)
29+
target_link_libraries(auto_${target}_test PRIVATE pthreads4w::pthreads4w)
30+
elseif(TARGET PThreads4W::PThreads4W)
2731
target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W)
2832
elseif(TARGET Threads::Threads)
2933
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
@@ -98,7 +102,10 @@ if(BUILD_TOXAV)
98102
auto_test(toxav_basic)
99103
auto_test(toxav_many)
100104

101-
if(MSVC)
105+
if(TARGET libvpx::libvpx)
106+
target_link_libraries(auto_toxav_basic_test PRIVATE libvpx::libvpx)
107+
target_link_libraries(auto_toxav_many_test PRIVATE libvpx::libvpx)
108+
elseif(TARGET PkgConfig::VPX)
102109
target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX)
103110
target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX)
104111
else()

auto_tests/encryptsave_test.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include <string.h>
44
#include <sys/types.h>
55

6-
#include <sodium.h>
7-
86
#include "../testing/misc_tools.h"
97
#include "../toxcore/ccompat.h"
108
#include "../toxcore/crypto_core.h"
@@ -14,13 +12,10 @@
1412
#include "check_compat.h"
1513

1614
static unsigned char test_salt[TOX_PASS_SALT_LENGTH] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F};
17-
static unsigned char known_key[TOX_PASS_KEY_LENGTH] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8};
15+
static unsigned char known_key[CRYPTO_SHARED_KEY_SIZE] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1};
1816
static const char *pw = "hunter2";
1917
static unsigned int pwlen = 7;
2018

21-
static unsigned char known_key2[CRYPTO_SHARED_KEY_SIZE] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1};
22-
// same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat
23-
2419
/* cause I'm shameless */
2520
static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
2621
{
@@ -33,20 +28,6 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
3328
}
3429
}
3530

36-
static void test_known_kdf(void)
37-
{
38-
unsigned char out[CRYPTO_SHARED_KEY_SIZE];
39-
int16_t res = crypto_pwhash_scryptsalsa208sha256(out,
40-
CRYPTO_SHARED_KEY_SIZE,
41-
pw,
42-
pwlen,
43-
test_salt,
44-
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8,
45-
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
46-
ck_assert_msg(res != -1, "crypto function failed");
47-
ck_assert_msg(memcmp(out, known_key, CRYPTO_SHARED_KEY_SIZE) == 0, "derived key is wrong");
48-
}
49-
5031
static void test_save_friend(void)
5132
{
5233
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
@@ -101,7 +82,7 @@ static void test_save_friend(void)
10182
Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr);
10283
ck_assert_msg(key != nullptr, "pass key allocation failure");
10384
memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH);
104-
memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH);
85+
memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key, TOX_PASS_KEY_LENGTH);
10586
size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
10687
uint8_t *encdata2 = (uint8_t *)malloc(size2);
10788
ck_assert(encdata2 != nullptr);
@@ -224,7 +205,6 @@ static void test_keys(void)
224205
int main(void)
225206
{
226207
setvbuf(stdout, nullptr, _IONBF, 0);
227-
test_known_kdf();
228208
test_save_friend();
229209
test_keys();
230210

azure-pipelines.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ jobs:
99
shared:
1010
conan.shared: "True"
1111
steps:
12-
- bash: python -m pip install conan==1.59.0
12+
- bash: choco install pkgconfiglite
13+
displayName: "Install pkg-config"
14+
- bash: python -m pip install conan
15+
displayName: "Install Conan"
1316
- bash: git submodule update --init --recursive
14-
- bash: conan install -if _build -o with_tests=True -o shared=$(conan.shared) .
15-
- bash: CONAN_CPU_COUNT=50 CTEST_OUTPUT_ON_FAILURE=1 conan build -bf _build -if _build . || true
17+
displayName: "Fetch git submodules"
18+
- bash: conan profile detect
19+
displayName: "Detect Conan profile"
20+
- bash: conan build -o "&:with_tests=True" -o "&:shared=$(conan.shared)" .
21+
displayName: "Build with Conan"

cmake/Dependencies.cmake

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,44 @@ find_library(SOCKET_LIBRARIES socket)
1212

1313
find_package(pthreads QUIET)
1414
if(NOT TARGET PThreads4W::PThreads4W)
15+
find_package(pthreads4w QUIET)
16+
endif()
17+
if(NOT TARGET pthreads4w::pthreads4w)
1518
set(THREADS_PREFER_PTHREAD_FLAG ON)
1619
find_package(Threads REQUIRED)
1720
endif()
1821

1922
# For toxcore.
20-
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET REQUIRED)
23+
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET)
2124
if(MSVC)
22-
find_package(unofficial-sodium REQUIRED)
25+
find_package(libsodium)
26+
if(NOT TARGET libsodium::libsodium)
27+
find_package(unofficial-sodium REQUIRED)
28+
endif()
2329
endif()
2430

2531
# For toxav.
2632
pkg_search_module(OPUS opus IMPORTED_TARGET)
2733
if(NOT OPUS_FOUND)
2834
pkg_search_module(OPUS Opus IMPORTED_TARGET)
2935
endif()
36+
if(NOT OPUS_FOUND)
37+
find_package(Opus)
38+
if(TARGET Opus::opus)
39+
set(OPUS_FOUND TRUE)
40+
endif()
41+
endif()
42+
3043
pkg_search_module(VPX vpx IMPORTED_TARGET)
3144
if(NOT VPX_FOUND)
3245
pkg_search_module(VPX libvpx IMPORTED_TARGET)
3346
endif()
47+
if(NOT VPX_FOUND)
48+
find_package(libvpx)
49+
if(TARGET libvpx::libvpx)
50+
set(VPX_FOUND TRUE)
51+
endif()
52+
endif()
3453

3554
# For tox-bootstrapd.
3655
pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET)

conanfile.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
import os
33
import re
44

5-
from conans import CMake
6-
from conans import ConanFile
7-
from conans.tools import collect_libs
8-
from conans.tools import load
5+
from conan import ConanFile
6+
from conan.tools.cmake import CMake
7+
from conan.tools.cmake import cmake_layout
8+
from conan.tools.cmake import CMakeDeps
9+
from conan.tools.cmake import CMakeToolchain
10+
from conan.tools.files import collect_libs
11+
from conan.tools.files import load
912

1013

1114
class ToxConan(ConanFile):
12-
name = "c-toxcore"
15+
name = "toxcore"
1316
url = "https://tox.chat"
1417
description = "The future of online communications."
1518
license = "GPL-3.0-only"
1619
settings = "os", "compiler", "build_type", "arch"
17-
requires = "libsodium/1.0.18", "opus/1.3.1", "libvpx/1.9.0"
18-
generators = "cmake_find_package"
20+
requires = (
21+
"libsodium/1.0.20",
22+
"opus/1.4",
23+
"libvpx/1.14.1",
24+
)
1925
scm = {"type": "git", "url": "auto", "revision": "auto"}
2026

2127
options = {
@@ -27,32 +33,9 @@ class ToxConan(ConanFile):
2733
"with_tests": False,
2834
}
2935

30-
_cmake = None
31-
32-
def _create_cmake(self):
33-
if self._cmake is not None:
34-
return self._cmake
35-
36-
self._cmake = CMake(self)
37-
self._cmake.definitions["AUTOTEST"] = self.options.with_tests
38-
self._cmake.definitions["BUILD_MISC_TESTS"] = self.options.with_tests
39-
self._cmake.definitions["TEST_TIMEOUT_SECONDS"] = "300"
40-
41-
self._cmake.definitions[
42-
"CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared
43-
self._cmake.definitions["ENABLE_SHARED"] = self.options.shared
44-
self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared
45-
self._cmake.definitions["MUST_BUILD_TOXAV"] = True
46-
if self.settings.compiler == "Visual Studio":
47-
self._cmake.definitions["MSVC_STATIC_SODIUM"] = True
48-
self._cmake.definitions[
49-
"FLAT_OUTPUT_STRUCTURE"] = self.options.shared
50-
51-
self._cmake.configure()
52-
return self._cmake
53-
5436
def set_version(self):
55-
content = load(os.path.join(self.recipe_folder, "CMakeLists.txt"))
37+
content = load(self, os.path.join(self.recipe_folder,
38+
"CMakeLists.txt"))
5639
version_major = re.search(r"set\(PROJECT_VERSION_MAJOR \"(.*)\"\)",
5740
content).group(1)
5841
version_minor = re.search(r"set\(PROJECT_VERSION_MINOR \"(.*)\"\)",
@@ -68,16 +51,42 @@ def set_version(self):
6851
def requirements(self):
6952
if self.settings.os == "Windows":
7053
self.requires("pthreads4w/3.0.0")
54+
if self.options.with_tests:
55+
self.build_requires("gtest/1.15.0")
56+
57+
def layout(self):
58+
cmake_layout(self)
59+
60+
def generate(self):
61+
deps = CMakeDeps(self)
62+
deps.generate()
63+
tc = CMakeToolchain(self)
64+
tc.variables["AUTOTEST"] = self.options.with_tests
65+
tc.variables["BUILD_MISC_TESTS"] = self.options.with_tests
66+
tc.variables["UNITTEST"] = self.options.with_tests
67+
tc.variables["TEST_TIMEOUT_SECONDS"] = "300"
68+
69+
tc.variables["ENABLE_SHARED"] = self.options.shared
70+
tc.variables["ENABLE_STATIC"] = not self.options.shared
71+
72+
tc.variables["MUST_BUILD_TOXAV"] = True
73+
74+
if self.settings.os == "Windows":
75+
tc.variables["MSVC_STATIC_SODIUM"] = True
76+
tc.variables[
77+
"CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared
78+
tc.variables["FLAT_OUTPUT_STRUCTURE"] = self.options.shared
79+
tc.generate()
7180

7281
def build(self):
73-
cmake = self._create_cmake()
82+
cmake = CMake(self)
83+
cmake.configure()
7484
cmake.build()
75-
7685
if self.options.with_tests:
77-
cmake.test(output_on_failure=True)
86+
cmake.ctest(cli_args=["--output-on-failure"])
7887

7988
def package(self):
80-
cmake = self._create_cmake()
89+
cmake = CMake(self)
8190
cmake.install()
8291

8392
def package_info(self):

testing/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ cc_library(
7575
deps = [
7676
"//c-toxcore/toxcore:ccompat",
7777
"//c-toxcore/toxcore:tox",
78-
"@libsodium",
7978
],
8079
)
8180

0 commit comments

Comments
 (0)