mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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:
parent
03a511482f
commit
56992b099e
|
@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 2.8.12)
|
|||
cmake_policy(VERSION 2.8.12)
|
||||
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(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)
|
||||
|
||||
if(MUST_BUILD_TOXAV)
|
||||
|
|
36
appveyor.yml
36
appveyor.yml
|
@ -1,35 +1,23 @@
|
|||
---
|
||||
cache:
|
||||
- '%APPDATA%\downloads'
|
||||
- '%USERPROFILE%\.conan'
|
||||
|
||||
install:
|
||||
# TODO(iphydf): Remove this when appveyor gets curl back, which it should
|
||||
# have according to https://www.appveyor.com/docs/how-to/download-file/.
|
||||
- choco install curl
|
||||
- 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 ../..
|
||||
- set PATH=C:\Python38-x64\Scripts;%PATH%
|
||||
- py -3 -m pip install conan
|
||||
- conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
|
||||
|
||||
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:
|
||||
project: _build/INSTALL.vcxproj
|
||||
build_script:
|
||||
- conan build .. --configure --build
|
||||
|
||||
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.
|
||||
- ctest -j50 --output-on-failure -C Debug &
|
||||
- set CONAN_CPU_COUNT=50
|
||||
- conan build .. --test &
|
||||
exit 0
|
||||
|
|
|
@ -16,8 +16,8 @@ find_library(SOCKET_LIBRARIES socket )
|
|||
pkg_use_module(LIBSODIUM libsodium )
|
||||
|
||||
# For toxav.
|
||||
pkg_use_module(OPUS opus )
|
||||
pkg_use_module(VPX vpx )
|
||||
pkg_use_module(OPUS "opus;Opus" )
|
||||
pkg_use_module(VPX "vpx;libvpx" )
|
||||
|
||||
# For tox-bootstrapd.
|
||||
pkg_use_module(LIBCONFIG libconfig )
|
||||
|
@ -38,18 +38,20 @@ pkg_use_module(MSGPACK msgpack )
|
|||
if(MSVC)
|
||||
# libsodium
|
||||
# ---------
|
||||
find_library(LIBSODIUM_LIBRARIES
|
||||
NAMES sodium libsodium
|
||||
PATHS
|
||||
"third_party/libsodium/Win32/Release/v140/dynamic"
|
||||
"third_party/libsodium/x64/Release/v140/dynamic"
|
||||
)
|
||||
if(LIBSODIUM_LIBRARIES)
|
||||
include_directories("third_party/libsodium/include")
|
||||
set(LIBSODIUM_FOUND TRUE)
|
||||
message("libsodium: ${LIBSODIUM_LIBRARIES}")
|
||||
else()
|
||||
message(FATAL_ERROR "libsodium libraries not found")
|
||||
if(NOT LIBSODIUM_FOUND)
|
||||
find_library(LIBSODIUM_LIBRARIES
|
||||
NAMES sodium libsodium
|
||||
PATHS
|
||||
"third_party/libsodium/Win32/Release/v140/dynamic"
|
||||
"third_party/libsodium/x64/Release/v140/dynamic"
|
||||
)
|
||||
if(LIBSODIUM_LIBRARIES)
|
||||
include_directories("third_party/libsodium/include")
|
||||
set(LIBSODIUM_FOUND TRUE)
|
||||
message("libsodium: ${LIBSODIUM_LIBRARIES}")
|
||||
else()
|
||||
message(FATAL_ERROR "libsodium libraries not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# pthreads
|
||||
|
@ -66,7 +68,12 @@ if(MSVC)
|
|||
add_definitions(-DHAVE_STRUCT_TIMESPEC)
|
||||
message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}")
|
||||
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()
|
||||
|
|
|
@ -21,21 +21,39 @@ endif()
|
|||
|
||||
find_package(PkgConfig)
|
||||
|
||||
function(pkg_use_module mod pkg)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_search_module(${mod} ${pkg})
|
||||
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)
|
||||
function(pkg_use_module mod pkgs)
|
||||
foreach(pkg IN ITEMS ${pkgs})
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_search_module(${mod} ${pkg})
|
||||
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)
|
||||
|
||||
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()
|
||||
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)
|
||||
|
|
33
conanfile.py
Normal file
33
conanfile.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user