Merge pull request #30 from threeal/fix-msvc-flags

Fix MSVC Flags
This commit is contained in:
Alfi Maulana 2023-01-17 13:16:25 +07:00 committed by GitHub
commit 8580c9d7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 15 deletions

View File

@ -40,7 +40,10 @@ jobs:
run: test ! -d build
additional-flags-usage:
runs-on: ubuntu-latest
runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest
strategy:
matrix:
compiler: [gcc, msvc]
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
@ -50,11 +53,14 @@ jobs:
with:
source-dir: test
targets: test_c test_cpp
c-flags: -Wno-unused-variable
cxx-flags: -Wno-unused-variable
c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
args: -D CHECK_SURPASS_WARNING=ON
- name: Run the build results
run: build/test_c && build/test_cpp
run: |
${{ matrix.compiler == 'msvc' && 'build\Debug\test_c.exe' || 'build/test_c' }}
${{ matrix.compiler == 'msvc' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }}
specified-compiler-usage:
runs-on: ${{ matrix.os }}-latest

View File

@ -41,25 +41,25 @@ runs:
id: process_inputs
shell: bash
run: |
ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}"
BUILD_ARGS="--build ${{ inputs.build-dir }}"
ARGS="'${{ inputs.source-dir }}' -B '${{ inputs.build-dir }}'"
BUILD_ARGS="--build '${{ inputs.build-dir }}'"
if [ -n '${{ inputs.targets }}' ]; then
BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}"
fi
if [ -n '${{ inputs.generator }}' ]; then
ARGS="$ARGS -G ${{ inputs.generator }}"
ARGS="$ARGS -G '${{ inputs.generator }}'"
fi
if [ -n '${{ inputs.c-compiler }}' ]; then
ARGS="$ARGS -D CMAKE_C_COMPILER=${{ inputs.c-compiler }}"
ARGS="$ARGS -D CMAKE_C_COMPILER='${{ inputs.c-compiler }}'"
fi
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
if [ -n '${{ inputs.c-flags }}' ]; then
ARGS="$ARGS -D CMAKE_C_FLAGS=${{ inputs.c-flags }}"
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 }}"
ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'"
fi
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
@ -78,9 +78,9 @@ runs:
esac
- name: Configure the CMake project
shell: bash
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
- name: Build targets
shell: bash
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}

View File

@ -5,9 +5,14 @@ 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)
if(MSVC)
set(CMAKE_C_FLAGS "/WX /W4 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "/WX /W4 ${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}")
endif()
endif()
add_executable(hello_world hello_world.cpp)