Skip to content

Commit 282b491

Browse files
committed
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.
1 parent 663a9ca commit 282b491

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ if(WIN32)
276276
/Zc:__cplusplus
277277
/sdl
278278
)
279+
target_link_options(core_interface INTERFACE
280+
# We embed our own manifests.
281+
/MANIFEST:NO
282+
)
279283
# Improve parallelism in MSBuild.
280284
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
281285
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")

cmake/module/AddWindowsResources.cmake

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44

55
include_guard(GLOBAL)
66

7-
macro(add_windows_resources target rc_file)
7+
function(add_windows_resources target rc_file)
88
if(WIN32)
99
target_sources(${target} PRIVATE ${rc_file})
1010
set_property(SOURCE ${rc_file}
1111
APPEND PROPERTY COMPILE_DEFINITIONS WINDRES_PREPROC
1212
)
1313
endif()
14-
endmacro()
14+
endfunction()
15+
16+
# Add a fusion manifest to Windows executables.
17+
# See: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests
18+
function(add_windows_application_manifest target)
19+
if(WIN32)
20+
configure_file(${PROJECT_SOURCE_DIR}/cmake/windows-app.manifest.in ${target}.manifest USE_SOURCE_PERMISSIONS)
21+
file(CONFIGURE
22+
OUTPUT ${target}-manifest.rc
23+
CONTENT "1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ \"${target}.manifest\""
24+
)
25+
add_windows_resources(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}-manifest.rc)
26+
endif()
27+
endfunction()

cmake/windows-app.manifest.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<assemblyIdentity
4+
type="win32"
5+
name="org.bitcoincore.${target}"
6+
version="${CLIENT_VERSION_MAJOR}.${CLIENT_VERSION_MINOR}.${CLIENT_VERSION_BUILD}.0"
7+
/>
8+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
9+
<security>
10+
<requestedPrivileges>
11+
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
12+
</requestedPrivileges>
13+
</security>
14+
</trustInfo>
15+
</assembly>

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ if(ENABLE_WALLET)
206206
wallet/wallettool.cpp
207207
)
208208
add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc)
209+
add_windows_application_manifest(bitcoin-wallet)
209210
target_link_libraries(bitcoin-wallet
210211
core_interface
211212
bitcoin_wallet
@@ -339,6 +340,7 @@ if(BUILD_DAEMON)
339340
init/bitcoind.cpp
340341
)
341342
add_windows_resources(bitcoind bitcoind-res.rc)
343+
add_windows_application_manifest(bitcoind)
342344
target_link_libraries(bitcoind
343345
core_interface
344346
bitcoin_node
@@ -392,6 +394,7 @@ target_link_libraries(bitcoin_cli
392394
if(BUILD_CLI)
393395
add_executable(bitcoin-cli bitcoin-cli.cpp)
394396
add_windows_resources(bitcoin-cli bitcoin-cli-res.rc)
397+
add_windows_application_manifest(bitcoin-cli)
395398
target_link_libraries(bitcoin-cli
396399
core_interface
397400
bitcoin_cli
@@ -407,6 +410,7 @@ endif()
407410
if(BUILD_TX)
408411
add_executable(bitcoin-tx bitcoin-tx.cpp)
409412
add_windows_resources(bitcoin-tx bitcoin-tx-res.rc)
413+
add_windows_application_manifest(bitcoin-tx)
410414
target_link_libraries(bitcoin-tx
411415
core_interface
412416
bitcoin_common
@@ -420,6 +424,7 @@ endif()
420424
if(BUILD_UTIL)
421425
add_executable(bitcoin-util bitcoin-util.cpp)
422426
add_windows_resources(bitcoin-util bitcoin-util-res.rc)
427+
add_windows_application_manifest(bitcoin-util)
423428
target_link_libraries(bitcoin-util
424429
core_interface
425430
bitcoin_common

src/qt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ add_executable(bitcoin-qt
256256
)
257257

258258
add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc)
259+
add_windows_application_manifest(bitcoin-qt)
259260

260261
target_link_libraries(bitcoin-qt
261262
core_interface

src/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ target_raw_data_sources(test_bitcoin NAMESPACE test::data
142142
data/asmap.raw
143143
)
144144

145+
add_windows_application_manifest(test_bitcoin)
146+
145147
target_link_libraries(test_bitcoin
146148
core_interface
147149
test_util

0 commit comments

Comments
 (0)