-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
157 lines (127 loc) · 5.88 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
cmake_minimum_required(VERSION 3.24)
set(APP_TARGET Qt6-CMake-QML)
set(APP_NAME "QML Test App")
option(APP_PACKAGE_SIGN "Enable packaging and signing of the app" OFF)
option(APP_BUNDLE "Enable bundling .appx package as .appxbundle (bundle gets signed instead of package)" OFF)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
message(STATUS "CMAKE_INSTALL_PREFIX changed to ${CMAKE_INSTALL_PREFIX} for the duration of this configuration script")
project(${APP_TARGET} VERSION 1.0.0 LANGUAGES CXX)
if(APP_PACKAGE_SIGN)
if(APP_BUNDLE)
set(package_bundle_message "packaging, bundling, and signing (the bundle)")
else()
set(package_bundle_message "packaging and signing (the package)")
endif()
# Generate PDB files (for Release build where it can be used for symbolicating crash reports)
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /Fd${APPX_PDB_SYMBOLS_DIR}/${APP_TARGET}.pdb")
# set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
# Other files: for inclusion (easy access in Qt Creator) but not for compiling
add_custom_target(non-compiled-files SOURCES
.gitignore
MakeSelfSignedCertificate.ps1
README.md
)
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
qt_standard_project_setup()
qt_add_executable(${APP_TARGET}
main.cpp
)
qt_add_qml_module(${APP_TARGET}
URI Primary
RESOURCE_PREFIX /
VERSION 1.0
QML_FILES
Main.qml
)
set_target_properties(${APP_TARGET} PROPERTIES
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_compile_definitions(${APP_TARGET} PRIVATE WINVER=0x0A00 _WIN32_WINNT=0x0A00)
target_link_libraries(${APP_TARGET}
PRIVATE
Qt6::Quick
WindowsApp
)
option(APP_INSTALL "Run install step following the build" OFF)
if (APP_INSTALL)
message(STATUS "Starting prepare for install step...")
install(TARGETS ${APP_TARGET}
BUNDLE DESTINATION .
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
if(${Qt6_VERSION} VERSION_LESS "6.5")
qt_generate_deploy_qml_app_script(
TARGET ${APP_TARGET}
FILENAME_VARIABLE deploy_script
)
else()
qt_generate_deploy_qml_app_script(
TARGET ${APP_TARGET}
OUTPUT_SCRIPT deploy_script
)
endif()
install(SCRIPT ${deploy_script})
include(InstallRequiredSystemLibraries)
set(APPX_PUBLISHER_ID "Qt.Experiment.Certificate")
set(APPX_PACKAGE_PRODUCT_NAME "QtExperiment.${APP_TARGET}")
set(APPX_PACKAGE_PRODUCT_DISPLAY_NAME "${APP_NAME}")
set(APPX_PACKAGE_PRODUCT_DESCRIPTION "Test app for building QML projects for Windows in CMake")
set(APPX_PACKAGE_PRODUCT_VERSION "${PROJECT_VERSION}.0")
set(APPX_PACKAGE_PRODUCT_BACKGROUND_COLOR "transparent")
set(APPX_PACKAGE_PUBLISHER_ID "CN=${APPX_PUBLISHER_ID}")
set(APPX_PACKAGE_PUBLISHER_DISPLAY_NAME "Publisher")
set(APPX_PACKAGE_MIN_VERSION "10.0.19041.0")
set(APPX_PACKAGE_MAX_VERSION_TESTED "10.0.19041.0")
set(APPX_PACKAGE_EXECUTABLE "${CMAKE_INSTALL_BINDIR}/${APP_TARGET}.exe")
set(APPX_PACKAGES_PREFIX "packages")
set(APPX_PACKAGE_NAME_X64 "${APP_TARGET}_x64.appx")
set(APPX_BUNDLE_NAME "${APP_TARGET}.appxbundle")
configure_file(AppxManifest.xml.in "${CMAKE_CURRENT_BINARY_DIR}/AppxManifest.xml")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/AppxManifest.xml"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
install(
DIRECTORY Assets
DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
message(STATUS "Done prepare for install step.")
endif()
if(APP_PACKAGE_SIGN)
message(STATUS "Starting ${package_bundle_message}...")
if(NOT DEFINED PFX_SIGNATURE_KEY)
message(FATAL_ERROR "PFX_SIGNATURE_KEY is not defined. Make sure to set it to the path of your PFX file.")
endif()
if(NOT DEFINED PFX_PASSWORD)
message(FATAL_ERROR "PFX_PASSWORD is not defined. Make sure to set it to the password of your PFX file.")
endif()
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/${PFX_SIGNATURE_KEY}")
message(FATAL_ERROR
"Make sure to point to the right certificate PFX file for signing.")
endif()
set(makeappx_pack_x64_command "makeappx pack /d \"${CMAKE_INSTALL_PREFIX}\" /p \"${CMAKE_BINARY_DIR}/${APPX_PACKAGES_PREFIX}/${APPX_PACKAGE_NAME_X64}\"")
set(makeappx_pack_x64_execute_process "execute_process(COMMAND ${makeappx_pack_x64_command})")
if(APP_BUNDLE)
set(makeappx_bundle_command "makeappx bundle /d \"${CMAKE_BINARY_DIR}/${APPX_PACKAGES_PREFIX}\" /p \"${CMAKE_BINARY_DIR}/${APPX_BUNDLE_NAME}\"")
set(makeappx_bundle_execute_process "execute_process(COMMAND ${makeappx_bundle_command})")
set(signtool_command "signtool sign /n \"${APPX_PUBLISHER_ID}\" /v /fd SHA256 /f \"${CMAKE_SOURCE_DIR}/${PFX_SIGNATURE_KEY}\" /p \"${PFX_PASSWORD}\" \"${CMAKE_BINARY_DIR}/${APPX_BUNDLE_NAME}\"")
set(signtool_execute_process "execute_process(COMMAND ${signtool_command})")
else()
set(makeappx_bundle_execute_process "")
set(signtool_command "signtool sign /n \"${APPX_PUBLISHER_ID}\" /v /fd SHA256 /f \"${CMAKE_SOURCE_DIR}/${PFX_SIGNATURE_KEY}\" /p \"${PFX_PASSWORD}\" \"${CMAKE_BINARY_DIR}/${APPX_PACKAGES_PREFIX}/${APPX_PACKAGE_NAME_X64}\"")
set(signtool_execute_process "execute_process(COMMAND ${signtool_command})")
endif()
install(CODE "
# file(MAKE_DIRECTORY \"${APPX_PDB_SYMBOLS_DIR}\")
# file(RENAME \"${CMAKE_INSTALL_PREFIX}/${APP_TARGET}.pdb\" \"${APPX_PDB_SYMBOLS_DIR}/${APP_TARGET}.pdb\")
file(REMOVE_RECURSE \"${CMAKE_BINARY_DIR}/${APPX_PACKAGES_PREFIX}\")
file(REMOVE \"${CMAKE_BINARY_DIR}/${APPX_BUNDLE_NAME}\")
${makeappx_pack_x64_execute_process}
${makeappx_bundle_execute_process}
${signtool_execute_process}
")
message(STATUS "Done ${package_bundle_message}")
endif()