From 92285f7c9de965ddc41e7dfaaab8c7c75aa55dbe Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 22 Sep 2022 21:17:55 +0100 Subject: [PATCH] cmake: Add set_gnulike_module_compile_flags (#1510) Factor out a macro to set module-specific compilation flags for GNU-like compilers. This simplifies setting compilation flags per test. Signed-off-by: Sven van Haastregt Signed-off-by: Sven van Haastregt --- CMakeLists.txt | 11 +++++++++++ .../images/kernel_read_write/CMakeLists.txt | 8 +------- test_conformance/math_brute_force/CMakeLists.txt | 12 +++--------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7c86ba1..6a25d5b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,17 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__SSE__") endif() +# Set a module's COMPILE_FLAGS if using gcc or clang. +macro(set_gnulike_module_compile_flags flags) + if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") + SET_SOURCE_FILES_PROPERTIES( + ${${MODULE_NAME}_SOURCES} + PROPERTIES + COMPILE_FLAGS ${flags} + ) + endif() +endmacro(set_gnulike_module_compile_flags) + if(MSVC) # Don't warn when using standard non-secure functions. add_compile_definitions(_CRT_SECURE_NO_WARNINGS) diff --git a/test_conformance/images/kernel_read_write/CMakeLists.txt b/test_conformance/images/kernel_read_write/CMakeLists.txt index 6eb5dc7f..ccd678c1 100644 --- a/test_conformance/images/kernel_read_write/CMakeLists.txt +++ b/test_conformance/images/kernel_read_write/CMakeLists.txt @@ -21,13 +21,7 @@ set(${MODULE_NAME}_SOURCES # Make unused variables not fatal in this module; see # https://github.com/KhronosGroup/OpenCL-CTS/issues/1484 -if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") - SET_SOURCE_FILES_PROPERTIES( - ${${MODULE_NAME}_SOURCES} - PROPERTIES - COMPILE_FLAGS "-Wno-error=unused-variable" - ) -endif() +set_gnulike_module_compile_flags("-Wno-error=unused-variable") include(../../CMakeCommon.txt) diff --git a/test_conformance/math_brute_force/CMakeLists.txt b/test_conformance/math_brute_force/CMakeLists.txt index 23ee6849..1db1ecdf 100644 --- a/test_conformance/math_brute_force/CMakeLists.txt +++ b/test_conformance/math_brute_force/CMakeLists.txt @@ -40,14 +40,8 @@ set(${MODULE_NAME}_SOURCES utility.h ) -# math_brute_force compiles cleanly with -Wall but other tests not (yet), so -# enable -Wall locally. -if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") - SET_SOURCE_FILES_PROPERTIES( - ${${MODULE_NAME}_SOURCES} - PROPERTIES - COMPILE_FLAGS "-Wall -Wno-format -Wno-strict-aliasing -Wno-unknown-pragmas" - ) -endif() +# math_brute_force compiles cleanly with -Wall (except for a few remaining +# warnings), but other tests not (yet); so enable -Wall locally. +set_gnulike_module_compile_flags("-Wall -Wno-format -Wno-strict-aliasing -Wno-unknown-pragmas") include(../CMakeCommon.txt)