cmake: fixed regex handling in process_flags function extensions.cmake
This commit fixes an issue in the process_flags function.
The function check a list of flags for generator expression for provided
language, for example:
$<$<COMPILE_LANGUAGE:C>:--flag>
and then converts that into a single compile flag, `--flag`
This works as long as $<COMPILE_LANGUAGE:[language]> is the only
generator expression present in the flag.
In case the flag contains multiple generator expression, then the
current substitution fails.
This commit keep existing behaviour for simple cases, but extends the
more complex cases into a always enabled generator expression, that is
$<$<COMPILE_LANGUAGE:C>:$<ADDITIONAL_EXPRESSION>> into
$<1:$<ADDITIONAL_EXPRESSION>>
and
$<$<FIRST_EXPRESSION>$<COMPILE_LANGUAGE:C>:--flag> into
$<$<FIRST_EXPRESSION>$<1:--flag>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake
index becfc3d..a08d251 100644
--- a/cmake/extensions.cmake
+++ b/cmake/extensions.cmake
@@ -253,6 +253,7 @@
# The flags might contains compile language generator expressions that
# look like this:
# $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
+ # $<$<COMPILE_LANGUAGE:CXX>:$<OTHER_EXPRESSION>>
#
# Flags that don't specify a language like this apply to all
# languages.
@@ -274,9 +275,18 @@
set(is_compile_lang_generator_expression 0)
foreach(l ${languages})
if(flag MATCHES "<COMPILE_LANGUAGE:${l}>:([^>]+)>")
+ set(updated_flag ${CMAKE_MATCH_1})
set(is_compile_lang_generator_expression 1)
if(${l} STREQUAL ${lang})
- list(APPEND tmp_list ${CMAKE_MATCH_1})
+ # This test will match in case there are more generator expressions in the flag.
+ # As example: $<$<COMPILE_LANGUAGE:C>:$<OTHER_EXPRESSION>>
+ # $<$<OTHER_EXPRESSION:$<COMPILE_LANGUAGE:C>:something>>
+ string(REGEX MATCH "(\\\$<)[^\\\$]*(\\\$<)[^\\\$]*(\\\$<)" IGNORE_RESULT ${flag})
+ if(CMAKE_MATCH_2)
+ # Nested generator expressions are used, just substitue `$<COMPILE_LANGUAGE:${l}>` to `1`
+ string(REGEX REPLACE "\\\$<COMPILE_LANGUAGE:${l}>" "1" updated_flag ${flag})
+ endif()
+ list(APPEND tmp_list ${updated_flag})
break()
endif()
endif()