-
Notifications
You must be signed in to change notification settings - Fork 5
premake workflows
Premake makes it possible for developers to work on the same project with different toolchains. This page provides workflow examples to develop c++ code using a generic code editor (Gedit, Sublime Text, Atom...) and make
or an Integrated Development Environment (Code::blocks, CodeLite, Xcode, Visual Studio...). It assumes that you use the following premake4.lua file:
solution 'eventStreamViewer'
configurations {'Release', 'Debug'}
location 'build'
project 'eventStreamViewer'
-- General settings
kind 'ConsoleApp'
language 'C++'
location 'build'
files {'source/**.hpp', 'source/**.cpp'}
-- Run moc and link to the Qt library (required only when using the Chameleon library displays)
local mocFiles = { -- must contain Chameleon components paths
'/usr/local/include/chameleon/backgroundCleaner.hpp',
'/usr/local/include/chameleon/changeDetectionDisplay.hpp',
'/usr/local/include/chameleon/logarithmicDisplay.hpp',
}
local mocCommand = '/usr/lib/x86_64-linux-gnu/qt5/bin/moc' -- must point to the moc executable
local qtIncludeDirectory = '/usr/include/x86_64-linux-gnu/qt5' -- must point to the directory containing Qt's headers
local qtLibDirectory = '/usr/lib/x86_64-linux-gnu' -- must point to the directory containing Qt's dynamic libraries
local mocDirectory = path.getdirectory(_SCRIPT) .. '/build/moc'
os.rmdir(mocDirectory)
os.mkdir(mocDirectory)
for index, mocFile in pairs(mocFiles) do
if os.execute(mocCommand
.. ' -I\'' .. qtIncludeDirectory .. '/QtQml\''
.. ' -o \'' .. mocDirectory .. '/' .. path.getbasename(mocFile) .. '.cpp\''
.. ' \''.. mocFile .. '\''
) ~= 0 then
print(string.char(27) .. '[31mPre-compiling ' .. mocFile .. ' failed' .. string.char(27) .. '[0m')
os.exit(1)
end
print(string.char(27) .. '[32m' .. mocFile .. ' was successfully pre-compiled' .. string.char(27) .. '[0m')
end
files {'build/moc/**.h', 'build/moc/**.cpp', 'source/**.qml'}
includedirs {qtIncludeDirectory, qtIncludeDirectory .. '/QtGui', qtIncludeDirectory .. '/QtQml'}
configuration 'linux'
libdirs {qtLibDirectory}
links {'Qt5Core', 'Qt5Gui', 'Qt5Qml', 'Qt5Quick'}
buildoptions {'-fPIC'}
configuration 'macosx'
linkoptions {
'-F' .. qtLibDirectory,
'-framework QtCore',
'-framework QtGui',
'-framework QtQml',
'-framework QtQuick',
'-framework QtQuickControls2',
}
configuration {}
-- Declare the configurations
configuration 'Release'
targetdir 'build/Release'
defines {'NDEBUG'}
flags {'OptimizeSpeed'}
configuration 'Debug'
targetdir 'build/Debug'
defines {'DEBUG'}
flags {'Symbols'}
-- Linux specific settings
configuration 'linux'
buildoptions {'-std=c++11'}
linkoptions {'-std=c++11'}
includedirs {'/usr/local/include'}
links {'pthread'}
-- Mac OS X specific settings
configuration 'macosx'
buildoptions {'-std=c++11', '-stdlib=libc++'}
linkoptions {'-std=c++11', '-stdlib=libc++'}
includedirs {'/usr/local/include'}
Since Qt's version varies over time and from an operating system to another, you need to manually edit three lines (18, 19 and 20) in this file to match your operating system and version. Examples for a few platforms are given below.
Debian 8
premake4.lua, lines 19, 20 and 21
local mocCommand = '/usr/lib/x86_64-linux-gnu/qt5/bin/moc' -- must point to the moc executable
local qtIncludeDirectory = '/usr/include/x86_64-linux-gnu/qt5' -- must point to the directory containing Qt's headers
local qtLibDirectory = '/usr/lib/x86_64-linux-gnu' -- must point to the directory containing Qt's dynamic libraries
macOS High Sierra with Homebrew's Qt
premake4.lua, lines 19, 20 and 21
local mocCommand = '/usr/local/opt/qt/bin/moc' -- must point to the moc executable
local qtIncludeDirectory = '/usr/local/opt/qt/include' -- must point to the directory containing Qt's headers
local qtLibDirectory = '/usr/local/opt/qt/lib' -- must point to the directory containing Qt's dynamic libraries
- Edit premake4.lua's variable
mocFiles
(line 14) to list the Chameleon displays you want to use. - Go to your application directory and run
premake4 gmake
. This will generate a build directory containing a Makefile listing the application files, and take care of Qt's pre-compilation step. - Edit the source code. If you want to add source files to your code, create them in the directory source and go back to step 2. If you want to add or remove Chameleon displays, go back to step 1.
- Go to the build directory and run
make
. - Go to the Release directory and run
./myProject
. - Go back to step 3 if you are not happy with the result yet.
- Edit premake.lua's variable
mocFiles
(line 14) to list the Chameleon displays you want to use. - Go to your application directory and run
premake4 [ide]
.[ide]
can bexcode3
,codeblocks
orcodelite
. This will generate a build directory containing a project file for the IDE. This project file is linked to the files in the source directory: any changes applied from the IDE will modify the actual files. - Edit the source code. You can use the IDE to create new files as long as you save them in the source directory. If you want to add or remove Chameleon displays, go back to step 1.
- Compile and run the code using the IDE's interface.
- Go back to step 3 if you are not happy with the result yet.
For macOS users: though the command's name is xcode3
, the generated project is compatible with more recent versions of Xcode. However, the IDE will raise a warning (yellow sign in the top bar), which can be resolved by clicking on it.