Using CMake build system: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(→‎CMake: Add Qt5 hint, because to use cmake with Qt5 is different then Qt4.)
Line 1: Line 1:


= CMake =
= CMake with Qt4 =
CMake - the cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.
CMake - the cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.


You can use it instead qmake, native Qt buid system. In this article i describe base functionality, that usualy used to build simple project.
You can use it instead qmake, native Qt buid system. In this article i describe base functionality, that usualy used to build simple project.


This article show you to use cmake with Qt4. For Qt5 see here [http://doc.qt.io/qt-5/cmake-manual.html Qt5 CMake Manual]
===== qmake typical .pro file =====
===== qmake typical .pro file =====


Line 66: Line 67:


== Project using CMake ==
== Project using CMake ==
''' KDE SC
* [http://www.kde.org KDE]
* Second Life  
* Second Life  


== Links ==
== Links ==
* [http://www.cmake.org/ Official Web-site]
* [http://doc.qt.io/qt-5/cmake-manual.html Qt5 CMake Manual]
* [http://www.cmake.org/ Official cmake Web-site]

Revision as of 17:20, 10 May 2015

CMake with Qt4

CMake - the cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.

You can use it instead qmake, native Qt buid system. In this article i describe base functionality, that usualy used to build simple project.

This article show you to use cmake with Qt4. For Qt5 see here Qt5 CMake Manual

qmake typical .pro file
TEMPLATE = app
SOURCES += main.cpp  mainwindow.cpp
HEADERS+= mainwindow.h
FORMS += mainwindow.ui
RESOURCES+= main.qrc

As you can see, this project consists from 4 files. Three of them is implementing MainWindow class and one is main.cpp file.

CMakeLists.txt for same project
cmake_minimum_required(VERSION 2.6)
project ( PROJECT_NAME )

# declaring files in your project

set ( SOURCES
 main.cpp
 mainwindow.cpp
)

set ( MOC_HEADERS
 mainwindow.h
)

set ( UIS
 mainwindow.ui
)

set ( RESOURCES
 main.qrc
)

# Next lines needed for building all Qt projects
find_package( Qt4 REQUIRED )
include( ${QT_USE_FILE} )
add_definitions( ${QT_DEFINITIONS} )
include_directories( ${CMAKE_BINARY_DIR} )


# Next, using precompiler, compiler and linker

# using Qt meta-system (precompiler)
QT4_ADD_RESOURCES( RES_SOURCES ${RESOURCES} )
QT4_WRAP_UI( UI_HEADERS ${UIS} )
QT4_WRAP_CPP( MOC_SRCS ${MOC_HEADERS} )

# compile
add_executable( PROJECT_NAME ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )
# or use line below instead, if you using Windows ™ Operating System.
#add_executable( PROJECT_NAME WIN32 ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )

# build it (link libraries)
target_link_libraries( PROJECT_NAME ${QT_LIBRARIES} )

You may use CMake, but most of people advice, not to use CMake for simple projects, because qmake build system functionality is more than enough for simple projects.

Project using CMake

  • KDE
  • Second Life

Links