Skip to content
Snippets Groups Projects
Unverified Commit 82a1d8bd authored by Joe Donofry's avatar Joe Donofry Committed by GitHub
Browse files

Merge pull request #23 from Nheko-Reborn/0.3.0-dev

Merge 0.3.0 dev branch to master
parents 7ee95265 7fc1d357
No related branches found
No related tags found
No related merge requests found
......@@ -7,8 +7,47 @@ if [[ ! -z $TRAVIS_OS_NAME ]]; then
fi
$CMD perl -pi -w -e \
's/rc_messages_per_second.*/rc_messages_per_second: 100/g;' data/homeserver.yaml
's/rc_messages_per_second.*/rc_messages_per_second: 1000/g;' data/homeserver.yaml
$CMD perl -pi -w -e \
's/rc_message_burst_count.*/rc_message_burst_count: 1000/g;' data/homeserver.yaml
's/rc_message_burst_count.*/rc_message_burst_count: 10000/g;' data/homeserver.yaml
(
cat <<HEREDOC
rc_message:
per_second: 1000
burst_count: 10000
rc_registration:
per_second: 1000
burst_count: 3000
rc_login:
address:
per_second: 1000
burst_count: 3000
account:
per_second: 1000
burst_count: 3000
failed_attempts:
per_second: 1000
burst_count: 3000
rc_admin_redaction:
per_second: 1000
burst_count: 5000
HEREDOC
) | $CMD tee -a data/homeserver.yaml
$CMD perl -pi -w -e \
's/enable_registration.*/enable_registration: True/g;' data/homeserver.yaml
's/#enable_registration: false/enable_registration: true/g;' data/homeserver.yaml
$CMD perl -pi -w -e \
's/tls: false/tls: true/g;' data/homeserver.yaml
$CMD perl -pi -w -e \
's/#tls_certificate_path:/tls_certificate_path:/g;' data/homeserver.yaml
$CMD perl -pi -w -e \
's/#tls_private_key_path:/tls_private_key_path:/g;' data/homeserver.yaml
$CMD openssl req -x509 -newkey rsa:4096 -keyout data/localhost.tls.key -out data/localhost.tls.crt -days 365 -subj '/CN=localhost' -nodes
$CMD chmod 0777 data/localhost.tls.crt
$CMD chmod 0777 data/localhost.tls.key
......@@ -10,6 +10,7 @@ lcov --directory . --capture --output-file coverage.info
# Filter out external code.
lcov --remove coverage.info \
'/usr/*' \
'*/.deps/*' \
'*tests*' \
--output-file coverage.info
......
......@@ -2,12 +2,20 @@
set -ex
if [ $TRAVIS_OS_NAME == osx ]; then
brew update || true
brew upgrade boost || true
brew install libsodium clang-format
brew tap nlohmann/json
# the nlohmann install seems to make travis angry
# because of the number of log messages
brew install --with-cmake nlohmann_json > /dev/null
CMAKE_VERSION=3.15.5
CMAKE_SHORT_VERSION=3.15
if [ $TRAVIS_OS_NAME == linux ]; then
# cmake
curl https://cmake.org/files/v${CMAKE_SHORT_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh -o cmake-install.sh
sudo bash cmake-install.sh --skip-license --prefix=/usr/local
export PATH="/usr/local/bin:$PATH"
mkdir -p build-lcov
( cd build-lcov
curl -L http://downloads.sourceforge.net/ltp/lcov-1.14.tar.gz -o lcov-1.14.tar.gz
tar xfz lcov-1.14.tar.gz
cd lcov-1.14/
sudo make install )
fi
......@@ -2,44 +2,48 @@
set -ex
mkdir -p .deps
if [ $TRAVIS_OS_NAME == linux ]; then
export CXX=${CXX_VERSION}
export CC=${CC_VERSION}
export PATH="/usr/local/bin:$PATH"
cmake --version
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/${CC_VERSION} 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/${CXX_VERSION} 10
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-8 10
sudo update-alternatives --set gcc "/usr/bin/${CC_VERSION}"
sudo update-alternatives --set g++ "/usr/bin/${CXX_VERSION}"
sudo update-alternatives --set gcov "/usr/bin/gcov-8"
# Build the library.
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug \
cmake -GNinja -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug \
-DBUILD_LIB_TESTS=ON \
-DBUILD_SHARED_LIBS=ON \
-DHUNTER_ENABLED=ON \
-DHUNTER_ROOT=.deps \
-DUSE_BUNDLED_OPENSSL=OFF \
-DCOVERAGE=${COVERAGE} || true
#-DHUNTER_CONFIGURATION_TYPES=Debug \ << needs gtest release for some reason
cmake --build build
# The tests will run anyway during coverage.
if [ $COVERAGE != ON ]; then
make test
fi
make test
fi
if [ $TRAVIS_OS_NAME == osx ]; then
brew update
brew upgrade cmake boost || true
# Build dependencies.
cmake -Hdeps -B.deps -DCMAKE_BUILD_TYPE=Release \
-DUSE_BUNDLED_BOOST=OFF \
-DUSE_BUNDLED_GTEST=OFF \
-DUSE_BUNDLED_JSON=OFF
cmake --build .deps
# Build the library.
cmake -H. -Bbuild -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release \
-DBUILD_LIB_TESTS=OFF \
-DBUILD_LIB_EXAMPLES=OFF \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=.deps/usr || true
-DHUNTER_ENABLED=ON \
-DHUNTER_CONFIGURATION_TYPES=Release \
-DHUNTER_ROOT=.deps \
-DUSE_BUNDLED_GTEST=OFF || true
cmake --build build
make lint
......
......@@ -28,11 +28,15 @@
*.app
# Build artifacts
build/
build*/
# Editor
tags
compile_commands.json
.exrc
.ccls-cache/
.clangd/
.*.swp
# Synapse data
data/
......
......@@ -2,7 +2,7 @@
language: cpp
sudo: required
dist: trusty
dist: xenial
services:
- docker
......@@ -10,30 +10,74 @@ services:
notifications:
email: false
matrix:
include:
- os: osx
osx_image: xcode9
osx_image: xcode11.3 # for c++17
compiler: clang
addons:
homebrew:
packages:
- clang-format
- ninja
- openssl
update: true
- os: linux
compiler: gcc
env:
- CXX_VERSION=g++-8
- CC_VERSION=gcc-8
- CMAKE_GENERATOR=Ninja
- COVERAGE=ON
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- software-properties-common
- curl
- ninja-build
- pkg-config
- make
- g++-8
- unzip
- git
- libssl-dev
- openssl
- os: linux
compiler: clang
env:
- CXX_VERSION=clang++-6.0
- CC_VERSION=clang-6.0
- COVERAGE=ON
- CMAKE_GENERATOR=Ninja
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-6.0
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages:
- clang++-6.0
- clang-6.0
- software-properties-common
- curl
- ninja-build
- pkg-config
- make
- g++-8
- unzip
- git
- libssl-dev
- openssl
install:
- |
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
docker build -t nheko-reborn/mtxclient -f Dockerfile .
fi
cache:
directories:
- .deps
- build/_deps
- ./.ci/install.sh
install: ./.ci/install.sh
script:
- $CXX --version
......@@ -42,30 +86,13 @@ script:
# Start the synapse server to run the tests.
- if [ $TRAVIS_OS_NAME == linux ]; then make synapse; fi
# Build the lib and run the test suite against synapse.
- |
if [ $TRAVIS_OS_NAME == linux ]; then
docker run -v `pwd`:/build --net=host \
-e CXX_VERSION=${CXX_VERSION} \
-e CC_VERSION=${CC_VERSION} \
-e COVERAGE=${COVERAGE} \
-e TRAVIS_OS_NAME=${TRAVIS_OS_NAME} \
nheko-reborn/mtxclient \
/bin/bash -c "./.ci/script.sh"
fi
# Build the lib and run the linter.
- |
if [ $TRAVIS_OS_NAME == osx ]; then
./.ci/script.sh
fi
# Build the lib and run the linter & tests.
- ./.ci/script.sh
after_success:
# Generate coverage report and upload report to CodeCov.
- |
if [ $COVERAGE == ON ]; then
docker run -v `pwd`:/build \
--net=host nheko-reborn/mtxclient \
/bin/bash -c "make -C build -j1 test_coverage && ./.ci/coverage.sh" && \
bash <(curl -s https://codecov.io/bash) -f "!*tests*" || echo "Codecov failed"
if [ "$COVERAGE" == ON ]; then
./.ci/coverage.sh && \
bash <(curl -s https://codecov.io/bash) -f build/coverage.info || echo "Codecov failed"
fi
This diff is collapsed.
FROM ubuntu:14.04
FROM ubuntu:16.04
ENV LIBSODIUM_VERSION=1.0.16
ENV SPDLOG_VERSION=1.1.0
ENV OLM_VERSION=2.2.2
ENV NLOHMANN_VERSION=v3.2.0
ENV CMAKE_VERSION=3.12.1
ENV CMAKE_SHORT_VERSION=3.12
ENV CMAKE_VERSION=3.15.5
ENV CMAKE_SHORT_VERSION=3.15
RUN \
apt-get update -qq && \
apt-get install -y --no-install-recommends apt-transport-https software-properties-common curl && \
apt-get install -y --no-install-recommends apt-transport-https software-properties-common curl ninja-build && \
# cmake
curl https://cmake.org/files/v${CMAKE_SHORT_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh -o cmake-install.sh && \
bash cmake-install.sh --skip-license --prefix=/usr/local && \
......@@ -18,7 +18,7 @@ RUN \
# Toolchains
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
apt-add-repository "deb https://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" && \
apt-add-repository "deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" && \
apt-get update -qq && \
apt-get install -y --no-install-recommends \
ninja-build \
......@@ -34,8 +34,10 @@ RUN \
openssl && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 10 && \
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 10 && \
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-8 10 && \
sudo update-alternatives --set gcc "/usr/bin/gcc-8" && \
sudo update-alternatives --set g++ "/usr/bin/g++-8" && \
sudo update-alternatives --set gcov "/usr/bin/gcov-8" && \
# libsodium
mkdir -p /build/libsodium && cd /build/libsodium && \
curl -L https://download.libsodium.org/libsodium/releases/libsodium-${LIBSODIUM_VERSION}.tar.gz -o libsodium-${LIBSODIUM_VERSION}.tar.gz && \
......@@ -52,10 +54,10 @@ RUN \
cmake --build build --target install && \
# boost
mkdir -p /build/boost && cd /build/boost && \
curl -L https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz -o boost_1_68_0.tar.gz && \
tar xfz boost_1_68_0.tar.gz && cd /build/boost/boost_1_68_0/ && \
curl -L https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz -o boost_1_70_0.tar.gz && \
tar xfz boost_1_70_0.tar.gz && cd /build/boost/boost_1_70_0/ && \
./bootstrap.sh --with-libraries=random,thread,system,iostreams,atomic,chrono,date_time,regex && \
./b2 -d0 cxxstd=14 variant=release link=static threading=multi --layout=system && \
./b2 -d0 cxxstd=17 variant=release link=static threading=multi --layout=system && \
./b2 -d0 install && \
# Gtest
mkdir -p /build/gtest && cd /build/gtest && \
......
FILES=`find lib include tests examples -type f -type f \( -iname "*.cpp" -o -iname "*.hpp" \)`
SYNAPSE_IMAGE="avhost/docker-matrix:v0.33.4"
SYNAPSE_IMAGE="matrixdotorg/synapse:v1.7.2"
DEPS_BUILD_DIR=.deps
DEPS_SOURCE_DIR=deps
......@@ -43,23 +43,25 @@ image:
docker build -t mtxclient-dev .
synapse: ## Start a synapse instance on docker
@mkdir -p data
@chmod 0777 data
@docker run -v `pwd`/data:/data --rm \
-e SERVER_NAME=localhost -e REPORT_STATS=no ${SYNAPSE_IMAGE} generate
-e SYNAPSE_SERVER_NAME=localhost -e SYNAPSE_REPORT_STATS=no ${SYNAPSE_IMAGE} generate
@./.ci/adjust-config.sh
@docker run -d \
--name synapse \
-p 443:8448 \
-p 8448:8448 \
-p 443:8008 \
-p 8448:8008 \
-p 8008:8008 \
-v `pwd`/data:/data ${SYNAPSE_IMAGE} start
-v `pwd`/data:/data ${SYNAPSE_IMAGE}
@echo Waiting for synapse to start...
@until curl -s -f -k https://localhost:443/_matrix/client/versions; do echo "Checking ..."; sleep 2; done
@echo Register alice
@docker exec synapse /bin/bash -c 'register_new_matrix_user --admin -u alice -p secret -c /data/homeserver.yaml http://localhost:8008'
@docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice -p secret -c /data/homeserver.yaml https://localhost:8008'
@echo Register bob
@docker exec synapse /bin/bash -c 'register_new_matrix_user --admin -u bob -p secret -c /data/homeserver.yaml http://localhost:8008'
@docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob -p secret -c /data/homeserver.yaml https://localhost:8008'
@echo Register carl
@docker exec synapse /bin/bash -c 'register_new_matrix_user --admin -u carl -p secret -c /data/homeserver.yaml http://localhost:8008'
@docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u carl -p secret -c /data/homeserver.yaml https://localhost:8008'
stop-synapse: ## Stop any running instance of synapse
@rm -rf ./data/*
......
......@@ -11,14 +11,25 @@ Client API library for the Matrix protocol, built on top of Boost.Asio.
### Dependencies
- Boost 1.66 (includes Boost.Beast)
- Boost 1.70 (includes Boost.Beast and makes the strand interface usable)
- OpenSSL
- C++ 14 compiler
- CMake 3.1 or greater
- C++ 17 compiler
- CMake 3.15 or greater (lower versions can work, but they tend to mess up linking the right boost libraries)
- Google Test (for testing)
- libsodium 1.0.14 or greater
Boost and GTest will be built automatically by CMake if they're not found on your system.
If you are missing some or all of those above dependencies, you can add `-DHUNTER_ENABLED=ON` to the cmake configure command to use bundled dependencies. You can finetune them with the following variables. They default to ON, if Hunter is enabled and to OFF otherwise.
| cmake flag | description |
|---------------------|-------------|
| USE_BUNDLED_BOOST | Use the bundled version of Boost. |
| USE_BUNDLED_SPDLOG | Use the bundled version of spdlog. |
| USE_BUNDLED_OLM | Use the bundled version of libolm. |
| USE_BUNDLED_GTEST | Use the bundled version of Google Test. |
| USE_BUNDLED_JSON | Use the bundled version of nlohmann json. |
| USE_BUNDLED_OPENSSL | Use the bundled version of OpenSSL. |
| USE_BUNDLED_SODIUM | Use the bundled version of libsodium. |
| USE_BUNDLED_ZLIB | Use the bundled version of zlib. |
Below is an example which will build the library along with the tests & examples.
......
---
version: 0.2.0-{build}
version: 0.3.0-{build}
configuration: Release
image: Visual Studio 2017
platform: x64
cache: c:\tools\vcpkg\installed\
cache:
- c:\hunter\ -> appveyor.yml
build:
verbosity: minimal
......@@ -16,36 +17,10 @@ install:
- set PATH=%PATH%;C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin
- mingw32-make.exe --version
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
- cd "C:\Tools\vcpkg"&& git pull && .\bootstrap-vcpkg.bat && cd %APPVEYOR_BUILD_FOLDER%
- vcpkg install
nlohmann-json:%PLATFORM%-windows
boost-asio:%PLATFORM%-windows
boost-beast:%PLATFORM%-windows
boost-iostreams:%PLATFORM%-windows
boost-random:%PLATFORM%-windows
boost-signals2:%PLATFORM%-windows
boost-system:%PLATFORM%-windows
boost-thread:%PLATFORM%-windows
libsodium:%PLATFORM%-windows
openssl:%PLATFORM%-windows
spdlog:%PLATFORM%-windows
zlib:%PLATFORM%-windows
build_script:
- cmake --version
- cmake -G "Visual Studio 15 2017 Win64" -Hdeps -B.deps
-DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake
-DCMAKE_BUILD_TYPE=Release
-DUSE_BUNDLED_BOOST=OFF
-DUSE_BUNDLED_SPDLOG=OFF
-DUSE_BUNDLED_GTEST=OFF
-DUSE_BUNDLED_JSON=OFF
- cmake --build .deps --config Release
- cmake -G "Visual Studio 15 2017 Win64" -H. -Bbuild
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake
-DBUILD_LIB_TESTS=OFF
-DBUILD_LIB_EXAMPLES=OFF
-DCMAKE_INSTALL_PREFIX=.deps/usr
- cmake -G "Visual Studio 15 2017 Win64" -H. -Bbuild -DHUNTER_ENABLED=ON -DHUNTER_ROOT="C:\hunter"
-DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release -DUSE_BUNDLED_GTEST=OFF -DBUILD_LIB_TESTS=OFF -DBUILD_LIB_EXAMPLES=OFF
- cmake --build build --config Release
#
# CMake module to search for the olm library
#
# On success, the macro sets the following variables:
# OLM_FOUND = if the library found
# OLM_LIBRARY = full path to the library
# OLM_INCLUDE_DIR = where to find the library headers
#
find_path(OLM_INCLUDE_DIR
NAMES olm/olm.h
PATHS /usr/include
/usr/local/include
$ENV{LIB_DIR}/include
$ENV{LIB_DIR}/include/olm)
find_library(OLM_LIBRARY
NAMES olm
PATHS /usr/lib /usr/local/lib $ENV{LIB_DIR}/lib)
if(OLM_FOUND)
set(OLM_INCLUDE_DIRS ${OLM_INCLUDE_DIR})
if(NOT OLM_LIBRARIES)
set(OLM_LIBRARIES ${OLM_LIBRARY})
endif()
endif()
if(NOT TARGET Olm::Olm)
add_library(Olm::Olm UNKNOWN IMPORTED)
set_target_properties(Olm::Olm
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${OLM_INCLUDE_DIR})
set_property(TARGET Olm::Olm APPEND PROPERTY IMPORTED_LOCATION ${OLM_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OLM DEFAULT_MSG OLM_INCLUDE_DIR OLM_LIBRARY)
mark_as_advanced(OLM_LIBRARY OLM_INCLUDE_DIR)
......@@ -17,13 +17,13 @@
#
# Once done the following variables will be defined:
#
# sodium_FOUND
# sodium_INCLUDE_DIR
# sodium_LIBRARY_DEBUG
# sodium_LIBRARY_RELEASE
# libsodium_FOUND
# libsodium_INCLUDE_DIR
# libsodium_LIBRARY_DEBUG
# libsodium_LIBRARY_RELEASE
#
#
# Furthermore an imported "sodium" target is created.
# Furthermore an imported "libsodium" target is created.
#
if (CMAKE_C_COMPILER_ID STREQUAL "GNU"
......@@ -32,16 +32,16 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU"
endif()
# static library option
if (NOT DEFINED sodium_USE_STATIC_LIBS)
option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF)
if (NOT DEFINED libsodium_USE_STATIC_LIBS)
option(libsodium_USE_STATIC_LIBS "enable to statically link against libsodium" OFF)
endif()
if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST))
unset(sodium_LIBRARY CACHE)
unset(sodium_LIBRARY_DEBUG CACHE)
unset(sodium_LIBRARY_RELEASE CACHE)
unset(sodium_DLL_DEBUG CACHE)
unset(sodium_DLL_RELEASE CACHE)
set(sodium_USE_STATIC_LIBS_LAST ${sodium_USE_STATIC_LIBS} CACHE INTERNAL "internal change tracking variable")
if(NOT (libsodium_USE_STATIC_LIBS EQUAL libsodium_USE_STATIC_LIBS_LAST))
unset(libsodium_LIBRARY CACHE)
unset(libsodium_LIBRARY_DEBUG CACHE)
unset(libsodium_LIBRARY_RELEASE CACHE)
unset(libsodium_DLL_DEBUG CACHE)
unset(libsodium_DLL_RELEASE CACHE)
set(libsodium_USE_STATIC_LIBS_LAST ${libsodium_USE_STATIC_LIBS} CACHE INTERNAL "internal change tracking variable")
endif()
......@@ -51,39 +51,39 @@ if (UNIX)
# import pkg-config
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(sodium_PKG QUIET libsodium)
pkg_check_modules(libsodium_PKG QUIET libsodium)
endif()
if(sodium_USE_STATIC_LIBS)
foreach(_libname ${sodium_PKG_STATIC_LIBRARIES})
if(libsodium_USE_STATIC_LIBS)
foreach(_libname ${libsodium_PKG_STATIC_LIBRARIES})
if (NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending with .a
list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a")
list(INSERT libsodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a")
endif()
endforeach()
list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES)
list(REMOVE_DUPLICATES libsodium_PKG_STATIC_LIBRARIES)
# if pkgconfig for libsodium doesn't provide
# static lib info, then override PKG_STATIC here..
if (sodium_PKG_STATIC_LIBRARIES STREQUAL "")
set(sodium_PKG_STATIC_LIBRARIES libsodium.a)
if (libsodium_PKG_STATIC_LIBRARIES STREQUAL "")
set(libsodium_PKG_STATIC_LIBRARIES libsodium.a)
endif()
set(XPREFIX sodium_PKG_STATIC)
set(XPREFIX libsodium_PKG_STATIC)
else()
if (sodium_PKG_LIBRARIES STREQUAL "")
set(sodium_PKG_LIBRARIES sodium)
if (libsodium_PKG_LIBRARIES STREQUAL "")
set(libsodium_PKG_LIBRARIES sodium)
endif()
set(XPREFIX sodium_PKG)
set(XPREFIX libsodium_PKG)
endif()
find_path(sodium_INCLUDE_DIR sodium.h
find_path(libsodium_INCLUDE_DIR sodium.h
HINTS ${${XPREFIX}_INCLUDE_DIRS}
)
find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES}
find_library(libsodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES}
find_library(libsodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES}
HINTS ${${XPREFIX}_LIBRARY_DIRS}
)
......@@ -91,11 +91,11 @@ if (UNIX)
########################################################################
# Windows
elseif (WIN32)
set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory")
mark_as_advanced(sodium_DIR)
set(libsodium_DIR "$ENV{libsodium_DIR}" CACHE FILEPATH "libsodium install directory")
mark_as_advanced(libsodium_DIR)
find_path(sodium_INCLUDE_DIR sodium.h
HINTS ${sodium_DIR}
find_path(libsodium_INCLUDE_DIR sodium.h
HINTS ${libsodium_DIR}
PATH_SUFFIXES include
)
......@@ -131,7 +131,7 @@ elseif (WIN32)
endif()
string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}")
if (sodium_USE_STATIC_LIBS)
if (libsodium_USE_STATIC_LIBS)
string(APPEND _PLATFORM_PATH "/static")
else()
string(APPEND _PLATFORM_PATH "/dynamic")
......@@ -140,59 +140,59 @@ elseif (WIN32)
string(REPLACE "$$CONFIG$$" "Debug" _DEBUG_PATH_SUFFIX "${_PLATFORM_PATH}")
string(REPLACE "$$CONFIG$$" "Release" _RELEASE_PATH_SUFFIX "${_PLATFORM_PATH}")
find_library(sodium_LIBRARY_DEBUG libsodium.lib
HINTS ${sodium_DIR}
find_library(libsodium_LIBRARY_DEBUG libsodium.lib
HINTS ${libsodium_DIR}
PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX}
)
find_library(sodium_LIBRARY_RELEASE libsodium.lib
HINTS ${sodium_DIR}
find_library(libsodium_LIBRARY_RELEASE libsodium.lib
HINTS ${libsodium_DIR}
PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX}
)
if (NOT sodium_USE_STATIC_LIBS)
if (NOT libsodium_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
find_library(sodium_DLL_DEBUG libsodium
HINTS ${sodium_DIR}
find_library(libsodium_DLL_DEBUG libsodium
HINTS ${libsodium_DIR}
PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX}
)
find_library(sodium_DLL_RELEASE libsodium
HINTS ${sodium_DIR}
find_library(libsodium_DLL_RELEASE libsodium
HINTS ${libsodium_DIR}
PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX}
)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK})
endif()
elseif(_GCC_COMPATIBLE)
if (sodium_USE_STATIC_LIBS)
find_library(sodium_LIBRARY_DEBUG libsodium.a
HINTS ${sodium_DIR}
if (libsodium_USE_STATIC_LIBS)
find_library(libsodium_LIBRARY_DEBUG libsodium.a
HINTS ${libsodium_DIR}
PATH_SUFFIXES lib
)
find_library(sodium_LIBRARY_RELEASE libsodium.a
HINTS ${sodium_DIR}
find_library(libsodium_LIBRARY_RELEASE libsodium.a
HINTS ${libsodium_DIR}
PATH_SUFFIXES lib
)
else()
find_library(sodium_LIBRARY_DEBUG libsodium.dll.a
HINTS ${sodium_DIR}
find_library(libsodium_LIBRARY_DEBUG libsodium.dll.a
HINTS ${libsodium_DIR}
PATH_SUFFIXES lib
)
find_library(sodium_LIBRARY_RELEASE libsodium.dll.a
HINTS ${sodium_DIR}
find_library(libsodium_LIBRARY_RELEASE libsodium.dll.a
HINTS ${libsodium_DIR}
PATH_SUFFIXES lib
)
file(GLOB _DLL
LIST_DIRECTORIES false
RELATIVE "${sodium_DIR}/bin"
"${sodium_DIR}/bin/libsodium*.dll"
RELATIVE "${libsodium_DIR}/bin"
"${libsodium_DIR}/bin/libsodium*.dll"
)
find_library(sodium_DLL_DEBUG ${_DLL} libsodium
HINTS ${sodium_DIR}
find_library(libsodium_DLL_DEBUG ${_DLL} libsodium
HINTS ${libsodium_DIR}
PATH_SUFFIXES bin
)
find_library(sodium_DLL_RELEASE ${_DLL} libsodium
HINTS ${sodium_DIR}
find_library(libsodium_DLL_RELEASE ${_DLL} libsodium
HINTS ${libsodium_DIR}
PATH_SUFFIXES bin
)
endif()
......@@ -211,14 +211,14 @@ endif()
########################################################################
# common stuff
# extract sodium version
if (sodium_INCLUDE_DIR)
set(_VERSION_HEADER "${sodium_INCLUDE_DIR}/sodium/version.h")
# extract libsodium version
if (libsodium_INCLUDE_DIR)
set(_VERSION_HEADER "${libsodium_INCLUDE_DIR}/sodium/version.h")
if (EXISTS "${_VERSION_HEADER}")
file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT)
string(REGEX REPLACE ".*#[ \t]*define[ \t]*SODIUM_VERSION_STRING[ \t]*\"([^\n]*)\".*" "\\1"
sodium_VERSION "${_VERSION_HEADER_CONTENT}")
set(sodium_VERSION "${sodium_VERSION}")
libsodium_VERSION "${_VERSION_HEADER_CONTENT}")
set(libsodium_VERSION "${libsodium_VERSION}")
endif()
endif()
......@@ -226,62 +226,63 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(sodium
REQUIRED_VARS
sodium_LIBRARY_RELEASE
sodium_LIBRARY_DEBUG
sodium_INCLUDE_DIR
libsodium_LIBRARY_RELEASE
libsodium_LIBRARY_DEBUG
libsodium_INCLUDE_DIR
VERSION_VAR
sodium_VERSION
libsodium_VERSION
)
# mark file paths as advanced
mark_as_advanced(sodium_INCLUDE_DIR)
mark_as_advanced(sodium_LIBRARY_DEBUG)
mark_as_advanced(sodium_LIBRARY_RELEASE)
mark_as_advanced(libsodium_INCLUDE_DIR)
mark_as_advanced(libsodium_LIBRARY_DEBUG)
mark_as_advanced(libsodium_LIBRARY_RELEASE)
if (WIN32)
mark_as_advanced(sodium_DLL_DEBUG)
mark_as_advanced(sodium_DLL_RELEASE)
mark_as_advanced(libsodium_DLL_DEBUG)
mark_as_advanced(libsodium_DLL_RELEASE)
endif()
# create imported target
if(sodium_USE_STATIC_LIBS)
if(libsodium_USE_STATIC_LIBS)
set(_LIB_TYPE STATIC)
else()
set(_LIB_TYPE SHARED)
endif()
add_library(sodium ${_LIB_TYPE} IMPORTED)
add_library(libsodium ${_LIB_TYPE} IMPORTED GLOBAL)
set_target_properties(sodium PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${sodium_INCLUDE_DIR}"
set_target_properties(libsodium PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${libsodium_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
)
add_library(libsodium::libsodium ALIAS libsodium)
if (sodium_USE_STATIC_LIBS)
set_target_properties(sodium PROPERTIES
if (libsodium_USE_STATIC_LIBS)
set_target_properties(libsodium PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "SODIUM_STATIC"
IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}"
IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}"
IMPORTED_LOCATION "${libsodium_LIBRARY_RELEASE}"
IMPORTED_LOCATION_DEBUG "${libsodium_LIBRARY_DEBUG}"
)
else()
if (UNIX)
set_target_properties(sodium PROPERTIES
IMPORTED_LOCATION "${sodium_LIBRARY_RELEASE}"
IMPORTED_LOCATION_DEBUG "${sodium_LIBRARY_DEBUG}"
set_target_properties(libsodium PROPERTIES
IMPORTED_LOCATION "${libsodium_LIBRARY_RELEASE}"
IMPORTED_LOCATION_DEBUG "${libsodium_LIBRARY_DEBUG}"
)
elseif (WIN32)
set_target_properties(sodium PROPERTIES
IMPORTED_IMPLIB "${sodium_LIBRARY_RELEASE}"
IMPORTED_IMPLIB_DEBUG "${sodium_LIBRARY_DEBUG}"
set_target_properties(libsodium PROPERTIES
IMPORTED_IMPLIB "${libsodium_LIBRARY_RELEASE}"
IMPORTED_IMPLIB_DEBUG "${libsodium_LIBRARY_DEBUG}"
)
if (NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND"))
set_target_properties(sodium PROPERTIES
IMPORTED_LOCATION_DEBUG "${sodium_DLL_DEBUG}"
if (NOT (libsodium_DLL_DEBUG MATCHES ".*-NOTFOUND"))
set_target_properties(libsodium PROPERTIES
IMPORTED_LOCATION_DEBUG "${libsodium_DLL_DEBUG}"
)
endif()
if (NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND"))
set_target_properties(sodium PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${sodium_DLL_RELEASE}"
IMPORTED_LOCATION_MINSIZEREL "${sodium_DLL_RELEASE}"
IMPORTED_LOCATION_RELEASE "${sodium_DLL_RELEASE}"
if (NOT (libsodium_DLL_RELEASE MATCHES ".*-NOTFOUND"))
set_target_properties(libsodium PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${libsodium_DLL_RELEASE}"
IMPORTED_LOCATION_MINSIZEREL "${libsodium_DLL_RELEASE}"
IMPORTED_LOCATION_RELEASE "${libsodium_DLL_RELEASE}"
)
endif()
endif()
......
hunter_config(
Boost
VERSION "1.70.0-p0"
CMAKE_ARGS IOSTREAMS_NO_BZIP2=1
)
# Copyright (c) 2013-2019, Ruslan Baratov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This is a gate file to Hunter package manager.
# Include this file using `include` command and add package you need, example:
#
# cmake_minimum_required(VERSION 3.2)
#
# include("cmake/HunterGate.cmake")
# HunterGate(
# URL "https://github.com/path/to/hunter/archive.tar.gz"
# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d"
# )
#
# project(MyProject)
#
# hunter_add_package(Foo)
# hunter_add_package(Boo COMPONENTS Bar Baz)
#
# Projects:
# * https://github.com/hunter-packages/gate/
# * https://github.com/ruslo/hunter
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.2")
message(
FATAL_ERROR
"At least CMake version 3.2 required for Hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF."
)
endif()
endif()
include(CMakeParseArguments) # cmake_parse_arguments
option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors")
function(hunter_gate_status_print)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
message(STATUS "[hunter] ${print_message}")
endforeach()
endif()
endfunction()
function(hunter_gate_status_debug)
if(HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
string(TIMESTAMP timestamp)
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
endforeach()
endif()
endfunction()
function(hunter_gate_error_page error_page)
message("------------------------------ ERROR ------------------------------")
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
message("-------------------------------------------------------------------")
message("")
message(FATAL_ERROR "")
endfunction()
function(hunter_gate_internal_error)
message("")
foreach(print_message ${ARGV})
message("[hunter ** INTERNAL **] ${print_message}")
endforeach()
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_error_page("error.internal")
endfunction()
function(hunter_gate_fatal_error)
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
if("${hunter_ERROR_PAGE}" STREQUAL "")
hunter_gate_internal_error("Expected ERROR_PAGE")
endif()
message("")
foreach(x ${hunter_UNPARSED_ARGUMENTS})
message("[hunter ** FATAL ERROR **] ${x}")
endforeach()
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_error_page("${hunter_ERROR_PAGE}")
endfunction()
function(hunter_gate_user_error)
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
endfunction()
function(hunter_gate_self root version sha1 result)
string(COMPARE EQUAL "${root}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("root is empty")
endif()
string(COMPARE EQUAL "${version}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("version is empty")
endif()
string(COMPARE EQUAL "${sha1}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("sha1 is empty")
endif()
string(SUBSTRING "${sha1}" 0 7 archive_id)
set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
set("${result}" "${hunter_self}" PARENT_SCOPE)
endfunction()
# Set HUNTER_GATE_ROOT cmake variable to suitable value.
function(hunter_gate_detect_root)
# Check CMake variable
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty)
if(not_empty)
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
return()
endif()
# Check environment variable
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty)
if(not_empty)
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
return()
endif()
# Check HOME environment variable
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
return()
endif()
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
if(WIN32)
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using SYSTEMDRIVE environment variable"
)
return()
endif()
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using USERPROFILE environment variable"
)
return()
endif()
endif()
hunter_gate_fatal_error(
"Can't detect HUNTER_ROOT"
ERROR_PAGE "error.detect.hunter.root"
)
endfunction()
function(hunter_gate_download dir)
string(
COMPARE
NOTEQUAL
"$ENV{HUNTER_DISABLE_AUTOINSTALL}"
""
disable_autoinstall
)
if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL)
hunter_gate_fatal_error(
"Hunter not found in '${dir}'"
"Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'"
"Settings:"
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
ERROR_PAGE "error.run.install"
)
endif()
string(COMPARE EQUAL "${dir}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("Empty 'dir' argument")
endif()
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("HUNTER_GATE_SHA1 empty")
endif()
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("HUNTER_GATE_URL empty")
endif()
set(done_location "${dir}/DONE")
set(sha1_location "${dir}/SHA1")
set(build_dir "${dir}/Build")
set(cmakelists "${dir}/CMakeLists.txt")
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")
if(EXISTS "${done_location}")
# while waiting for lock other instance can do all the job
hunter_gate_status_debug("File '${done_location}' found, skip install")
return()
endif()
file(REMOVE_RECURSE "${build_dir}")
file(REMOVE_RECURSE "${cmakelists}")
file(MAKE_DIRECTORY "${build_dir}") # check directory permissions
# Disabling languages speeds up a little bit, reduces noise in the output
# and avoids path too long windows error
file(
WRITE
"${cmakelists}"
"cmake_minimum_required(VERSION 3.2)\n"
"project(HunterDownload LANGUAGES NONE)\n"
"include(ExternalProject)\n"
"ExternalProject_Add(\n"
" Hunter\n"
" URL\n"
" \"${HUNTER_GATE_URL}\"\n"
" URL_HASH\n"
" SHA1=${HUNTER_GATE_SHA1}\n"
" DOWNLOAD_DIR\n"
" \"${dir}\"\n"
" TLS_VERIFY\n"
" ${HUNTER_TLS_VERIFY}\n"
" SOURCE_DIR\n"
" \"${dir}/Unpacked\"\n"
" CONFIGURE_COMMAND\n"
" \"\"\n"
" BUILD_COMMAND\n"
" \"\"\n"
" INSTALL_COMMAND\n"
" \"\"\n"
")\n"
)
if(HUNTER_STATUS_DEBUG)
set(logging_params "")
else()
set(logging_params OUTPUT_QUIET)
endif()
hunter_gate_status_debug("Run generate")
# Need to add toolchain file too.
# Otherwise on Visual Studio + MDD this will fail with error:
# "Could not find an appropriate version of the Windows 10 SDK installed on this machine"
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}")
else()
# 'toolchain_arg' can't be empty
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=")
endif()
string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make)
if(no_make)
set(make_arg "")
else()
# Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM
set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
endif()
execute_process(
COMMAND
"${CMAKE_COMMAND}"
"-H${dir}"
"-B${build_dir}"
"-G${CMAKE_GENERATOR}"
"${toolchain_arg}"
${make_arg}
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE download_result
${logging_params}
)
if(NOT download_result EQUAL 0)
hunter_gate_internal_error(
"Configure project failed."
"To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}"
"In directory ${dir}"
)
endif()
hunter_gate_status_print(
"Initializing Hunter workspace (${HUNTER_GATE_SHA1})"
" ${HUNTER_GATE_URL}"
" -> ${dir}"
)
execute_process(
COMMAND "${CMAKE_COMMAND}" --build "${build_dir}"
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE download_result
${logging_params}
)
if(NOT download_result EQUAL 0)
hunter_gate_internal_error("Build project failed")
endif()
file(REMOVE_RECURSE "${build_dir}")
file(REMOVE_RECURSE "${cmakelists}")
file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}")
file(WRITE "${done_location}" "DONE")
hunter_gate_status_debug("Finished")
endfunction()
# Must be a macro so master file 'cmake/Hunter' can
# apply all variables easily just by 'include' command
# (otherwise PARENT_SCOPE magic needed)
macro(HunterGate)
if(HUNTER_GATE_DONE)
# variable HUNTER_GATE_DONE set explicitly for external project
# (see `hunter_download`)
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
endif()
# First HunterGate command will init Hunter, others will be ignored
get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET)
if(NOT HUNTER_ENABLED)
# Empty function to avoid error "unknown function"
function(hunter_add_package)
endfunction()
set(
_hunter_gate_disabled_mode_dir
"${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode"
)
if(EXISTS "${_hunter_gate_disabled_mode_dir}")
hunter_gate_status_debug(
"Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}"
)
list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}")
endif()
elseif(_hunter_gate_done)
hunter_gate_status_debug("Secondary HunterGate (use old settings)")
hunter_gate_self(
"${HUNTER_CACHED_ROOT}"
"${HUNTER_VERSION}"
"${HUNTER_SHA1}"
_hunter_self
)
include("${_hunter_self}/cmake/Hunter")
else()
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}")
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
if(_have_project_name)
hunter_gate_fatal_error(
"Please set HunterGate *before* 'project' command. "
"Detected project: ${PROJECT_NAME}"
ERROR_PAGE "error.huntergate.before.project"
)
endif()
cmake_parse_arguments(
HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV}
)
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1)
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url)
string(
COMPARE
NOTEQUAL
"${HUNTER_GATE_UNPARSED_ARGUMENTS}"
""
_have_unparsed
)
string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global)
string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath)
if(_have_unparsed)
hunter_gate_user_error(
"HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}"
)
endif()
if(_empty_sha1)
hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory")
endif()
if(_empty_url)
hunter_gate_user_error("URL suboption of HunterGate is mandatory")
endif()
if(_have_global)
if(HUNTER_GATE_LOCAL)
hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)")
endif()
if(_have_filepath)
hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)")
endif()
endif()
if(HUNTER_GATE_LOCAL)
if(_have_global)
hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)")
endif()
if(_have_filepath)
hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)")
endif()
endif()
if(_have_filepath)
if(_have_global)
hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)")
endif()
if(HUNTER_GATE_LOCAL)
hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)")
endif()
endif()
hunter_gate_detect_root() # set HUNTER_GATE_ROOT
# Beautify path, fix probable problems with windows path slashes
get_filename_component(
HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE
)
hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}")
if(NOT HUNTER_ALLOW_SPACES_IN_PATH)
string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces)
if(NOT _contain_spaces EQUAL -1)
hunter_gate_fatal_error(
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
"(Use at your own risk!)"
ERROR_PAGE "error.spaces.in.hunter.root"
)
endif()
endif()
string(
REGEX
MATCH
"[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*"
HUNTER_GATE_VERSION
"${HUNTER_GATE_URL}"
)
string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty)
if(_is_empty)
set(HUNTER_GATE_VERSION "unknown")
endif()
hunter_gate_self(
"${HUNTER_GATE_ROOT}"
"${HUNTER_GATE_VERSION}"
"${HUNTER_GATE_SHA1}"
_hunter_self
)
set(_master_location "${_hunter_self}/cmake/Hunter")
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")
# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()
if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()
if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
if(NOT _is_equal)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
endif()
include("${_master_location}")
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
endif()
endmacro()
cmake_minimum_required(VERSION 3.11)
project(MTXCLIENT_DEPS)
# Point CMake at any custom modules we may ship
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr"
CACHE PATH "Dependencies install directory.")
set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin"
CACHE PATH "Dependencies binary install directory.")
set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib"
CACHE PATH "Dependencies library install directory.")
set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build"
CACHE PATH "Dependencies build directory.")
set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads"
CACHE PATH "Dependencies download directory.")
option(USE_BUNDLED "Use bundled dependencies." ON)
option(USE_BUNDLED_BOOST "Use the bundled version of Boost." ${USE_BUNDLED})
option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${USE_BUNDLED})
option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${USE_BUNDLED})
option(USE_BUNDLED_GTEST "Use the bundled version of Google Test."
${USE_BUNDLED})
option(USE_BUNDLED_JSON "Use the bundled version of nlohmann json." ${USE_BUNDLED})
option(USE_EXISTING_SRC_DIR
"Skip download of deps sources in case of existing source directory."
OFF)
include(ExternalProject)
if(USE_BUNDLED_BOOST)
# bundled boost is 1.68, which requires CMake 3.12 or greater.
cmake_minimum_required(VERSION 3.12)
endif()
set(BOOST_URL
https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2)
set(BOOST_SHA256
8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406)
set(GTEST_URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz)
set(GTEST_SHA1 e7e646a6204638fe8e87e165292b8dd9cd4c36ed)
set(OLM_URL https://git.matrix.org/git/olm.git)
set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae)
set(SPDLOG_URL https://github.com/gabime/spdlog/archive/v1.1.0.tar.gz)
set(SPDLOG_HASH
3dbcbfd8c07e25f5e0d662b194d3a7772ef214358c49ada23c044c4747ce8b19)
set(JSON_URL
https://github.com/nlohmann/json.git)
set(JSON_TAG
v3.2.0)
if(USE_BUNDLED_JSON)
include(Json)
endif()
if(USE_BUNDLED_BOOST)
include(Boost)
endif()
if(USE_BUNDLED_SPDLOG)
include(SpdLog)
endif()
if(USE_BUNDLED_OLM)
include(Olm)
endif()
if(USE_BUNDLED_GTEST)
include(GoogleTest)
endif()
if(WIN32)
if("${TARGET_ARCH}" STREQUAL "X86_64")
set(TARGET_ARCH x64)
elseif(TARGET_ARCH STREQUAL "X86")
set(TARGET_ARCH ia32)
endif()
endif()
add_custom_target(third-party ALL
COMMAND ${CMAKE_COMMAND} -E touch .third-party
DEPENDS ${THIRD_PARTY_DEPS})
if(WIN32)
message(STATUS "Building Boost in Windows is not supported (skipping)")
return()
endif()
ExternalProject_Add(
Boost
URL ${BOOST_URL}
URL_HASH SHA256=${BOOST_SHA256}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/boost
DOWNLOAD_NO_PROGRESS 0
BUILD_IN_SOURCE 1
SOURCE_DIR ${DEPS_BUILD_DIR}/boost
CONFIGURE_COMMAND ${DEPS_BUILD_DIR}/boost/bootstrap.sh
--with-libraries=random,thread,system,iostreams,atomic,chrono,date_time,regex
--prefix=${DEPS_INSTALL_DIR}
BUILD_COMMAND ${DEPS_BUILD_DIR}/boost/b2 -d0 cxxstd=14 variant=release link=shared runtime-link=shared threading=multi --layout=system
INSTALL_COMMAND ${DEPS_BUILD_DIR}/boost/b2 -d0 install
)
list(APPEND THIRD_PARTY_DEPS Boost)
if(WIN32)
message(STATUS "Building gtest in Windows is not supported (skipping)")
return()
endif()
ExternalProject_Add(
GTest
URL ${GTEST_URL}
URL_HASH SHA1=${GTEST_SHA1}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/gtest
DOWNLOAD_NO_PROGRESS 0
BUILD_IN_SOURCE 1
SOURCE_DIR ${DEPS_BUILD_DIR}/gtest
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=Release
${DEPS_BUILD_DIR}/gtest
BUILD_COMMAND ${CMAKE_COMMAND}
--build ${DEPS_BUILD_DIR}/gtest
--config Release)
list(APPEND THIRD_PARTY_DEPS GTest)
ExternalProject_Add(
Json
GIT_REPOSITORY ${JSON_URL}
GIT_TAG ${JSON_TAG}
BUILD_IN_SOURCE 1
SOURCE_DIR ${DEPS_BUILD_DIR}/json
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DJSON_BuildTests=OFF
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
BUILD_COMMAND ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR}/json
INSTALL_COMMAND make install
)
list(APPEND THIRD_PARTY_DEPS Json)
set(WINDOWS_FLAGS "")
if(MSVC)
set(WINDOWS_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64")
endif()
ExternalProject_Add(
Olm
GIT_REPOSITORY ${OLM_URL}
GIT_TAG ${OLM_TAG}
BUILD_IN_SOURCE 1
SOURCE_DIR ${DEPS_BUILD_DIR}/olm
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/cmake/OlmCMakeLists.txt
${DEPS_BUILD_DIR}/olm/CMakeLists.txt
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/cmake/OlmConfig.cmake.in
${DEPS_BUILD_DIR}/olm/cmake/OlmConfig.cmake.in
COMMAND ${CMAKE_COMMAND}
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=Release
${DEPS_BUILD_DIR}/olm
${WINDOWS_FLAGS}
BUILD_COMMAND ${CMAKE_COMMAND}
--build ${DEPS_BUILD_DIR}/olm
--config Release
INSTALL_COMMAND ${CMAKE_COMMAND}
--build ${DEPS_BUILD_DIR}/olm
--config Release
--target install)
list(APPEND THIRD_PARTY_DEPS Olm)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment