Skip to content

Commit

Permalink
cmake: Add platform-specific flags
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 2, 2023
1 parent e0621e9 commit 3736470
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ set(configure_warnings)
# It is intended to be a usage requirement for all other targets.
add_library(core INTERFACE)

include(TryAppendLinkerFlag)

if(WIN32)
#[=[
This build system supports two ways to build binaries for Windows.
Expand Down Expand Up @@ -126,14 +128,29 @@ if(WIN32)
_MT
)
# We require Windows 7 (NT 6.1) or later.
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
try_append_linker_flag(core "-Wl,--major-subsystem-version,6")
try_append_linker_flag(core "-Wl,--minor-subsystem-version,1")
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
_FILE_OFFSET_BITS=64
)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(core 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(core "-Wl,-dead_strip")
try_append_linker_flag(core "-Wl,-dead_strip_dylibs")
try_append_linker_flag(core "-Wl,-headerpad_max_install_names")
endif()

if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
Expand Down Expand Up @@ -230,6 +247,8 @@ else()
set(common_link_options)
endif()
message("Common link options ................... ${common_link_options}")
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}")
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
if(DEFINED CMAKE_BUILD_TYPE)
message("Build type:")
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
Expand Down
4 changes: 4 additions & 0 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ if(NOT CMAKE_OBJCXX_COMPILER)
endif()
set(CMAKE_OBJCXX_FLAGS_INIT "${DEPENDS_OBJCXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")
endif()

set(CMAKE_AR "@AR@")
set(CMAKE_RANLIB "@RANLIB@")
set(CMAKE_STRIP "@STRIP@")
Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ if(BUILD_DAEMON)
core
bitcoin_node
)
target_link_options(bitcoind
PRIVATE
$<$<BOOL:${MINGW}>:-static>
)
endif()


Expand Down

0 comments on commit 3736470

Please sign in to comment.