From 209d67a04d188785efed558a2857f1aba0040a9f Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Wed, 23 Aug 2023 11:18:37 +0100 Subject: [PATCH] ci: fail Ubuntu CI if there are compiler warnings Add a [`CMakePresets.json`][1] file that contains `ci-ubuntu` preset. This preset contains most of the recommended compiler warnings from the [`cmake-init`][2] project. However, I had to remove the `-Wdouble-promotion` and `-Werror=float-equal` flags since there are issues within the GTest headers. For compatibility with g++-7, `-Wextra-semi` was removed. I also had to remove some of the following flags like: `-fstack-protector-strong -fstack-clash-protection`. These flags cause errors in Clang v10 (still run in CI), and to be honest, with stuff like address sanitizer, we probably don't need them. [1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html [2]: https://github.com/friendlyanon/cmake-init/blob/aa42211c79ab5117b05a2d9f795427f078a0a3d5/cmake-init/templates/common/CMakePresets.json#L88 --- .github/workflows/build-ubuntu-20.04.yml | 5 +- .github/workflows/build-ubuntu-latest.yml | 5 +- CMakePresets.json | 59 +++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 CMakePresets.json diff --git a/.github/workflows/build-ubuntu-20.04.yml b/.github/workflows/build-ubuntu-20.04.yml index dd0ac2ec..fe2d1be4 100644 --- a/.github/workflows/build-ubuntu-20.04.yml +++ b/.github/workflows/build-ubuntu-20.04.yml @@ -27,12 +27,11 @@ jobs: sudo apt-get update --fix-missing sudo apt install -y ${{ matrix.compiler.pkg }}-${{ matrix.compiler.version }} - name: Compile tests - working-directory: build env: CXX: ${{ matrix.compiler.exe }}-${{ matrix.compiler.version }} run: | - cmake ${{ matrix.mode }} -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF .. - make -j2 + cmake ${{ matrix.mode }} --preset ci-ubuntu + cmake --build build/ --parallel 2 - name: Run tests working-directory: build env: diff --git a/.github/workflows/build-ubuntu-latest.yml b/.github/workflows/build-ubuntu-latest.yml index 0a1a6888..d67ed479 100644 --- a/.github/workflows/build-ubuntu-latest.yml +++ b/.github/workflows/build-ubuntu-latest.yml @@ -26,12 +26,11 @@ jobs: sudo apt-get update --fix-missing sudo apt install -y ${{ matrix.compiler.pkg }}-${{ matrix.compiler.version }} - name: Compile tests - working-directory: build env: CXX: ${{ matrix.compiler.exe }}-${{ matrix.compiler.version }} run: | - cmake ${{ matrix.mode }} -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF .. - make -j2 + cmake ${{ matrix.mode }} --preset ci-ubuntu + cmake --build build/ --parallel 2 - name: Run tests working-directory: build env: diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..53eacd08 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,59 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 13, + "patch": 0 + }, + "configurePresets": [ + { + "name": "cmake-pedantic", + "description": "Enables all CMake warnings.`", + "hidden": true, + "warnings": { + "dev": true, + "deprecated": true, + "uninitialized": true, + "unusedCli": true, + "systemVars": false + } + }, + { + "name": "dev-mode", + "hidden": true, + "description": "Common (non-OS specific) mode for development", + "inherits": "cmake-pedantic", + "cacheVariables": { + "BUILD_TESTING": true, + "libuv_buildtests": false + } + }, + { + "name": "flags-linux", + "hidden": true, + "description": "Compiler flags for GNU and Clang compilers. When compiling in DEBUG mode, all warnings will be converted into errors.", + "cacheVariables": { + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wimplicit-fallthrough -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast", + "CMAKE_CXX_FLAGS_DEBUG": "-Werror" + } + }, + { + "name": "ci-linux", + "generator": "Unix Makefiles", + "hidden": true, + "inherits": ["flags-linux"], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "ci-build", + "binaryDir": "${sourceDir}/build", + "hidden": true + }, + { + "name": "ci-ubuntu", + "inherits": ["ci-build", "ci-linux", "dev-mode"] + } + ] +}