Using CMake build system: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=CMake=
h1. CMake


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.


=====qmake typical *.pro file=====
===== qmake typical '''.pro file
<br /><code><br />TEMPLATE = app<br />SOURCES ''= main.cpp  mainwindow.cpp<br />HEADERS''= mainwindow.h<br />FORMS ''= mainwindow.ui<br />RESOURCES''= main.qrc<br /></code>
<br />As you can see, this project consists from 4 files. Three of them is implementing MainWindow class and one is main.cpp file.
<br />h5. CMakeLists.txt for same project
<br /><code>cmake_minimum_required(VERSION 2.6)<br />project ( PROJECT_NAME )
<br /># declaring files in your project
<br />set ( SOURCES<br /> main.cpp<br /> mainwindow.cpp<br />)
<br />set ( MOC_HEADERS<br /> mainwindow.h<br />)
<br />set ( UIS<br /> mainwindow.ui<br />)
<br />set ( RESOURCES<br /> main.qrc<br />)
<br /># Next lines needed for building all Qt projects<br />find_package( Qt4 REQUIRED )<br />include( ${QT_USE_FILE} )<br />add_definitions( ${QT_DEFINITIONS} )<br />include_directories( ${CMAKE_BINARY_DIR} )


As you can see, this project consists from 4 files. Three of them is implementing MainWindow class and one is main.cpp file.
<br /># Next, using precompiler, compiler and linker
<br /># using Qt meta-system &amp;#40;precompiler&amp;amp;#41;<br />QT4_ADD_RESOURCES( RES_SOURCES ${RESOURCES} )<br />QT4_WRAP_UI( UI_HEADERS ${UIS} )<br />QT4_WRAP_CPP( MOC_SRCS ${MOC_HEADERS} )
<br /># compile<br />add_executable( PROJECT_NAME ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )<br /># or use line below instead, if you using Windows ™ Operating System.<br />#add_executable( PROJECT_NAME WIN32 ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )
<br /># build it (link libraries)<br />target_link_libraries( PROJECT_NAME ${QT_LIBRARIES} )<br /></code>
<br />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.
<br />h2. Project using CMake<br />''' KDE SC<br />* Second Life =====


=====CMakeLists.txt for same project=====
== Links<br />* &quot;Official Web-site&amp;quot;:http://www.cmake.org/ ==
 
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==
 
* <span class="caps">KDE</span> SC
* Second Life
 
==Links==
 
* [http://www.cmake.org/ Official Web-site] ''[cmake.org]''
* [http://en.wikipedia.org/wiki/CMake CMake on Wikipedia] ''[en.wikipedia.org]''

Revision as of 11:25, 24 February 2015

h1. CMake

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.

===== qmake typical .pro file


<br />TEMPLATE = app<br />SOURCES ''= main.cpp  mainwindow.cpp<br />HEADERS''= mainwindow.h<br />FORMS ''= mainwindow.ui<br />RESOURCES''= main.qrc<br />


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


cmake_minimum_required(VERSION 2.6)<br />project ( PROJECT_NAME )
<br /># declaring files in your project
<br />set ( SOURCES<br /> main.cpp<br /> mainwindow.cpp<br />)
<br />set ( MOC_HEADERS<br /> mainwindow.h<br />)
<br />set ( UIS<br /> mainwindow.ui<br />)
<br />set ( RESOURCES<br /> main.qrc<br />)
<br /># Next lines needed for building all Qt projects<br />find_package( Qt4 REQUIRED )<br />include( ${QT_USE_FILE} )<br />add_definitions( ${QT_DEFINITIONS} )<br />include_directories( ${CMAKE_BINARY_DIR} )

<br /># Next, using precompiler, compiler and linker
<br /># using Qt meta-system &amp;#40;precompiler&amp;amp;#41;<br />QT4_ADD_RESOURCES( RES_SOURCES ${RESOURCES} )<br />QT4_WRAP_UI( UI_HEADERS ${UIS} )<br />QT4_WRAP_CPP( MOC_SRCS ${MOC_HEADERS} )
<br /># compile<br />add_executable( PROJECT_NAME ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )<br /># or use line below instead, if you using Windows  Operating System.<br />#add_executable( PROJECT_NAME WIN32 ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )
<br /># build it (link libraries)<br />target_link_libraries( PROJECT_NAME ${QT_LIBRARIES} )<br />


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.
h2. Project using CMake
KDE SC
* Second Life =====

Links
* "Official Web-site&quot;:http://www.cmake.org/