Skip to content

Commit c7e33e0

Browse files
authored
Merge pull request #708 from hvdijk/compile-warning-as-error
For CMake 3.24+, use COMPILE_WARNINGS_AS_ERRORS.
2 parents aa11fc8 + fb27da9 commit c7e33e0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

cmake/AddCA.cmake

+20-4
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,22 @@ add_compile_options(
148148
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
149149
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>)
150150

151-
set(CA_COMPILE_OPTIONS
151+
# Enable warnings as errors when not a subproject
152+
set(CA_COMPILE_WARNING_AS_ERROR OFF)
153+
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
154+
set(CA_COMPILE_WARNING_AS_ERROR ON)
155+
endif()
156+
157+
set(CA_COMPILE_OPTIONS)
158+
159+
if(CA_COMPILE_WARNING_AS_ERROR AND CMAKE_VERSION VERSION_LESS "3.24")
160+
list(APPEND CA_COMPILE_OPTIONS
161+
$<$<OR:$<BOOL:${UNIX}>,$<BOOL:${ANDROID}>,$<BOOL:${MINGW}>>:-Werror>
162+
)
163+
endif()
164+
165+
list(APPEND CA_COMPILE_OPTIONS
152166
$<$<OR:$<BOOL:${UNIX}>,$<BOOL:${ANDROID}>,$<BOOL:${MINGW}>>:
153-
$<$<STREQUAL:${CMAKE_SOURCE_DIR},${PROJECT_SOURCE_DIR}>:
154-
-Werror # Enable warnings as errors when not a subproject
155-
>
156167
-Wno-error=deprecated-declarations # Disable: use of deprecated functions
157168
-Wno-error=array-bounds # Disable errors that vary heavily on compiler and
158169
-Wno-error=uninitialized # optimization level and have false positives.
@@ -483,6 +494,8 @@ macro(add_ca_library)
483494
PRIVATE ${CA_COMPILE_OPTIONS})
484495
target_compile_definitions(${ARGV0}
485496
PRIVATE ${CA_COMPILE_DEFINITIONS} ${CA_COMPILER_COMPILE_DEFINITIONS})
497+
set_target_properties(${ARGV0} PROPERTIES
498+
COMPILE_WARNING_AS_ERROR ${CA_COMPILE_WARNING_AS_ERROR})
486499
set_ca_target_output_directory(${ARGV0})
487500
if(COMMAND add_ca_tidy)
488501
add_ca_tidy(${ACL_UNPARSED_ARGUMENTS} DEPENDS ${ACL_DEPENDS})
@@ -509,6 +522,8 @@ macro(add_ca_interface_library)
509522
INTERFACE ${CA_COMPILE_OPTIONS})
510523
target_compile_definitions(${ARGV0}
511524
INTERFACE ${CA_COMPILE_DEFINITIONS} ${CA_COMPILER_COMPILE_DEFINITIONS})
525+
set_target_properties(${ARGV0} PROPERTIES
526+
COMPILE_WARNING_AS_ERROR ${CA_COMPILE_WARNING_AS_ERROR})
512527
endmacro()
513528

514529
#[=======================================================================[.rst:
@@ -569,6 +584,7 @@ macro(add_ca_executable)
569584
target_compile_definitions(${ARGV0}
570585
PRIVATE ${CA_COMPILE_DEFINITIONS} ${CA_COMPILER_COMPILE_DEFINITIONS})
571586
set_target_properties(${ARGV0} PROPERTIES
587+
COMPILE_WARNING_AS_ERROR ${CA_COMPILE_WARNING_AS_ERROR}
572588
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
573589
if(COMMAND add_ca_tidy)
574590
add_ca_tidy(${ACE_UNPARSED_ARGUMENTS} DEPENDS ${ACE_DEPENDS})

modules/compiler/builtins/libimg/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ target_include_directories(image_library_host SYSTEM PUBLIC
8888
"${CODEPLAY_IMG_OPENCL_INCLUDE_DIR}")
8989
target_compile_options(image_library_host
9090
PRIVATE ${CA_COMPILE_OPTIONS})
91+
set_target_properties(image_library_host PROPERTIES
92+
COMPILE_WARNING_AS_ERROR ${CA_COMPILE_WARNING_AS_ERROR})
9193

9294
target_compile_definitions(image_library_host
9395
PUBLIC CL_TARGET_OPENCL_VERSION=${CA_CL_STANDARD_INTERNAL}

0 commit comments

Comments
 (0)