Skip to content

Commit

Permalink
cmake: Do not override user's CMAKE_C_FLAGS_RELEASE
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jun 27, 2024
1 parent 4692294 commit 90d8760
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
cmake_policy(SET CMP0092 NEW)
endif()

set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_LIST_DIR}/cmake/OverrideC.cmake)
project(libsecp256k1
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
# the API. All changes in experimental modules are treated as
Expand All @@ -16,6 +17,7 @@ project(libsecp256k1
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
LANGUAGES C
)
unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)

if(CMAKE_VERSION VERSION_LESS 3.21)
# Emulates CMake 3.21+ behavior.
Expand Down Expand Up @@ -184,8 +186,6 @@ else()
string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
string(REGEX REPLACE "-O3([ \t\r\n]*)" "-O2\\1" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
endif()

# Define custom "Coverage" build type.
Expand Down
2 changes: 2 additions & 0 deletions cmake/OverrideC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
string(REGEX REPLACE "(^| )-O3( |$)" "\\1-O2\\2" CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}")

0 comments on commit 90d8760

Please sign in to comment.