From 6be8bbe5f428144f07a02773a454b0c5f764a34d Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 3 May 2024 23:27:29 +0200 Subject: [PATCH] Setup github actions based CI --- .github/workflows/build.yaml | 78 ++++++++++++++++++++++++++++++++++++ benchmarks/CMakeLists.txt | 50 +++++------------------ tests/CMakeLists.txt | 64 ++++++----------------------- 3 files changed, 102 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2884f01 --- /dev/null +++ b/.github/workflows/build.yaml @@ -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 diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index cdcaa55..851d28c 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3744cde..57b83ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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