2011-09-27 11:55:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-09-27 11:55:44 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator
|
2011-09-27 11:55:44 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Free Documentation License
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file included in the packaging of this
|
|
|
|
|
** file.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// NOTE: the sections are not ordered by their logical order to avoid
|
|
|
|
|
// reshuffling the file each time the index order changes (i.e., often).
|
|
|
|
|
// Run the fixnavi.pl script to adjust the links to the index order.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
2014-03-17 12:18:12 +01:00
|
|
|
\contentspage {Qt Creator Manual}
|
2011-12-13 11:52:47 +01:00
|
|
|
\previouspage creator-project-other.html
|
2011-09-27 11:55:44 +02:00
|
|
|
\page creator-project-cmake.html
|
2013-02-20 11:54:30 +01:00
|
|
|
\nextpage creator-project-qbs.html
|
2011-09-27 11:55:44 +02:00
|
|
|
|
|
|
|
|
\title Setting Up a CMake Project
|
|
|
|
|
|
|
|
|
|
CMake is an alternative to qmake for automating the generation of build
|
|
|
|
|
configurations. It controls the software compilation process by using simple
|
|
|
|
|
configuration files, called \c{CMakeLists.txt} files. CMake generates native
|
|
|
|
|
build configurations and workspaces that you can use in the compiler
|
|
|
|
|
environment of your choice.
|
|
|
|
|
|
|
|
|
|
Since \QC 1.1, CMake configuration files are supported. Since \QC 1.3, the
|
|
|
|
|
Microsoft tool chain is supported if the CMake version is at least 2.8.
|
|
|
|
|
|
|
|
|
|
\section1 Setting the Path for CMake
|
|
|
|
|
|
|
|
|
|
You can set the path for the \c CMake executable in \gui{Tools} >
|
2011-10-18 11:27:30 +02:00
|
|
|
\gui{Options > Build & Run > CMake}.
|
2011-09-27 11:55:44 +02:00
|
|
|
|
|
|
|
|
\image qtcreator-cmakeexecutable.png
|
|
|
|
|
|
|
|
|
|
\note Before you open a \c CMake project, you must modify the \c{PATH}
|
2011-10-14 13:33:17 +02:00
|
|
|
environment variable to include the bin folders of \c mingw and Qt.
|
2011-09-27 11:55:44 +02:00
|
|
|
|
2012-10-22 15:03:38 +02:00
|
|
|
For instance, if the Qt 4 SDK is installed in \c {C:\SDK}, you would use the
|
2011-09-27 11:55:44 +02:00
|
|
|
following command to set the environment variables in the command line
|
|
|
|
|
prompt:
|
|
|
|
|
\code
|
|
|
|
|
set PATH=C:\sdk\mingw\bin;C:\sdk\qt\bin;
|
|
|
|
|
\endcode
|
|
|
|
|
Then start \QC by typing:
|
|
|
|
|
\code
|
|
|
|
|
C:\sdk\bin\qtcreator.exe
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
\section1 Opening CMake Projects
|
|
|
|
|
|
|
|
|
|
To open a \c CMake project:
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Select \gui{File} > \gui{Open File or Project}.
|
2011-09-27 11:55:44 +02:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Select the \c{CMakeLists.txt} file from your \c CMake project.
|
2011-09-27 11:55:44 +02:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
A wizard guides you through the rest of the process.
|
|
|
|
|
|
|
|
|
|
\note If the \c CMake project does not have an in-place build, \QC
|
|
|
|
|
lets you specify the directory in which the project is built
|
|
|
|
|
(\l{glossary-shadow-build}{shadow build}).
|
|
|
|
|
|
|
|
|
|
\image qtcreator-cmake-import-wizard1.png
|
|
|
|
|
|
|
|
|
|
The screenshot below shows how you can specify command line arguments to
|
|
|
|
|
\c CMake for your project.
|
|
|
|
|
|
|
|
|
|
\image qtcreator-cmake-import-wizard2.png
|
|
|
|
|
|
|
|
|
|
Normally, there is no need to pass any command line arguments for projects
|
|
|
|
|
that are already built, as \c CMake caches that information.
|
|
|
|
|
|
|
|
|
|
\section1 Building CMake Projects
|
|
|
|
|
|
|
|
|
|
\QC builds \c CMake projects by running \c make, \c mingw32-make, or
|
|
|
|
|
\c nmake depending on your platform. The build errors and warnings are
|
2011-10-14 12:29:53 +02:00
|
|
|
parsed and displayed in the \gui{Issues} output pane.
|
2011-09-27 11:55:44 +02:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
By default, \QC builds the \b{all} target. You can specify which
|
2011-09-27 11:55:44 +02:00
|
|
|
targets to build in \gui{Project} mode, under \gui{Build Settings}.
|
|
|
|
|
|
|
|
|
|
\image qtcreator-cmake-build-settings.png
|
|
|
|
|
|
|
|
|
|
\QC supports multiple build configurations. You can change the build
|
|
|
|
|
directory after the initial import.
|
|
|
|
|
|
|
|
|
|
\section1 Running CMake Projects
|
|
|
|
|
|
|
|
|
|
\QC automatically adds \gui{Run Configurations} for all targets specified
|
|
|
|
|
in the \c CMake project file.
|
|
|
|
|
|
|
|
|
|
For more information about known issues for the current version, see
|
|
|
|
|
\l{Known Issues}.
|
|
|
|
|
|
2013-11-21 10:46:40 +01:00
|
|
|
\section1 Deploying CMake Projects to Embedded Linux Devices
|
|
|
|
|
|
|
|
|
|
\QC cannot extract files to be installed from a CMake project, and
|
|
|
|
|
therefore, only executable targets are automatically added to deployment
|
|
|
|
|
files. You must specify all other files in the \c QtCreatorDeployment.txt
|
|
|
|
|
file that you create and place in the root directory of the CMake project.
|
|
|
|
|
|
|
|
|
|
Use the following syntax in the file:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
<deployment/prefix>
|
|
|
|
|
<relative/source/file1>:<relative/destination/dir1>
|
|
|
|
|
...
|
|
|
|
|
<relative/source/filen>:<relative/destination/dirn>
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
Where:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
|
|
|
|
\li \c{<deployment/prefix>} is the (absolute) path prefix to where files
|
|
|
|
|
are copied on the remote machine.
|
|
|
|
|
|
|
|
|
|
\li \c{<relative/source/file>} is the file path relative to the CMake
|
|
|
|
|
project root. No directories or wildcards are allowed in this
|
|
|
|
|
value.
|
|
|
|
|
|
|
|
|
|
\li \c{<relative/destination/dir>} is the destination directory path
|
|
|
|
|
relative to \c{deployment/prefix}.
|
|
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
To automate the creation of \c QtCreatorDeployment.txt file:
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
|
|
|
|
\li Define the following macros in the top level \c CMakeLists.txt file:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
file(WRITE "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "<deployment/prefix>\n")
|
|
|
|
|
|
|
|
|
|
macro(add_deployment_file SRC DEST)
|
|
|
|
|
file(RELATIVE_PATH path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
file(APPEND "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "${path}/${SRC}:${DEST}\n")
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
macro(add_deployment_directory SRC DEST)
|
|
|
|
|
file(GLOB_RECURSE files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${SRC}/*")
|
|
|
|
|
foreach(filename ${files})
|
|
|
|
|
get_filename_component(path ${filename} PATH)
|
|
|
|
|
add_deployment_file("${filename}" "${DEST}/${path}")
|
|
|
|
|
endforeach(filename)
|
|
|
|
|
endmacro()
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
\li Use \c {add_deployment_file(<file/name>)} to add files and
|
|
|
|
|
\c {add_deployment_directory(<folder/name>)} to add directories
|
|
|
|
|
(including subdirectories) to the \c QtCreatorDeployment.txt file.
|
|
|
|
|
|
|
|
|
|
\li Re-run \c cmake after you add or remove files using the macros.
|
|
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2011-09-27 11:55:44 +02:00
|
|
|
\section1 Adding External Libraries to CMake Projects
|
|
|
|
|
|
|
|
|
|
Through external libraries, \QC can support code completion and syntax
|
|
|
|
|
highlighting as if they were part of the current project or the Qt library.
|
|
|
|
|
|
|
|
|
|
\QC detects the external libraries using the \c FIND_PACKAGE()
|
|
|
|
|
macro. Some libraries come with the CMake installation. You can find those
|
|
|
|
|
in the \c {Modules} directory of your CMake installation.
|
|
|
|
|
|
|
|
|
|
\note If you provide your own libraries, you also need to provide your own
|
|
|
|
|
\c FindFoo.cmake file. For more information, see
|
|
|
|
|
\l{http://vtk.org/Wiki/CMake_FAQ#Writing_FindXXX.cmake_files}{CMake FAQ}.
|
|
|
|
|
|
|
|
|
|
Syntax completion and highlighting work once your project successfully
|
|
|
|
|
builds and links against the external library.
|
|
|
|
|
|
|
|
|
|
*/
|