Skip to content

Commit 4c0d77f

Browse files
committed
BUG: Fix macOS packaging of Qt designer
This commit ensures designer executable is fixed-up and packaged on macOS. It also configures a launcher named "SlicerDesigner" allowing to start Qt designer consistently on all platform. git-svn-id: http://svn.slicer.org/Slicer4/trunk@27709 3bd1e089-480b-0410-8dfb-8563597acbee
1 parent d2995f5 commit 4c0d77f

File tree

4 files changed

+95
-30
lines changed

4 files changed

+95
-30
lines changed

CMake/SlicerBlockInstallQt.cmake

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ if(Slicer_REQUIRED_QT_VERSION VERSION_LESS "5")
3030

3131
else()
3232

33-
if(NOT EXISTS ${qt_root_dir})
34-
message(FATAL_ERROR "qt_root_dir set to nonexistent directory [${qt_root_dir}]")
35-
endif()
36-
3733
list(APPEND QT_LIBRARIES
3834
"Qt5::Gui"
3935
)
@@ -57,6 +53,11 @@ else()
5753

5854
if(UNIX)
5955

56+
# Get root directory
57+
get_property(_filepath TARGET "Qt5::Core" PROPERTY LOCATION_RELEASE)
58+
get_filename_component(_dir ${_filepath} PATH)
59+
set(qt_root_dir "${_dir}/..")
60+
6061
find_package(Qt5 REQUIRED COMPONENTS
6162
DBus
6263
X11Extras
@@ -185,4 +186,12 @@ else()
185186
COMPONENT Runtime
186187
)
187188
endif()
189+
190+
# Qt designer
191+
if(Slicer_BUILD_QT_DESIGNER_PLUGINS)
192+
install(PROGRAMS ${qt_root_dir}/bin/designer${CMAKE_EXECUTABLE_SUFFIX}
193+
DESTINATION ${Slicer_INSTALL_ROOT}/bin COMPONENT Runtime
194+
RENAME designer-real${CMAKE_EXECUTABLE_SUFFIX}
195+
)
196+
endif()
188197
endif()

CMake/SlicerCPack.cmake

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,52 @@ if(Slicer_BUILD_DICOM_SUPPORT AND NOT Slicer_USE_SYSTEM_DCMTK)
6666
include(${Slicer_CMAKE_DIR}/SlicerBlockInstallDCMTKApps.cmake)
6767
endif()
6868

