diff --git a/CMakeLists.txt b/CMakeLists.txt index 75f7e70e59e44..798276785c356 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,6 +496,9 @@ if(CMAKE_CROSSCOMPILING) if(DEFINED ENV{CXXFLAGS}) deduplicate_flags(CMAKE_CXX_FLAGS) endif() + if(DEFINED ENV{LDFLAGS}) + deduplicate_flags(CMAKE_EXE_LINKER_FLAGS) + endif() endif() add_subdirectory(src) @@ -507,6 +510,7 @@ include(Maintenance) setup_split_debug_script() add_maintenance_targets() add_windows_deploy_target() +add_macos_deploy_target() include(GetTargetInterface) diff --git a/cmake/module/Maintenance.cmake b/cmake/module/Maintenance.cmake index b552e408658dd..2834bdbb2f95f 100644 --- a/cmake/module/Maintenance.cmake +++ b/cmake/module/Maintenance.cmake @@ -88,3 +88,64 @@ function(add_windows_deploy_target) add_custom_target(deploy DEPENDS ${CMAKE_BINARY_DIR}/bitcoin-win64-setup.exe) endif() endfunction() + +function(add_macos_deploy_target) + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND TARGET bitcoin-qt) + set(macos_app "Bitcoin-Qt.app") + # Populate Contents subdirectory. + configure_file(${PROJECT_SOURCE_DIR}/share/qt/Info.plist.in ${macos_app}/Contents/Info.plist) + file(CONFIGURE OUTPUT ${macos_app}/Contents/PkgInfo CONTENT "APPL????") + # Populate Contents/Resources subdirectory. + file(CONFIGURE OUTPUT ${macos_app}/Contents/Resources/empty.lproj CONTENT "") + configure_file(${PROJECT_SOURCE_DIR}/src/qt/res/icons/bitcoin.icns ${macos_app}/Contents/Resources/bitcoin.icns COPYONLY) + file(CONFIGURE OUTPUT ${macos_app}/Contents/Resources/Base.lproj/InfoPlist.strings + CONTENT "{ CFBundleDisplayName = \"@PACKAGE_NAME@\"; CFBundleName = \"@PACKAGE_NAME@\"; }" + ) + + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt + COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --config $ --component GUI --prefix ${macos_app}/Contents/MacOS --strip + COMMAND ${CMAKE_COMMAND} -E rename ${macos_app}/Contents/MacOS/bin/$ ${macos_app}/Contents/MacOS/Bitcoin-Qt + COMMAND ${CMAKE_COMMAND} -E rm -rf ${macos_app}/Contents/MacOS/bin + VERBATIM + ) + + string(REPLACE " " "-" osx_volname ${PACKAGE_NAME}) + if(CMAKE_CROSSCOMPILING) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/dist/${macos_app}/Contents/MacOS/Bitcoin-Qt + COMMAND INSTALL_NAME_TOOL=${CMAKE_INSTALL_NAME_TOOL} OTOOL=${OTOOL} STRIP=${CMAKE_STRIP} ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt + VERBATIM + ) + add_custom_target(deploydir + DEPENDS ${CMAKE_BINARY_DIR}/dist/${macos_app}/Contents/MacOS/Bitcoin-Qt + ) + + find_program(ZIP_COMMAND zip REQUIRED) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/dist/${osx_volname}.zip + WORKING_DIRECTORY dist + COMMAND ${PROJECT_SOURCE_DIR}/cmake/script/macos_zip.sh ${ZIP_COMMAND} ${osx_volname}.zip + VERBATIM + ) + add_custom_target(deploy + DEPENDS ${CMAKE_BINARY_DIR}/dist/${osx_volname}.zip + ) + add_dependencies(deploy deploydir) + else() + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/${osx_volname}.zip + COMMAND ${PYTHON_COMMAND} ${CMAKE_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} -zip + DEPENDS ${macos_app}/Contents/MacOS/Bitcoin-Qt + VERBATIM + ) + add_custom_target(deploydir + DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip + ) + add_custom_target(deploy + DEPENDS ${CMAKE_BINARY_DIR}/${osx_volname}.zip + ) + endif() + endif() +endfunction() diff --git a/cmake/script/macos_zip.sh b/cmake/script/macos_zip.sh new file mode 100755 index 0000000000000..5a42d1bbf4077 --- /dev/null +++ b/cmake/script/macos_zip.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +if [ -n "$SOURCE_DATE_EPOCH" ]; then + find . -exec touch -d "@$SOURCE_DATE_EPOCH" {} + +fi + +find . | sort | "$1" -X@ "$2" diff --git a/contrib/guix/guix-build b/contrib/guix/guix-build index 731355598cb13..870938cb52acf 100755 --- a/contrib/guix/guix-build +++ b/contrib/guix/guix-build @@ -75,12 +75,9 @@ mkdir -p "$VERSION_BASE" # Default to building for all supported HOSTs (overridable by environment) # powerpc64le-linux-gnu currently disabled due non-determinism issues across build arches. -# TODO: Re-enable macOS hosts. -# export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu -# x86_64-w64-mingw32 -# x86_64-apple-darwin arm64-apple-darwin}" export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu - x86_64-w64-mingw32}" + x86_64-w64-mingw32 + x86_64-apple-darwin arm64-apple-darwin}" # Usage: distsrc_for_host HOST # diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh index ad189d591fc5c..ed47af6603f85 100755 --- a/contrib/guix/libexec/build.sh +++ b/contrib/guix/libexec/build.sh @@ -284,7 +284,7 @@ mkdir -p "$DISTSRC" # Install built Bitcoin Core to $INSTALLPATH case "$HOST" in *darwin*) - make install-strip DESTDIR="${INSTALLPATH}" ${V:+V=1} + cmake --install build --strip --prefix "${INSTALLPATH}" ${V:+--verbose} ;; *) cmake --install build --prefix "${INSTALLPATH}" ${V:+--verbose} @@ -293,13 +293,12 @@ mkdir -p "$DISTSRC" case "$HOST" in *darwin*) - make osx_volname ${V:+V=1} - make deploydir ${V:+V=1} + cmake --build build --target deploy ${V:+--verbose} + mv build/dist/Bitcoin-Core.zip "${OUTDIR}/${DISTNAME}-${HOST}-unsigned.zip" mkdir -p "unsigned-app-${HOST}" cp --target-directory="unsigned-app-${HOST}" \ - osx_volname \ contrib/macdeploy/detached-sig-create.sh - mv --target-directory="unsigned-app-${HOST}" dist + mv --target-directory="unsigned-app-${HOST}" build/dist ( cd "unsigned-app-${HOST}" find . -print0 \ @@ -308,7 +307,6 @@ mkdir -p "$DISTSRC" | gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST}-unsigned.tar.gz" \ || ( rm -f "${OUTDIR}/${DISTNAME}-${HOST}-unsigned.tar.gz" && exit 1 ) ) - make deploy ${V:+V=1} OSX_ZIP="${OUTDIR}/${DISTNAME}-${HOST}-unsigned.zip" ;; esac ( @@ -389,7 +387,7 @@ mkdir -p "$DISTSRC" case "$HOST" in *mingw*) - cp -rf --target-directory=. "${DISTSRC}/contrib/windeploy" + cp -rf --target-directory=. contrib/windeploy ( cd ./windeploy mkdir -p unsigned diff --git a/depends/Makefile b/depends/Makefile index f75a1822c045a..6492de79564e5 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -282,6 +282,9 @@ $(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_ -e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS))|' \ -e 's|@CPPFLAGS_RELEASE@|$(strip $(host_release_CPPFLAGS))|' \ -e 's|@CPPFLAGS_DEBUG@|$(strip $(host_debug_CPPFLAGS))|' \ + -e 's|@LDFLAGS@|$(strip $(host_LDFLAGS))|' \ + -e 's|@LDFLAGS_RELEASE@|$(strip $(host_release_LDFLAGS))|' \ + -e 's|@LDFLAGS_DEBUG@|$(strip $(host_debug_LDFLAGS))|' \ -e 's|@no_qt@|$(NO_QT)|' \ -e 's|@no_qr@|$(NO_QR)|' \ -e 's|@no_zmq@|$(NO_ZMQ)|' \ diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index 9ff2bbeb51e12..4771d80005efa 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -73,6 +73,16 @@ set(DEPENDS_COMPILE_DEFINITIONS @CPPFLAGS@) set(DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO @CPPFLAGS_RELEASE@) set(DEPENDS_COMPILE_DEFINITIONS_DEBUG @CPPFLAGS_DEBUG@) +if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT) + set(CMAKE_EXE_LINKER_FLAGS_INIT "@LDFLAGS@") +endif() +if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT) + set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "@LDFLAGS_RELEASE@") +endif() +if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT) + set(CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "@LDFLAGS_DEBUG@") +endif() + set(CMAKE_AR "@AR@") set(CMAKE_RANLIB "@RANLIB@") set(CMAKE_STRIP "@STRIP@")