From 668190f166395be98850f0d589f92f57689b1fdf Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Fri, 21 Mar 2025 11:28:44 -0700 Subject: [PATCH] Make -Werror and /WX optional --- CMakeLists.txt | 1 + Source/UnitTest/cmake_core.cmake | 43 +++++++++++++++++++------------- Source/cmake_compiler.cmake | 37 +++++++++++++++++++++++++++ Source/cmake_core.cmake | 27 +++----------------- 4 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 Source/cmake_compiler.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d7dcd51c..5273d7b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ option(ASTCENC_UNITTEST "Enable astcenc builds with unit tests") option(ASTCENC_INVARIANCE "Enable astcenc floating point invariance" ON) option(ASTCENC_CLI "Enable build of astcenc command line tools" ON) option(ASTCENC_X86_GATHERS "Enable use of native x86 gathers" ON) +option(ASTCENC_WERROR "Force builds to treat warnings as errors" ON) # Preflight for some macOS-specific build options if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") diff --git a/Source/UnitTest/cmake_core.cmake b/Source/UnitTest/cmake_core.cmake index ed3d90f4..a467354a 100644 --- a/Source/UnitTest/cmake_core.cmake +++ b/Source/UnitTest/cmake_core.cmake @@ -15,6 +15,8 @@ # under the License. # ---------------------------------------------------------------------------- +include(../cmake_compiler.cmake) + set(ASTCENC_TEST test-unit-${ASTCENC_ISA_SIMD}) add_executable(${ASTCENC_TEST}) @@ -57,27 +59,34 @@ target_compile_options(${ASTCENC_TEST} $<$:-pthread> # MSVC compiler defines - $<$:/EHsc> + $<${is_msvc_fe}:/EHsc> + $<$,${is_msvc_fe}>:/WX> + $<${is_msvccl}:/wd4324> # G++ and Clang++ compiler defines - $<$>:-Wall> - $<$>:-Wextra> - $<$>:-Wpedantic> - $<$>:-Werror> - $<$>:-Wshadow> - $<$>:-Wno-c++98-compat-pedantic> - $<$>:-Wno-c++98-c++11-compat-pedantic> - $<$>:-Wno-float-equal> - $<$>:-Wno-overriding-option> - $<$>:-Wno-unsafe-buffer-usage> - $<$>:-Wno-switch-default> + $<${is_gnu_fe}:-Wall> + $<${is_gnu_fe}:-Wextra> + $<${is_gnu_fe}:-Wpedantic> + $<$,${is_gnu_fe}>:-Werror> + $<${is_gnu_fe}:-Wshadow> + $<${is_gnu_fe}:-Wdouble-promotion> + $<${is_clang}:-Wdocumentation> + + # Hide noise thrown up by Clang 10 and clang-cl + $<${is_gnu_fe}:-Wno-unknown-warning-option> + $<${is_gnu_fe}:-Wno-c++98-compat-pedantic> + $<${is_gnu_fe}:-Wno-c++98-c++11-compat-pedantic> + $<${is_gnu_fe}:-Wno-float-equal> + $<${is_gnu_fe}:-Wno-overriding-option> + $<${is_gnu_fe}:-Wno-unsafe-buffer-usage> + $<${is_clang}:-Wno-switch-default> # Ignore things that the googletest build triggers - $<$>:-Wno-unknown-warning-option> - $<$>:-Wno-double-promotion> - $<$>:-Wno-undef> - $<$>:-Wno-reserved-identifier> - $<$>:-Wno-global-constructors>) + $<${is_gnu_fe}:-Wno-unknown-warning-option> + $<${is_gnu_fe}:-Wno-double-promotion> + $<${is_gnu_fe}:-Wno-undef> + $<${is_gnu_fe}:-Wno-reserved-identifier> + $<${is_gnu_fe}:-Wno-global-constructors>) # Set up configuration for SIMD ISA builds if(${ASTCENC_ISA_SIMD} MATCHES "none") diff --git a/Source/cmake_compiler.cmake b/Source/cmake_compiler.cmake new file mode 100644 index 00000000..8b4d6714 --- /dev/null +++ b/Source/cmake_compiler.cmake @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: Apache-2.0 +# ---------------------------------------------------------------------------- +# Copyright 2020-2025 Arm Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set +if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "") + set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}") +endif() + +# Compiler accepts MSVC-style command line options +set(is_msvc_fe "$") +# Compiler accepts GNU-style command line options +set(is_gnu_fe1 "$") +# Compiler accepts AppleClang-style command line options, which is also GNU-style +set(is_gnu_fe2 "$") +# Compiler accepts GNU-style command line options +set(is_gnu_fe "$") + +# Compiler is Visual Studio cl.exe +set(is_msvccl "$>") +# Compiler is Visual Studio clangcl.exe +set(is_clangcl "$>") +# Compiler is upstream clang with the standard frontend +set(is_clang "$>") diff --git a/Source/cmake_core.cmake b/Source/cmake_core.cmake index 8c633a10..a9196b1b 100644 --- a/Source/cmake_core.cmake +++ b/Source/cmake_core.cmake @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 # ---------------------------------------------------------------------------- -# Copyright 2020-2024 Arm Limited +# Copyright 2020-2025 Arm Limited # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # 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}) project(${ASTCENC_TARGET}) -# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set -if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "") - set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}") -endif() - -# Compiler accepts MSVC-style command line options -set(is_msvc_fe "$") -# Compiler accepts GNU-style command line options -set(is_gnu_fe1 "$") -# Compiler accepts AppleClang-style command line options, which is also GNU-style -set(is_gnu_fe2 "$") -# Compiler accepts GNU-style command line options -set(is_gnu_fe "$") - -# Compiler is Visual Studio cl.exe -set(is_msvccl "$>") -# Compiler is Visual Studio clangcl.exe -set(is_clangcl "$>") -# Compiler is upstream clang with the standard frontend -set(is_clang "$>") +include(cmake_compiler.cmake) add_library(${ASTCENC_TARGET}-static STATIC @@ -164,14 +145,14 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_VENEER_TYPE) # MSVC compiler defines $<${is_msvc_fe}:/EHsc> - $<${is_msvc_fe}:/WX> + $<$,${is_msvc_fe}>:/WX> $<${is_msvccl}:/wd4324> # G++ and Clang++ compiler defines $<${is_gnu_fe}:-Wall> $<${is_gnu_fe}:-Wextra> $<${is_gnu_fe}:-Wpedantic> - $<${is_gnu_fe}:-Werror> + $<$,${is_gnu_fe}>:-Werror> $<${is_gnu_fe}:-Wshadow> $<${is_gnu_fe}:-Wdouble-promotion> $<${is_clang}:-Wdocumentation>