69-
# Get Qt root directory
70-
set(qt_root_dir "")
71-
if(Slicer_REQUIRED_QT_VERSION VERSION_GREATER "5")
72-
get_property(_filepath TARGET "Qt5::Core" PROPERTY LOCATION_RELEASE)
73-
get_filename_component(_dir ${_filepath} PATH)
74-
set(qt_root_dir "${_dir}/..")
75-
endif()
76-
77-
# Qt designer
78-
if(Slicer_BUILD_QT_DESIGNER_PLUGINS AND Slicer_REQUIRED_QT_VERSION VERSION_GREATER "5")
79-
install(PROGRAMS ${qt_root_dir}/bin/designer${CMAKE_EXECUTABLE_SUFFIX}
80-
DESTINATION ${Slicer_INSTALL_ROOT}/bin COMPONENT Runtime
81-
)
69+
# Install Qt designer launcher
70+
if(Slicer_BUILD_QT_DESIGNER_PLUGINS AND ${Slicer_REQUIRED_QT_VERSION} VERSION_GREATER_EQUAL 5)
71+
set(executablename "SlicerDesigner")
72+
set(build_designer_executable "${QT_BINARY_DIR}/designer${CMAKE_EXECUTABLE_SUFFIX}")
8273
if(APPLE)
83-
set(dollar "$")
84-
install(CODE
85-
"set(app ${Slicer_INSTALL_BIN_DIR}/designer)
86-
set(appfilepath \"${dollar}ENV{DESTDIR}${dollar}{CMAKE_INSTALL_PREFIX}/${dollar}{app}\")
87-
message(\"CPack: - Adding rpath to ${dollar}{app}\")
88-
execute_process(COMMAND install_name_tool -add_rpath @loader_path/.. ${dollar}{appfilepath})"
89-
COMPONENT Runtime
90-
)
74+
set(build_designer_executable "${QT_BINARY_DIR}/Designer.app/Contents/MacOS/designer")
75+
endif()
76+
set(installed_designer_executable "designer-real${CMAKE_EXECUTABLE_SUFFIX}")
77+
set(installed_designer_subdir ".")
78+
if(APPLE)
79+
set(installed_designer_executable "Designer")
80+
set(installed_designer_subdir "Designer.app/Contents/MacOS/designer")
9181
endif()
82+
find_package(CTKAppLauncher REQUIRED)
83+
ctkAppLauncherConfigureForExecutable(
84+
APPLICATION_NAME ${executablename}
85+
SPLASHSCREEN_DISABLED
86+
# Additional settings exclude groups
87+
ADDITIONAL_SETTINGS_EXCLUDE_GROUPS "General,Application,ExtraApplicationToLaunch"
88+
# Launcher settings specific to build tree
89+
APPLICATION_EXECUTABLE ${build_designer_executable}
90+
DESTINATION_DIR ${CMAKE_BINARY_DIR}/${Slicer_BIN_DIR}
91+
ADDITIONAL_SETTINGS_FILEPATH_BUILD "${Slicer_BINARY_DIR}/${Slicer_BINARY_INNER_SUBDIR}/SlicerLauncherSettings.ini"
92+
# Launcher settings specific to install tree
93+
APPLICATION_INSTALL_EXECUTABLE_NAME designer-real${CMAKE_EXECUTABLE_SUFFIX}
94+
APPLICATION_INSTALL_SUBDIR "${installed_designer_subdir}"
95+
ADDITIONAL_SETTINGS_FILEPATH_INSTALLED "<APPLAUNCHER_SETTINGS_DIR>/SlicerLauncherSettings.ini"
96+
)
97+
# Install designer launcher settings
98+
install(
99+
FILES ${CMAKE_BINARY_DIR}/${Slicer_BIN_DIR}/${executablename}LauncherSettingsToInstall.ini
100+
DESTINATION ${Slicer_INSTALL_BIN_DIR}
101+
RENAME ${executablename}LauncherSettings.ini
102+
COMPONENT Runtime
103+
)
104+
# Install designer launcher
105+
set(_launcher CTKAppLauncher)
106+
if(Slicer_BUILD_WIN32_CONSOLE)
107+
set(_launcher CTKAppLauncherW)
108+
endif()
109+
install(
110+
PROGRAMS ${CTKAppLauncher_DIR}/bin/${_launcher}${CMAKE_EXECUTABLE_SUFFIX}
111+
DESTINATION ${Slicer_INSTALL_BIN_DIR}
112+
RENAME ${executablename}${CMAKE_EXECUTABLE_SUFFIX}
113+
COMPONENT Runtime
114+
)
92115
endif()
93116

94117
# -------------------------------------------------------------------------

CMake/SlicerCPackBundleFixup.cmake.in

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,13 @@ function(fixup_bundle_with_plugins app)
322322
"${libs_path}"
323323
)
324324

325-
# Since BundleUtilities function do not copy the "Helpers" directory found
326-
# in frameworks. The following will explicitly copy and fixup
327-
# QtWebEngineCore.framework/Versions/5/Helpers/QtWebEngineProcess.app
328325
set(Slicer_USE_SYSTEM_QT "@Slicer_USE_SYSTEM_QT@")
329326
if(NOT Slicer_USE_SYSTEM_QT)
330327
set(qt_root_dir "@qt_root_dir@")
328+
329+
# Since BundleUtilities function do not copy the "Helpers" directory found
330+
# in frameworks. The following will explicitly copy and fixup
331+
# QtWebEngineCore.framework/Versions/5/Helpers/QtWebEngineProcess.app
331332
set(qtwebenginecore_app_subdir "Helpers/QtWebEngineProcess.app")
332333
set(qtwebenginecore_src_dir "${qt_root_dir}/QtWebEngineCore.framework/${qtwebenginecore_app_subdir}")
333334
set(qtwebenginecore_dest_dir "${app_dir}/Contents/Frameworks/QtWebEngineCore.framework/Versions/Current/${qtwebenginecore_app_subdir}")
@@ -364,6 +365,38 @@ function(fixup_bundle_with_plugins app)
364365
WORKING_DIRECTORY "${app_dir}/Contents/Frameworks/QtWebEngineCore.framework"
365366
)
366367
endif()
368+
369+
# Since BundleUtilities module does not know how to install .app directory withing
370+
# an existing app, the following explicitly install the designer application.
371+
set(Slicer_BUILD_QT_DESIGNER_PLUGINS "@Slicer_BUILD_QT_DESIGNER_PLUGINS@")
372+
set(designer_app_subdir "Designer.app")
373+
set(designer_src_dir "${qt_root_dir}/../bin/${designer_app_subdir}")
374+
set(designer_dest_dir "${app_dir}/Contents/bin/${designer_app_subdir}")
375+
if(Slicer_BUILD_QT_DESIGNER_PLUGINS AND EXISTS ${designer_src_dir})
376+
file(COPY "${designer_src_dir}/Contents" DESTINATION "${designer_dest_dir}/" USE_SOURCE_PERMISSIONS)
377+
set(designer_executable "${designer_dest_dir}/Contents/MacOS/Designer")
378+
# Collect list of Qt framework dependencies
379+
set(prereqs )
380+
get_prerequisites(${designer_executable} "prereqs" 1 0 "" "")
381+
# Generate list of "-change" arguments
382+
set(changes "")
383+
foreach(item ${prereqs})
384+
gp_item_default_embedded_path_override("${item}" path)
385+
get_filename_component(item_name "${item}" NAME)
386+
# Examples of values:
387+
# item : /Volumes/Dashboards/Support/qt-everywhere-build-5.10.0/lib/QtNetwork.framework/Versions/5/QtNetwork
388+
# item_name : QtNetwork
389+
# path : @rpath/Frameworks
390+
# embedded_item : @rpath/Frameworks/QtNetwork.framework/Versions/5/QtNetwork
391+
string(REGEX REPLACE "^.*(${item_name}.framework/.*/?${item_name}).*$" "${path}/\\1" embedded_item "${item}")
392+
set(changes ${changes} "-change" "${item}" "${embedded_item}")
393+
endforeach()
394+
# Update executable
395+
execute_process(COMMAND install_name_tool
396+
-rpath "@executable_path/Frameworks" "@loader_path/../../../../"
397+
${changes} "${designer_executable}"
398+
)
399+
endif()
367400
endif()
368401

369402
endfunction()

CMake/SlicerMacroBuildApplication.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,11 @@ macro(slicerMacroBuildApplication)
604604
endif()
605605
endforeach()
606606

607-
if(${Slicer_REQUIRED_QT_VERSION} VERSION_GREATER_EQUAL 5 AND EXISTS ${QT_DESIGNER_EXECUTABLE})
607+
if(${Slicer_REQUIRED_QT_VERSION} VERSION_GREATER_EQUAL 5 AND EXISTS ${QT_DESIGNER_EXECUTABLE} AND NOT APPLE)
608608
ctkAppLauncherAppendExtraAppToLaunchToList(
609609
LONG_ARG designer
610610
HELP "Start Qt designer using Slicer plugins"
611-
PATH "<APPLAUNCHER_SETTINGS_DIR>/../bin/designer${CMAKE_EXECUTABLE_SUFFIX}"
611+
PATH "<APPLAUNCHER_SETTINGS_DIR>/../bin/designer-real${CMAKE_EXECUTABLE_SUFFIX}"
612612
OUTPUTVAR extraApplicationToLaunchListForInstallTree
613613
)
614614
endif()

0 commit comments

Comments
 (0)