From 11ab5771ea032a92114059b487dd5aad5a0333aa Mon Sep 17 00:00:00 2001 From: trinitou Date: Wed, 10 Jan 2024 08:05:51 +0100 Subject: [PATCH 1/3] Add github format and code checks --- .github/workflows/code-checks.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/code-checks.yml diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml new file mode 100644 index 0000000..d6e1d8f --- /dev/null +++ b/.github/workflows/code-checks.yml @@ -0,0 +1,18 @@ +name: Clap Helpers Format and Code Checks +on: [pull_request] +jobs: + formatting-check: + name: Clang Format Check + runs-on: ubuntu-latest + strategy: + matrix: + path: + - 'src' + - 'include' + steps: + - uses: actions/checkout@v3 + - name: Run clang-format style check + uses: jidicula/clang-format-action@v4.11.0 + with: + clang-format-version: '17' + check-path: ${{ matrix.path }} From 6f9636a41d638ece83825e2ff8735f28a9468dee Mon Sep 17 00:00:00 2001 From: trinitou Date: Sat, 13 Jan 2024 06:06:33 +0100 Subject: [PATCH 2/3] Add github test job --- .github/workflows/pullreq.yml | 94 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + CMakeLists.txt | 72 ++++++++++++++++++++++----- cmake/external/CPM.cmake | 24 +++++++++ 4 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/pullreq.yml create mode 100644 .gitignore create mode 100644 cmake/external/CPM.cmake diff --git a/.github/workflows/pullreq.yml b/.github/workflows/pullreq.yml new file mode 100644 index 0000000..8a2bdb6 --- /dev/null +++ b/.github/workflows/pullreq.yml @@ -0,0 +1,94 @@ +name: Pull Request Validation + +on: + pull_request: + branches: + - main + - next + +jobs: + buidl_and_run_tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: windows-latest + cmakeargs: -A x64 + install_ninja: false + name: Windows 64bit MSVC + + - os: windows-latest + cmakeargs: -A x64 -DCLAP_HELPERS_TESTS_CXX_STANDARD=20 + install_ninja: false + name: Windows 64bit C++20 MSVC + + - os: windows-latest + cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc + install_ninja: true + name: Windows gcc/minGW + + - os: windows-latest + cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang + install_ninja: true + name: Windows clang + + - os: ubuntu-latest + cmakeargs: -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11 + install_ninja: false + name: Linux gcc11 + + - os: ubuntu-latest + cmakeargs: -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 + install_ninja: false + name: Linux gcc12 + + - os: ubuntu-latest + cmakeargs: -DCLAP_HELPERS_TESTS_CXX_STANDARD=20 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 + install_ninja: false + name: Linux gcc12 C++20 + + - os: ubuntu-latest + cmakeargs: -DCLAP_HELPERS_TESTS_CXX_STANDARD=23 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 + install_ninja: false + name: Linux gcc12 C++23 + + - os: macos-latest + cmakeargs: -GNinja + install_ninja: true + name: MacOS Ninja + + - os: macos-latest + cmakeargs: -G"Xcode" + install_ninja: false + name: MacOS Xcode + + - os: macos-latest + cmakeargs: -G"Ninja Multi-Config" -DCLAP_HELPERS_TESTS_CXX_STANDARD=20 + install_ninja: true + name: MacOS Ninja Multi C++20 + + - os: macos-latest + cmakeargs: -G"Unix Makefiles" + install_ninja: false + name: MacOS Unix Makefiles + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install Ninja + if: ${{ matrix.install_ninja }} + uses: seanmiddleditch/gha-setup-ninja@master + + - name: Build project + run: | + cmake -S . -B ./build ${{ matrix.cmakeargs }} -DCMAKE_BUILD_TYPE=Debug -DCLAP_HELPERS_TESTS_ONLY=TRUE + cmake --build ./build --config Debug + + - name: Run Tests + shell: bash + run: | + todo run tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0069898..d26a916 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,57 @@ cmake_minimum_required(VERSION 3.17) cmake_policy(SET CMP0100 NEW) # handle .hh files project(CLAP_HELPERS C CXX) +set(add_tests ${CLAP_BUILD_TESTS}) +set(add_tests_to_clap_tests TRUE) +set(skip_install FALSE) +set(tests_cxx_standard 11) +set(download_packages FALSE) +# define special handling for CLAP_HELPERS_TESTS_ONLY: +if (${CLAP_HELPERS_TESTS_ONLY}) + set(add_tests TRUE) + set(add_tests_to_clap_tests FALSE) + set(skip_install TRUE) + if (DEFINED CLAP_HELPERS_TESTS_CXX_STANDARD) + set(tests_cxx_standard ${CLAP_HELPERS_TESTS_CXX_STANDARD}) + else() + set(tests_cxx_standard 17) + endif() + message(STATUS "clap-helpers-tests: including CPM") + include(cmake/external/CPM.cmake) + set(download_packages TRUE) +endif() + add_library(clap-helpers INTERFACE) target_include_directories(clap-helpers SYSTEM INTERFACE include) -target_link_libraries(clap-helpers INTERFACE clap) +if (${download_packages}) + CPMAddPackage( + NAME "clap" + GITHUB_REPOSITORY "free-audio/clap" + GIT_TAG "1.1.10" + EXCLUDE_FROM_ALL TRUE + DOWNLOAD_ONLY TRUE + SOURCE_DIR cpm/clap + ) + find_package(clap QUIET) +else() + target_link_libraries(clap-helpers INTERFACE clap) +endif() -# CLAP_BUILD_TESTS is inherited from clap -if (${CLAP_BUILD_TESTS}) - enable_testing() +if (${add_tests}) + if(${add_tests_to_clap_tests}) + enable_testing() + endif() + if (${download_packages}) + CPMAddPackage( + NAME "Catch2" + GITHUB_REPOSITORY "catchorg/Catch2" + GIT_TAG "v3.5.1" + EXCLUDE_FROM_ALL TRUE + DOWNLOAD_ONLY TRUE + SOURCE_DIR cpm/catch2 + ) + endif() find_package(Catch2 3 QUIET) - if (Catch2_FOUND) add_executable(clap-helpers-tests EXCLUDE_FROM_ALL tests/hex-encoder.cc @@ -20,16 +62,22 @@ if (${CLAP_BUILD_TESTS}) tests/main.cc tests/preset-discovery-indexer.cc tests/preset-discovery-provider.cc - tests/preset-discovery-metadata-receiver.cc) - set_target_properties(clap-helpers-tests PROPERTIES CXX_STANDARD 11) + tests/preset-discovery-metadata-receiver.cc + ) + set_target_properties(clap-helpers-tests PROPERTIES CXX_STANDARD ${tests_cxx_standard}) + target_include_directories(clap-helpers-tests SYSTEM INTERFACE include) target_link_libraries(clap-helpers-tests clap-helpers clap Catch2::Catch2WithMain) target_compile_definitions(clap-helpers-tests PUBLIC -DCATCH_CONFIG_PREFIX_ALL) - add_test(NAME test-clap-helpers COMMAND clap-helpers-tests) - add_dependencies(clap-tests clap-helpers-tests) + if(${add_tests_to_clap_tests}) + add_test(NAME test-clap-helpers COMMAND clap-helpers-tests) + add_dependencies(clap-helpers clap-helpers-tests) + endif() else() - message(STATUS "Catch2 >= 3 isn't found -> disable clap-helpers unit tests") + message(STATUS "clap-helpers: Catch2 >= 3 isn't found -> disable unit tests") endif() endif() -install(DIRECTORY include DESTINATION ".") -install(FILES "cmake/clap-helpers-config.cmake" DESTINATION "./lib/cmake/clap-helpers") +if (NOT ${skip_install}) + install(DIRECTORY include DESTINATION ".") + install(FILES "cmake/clap-helpers-config.cmake" DESTINATION "./lib/cmake/clap-helpers") +endif() diff --git a/cmake/external/CPM.cmake b/cmake/external/CPM.cmake new file mode 100644 index 0000000..ad6b74a --- /dev/null +++ b/cmake/external/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.38.6) +set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) From 8bd532049b8cb42d747cb3c950f47449329176de Mon Sep 17 00:00:00 2001 From: trinitou Date: Mon, 15 Jan 2024 22:02:31 +0100 Subject: [PATCH 3/3] Correct path for format & code checks --- .github/workflows/code-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index d6e1d8f..d1af5eb 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: path: - - 'src' + - 'tests' - 'include' steps: - uses: actions/checkout@v3