Replace OVERTE_WARNINGS_AS_ERRORS with CMake's new COMPILE_WARNING_AS_ERROR.

This commit is contained in:
Julian Groß 2025-05-31 13:58:50 +02:00
parent 01223c8672
commit 317e1a7d88

View file

@ -3,11 +3,11 @@
# Copyright 2020-2025 Overte e.V. # Copyright 2020-2025 Overte e.V.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# 3.14 is the minimum version that supports symlinks on Windows
cmake_minimum_required(VERSION 3.14)
# This should allow using long paths on Windows # This should allow using long paths on Windows
SET(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "") SET(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
# 3.24 is the minimum version that supports COMPILE_WARNING_AS_ERROR
cmake_minimum_required(VERSION 3.24)
include(SelectLibraryConfigurations) include(SelectLibraryConfigurations)
@ -93,6 +93,8 @@ if( NOT WIN32 )
message($ENV{CXXFLAGS}) message($ENV{CXXFLAGS})
endif() endif()
#
# OVERTE_WARNINGS # OVERTE_WARNINGS
# #
# Here we add the ability to allowlist warnings we've determined we can't fix, or are safe to # Here we add the ability to allowlist warnings we've determined we can't fix, or are safe to
@ -101,14 +103,7 @@ endif()
# #
# We can also treat warnings as errors. Without the allowlist this will almost certainly lead # We can also treat warnings as errors. Without the allowlist this will almost certainly lead
# to a build failure. # to a build failure.
set(OVERTE_WARNINGS_ALLOWLIST ON CACHE BOOL "Allowlist some warnings we can't currently fix.")
if(NOT DEFINED OVERTE_WARNINGS_ALLOWLIST)
set(OVERTE_WARNINGS_ALLOWLIST true CACHE BOOL "Allowlist some warnings we can't currently fix")
endif()
if(NOT DEFINED OVERTE_WARNINGS_AS_ERRORS)
set(OVERTE_WARNINGS_AS_ERRORS false CACHE BOOL "Count warnings as errors")
endif()
if(OVERTE_WARNINGS_ALLOWLIST) if(OVERTE_WARNINGS_ALLOWLIST)
if (NOT WIN32) if (NOT WIN32)
@ -130,14 +125,13 @@ if(OVERTE_WARNINGS_ALLOWLIST)
endif() endif()
endif() endif()
if(OVERTE_WARNINGS_AS_ERRORS) # Enabling warnings-as-errors by default on our Linux target and on Windows.
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "" AND WIN32)) # Our current Linux development target is Ubuntu 22.04, which uses GCC 11.2.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") # TODO: Enable warnings-as-errors once we stop throwing warnings on the relevant platforms.
set(CMAKE_CFLAGS "${CMAKE_CFLAGS} /WX") if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION MATCHES "11"))
else() set(COMPILE_WARNING_AS_ERROR OFF CACHE BOOL "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # Windows
set(CMAKE_CFLAGS "${CMAKE_CFLAGS} -Werror") set(COMPILE_WARNING_AS_ERROR OFF CACHE BOOL "")
endif()
endif() endif()