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 Jul 16, 2023
1 parent 908b1a3 commit 103637a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(configure_warnings)

include(TryAppendLinkerFlag)

if(WIN32)
#[=[
This build system supports two ways to build binaries for Windows.
Expand All @@ -106,13 +108,32 @@ if(WIN32)

if(MINGW)
add_compile_definitions(WIN32 _WINDOWS _MT)
set(mingw_linker_flags "")
# 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(mingw_linker_flags "-Wl,--major-subsystem-version,6")
try_append_linker_flag(mingw_linker_flags "-Wl,--minor-subsystem-version,1")
separate_arguments(mingw_linker_flags)
add_link_options(${mingw_linker_flags})
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.
add_compile_definitions(_FILE_OFFSET_BITS=64)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions(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.
set(macos_linker_flags "")
try_append_linker_flag(macos_linker_flags "-Wl,-dead_strip")
try_append_linker_flag(macos_linker_flags "-Wl,-dead_strip_dylibs")
try_append_linker_flag(macos_linker_flags "-Wl,-headerpad_max_install_names")
separate_arguments(macos_linker_flags)
add_link_options(${macos_linker_flags})
endif()

if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
Expand Down Expand Up @@ -200,6 +221,8 @@ message("Common compile options ................ ${common_compile_options}")
get_directory_property(common_link_options LINK_OPTIONS)
string(REPLACE ";" " " common_link_options "${common_link_options}")
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 @@ -235,10 +235,6 @@ if(BUILD_DAEMON)
PRIVATE
bitcoin_node
)
target_link_options(bitcoind
PRIVATE
$<$<BOOL:${MINGW}>:-static>
)
endif()


Expand Down

0 comments on commit 103637a

Please sign in to comment.