forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlicerBlockInstallQt.cmake
218 lines (196 loc) · 7.84 KB
/
SlicerBlockInstallQt.cmake
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# -------------------------------------------------------------------------
# Find and install Qt
# -------------------------------------------------------------------------
set(QT_INSTALL_LIB_DIR ${Slicer_INSTALL_LIB_DIR})
list(APPEND QT_LIBRARIES
"Qt5::Gui"
)
# WebEngine Dependencies
if("Qt5::WebEngine" IN_LIST QT_LIBRARIES)
find_package(Qt5 REQUIRED
COMPONENTS
Qml
Quick
QuickWidgets
OPTIONAL_COMPONENTS
Positioning # Soft build-time dependency. See https://bugreports.qt.io/browse/QTBUG-57418
)
list(APPEND QT_LIBRARIES
"Qt5::Qml"
"Qt5::Quick"
"Qt5::QuickWidgets"
"Qt5::WebEngineCore"
)
# QmlModels moved into its own library in Qt >= 5.14
# Since windeployqt implicitly copies "Qt5QmlModels.dll" when
# "-qml" is specified, exclude it on Windows.
if(TARGET Qt5::QmlModels AND NOT WIN32)
list(APPEND QT_LIBRARIES "Qt5::QmlModels")
endif()
if(TARGET Qt5::Positioning)
list(APPEND QT_LIBRARIES "Qt5::Positioning")
endif()
endif()
# Get root directory
get_property(_filepath TARGET "Qt5::Core" PROPERTY LOCATION_RELEASE)
get_filename_component(_dir ${_filepath} PATH)
set(qt_root_dir "${_dir}/..")
if(UNIX)
find_package(Qt5 REQUIRED COMPONENTS
DBus
X11Extras
)
list(APPEND QT_LIBRARIES
"Qt5::DBus"
"Qt5::X11Extras"
)
# XcbQpa
slicerInstallLibrary(FILE ${qt_root_dir}/lib/libQt5XcbQpa.so
DESTINATION ${QT_INSTALL_LIB_DIR} COMPONENT Runtime
STRIP
)
# ICU libraries
foreach(iculib IN ITEMS data i18n io le lx test tu uc)
slicerInstallLibrary(FILE ${qt_root_dir}/lib/libicu${iculib}.so
DESTINATION ${QT_INSTALL_LIB_DIR} COMPONENT Runtime
STRIP
)
endforeach()
# Qt designer plugin
if(Slicer_BUILD_QT_DESIGNER_PLUGINS)
find_package(Qt5 REQUIRED COMPONENTS
Designer
)
list(APPEND QT_LIBRARIES
"Qt5::Designer"
)
endif()
# Qt designer
if(Slicer_BUILD_QT_DESIGNER_PLUGINS)
# Needed by designer. It is explicitly installed because there is
# no corresponding CMake module.
slicerInstallLibrary(FILE ${qt_root_dir}/lib/libQt5DesignerComponents.so
DESTINATION ${QT_INSTALL_LIB_DIR} COMPONENT Runtime
STRIP
)
endif()
# WebEngine Dependencies
if("Qt5::WebEngine" IN_LIST QT_LIBRARIES)
install(PROGRAMS ${qt_root_dir}/libexec/QtWebEngineProcess
DESTINATION ${Slicer_INSTALL_ROOT}/libexec COMPONENT Runtime
)
slicerStripInstalledLibrary(
FILES "${Slicer_INSTALL_ROOT}/libexec/QtWebEngineProcess"
COMPONENT Runtime)
# XXX Workaround for QTBUG-66346 fixed in Qt >= 5.11 (See https://github.com/Slicer/Slicer/pull/944)
set(qt_conf_contents "[Paths]\nPrefix = ..\nTranslations = share/QtTranslations")
install(
CODE "file(WRITE \"\${CMAKE_INSTALL_PREFIX}/libexec/qt.conf\" \"${qt_conf_contents}\")"
COMPONENT Runtime)
endif()
set(_qt_version "${Qt5_VERSION_MAJOR}.${Qt5_VERSION_MINOR}.${Qt5_VERSION_PATCH}")
foreach(target ${QT_LIBRARIES})
get_target_property(type ${target} TYPE)
if(NOT type STREQUAL "SHARED_LIBRARY")
continue()
endif()
get_property(location TARGET ${target} PROPERTY LOCATION_RELEASE)
if(UNIX)
# Install .so and versioned .so.x.y
get_filename_component(QT_LIB_DIR_tmp ${location} PATH)
get_filename_component(QT_LIB_NAME_tmp ${location} NAME)
string(REPLACE ".${_qt_version}" "" QT_LIB_NAME_tmp ${QT_LIB_NAME_tmp})
install(DIRECTORY ${QT_LIB_DIR_tmp}/
DESTINATION ${QT_INSTALL_LIB_DIR} COMPONENT Runtime
FILES_MATCHING PATTERN "${QT_LIB_NAME_tmp}*"
PATTERN "${QT_LIB_NAME_tmp}*.debug" EXCLUDE)
slicerStripInstalledLibrary(
FILES "${QT_INSTALL_LIB_DIR}/${QT_LIB_NAME_tmp}"
COMPONENT Runtime)
endif()
endforeach()
# Install resources directory
set(resources_dir "${qt_root_dir}/resources")
install(DIRECTORY ${resources_dir}
DESTINATION ${Slicer_INSTALL_ROOT} COMPONENT Runtime
)
# Install webengine translations
if("Qt5::WebEngine" IN_LIST QT_LIBRARIES)
set(translations_dir "${qt_root_dir}/translations/qtwebengine_locales")
install(DIRECTORY ${translations_dir}
DESTINATION ${Slicer_INSTALL_ROOT}/share/QtTranslations/ COMPONENT Runtime
)
endif()
# Configure and install qt.conf
set(qt_conf_contents "[Paths]\nPrefix = ..\nPlugins = ${Slicer_INSTALL_QtPlugins_DIR}\nTranslations = share/QtTranslations")
install(
CODE "file(WRITE \"\${CMAKE_INSTALL_PREFIX}/bin/qt.conf\" \"${qt_conf_contents}\")"
COMPONENT Runtime
)
elseif(WIN32)
# Get location of windeployqt.exe based on uic.exe location
get_target_property(uic_location Qt5::uic IMPORTED_LOCATION)
get_filename_component(_dir ${uic_location} DIRECTORY)
set(windeployqt "${_dir}/windeployqt.exe")
if(NOT EXISTS ${windeployqt})
message(FATAL_ERROR "Failed to locate windeployqt executable: [${windeployqt}]")
endif()
set(_args "--release --no-compiler-runtime --no-translations --no-plugins")
foreach(target IN LISTS QT_LIBRARIES)
get_target_property(type ${target} TYPE)
if(NOT type STREQUAL "SHARED_LIBRARY")
continue()
endif()
string(REPLACE "Qt5::" "" module ${target})
string(TOLOWER ${module} module_lc)
set(_args "${_args} -${module_lc}")
endforeach()
# Qt designer
if(Slicer_BUILD_QT_DESIGNER_PLUGINS)
# Needed by designer. It is explicitly specified because there is
# no corresponding CMake module.
set(_args "${_args} -designercomponents")
endif()
set(executable "${Slicer_MAIN_PROJECT_APPLICATION_NAME}App-real.exe")
# Setting the "WindowsSdkDir" env. variable before building the PACKAGE target ensures
# that the "windeployqt" tool can lookup the path of a recent version of the "d3dcompiler_47.dll"
# library in the directory "%WindowsSdkDir%/Redist/D3D/x64"
if(CMAKE_WINDOWS_KITS_10_DIR)
# See https://cmake.org/cmake/help/latest/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.html
# and https://cmake.org/cmake/help/latest/module/InstallRequiredSystemLibraries.html
set(windows_kits_dir "${CMAKE_WINDOWS_KITS_10_DIR}")
elseif(ENV{WindowsSdkDir})
# If building from an environments established by vcvarsall.bat or similar scripts.
set(windows_kits_dir "$ENV{WindowsSdkDir}")
else()
# Default to registry value
# Copied from CMake/Modules/InstallRequiredSystemLibraries.cmake
get_filename_component(windows_kits_dir
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE)
endif()
if(NOT windows_kits_dir)
message(WARNING "Failed to lookup Windows SDK directory required to package Qt libraries")
endif()
install(
CODE "
set(windows_kits_dir \"${windows_kits_dir}\")
set(ENV{WindowsSdkDir} \${windows_kits_dir})
if(\"\$ENV{WindowsSdkDir}\" STREQUAL \"\")
message(FATAL_ERROR \"Setting WindowsSdkDir env. variable is required to ensure windeployqt can install the most recent version of d3dcompiler_47.dll\")
endif()
set(ENV{PATH} \"${QT_BINARY_DIR};\$ENV{PATH}\")
execute_process(COMMAND \"${windeployqt}\" ${_args} \"\${CMAKE_INSTALL_PREFIX}/bin/${executable}\")
"
COMPONENT Runtime
)
endif()
# Qt designer
if(Slicer_BUILD_QT_DESIGNER_PLUGINS)
install(PROGRAMS ${qt_root_dir}/bin/designer${CMAKE_EXECUTABLE_SUFFIX}
DESTINATION ${Slicer_INSTALL_ROOT}/bin COMPONENT Runtime
RENAME designer-real${CMAKE_EXECUTABLE_SUFFIX}
)
slicerStripInstalledLibrary(
FILES "${Slicer_INSTALL_ROOT}/bin/designer-real"
COMPONENT Runtime)
endif()