mirror of
				https://github.com/threeal/cmake-action.git
				synced 2025-11-03 21:33:42 +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
 | 
			
		||||
        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:
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
    $<$<STREQUAL:"${LANG}","c">:IS_C>
 | 
			
		||||
    $<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
 | 
			
		||||
    $<$<BOOL:${CHECK_SURPASS_WARNING}>:CHECK_SURPASS_WARNING>
 | 
			
		||||
  )
 | 
			
		||||
endforeach()
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user