diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4cb86d..2c15084 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,23 @@ jobs: - name: Check if the default build directory does not exist run: test ! -d build + additional-flags-usage: + runs-on: ubuntu-latest + steps: + - name: Check out this repository + uses: actions/checkout@v3.3.0 + + - name: Use this action with additional compiler flags + uses: ./ + with: + source-dir: test + targets: test_c test_cpp + c-flags: -Wno-unused-variable + cxx-flags: -Wno-unused-variable + + - name: Run the build results + run: build/test_c && build/test_cpp + specified-compiler-usage: runs-on: ${{ matrix.os }}-latest strategy: diff --git a/README.md b/README.md index 8e3bbb6..1941a7e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ For more information, see [action.yml](./action.yml) and [GitHub Actions guide]( | `generator` | String | Build system generator of the CMake project. | | `c-compiler` | String | Preferred executable for compiling C language files. | | `cxx-compiler` | String | Preferred executable for compiling CXX language files. | +| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. Could be specified more than one. Separate each flag with a space or a new line. | +| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. Could be specified more than one. Separate each flag with a space or a new line. | | `args` | Multiple strings | Additional arguments passed during the CMake configuration. Could be specified more than one. Separate each target with a space or a new line. | ### Examples diff --git a/action.yml b/action.yml index f2e549a..35b63a4 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,12 @@ inputs: cxx-compiler: description: Preferred executable for compiling CXX language files required: false + c-flags: + description: Additional flags passed when compiling C language files + required: false + cxx-flags: + description: Additional flags passed when compiling C++ language files + required: false args: description: Additional arguments passed during the CMake configuration required: false @@ -49,6 +55,12 @@ runs: if [ -n '${{ inputs.cxx-compiler }}' ]; then ARGS="$ARGS -D CMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }}" fi + if [ -n '${{ inputs.c-flags }}' ]; then + ARGS="$ARGS -D CMAKE_C_FLAGS=${{ inputs.c-flags }}" + fi + if [ -n '${{ inputs.cxx-flags }}' ]; then + ARGS="$ARGS -D CMAKE_CXX_FLAGS=${{ inputs.cxx-flags }}" + fi if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1e108b3..434f472 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.0) project(test) option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) +option(CHECK_SURPASS_WARNING "check if target could surpass a compiler warning" OFF) + +if(CHECK_SURPASS_WARNING) + set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}") +endif() add_executable(hello_world hello_world.cpp) @@ -13,5 +19,6 @@ foreach(LANG ${LANGS}) test_${LANG} PRIVATE $<$:IS_C> $<$:CHECK_USING_CLANG> + $<$:CHECK_SURPASS_WARNING> ) endforeach() diff --git a/test/test.in b/test/test.in index 6a4eb5f..4098a34 100644 --- a/test/test.in +++ b/test/test.in @@ -7,6 +7,9 @@ #endif int main() { +#ifdef CHECK_SURPASS_WARNING + int unused; +#endif #if defined(CHECK_USING_CLANG) && !defined(__clang__) PRINT("compiler is not clang"); return 1;