aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <[email protected]>2021-11-11 15:06:55 +0100
committerFabian Kosmale <[email protected]>2022-03-29 22:12:43 +0200
commit612d988243496aa1fc53442c0a385d633b411872 (patch)
treec8a7663eebb62e4a1f9b6449dd08e41da533908d
parenta0560af8afff487b4f6ecc0618a85b68ef5321a1 (diff)
Add cmake support for examples
qml-i18n needed to be ported to CMake first. It uses qt_add_translations introduced in 6.2 As a drive-by, move find_package calls from examples' CML to the top level CML, and make the QtSql dependency optional. Also make sure that we only add the dynamicscene example when the Quick target is available. Pick-to: 6.2 6.3 Fixes: QTBUG-90964 Change-Id: Id357eb14e4704753386e01393300966eb89b4e86 Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r--CMakeLists.txt2
-rw-r--r--examples/CMakeLists.txt2
-rw-r--r--examples/qml/CMakeLists.txt5
-rw-r--r--examples/qml/qml-i18n/CMakeLists.txt44
-rw-r--r--examples/quickcontrols2/CMakeLists.txt4
5 files changed, 52 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3bf7d25cd..8dae927256 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ project(QtDeclarative # special case
)
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) # special case
-find_package(Qt6 ${PROJECT_VERSION} QUIET CONFIG OPTIONAL_COMPONENTS Gui Network Widgets OpenGL OpenGLWidgets Sql Concurrent Test LanguageServerPrivate)
+find_package(Qt6 ${PROJECT_VERSION} QUIET CONFIG OPTIONAL_COMPONENTS Gui Network Widgets OpenGL OpenGLWidgets Sql Concurrent Test LanguageServerPrivate LinguistTools)
# Set up QT_HOST_PATH as an extra root path to look for the ShaderToolsTools package
# when cross-compiling.
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 86b8aaad1a..861b34e33c 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,5 +1,3 @@
-find_package(Qt6 REQUIRED COMPONENTS Sql)
-
qt_examples_build_begin(EXTERNAL_BUILD)
add_subdirectory(qml)
diff --git a/examples/qml/CMakeLists.txt b/examples/qml/CMakeLists.txt
index 459fe041c9..9601672513 100644
--- a/examples/qml/CMakeLists.txt
+++ b/examples/qml/CMakeLists.txt
@@ -1,10 +1,13 @@
-qt_internal_add_example(dynamicscene)
add_subdirectory(referenceexamples)
add_subdirectory(tutorials)
qt_internal_add_example(shell)
if(TARGET Qt::Quick)
qt_internal_add_example(qmlextensionplugins)
qt_internal_add_example(xmlhttprequest)
+ if (TARGET Qt::lupdate)
+ qt_internal_add_example(qml-i18n)
+ endif()
+ qt_internal_add_example(dynamicscene)
endif()
if(QT_FEATURE_qml_network AND TARGET Qt::Quick)
qt_internal_add_example(networkaccessmanagerfactory)
diff --git a/examples/qml/qml-i18n/CMakeLists.txt b/examples/qml/qml-i18n/CMakeLists.txt
new file mode 100644
index 0000000000..ad69bd6db6
--- /dev/null
+++ b/examples/qml/qml-i18n/CMakeLists.txt
@@ -0,0 +1,44 @@
+cmake_minimum_required(VERSION 3.16)
+project(qml-i18n LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmli18n")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Qml LinguistTools)
+
+qt_add_executable(qmli18n WIN32 MACOSX_BUNDLE main.cpp)
+
+target_link_libraries(qmli18n PRIVATE
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+)
+
+qt_add_qml_module(qmli18n
+ URI dynamicscene
+ VERSION 1.0
+ QML_FILES
+ qml-i18n.qml
+ NO_RESOURCE_TARGET_PATH
+)
+
+qt_add_translations(qmli18n
+ TS_FILES
+ i18n/base.ts
+ i18n/qml_en.ts
+ i18n/qml_en_AU.ts
+ i18n/qml_fr.ts
+)
+
+install(TARGETS qmli18n
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/quickcontrols2/CMakeLists.txt b/examples/quickcontrols2/CMakeLists.txt
index bca1743245..7a51634790 100644
--- a/examples/quickcontrols2/CMakeLists.txt
+++ b/examples/quickcontrols2/CMakeLists.txt
@@ -1,5 +1,7 @@
qt_internal_add_example(gallery)
-add_subdirectory(chattutorial)
+if (TARGET Qt::Sql)
+ add_subdirectory(chattutorial)
+endif()
if (QT_FEATURE_quicktemplates2_calendar AND TARGET Qt::Sql)
qt_internal_add_example(eventcalendar)
endif()