Skip to content

Commit 8837f91

Browse files
authored
Make -Werror and /WX optional (#569)
1 parent bb89ab4 commit 8837f91

File tree

4 files changed

+68
-40
lines changed

4 files changed

+68
-40
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ option(ASTCENC_UNITTEST "Enable astcenc builds with unit tests")
5353
option(ASTCENC_INVARIANCE "Enable astcenc floating point invariance" ON)
5454
option(ASTCENC_CLI "Enable build of astcenc command line tools" ON)
5555
option(ASTCENC_X86_GATHERS "Enable use of native x86 gathers" ON)
56+
option(ASTCENC_WERROR "Force builds to treat warnings as errors" ON)
5657

5758
# Preflight for some macOS-specific build options
5859
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")

Source/UnitTest/cmake_core.cmake

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# under the License.
1616
# ----------------------------------------------------------------------------
1717

18+
include(../cmake_compiler.cmake)
19+
1820
set(ASTCENC_TEST test-unit-${ASTCENC_ISA_SIMD})
1921

2022
add_executable(${ASTCENC_TEST})
@@ -57,27 +59,34 @@ target_compile_options(${ASTCENC_TEST}
5759
$<$<PLATFORM_ID:Linux,Darwin>:-pthread>
5860

5961
# MSVC compiler defines
60-
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
62+
$<${is_msvc_fe}:/EHsc>
63+
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_msvc_fe}>:/WX>
64+
$<${is_msvccl}:/wd4324>
6165

6266
# G++ and Clang++ compiler defines
63-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall>
64-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wextra>
65-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wpedantic>
66-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
67-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wshadow>
68-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-compat-pedantic>
69-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-c++11-compat-pedantic>
70-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-float-equal>
71-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-overriding-option>
72-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unsafe-buffer-usage>
73-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-switch-default>
67+
$<${is_gnu_fe}:-Wall>
68+
$<${is_gnu_fe}:-Wextra>
69+
$<${is_gnu_fe}:-Wpedantic>
70+
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_gnu_fe}>:-Werror>
71+
$<${is_gnu_fe}:-Wshadow>
72+
$<${is_gnu_fe}:-Wdouble-promotion>
73+
$<${is_clang}:-Wdocumentation>
74+
75+
# Hide noise thrown up by Clang 10 and clang-cl
76+
$<${is_gnu_fe}:-Wno-unknown-warning-option>
77+
$<${is_gnu_fe}:-Wno-c++98-compat-pedantic>
78+
$<${is_gnu_fe}:-Wno-c++98-c++11-compat-pedantic>
79+
$<${is_gnu_fe}:-Wno-float-equal>
80+
$<${is_gnu_fe}:-Wno-overriding-option>
81+
$<${is_gnu_fe}:-Wno-unsafe-buffer-usage>
82+
$<${is_clang}:-Wno-switch-default>
7483

7584
# Ignore things that the googletest build triggers
76-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unknown-warning-option>
77-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-double-promotion>
78-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-undef>
79-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-reserved-identifier>
80-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-global-constructors>)
85+
$<${is_gnu_fe}:-Wno-unknown-warning-option>
86+
$<${is_gnu_fe}:-Wno-double-promotion>
87+
$<${is_gnu_fe}:-Wno-undef>
88+
$<${is_gnu_fe}:-Wno-reserved-identifier>
89+
$<${is_gnu_fe}:-Wno-global-constructors>)
8190

8291
# Set up configuration for SIMD ISA builds
8392
if(${ASTCENC_ISA_SIMD} MATCHES "none")

Source/cmake_compiler.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# ----------------------------------------------------------------------------
3+
# Copyright 2020-2025 Arm Limited
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
# use this file except in compliance with the License. You may obtain a copy
7+
# of the License at:
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
# ----------------------------------------------------------------------------
17+
18+
# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set
19+
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
20+
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
21+
endif()
22+
23+
# Compiler accepts MSVC-style command line options
24+
set(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
25+
# Compiler accepts GNU-style command line options
26+
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
27+
# Compiler accepts AppleClang-style command line options, which is also GNU-style
28+
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
29+
# Compiler accepts GNU-style command line options
30+
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")
31+
32+
# Compiler is Visual Studio cl.exe
33+
set(is_msvccl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:MSVC>>")
34+
# Compiler is Visual Studio clangcl.exe
35+
set(is_clangcl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:Clang>>")
36+
# Compiler is upstream clang with the standard frontend
37+
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")

Source/cmake_core.cmake

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# ----------------------------------------------------------------------------
3-
# Copyright 2020-2024 Arm Limited
3+
# Copyright 2020-2025 Arm Limited
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
66
# use this file except in compliance with the License. You may obtain a copy
@@ -19,26 +19,7 @@ set(ASTCENC_TARGET astc${ASTCENC_CODEC}-${ASTCENC_ISA_SIMD})
1919

2020
project(${ASTCENC_TARGET})
2121

22-
# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set
23-
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
24-
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
25-
endif()
26-
27-
# Compiler accepts MSVC-style command line options
28-
set(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
29-
# Compiler accepts GNU-style command line options
30-
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
31-
# Compiler accepts AppleClang-style command line options, which is also GNU-style
32-
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
33-
# Compiler accepts GNU-style command line options
34-
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")
35-
36-
# Compiler is Visual Studio cl.exe
37-
set(is_msvccl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:MSVC>>")
38-
# Compiler is Visual Studio clangcl.exe
39-
set(is_clangcl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:Clang>>")
40-
# Compiler is upstream clang with the standard frontend
41-
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")
22+
include(cmake_compiler.cmake)
4223

4324
add_library(${ASTCENC_TARGET}-static
4425
STATIC
@@ -164,14 +145,14 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_VENEER_TYPE)
164145

165146
# MSVC compiler defines
166147
$<${is_msvc_fe}:/EHsc>
167-
$<${is_msvc_fe}:/WX>
148+
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_msvc_fe}>:/WX>
168149
$<${is_msvccl}:/wd4324>
169150

170151
# G++ and Clang++ compiler defines
171152
$<${is_gnu_fe}:-Wall>
172153
$<${is_gnu_fe}:-Wextra>
173154
$<${is_gnu_fe}:-Wpedantic>
174-
$<${is_gnu_fe}:-Werror>
155+
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_gnu_fe}>:-Werror>
175156
$<${is_gnu_fe}:-Wshadow>
176157
$<${is_gnu_fe}:-Wdouble-promotion>
177158
$<${is_clang}:-Wdocumentation>

0 commit comments

Comments
 (0)