mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-21 11:01:20 +00:00
Merge pull request #25 from threeal/add-compiler-flags-input
Add Compiler Flags Input Options
This commit is contained in:
commit
5e43077b06
17
.github/workflows/test.yml
vendored
17
.github/workflows/test.yml
vendored
@ -39,6 +39,23 @@ jobs:
|
|||||||
- name: Check if the default build directory does not exist
|
- name: Check if the default build directory does not exist
|
||||||
run: test ! -d build
|
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:
|
specified-compiler-usage:
|
||||||
runs-on: ${{ matrix.os }}-latest
|
runs-on: ${{ matrix.os }}-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -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. |
|
| `generator` | String | Build system generator of the CMake project. |
|
||||||
| `c-compiler` | String | Preferred executable for compiling C language files. |
|
| `c-compiler` | String | Preferred executable for compiling C language files. |
|
||||||
| `cxx-compiler` | String | Preferred executable for compiling CXX 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. |
|
| `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
|
### Examples
|
||||||
|
12
action.yml
12
action.yml
@ -25,6 +25,12 @@ inputs:
|
|||||||
cxx-compiler:
|
cxx-compiler:
|
||||||
description: Preferred executable for compiling CXX language files
|
description: Preferred executable for compiling CXX language files
|
||||||
required: false
|
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:
|
args:
|
||||||
description: Additional arguments passed during the CMake configuration
|
description: Additional arguments passed during the CMake configuration
|
||||||
required: false
|
required: false
|
||||||
@ -49,6 +55,12 @@ runs:
|
|||||||
if [ -n '${{ inputs.cxx-compiler }}' ]; then
|
if [ -n '${{ inputs.cxx-compiler }}' ]; then
|
||||||
ARGS="$ARGS -D CMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }}"
|
ARGS="$ARGS -D CMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }}"
|
||||||
fi
|
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
|
if [ -n '${{ inputs.args }}' ]; then
|
||||||
ARGS="$ARGS ${{ inputs.args }}"
|
ARGS="$ARGS ${{ inputs.args }}"
|
||||||
fi
|
fi
|
||||||
|
@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
project(test)
|
project(test)
|
||||||
|
|
||||||
option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF)
|
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)
|
add_executable(hello_world hello_world.cpp)
|
||||||
|
|
||||||
@ -13,5 +19,6 @@ foreach(LANG ${LANGS})
|
|||||||
test_${LANG} PRIVATE
|
test_${LANG} PRIVATE
|
||||||
$<$<STREQUAL:"${LANG}","c">:IS_C>
|
$<$<STREQUAL:"${LANG}","c">:IS_C>
|
||||||
$<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
|
$<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
|
||||||
|
$<$<BOOL:${CHECK_SURPASS_WARNING}>:CHECK_SURPASS_WARNING>
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifdef CHECK_SURPASS_WARNING
|
||||||
|
int unused;
|
||||||
|
#endif
|
||||||
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
|
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
|
||||||
PRINT("compiler is not clang");
|
PRINT("compiler is not clang");
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user