Skip to content

Commit c32e4a7

Browse files
tejlmandfabiobaltieri
authored andcommitted
cmake: support grouping of compile options for compiler testing
Fixes: #47588 Kitware decided to fail compiler tests of single options if the compiler reported only a warning and not an error: github.com/Kitware/CMake/commit/f745e0497ee71d35fd1b3524b1636a72da76c266 which affects CMake 3.23.0 and 3.23.1 This change was later reverted in CMake >=3.23.2 and >=3.24.0 github.com/Kitware/CMake/commit/4941887d7defecb3016d2bd94d3a45754251ca56 Although the immediate issue is related to CMake, and has been fixed reverted in later releases, then it still makes sense to be able to group compiler options together that generally are depending on each other to function correctly. This commit introduces the possibility to group compiler options which must be tested together. It uses same approach as > add_compile_options("SHELL:<option1> <option2> ...") Usage: > check_set_compiler_property(PROPERTY <property> > "SHELL:<option1> <option2> ..." > ) Will test the option together. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 5951cd4 commit c32e4a7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cmake/modules/extensions.cmake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ function(zephyr_check_compiler_flag lang option check)
10481048
set(key_string "${key_string}${option}_")
10491049
set(key_string "${key_string}${CMAKE_REQUIRED_FLAGS}_")
10501050

1051-
string(MD5 key ${key_string})
1051+
string(MD5 key "${key_string}")
10521052

10531053
# Check the cache
10541054
set(key_path ${ZEPHYR_TOOLCHAIN_CAPABILITY_CACHE_DIR}/${key})
@@ -1068,7 +1068,7 @@ function(zephyr_check_compiler_flag lang option check)
10681068
# tested, so to test -Wno-<warning> flags we test -W<warning>
10691069
# instead.
10701070
if("${option}" MATCHES "-Wno-(.*)")
1071-
set(possibly_translated_option -W${CMAKE_MATCH_1})
1071+
string(REPLACE "-Wno-" "-W" possibly_translated_option "${option}")
10721072
else()
10731073
set(possibly_translated_option ${option})
10741074
endif()
@@ -1814,7 +1814,7 @@ function(check_compiler_flag lang option ok)
18141814
endif()
18151815

18161816
string(MAKE_C_IDENTIFIER
1817-
check${option}_${lang}_${CMAKE_REQUIRED_FLAGS}
1817+
"check${option}_${lang}_${CMAKE_REQUIRED_FLAGS}"
18181818
${ok}
18191819
)
18201820

@@ -2004,6 +2004,12 @@ endfunction()
20042004
# with the extension that it will check that the compiler supports the flag
20052005
# before setting the property on compiler or compiler-cpp targets.
20062006
#
2007+
# To test flags together, such as '-Wformat -Wformat-security', an option group
2008+
# can be specified by using shell-like quoting along with a 'SHELL:' prefix.
2009+
# The 'SHELL:' prefix will be dropped before testing, so that
2010+
# '"SHELL:-Wformat -Wformat-security"' becomes '-Wformat -Wformat-security' for
2011+
# testing.
2012+
#
20072013
# APPEND: Flag indicated that the property should be appended to the existing
20082014
# value list for the property.
20092015
# PROPERTY: Name of property with the value(s) following immediately after
@@ -2021,16 +2027,21 @@ function(check_set_compiler_property)
20212027
list(REMOVE_AT COMPILER_PROPERTY_PROPERTY 0)
20222028

20232029
foreach(option ${COMPILER_PROPERTY_PROPERTY})
2030+
if(${option} MATCHES "^SHELL:")
2031+
string(REGEX REPLACE "^SHELL:" "" option ${option})
2032+
separate_arguments(option UNIX_COMMAND ${option})
2033+
endif()
2034+
20242035
if(CONFIG_CPLUSPLUS)
2025-
zephyr_check_compiler_flag(CXX ${option} check)
2036+
zephyr_check_compiler_flag(CXX "${option}" check)
20262037

20272038
if(${check})
20282039
set_property(TARGET compiler-cpp ${APPEND-CPP} PROPERTY ${property} ${option})
20292040
set(APPEND-CPP "APPEND")
20302041
endif()
20312042
endif()
20322043

2033-
zephyr_check_compiler_flag(C ${option} check)
2044+
zephyr_check_compiler_flag(C "${option}" check)
20342045

20352046
if(${check})
20362047
set_property(TARGET compiler ${APPEND} PROPERTY ${property} ${option})

0 commit comments

Comments
 (0)