mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-01 00:19:07 +02:00
1f9b2e150ce5aa192226d2daae73f7d678c47d65 cmake: Require `zip` only for `deploy` target (Hennadii Stepanov) 0aeff2995138c247f1b1f843c30eb547e199f5f7 cmake: Check for `makensis` tool before using it (Hennadii Stepanov) Pull request description: For `x86_64-w64-mingw32` and `*-apple-darwin` targets, the optional `deploy` target requires dedicated tools: `makensis` and `zip`, respectively. This PR introduces a uniform checks for those tools when attempting to build the `deploy` target, ensuring they are not required for configuring and building any other targets. Here is an example of workflow for `x86_64-w64-mingw32`: ``` $ # `nsis` is not installed $ cmake -B build -G "GNU Makefiles" --toolchain depends/x86_64-w64-mingw32/toolchain.cmake $ cmake --build build -j $(nproc) $ cmake --build build -t deploy Error: NSIS not found. Please install NSIS and/or ensure that its executable is accessible to the find_program() command— for example, by setting the MAKENSIS_EXECUTABLE variable or another relevant CMake variable. Then re-run cmake to regenerate the build system. Built target deploy $ sudo apt install nsis $ cmake -B build $ cmake --build build -t deploy ... [100%] Generating bitcoin-win64-setup.exe [100%] Built target deploy ``` Fixes https://github.com/bitcoin/bitcoin/issues/32018. ACKs for top commit: hodlinator: re-ACK 1f9b2e150ce5aa192226d2daae73f7d678c47d65 fanquake: ACK 1f9b2e150ce5aa192226d2daae73f7d678c47d65 Tree-SHA512: 5e2bd28a13bd8fa7c4ba8cf1756d200a4651afe83c463d76ece10027cca343e124eff97012a5368028f761df60f420ab891106b4e33b50045051d57c7464ff98
144 lines
6.3 KiB
CMake
144 lines
6.3 KiB
CMake
# Copyright (c) 2023-present The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or https://opensource.org/license/mit/.
|
|
|
|
include_guard(GLOBAL)
|
|
|
|
function(setup_split_debug_script)
|
|
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
|
|
set(OBJCOPY ${CMAKE_OBJCOPY})
|
|
set(STRIP ${CMAKE_STRIP})
|
|
configure_file(
|
|
contrib/devtools/split-debug.sh.in split-debug.sh
|
|
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE
|
|
GROUP_READ GROUP_EXECUTE
|
|
WORLD_READ
|
|
@ONLY
|
|
)
|
|
endif()
|
|
endfunction()
|
|
|
|
function(add_maintenance_targets)
|
|
if(NOT PYTHON_COMMAND)
|
|
return()
|
|
endif()
|
|
|
|
foreach(target IN ITEMS bitcoind bitcoin-qt bitcoin-cli bitcoin-tx bitcoin-util bitcoin-wallet test_bitcoin bench_bitcoin)
|
|
if(TARGET ${target})
|
|
list(APPEND executables $<TARGET_FILE:${target}>)
|
|
endif()
|
|
endforeach()
|
|
|
|
add_custom_target(check-symbols
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Running symbol and dynamic library checks..."
|
|
COMMAND ${PYTHON_COMMAND} ${PROJECT_SOURCE_DIR}/contrib/devtools/symbol-check.py ${executables}
|
|
VERBATIM
|
|
)
|
|
|
|
add_custom_target(check-security
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Checking binary security..."
|
|
COMMAND ${PYTHON_COMMAND} ${PROJECT_SOURCE_DIR}/contrib/devtools/security-check.py ${executables}
|
|
VERBATIM
|
|
)
|
|
endfunction()
|
|
|
|
function(add_windows_deploy_target)
|
|
if(MINGW AND TARGET bitcoin-qt AND TARGET bitcoind AND TARGET bitcoin-cli AND TARGET bitcoin-tx AND TARGET bitcoin-wallet AND TARGET bitcoin-util AND TARGET test_bitcoin)
|
|
find_program(MAKENSIS_EXECUTABLE makensis)
|
|
if(NOT MAKENSIS_EXECUTABLE)
|
|
add_custom_target(deploy
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Error: NSIS not found"
|
|
)
|
|
return()
|
|
endif()
|
|
|
|
# TODO: Consider replacing this code with the CPack NSIS Generator.
|
|
# See https://cmake.org/cmake/help/latest/cpack_gen/nsis.html
|
|
include(GenerateSetupNsi)
|
|
generate_setup_nsi()
|
|
add_custom_command(
|
|
OUTPUT ${PROJECT_BINARY_DIR}/bitcoin-win64-setup.exe
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/release
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoin-qt> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoin-qt>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoind> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoind>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoin-cli> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoin-cli>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoin-tx> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoin-tx>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoin-wallet> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoin-wallet>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:bitcoin-util> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:bitcoin-util>
|
|
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:test_bitcoin> -o ${PROJECT_BINARY_DIR}/release/$<TARGET_FILE_NAME:test_bitcoin>
|
|
COMMAND ${MAKENSIS_EXECUTABLE} -V2 ${PROJECT_BINARY_DIR}/bitcoin-win64-setup.nsi
|
|
VERBATIM
|
|
)
|
|
add_custom_target(deploy DEPENDS ${PROJECT_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 NO_SOURCE_PERMISSIONS)
|
|
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 NO_SOURCE_PERMISSIONS COPYONLY)
|
|
file(CONFIGURE OUTPUT ${macos_app}/Contents/Resources/Base.lproj/InfoPlist.strings
|
|
CONTENT "{ CFBundleDisplayName = \"@CLIENT_NAME@\"; CFBundleName = \"@CLIENT_NAME@\"; }"
|
|
)
|
|
|
|
add_custom_command(
|
|
OUTPUT ${PROJECT_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --config $<CONFIG> --component bitcoin-qt --prefix ${macos_app}/Contents/MacOS --strip
|
|
COMMAND ${CMAKE_COMMAND} -E rename ${macos_app}/Contents/MacOS/bin/$<TARGET_FILE_NAME:bitcoin-qt> ${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
COMMAND ${CMAKE_COMMAND} -E rm -rf ${macos_app}/Contents/MacOS/bin
|
|
COMMAND ${CMAKE_COMMAND} -E rm -rf ${macos_app}/Contents/MacOS/share
|
|
VERBATIM
|
|
)
|
|
|
|
string(REPLACE " " "-" osx_volname ${CLIENT_NAME})
|
|
if(CMAKE_HOST_APPLE)
|
|
add_custom_command(
|
|
OUTPUT ${PROJECT_BINARY_DIR}/${osx_volname}.zip
|
|
COMMAND ${PYTHON_COMMAND} ${PROJECT_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR} -zip
|
|
DEPENDS ${PROJECT_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
VERBATIM
|
|
)
|
|
add_custom_target(deploydir
|
|
DEPENDS ${PROJECT_BINARY_DIR}/${osx_volname}.zip
|
|
)
|
|
add_custom_target(deploy
|
|
DEPENDS ${PROJECT_BINARY_DIR}/${osx_volname}.zip
|
|
)
|
|
else()
|
|
add_custom_command(
|
|
OUTPUT ${PROJECT_BINARY_DIR}/dist/${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
COMMAND OBJDUMP=${CMAKE_OBJDUMP} ${PYTHON_COMMAND} ${PROJECT_SOURCE_DIR}/contrib/macdeploy/macdeployqtplus ${macos_app} ${osx_volname} -translations-dir=${QT_TRANSLATIONS_DIR}
|
|
DEPENDS ${PROJECT_BINARY_DIR}/${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
VERBATIM
|
|
)
|
|
add_custom_target(deploydir
|
|
DEPENDS ${PROJECT_BINARY_DIR}/dist/${macos_app}/Contents/MacOS/Bitcoin-Qt
|
|
)
|
|
|
|
find_program(ZIP_EXECUTABLE zip)
|
|
if(NOT ZIP_EXECUTABLE)
|
|
add_custom_target(deploy
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Error: ZIP not found"
|
|
)
|
|
else()
|
|
add_custom_command(
|
|
OUTPUT ${PROJECT_BINARY_DIR}/dist/${osx_volname}.zip
|
|
WORKING_DIRECTORY dist
|
|
COMMAND ${PROJECT_SOURCE_DIR}/cmake/script/macos_zip.sh ${ZIP_EXECUTABLE} ${osx_volname}.zip
|
|
VERBATIM
|
|
)
|
|
add_custom_target(deploy
|
|
DEPENDS ${PROJECT_BINARY_DIR}/dist/${osx_volname}.zip
|
|
)
|
|
endif()
|
|
endif()
|
|
add_dependencies(deploydir bitcoin-qt)
|
|
add_dependencies(deploy deploydir)
|
|
endif()
|
|
endfunction()
|