From 0a9d95dfc9ef2c7e822257cc7b256cdd24d4a0d3 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 4 Jun 2018 13:54:51 +0300 Subject: [PATCH] Include mtxclient in the build --- .gitignore | 1 + CMakeLists.txt | 31 ++++++------- Makefile | 16 ++++++- appveyor.yml | 25 ++++++++++- cmake/MatrixStructs.cmake | 33 -------------- deps/CMakeLists.txt | 82 ++++++++++++++++++++++++++++++++++ deps/cmake/Boost.cmake | 23 ++++++++++ deps/cmake/MatrixClient.cmake | 30 +++++++++++++ deps/cmake/MatrixStructs.cmake | 25 +++++++++++ deps/cmake/Olm.cmake | 24 ++++++++++ deps/cmake/SpdLog.cmake | 15 +++++++ src/MatrixClient.cc | 3 ++ 12 files changed, 257 insertions(+), 51 deletions(-) delete mode 100644 cmake/MatrixStructs.cmake create mode 100644 deps/CMakeLists.txt create mode 100644 deps/cmake/Boost.cmake create mode 100644 deps/cmake/MatrixClient.cmake create mode 100644 deps/cmake/MatrixStructs.cmake create mode 100644 deps/cmake/Olm.cmake create mode 100644 deps/cmake/SpdLog.cmake diff --git a/.gitignore b/.gitignore index cb860801..88f85bbb 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ package.dir # Dependencies .third-party +.deps diff --git a/CMakeLists.txt b/CMakeLists.txt index fffe0f7d..0fcd9f2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,16 @@ set(IDENTIFIER "com.github.mujx.nheko") add_project_meta(META_FILES_TO_INCLUDE) +set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" + CACHE PATH "Path prefix for finding dependencies") +list(INSERT CMAKE_PREFIX_PATH 0 ${DEPS_PREFIX}) + +include_directories(SYSTEM ${DEPS_PREFIX}/include) + +if(APPLE) + set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) +endif() + # # LMDB # @@ -177,20 +187,10 @@ set(SRC_FILES # ExternalProject dependencies set(EXTERNAL_PROJECT_DEPS "") -# -# matrix-structs -# -find_library(MATRIX_STRUCTS_LIBRARY - NAMES matrix_structs - PATHS ${MATRIX_STRUCTS_ROOT} - ${MATRIX_STRUCTS_ROOT}/lib - ${MATRIX_STRUCTS_ROOT}/lib/static) - -if(NOT MATRIX_STRUCTS_LIBRARY) - include(MatrixStructs) - set(EXTERNAL_PROJECT_DEPS ${EXTERNAL_PROJECT_DEPS} MatrixStructs) -endif() -include_directories(SYSTEM ${MATRIX_STRUCTS_INCLUDE_DIR}) +find_package(MatrixStructs REQUIRED) +find_package(MatrixClient REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(ZLIB REQUIRED) # # tweeny @@ -293,7 +293,8 @@ include(Translations) set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC}) set(COMMON_LIBS - ${MATRIX_STRUCTS_LIBRARY} + MatrixStructs::MatrixStructs + MatrixClient::MatrixClient Qt5::Widgets Qt5::Network Qt5::Svg diff --git a/Makefile b/Makefile index 4d46e935..833d81a0 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,23 @@ +DEPS_BUILD_DIR=.deps +DEPS_SOURCE_DIR=deps debug: @cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 @cmake --build build +third_party: + @mkdir -p ${DEPS_BUILD_DIR}/usr/{lib,include}/ + @cmake -GNinja -H${DEPS_SOURCE_DIR} -B${DEPS_BUILD_DIR} \ + -DCMAKE_BUILD_TYPE=Release \ + -DUSE_BUNDLED_BOOST=OFF + @cmake --build ${DEPS_BUILD_DIR} + ci: - @cmake -H. -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo - @cmake --build build + mkdir -p ${DEPS_BUILD_DIR}/usr/{lib,include}/ + cmake -H${DEPS_SOURCE_DIR} -B${DEPS_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release + cmake --build ${DEPS_BUILD_DIR} + cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo + cmake --build build release: @cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo diff --git a/appveyor.yml b/appveyor.yml index adbad603..0cd819ab 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,19 @@ install: - set QT_DIR=C:\Qt\5.10.1\msvc2017_64 - set PATH=%PATH%;%QT_DIR%\bin;C:\MinGW\bin - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" - - vcpkg install lmdb:%PLATFORM%-windows + - vcpkg install + 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 + lmdb:%PLATFORM%-windows + openssl:%PLATFORM%-windows + spdlog:%PLATFORM%-windows + zlib:%PLATFORM%-windows build_script: # VERSION format: branch-master/branch-1.2 @@ -35,6 +47,17 @@ build_script: - echo %VERSION% - echo %INSTVERSION% - echo %DATE% + + # Build & install the dependencies + - 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 + - cmake --build .deps --config Release + + # Build nheko - cmake -G "Visual Studio 15 2017 Win64" -H. -Bbuild -DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release diff --git a/cmake/MatrixStructs.cmake b/cmake/MatrixStructs.cmake deleted file mode 100644 index af694c0f..00000000 --- a/cmake/MatrixStructs.cmake +++ /dev/null @@ -1,33 +0,0 @@ -include(ExternalProject) - -# -# Build matrix-structs. -# - -set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party) -set(MATRIX_STRUCTS_ROOT ${THIRD_PARTY_ROOT}/matrix_structs) -set(MATRIX_STRUCTS_INCLUDE_DIR ${MATRIX_STRUCTS_ROOT}/include) -set(MATRIX_STRUCTS_LIBRARY matrix_structs) - -link_directories(${MATRIX_STRUCTS_ROOT}) - -set(WINDOWS_FLAGS "") - -if(MSVC) - set(WINDOWS_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64") -endif() - -ExternalProject_Add( - MatrixStructs - - GIT_REPOSITORY https://github.com/mujx/matrix-structs - GIT_TAG 5e57c2385a79b6629d1998fec4a7c0baee23555e - - BUILD_IN_SOURCE 1 - SOURCE_DIR ${MATRIX_STRUCTS_ROOT} - CONFIGURE_COMMAND ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Release ${MATRIX_STRUCTS_ROOT} - ${WINDOWS_FLAGS} - BUILD_COMMAND ${CMAKE_COMMAND} --build ${MATRIX_STRUCTS_ROOT} --config Release - INSTALL_COMMAND "" -) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt new file mode 100644 index 00000000..234e904f --- /dev/null +++ b/deps/CMakeLists.txt @@ -0,0 +1,82 @@ +cmake_minimum_required(VERSION 3.1) +project(NHEKO_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_MATRIX_STRUCTS "Use the bundled version of matrix-structs." + ${USE_BUNDLED}) +option(USE_BUNDLED_MATRIX_CLIENT "Use the bundled version of mtxclient." + ${USE_BUNDLED}) + +include(ExternalProject) + +set(BOOST_URL + https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2) +set(BOOST_SHA256 + 5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9) + +set(MATRIX_STRUCTS_URL https://github.com/mujx/matrix-structs) +set(MATRIX_STRUCTS_TAG eeb7373729a1618e2b3838407863342b88b8a0de) + +set(MTXCLIENT_URL https://github.com/mujx/mtxclient) +set(MTXCLIENT_TAG 219d2a8887376122e76ba0f64c0cc9935f62f308) + +set(OLM_URL https://git.matrix.org/git/olm.git) +set(OLM_TAG 4065c8e11a33ba41133a086ed3de4da94dcb6bae) + +set(SPDLOG_URL https://github.com/gabime/spdlog) +set(SPDLOG_TAG 560df2878ad308b27873b3cc5e810635d69cfad6) + +if(USE_BUNDLED_BOOST) + include(Boost) +endif() + +if(USE_BUNDLED_SPDLOG) + include(SpdLog) +endif() + +if(USE_BUNDLED_OLM) + include(Olm) +endif() + +if(USE_BUNDLED_MATRIX_STRUCTS) + include(MatrixStructs) +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(USE_BUNDLED_MATRIX_CLIENT) + include(MatrixClient) + add_dependencies(MatrixClient third-party) +endif() diff --git a/deps/cmake/Boost.cmake b/deps/cmake/Boost.cmake new file mode 100644 index 00000000..572d1d07 --- /dev/null +++ b/deps/cmake/Boost.cmake @@ -0,0 +1,23 @@ +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 variant=release link=static threading=multi --layout=system + INSTALL_COMMAND ${DEPS_BUILD_DIR}/boost/b2 -d0 install +) + +list(APPEND THIRD_PARTY_DEPS Boost) diff --git a/deps/cmake/MatrixClient.cmake b/deps/cmake/MatrixClient.cmake new file mode 100644 index 00000000..7377f710 --- /dev/null +++ b/deps/cmake/MatrixClient.cmake @@ -0,0 +1,30 @@ +set(PLATFORM_FLAGS "") + +if(MSVC) + set(PLATFORM_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64") +endif() + +if(APPLE) + set(PLATFORM_FLAGS "-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl") +endif() + +ExternalProject_Add( + MatrixClient + + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/mtxclient + GIT_REPOSITORY ${MTXCLIENT_URL} + GIT_TAG ${MTXCLIENT_TAG} + + BUILD_IN_SOURCE 1 + SOURCE_DIR ${DEPS_BUILD_DIR}/mtxclient + CONFIGURE_COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + -DCMAKE_BUILD_TYPE=Release + -DBUILD_LIB_TESTS=OFF + -DBUILD_LIB_EXAMPLES=OFF + ${PLATFORM_FLAGS} + ${DEPS_BUILD_DIR}/mtxclient + BUILD_COMMAND + ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR}/mtxclient --config Release) + +list(APPEND THIRD_PARTY_DEPS MatrixClient) diff --git a/deps/cmake/MatrixStructs.cmake b/deps/cmake/MatrixStructs.cmake new file mode 100644 index 00000000..fd12ad39 --- /dev/null +++ b/deps/cmake/MatrixStructs.cmake @@ -0,0 +1,25 @@ +set(WINDOWS_FLAGS "") + +if(MSVC) + set(WINDOWS_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64") +endif() + +ExternalProject_Add( + MatrixStructs + + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/matrix_structs + GIT_REPOSITORY ${MATRIX_STRUCTS_URL} + GIT_TAG ${MATRIX_STRUCTS_TAG} + + BUILD_IN_SOURCE 1 + SOURCE_DIR ${DEPS_BUILD_DIR}/matrix_structs + CONFIGURE_COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + -DCMAKE_BUILD_TYPE=Release + ${DEPS_BUILD_DIR}/matrix_structs + ${WINDOWS_FLAGS} + BUILD_COMMAND ${CMAKE_COMMAND} + --build ${DEPS_BUILD_DIR}/matrix_structs + --config Release) + +list(APPEND THIRD_PARTY_DEPS MatrixStructs) diff --git a/deps/cmake/Olm.cmake b/deps/cmake/Olm.cmake new file mode 100644 index 00000000..b0df2833 --- /dev/null +++ b/deps/cmake/Olm.cmake @@ -0,0 +1,24 @@ +if(MSVC) + set(MAKE_CMD "mingw32-make.exe") +else() + set(MAKE_CMD "make") +endif() + +set(OLM_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}olm${CMAKE_STATIC_LIBRARY_SUFFIX}") + +ExternalProject_Add( + Olm + + GIT_REPOSITORY ${OLM_URL} + GIT_TAG ${OLM_TAG} + + BUILD_IN_SOURCE 1 + SOURCE_DIR ${DEPS_BUILD_DIR}/olm + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_CMD} static + INSTALL_COMMAND + cp -R ${DEPS_BUILD_DIR}/olm/include ${DEPS_INSTALL_DIR} && + cp ${DEPS_BUILD_DIR}/olm/build/libolm.a ${DEPS_INSTALL_DIR}/lib +) + +list(APPEND THIRD_PARTY_DEPS Olm) diff --git a/deps/cmake/SpdLog.cmake b/deps/cmake/SpdLog.cmake new file mode 100644 index 00000000..e49c947f --- /dev/null +++ b/deps/cmake/SpdLog.cmake @@ -0,0 +1,15 @@ +ExternalProject_Add( + SpdLog + + GIT_REPOSITORY ${SPDLOG_URL} + GIT_TAG ${SPDLOG_TAG} + + BUILD_IN_SOURCE 1 + SOURCE_DIR ${DEPS_BUILD_DIR}/spdlog + CONFIGURE_COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + -DCMAKE_BUILD_TYPE=Release + ${DEPS_BUILD_DIR}/spdlog +) + +list(APPEND THIRD_PARTY_DEPS SpdLog) diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index a9720d10..c4eaf347 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -32,6 +32,7 @@ #include #include "MatrixClient.h" +#include namespace { std::unique_ptr instance_ = nullptr; @@ -39,6 +40,8 @@ std::unique_ptr instance_ = nullptr; namespace http { +std::shared_ptr client_ = nullptr; + void init() {