Skip to content

Commit

Permalink
CPack drop qt deloy tool
Browse files Browse the repository at this point in the history
Ship with package managers
  • Loading branch information
ManuelSchneid3r committed Nov 7, 2024
1 parent 0aa8749 commit 4a7577f
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 90 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(albert
DESCRIPTION "Keyboard launcher"
HOMEPAGE_URL "https://albertlauncher.github.io"
)
set(PROJECT_DISPLAY_NAME "Albert")

# Local cmake modules (also CMake uses this in a pretty obscure way, e.g. for the plist)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
Expand Down Expand Up @@ -448,11 +449,11 @@ if (APPLE)
set_target_properties(${TARGET_APP} PROPERTIES
BUNDLE True
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}"
MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_DISPLAY_NAME}" # "${PROJECT_NAME}"
MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2024 Manuel Schneider"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.albertlauncher.albert"
MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}
MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}"
MACOSX_BUNDLE_INFO_STRING "Albert keyboard launcher"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_PROJECT_VERSION}"
)
Expand Down Expand Up @@ -486,11 +487,16 @@ install(
# CMake uses this one instead of searching systemwide.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_BINARY_DIR}")

# on macOS include the macports lookup path
if (APPLE)
list(APPEND CMAKE_PREFIX_PATH "/opt/local")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
endif()
# # on macOS include the macports lookup path
# if (APPLE)
# list(APPEND CMAKE_PREFIX_PATH "/opt/local")
# message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
# endif()
#2024: Drop ports use brew only
# if (APPLE)
# list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew")
# message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
# endif()

option(BUILD_PLUGINS "Build plugins" ON)
set(PLUGINS_DIR "${CMAKE_CURRENT_LIST_DIR}/plugins")
Expand Down Expand Up @@ -540,7 +546,6 @@ endif()

### Packaging #################################################################

set(PROJECT_DISPLAY_NAME "Albert")

if (APPLE)
set(CPACK_GENERATOR "DragNDrop")
Expand Down
203 changes: 121 additions & 82 deletions cmake/bundle-macos.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,166 @@ set(CMAKE_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@") # library paths
set(CMAKE_INSTALL_DATADIR "@CMAKE_INSTALL_DATADIR@")
set(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@") # qml lib lookup dir for macdeployqt
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
set(QT_DEPLOY_SCRIPT "@QT_DEPLOY_SCRIPT@")
set(QT_DEPLOY_SUPPORT "@QT_DEPLOY_SUPPORT@")
set(BUNDLE_PATH "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app")

# Print CMake env


# PRINT CMAKE ENV

message(STATUS "--- ENV ---")
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "--- ENV END ---")

message(STATUS "QT_DEPLOY_SUPPORT ${QT_DEPLOY_SUPPORT}")
include("${QT_DEPLOY_SUPPORT}")

# Move resources
set(RES_SRC ${CMAKE_INSTALL_PREFIX}/share/albert)
FILE(GLOB children RELATIVE ${RES_SRC} ${RES_SRC}/*)
FOREACH(child ${children})
file(RENAME
${RES_SRC}/${child}
${BUNDLE_PATH}/Contents/Resources/${child}
)
ENDFOREACH()

file(MAKE_DIRECTORY "${BUNDLE_PATH}/Contents/PlugIns")
file(MAKE_DIRECTORY "${BUNDLE_PATH}/Contents/Frameworks")

# Move plugins
file(RENAME
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/albert
${BUNDLE_PATH}/Contents/PlugIns/albert
)
# MOVE FILES INTO BUNDLE


# Move albert lib
## Library
file(MAKE_DIRECTORY "${BUNDLE_PATH}/Contents/Frameworks")
file(RENAME
"${CMAKE_INSTALL_PREFIX}/albert.framework"
"${BUNDLE_PATH}/Contents/Frameworks/albert.framework"
)

# RPATH frameworks
execute_process(
COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks/" "${BUNDLE_PATH}/Contents/MacOS/albert"
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)
# RPATH macports
execute_process(
COMMAND install_name_tool -add_rpath "/opt/local/lib/" "${BUNDLE_PATH}/Contents/MacOS/albert"
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
## Plugins
file(MAKE_DIRECTORY "${BUNDLE_PATH}/Contents/PlugIns")
file(RENAME
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/albert
${BUNDLE_PATH}/Contents/PlugIns/albert
)
# RPATH homebrew arm

## Resources
set(RES_SRC ${CMAKE_INSTALL_PREFIX}/share/albert)
file(GLOB children RELATIVE ${RES_SRC} ${RES_SRC}/*)
foreach(child ${children})
file(RENAME
${RES_SRC}/${child}
${BUNDLE_PATH}/Contents/Resources/${child}
)
endforeach()

file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")



# ADD RPATHS TO EXECUTABLE

execute_process(
COMMAND install_name_tool -add_rpath "/opt/homebrew/lib/" "${BUNDLE_PATH}/Contents/MacOS/albert"
COMMAND install_name_tool
-add_rpath "@executable_path/../Frameworks/" # in bundle
-add_rpath "/opt/local/lib/" # RPATH macports
-add_rpath "/opt/homebrew/lib/" # RPATH homebrew arm
-add_rpath "/usr/local/lib/" # RPATH homebrew intel
"${BUNDLE_PATH}/Contents/MacOS/${PROJECT_NAME}"
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)
# RPATH homebrew intel



# DEPLOY (APPROACH #1, use qt_deploy_runtime_dependencies)

# set(QT_DEPLOY_SUPPORT "@QT_DEPLOY_SUPPORT@")
# message(STATUS "QT_DEPLOY_SUPPORT ${QT_DEPLOY_SUPPORT}")
# include("${QT_DEPLOY_SUPPORT}")

# ## Get a list of plugin files
# # file(GLOB PLUGINS "${BUNDLE_PATH}/Contents/MacOS/plugins/*")
# # message(STATUS PLUGINS: ${PLUGINS})

# qt_deploy_runtime_dependencies(
# EXECUTABLE ${BUNDLE_PATH}
# # ADDITIONAL_EXECUTABLES ${PLUGINS}
# GENERATE_QT_CONF
# VERBOSE
# )



# DEPLOY (APPROACH #2, call macdeployqt)

# find_program(MACDEPLOYQT NAMES macdeployqt macdeployqt REQUIRED)
# get_filename_component(QT_BIN_DIR "${MACDEPLOYQT}" DIRECTORY)
# get_filename_component(QT_DIR "${QT_BIN_DIR}" DIRECTORY)
# set(QT_LIB_DIR "${QT_DIR}/${CMAKE_INSTALL_LIBDIR}")

# # Build list of -executable= parameters for plugins consumed by macdeployqt
# FILE(GLOB PLUGINS "${BUNDLE_PATH}/Contents/PlugIns/albert/*")
# foreach(PLUGIN ${PLUGINS})
# list(APPEND PLUGINS_EXEC_PARAMS "-executable=${PLUGIN}")
# endforeach()

# message(STATUS "MACDEPLOYQT ${MACDEPLOYQT}")
# message(STATUS "QT_DIR ${QT_DIR}")
# message(STATUS "QT_BIN_DIR ${QT_BIN_DIR}")
# message(STATUS "QT_LIB_DIR ${QT_LIB_DIR}")

# execute_process(
# COMMAND "${MACDEPLOYQT}"
# "${BUNDLE_PATH}"
# "-executable=${BUNDLE_PATH}/Contents/Frameworks/albert.framework/Versions/A/albert"
# ${PLUGINS_EXEC_PARAMS}
# #"-libpath=${CMAKE_INSTALL_PREFIX}" # albert lib
# #"-libpath=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" # albert lib
# #"-libpath=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" # albert lib
# "-libpath=/opt/local/lib" # macports dependencies
# #"-qmldir=${CMAKE_SOURCE_DIR}/plugins/qmlboxmodel/resources/qml"
# "-appstore-compliant"
# "-verbose=1"
# #"-dmg"
# COMMAND_ECHO STDOUT
# COMMAND_ERROR_IS_FATAL ANY
# )



# CODE SIGN

# execute_process(
# COMMAND xattr -d com.apple.quarantine "${BUNDLE_PATH}"
# COMMAND_ECHO STDOUT
# COMMAND_ERROR_IS_FATAL ANY
# )
execute_process(
COMMAND install_name_tool -add_rpath "/usr/local/lib/" "${BUNDLE_PATH}/Contents/MacOS/albert"
COMMAND codesign --force --deep --sign - "${BUNDLE_PATH}"
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)



## CLEANUP

# include(BundleUtilities)
# verify_app("${BUNDLE_PATH}")


# Older, possibly useful stuff

## Build library lookup paths from CMAKE_PREFIX_PATH
#foreach(PATH ${CMAKE_PREFIX_PATH})
# list(APPEND DIRS "${PATH}/lib")
#endforeach()
#list(APPEND DIRS "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") # albert lib
#list(APPEND DIRS "/Library/Developer/CommandLineTools/Library/Frameworks/") # system python

## Get a list of plugin files
#FILE(GLOB LIBS "${BUNDLE_PATH}/Contents/MacOS/plugins/*")



#include(BundleUtilities)
##fixup_bundle("${BUNDLE_PATH}" "${LIBS}" "${DIRS}")
#fixup_bundle("${BUNDLE_PATH}" "${LIBS}" "${DIRS}")




file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")

# Build list of -executable= parameters for plugins consumed by macdeployqt
FILE(GLOB PLUGINS "${BUNDLE_PATH}/Contents/PlugIns/albert/*")
foreach(PLUGIN ${PLUGINS})
list(APPEND PLUGINS_EXEC_PARAMS "-executable=${PLUGIN}")
endforeach()

# Qt macdeployqt
find_program(MACDEPLOYQT NAMES macdeployqt macdeployqt REQUIRED)
get_filename_component(QT_BIN_DIR "${MACDEPLOYQT}" DIRECTORY)
get_filename_component(QT_DIR "${QT_BIN_DIR}" DIRECTORY)
set(QT_LIB_DIR "${QT_DIR}/${CMAKE_INSTALL_LIBDIR}")
message(STATUS "MACDEPLOYQT ${MACDEPLOYQT}")
message(STATUS "QT_BIN_DIR ${QT_BIN_DIR}")
message(STATUS "QT_LIB_DIR ${QT_LIB_DIR}")
message(STATUS "QT_DIR ${QT_DIR}")
message(STATUS "MACDEPLOYQT: ${MACDEPLOYQT}")
#message(STATUS "DYLD_LIBRARY_PATH: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
#set(ENV{DYLD_LIBRARY_PATH} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
execute_process(
COMMAND "${MACDEPLOYQT}"
"${BUNDLE_PATH}"
"-executable=${BUNDLE_PATH}/Contents/Frameworks/albert.framework/Versions/A/albert"
${PLUGINS_EXEC_PARAMS}
#"-libpath=${CMAKE_INSTALL_PREFIX}" # albert lib
#"-libpath=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" # albert lib
#"-libpath=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" # albert lib
"-libpath=/opt/local/lib" # macports dependencies
"-qmldir=${CMAKE_SOURCE_DIR}/plugins/qmlboxmodel/resources/qml"
"-appstore-compliant"
"-verbose=1"
#"-dmg"
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)

# Copy missing svg imageformat
file(COPY_FILE
"${QT_DIR}/plugins/imageformats/libqsvg.dylib"
"${BUNDLE_PATH}/Contents/PlugIns/imageformats/libqsvg.dylib"
)

## file(REMOVE_RECURSE \${CMAKE_INSTALL_PREFIX}/lib)
## file(REMOVE_RECURSE \${CMAKE_INSTALL_PREFIX}/share)

0 comments on commit 4a7577f

Please sign in to comment.