Skip to content

Commit

Permalink
Setup github actions based CI
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid committed May 3, 2024
1 parent 3ea1f95 commit 6be8bbe
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 90 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build
on: push
jobs:
build:
strategy:
matrix:
build_type:
- Release
- Debug

include:
- os: ubuntu-22.04
compiler: g++
compiler_package: g++
boost_version: '1.74'

- os: ubuntu-22.04
compiler: g++
compiler_package: g++
boost_version: '1.74'

- os: ubuntu-22.04
compiler: clang++
compiler_package: clang
boost_version: '1.74'

- os: ubuntu-22.04
compiler: clang++
compiler_package: clang
boost_version: '1.74'

name: Build ${{ matrix.build_type }} with ${{ matrix.compiler }} and boost ${{ matrix.boost_version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Update apt-get
run: sudo apt-get update

- name: Install apt packages for dependencies
run: >
sudo apt-get install -y --no-install-recommends
ccache
cmake
libboost-atomic${{ matrix.boost_version }}-dev
libboost-context${{ matrix.boost_version }}-dev
libboost-coroutine${{ matrix.boost_version }}-dev
libboost-date-time${{ matrix.boost_version }}-dev
libboost-thread${{ matrix.boost_version }}-dev
ninja-build
${{ matrix.compiler_package }}
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.build_type }}
max-size: 1G

- name: Configure
run: >
cmake
-B build
-S .
-G Ninja
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
-D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
-D CMAKE_CXX_COMPILER=${{ matrix.compiler }}
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache
-D RESOURCE_POOL_BUILD_TESTS=ON
-D RESOURCE_POOL_BUILD_EXAMPLES=ON
-D RESOURCE_POOL_BUILD_BENCHMARKS=ON
- name: Build
run: cmake --build build

- name: Install
run: cmake --install build
50 changes: 11 additions & 39 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,24 @@ find_package(Boost COMPONENTS coroutine context REQUIRED)
find_package(benchmark)

if(NOT TARGET google_benchmark AND NOT benchmark_FOUND)
include(ExternalProject)

set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/external)

if(NOT GOOGLE_BENCHMARK_REPOSITORY)
if(NOT DEFINED ENV{GOOGLE_BENCHMARK_REPOSITORY})
set(GOOGLE_BENCHMARK_REPOSITORY https://github.com/google/benchmark.git)
else()
set(GOOGLE_BENCHMARK_REPOSITORY $ENV{GOOGLE_BENCHMARK_REPOSITORY})
endif()
endif()

ExternalProject_Add(
google_benchmark
GIT_REPOSITORY ${GOOGLE_BENCHMARK_REPOSITORY}
TIMEOUT 1
CONFIGURE_COMMAND cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF ../google_benchmark
INSTALL_COMMAND ""
UPDATE_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
set(BENCHMARK_ENABLE_TESTING OFF)
set(BENCHMARK_ENABLE_INSTALL OFF)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)

include(FetchContent)
FetchContent_Declare(benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
URL_HASH SHA512=d73587ad9c49338749e1d117a6f8c7ff9c603a91a2ffa91a7355c7df7dea82710b9a810d34ddfef20973ecdc77092ec10fb2b4e4cc8d2e7810cbed79617b3828
SOURCE_DIR fetched/benchmark
)

ExternalProject_Get_Property(google_benchmark source_dir)
include_directories(SYSTEM ${source_dir}/include)

ExternalProject_Get_Property(google_benchmark binary_dir)
link_directories(${binary_dir}/src)
endif()

if(benchmark_FOUND)
include_directories(SYSTEM ${benchmark_INCLUDE_DIRS})
get_filename_component(_BENCHMARK_LIB_DIR ${benchmark_LIBRARIES} PATH)
link_directories(${_BENCHMARK_LIB_DIR})
FetchContent_MakeAvailableExcludeFromAll(benchmark)
endif()

add_executable(resource_pool_benchmark_async async.cc)

if(TARGET google_benchmark)
add_dependencies(resource_pool_benchmark_async google_benchmark)
endif()

set(LIBRARIES
pthread
benchmark
benchmark::benchmark
Boost::coroutine
Boost::context
elsid::resource_pool
Expand Down
64 changes: 13 additions & 51 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,21 @@ find_package(GTest)
find_package(GMock)

if(NOT TARGET googletest AND (NOT GTEST_FOUND OR NOT GMOCK_FOUND))
include(ExternalProject)

set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/external)

if(NOT GOOGLETEST_REPOSITORY)
if(NOT DEFINED ENV{GOOGLETEST_REPOSITORY})
set(GOOGLETEST_REPOSITORY https://github.com/google/googletest.git)
else()
set(GOOGLETEST_REPOSITORY $ENV{GOOGLETEST_REPOSITORY})
endif()
endif()

ExternalProject_Add(
googletest
GIT_REPOSITORY ${GOOGLETEST_REPOSITORY}
GIT_TAG release-1.10.0
TIMEOUT 1
CONFIGURE_COMMAND cmake
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/lib
../googletest
UPDATE_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
include(FetchContent)
FetchContent_Declare(googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
URL_HASH SHA512=1479ea2f3172c622c0ca305f5b2bc45a42941221ec0ac7865e6d6d020ec4d008d952fc64e01a4c5138d7bed4148cf75596f25bb9e9044a98bbbf5662053ea11c
SOURCE_DIR fetched/googletest
)
endif()

if (GTEST_FOUND AND GMOCK_FOUND)
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS})
get_filename_component(_GOOGLETEST_LIB_DIR ${GMOCK_MAIN_LIBRARY} PATH)
else()
include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/include)

set(_GOOGLETEST_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)

set(GTEST_LIBRARIES ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
set(GTEST_MAIN_LIBRARY ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a)
set(GTEST_BOTH_LIBRARIES "${GTEST_LIBRARIES};${GTEST_MAIN_LIBRARY}")
if (MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_MakeAvailableExcludeFromAll(googletest)

set(GMOCK_LIBRARIES ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock.a)
set(GMOCK_MAIN_LIBRARY ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main.a)
set(GMOCK_BOTH_LIBRARIES "${GMOCK_LIBRARIES};${GMOCK_MAIN_LIBRARY}")
add_library(GTest::GTest ALIAS gtest)
add_library(GMock::GMock ALIAS gmock)
endif()

link_directories(${_GOOGLETEST_LIB_DIR})

add_executable(resource_pool_test
main.cc
error.cc
Expand All @@ -76,14 +42,10 @@ add_executable(resource_pool_test
async/integration.cc
)

if(TARGET googletest)
add_dependencies(resource_pool_test googletest)
endif()

set(LIBRARIES
pthread
gtest
gmock
GTest::GTest
GMock::GMock
Boost::coroutine
Boost::context
elsid::resource_pool
Expand Down

0 comments on commit 6be8bbe

Please sign in to comment.