From 12987d630e45dfbf8e5a69a1a3272c520dbbe66f Mon Sep 17 00:00:00 2001 From: Claus Date: Thu, 17 Aug 2023 17:31:22 +0200 Subject: [PATCH 1/8] Add cmake workflow presets --- CMakePresets.json | 100 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 35630033..57f7c238 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,8 +1,8 @@ { - "version": 4, + "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 21, + "minor": 25, "patch": 0 }, "configurePresets": [ @@ -11,7 +11,8 @@ "hidden": true, "environment": { "CCACHE_BASEDIR": "${sourceDir}", - "CCACHE_SLOPPINESS": "pch_defines,time_macros" + "CCACHE_SLOPPINESS": "pch_defines,time_macros", + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES" } }, { @@ -90,6 +91,97 @@ "lhs": "${hostSystemName}", "rhs": "Windows" } + }, + { + "name": "ci-ninja-debug", + "displayName": "Ninja debug", + "configurePreset": "ci-ninja-debug", + "configuration": "Debug", + "targets": [ "all", "help" ] + }, + { + "name": "ci-ninja-release", + "displayName": "Ninja release", + "configurePreset": "ci-ninja-release", + "configuration": "Release", + "targets": [ "all", "api_doc" ] + } + ], + "testPresets": [ + { + "name": "test-common", + "description": "Test CMake settings that apply to all configurations", + "hidden": true, + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + }, + { + "name": "ci-ninja-debug", + "displayName": "Strict", + "description": "Enable output and stop on failure", + "inherits": "test-common", + "configurePreset": "ci-ninja-debug" + }, + { + "name": "ci-ninja-release", + "displayName": "Strict", + "description": "Enable output and stop on failure", + "inherits": "test-common", + "configurePreset": "ci-ninja-release" + } + ], + "packagePresets": [ + { + "name": "ci-ninja-release", + "configurePreset": "ci-ninja-release", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "ci-ninja-debug", + "steps": [ + { + "type": "configure", + "name": "ci-ninja-debug" + }, + { + "type": "build", + "name": "ci-ninja-debug" + }, + { + "type": "test", + "name": "ci-ninja-debug" + } + ] + }, + { + "name": "ci-ninja-release", + "steps": [ + { + "name": "ci-ninja-release", + "type": "configure" + }, + { + "name": "ci-ninja-release", + "type": "build" + }, + { + "type": "test", + "name": "ci-ninja-release" + }, + { + "name": "ci-ninja-release", + "type": "package" + } + ] } ] -} \ No newline at end of file +} From 5a05b44f6280f97f398ec0a8d97d6ee73917fe27 Mon Sep 17 00:00:00 2001 From: Claus Date: Mon, 21 Aug 2023 09:00:25 +0200 Subject: [PATCH 2/8] Prepare use of run-clang-tidy Also upgrade to catch2 v3.4.0 to use Catch2WithMain. Add intermeediate header for now. --- .clang-tidy | 55 +++++++++++++++++++ CMakePresets.json | 31 +++++++---- conanfile.txt | 2 +- include/catch2/catch.hpp | 2 + test/CMakeLists.txt | 17 +++--- test/src/derived_unit_tests/velocity_tests.cc | 2 +- .../src/detail_tests/unit_t_operator_tests.cc | 8 +-- 7 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 .clang-tidy create mode 100644 include/catch2/catch.hpp diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..ab862b2a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,55 @@ +--- +# +# clang-format v12.0.0 +# +Checks: +'-*, + #TBD llvm-header-guard, + bugprone-*, + cert-*, + clang-analyzer-*, + -clang-analyzer-cplusplus.Move, + cppcoreguidelines-*, + -cppcoreguidelines-macro-usage, + concurrency-*, + #MAYBE google-*, + hicpp-*, + misc-*, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + portability-*, + readability-*, + -readability-identifier-naming, + -readability-identifier-length, + -*-magic-numbers, +' + +HeaderFilterRegex: '.*' +WarningsAsErrors: 'clang*' +FormatStyle: google +UseColor: false +User: klein_cl + +CheckOptions: + - { key: readability-identifier-naming.NamespaceCase, value: CamelCase } + - { key: readability-identifier-naming.ClassCase, value: CamelCase } + - { key: readability-identifier-naming.MemberCase, value: camelBack } + - { key: readability-identifier-naming.MemberPrefix, value: m_ } + - { key: readability-identifier-naming.StructCase, value: lower_case } + - { key: readability-identifier-naming.UnionCase, value: lower_case } + - { key: readability-identifier-naming.TypedefCase, value: lower_case } + - { key: readability-identifier-naming.TypedefSuffix, value: _type } + - { key: readability-identifier-naming.FunctionCase, value: camelBack } + - { key: readability-identifier-naming.EnumCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprFunctionCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprMethodCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } + - { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE } + - { key: readability-identifier-naming.LocalConstantPointerCase, value: UPPER_CASE } + - { key: readability-identifier-naming.ScopedEnumConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE } +... diff --git a/CMakePresets.json b/CMakePresets.json index 57f7c238..175069c6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,30 +9,42 @@ { "name": "ccache-env", "hidden": true, + "description": "build using ccache", + "cacheVariables": { + "CMAKE_CXX_COMPILER_LAUNCHER ": "ccache" + }, "environment": { "CCACHE_BASEDIR": "${sourceDir}", - "CCACHE_SLOPPINESS": "pch_defines,time_macros", - "CMAKE_EXPORT_COMPILE_COMMANDS": "YES" + "CCACHE_SLOPPINESS": "pch_defines,time_macros" } }, { - "name": "conan-module-path", + "name": "clang-tidy", "hidden": true, + "description": "build using clang-tidy as precompile step", "cacheVariables": { - "CMAKE_PREFIX_PATH": "${sourceDir}/build/" + "CMAKE_CXX_CLANG_TIDY": "clang-tidy" + }, + "environment": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES" } }, + { + "name": "conan-module-path", + "hidden": true, + "description": "setup using conan toolchain", + "toolchainFile": "conan_toolchain.cmake", + "binaryDir": "${sourceDir}/build" + }, { "name": "ci-ninja", - "displayName": "Ninja", + "hidden": true, "description": "build using Ninja generator", "inherits": [ "ccache-env", "conan-module-path" ], - "generator": "Ninja", - "hidden": true, - "binaryDir": "${sourceDir}/build" + "generator": "Ninja" }, { "name": "ci-ninja-debug", @@ -96,8 +108,7 @@ "name": "ci-ninja-debug", "displayName": "Ninja debug", "configurePreset": "ci-ninja-debug", - "configuration": "Debug", - "targets": [ "all", "help" ] + "configuration": "Debug" }, { "name": "ci-ninja-release", diff --git a/conanfile.txt b/conanfile.txt index b3786fa0..da38c1a8 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -catch2/2.13.10 +catch2/3.4.0 [generators] CMakeDeps \ No newline at end of file diff --git a/include/catch2/catch.hpp b/include/catch2/catch.hpp new file mode 100644 index 00000000..564e5e8a --- /dev/null +++ b/include/catch2/catch.hpp @@ -0,0 +1,2 @@ +// see https://github.com/catchorg/Catch2/blob/v3.0.1/docs/migrate-v2-to-v3.md#how-to-migrate-projects-from-v2-to-v3 +#include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d02b93ec..5718a1e4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.23) add_executable(SI_detail_tests) target_sources( SI_detail_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/detail_tests/detail_tests.cc src/detail_tests/number_parser_tests.cc src/detail_tests/unit_t_operator_tests.cc @@ -17,7 +17,7 @@ target_include_directories( $) target_compile_features(SI_detail_tests PRIVATE cxx_std_17) -target_link_libraries(SI_detail_tests Catch2::Catch2) +target_link_libraries(SI_detail_tests Catch2::Catch2WithMain) target_compile_options( SI_detail_tests @@ -33,7 +33,7 @@ target_compile_options( add_executable(SI_base_unit_tests) target_sources( SI_base_unit_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/base_unit_tests/mass_tests.cc src/base_unit_tests/time_tests.cc src/base_unit_tests/electric_current_tests.cc @@ -48,7 +48,7 @@ target_include_directories( $) target_compile_features(SI_base_unit_tests PRIVATE cxx_std_17) -target_link_libraries(SI_base_unit_tests Catch2::Catch2) +target_link_libraries(SI_base_unit_tests Catch2::Catch2WithMain) target_compile_options( SI_base_unit_tests @@ -68,7 +68,7 @@ target_compile_options( add_executable(SI_derived_unit_tests) target_sources( SI_derived_unit_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/derived_unit_tests/area_tests.cc src/derived_unit_tests/frequency_tests.cc src/derived_unit_tests/electric_charge_tests.cc @@ -105,7 +105,7 @@ target_include_directories( $) target_compile_features(SI_derived_unit_tests PRIVATE cxx_std_17) -target_link_libraries(SI_derived_unit_tests Catch2::Catch2) +target_link_libraries(SI_derived_unit_tests Catch2::Catch2WithMain) target_compile_options( SI_derived_unit_tests @@ -121,7 +121,8 @@ target_compile_options( add_executable(SI_unit_benchmarks) target_sources( SI_unit_benchmarks - PRIVATE src/Catch2Main.cc src/benchmarks/unit_assignment_benchmarks.cc + PRIVATE #XXX src/Catch2Main.cc + src/benchmarks/unit_assignment_benchmarks.cc src/benchmarks/detail_benchmarks.cc src/benchmarks/string_operations_benchmarks.cc) @@ -131,7 +132,7 @@ target_include_directories( $) target_compile_features(SI_unit_benchmarks PRIVATE cxx_std_17) -target_link_libraries(SI_unit_benchmarks Catch2::Catch2) +target_link_libraries(SI_unit_benchmarks Catch2::Catch2WithMain) target_compile_options( SI_unit_benchmarks diff --git a/test/src/derived_unit_tests/velocity_tests.cc b/test/src/derived_unit_tests/velocity_tests.cc index 17500476..a9363db6 100644 --- a/test/src/derived_unit_tests/velocity_tests.cc +++ b/test/src/derived_unit_tests/velocity_tests.cc @@ -139,7 +139,7 @@ TEST_CASE("GIVEN a length of type float WHEN divided by a value of type double " SI::metre_t a = 1.5_km; SI::seconds_t s{1.0}; - SI::metre_per_second_t c = a / s; + SI::metre_per_second_t c = a / s; // NOLINT(clang-analyzer-deadcode.DeadStores) STATIC_REQUIRE( std::is_same>::value); } diff --git a/test/src/detail_tests/unit_t_operator_tests.cc b/test/src/detail_tests/unit_t_operator_tests.cc index 37095fa6..b0bcb19f 100644 --- a/test/src/detail_tests/unit_t_operator_tests.cc +++ b/test/src/detail_tests/unit_t_operator_tests.cc @@ -60,7 +60,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v1{123}; unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v2{std::move(v1)}; - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) } TEMPLATE_TEST_CASE( @@ -71,7 +71,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v1{1000}; unit_t<'X', std::ratio<1>, TestType, std::kilo> v2{std::move(v1)}; - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) REQUIRE(v2.value() == 1); } @@ -84,7 +84,7 @@ TEMPLATE_TEST_CASE("GIVEN two values of the same unit type WHEN move assigned" v2 = std::move(v1); - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) } TEMPLATE_TEST_CASE( @@ -98,7 +98,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::kilo> v2{0}; v2 = std::move(v1); - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) REQUIRE(v2.value() == 1); } From ec02b4bb627ef21a6f4cd35479cbb81929d40dec Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 27 Oct 2023 20:29:04 +0200 Subject: [PATCH 3/8] Changes according review Suppress more clang-tidy-17 warnings too --- .clang-tidy | 11 ++++++++++- CMakeLists.txt | 2 +- test/CMakeLists.txt | 8 ++++---- {include => test/include}/catch2/catch.hpp | 0 4 files changed, 15 insertions(+), 6 deletions(-) rename {include => test/include}/catch2/catch.hpp (100%) diff --git a/.clang-tidy b/.clang-tidy index ab862b2a..4c71ee9e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,23 +14,32 @@ Checks: concurrency-*, #MAYBE google-*, hicpp-*, + -hicpp-explicit-conversions, misc-*, + -misc-const-correctness, + -misc-include-cleaner, modernize-*, + -modernize-type-traits, + -modernize-use-nodiscard, -modernize-use-trailing-return-type, performance-*, portability-*, readability-*, -readability-identifier-naming, -readability-identifier-length, + -readability-simplify-boolean-expr, + -readability-string-compare, -*-magic-numbers, + -*-narrowing-conversions, + -*-uppercase-literal-suffix, ' HeaderFilterRegex: '.*' WarningsAsErrors: 'clang*' FormatStyle: google UseColor: false -User: klein_cl +#MAYBE: ... example only CheckOptions: - { key: readability-identifier-naming.NamespaceCase, value: CamelCase } - { key: readability-identifier-naming.ClassCase, value: CamelCase } diff --git a/CMakeLists.txt b/CMakeLists.txt index df3f67ad..95a9a0c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.23) +cmake_minimum_required(VERSION 3.23...3.27) project( "SI" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5718a1e4..8b2f301b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.23) add_executable(SI_detail_tests) target_sources( SI_detail_tests - PRIVATE #XXX src/Catch2Main.cc + PRIVATE src/detail_tests/detail_tests.cc src/detail_tests/number_parser_tests.cc src/detail_tests/unit_t_operator_tests.cc @@ -33,7 +33,7 @@ target_compile_options( add_executable(SI_base_unit_tests) target_sources( SI_base_unit_tests - PRIVATE #XXX src/Catch2Main.cc + PRIVATE src/base_unit_tests/mass_tests.cc src/base_unit_tests/time_tests.cc src/base_unit_tests/electric_current_tests.cc @@ -68,7 +68,7 @@ target_compile_options( add_executable(SI_derived_unit_tests) target_sources( SI_derived_unit_tests - PRIVATE #XXX src/Catch2Main.cc + PRIVATE src/derived_unit_tests/area_tests.cc src/derived_unit_tests/frequency_tests.cc src/derived_unit_tests/electric_charge_tests.cc @@ -121,7 +121,7 @@ target_compile_options( add_executable(SI_unit_benchmarks) target_sources( SI_unit_benchmarks - PRIVATE #XXX src/Catch2Main.cc + PRIVATE src/benchmarks/unit_assignment_benchmarks.cc src/benchmarks/detail_benchmarks.cc src/benchmarks/string_operations_benchmarks.cc) diff --git a/include/catch2/catch.hpp b/test/include/catch2/catch.hpp similarity index 100% rename from include/catch2/catch.hpp rename to test/include/catch2/catch.hpp From 36dc249ff99a5869c150b76e48b179f5aa3c4cba Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 27 Oct 2023 21:54:41 +0200 Subject: [PATCH 4/8] Use clang-tidy for ci-ninja-release build --- CMakePresets.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 175069c6..66e0735d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,7 +19,7 @@ } }, { - "name": "clang-tidy", + "name": "clang-tidy-env", "hidden": true, "description": "build using clang-tidy as precompile step", "cacheVariables": { @@ -33,8 +33,10 @@ "name": "conan-module-path", "hidden": true, "description": "setup using conan toolchain", - "toolchainFile": "conan_toolchain.cmake", - "binaryDir": "${sourceDir}/build" + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_PREFIX_PATH": "${sourceDir}/build/" + } }, { "name": "ci-ninja", @@ -60,6 +62,7 @@ "name": "ci-ninja-release", "displayName": "Ninja Release", "inherits": [ + "clang-tidy-env", "ci-ninja" ], "cacheVariables": { From d170720e54e0adc56e06e35e8799d2a1a2131743 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 27 Oct 2023 22:12:27 +0200 Subject: [PATCH 5/8] Remove trailing spaces on yml files --- .github/workflows/benchmark.yml | 1 - .github/workflows/ci.yml | 15 +++++++-------- .github/workflows/codeql.yml | 2 +- CMakePresets.json | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 7c99dbab..be114884 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -17,7 +17,6 @@ jobs: - name: Build and run benchmarks with Catch2 run: | - conan install . --output-folder=build --build=missing --settings=build_type=Release cmake --preset=ci-ninja-release cmake --build build --target SI_unit_benchmarks diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c39463e..75c9c813 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: name: [ubuntu-gcc-9, ubuntu-clang-12, macos-apple-clang-11, windows-msvc-19] @@ -37,7 +37,7 @@ jobs: os: windows-2019 configure-preset: "ci-windows-msvc2019" build-preset: "ci-msvc2019-debug" - + steps: - uses: actions/checkout@v2 @@ -46,7 +46,7 @@ jobs: run: | sudo apt install shunit2 ninja-build python3-setuptools python3-pip -y sudo pip3 install conan - + - name: dependencies (macos) if: runner.os == 'macOS' @@ -59,7 +59,7 @@ jobs: pip install conan curl -L0 https://github.com/kward/shunit2/archive/v2.1.7.zip --output shunit2.zip unzip -j -n shunit2.zip - + - name: set-compiler-env run: | if [ "${{ matrix.compiler }}" != "" ]; then @@ -86,16 +86,15 @@ jobs: else cmake --preset=ci-ninja-debug fi - + shell: bash - + - name: build-debug run: | - if [ "${{ matrix.build-preset }}" != "" ]; then cmake --build ./build --preset=${{ matrix.build-preset }} else - cmake --build ./build + cmake --build ./build fi shell: bash diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f7f169e6..4bab0ef8 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -46,7 +46,7 @@ jobs: - name: build run: | cmake --preset ci-ninja-debug - cmake --build build + cmake --build build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/CMakePresets.json b/CMakePresets.json index 66e0735d..4bb625fe 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -73,7 +73,6 @@ "name": "ci-windows-msvc2019", "displayName": "MSVC 2019", "generator": "Visual Studio 16 2019", - "binaryDir": "${sourceDir}/build", "inherits": [ "conan-module-path" ], From c6268cbbedd79d27d2cc741e35723d902fa200b9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 28 Oct 2023 14:37:11 +0200 Subject: [PATCH 6/8] Use g++-11 on CI and C++17 std --- .github/workflows/api-doc.yml | 2 +- .github/workflows/benchmark.yml | 2 +- .github/workflows/ci.yml | 12 +++++------- CMakeLists.txt | 21 ++++++++++----------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/api-doc.yml b/.github/workflows/api-doc.yml index c6d56e7c..5135bb9d 100644 --- a/.github/workflows/api-doc.yml +++ b/.github/workflows/api-doc.yml @@ -7,7 +7,7 @@ jobs: name: generate-doxygen runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: install dependencies run: | sudo apt install doxygen graphviz diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index be114884..1aae3971 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -7,7 +7,7 @@ jobs: name: Run SI benchmarks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: install dependencies run: | sudo -H pip3 install setuptools wheel diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75c9c813..dadd939a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,12 +15,12 @@ jobs: fail-fast: false matrix: name: - [ubuntu-gcc-9, ubuntu-clang-12, macos-apple-clang-11, windows-msvc-19] + [ubuntu-gcc-11, ubuntu-clang-12, macos-apple-clang-11, windows-msvc-19] include: - - name: ubuntu-gcc-9 + - name: ubuntu-gcc-11 os: ubuntu-22.04 compiler: g++ - compiler-version: 9 + compiler-version: 11 compiler-name-conan: gcc - name: ubuntu-clang-12 @@ -32,15 +32,13 @@ jobs: - name: macos-apple-clang-11 os: macos-11 - - name: windows-msvc-19 os: windows-2019 configure-preset: "ci-windows-msvc2019" build-preset: "ci-msvc2019-debug" - steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: dependencies (Linux) if: runner.os == 'Linux' run: | @@ -120,7 +118,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 95a9a0c6..77313471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,10 @@ cmake_minimum_required(VERSION 3.23...3.27) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +endif() + project( "SI" VERSION 2.5.3 @@ -11,26 +16,20 @@ project( include(GNUInstallDirs) include(CTest) -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - set(IS_TOPLEVEL_PROJECT TRUE) -else() - set(IS_TOPLEVEL_PROJECT FALSE) -endif() - option(SI_INSTALL_LIBRARY "Enable installing of SI library into default locations" - ${IS_TOPLEVEL_PROJECT}) -option(SI_BUILD_TESTING "Build and run SI tests " ${IS_TOPLEVEL_PROJECT}) -option(SI_BUILD_DOC "Generate SI documentation" ${IS_TOPLEVEL_PROJECT}) + ${PROJECT_IS_TOP_LEVEL}) +option(SI_BUILD_TESTING "Build and run SI tests " ${PROJECT_IS_TOP_LEVEL}) +option(SI_BUILD_DOC "Generate SI documentation" ${PROJECT_IS_TOP_LEVEL}) # Only search for Catch2 if we're doing testing # (this reduces the amount of warnings when added via FetchContent or git submodules) if(SI_BUILD_TESTING) find_package(Catch2) - if (NOT Catch2_FOUND) + if(NOT Catch2_FOUND) message(WARNING "Catch2 not found, not building tests") set(SI_BUILD_TESTING OFF) - endif () + endif() endif() add_library(SI INTERFACE) From d7cdc450db8a2d93a04d5ccea2c11a5d316fd5ce Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 29 Oct 2023 14:59:52 +0100 Subject: [PATCH 7/8] Use mcaos-latest on CI --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dadd939a..442cd814 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: name: - [ubuntu-gcc-11, ubuntu-clang-12, macos-apple-clang-11, windows-msvc-19] + [ubuntu-gcc-11, ubuntu-clang-13, macos-apple-clang, windows-msvc-19] include: - name: ubuntu-gcc-11 os: ubuntu-22.04 @@ -23,14 +23,14 @@ jobs: compiler-version: 11 compiler-name-conan: gcc - - name: ubuntu-clang-12 + - name: ubuntu-clang-13 os: ubuntu-22.04 compiler: clang++ - compiler-version: "12" + compiler-version: "13" compiler-name-conan: clang - - name: macos-apple-clang-11 - os: macos-11 + - name: macos-apple-clang + os: macos-latest - name: windows-msvc-19 os: windows-2019 From f198742472029edb715a99dcd7b8737cb295aee2 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 30 Oct 2023 09:37:36 +0100 Subject: [PATCH 8/8] Prevent build errors on CI Quickfix for OSX CI build problems. Prevent to build ctests while version-consistency tests. --- .github/workflows/ci.yml | 8 ++++++-- CMakeLists.txt | 5 +++-- test/compilation-tests.sh | 20 ++++++++++---------- test/installation-tests.sh | 24 ++++++++++++------------ test/version-consistency.sh | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 442cd814..13b00d01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - name: macos-apple-clang os: macos-latest + compiler-cppstd: "gnu17" - name: windows-msvc-19 os: windows-2019 @@ -69,10 +70,13 @@ jobs: run: | conan profile detect --force if [ "${{ matrix.compiler-name-conan }}" != "" ]; then - sed -i 's/compiler=.*/compiler=${{ matrix.compiler-name-conan }}/g' ~/.conan2/profiles/default + sed -i.bak -e 's/compiler=.*/compiler=${{ matrix.compiler-name-conan }}/g' ~/.conan2/profiles/default fi if [ "${{ matrix.compiler-version }}" != "" ]; then - sed -i 's/compiler.version=[0-9]\+/compiler.version=${{ matrix.compiler-version }}/g' ~/.conan2/profiles/default + sed -i.bak -e 's/compiler.version=[0-9]\+/compiler.version=${{ matrix.compiler-version }}/g' ~/.conan2/profiles/default + fi + if [ "${{ matrix.compiler-cppstd }}" != "" ]; then + sed -i.bak -e 's/compiler.cppstd=gnu[0-9]\+/compiler.cppstd=${{ matrix.compiler-cppstd }}/g' ~/.conan2/profiles/default fi shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index 77313471..5faa0b8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,6 @@ project( LANGUAGES CXX) include(GNUInstallDirs) -include(CTest) option(SI_INSTALL_LIBRARY "Enable installing of SI library into default locations" @@ -44,7 +43,9 @@ target_include_directories( target_compile_features(SI INTERFACE cxx_std_17) -if(BUILD_TESTING AND SI_BUILD_TESTING) +if(SI_BUILD_TESTING) + enable_testing() + include(Catch) add_subdirectory(test) endif() diff --git a/test/compilation-tests.sh b/test/compilation-tests.sh index 41cf08f1..6c036394 100755 --- a/test/compilation-tests.sh +++ b/test/compilation-tests.sh @@ -10,15 +10,15 @@ buildSingleTarget() if [ "${2}" == "DEFAULTBUILD" ]; then cmake ${ROOT_DIR}/test/src/compilation_tests/ -B${BUILD_DIR} -DCMAKE_PREFIX_PATH=${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=Release -G Ninja > /dev/null assertEquals "Configuration successful" 0 $? - + else cmake ${ROOT_DIR}/test/src/compilation_tests/ -B${BUILD_DIR} -DCMAKE_PREFIX_PATH=${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-DSI_DISABLE_IMPLICIT_RATIO_CONVERSION" -G Ninja > /dev/null assertEquals "Configuration successful" 0 $? fi - + cmake --build ${BUILD_DIR} --config Release --target $1 > /dev/null RESULT=$? - + if [ "${3}" == "PASS" ]; then assertEquals "Building successful" 0 $RESULT else @@ -27,14 +27,14 @@ buildSingleTarget() } oneTimeSetUp(){ - + BUILD_DIR=$(mktemp -d) conan install . --output-folder=${BUILD_DIR} --build=missing --settings=build_type=Release 2>&1> /dev/null - + # install SI - cmake ${ROOT_DIR} -B${BUILD_DIR} -DCMAKE_PREFIX_PATH=${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DBUILD_TESTING=off -DCMAKE_BUILD_TYPE=Release -G Ninja > /dev/null + cmake ${ROOT_DIR} -B${BUILD_DIR} -DCMAKE_PREFIX_PATH=${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DSI_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja > /dev/null cmake --build ${BUILD_DIR} --config Release --target install > /dev/null - + if [ -d ${BUILD_DIR} ]; then rm -rf ${BUILD_DIR} fi @@ -52,7 +52,7 @@ tearDown(){ } testSISelfSuccessfulCompilationWhenDefaultInvocation() { - + cmake ${ROOT_DIR} -B${BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${BUILD_DIR} -G Ninja > /dev/null assertEquals "Configuration successful" 0 $? cmake --build ${BUILD_DIR} --config Release > /dev/null @@ -60,7 +60,7 @@ testSISelfSuccessfulCompilationWhenDefaultInvocation() { } testSISelfFailedCompilationWhenImplicitConversionDisabled() { - + cmake ${ROOT_DIR} -B${BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${BUILD_DIR} -DCMAKE_CXX_FLAGS="-DSI_DISABLE_IMPLICIT_RATIO_CONVERSION" -G Ninja > /dev/null assertEquals "Configuration successful" 0 $? cmake --build ${BUILD_DIR} --config Release @@ -347,4 +347,4 @@ testCompilationSucceedsWhenNumberParserDoesNotOverflow() # Load shUnit2. -. shunit2 \ No newline at end of file +. shunit2 diff --git a/test/installation-tests.sh b/test/installation-tests.sh index 2cc4d551..5ed4deeb 100755 --- a/test/installation-tests.sh +++ b/test/installation-tests.sh @@ -17,11 +17,11 @@ tearDown() { if [ -d ${SI_BUILD_DIR} ]; then rm -rf ${SI_BUILD_DIR} fi - + if [ -d ${INSTALL_PATH} ]; then rm -rf ${INSTALL_PATH} fi - + if [ -d ${BUILD_DIR} ]; then rm -rf ${BUILD_DIR} fi @@ -29,30 +29,30 @@ tearDown() { testPureCmakeInstallation() { # install SI - cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DBUILD_TESTING=off -DCMAKE_BUILD_TYPE=Release + cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DSI_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release cmake --build ${SI_BUILD_DIR} --config Release --target install assertEquals "Installation build successful" 0 $? cmake ${ROOT_DIR}/test/installation-tests -B${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} cmake --build ${BUILD_DIR} assertEquals "build against installation successful" 0 $? - + } testPureCmakeInstallationWithInstallOptionTurnedOff() { # install SI - cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DBUILD_TESTING=off -DSI_INSTALL_LIBRARY=OFF -DCMAKE_BUILD_TYPE=Release + cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} -DSI_BUILD_TESTING=OFF -DSI_INSTALL_LIBRARY=OFF -DCMAKE_BUILD_TYPE=Release cmake --build ${SI_BUILD_DIR} --config Release --target install assertNotEquals "Installation build successful" 0 $? - + DIRECTORY_CONTENTS=$(ls -A ${INSTALL_PATH}) EMPTY="" assertEquals "Installation directory is empty" "${EMPTY}" "${DIRECTORY_CONTENTS}" - + } testCpackInstallation() { # install SI - cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCPACK_PACKAGE_FILE_NAME=install-SI -DBUILD_TESTING=off -DCMAKE_BUILD_TYPE=Release + cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DCPACK_PACKAGE_FILE_NAME=install-SI -DSI_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release cmake --build ${SI_BUILD_DIR} --config Release --target package assertEquals "Installation build successful" 0 $? if [ "${OS_NAME}" = "Linux" ] || [ "${OS_NAME}" = "Darwin" ]; then @@ -63,13 +63,13 @@ testCpackInstallation() { # echo "done" return fi - + assertEquals "Installation script successful" 0 $? - + cmake ${ROOT_DIR}/test/installation-tests -B${BUILD_DIR} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} cmake --build ${BUILD_DIR} assertEquals "build against installation successful" 0 $? - + } @@ -78,7 +78,7 @@ testUsageAsSubdirectory() { cmake ${ROOT_DIR}/test/installation-test-subdirectory -B${BUILD_DIR} -DCMAKE_BUILD_TYPE=Release cmake --build ${BUILD_DIR} assertEquals "build against installation successful" 0 $? - + } # Load shUnit2. diff --git a/test/version-consistency.sh b/test/version-consistency.sh index 9e700013..1d6dce41 100755 --- a/test/version-consistency.sh +++ b/test/version-consistency.sh @@ -24,7 +24,7 @@ testVersionNumberConsistency() { CHANGELOG_VERSION=$(sed -n -E '/## [0-9]+\.[0-9]+\.[0-9]+/p' ${ROOT_DIR}/CHANGELOG.md | head -1 | grep -E -o '[0-9]+\.[0-9]+\.[0-9]+') ORIG_DIR=$(pwd) - cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DBUILD_TESTING=off -DCMAKE_BUILD_TYPE=Debug >/dev/null + cmake ${ROOT_DIR} -B${SI_BUILD_DIR} -DSI_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Debug >/dev/null cd ${SI_BUILD_DIR} CMAKE_VERSION=$(cmake --system-information | grep -E "VERSION:STATIC" | grep -E -o '[0-9]+\.[0-9]+\.[0-9]+') cd ${ORIG_DIR}