From 282b4913c7e4d4b5a141c9f89da97a65ee86bdd9 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 15 May 2025 13:57:57 +0100 Subject: [PATCH] cmake: Add application manifests when cross-compiling for Windows Windows application manifests provide several benefits. However, on the master branch, the linker generates and embeds manifests only when building with MSVC. This change unifies manifest embedding for both native and cross-compilation. --- CMakeLists.txt | 4 ++++ cmake/module/AddWindowsResources.cmake | 17 +++++++++++++++-- cmake/windows-app.manifest.in | 15 +++++++++++++++ src/CMakeLists.txt | 5 +++++ src/qt/CMakeLists.txt | 1 + src/test/CMakeLists.txt | 2 ++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 cmake/windows-app.manifest.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 69f23d44b16..7b88987caf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,6 +276,10 @@ if(WIN32) /Zc:__cplusplus /sdl ) + target_link_options(core_interface INTERFACE + # We embed our own manifests. + /MANIFEST:NO + ) # Improve parallelism in MSBuild. # See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/. list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true") diff --git a/cmake/module/AddWindowsResources.cmake b/cmake/module/AddWindowsResources.cmake index a9b4f51f73d..5c69d968897 100644 --- a/cmake/module/AddWindowsResources.cmake +++ b/cmake/module/AddWindowsResources.cmake @@ -4,11 +4,24 @@ include_guard(GLOBAL) -macro(add_windows_resources target rc_file) +function(add_windows_resources target rc_file) if(WIN32) target_sources(${target} PRIVATE ${rc_file}) set_property(SOURCE ${rc_file} APPEND PROPERTY COMPILE_DEFINITIONS WINDRES_PREPROC ) endif() -endmacro() +endfunction() + +# Add a fusion manifest to Windows executables. +# See: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests +function(add_windows_application_manifest target) + if(WIN32) + configure_file(${PROJECT_SOURCE_DIR}/cmake/windows-app.manifest.in ${target}.manifest USE_SOURCE_PERMISSIONS) + file(CONFIGURE + OUTPUT ${target}-manifest.rc + CONTENT "1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ \"${target}.manifest\"" + ) + add_windows_resources(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}-manifest.rc) + endif() +endfunction() diff --git a/cmake/windows-app.manifest.in b/cmake/windows-app.manifest.in new file mode 100644 index 00000000000..c3bd333a227 --- /dev/null +++ b/cmake/windows-app.manifest.in @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dac8872080a..82bb4de460a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -206,6 +206,7 @@ if(ENABLE_WALLET) wallet/wallettool.cpp ) add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc) + add_windows_application_manifest(bitcoin-wallet) target_link_libraries(bitcoin-wallet core_interface bitcoin_wallet @@ -339,6 +340,7 @@ if(BUILD_DAEMON) init/bitcoind.cpp ) add_windows_resources(bitcoind bitcoind-res.rc) + add_windows_application_manifest(bitcoind) target_link_libraries(bitcoind core_interface bitcoin_node @@ -392,6 +394,7 @@ target_link_libraries(bitcoin_cli if(BUILD_CLI) add_executable(bitcoin-cli bitcoin-cli.cpp) add_windows_resources(bitcoin-cli bitcoin-cli-res.rc) + add_windows_application_manifest(bitcoin-cli) target_link_libraries(bitcoin-cli core_interface bitcoin_cli @@ -407,6 +410,7 @@ endif() if(BUILD_TX) add_executable(bitcoin-tx bitcoin-tx.cpp) add_windows_resources(bitcoin-tx bitcoin-tx-res.rc) + add_windows_application_manifest(bitcoin-tx) target_link_libraries(bitcoin-tx core_interface bitcoin_common @@ -420,6 +424,7 @@ endif() if(BUILD_UTIL) add_executable(bitcoin-util bitcoin-util.cpp) add_windows_resources(bitcoin-util bitcoin-util-res.rc) + add_windows_application_manifest(bitcoin-util) target_link_libraries(bitcoin-util core_interface bitcoin_common diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 7379a1f328e..6c853cbf2f8 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -256,6 +256,7 @@ add_executable(bitcoin-qt ) add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc) +add_windows_application_manifest(bitcoin-qt) target_link_libraries(bitcoin-qt core_interface diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index ce9f3218879..6ce33621af8 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -142,6 +142,8 @@ target_raw_data_sources(test_bitcoin NAMESPACE test::data data/asmap.raw ) +add_windows_application_manifest(test_bitcoin) + target_link_libraries(test_bitcoin core_interface test_util