1# 2# Copyright (C) 2016-2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 3# All rights reserved. 4# 5# Author: Andras Mantia <andras.mantia@kdab.com> 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 11# 1. Redistributions of source code must retain the copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 3. The name of the author may not be used to endorse or promote products 17# derived from this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30# 31# Creates targets for IFW packages. 32# 33# Usage: 34# addPackageTarget(package_name build_target install_target package_type) 35# 36# Where: 37# - package_name is the name of the package (application), like GammaRay 38# - build_target is the name of the make target used to build the required code (eg. src, sub-src, lib, docs, etc) 39# - install_target is the name of the make target used to install the required code (eg. install, install_docs, etc) 40# - package_type is the type of the package. Should be one of lib, doc, examples, tools 41# 42# 43# For each type there will be a target created, eg. packagelib, packagedoc, etc. and there will be 44# a master target called packages. Running 45# 46# make packages 47# 48# will create the 7z packages for all added targets. 49 50 51get_filename_component(PACKAGE_PREFIX ${QT_INSTALL_PREFIX} NAME) 52set(INSTALL_PATH "${CMAKE_BINARY_DIR}/install/${Qt5Core_VERSION}/${PACKAGE_PREFIX}") 53set(PACKAGE_PATH "${CMAKE_BINARY_DIR}/install/") 54 55add_custom_target(packages) 56# Used to serialize the package creation, otherwise the packaging for different types will 57# conflict due to installing to the same place 58set(LAST_TARGET "") 59 60macro(addPackageTarget packageName dependsTarget installTarget type) 61 set(PACKAGE_LIB_FILE "${CMAKE_BINARY_DIR}/${packageName}-${type}-${Qt5Core_VERSION}-${PACKAGE_PREFIX}.7z") 62 set(PACKAGE_TARGET "${type}_package") 63 add_custom_target(${PACKAGE_TARGET} 64 DEPENDS "${LAST_TARGET}" 65 COMMAND echo "Creating IFW package for ${packageName} of type ${type}: ${PACKAGE_LIB_FILE}" 66 COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/${installTarget}" 67 COMMAND ${CMAKE_COMMAND} -E remove -f ${PACKAGE_LIB_FILE} 68 COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} -DCMAKE_INSTALL_PREFIX="${INSTALL_PATH}" -DBUILD_TESTING=Off 69 COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}" "${CMAKE_MAKE_PROGRAM}" ${installTarget} 70 COMMAND ${CMAKE_COMMAND} -E chdir "${PACKAGE_PATH}" 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on ${PACKAGE_LIB_FILE} . 71 COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/${installTarget}" 72 COMMAND echo "Generated package file: ${PACKAGE_LIB_FILE}" 73 ) 74 add_dependencies(packages ${PACKAGE_TARGET}) 75 set(LAST_TARGET ${PACKAGE_TARGET}) 76endmacro() 77 78