Add support for the conan C/C++ package manager

* Don't overwrite the CMAKE_MODULE_PATH
* Allow linking libsodium statically with MSVC
* Allow finding libsodium the normal way on MSVC
* Allow using pthreads4w for pthreads on MSVC
* Fall back to find_package if pkg_find_module fails
* Don't pass incompatible compile flags to MSVC
* Also try to find Opus and libvpx using their canonical names
* Support building using conan
* Allow pkg_use_module to take a list of libraries to look for
* Build for Windows on Appveyor using conan
This commit is contained in:
Robin Linden 2020-05-14 01:50:43 +02:00
parent 03a511482f
commit 56992b099e
No known key found for this signature in database
GPG Key ID: 601A604B7E605776
5 changed files with 107 additions and 54 deletions

View File

@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 2.8.12)
cmake_policy(VERSION 2.8.12) cmake_policy(VERSION 2.8.12)
project(toxcore) project(toxcore)
set(CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
################################################################################ ################################################################################
# #
@ -115,6 +115,13 @@ option(NON_HERMETIC_TESTS "Whether to build and run tests that depend on an inte
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)
if(MSVC)
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
if(MSVC_STATIC_SODIUM)
add_definitions(-DSODIUM_STATIC=1 -DSODIUM_EXPORT)
endif()
endif()
include(Dependencies) include(Dependencies)
if(MUST_BUILD_TOXAV) if(MUST_BUILD_TOXAV)

View File

@ -1,35 +1,23 @@
--- ---
cache: cache:
- '%APPDATA%\downloads' - '%USERPROFILE%\.conan'
install: install:
# TODO(iphydf): Remove this when appveyor gets curl back, which it should - set PATH=C:\Python38-x64\Scripts;%PATH%
# have according to https://www.appveyor.com/docs/how-to/download-file/. - py -3 -m pip install conan
- choco install curl - conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
- refreshenv
- if not exist %APPDATA%\downloads mkdir %APPDATA%\downloads
- cd third_party
# libsodium
- mkdir libsodium && cd libsodium
- if not exist %APPDATA%\downloads\libsodium.zip curl -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-msvc.zip -o %APPDATA%\downloads\libsodium.zip
- unzip %APPDATA%\downloads\libsodium.zip
- cd ..
# pthreads-win32
- mkdir pthreads-win32 && cd pthreads-win32
- if not exist %APPDATA%\downloads\pthreads.zip curl -L ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip -o %APPDATA%\downloads\pthreads.zip
- unzip %APPDATA%\downloads\pthreads.zip
- cd ../..
before_build: before_build:
- cmake -B_build -H. -DBOOTSTRAP_DAEMON=OFF -DENABLE_SHARED=OFF -DBUILD_TOXAV=OFF -DTEST_TIMEOUT_SECONDS=120 -DAUTOTEST=ON - ps: |
mkdir _build
cd _build
conan install ..
build: build_script:
project: _build/INSTALL.vcxproj - conan build .. --configure --build
test_script: test_script:
- copy third_party\pthreads-win32\Pre-built.2\dll\x86\*.dll _build
- copy third_party\libsodium\Win32\Debug\v140\dynamic\libsodium.dll _build
- cd _build
# TODO(iphydf): Tests are unstable and slow on windows at the moment. # TODO(iphydf): Tests are unstable and slow on windows at the moment.
- ctest -j50 --output-on-failure -C Debug & - set CONAN_CPU_COUNT=50
- conan build .. --test &
exit 0 exit 0

View File

@ -16,8 +16,8 @@ find_library(SOCKET_LIBRARIES socket )
pkg_use_module(LIBSODIUM libsodium ) pkg_use_module(LIBSODIUM libsodium )
# For toxav. # For toxav.
pkg_use_module(OPUS opus ) pkg_use_module(OPUS "opus;Opus" )
pkg_use_module(VPX vpx ) pkg_use_module(VPX "vpx;libvpx" )
# For tox-bootstrapd. # For tox-bootstrapd.
pkg_use_module(LIBCONFIG libconfig ) pkg_use_module(LIBCONFIG libconfig )
@ -38,18 +38,20 @@ pkg_use_module(MSGPACK msgpack )
if(MSVC) if(MSVC)
# libsodium # libsodium
# --------- # ---------
find_library(LIBSODIUM_LIBRARIES if(NOT LIBSODIUM_FOUND)
NAMES sodium libsodium find_library(LIBSODIUM_LIBRARIES
PATHS NAMES sodium libsodium
"third_party/libsodium/Win32/Release/v140/dynamic" PATHS
"third_party/libsodium/x64/Release/v140/dynamic" "third_party/libsodium/Win32/Release/v140/dynamic"
) "third_party/libsodium/x64/Release/v140/dynamic"
if(LIBSODIUM_LIBRARIES) )
include_directories("third_party/libsodium/include") if(LIBSODIUM_LIBRARIES)
set(LIBSODIUM_FOUND TRUE) include_directories("third_party/libsodium/include")
message("libsodium: ${LIBSODIUM_LIBRARIES}") set(LIBSODIUM_FOUND TRUE)
else() message("libsodium: ${LIBSODIUM_LIBRARIES}")
message(FATAL_ERROR "libsodium libraries not found") else()
message(FATAL_ERROR "libsodium libraries not found")
endif()
endif() endif()
# pthreads # pthreads
@ -66,7 +68,12 @@ if(MSVC)
add_definitions(-DHAVE_STRUCT_TIMESPEC) add_definitions(-DHAVE_STRUCT_TIMESPEC)
message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}") message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}")
else() else()
message(FATAL_ERROR "libpthreads libraries not found") find_package(pthreads4w)
if(NOT pthreads4w_FOUND)
message(FATAL_ERROR "libpthreads libraries not found")
endif()
include_directories(${pthreads4w_INCLUDE_DIR})
link_libraries(${pthreads4w_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()

View File

@ -21,21 +21,39 @@ endif()
find_package(PkgConfig) find_package(PkgConfig)
function(pkg_use_module mod pkg) function(pkg_use_module mod pkgs)
if(PKG_CONFIG_FOUND) foreach(pkg IN ITEMS ${pkgs})
pkg_search_module(${mod} ${pkg}) if(PKG_CONFIG_FOUND)
endif() pkg_search_module(${mod} ${pkg})
if(${mod}_FOUND) endif()
link_directories(${${mod}_LIBRARY_DIRS}) if(NOT ${mod}_FOUND)
include_directories(${${mod}_INCLUDE_DIRS}) find_package(${pkg} QUIET)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) # This is very very ugly, but the variables are sometimes used in this scope
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_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)
foreach(dir ${${mod}_INCLUDE_DIRS}) if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE) foreach(dir ${${mod}_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
endforeach() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
endif() endforeach()
endif()
break()
endif()
endforeach()
endfunction() endfunction()
function(add_module lib) function(add_module lib)

33
conanfile.py Normal file
View File

@ -0,0 +1,33 @@
# pylint: disable=not-callable
from conans import CMake
from conans import ConanFile
class ToxConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "libsodium/1.0.18", "opus/1.3.1", "libvpx/1.8.0@bincrafters/stable"
generators = "cmake_find_package"
def requirements(self):
if self.settings.os == "Windows":
self.requires("pthreads4w/3.0.0")
def source(self):
self.run("git clone https://github.com/toktok/c-toxcore.git")
def build(self):
cmake = CMake(self)
cmake.definitions["AUTOTEST"] = True
cmake.definitions["BUILD_MISC_TESTS"] = True
cmake.definitions["MUST_BUILD_TOXAV"] = True
if self.settings.compiler == "Visual Studio":
cmake.definitions["MSVC_STATIC_SODIUM"] = True
if self.should_configure:
cmake.configure()
if self.should_build:
cmake.build()
if self.should_test:
cmake.test()