CoR

Hello World in Qt using CMake and OpenEmbedded

Let’s compile !

By default, compiling Qt programs rely on qmake. Since this is not standard C++, few steps needs to be done before our project can be handled by regular compilers like gcc or mvc.
In order to that, you can do a .pro file and describe your project, qmake will handle it and give you a nice executable file.

When you are using other libraries, CUDA, stuff like that, doing that all that with qmake gets tricky.
Let’s use CMake instead ! It’s way much powerful, portable, simple, etc …

Here is a simple CMakeLists.txt for our program:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(HelloWorldQt)
 
SET(CMAKE_BUILD_TYPE Release)
 
SET(CMAKE_CXX_FLAGS "-Wall")
 
# QT4 Handling
FIND_PACKAGE(Qt4 REQUIRED)
 
INCLUDE(${QT_USE_FILE})
 
SET( HWQ_Qt4_SRC
	MainWindow.h
	HelloWidget.h
)
SET( HWQ_Qt4_UI
)
SET( HWQ_Qt4_RES
)
 
QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC})
QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI})
QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES})
 
INCLUDE_DIRECTORIES( . )
 
# General
SET( HWQ_SRC
	main.cpp
	MainWindow.cpp
	HelloWidget.cpp
	${HWQ_MOC_CPP}
	${HWQ_UI_CPP}
	${HWQ_RES_H}
)
 
SET( HWQ_LIB
	${QT_LIBRARIES}
)
 
ADD_EXECUTABLE( HelloWorldQt ${HWQ_SRC} )
TARGET_LINK_LIBRARIES( HelloWorldQt ${HWQ_LIB} )
INSTALL_TARGETS( /bin HelloWorldQt)

An overall view on what cmake is going to do is that it will first ask qmake to handle all Qt files, and then it will compile the sources, along with some files produced by qmake, and finally link all things together.

On Linux or Mac, simply do this commands in the directory where there is your sources:

cmake .
make
./HelloWorldQt

It’s likely to work by doing so if your Qt installation is correct (meaning that qmake is in your path, and LD_PATH too).

Pages: 1 2 3

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...