Skip to content

Commit df7c273

Browse files
committed
cmake: Let libsecp256k1 manage config-specific C flags
1 parent 4a76af5 commit df7c273

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

CMakeLists.txt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,12 @@ target_compile_definitions(core_interface_debug INTERFACE
427427
)
428428
# We leave assertions on.
429429
if(MSVC)
430-
remove_c_flag_from_all_configs(/DNDEBUG)
431430
remove_cxx_flag_from_all_configs(/DNDEBUG)
432431
else()
433-
remove_c_flag_from_all_configs(-DNDEBUG)
434432
remove_cxx_flag_from_all_configs(-DNDEBUG)
435433

436-
# Adjust flags used by the C/CXX compiler during RELEASE builds.
434+
# Adjust flags used by the CXX compiler during RELEASE builds.
437435
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
438-
replace_c_flag_in_config(Release -O3 -O2)
439436
replace_cxx_flag_in_config(Release -O3 -O2)
440437

441438
are_flags_overridden(CMAKE_CXX_FLAGS_DEBUG cxx_flags_debug_overridden)
@@ -445,6 +442,7 @@ else()
445442
if(compiler_supports_g3)
446443
replace_cxx_flag_in_config(Debug -g -g3)
447444
endif()
445+
unset(compiler_supports_g3)
448446

449447
try_append_cxx_flags("-ftrapv" RESULT_VAR compiler_supports_ftrapv)
450448
if(compiler_supports_ftrapv)
@@ -461,24 +459,6 @@ else()
461459
)
462460
endif()
463461
unset(cxx_flags_debug_overridden)
464-
465-
are_flags_overridden(CMAKE_C_FLAGS_DEBUG c_flags_debug_overridden)
466-
if(NOT c_flags_debug_overridden)
467-
# Redefine flags used by the C compiler during DEBUG builds.
468-
if(compiler_supports_g3)
469-
replace_c_flag_in_config(Debug -g -g3)
470-
endif()
471-
472-
string(PREPEND CMAKE_C_FLAGS_DEBUG "-O0 ")
473-
474-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}"
475-
CACHE STRING
476-
"Flags used by the C compiler during DEBUG builds."
477-
FORCE
478-
)
479-
endif()
480-
unset(compiler_supports_g3)
481-
unset(c_flags_debug_overridden)
482462
endif()
483463

484464
include(cmake/optional.cmake)

cmake/module/ProcessConfigurations.cmake

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,6 @@ function(set_default_config config)
8484
endif()
8585
endfunction()
8686

87-
function(remove_c_flag_from_all_configs flag)
88-
get_all_configs(all_configs)
89-
foreach(config IN LISTS all_configs)
90-
string(TOUPPER "${config}" config_uppercase)
91-
set(flags "${CMAKE_C_FLAGS_${config_uppercase}}")
92-
separate_arguments(flags)
93-
list(FILTER flags EXCLUDE REGEX "${flag}")
94-
list(JOIN flags " " new_flags)
95-
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
96-
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}"
97-
CACHE STRING
98-
"Flags used by the C compiler during ${config_uppercase} builds."
99-
FORCE
100-
)
101-
endforeach()
102-
endfunction()
103-
10487
function(remove_cxx_flag_from_all_configs flag)
10588
get_all_configs(all_configs)
10689
foreach(config IN LISTS all_configs)
@@ -118,17 +101,6 @@ function(remove_cxx_flag_from_all_configs flag)
118101
endforeach()
119102
endfunction()
120103

121-
function(replace_c_flag_in_config config old_flag new_flag)
122-
string(TOUPPER "${config}" config_uppercase)
123-
string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_C_FLAGS_${config_uppercase}}")
124-
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
125-
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}"
126-
CACHE STRING
127-
"Flags used by the C compiler during ${config_uppercase} builds."
128-
FORCE
129-
)
130-
endfunction()
131-
132104
function(replace_cxx_flag_in_config config old_flag new_flag)
133105
string(TOUPPER "${config}" config_uppercase)
134106
string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_CXX_FLAGS_${config_uppercase}}")

0 commit comments

Comments
 (0)