Skip to content

Commit

Permalink
Squash CPack (#6)
Browse files Browse the repository at this point in the history
CPack: Move Apple and Linux installers to CMake/CPack
  • Loading branch information
tresf authored May 18, 2024
1 parent f891bb3 commit 6eb84fa
Show file tree
Hide file tree
Showing 22 changed files with 996 additions and 502 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
ccache --zero-stats
source /opt/qt5*/bin/qt5*-env.sh || true
mkdir build && cd build
cmake .. $CMAKE_OPTS -DCMAKE_INSTALL_PREFIX=./install
cmake .. $CMAKE_OPTS
- name: Build
run: cmake --build build
- name: Run tests
Expand All @@ -47,8 +47,7 @@ jobs:
ctest --output-on-failure -j2
- name: Package
run: |
cmake --build build --target install
cmake --build build --target appimage
cmake --build build --target package
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -101,8 +100,6 @@ jobs:
- name: Install dependencies
run: |
brew bundle install --verbose
npm update -g npm
npm install --location=global appdmg
env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_UPGRADE: 1
Expand All @@ -113,7 +110,6 @@ jobs:
mkdir build
cmake -S . \
-B build \
-DCMAKE_INSTALL_PREFIX="../target" \
-DCMAKE_PREFIX_PATH="$(brew --prefix qt@5)" \
$CMAKE_OPTS \
-DUSE_WERROR=OFF
Expand All @@ -125,8 +121,7 @@ jobs:
ctest --output-on-failure -j3
- name: Package
run: |
cmake --build build --target install
cmake --build build --target dmg
cmake --build build --target package
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ option(WANT_DEBUG_TSAN "Enable ThreadSanitizer" OFF)
option(WANT_DEBUG_MSAN "Enable MemorySanitizer" OFF)
option(WANT_DEBUG_UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
OPTION(BUNDLE_QT_TRANSLATIONS "Install Qt translation files for LMMS" OFF)
option(WANT_DEBUG_CPACK "Show detailed logs for packaging commands" OFF)
option(WANT_CPACK_TARBALL "Request CPack to create a tarball instead of an installer" OFF)


IF(LMMS_BUILD_APPLE)
Expand Down Expand Up @@ -628,6 +630,17 @@ ELSE()
SET (STATUS_DEBUG_FPE "Disabled")
ENDIF(WANT_DEBUG_FPE)

if(WANT_DEBUG_CPACK)
if((LMMS_BUILD_WIN32 AND CMAKE_VERSION VERSION_LESS "3.19") OR WANT_CPACK_TARBALL)
set(STATUS_DEBUG_CPACK "Wanted but disabled due to unsupported configuration")
else()
set(CPACK_DEBUG TRUE)
set(STATUS_DEBUG_CPACK "Enabled")
endif()
else()
set(STATUS_DEBUG_CPACK "Disabled")
endif()

# check for libsamplerate
FIND_PACKAGE(Samplerate 0.1.8 MODULE REQUIRED)

Expand Down Expand Up @@ -777,7 +790,7 @@ IF(LMMS_BUILD_LINUX)
"${CMAKE_BINARY_DIR}/lmmsconfig.h"
"${CMAKE_BINARY_DIR}/lmmsversion.h"
"${CMAKE_SOURCE_DIR}/src/gui/embed.cpp"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/lmms/")
DESTINATION "include/lmms/")
ENDIF(LMMS_BUILD_LINUX)

#
Expand Down Expand Up @@ -881,6 +894,7 @@ MESSAGE(
"* Debug using ThreadSanitizer : ${STATUS_DEBUG_TSAN}\n"
"* Debug using MemorySanitizer : ${STATUS_DEBUG_MSAN}\n"
"* Debug using UBSanitizer : ${STATUS_DEBUG_UBSAN}\n"
"* Debug packaging commands : ${STATUS_DEBUG_CPACK}\n"
)

MESSAGE(
Expand Down
12 changes: 8 additions & 4 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ ENDIF()
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_UCASE}")
SET(CPACK_SOURCE_GENERATOR "TBZ2")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}")
IF(NOT DEFINED WIN32)
SET(CPACK_STRIP_FILES "bin/${CMAKE_PROJECT_NAME};${PLUGIN_DIR}/*.so")
SET(CPACK_PACKAGE_EXECUTABLES "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME_UCASE} binary")
ENDIF()
SET(CPACK_PACKAGE_EXECUTABLES "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME_UCASE} binary")

