Merge bitcoin-core/secp256k1#1546: cmake: Rename SECP256K1_LATE_CFLAGS and switch to Bitcoin Core's approach
4706be2cd0cmake: Reimplement `SECP256K1_APPEND_CFLAGS` using Bitcoin Core approach (Hennadii Stepanov)c2764dbb99cmake: Rename `SECP256K1_LATE_CFLAGS` to `SECP256K1_APPEND_CFLAGS` (Hennadii Stepanov) Pull request description: This PR address this https://github.com/hebasto/bitcoin/issues/239#issuecomment-2182713690: > For consistency with libsecp256k1: > > > > Is this code block supposed to achieve the same as our `SECP256K1_LATE_CFLAGS` (implemented by a user-defined function `all_targets_add_compile_options`) in libsecp256k1? > > > > > > It is. But this approach guaranties to override even options that are abstracted by CMake, for instance [#157 (comment)](https://github.com/hebasto/bitcoin/pull/157#issuecomment-2090465123). > > * If we agree that appending to rule variables is superior, should we also do this in libsecp256k1? > > * And/or should we rename the `SECP256K1_LATE_CFLAGS` variable to `APPEND_CFLAGS`? ACKs for top commit: real-or-random: utACK4706be2cd0Tree-SHA512: 24603886c4d6ab4e31836a67d5759f9855a60c6c9d34cfc6fc4023bd309cd51c15d986ac0b77a434f9fdc6d5e97dcd3b8484d8f5ef5d8f840f47dc141de18084
This commit is contained in:
@@ -280,14 +280,16 @@ if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUST
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
set(SECP256K1_LATE_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system.")
|
||||
include(AllTargetsCompileOptions)
|
||||
set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")
|
||||
if(SECP256K1_APPEND_CFLAGS)
|
||||
# Appending to this low-level rule variable is the only way to
|
||||
# guarantee that the flags appear at the end of the command line.
|
||||
string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS}")
|
||||
if(SECP256K1_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS}")
|
||||
endif()
|
||||
|
||||
message("\n")
|
||||
@@ -361,8 +363,8 @@ else()
|
||||
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
||||
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
||||
endif()
|
||||
if(SECP256K1_LATE_CFLAGS)
|
||||
message("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS}")
|
||||
if(SECP256K1_APPEND_CFLAGS)
|
||||
message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}")
|
||||
endif()
|
||||
message("")
|
||||
if(print_msan_notice)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# Add compile options to all targets added in the subdirectory.
|
||||
function(all_targets_compile_options dir options)
|
||||
get_directory_property(targets DIRECTORY ${dir} BUILDSYSTEM_TARGETS)
|
||||
separate_arguments(options)
|
||||
set(compiled_target_types STATIC_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY EXECUTABLE)
|
||||
foreach(target ${targets})
|
||||
get_target_property(type ${target} TYPE)
|
||||
if(type IN_LIST compiled_target_types)
|
||||
target_compile_options(${target} PRIVATE ${options})
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user