From 8c984bfcffed8064279bd9ddfd2ecf39915eae5a Mon Sep 17 00:00:00 2001 From: Michael Brunner Date: Thu, 30 May 2024 13:54:18 +0200 Subject: [PATCH] ENH: test action --- .github/workflows/build-matrix.yml | 13 +++++++-- CMakeLists.txt | 24 ++++++++++++++- ProjectConfig.h.in | 3 ++ gtfs/CMakeLists.txt | 21 +------------ gtfs/benchmarks/CMakeLists.txt | 47 ++++-------------------------- gtfs/test/CMakeLists.txt | 28 ++---------------- gtfs/test/test_addition.cpp | 6 ++-- logging/CMakeLists.txt | 20 ++----------- raptor/CMakeLists.txt | 18 ------------ 9 files changed, 52 insertions(+), 128 deletions(-) create mode 100644 ProjectConfig.h.in diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 204d10e3..4237c4bf 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -22,10 +22,19 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.4 + - name: Set up cache + id: cache-cpm + uses: actions/cache@v2 + with: + path: ~/cpm-cache + key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }} + restore-keys: | + ${{ runner.os }}-cpm- + - name: Configure CMake run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake -B build -DCMAKE_BUILD_TYPE=Release -DCPM_SOURCE_CACHE=~/cpm-cache - name: Build run: | - cmake --build build --config Release + cmake --build build --config Release -- -j2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e2fb370..13cc1424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,27 @@ cmake_minimum_required(VERSION 3.28) -project(raptorxx) +project(raptorxx VERSION 0.0.1) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if (CMAKE_CXX_STANDARD LESS 23) + message(FATAL_ERROR "At least C++23 required but have ${CMAKE_CXX_STANDARD}") +endif () + +if(MSVC) + add_compile_options(/W4 /WX /std:c++latest) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-Wall -Wextra -pedantic -Werror -std=c++23) +else() + message(WARNING "You are using an unsupported compiler! Compilation has only been tested with MSVC, GCC and Clang.") +endif() + +configure_file ( + "${PROJECT_SOURCE_DIR}/ProjectConfig.h.in" + "${PROJECT_BINARY_DIR}/ProjectConfig.h" +) + + add_subdirectory(logging) add_subdirectory(gtfs) diff --git a/ProjectConfig.h.in b/ProjectConfig.h.in new file mode 100644 index 00000000..7eccf60b --- /dev/null +++ b/ProjectConfig.h.in @@ -0,0 +1,3 @@ +#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ \ No newline at end of file diff --git a/gtfs/CMakeLists.txt b/gtfs/CMakeLists.txt index 305888f2..248ece0b 100644 --- a/gtfs/CMakeLists.txt +++ b/gtfs/CMakeLists.txt @@ -1,26 +1,7 @@ -cmake_minimum_required(VERSION 3.28) - -project(gtfs +project(gtfs DESCRIPTION "C++ implementation of GTFS reader" ) -if (MSVC) - add_compile_options(/W4 /WX) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options(-Wall -Wextra -pedantic -Werror) -else () - # neither MSVC nor GCC is being used - # TODO add compiler specific options - message(STATUS "Using another compiler") -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if (CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "At least C++20 required but have ${CMAKE_CXX_STANDARD}") -endif () - add_library(${PROJECT_NAME} SHARED src/TestObject.cpp src/TestObject.h diff --git a/gtfs/benchmarks/CMakeLists.txt b/gtfs/benchmarks/CMakeLists.txt index b32a4bf4..384f9695 100644 --- a/gtfs/benchmarks/CMakeLists.txt +++ b/gtfs/benchmarks/CMakeLists.txt @@ -1,44 +1,9 @@ cmake_minimum_required(VERSION 3.28) - project(benchmarks) -if (MSVC) - add_compile_options(/W4 /WX) -elseif (GCC) - add_compile_options(-Wall -Wextra -pedantic -Werror) -else () - # neither MSVC nor GCC is being used - # TODO add compiler specific options - message(using another compiler) -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if (CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "At least C++20 required but have ${CMAKE_CXX_STANDARD}") -endif () - -include(FetchContent) -FetchContent_Declare( - benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG main -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(benchmark_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(benchmark) -include_directories(${benchmark_SOURCE_DIR}/include ${benchmark_SOURCE_DIR}) - -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) -include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) +include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake) +CPMAddPackage("gh:google/googletest#main") +CPMAddPackage("gh:google/benchmark#main") file(GLOB CHAPTER_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h") @@ -49,7 +14,5 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/gtfs/src) target_include_directories(${PROJECT_NAME} PRIVATE ${benchmark_SOURCE_DIR}/include ${benchmark_SOURCE_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) -target_link_libraries(${PROJECT_NAME} - benchmark::benchmark - gtfs -) +target_link_libraries(${PROJECT_NAME} benchmark::benchmark) +target_link_libraries(${PROJECT_NAME} gtfs) diff --git a/gtfs/test/CMakeLists.txt b/gtfs/test/CMakeLists.txt index 90afdd9d..82b49cbf 100644 --- a/gtfs/test/CMakeLists.txt +++ b/gtfs/test/CMakeLists.txt @@ -4,30 +4,8 @@ project("test" DESCRIPTION "C++ implementation of GTFS reader" ) -if (MSVC) - add_compile_options(/W4 /WX) -elseif (GCC) - add_compile_options(-Wall -Wextra -pedantic -Werror) -else () - message(using another compiler) -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if (CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "At least C++20 required but have ${CMAKE_CXX_STANDARD}") -endif () - -include(FetchContent) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) +include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake) +CPMAddPackage("gh:google/googletest#main") add_executable(${PROJECT_NAME} test_addition.cpp @@ -35,9 +13,9 @@ add_executable(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/gtfs/src) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) target_link_libraries(${PROJECT_NAME} gtest gtest_main) - target_link_libraries(${PROJECT_NAME} gtfs) diff --git a/gtfs/test/test_addition.cpp b/gtfs/test/test_addition.cpp index da14ab17..e9a1eb5c 100644 --- a/gtfs/test/test_addition.cpp +++ b/gtfs/test/test_addition.cpp @@ -3,8 +3,9 @@ // -#include "gtest/gtest.h" -#include "TestObject.h" +#include +#include +#include auto add(const int a, const int b) { return a + b; @@ -14,6 +15,7 @@ auto add(const int a, const int b) { TEST(MathTest, Addition) { TestObject lTest = TestObject(); lTest.testFunction(); + std::cout << "v" << PROJECT_VERSION_MAJOR << "." << PROJECT_VERSION_MINOR << "." << PROJECT_VERSION_PATCH << std::endl; EXPECT_EQ(add(5, 8), 13); EXPECT_EQ(add(5, -8), -3); } diff --git a/logging/CMakeLists.txt b/logging/CMakeLists.txt index 65332f99..eaba6a96 100644 --- a/logging/CMakeLists.txt +++ b/logging/CMakeLists.txt @@ -2,29 +2,13 @@ cmake_minimum_required(VERSION 3.28) project("logging") -if (MSVC) - add_compile_options(/W3) -elseif (GCC) - add_compile_options(-Wall -Wextra -pedantic -Werror) -else () - # neither MSVC nor GCC is being used - # TODO add compiler specific options - message(using another compiler) -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake) +CPMAddPackage("gh:gabime/spdlog#v1.x") -if (CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "At least C++20 required but have ${CMAKE_CXX_STANDARD}") -endif () add_library(${PROJECT_NAME} LoggingPool.cpp LoggingPool.h ) -include(../cmake/CPM.cmake) -CPMAddPackage("gh:gabime/spdlog#v1.x") - target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) diff --git a/raptor/CMakeLists.txt b/raptor/CMakeLists.txt index efc116b7..cc8010a2 100644 --- a/raptor/CMakeLists.txt +++ b/raptor/CMakeLists.txt @@ -4,24 +4,6 @@ project("raptor" DESCRIPTION "C++ implementation of raptor algorithm" ) - -if (MSVC) - add_compile_options(/W4 /WX) -elseif (GCC) - add_compile_options(-Wall -Wextra -pedantic -Werror) -else () - # neither MSVC nor GCC is being used - # TODO add compiler specific options - message(using another compiler) -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if (CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "At least C++20 required but have ${CMAKE_CXX_STANDARD}") -endif () - include_directories(${CMAKE_SOURCE_DIR}/common/logging/include) add_library(${PROJECT_NAME}