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 <sven.vanhaastregt@arm.com>

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt
2022-09-22 21:17:55 +01:00
committed by GitHub
parent 86d5ee5414
commit 92285f7c9d
3 changed files with 15 additions and 16 deletions

View File

@@ -113,6 +113,17 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__SSE__") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__SSE__")
endif() 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) if(MSVC)
# Don't warn when using standard non-secure functions. # Don't warn when using standard non-secure functions.
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)

View File

@@ -21,13 +21,7 @@ set(${MODULE_NAME}_SOURCES
# Make unused variables not fatal in this module; see # Make unused variables not fatal in this module; see
# https://github.com/KhronosGroup/OpenCL-CTS/issues/1484 # https://github.com/KhronosGroup/OpenCL-CTS/issues/1484
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") set_gnulike_module_compile_flags("-Wno-error=unused-variable")
SET_SOURCE_FILES_PROPERTIES(
${${MODULE_NAME}_SOURCES}
PROPERTIES
COMPILE_FLAGS "-Wno-error=unused-variable"
)
endif()
include(../../CMakeCommon.txt) include(../../CMakeCommon.txt)

View File

@@ -40,14 +40,8 @@ set(${MODULE_NAME}_SOURCES
utility.h utility.h
) )
# math_brute_force compiles cleanly with -Wall but other tests not (yet), so # math_brute_force compiles cleanly with -Wall (except for a few remaining
# enable -Wall locally. # warnings), but other tests not (yet); so enable -Wall locally.
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") set_gnulike_module_compile_flags("-Wall -Wno-format -Wno-strict-aliasing -Wno-unknown-pragmas")
SET_SOURCE_FILES_PROPERTIES(
${${MODULE_NAME}_SOURCES}
PROPERTIES
COMPILE_FLAGS "-Wall -Wno-format -Wno-strict-aliasing -Wno-unknown-pragmas"
)
endif()
include(../CMakeCommon.txt) include(../CMakeCommon.txt)