diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4807364..ec5b78e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,6 @@ jobs: run: | cmake ${{ matrix.package }} \ -B ${{ matrix.package }}/build \ - -D CMAKE_CXX_FLAGS=-Werror \ -D BUILD_TESTING=ON - name: Check code formatting @@ -58,7 +57,6 @@ jobs: cmake ${{ matrix.package }} ` -B ${{ matrix.package }}/build ` -D CMAKE_CXX_COMPILER=cl ` - -D CMAKE_CXX_FLAGS=/WX ` -D BUILD_TESTING=ON - name: Build project diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 7aea9d0..500ddc1 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -2,36 +2,51 @@ cmake_minimum_required(VERSION 3.0) project(error) -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /W4 /w14640 /EHsc") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -Wpedantic") -endif() - -set(CMAKE_CXX_STANDARD 11) - +# Import dependencies include(cmake/CPM.cmake) cpmaddpackage("gh:fmtlib/fmt#10.0.0") +# Build the main library add_library(error src/error.cpp) target_include_directories(error PUBLIC include) target_link_libraries(error PUBLIC fmt) +# Check if this project is the main project if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + # Import Format.cmake to format source code cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") if(BUILD_TESTING) enable_testing() + # Import Catch2 as the main testing framework cpmaddpackage("gh:catchorg/Catch2@3.3.2") include("${Catch2_SOURCE_DIR}/extras/Catch.cmake") - if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC -O0") - endif() - + # Build tests for the main library add_executable(error_test test/error_test.cpp) target_link_libraries(error_test PRIVATE error Catch2::Catch2WithMain) catch_discover_tests(error_test) endif() + + # Get all targets in this directory + get_property( + TARGETS + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + PROPERTY BUILDSYSTEM_TARGETS) + + foreach(TARGET IN LISTS TARGETS) + # Statically analyze code by checking for warnings + if(MSVC) + target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc) + else() + target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic) + endif() + + # Enable support to check for test coverage + if(BUILD_TESTING AND NOT MSVC) + target_compile_options(${TARGET} PRIVATE --coverage -O0) + target_link_options(${TARGET} PRIVATE --coverage) + endif() + endforeach() endif()