cmake: improve the check of optimization level against CMAKE_BUILD_TYPE

Fixes: #39626

The CMAKE_C_FLAGS_<build_type> is a string with arguments separated by
spaces and not a list, for example "-O3 -DNDEBUG".

Therefore update the `if()` check to do a regex match to determine if
the optimization level specified through Kconfig matches the
optimization level that would be defined by the CMAKE_BUILD_TYPE
setting.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 file changed