Skip to content

Commit

Permalink
FIXUP: Introduce core_base_interface
Browse files Browse the repository at this point in the history
The core_base_interface does not have C++-specific compiler options.
  • Loading branch information
hebasto committed Jan 26, 2024
1 parent 48932db commit 131db28
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
48 changes: 26 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -131,15 +135,15 @@ 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
NOMINMAX
)

if(MSVC)
target_compile_definitions(core_interface INTERFACE
target_compile_definitions(core_base_interface INTERFACE
_UNICODE;UNICODE
)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand All @@ -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 "$<$<COMPILE_LANGUAGE:C>:${DEPENDS_C_COMPILER_FLAGS}>")
target_compile_options(core_interface INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:${DEPENDS_CXX_COMPILER_FLAGS}>")
target_compile_definitions(core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS})
target_compile_options(core_base_interface INTERFACE "$<$<COMPILE_LANGUAGE:C>:${DEPENDS_C_COMPILER_FLAGS}>")
target_compile_options(core_base_interface INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:${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
Expand Down Expand Up @@ -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
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Debug>:DEBUG_LOCKORDER>
$<$<CONFIG:Debug>:DEBUG_LOCKCONTENTION>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion cmake/secp256k1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 131db28

Please sign in to comment.