From 73f22aa23f2d768e5ca55c2871e0f7b227225827 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Tue, 1 Jul 2025 21:00:34 +0100 Subject: [PATCH] Allow building with cmake --compile-no-warning-as-error. (#2401) In CMake 3.24+, there is built-in support for adding -Werror that does not require adding -Werror explicitly, and allows it to be downgraded to a warning if the user wants that. Use this, to account for warnings that have false positives. --- CMakeLists.txt | 6 +++++- test_conformance/common/vulkan_wrapper/CMakeLists.txt | 1 + .../extensions/cl_khr_external_semaphore/CMakeLists.txt | 1 + test_conformance/vulkan/CMakeLists.txt | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ba12adf..f34ade8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang" add_cxx_flag_if_supported(-Wmisleading-indentation) add_cxx_flag_if_supported(-Wunused-function) add_cxx_flag_if_supported(-Wunused-variable) - add_cxx_flag_if_supported(-Werror) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + set(CMAKE_COMPILE_WARNING_AS_ERROR ON) + else() + add_cxx_flag_if_supported(-Werror) + endif() if(NOT CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo|MinSizeRel") # Enable more warnings if not doing a release build. add_cxx_flag_if_supported(-Wall) diff --git a/test_conformance/common/vulkan_wrapper/CMakeLists.txt b/test_conformance/common/vulkan_wrapper/CMakeLists.txt index c647b4b6..42397998 100644 --- a/test_conformance/common/vulkan_wrapper/CMakeLists.txt +++ b/test_conformance/common/vulkan_wrapper/CMakeLists.txt @@ -6,6 +6,7 @@ set(VULKAN_WRAPPER_SOURCES ) # needed by Vulkan wrapper to compile +set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) add_cxx_flag_if_supported(-Wmisleading-indentation) add_cxx_flag_if_supported(-Wno-narrowing) add_cxx_flag_if_supported(-Wno-format) diff --git a/test_conformance/extensions/cl_khr_external_semaphore/CMakeLists.txt b/test_conformance/extensions/cl_khr_external_semaphore/CMakeLists.txt index 633dea33..1161e519 100644 --- a/test_conformance/extensions/cl_khr_external_semaphore/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_external_semaphore/CMakeLists.txt @@ -17,6 +17,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories (${CLConform_INCLUDE_DIR}) list(APPEND CLConform_LIBRARIES vulkan_wrapper) +set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_CXX_FLAGS "-fpermissive") include_directories("../../common/vulkan_wrapper") diff --git a/test_conformance/vulkan/CMakeLists.txt b/test_conformance/vulkan/CMakeLists.txt index 85313c39..e658b31c 100644 --- a/test_conformance/vulkan/CMakeLists.txt +++ b/test_conformance/vulkan/CMakeLists.txt @@ -1,6 +1,7 @@ set (MODULE_NAME VULKAN) list(APPEND CLConform_LIBRARIES vulkan_wrapper) +set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_CXX_FLAGS "-fpermissive") if(WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR")