From e596cb552735b98542f38d425c87c7e8e100117a Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Thu, 6 Jun 2024 22:24:20 +0300 Subject: [PATCH] feat(tool): Adds idf_build_remove_options_from_property func --- CMakeLists.txt | 7 +------ tools/cmake/build.cmake | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ec62c5134..b381db8484 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,14 +202,9 @@ if(CONFIG_COMPILER_DISABLE_GCC13_WARNINGS) endif() if(CONFIG_COMPILER_DISABLE_DEFAULT_ERRORS) - set(compiler_flags "-Wno-error") if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang") - list(APPEND compiler_flags "-Werror=all") + idf_build_replace_option_from_property(COMPILE_OPTIONS "-Werror" "-Werror=all") endif() - - list(APPEND compile_options ${compiler_flags}) - list(APPEND c_compile_options ${compiler_flags}) - list(APPEND cxx_compile_options ${compiler_flags}) endif() # GCC-specific options diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 8fd16c4c0d..a86340a752 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -61,6 +61,35 @@ function(idf_build_unset_property property) idf_build_set_property(__BUILD_PROPERTIES "${build_properties}") endfunction() +# idf_build_replace_option_from_property +# +# @brief Replace specified option with new one in a given property. +# +# @param[in] property_name the property in which to replace the options (ex.: COMPILE_OPTIONS, C_COMPILE_OPTIONS,..) +# +# @param[in] option_to_remove the option to be replaced +# @param[in] new_option the option to replace with (if empty, the old option will be removed) +# +# Example usage: +# idf_build_replace_options_from_property(COMPILE_OPTIONS "-Werror" "-Werror=all") +# idf_build_replace_options_from_property(COMPILE_OPTIONS "-Wno-error=extra" "") +# +function(idf_build_replace_option_from_property property_name option_to_remove new_option) + idf_build_get_property(current_list_of_options ${property_name}) + + set(new_list_of_options) + foreach(option ${current_list_of_options}) + if(option STREQUAL option_to_remove) + list(APPEND new_list_of_options "${new_option}") + else() + list(APPEND new_list_of_options "${option}") + endif() + endforeach() + + # Set the updated list back + idf_build_set_property(${property_name} "${new_list_of_options}") +endfunction() + # # Retrieve the IDF_PATH repository's version, either using a version # file or Git revision. Sets the IDF_VER build property.