From d1793f077d7bdb6b5ccfc4f046de34453fcf8252 Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 22 Dec 2023 12:38:38 -0800 Subject: [PATCH] [build] cmake: Add NO_WERROR option to disable -Werror (#6071) --- CMakeLists.txt | 3 +++ README-CMAKE.md | 2 ++ cmake/modules/CompileWarnings.cmake | 14 +++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 726a1e8cc4..c688bba3b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,9 @@ option(USE_SYSTEM_EIGEN "Use system eigen" OFF) # Options for location of OpenCV Java. set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file") +# Options for compilation flags. +option(NO_WERROR "Disable -Werror flag during compilation" OFF) + # Set default build type to release with debug info (i.e. release mode optimizations # are performed, but debug info still exists). if(NOT CMAKE_BUILD_TYPE) diff --git a/README-CMAKE.md b/README-CMAKE.md index a2750bd70d..0d6f0b90c8 100644 --- a/README-CMAKE.md +++ b/README-CMAKE.md @@ -63,6 +63,8 @@ The following build options are available: * TODO * `OPENCV_JAVA_INSTALL_DIR` * Set this option to the location of the archive of the OpenCV Java bindings (it should be called opencv-xxx.jar, with the x'es being version numbers). NOTE: set it to the LOCATION of the file, not the file itself! +* `NO_WERROR` (OFF Default) + * This option will disable the `-Werror` compilation flag for non-MSVC builds. ## Build Setup diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index af21d1d001..5de103201e 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -1,9 +1,17 @@ macro(wpilib_target_warnings target) if(NOT MSVC) - target_compile_options( - ${target} - PRIVATE -Wall -pedantic -Wextra -Werror -Wno-unused-parameter ${WPILIB_TARGET_WARNINGS} + set(WARNING_FLAGS + -Wall + -pedantic + -Wextra + -Wno-unused-parameter + ${WPILIB_TARGET_WARNINGS} ) + if(NOT NO_WERROR) + set(WARNING_FLAGS ${WARNING_FLAGS} -Werror) + endif() + + target_compile_options(${target} PRIVATE ${WARNING_FLAGS}) else() target_compile_options( ${target}