# Disable strip for Debug|RelWithDebInfo
if(CMAKE_BUILD_TYPE MATCHES "Deb")
unset(CPACK_STRIP_FILES)
else()
set(CPACK_STRIP_FILES TRUE)
endif()

IF(LMMS_BUILD_WIN32)
ADD_SUBDIRECTORY(nsis)
Expand Down
81 changes: 51 additions & 30 deletions cmake/apple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
SET(MACOSX_BUNDLE_ICON_FILE "icon.icns")
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_NAME_UCASE}")
SET(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION}")
SET(MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME_UCASE}")
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION}")
SET(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION}")
SET(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT}")
SET(MACOSX_BUNDLE_MIMETYPE "application/x-lmms-project")
SET(MACOSX_BUNDLE_MIMETYPE_ICON "project.icns")
SET(MACOSX_BUNDLE_MIMETYPE_ID "io.lmms")
SET(MACOSX_BUNDLE_PROJECT_URL "${PROJECT_URL}")
SET(MACOSX_BUNDLE_DMG_TITLE "${MACOSX_BUNDLE_BUNDLE_NAME} ${MACOSX_BUNDLE_LONG_VERSION_STRING}")
# Info.plist
set(MACOS_ICON "${PROJECT_NAME_UCASE}.icns")
set(MACOS_MIMETYPE "application/x-lmms-project")
set(MACOS_MIMETYPE_ICON "project.icns")
set(MACOS_MIMETYPE_ID "io.lmms")
configure_file("lmms.plist.in" "Info.plist" @ONLY)

# FIXME: appdmg won't allow volume names > 27 char
# See also https://github.com/LinusU/node-appdmg/issues/48
STRING(SUBSTRING "${MACOSX_BUNDLE_DMG_TITLE}" 0 27 MACOSX_BUNDLE_DMG_TITLE)
# "Bundle"-specific CPack options
set(CPACK_GENERATOR "Bundle" PARENT_SCOPE)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME_UCASE}" PARENT_SCOPE)
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist" PARENT_SCOPE)
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icon.icns" PARENT_SCOPE)

CONFIGURE_FILE("lmms.plist.in" "${CMAKE_BINARY_DIR}/Info.plist")
CONFIGURE_FILE("install_apple.sh.in" "${CMAKE_BINARY_DIR}/install_apple.sh" @ONLY)
CONFIGURE_FILE("package_apple.json.in" "${CMAKE_BINARY_DIR}/package_apple.json" @ONLY)
# Standard CPack options
# suppress license popup
unset(CPACK_RESOURCE_FILE_LICENSE PARENT_SCOPE)
# disable cpack's strip: causes missing symbols on macOS
set(CPACK_STRIP_FILES_ORIG "${CPACK_STRIP_FILES}" PARENT_SCOPE)
set(CPACK_STRIP_FILES false PARENT_SCOPE)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}-mac${APPLE_OS_VER}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}" PARENT_SCOPE)
set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/MacDeployQt.cmake" PARENT_SCOPE)
set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME_UCASE} ${VERSION}" PARENT_SCOPE)
set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/${SUBDIR}/background.tiff" PARENT_SCOPE)
set(CPACK_DMG_DS_STORE "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/DS_Store" PARENT_SCOPE)

