summaryrefslogtreecommitdiffstats
path: root/examples/CMakeLists.txt
diff options
context:
space:
mode:
authorKevin Funk <kevin.funk@kdab.com>2019-06-04 17:08:47 +0200
committerKevin Funk <kevin.funk@kdab.com>2019-06-05 12:53:28 +0000
commit99539a289491a2a709c2a63cd91eac155a1699da (patch)
treed928d6c6e123c6588261bea9358354fe1e1a7400 /examples/CMakeLists.txt
parentace549587073d387823815b02ec85a28da408844 (diff)
Allow to build examples as standalone project
Create CMake config files which can be used from the very same CMake project. These CMake config files simply do not create any targets, controlled via the QT_NO_CREATE_TARGETS. This patch also allows to build qtbase.git:examples as a standalone project, against an already-built Qt. Ran this: ag -s "QT " examples -l -0 | xargs -0 -n 1 .../util/cmake/pro2cmake.py --is-example Task-number: QTBUG-74713 Change-Id: I44cce5a4048618b30f890c5b789592c227a8b47d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'examples/CMakeLists.txt')
-rw-r--r--examples/CMakeLists.txt67
1 files changed, 65 insertions, 2 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index cdbf0c411d..5f61a098bd 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,3 +1,25 @@
+# special case begin
+cmake_minimum_required(VERSION 3.14.0)
+
+project(QtBaseExamples LANGUAGES CXX C ASM)
+
+# Check whether this project is built as part of a Qt build
+if (CMAKE_PROJECT_NAME STREQUAL "QtBaseExamples")
+ set(QT_STANDALONE_EXAMPLES_BUILD TRUE)
+endif()
+
+if (NOT QT_STANDALONE_EXAMPLES_BUILD)
+ # It is part of a Qt build => Use the CMake config files from the binary dir
+ list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
+ # Also make sure the CMake config files do not recreate the already-existing targets
+ set(QT_NO_CREATE_TARGETS TRUE)
+endif()
+
+find_package(Qt5 COMPONENTS DBus Network Test Concurrent Sql Widgets Xml Gui)
+# special case end
+
+# Generated from examples.pro.
+
add_subdirectory(corelib)
add_subdirectory(embedded)
add_subdirectory(qpa)
@@ -5,21 +27,62 @@ add_subdirectory(qpa)
if(TARGET Qt::DBus)
add_subdirectory(dbus)
endif()
+
if(TARGET Qt::Network)
add_subdirectory(network)
endif()
+
if(TARGET Qt::Test)
add_subdirectory(qtestlib)
endif()
+
if(TARGET Qt::Concurrent)
add_subdirectory(qtconcurrent)
endif()
+
if(TARGET Qt::Sql)
add_subdirectory(sql)
endif()
+
+if(TARGET Qt::Widgets)
+ add_subdirectory(widgets)
+endif()
+
+if(TARGET Qt::Xml)
+ add_subdirectory(xml)
+endif()
+
if(TARGET Qt::Gui)
add_subdirectory(gui)
+
+ if(QT_FEATURE_opengl)
+# add_subdirectory(opengl) # special case: removed
+ endif()
+
+ if(QT_FEATURE_vulkan)
+# add_subdirectory(vulkan) # special case: removed
+ endif()
endif()
-if(TARGET Qt::Widgets)
- add_subdirectory(widgets)
+
+# special case begin
+if (NOT QT_STANDALONE_EXAMPLES_BUILD)
+ # We use AUTOMOC/UIC/RCC in the examples. Make sure to not fail on a fresh Qt build, that e.g. the moc binary does not exist yet.
+
+ # This function gets all targets below this directory
+ function(get_all_targets _result _dir)
+ get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
+ foreach(_subdir IN LISTS _subdirs)
+ get_all_targets(${_result} "${_subdir}")
+ endforeach()
+ get_property(_sub_targets DIRECTORY "${_dir}" PROPERTY BUILDSYSTEM_TARGETS)
+ set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
+ endfunction()
+
+ get_all_targets(targets "${CMAKE_CURRENT_SOURCE_DIR}")
+
+ foreach(target ${targets})
+ qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "moc" "uic" "rcc")
+ endforeach()
+
endif()
+# special case end