Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qt_standard_project_setup.qdoc
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qt-standard-project-setup.html
6\ingroup cmake-commands-qtcore
7
8\title qt_standard_project_setup
9\keyword qt_standard_project_setup()
10
11\summary {Setup project-wide defaults to a standard arrangement.}
12
13\include cmake-find-package-core.qdocinc
14
15\cmakecommandsince 6.3
16
17\section1 Synopsis
18
19\badcode
20qt_standard_project_setup(
21 [REQUIRES <version>]
22 [SUPPORTS_UP_TO <version>]
23 [I18N_TRANSLATED_LANGUAGES <language...>]
24 [I18N_SOURCE_LANGUAGE <language>]
25)
26\endcode
27
28\versionlessCMakeCommandsNote qt6_standard_project_setup()
29
30\section1 Description
31
32This command simplifies the task of setting up a typical Qt application.
33It would usually be called immediately after the first \c{find_package(Qt6)}
34call, normally in the top level \c{CMakeLists.txt} file and before any targets
35have been defined. If you call it later, it does not apply to any targets
36defined before, with possibly confusing results. It does the following things:
37
38\list
39\li The standard CMake variables \c{CMAKE_AUTOMOC} and \c{CMAKE_AUTOUIC}
40 are set to true if they are not already defined.
41 This enables all Qt-related autogen features by default for subsequently
42 created targets in the current directory scope and below.
43\li CMake's \l{GNUInstallDirs} module is automatically included. This defines
44 appropriate defaults for variables like \c{CMAKE_INSTALL_BINDIR},
45 \c{CMAKE_INSTALL_LIBDIR}, and so on.
46\li When targeting Windows, if the \c{CMAKE_RUNTIME_OUTPUT_DIRECTORY} variable
47 is not already set, it will be set to
48 \c{${CMAKE_CURRENT_BINARY_DIR}}.
49\li When target platforms other than Apple or Windows, \c{CMAKE_INSTALL_RPATH}
50 will be augmented as described below.
51\li CMake's \l USE_FOLDERS property is set to \c{ON}, and \l QT_TARGETS_FOLDER is
52 set to \c{QtInternalTargets}. IDEs that support folders will display
53 Qt-internal targets in this folder.
54\li When using the Xcode generator with CMake 4.4 or later,
55 \c{CMAKE_XCODE_LINK_BUILD_PHASE_MODE} is set to \c{KNOWN_LOCATION} if it is
56 not already defined. This causes linked libraries and frameworks to be added
57 to Xcode's \e{Link Binary With Libraries} build phase, making them visible
58 in the Xcode target's \e{General} tab rather than being passed as raw linker
59 flags.
60\endlist
61
62Since Qt 6.5, it is possible to change the default behavior of Qt's CMake
63API by opting in to behavior changes from newer Qt versions via
64\l{Qt CMake policies}. This is similar to CMake's own policy concept
65(compare \l{cmake_policy}). If \c{REQUIRES} is specified, all policies
66introduced in Qt versions up to and including \c{REQUIRES} are automatically
67set to \c{NEW}, and using an older Qt version will result in an error.
68For example, specifying \c{REQUIRES 6.8} enables policies QTP0001 through
69QTP0005. If \c{SUPPORTS_UP_TO} is also specified, policies up to that version
70are enabled as well, but without requiring that particular Qt version to be
71present.
72
73The following policies are available:
74
75\annotatedlist qt-cmake-policies
76
77See \l qt_policy() for details on manually setting individual policies.
78
79On platforms that support \c{RPATH} (other than Apple platforms), two values
80are appended to the \c{CMAKE_INSTALL_RPATH} variable by this command.
81\c{$ORIGIN} is appended so that libraries will find other libraries they depend
82on in the same directory as themselves. \c{$ORIGIN/<reldir>} is also appended,
83where \c{<reldir>} is the relative path from \c{CMAKE_INSTALL_BINDIR} to
84\c{CMAKE_INSTALL_LIBDIR}. This allows executables installed to
85\c{CMAKE_INSTALL_BINDIR} to find any libraries they may depend on installed to
86\c{CMAKE_INSTALL_LIBDIR}. Any duplicates in \c{CMAKE_INSTALL_RPATH} are
87removed. In practice, these two values ensure that executables and libraries
88will find their link-time dependencies, assuming projects install them to the
89default locations the \l{install(TARGETS)} command uses when no destination is
90explicitly provided.
91
92To disable folder support for IDEs, set \l USE_FOLDERS to \c OFF before or after
93the call to \c{qt_standard_project_setup}.
94
95The \c{qt_standard_project_setup()} command can effectively be disabled by
96setting the \l{QT_NO_STANDARD_PROJECT_SETUP} variable to true.
97
98\sa qt_generate_deploy_app_script()
99\sa qt_policy()
100
101\section1 Internationalization
102
103Since Qt 6.7, it is possible to specify the languages that are used for project
104internationalization with the \c I18N_TRANSLATED_LANGUAGES argument. See \l
105QT_I18N_TRANSLATED_LANGUAGES for details.
106
107Use I18N_SOURCE_LANGUAGE to specify the language that translatable strings are
108written in. By default, \c en is used. See \l QT_I18N_SOURCE_LANGUAGE for
109details.
110
111\section1 Example
112
113\include cmake-generate-deploy-app-script.qdocinc
114
115\sa {Automatic Determination of .ts File Paths}{qt_add_translations()}
116*/