QT Deployment V – Separating Build and Install Time

It’s the last post of this deployment life cycle. In the 2nd chapter C QT Deployer tool were called in post build process. It is okay, but not that okay. Every build time it’s deploying package. In a light weighted QML application it doesn’t take much time, what about a complex project, is it nice to wait for several minutes? To prevent that build time and install time should be separated. Developers don’t deploy that much, they always build their minor changes to see if it affects, at least me 🙂

Sample project code is available on GitHub repository.

Kill Them ALL!

Do you remember Chapter 2. add used add_custom_command for post. It’s time to remove it!

add_custom_command(TARGET ${CMAKE_PROJECT_NAME}
                   COMMAND cqtdeployer -confFile "${CMAKE_BINARY_DIR}/deployment.json")

At this stage if we type make package it cannot create a package. And we don’t have opportunity to call C QT Deployer tool in build time.

Deploying for .run files!

It’s the easiest way to do it actually. Let’s forget about all of the CPack commands from our CMakeLists.txt. I’m adding a new template file called deployment/deployment.sh.in. Just for this step in only has our cqtdeployer command to call.


cqtdeployer -confFile "${CMAKE_BINARY_DIR}/deployment.json"

And it will execute this template script in install time. So we can add a new configure_file() function to list:

configure_file("${CMAKE_SOURCE_DIR}/deployment/deployment.sh.in" "${CMAKE_BINARY_DIR}/deployment.sh")

Do you remember install() function that we used to copy deployment folder to our .deb package for CPack, it is actually for install time. You can see it’s documentation, if you don’t believe me 🙂 and it allows us to do a lot of things. I will use execute_process in install function to call our shell script.

install(CODE "execute_process(COMMAND sh \"${CMAKE_BINARY_DIR}/deployment.sh\")")

\” is string literal to use double-quote mark inside of another double quote. for path parameter it’s a must. At the end of our CMakeLists.txt file will look like this for .run package:

cmake_minimum_required(VERSION 3.10)

project(DeploymentProject LANGUAGES CXX)



set(CMAKE_PREFIX_PATH "/home/muhammet/Qt/5.15.0/gcc_64")

find_package(Qt5 COMPONENTS Core Quick REQUIRED)

configure_file("${CMAKE_SOURCE_DIR}/deployment/deployment.json.in" "${CMAKE_BINARY_DIR}/deployment.json")
configure_file("${CMAKE_SOURCE_DIR}/deployment/deployment.sh.in" "${CMAKE_BINARY_DIR}/deployment.sh")


  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
  PRIVATE Qt5::Core Qt5::Quick)

install(CODE "execute_process(COMMAND sh \"${CMAKE_BINARY_DIR}/deployment.sh\")")

And don’t forget to edit back your deployment.json.in file to turn true “qif”:

    "clear": true,
    "deploySystem": true,
    "extractPlugins": true,
    "noCheckRPATH": true,
    "qif": true,
    "qmlDir": "${CMAKE_SOURCE_DIR}",
    "qmake": "${CMAKE_PREFIX_PATH}/bin/qmake",
    "targetDir" : "${CMAKE_BINARY_DIR}/DeploymentPackage"

Whenever your target is not install it just builds up your project and doesn’t steal your development time.

It didn’t generate a deployment package with current setting

Now it’s time to change Targets to install to generate deployment package.

Current target is set to install from Targets section and deployment package has generated

You can get sample code from GitHub Repository.

For terminal it’s also so easy. make install command will create deployment package

mkdir build
cd build
cmake ..
make -j8
make install

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *