diff options
| author | Alexandru Croitor <alexandru.croitor@qt.io> | 2025-07-30 16:38:47 +0200 |
|---|---|---|
| committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2025-08-01 16:36:43 +0200 |
| commit | 26f8dff7daeb6538b9308d2bef77ecea8bd2a80e (patch) | |
| tree | ba8b28235bef5f2e124e8326b7f4718ca3618d2f /cmake/QtBuildRepoExamplesHelpers.cmake | |
| parent | 346a748ffe5571e05b01a02ddbd3131c336ca433 (diff) | |
CMake: Add warnings as errors support for example builds
We want to ensure we don't introduce new build warnings in examples.
We have a mechanism to enable warnings as errors for qt targets like
modules or plugins, but not for targets in example projects.
To enable this, we introduce a new internal target
PlatformExampleInternal, which is linked to all targets created
by qt_add_executable and qt_add_library-like functions in projects
in the <repo>/examples subdirectory.
The detection of targets in example projects is done by checking the
QT_INTERNAL_IS_EXAMPLE_EP_BUILD variable or the
QT_INTERNAL_IS_EXAMPLE_IN_TREE_BUILD variable. These are set either by
ExternalProject_Add in the case of external example projects, or by
qt_examples_build_begin in the case of in-tree example projects.
The PlatformExampleInternal target gets the same warnings as errors
flags as the other Platform*Internal targets.
To enable gradual adoption, the new feature is opt-in rather than
opt-out, on a per-repo basis. The QT_REPO_EXAMPLES_WARNINGS_CLEAN
variable can be set to TRUE in a repo's '.cmake.conf' file.
The warnings as errors behavior is controlled as usual by configuring
qt with -DWARNINGS_ARE_ERRORS=ON.
Pick-to: 6.8 6.9 6.10
Task-number: QTBUG-108448
Change-Id: If62b47b205c111f2a1fec791e5bb6502f5b64f9c
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'cmake/QtBuildRepoExamplesHelpers.cmake')
| -rw-r--r-- | cmake/QtBuildRepoExamplesHelpers.cmake | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cmake/QtBuildRepoExamplesHelpers.cmake b/cmake/QtBuildRepoExamplesHelpers.cmake index d9e219ae80b..a6d7c2b144b 100644 --- a/cmake/QtBuildRepoExamplesHelpers.cmake +++ b/cmake/QtBuildRepoExamplesHelpers.cmake @@ -89,6 +89,9 @@ macro(qt_examples_build_begin) if(active_linker_flags) add_link_options(${active_linker_flags}) endif() + + # Marker for warnings_as_errors. + set(QT_INTERNAL_IS_EXAMPLE_IN_TREE_BUILD ON) endif() # TODO: Change this to TRUE when all examples in all repos are ported to use @@ -467,6 +470,8 @@ function(qt_internal_add_example_external_project subdir) QT_ADDITIONAL_PACKAGES_PREFIX_PATH:STRING QT_ADDITIONAL_QML_PLUGIN_GLOB_PREFIXES:STRING QT_INTERNAL_SKIP_DEPLOYMENT:BOOL + QT_REPO_EXAMPLES_WARNINGS_CLEAN:BOOL + WARNINGS_ARE_ERRORS:BOOL CMAKE_FIND_ROOT_PATH:STRING CMAKE_MODULE_PATH:STRING BUILD_SHARED_LIBS:BOOL @@ -608,6 +613,7 @@ function(qt_internal_add_example_external_project subdir) TEST_COMMAND "" DEPENDS ${deps} CMAKE_CACHE_ARGS ${var_defs} + -DQT_INTERNAL_IS_EXAMPLE_EP_BUILD:BOOL=TRUE -DCMAKE_INSTALL_PREFIX:STRING=<INSTALL_DIR> -DQT_INTERNAL_SET_EXAMPLE_INSTALL_DIR_TO_DOT:BOOL=TRUE ${terminal_args} |