# DMG creation target
SET(DMG_FILE "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${VERSION}-mac${APPLE_OS_VER}.dmg")
FILE(REMOVE "${DMG_FILE}")
ADD_CUSTOM_TARGET(removedmg
COMMAND touch "\"${DMG_FILE}\"" && rm "\"${DMG_FILE}\""
COMMENT "Removing old DMG")
ADD_CUSTOM_TARGET(dmg
COMMAND appdmg "\"${CMAKE_BINARY_DIR}/package_apple.json\"" "\"${DMG_FILE}\""
DEPENDS "${CMAKE_BINARY_DIR}/package_apple.json"
COMMENT "Generating DMG")
ADD_DEPENDENCIES(dmg removedmg)
# Custom vars to expose to Cpack
# must be prefixed with "CPACK_" per https://stackoverflow.com/a/46526757/3196753)
set(CPACK_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
set(CPACK_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)
set(CPACK_BINARY_DIR "${CMAKE_BINARY_DIR}" PARENT_SCOPE)
set(CPACK_SOURCE_DIR "${CMAKE_SOURCE_DIR}" PARENT_SCOPE)
set(CPACK_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}" PARENT_SCOPE)
set(CPACK_CARLA_LIBRARIES "${CARLA_LIBRARIES}" PARENT_SCOPE)
set(CPACK_PROJECT_NAME "${PROJECT_NAME}" PARENT_SCOPE)
set(CPACK_PROJECT_NAME_UCASE "${PROJECT_NAME_UCASE}" PARENT_SCOPE)

# see also ../postinstall/CMakeLists.txt
# appdmg is no longer required unless a new .DS_Store file is needed
# Usage:
# make package
# make appdmg
# ... manually copy .DS_Store file
# appdmg won't allow volume names > 27 char https://github.com/LinusU/node-alias/issues/7
string(SUBSTRING "${PROJECT_NAME_UCASE} ${VERSION}" 0 27 APPDMG_VOLUME_NAME)
# We'll configure this file twice (again in MacDeployQt.cmake once we know CPACK_TEMPORARY_INSTALL_DIRECTORY)
configure_file("appdmg.json.in" "_appdmg.json.in" @ONLY)
add_custom_target(appdmg
COMMAND touch "${CMAKE_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}-appdmg.dmg"
COMMAND rm "${CMAKE_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}-appdmg.dmg"
COMMAND appdmg appdmg.json "${CMAKE_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}-appdmg.dmg"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/appdmg.json"
COMMENT "Generating DMG")

if(CMAKE_VERSION VERSION_LESS "3.19")
message(WARNING "DMG creation requires at least CMake 3.19")
endif()
Binary file added cmake/apple/DS_Store
Binary file not shown.
121 changes: 121 additions & 0 deletions cmake/apple/MacDeployQt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Variables must be prefixed with "CPACK_" to be visible here
set(lmms "${CPACK_PROJECT_NAME}")
set(APP "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/${CPACK_PROJECT_NAME_UCASE}.app")

# 0 = no output, 1 = error/warning, 2 = normal, 3 = debug
set(VERBOSITY 1)
# Set to "STDOUT" to show all verbose commands
set(COMMAND_ECHO NONE)

# Detect release|debug build
if(NOT CPACK_STRIP_FILES_ORIG)
# -use-debug-libs implies -no-strip
if(CPACK_QMAKE_EXECUTABLE MATCHES "/homebrew/|/usr/local")
message(STATUS "Homebrew does not provide debug qt libraries, replacing \"-use-debug-libs\" with \"-no-strip\" instead")
set(USE_DEBUG_LIBS -no-strip)
else()
set(USE_DEBUG_LIBS -use-debug-libs)
endif()
endif()

if(CPACK_DEBUG)
set(VERBOSITY 2)
set(COMMAND_ECHO STDOUT)
endif()

execute_process(COMMAND convert
"${CPACK_CURRENT_SOURCE_DIR}/*.png"
"${CPACK_CURRENT_BINARY_DIR}/background.tiff"
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)

# Copy missing files
file(COPY "${CPACK_CURRENT_SOURCE_DIR}/project.icns" DESTINATION "${APP}/Contents/Resources")

# Updates appdmg.json with CPACK_TEMPORARY_INSTALL_DIRECTORY
# - .DS_Store can be recreated using appdmg appdmg.json lmms.dmg
# - Find new .DS_Store from the root of the DMG file
# - cp /Volumes/lmms-x.x.x/.DS_Store ../cmake/apple/DS_Store
configure_file("${CPACK_CURRENT_BINARY_DIR}/_appdmg.json.in" "${CPACK_CURRENT_BINARY_DIR}/appdmg.json")
file(REMOVE "${CPACK_CURRENT_BINARY_DIR}/_appdmg.json.in")

# Create bundle structure
file(MAKE_DIRECTORY "${APP}/Contents/MacOS")
file(MAKE_DIRECTORY "${APP}/Contents/Frameworks")
file(MAKE_DIRECTORY "${APP}/Contents/Resources")

# Make all libraries writable for macdeployqt
file(CHMOD_RECURSE "${APP}/Contents" PERMISSIONS
OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_WRITE GROUP_READ
WORLD_READ)

# Fix layout
file(RENAME "${APP}/Contents/Resources/lib" "${APP}/Contents/lib")
file(RENAME "${APP}/Contents/Resources/share" "${APP}/Contents/share")
file(RENAME "${APP}/Contents/Resources/bin" "${APP}/Contents/bin")

# Move binaries into Contents/MacOS
file(RENAME "${APP}/Contents/bin/${lmms}" "${APP}/Contents/MacOS/${lmms}")
file(RENAME "${APP}/Contents/lib/${lmms}/RemoteZynAddSubFx" "${APP}/Contents/MacOS/RemoteZynAddSubFx")
file(REMOVE_RECURSE "${APP}/Contents/bin")
file(REMOVE_RECURSE "${APP}/Contents/share/man1")
file(REMOVE_RECURSE "${APP}/Contents/include")

# Replace @rpath with @loader_path for Carla
execute_process(COMMAND install_name_tool -change
"@rpath/libcarlabase.dylib"
"@loader_path/libcarlabase.dylib"
"${APP}/Contents/lib/${lmms}/libcarlapatchbay.so"
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND install_name_tool -change
"@rpath/libcarlabase.dylib"
"@loader_path/libcarlabase.dylib"
"${APP}/Contents/lib/${lmms}/libcarlarack.so"
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)

# Build list of executables to inform macdeployqt about
# e.g. -executable=foo.dylib -executable=bar.dylib
file(GLOB LIBS "${APP}/Contents/lib/${lmms}/*.so")
file(GLOB LADSPA "${APP}/Contents/lib/${lmms}/ladspa/*.so")
list(APPEND LIBS ${LADSPA})
list(APPEND LIBS "${APP}/Contents/MacOS/RemoteZynAddSubFx")
list(SORT LIBS)

# Construct macdeployqt parameters
foreach(_lib IN LISTS LIBS)
list(APPEND EXECUTABLES "-executable=${_lib}")
endforeach()

# Call macdeployqt
get_filename_component(QTBIN "${CPACK_QMAKE_EXECUTABLE}" DIRECTORY)
message(STATUS "Calling ${QTBIN}/macdeployqt ${APP} [... executables]")
execute_process(COMMAND "${QTBIN}/macdeployqt" "${APP}" ${EXECUTABLES}
-verbose=${VERBOSITY}
${USE_DEBUG_LIBS}
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)

# Remove dummy carla libs, relink to a sane location (e.g. /Applications/Carla.app/...)
# (must be done after calling macdeployqt)
file(GLOB CARLALIBS "${APP}/Contents/lib/${lmms}/libcarla*")
foreach(_carlalib IN LISTS CARLALIBS)
foreach(_lib "${CPACK_CARLA_LIBRARIES}")
set(_oldpath "../../Frameworks/lib${_lib}.dylib")
set(_newpath "Carla.app/Contents/MacOS/lib${_lib}.dylib")
execute_process(COMMAND install_name_tool -change
"@loader_path/${_oldpath}"
"@executable_path/../../../${_newpath}"
"${_carlalib}"
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)
file(REMOVE "${APP}/Contents/Frameworks/lib${_lib}.dylib")
endforeach()
endforeach()

# Call ad-hoc codesign manually (CMake offers this as well)
execute_process(COMMAND codesign --force --deep --sign - "${APP}"
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)
9 changes: 9 additions & 0 deletions cmake/apple/appdmg.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"title": "@APPDMG_VOLUME_NAME@",
"background": "@CMAKE_SOURCE_DIR@/cmake/apple/background.png",
"icon-size": 128,
"contents": [
{ "x": 139, "y": 200, "type": "file", "path": "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/@PROJECT_NAME_UCASE@.app" },
{ "x": 568, "y": 200, "type": "link", "path": "/Applications" }
]
}
File renamed without changes
File renamed without changes
Loading

0 comments on commit 6eb84fa

Please sign in to comment.