From c2764dbb99e7b8769df6814cf71beaeb59552701 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:46:42 +0100 Subject: [PATCH 1/2] cmake: Rename `SECP256K1_LATE_CFLAGS` to `SECP256K1_APPEND_CFLAGS` This change follows the naming convention currently used in the Bitcoin Core's CMake staging branch. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef2b07a11f..26ca2e8f95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,14 +284,14 @@ 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.") +set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system.") include(AllTargetsCompileOptions) add_subdirectory(src) -all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS}") +all_targets_compile_options(src "${SECP256K1_APPEND_CFLAGS}") if(SECP256K1_BUILD_EXAMPLES) add_subdirectory(examples) - all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS}") + all_targets_compile_options(examples "${SECP256K1_APPEND_CFLAGS}") endif() message("\n") @@ -365,8 +365,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) From 4706be2cd0bcac97da10ed3b98790f1ac6f04efb Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:45:07 +0100 Subject: [PATCH 2/2] cmake: Reimplement `SECP256K1_APPEND_CFLAGS` using Bitcoin Core approach --- CMakeLists.txt | 10 ++++++---- cmake/AllTargetsCompileOptions.cmake | 12 ------------ 2 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 cmake/AllTargetsCompileOptions.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 26ca2e8f95..d91c50d7a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,14 +284,16 @@ if(SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUST enable_testing() endif() -set(SECP256K1_APPEND_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_APPEND_CFLAGS}") if(SECP256K1_BUILD_EXAMPLES) add_subdirectory(examples) - all_targets_compile_options(examples "${SECP256K1_APPEND_CFLAGS}") endif() message("\n") diff --git a/cmake/AllTargetsCompileOptions.cmake b/cmake/AllTargetsCompileOptions.cmake deleted file mode 100644 index 6e420e0fde..0000000000 --- a/cmake/AllTargetsCompileOptions.cmake +++ /dev/null @@ -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()