Skip to content
Snippets Groups Projects
Commit bcc6deea authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Include cmake modules for building Boost & GTest

parent fbcd864f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
set -evx
sudo wget -O boost_1_66_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.66.0/boost_1_66_0.tar.gz/download
sudo tar xzf boost_1_66_0.tar.gz
cd boost_1_66_0/
sudo ./bootstrap.sh --with-libraries=random,thread,system --prefix=/usr/local
sudo ./b2 -d0 variant=debug link=shared
sudo ./b2 -d0 install
#!/usr/bin/env bash
set -evx
sudo apt-get -qq update
sudo apt-get install -y libgtest-dev
wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz
tar xf release-1.8.0.tar.gz
cd googletest-release-1.8.0
cmake -DBUILD_SHARED_LIBS=ON .
make
sudo cp -a googletest/include/gtest /usr/include
sudo cp -a googlemock/gtest/*.so /usr/lib/
sudo ldconfig -v | grep gtest
cd $TRAVIS_BUILD_DIR
......@@ -36,3 +36,6 @@ compile_commands.json
# Synapse data
data/
# Deps
.third-party
......@@ -57,9 +57,6 @@ matrix:
- "g++-7"
install:
- if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew upgrade boost; fi
- if [ $TRAVIS_OS_NAME == linux ]; then ./.ci/gtest.sh; fi
- if [ $TRAVIS_OS_NAME == linux ]; then ./.ci/boost.sh; fi
- if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:george-edison55/cmake-3.x; fi
- if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq; fi
- if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -qq -y cmake; fi
......
......@@ -40,26 +40,47 @@ if(NOT APPLE AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
#
# OpenSSL
#
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
#
# Boost 1.66
#
# If we can't find an already installed version we will
# download it and build it from source.
#
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.66 REQUIRED)
find_package(Boost 1.66)
find_package(Boost 1.66 COMPONENTS system random thread)
find_package(OpenSSL REQUIRED)
if(NOT Boost_FOUND)
message(STATUS "Fetching and building Boost 1.66")
include(${CMAKE_SOURCE_DIR}/cmake/Boost.cmake)
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(src)
#
# matrix-structs
#
add_subdirectory(libs/matrix-structs)
include_directories(${matrix_structs_SOURCE_DIR}/include)
include_directories(${matrix_structs_SOURCE_DIR}/deps)
include_directories(src)
set(SRC src/client.cpp src/utils.cpp)
add_library(matrix_client ${SRC})
target_link_libraries(matrix_client matrix_structs ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES})
if(NOT Boost_FOUND)
add_dependencies(matrix_client Boost)
endif()
if (BUILD_LIB_EXAMPLES)
add_executable(room_feed examples/room_feed.cpp)
target_link_libraries(room_feed matrix_client matrix_structs)
......@@ -68,7 +89,13 @@ endif()
if (BUILD_LIB_TESTS)
enable_testing()
find_package(GTest REQUIRED)
find_package(GTest)
if (NOT GTest_FOUND)
message(STATUS "Fetching and building GTest 1.8")
include(${CMAKE_SOURCE_DIR}/cmake/GoogleTest.cmake)
endif()
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(client_api tests/client_api.cpp)
......@@ -86,6 +113,11 @@ if (BUILD_LIB_TESTS)
add_executable(connection tests/connection.cpp)
target_link_libraries(connection matrix_client ${GTEST_BOTH_LIBRARIES})
if (NOT GTest_FOUND)
add_dependencies(client_api GTest)
add_dependencies(connection GTest)
endif()
add_test(BasicConnectivity connection)
add_test(ClientAPI client_api)
endif()
include(ExternalProject)
#
# Download & install Boost from source.
#
set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party)
set(BUNDLED_BOOST_ROOT ${THIRD_PARTY_ROOT}/boost_1_66_0)
ExternalProject_Add(
Boost
URL https://sourceforge.net/projects/boost/files/boost/1.66.0/boost_1_66_0.tar.bz2/download
URL_HASH SHA1=b6b284acde2ad7ed49b44e856955d7b1ea4e9459
DOWNLOAD_DIR ${THIRD_PARTY_ROOT}/downloads
DOWNLOAD_NO_PROGRESS 0
BUILD_IN_SOURCE 1
SOURCE_DIR ${BUNDLED_BOOST_ROOT}
CONFIGURE_COMMAND ${BUNDLED_BOOST_ROOT}/bootstrap.sh
--with-libraries=random,thread,system
--prefix=${BUNDLED_BOOST_ROOT}
BUILD_COMMAND ${BUNDLED_BOOST_ROOT}/b2 -d0 variant=release link=static threading=multi
INSTALL_COMMAND ${BUNDLED_BOOST_ROOT}/b2 -d0 install
)
set(Boost_INCLUDE_DIRS ${BUNDLED_BOOST_ROOT})
set(Boost_LIBRARIES boost_random boost_system boost_thread)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
link_directories(${Boost_INCLUDE_DIRS}/stage/lib)
include(ExternalProject)
#
# Download & install Google Test from source.
#
set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party)
set(BUNDLED_GTEST_ROOT ${THIRD_PARTY_ROOT}/gtest_1_8_0)
ExternalProject_Add(
GTest
URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz
URL_HASH SHA1=e7e646a6204638fe8e87e165292b8dd9cd4c36ed
DOWNLOAD_DIR ${THIRD_PARTY_ROOT}/downloads
DOWNLOAD_NO_PROGRESS 0
BUILD_IN_SOURCE 1
SOURCE_DIR ${BUNDLED_GTEST_ROOT}
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${BUNDLED_GTEST_ROOT}
BUILD_COMMAND make
INSTALL_COMMAND ""
)
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
include_directories(SYSTEM ${BUNDLED_GTEST_ROOT}/googletest/include)
link_directories(${BUNDLED_GTEST_ROOT}/googlemock/gtest)
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