Skip to content

Commit 3736470

Browse files
committed
cmake: Add platform-specific flags
1 parent e0621e9 commit 3736470

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ set(configure_warnings)
8484
# It is intended to be a usage requirement for all other targets.
8585
add_library(core INTERFACE)
8686

87+
include(TryAppendLinkerFlag)
88+
8789
if(WIN32)
8890
#[=[
8991
This build system supports two ways to build binaries for Windows.
@@ -126,14 +128,29 @@ if(WIN32)
126128
_MT
127129
)
128130
# We require Windows 7 (NT 6.1) or later.
129-
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
131+
try_append_linker_flag(core "-Wl,--major-subsystem-version,6")
132+
try_append_linker_flag(core "-Wl,--minor-subsystem-version,1")
130133
endif()
131134
endif()
132135

136+
# Use 64-bit off_t on 32-bit Linux.
137+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
138+
# Ensure 64-bit offsets are used for filesystem accesses for 32-bit compilation.
139+
target_compile_definitions(core INTERFACE
140+
_FILE_OFFSET_BITS=64
141+
)
142+
endif()
143+
133144
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
134145
target_compile_definitions(core INTERFACE
135146
MAC_OSX
136147
)
148+
# These flags are specific to ld64, and may cause issues with other linkers.
149+
# For example: GNU ld will interpret -dead_strip as -de and then try and use
150+
# "ad_strip" as the symbol for the entry point.
151+
try_append_linker_flag(core "-Wl,-dead_strip")
152+
try_append_linker_flag(core "-Wl,-dead_strip_dylibs")
153+
try_append_linker_flag(core "-Wl,-headerpad_max_install_names")
137154
endif()
138155

139156
if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
@@ -230,6 +247,8 @@ else()
230247
set(common_link_options)
231248
endif()
232249
message("Common link options ................... ${common_link_options}")
250+
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}")
251+
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
233252
if(DEFINED CMAKE_BUILD_TYPE)
234253
message("Build type:")
235254
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")

depends/toolchain.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ if(NOT CMAKE_OBJCXX_COMPILER)
7373
endif()
7474
set(CMAKE_OBJCXX_FLAGS_INIT "${DEPENDS_OBJCXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@")
7575

76+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
77+
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")
78+
endif()
79+
7680
set(CMAKE_AR "@AR@")
7781
set(CMAKE_RANLIB "@RANLIB@")
7882
set(CMAKE_STRIP "@STRIP@")

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ if(BUILD_DAEMON)
243243
core
244244
bitcoin_node
245245
)
246-
target_link_options(bitcoind
247-
PRIVATE
248-
$<$<BOOL:${MINGW}>:-static>
249-
)
250246
endif()
251247

252248

0 commit comments

Comments
 (0)