Minimal Qt/CMake template

I'm starting working on the GUI submission tool for Acoustid and I wanted to use CMake instead of qmake for building the application. I couldn't find anywhere a simple example of what do I have to put into my CMakeLists.txt in order to build a Qt application while correctly handling all moc files, ui files and resources.

Here is a minimal template that can be used for starting a Qt/CMake project from scratch:

cmake_minimum_required(VERSION 2.6)


find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED)

set(myproject_HEADERS someclass.h)
set(myproject_SOURCES someclass.cpp main.cpp)
set(myproject_UIS myproject.ui)
set(myproject_RESOURCES myproject.qrc)

qt4_wrap_cpp(myproject_MOC ${myproject_HEADERS})
qt4_wrap_ui(myproject_UIS_H ${myproject_UIS})
qt4_add_resources(myproject_RESOURCES_CPP ${myproject_RESOURCES})



target_link_libraries(myproject ${QT_LIBRARIES})

Leave a Reply

comments powered by Disqus