aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2022-12-22 17:24:16 +0100
committerSami Shalayel <sami.shalayel@qt.io>2023-02-02 18:11:07 +0100
commit01d84ffc74d4328240e4f242f35f34c2164dbbca (patch)
tree36fa3292d150277179ea5492c589926cb6a8501d /src
parent55f3bf8882fc8eeb132b4d2af9158bd1fee6bd78 (diff)
qmltc: export generated classes
Add QMLTC_EXPORT_MACRO_NAME and QMLTC_EXPORT_FILE_NAME arguments to qt_add_qml_module() that allows the user to export qmltc-generated code from its library. The qmltc-generated code will include the header-file specified in QMLTC_EXPORT_FILE_NAME and will be exported with the macro specified by QMLTC_EXPORT_MACRO_NAME. Leave both options unspecified to not export the code generated by qmltc. Describe the options in the documentation and write a test to see if the class really has an export macro in the generated code: 1) tst_qmltc_qprocess will test if the macro and the header are correctly inserted in the generated code. 2) tst_qmltc_{no,}diskcache will test if the generated code can still be used from a static library. Fixes: QTBUG-106840 Task-number: QTBUG-96040 Change-Id: I554f03bcdf043e8114e42f51a7289a5c00de4f89 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/Qt6QmlMacros.cmake41
-rw-r--r--src/qml/doc/src/cmake/qt_add_qml_module.qdoc14
2 files changed, 49 insertions, 6 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 6b3e8ffb08..70f33d0749 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -58,6 +58,8 @@ function(qt6_add_qml_module target)
INSTALL_DIRECTORY
INSTALL_LOCATION
TYPE_COMPILER_NAMESPACE
+ QMLTC_EXPORT_DIRECTIVE
+ QMLTC_EXPORT_FILE_NAME
)
set(args_multi
@@ -147,11 +149,32 @@ function(qt6_add_qml_module target)
)
endif()
- if (DEFINED arg_TYPE_COMPILER_NAMESPACE AND NOT arg_ENABLE_TYPE_COMPILER)
- message(WARNING
- "TYPE_COMPILER_NAMESPACE is set, but ENABLE_TYPE_COMPILER is not specified. "
- "The TYPE_COMPILER_NAMESPACE value will be ignored."
- )
+ if (NOT arg_ENABLE_TYPE_COMPILER)
+ if (DEFINED arg_TYPE_COMPILER_NAMESPACE)
+ message(WARNING
+ "TYPE_COMPILER_NAMESPACE is set, but ENABLE_TYPE_COMPILER is not specified. "
+ "The TYPE_COMPILER_NAMESPACE value will be ignored."
+ )
+ endif()
+
+ if (DEFINED arg_QMLTC_EXPORT_DIRECTIVE)
+ message(WARNING
+ "QMLTC_EXPORT_DIRECTIVE is set, but ENABLE_TYPE_COMPILER is not specified. "
+ "The QMLTC_EXPORT_DIRECTIVE value will be ignored."
+ )
+ endif()
+ if (DEFINED arg_QMLTC_EXPORT_FILE_NAME)
+ message(WARNING
+ "QMLTC_EXPORT_FILE_NAME is set, but ENABLE_TYPE_COMPILER is not specified. "
+ "The QMLTC_EXPORT_FILE_NAME will be ignored."
+ )
+ endif()
+ else()
+ if ((DEFINED arg_QMLTC_EXPORT_FILE_NAME) AND (NOT (DEFINED arg_QMLTC_EXPORT_DIRECTIVE)))
+ message(FATAL_ERROR
+ "Specifying a value for QMLTC_EXPORT_FILE_NAME also requires one for QMLTC_EXPORT_DIRECTIVE."
+ )
+ endif()
endif()
set(is_executable FALSE)
@@ -670,6 +693,8 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details."
QML_FILES ${arg_QML_FILES}
IMPORT_PATHS ${arg_IMPORT_PATH}
NAMESPACE ${qmltc_namespace}
+ EXPORT_MACRO_NAME ${arg_QMLTC_EXPORT_DIRECTIVE}
+ EXPORT_FILE_NAME ${arg_QMLTC_EXPORT_FILE_NAME}
)
endif()
@@ -1243,7 +1268,7 @@ endfunction()
# Compile Qml files (.qml) to C++ source files with Qml Type Compiler (qmltc).
function(_qt_internal_target_enable_qmltc target)
set(args_option "")
- set(args_single NAMESPACE)
+ set(args_single NAMESPACE EXPORT_MACRO_NAME EXPORT_FILE_NAME)
set(args_multi QML_FILES IMPORT_PATHS)
cmake_parse_arguments(PARSE_ARGV 1 arg
@@ -1276,6 +1301,10 @@ function(_qt_internal_target_enable_qmltc target)
if(arg_NAMESPACE)
list(APPEND common_args --namespace "${arg_NAMESPACE}")
endif()
+ if(arg_EXPORT_MACRO_NAME)
+ list(APPEND common_args --export "${arg_EXPORT_MACRO_NAME}")
+ list(APPEND common_args --exportInclude "${arg_EXPORT_FILE_NAME}")
+ endif()
get_target_property(output_dir ${target} QT_QML_MODULE_OUTPUT_DIRECTORY)
set(qmldir_file ${output_dir}/qmldir)
diff --git a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
index 857779af2d..e7572163f0 100644
--- a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
+++ b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc
@@ -50,6 +50,9 @@ qt_add_qml_module(
[NO_IMPORT_SCAN]
[ENABLE_TYPE_COMPILER]
[TYPE_COMPILER_NAMESPACE namespace]
+ [QMLTC_EXPORT_DIRECTIVE export_macro]
+ [QMLTC_EXPORT_FILE_NAME header_defining_export_macro]
+
)
\endcode
@@ -691,4 +694,15 @@ can be put instead in a custom namespace, where different subnamespaces are to
be separated by a "::", e.g. "MyNamespace::MySubnamespace" for the namespace MySubnamespace that
is inside the MyNamespace. Apart from the "::", C++ namespace naming rules
apply.
+
+\c QMLTC_QMLTC_EXPORT_DIRECTIVE should be used with \c QMLTC_EXPORT_FILE_NAME when
+the classes generated by \l{QML Type Compiler}{qmltc} should be exported from
+the qml library. By default, classes generated by qmltc are not exported from
+their library.
+The header defining the export macro for the current library
+can be specified as an optional argument to \c QMLTC_EXPORT_FILE_NAME while the
+exporting macro name should be specified as an argument to
+\c QMLTC_QMLTC_EXPORT_DIRECTIVE. If no additional include is required or wanted,
+e.g. when the header of the export macro is already indirectly included by a base
+class, then the \c QMLTC_EXPORT_FILE_NAME option can be left out.
*/