Skip to content

use Qt in a premake project

Alexandre Marcireau edited this page Jun 3, 2018 · 8 revisions

Each Qt class (including Chameleon displays) requires an extra file to be generated before compilation. The program handling this step is called moc.

The options required by moc, as well as the include and link directories required during compilation, depend on the platform. Chameleon provides the file "third_party/chameleon/source/qt.lua" to simplify the integration of Qt in a premake 4 project.

Assuming the following project structure:

solution
├── premake4.lua
├── source
|   ├── project.hpp
|   └── project.cpp
└── third_party
    └── chameleon

the file premake4.lua can use qt.lua as follows:

local qt = require 'third_party/chameleon/qt'

solution 'solution'
    project 'project'
        kind 'ConsoleApp'
        language 'C++'
        location 'build'
        files {'source/*.hpp', 'source/*.cpp'}
        files(qt.moc({
            'third_party/chameleon/source/background_cleaner.hpp',
            'third_party/chameleon/source/dvs_display.hpp',
            'third_party/chameleon/source/flow_display.hpp'},
            'build/moc'))
        includedirs(qt.includedirs())
        libdirs(qt.libdirs())
        links(qt.links())
        buildoptions(qt.buildoptions())
        linkoptions(qt.linkoptions())

The functions provided by qt.lua have the following signatures:

-- generate_configuration merges the given configuration map with the default one.
-- The current os configuration is extracted with premake's os.get().
function generate_configuration(os_to_configuration)

-- moc calls Qt's moc on each file, and writes the result to target_directory.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.moc(files, target_directory, os_to_configuration)

-- includedirs returns a list to be passed to premake's includedirs function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.

-- libdirs returns a list to be passed to premake's libdirs function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.libdirs(os_to_configuration)

-- links returns a list to be passed to premake's links function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.links(os_to_configuration)

-- buildoptions returns a list to be passed to premake's buildoptions function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.buildoptions(os_to_configuration)

-- linkoptions returns a list to be passed to premake's linkoptions function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.linkoptions(os_to_configuration)
  • os_to_configuration
Clone this wiki locally