Skip to content

Commit

Permalink
Add BUILD_WERROR option
Browse files Browse the repository at this point in the history
Adds a cmake BUILD_WERROR option to enable warnings as errors. This
option is off by default.

This change also cleans up a few more compiler warnings.
  • Loading branch information
ncesario-lunarg authored and arcady-lunarg committed Nov 29, 2023
1 parent 719b6b7 commit 3f615ad
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
key: ubuntu-22-${{ matrix.cmake_build_type }}-${{ matrix.compiler.cc }}-${{matrix.compiler.cxx}}
- run: ./update_glslang_sources.py
- name: Configure
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_WERROR=ON
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: lukka/get-cmake@8be6cca406b575906541e8e3b885d46f416bba39 # v3.27.7
- run: ./update_glslang_sources.py
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja
- run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -G Ninja -DBUILD_WERROR=ON
env:
CC: ${{matrix.compiler.cc}}
CXX: ${{matrix.compiler.cxx}}
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
- run: python update_glslang_sources.py
- name: Build
run: |
cmake -S. -Bbuild -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="$PWD/build/install"
cmake -S. -Bbuild -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX="$PWD/build/install" -DBUILD_WERROR=ON
cmake --build build --config ${{matrix.cmake_build_type}} --target install
- name: Test
run: ctest -C ${{matrix.cmake_build_type}} --output-on-failure --test-dir build
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ include(CMakeDependentOption)

option(BUILD_SHARED_LIBS "Build Shared Libraries")
option(BUILD_EXTERNAL "Build external dependencies in /External" ON)
option(BUILD_WERROR "Enable warnings as errors (default is OFF)" OFF)

set(LIB_TYPE STATIC)

Expand Down Expand Up @@ -177,6 +178,15 @@ elseif(MSVC)
endif()
endif()

# NOTE we could potentially replace this logic with COMPILE_WARNING_AS_ERROR if cmake minimum is bumped to >= 3.24
if (BUILD_WERROR)
if (NOT MSVC)
add_compile_options(-Werror)
else()
add_compile_options(/WX)
endif()
endif()

if(ENABLE_GLSLANG_JS)
if(MSVC)
add_compile_options(/Os /GR-)
Expand Down
8 changes: 4 additions & 4 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7458,7 +7458,7 @@ static void ForEachOpaque(const TType& type, const TString& path, Function callb
++flatIndex)
{
TString subscriptPath = path;
for (int dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
for (size_t dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
{
int index = indices[dimIndex];
subscriptPath.append("[");
Expand All @@ -7468,7 +7468,7 @@ static void ForEachOpaque(const TType& type, const TString& path, Function callb

recursion(type, subscriptPath, true, recursion);

for (int dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
for (size_t dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
{
++indices[dimIndex];
if (indices[dimIndex] < type.getArraySizes()->getDimSize(dimIndex))
Expand Down Expand Up @@ -7537,7 +7537,7 @@ void TParseContext::vkRelaxedRemapUniformMembers(const TSourceLoc& loc, const TP
});
}

void TParseContext::vkRelaxedRemapFunctionParameter(const TSourceLoc& loc, TFunction* function, TParameter& param, std::vector<int>* newParams)
void TParseContext::vkRelaxedRemapFunctionParameter(TFunction* function, TParameter& param, std::vector<int>* newParams)
{
function->addParameter(param);

Expand Down Expand Up @@ -7615,7 +7615,7 @@ TIntermNode* TParseContext::vkRelaxedRemapFunctionArgument(const TSourceLoc& loc
param.type->shallowCopy(intermTyped->getType());

std::vector<int> newParams = {};
vkRelaxedRemapFunctionParameter(loc, function, param, &newParams);
vkRelaxedRemapFunctionParameter(function, param, &newParams);

if (intermTyped->getType().isOpaque())
{
Expand Down
2 changes: 1 addition & 1 deletion glslang/MachineIndependent/ParseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class TParseContext : public TParseContextBase {
// returns true if the variable was remapped to something else
bool vkRelaxedRemapUniformVariable(const TSourceLoc&, TString&, const TPublicType&, TArraySizes*, TIntermTyped*, TType&);
void vkRelaxedRemapUniformMembers(const TSourceLoc&, const TPublicType&, const TType&, const TString&);
void vkRelaxedRemapFunctionParameter(const TSourceLoc&, TFunction*, TParameter&, std::vector<int>* newParams = nullptr);
void vkRelaxedRemapFunctionParameter(TFunction*, TParameter&, std::vector<int>* newParams = nullptr);
TIntermNode* vkRelaxedRemapFunctionArgument(const TSourceLoc&, TFunction*, TIntermTyped*);
TIntermTyped* vkRelaxedRemapDotDereference(const TSourceLoc&, TIntermTyped&, const TType&, const TString&);

Expand Down
4 changes: 2 additions & 2 deletions glslang/MachineIndependent/glslang.y
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ function_header_with_parameters
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
$1->addParameter($2.param);
else
parseContext.vkRelaxedRemapFunctionParameter($2.loc, $1, $2.param);
parseContext.vkRelaxedRemapFunctionParameter($1, $2.param);
}
else
delete $2.param.type;
Expand All @@ -1029,7 +1029,7 @@ function_header_with_parameters
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
$1->addParameter($3.param);
else
parseContext.vkRelaxedRemapFunctionParameter($3.loc, $1, $3.param);
parseContext.vkRelaxedRemapFunctionParameter($1, $3.param);
}
}
;
Expand Down
4 changes: 2 additions & 2 deletions glslang/MachineIndependent/glslang_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6319,7 +6319,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
(yyvsp[-1].interm.function)->addParameter((yyvsp[0].interm).param);
else
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[0].interm).loc, (yyvsp[-1].interm.function), (yyvsp[0].interm).param);
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[-1].interm.function), (yyvsp[0].interm).param);
}
else
delete (yyvsp[0].interm).param.type;
Expand All @@ -6346,7 +6346,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
(yyvsp[-2].interm.function)->addParameter((yyvsp[0].interm).param);
else
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[0].interm).loc, (yyvsp[-2].interm.function), (yyvsp[0].interm).param);
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[-2].interm.function), (yyvsp[0].interm).param);
}
}
#line 6353 "MachineIndependent/glslang_tab.cpp"
Expand Down

0 comments on commit 3f615ad

Please sign in to comment.