From 7565b665c38c9f1421c9d38d07cec9e53f052a6d Mon Sep 17 00:00:00 2001 From: ribbon-otter Date: Sun, 10 Aug 2025 22:53:50 -0700 Subject: [PATCH] add option to disable -Werror on tests --- dlib/test/CMakeLists.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/dlib/test/CMakeLists.txt b/dlib/test/CMakeLists.txt index 330ac2417c..02b1f7ee78 100644 --- a/dlib/test/CMakeLists.txt +++ b/dlib/test/CMakeLists.txt @@ -9,9 +9,13 @@ cmake_minimum_required(VERSION 3.10.0) set (target_name dtest) PROJECT(${target_name}) +option(Werror "Error on warnings" ON) + # compile the dlib/all/source.cpp file into its own object just to make sure it compiles set(DLIB_TEST_COMPILE_ALL_SOURCE_CPP ON) + + add_subdirectory(.. dlib_build) add_executable(${target_name} main.cpp tester.cpp @@ -170,7 +174,11 @@ target_compile_definitions(${target_name} PRIVATE DLIB_FFMPEG_DATA="${DLIB_FFMPE if (CMAKE_COMPILER_IS_GNUCXX) # Turn on all warnings, and treat them as errors. - add_compile_options(-W -Wall -Wextra -Wpedantic -Werror) + add_compile_options(-W -Wall -Wextra -Wpedantic) + if (Werror) + add_compile_options(-Werror) + endif() + add_compile_options(-fdiagnostics-color=always) # I don't care about unused testing functions though. I like to keep them # around. Don't warn about it. @@ -205,11 +213,16 @@ if (CMAKE_COMPILER_IS_GNUCXX) endif() elseif (MSVC) - # Treat warnings as errors. - add_compile_options(/WX) + if (Werror) + # Treat warnings as errors. + add_compile_options(/WX) + endif() else() # basically Clang # Treat warnings as errors, but do not turn on all warnings. - add_compile_options(-W -Werror) + add_compile_options(-W) + if (Werror) + add_compile_options(-Werror) + endif() # This is for the comment in face_detection_ex.cpp that says "faces/*.jpg" add_compile_options(-Wno-comment)