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.
This commit is contained in:
Hennadii Stepanov
2025-05-15 13:57:57 +01:00
parent 663a9cabf8
commit 282b4913c7
6 changed files with 42 additions and 2 deletions

View File

@ -276,6 +276,10 @@ if(WIN32)
/Zc:__cplusplus /Zc:__cplusplus
/sdl /sdl
) )
target_link_options(core_interface INTERFACE
# We embed our own manifests.
/MANIFEST:NO
)
# Improve parallelism in MSBuild. # Improve parallelism in MSBuild.
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/. # See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true") list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")

View File

@ -4,11 +4,24 @@
include_guard(GLOBAL) include_guard(GLOBAL)
macro(add_windows_resources target rc_file) function(add_windows_resources target rc_file)
if(WIN32) if(WIN32)
target_sources(${target} PRIVATE ${rc_file}) target_sources(${target} PRIVATE ${rc_file})
set_property(SOURCE ${rc_file} set_property(SOURCE ${rc_file}
APPEND PROPERTY COMPILE_DEFINITIONS WINDRES_PREPROC APPEND PROPERTY COMPILE_DEFINITIONS WINDRES_PREPROC
) )
endif() 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()

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="org.bitcoincore.${target}"
version="${CLIENT_VERSION_MAJOR}.${CLIENT_VERSION_MINOR}.${CLIENT_VERSION_BUILD}.0"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@ -206,6 +206,7 @@ if(ENABLE_WALLET)
wallet/wallettool.cpp wallet/wallettool.cpp
) )
add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc) add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc)
add_windows_application_manifest(bitcoin-wallet)
target_link_libraries(bitcoin-wallet target_link_libraries(bitcoin-wallet
core_interface core_interface
bitcoin_wallet bitcoin_wallet
@ -339,6 +340,7 @@ if(BUILD_DAEMON)
init/bitcoind.cpp init/bitcoind.cpp
) )
add_windows_resources(bitcoind bitcoind-res.rc) add_windows_resources(bitcoind bitcoind-res.rc)
add_windows_application_manifest(bitcoind)
target_link_libraries(bitcoind target_link_libraries(bitcoind
core_interface core_interface
bitcoin_node bitcoin_node
@ -392,6 +394,7 @@ target_link_libraries(bitcoin_cli
if(BUILD_CLI) if(BUILD_CLI)
add_executable(bitcoin-cli bitcoin-cli.cpp) add_executable(bitcoin-cli bitcoin-cli.cpp)
add_windows_resources(bitcoin-cli bitcoin-cli-res.rc) add_windows_resources(bitcoin-cli bitcoin-cli-res.rc)
add_windows_application_manifest(bitcoin-cli)
target_link_libraries(bitcoin-cli target_link_libraries(bitcoin-cli
core_interface core_interface
bitcoin_cli bitcoin_cli
@ -407,6 +410,7 @@ endif()
if(BUILD_TX) if(BUILD_TX)
add_executable(bitcoin-tx bitcoin-tx.cpp) add_executable(bitcoin-tx bitcoin-tx.cpp)
add_windows_resources(bitcoin-tx bitcoin-tx-res.rc) add_windows_resources(bitcoin-tx bitcoin-tx-res.rc)
add_windows_application_manifest(bitcoin-tx)
target_link_libraries(bitcoin-tx target_link_libraries(bitcoin-tx
core_interface core_interface
bitcoin_common bitcoin_common
@ -420,6 +424,7 @@ endif()
if(BUILD_UTIL) if(BUILD_UTIL)
add_executable(bitcoin-util bitcoin-util.cpp) add_executable(bitcoin-util bitcoin-util.cpp)
add_windows_resources(bitcoin-util bitcoin-util-res.rc) add_windows_resources(bitcoin-util bitcoin-util-res.rc)
add_windows_application_manifest(bitcoin-util)
target_link_libraries(bitcoin-util target_link_libraries(bitcoin-util
core_interface core_interface
bitcoin_common bitcoin_common

View File

@ -256,6 +256,7 @@ add_executable(bitcoin-qt
) )
add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc) add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc)
add_windows_application_manifest(bitcoin-qt)
target_link_libraries(bitcoin-qt target_link_libraries(bitcoin-qt
core_interface core_interface

View File

@ -142,6 +142,8 @@ target_raw_data_sources(test_bitcoin NAMESPACE test::data
data/asmap.raw data/asmap.raw
) )
add_windows_application_manifest(test_bitcoin)
target_link_libraries(test_bitcoin target_link_libraries(test_bitcoin
core_interface core_interface
test_util test_util