From 131db281e79e566dcad799a8b438d4f2b860170d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:51:22 +0000 Subject: [PATCH] FIXUP: Introduce core_base_interface The core_base_interface does not have C++-specific compiler options. --- CMakeLists.txt | 48 +++++++++++++++++++++++-------------------- cmake/secp256k1.cmake | 4 +++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5502e7fb2207..4e1ad82019d89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,10 @@ unset(check_pie_output) # The core_interface library aims to encapsulate common build flags. # It is intended to be a usage requirement for all other targets. add_library(core_interface INTERFACE) +# The core_base_interface library does not include warn_interface, +# which is useful for compiling C code in the secp256k1 subtree. +add_library(core_base_interface INTERFACE) +target_link_libraries(core_interface INTERFACE core_base_interface) include(TryAppendCXXFlags) include(TryAppendLinkerFlag) @@ -131,7 +135,7 @@ if(WIN32) - A run-time library must be specified explicitly using _MT definition. ]=] - target_compile_definitions(core_interface INTERFACE + target_compile_definitions(core_base_interface INTERFACE _WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN @@ -139,7 +143,7 @@ if(WIN32) ) if(MSVC) - target_compile_definitions(core_interface INTERFACE + target_compile_definitions(core_base_interface INTERFACE _UNICODE;UNICODE ) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") @@ -153,52 +157,52 @@ if(WIN32) endif() if(MINGW) - target_compile_definitions(core_interface INTERFACE + target_compile_definitions(core_base_interface INTERFACE WIN32 _WINDOWS _MT ) # Avoid the use of aligned vector instructions when building for Windows. # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412. - try_append_cxx_flags("-Wa,-muse-unaligned-vector-move" TARGET core_interface) - try_append_linker_flag("-static" TARGET core_interface) + try_append_cxx_flags("-Wa,-muse-unaligned-vector-move" TARGET core_base_interface) + try_append_linker_flag("-static" TARGET core_base_interface) # We require Windows 7 (NT 6.1) or later. - try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_interface) - try_append_linker_flag("-Wl,--minor-subsystem-version,1" TARGET core_interface) + try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_base_interface) + try_append_linker_flag("-Wl,--minor-subsystem-version,1" TARGET core_base_interface) endif() endif() # Use 64-bit off_t on 32-bit Linux. if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4) # Ensure 64-bit offsets are used for filesystem accesses for 32-bit compilation. - target_compile_definitions(core_interface INTERFACE + target_compile_definitions(core_base_interface INTERFACE _FILE_OFFSET_BITS=64 ) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - target_compile_definitions(core_interface INTERFACE + target_compile_definitions(core_base_interface INTERFACE MAC_OSX ) # These flags are specific to ld64, and may cause issues with other linkers. # For example: GNU ld will interpret -dead_strip as -de and then try and use # "ad_strip" as the symbol for the entry point. - try_append_linker_flag("-Wl,-dead_strip" TARGET core_interface) - try_append_linker_flag("-Wl,-dead_strip_dylibs" TARGET core_interface) - try_append_linker_flag("-Wl,-headerpad_max_install_names" TARGET core_interface) + try_append_linker_flag("-Wl,-dead_strip" TARGET core_base_interface) + try_append_linker_flag("-Wl,-dead_strip_dylibs" TARGET core_base_interface) + try_append_linker_flag("-Wl,-headerpad_max_install_names" TARGET core_base_interface) endif() if(CMAKE_CROSSCOMPILING) - target_compile_definitions(core_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS}) - target_compile_options(core_interface INTERFACE "$<$:${DEPENDS_C_COMPILER_FLAGS}>") - target_compile_options(core_interface INTERFACE "$<$:${DEPENDS_CXX_COMPILER_FLAGS}>") + target_compile_definitions(core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS}) + target_compile_options(core_base_interface INTERFACE "$<$:${DEPENDS_C_COMPILER_FLAGS}>") + target_compile_options(core_base_interface INTERFACE "$<$:${DEPENDS_CXX_COMPILER_FLAGS}>") endif() include(AddThreadsIfNeeded) add_threads_if_needed() add_library(sanitizing_interface INTERFACE) -target_link_libraries(core_interface INTERFACE sanitizing_interface) +target_link_libraries(core_base_interface INTERFACE sanitizing_interface) if(SANITIZERS) # First check if the compiler accepts flags. If an incompatible pair like # -fsanitize=address,thread is used here, this check will fail. This will also @@ -302,7 +306,7 @@ include(ProcessConfigurations) set_default_config(RelWithDebInfo) # Redefine configuration flags. -target_compile_definitions(core_interface INTERFACE +target_compile_definitions(core_base_interface INTERFACE $<$:DEBUG> $<$:DEBUG_LOCKORDER> $<$:DEBUG_LOCKCONTENTION> @@ -336,17 +340,17 @@ endif() include(cmake/optional.cmake) # Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. -try_append_cxx_flags("-fno-extended-identifiers" TARGET core_interface) +try_append_cxx_flags("-fno-extended-identifiers" TARGET core_base_interface) # Currently all versions of gcc are subject to a class of bugs, see the # gccbug_90348 test case (only reproduces on GCC 11 and earlier) and # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111843. To work around that, set # -fstack-reuse=none for all gcc builds. (Only gcc understands this flag). -try_append_cxx_flags("-fstack-reuse=none" TARGET core_interface) +try_append_cxx_flags("-fstack-reuse=none" TARGET core_base_interface) if(HARDENING) add_library(hardening_interface INTERFACE) - target_link_libraries(core_interface INTERFACE hardening_interface) + target_link_libraries(core_base_interface INTERFACE hardening_interface) if(MSVC) try_append_linker_flag("/DYNAMICBASE" TARGET hardening_interface) try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface) @@ -389,7 +393,7 @@ endif() if(REDUCE_EXPORTS) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) - try_append_linker_flag("-Wl,--exclude-libs,ALL" TARGET core_interface) + try_append_linker_flag("-Wl,--exclude-libs,ALL" TARGET core_base_interface) endif() if(WERROR) @@ -398,7 +402,7 @@ if(WERROR) else() set(werror_flag "-Werror") endif() - try_append_cxx_flags(${werror_flag} TARGET core_interface RESULT_VAR compiler_supports_werror) + try_append_cxx_flags(${werror_flag} TARGET core_base_interface RESULT_VAR compiler_supports_werror) if(NOT compiler_supports_werror) message(FATAL_ERROR "WERROR set but ${werror_flag} is not usable.") endif() diff --git a/cmake/secp256k1.cmake b/cmake/secp256k1.cmake index 5b932cc4c6bc1..ef93cd064cd9a 100644 --- a/cmake/secp256k1.cmake +++ b/cmake/secp256k1.cmake @@ -57,4 +57,6 @@ if(MSVC) ) endif() -target_link_libraries(secp256k1 PRIVATE core_interface) +# Using core_base_interface instead of core_interface +# to avoid C++-specific flags from warn_interface. +target_link_libraries(secp256k1 PRIVATE core_base_interface)