From df7c27373796d14256a00813f32196104ef5ed84 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 25 May 2024 10:15:03 +0100 Subject: [PATCH] cmake: Let libsecp256k1 manage config-specific C flags --- CMakeLists.txt | 24 ++------------------ cmake/module/ProcessConfigurations.cmake | 28 ------------------------ 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da96df9b88a08..04f6b760b25dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,15 +427,12 @@ target_compile_definitions(core_interface_debug INTERFACE ) # We leave assertions on. if(MSVC) - remove_c_flag_from_all_configs(/DNDEBUG) remove_cxx_flag_from_all_configs(/DNDEBUG) else() - remove_c_flag_from_all_configs(-DNDEBUG) remove_cxx_flag_from_all_configs(-DNDEBUG) - # Adjust flags used by the C/CXX compiler during RELEASE builds. + # Adjust flags used by the CXX compiler during RELEASE builds. # Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.) - replace_c_flag_in_config(Release -O3 -O2) replace_cxx_flag_in_config(Release -O3 -O2) are_flags_overridden(CMAKE_CXX_FLAGS_DEBUG cxx_flags_debug_overridden) @@ -445,6 +442,7 @@ else() if(compiler_supports_g3) replace_cxx_flag_in_config(Debug -g -g3) endif() + unset(compiler_supports_g3) try_append_cxx_flags("-ftrapv" RESULT_VAR compiler_supports_ftrapv) if(compiler_supports_ftrapv) @@ -461,24 +459,6 @@ else() ) endif() unset(cxx_flags_debug_overridden) - - are_flags_overridden(CMAKE_C_FLAGS_DEBUG c_flags_debug_overridden) - if(NOT c_flags_debug_overridden) - # Redefine flags used by the C compiler during DEBUG builds. - if(compiler_supports_g3) - replace_c_flag_in_config(Debug -g -g3) - endif() - - string(PREPEND CMAKE_C_FLAGS_DEBUG "-O0 ") - - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" - CACHE STRING - "Flags used by the C compiler during DEBUG builds." - FORCE - ) - endif() - unset(compiler_supports_g3) - unset(c_flags_debug_overridden) endif() include(cmake/optional.cmake) diff --git a/cmake/module/ProcessConfigurations.cmake b/cmake/module/ProcessConfigurations.cmake index d5895497deb26..e53df8c14f112 100644 --- a/cmake/module/ProcessConfigurations.cmake +++ b/cmake/module/ProcessConfigurations.cmake @@ -84,23 +84,6 @@ function(set_default_config config) endif() endfunction() -function(remove_c_flag_from_all_configs flag) - get_all_configs(all_configs) - foreach(config IN LISTS all_configs) - string(TOUPPER "${config}" config_uppercase) - set(flags "${CMAKE_C_FLAGS_${config_uppercase}}") - separate_arguments(flags) - list(FILTER flags EXCLUDE REGEX "${flag}") - list(JOIN flags " " new_flags) - set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE) - set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" - CACHE STRING - "Flags used by the C compiler during ${config_uppercase} builds." - FORCE - ) - endforeach() -endfunction() - function(remove_cxx_flag_from_all_configs flag) get_all_configs(all_configs) foreach(config IN LISTS all_configs) @@ -118,17 +101,6 @@ function(remove_cxx_flag_from_all_configs flag) endforeach() endfunction() -function(replace_c_flag_in_config config old_flag new_flag) - string(TOUPPER "${config}" config_uppercase) - string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_C_FLAGS_${config_uppercase}}") - set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE) - set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" - CACHE STRING - "Flags used by the C compiler during ${config_uppercase} builds." - FORCE - ) -endfunction() - function(replace_cxx_flag_in_config config old_flag new_flag) string(TOUPPER "${config}" config_uppercase) string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_CXX_FLAGS_${config_uppercase}}")