Skip to content

Commit 18f491a

Browse files
committed
Do not punish users for using dashes in plugin target names
Implicitly convert the target name to a valid C indentifier, so users may use dash-separated names for their targets. Add warning about plugin name substitution, for the cases where this might be critical. Task-number: QTBUG-135860 Change-Id: Ie148424ec182a3b1ce2af2a0e29c2f9eb8d457f1 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
1 parent 086bb48 commit 18f491a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/corelib/Qt6CoreMacros.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,16 @@ function(qt6_add_plugin target)
26122612
set(plugin_class_name "")
26132613
if (NOT "${arg_PLUGIN_TYPE}" STREQUAL "qml_plugin")
26142614
if (NOT arg_CLASS_NAME)
2615-
set(plugin_class_name "${target}")
2615+
string(MAKE_C_IDENTIFIER "${target}" plugin_class_name)
2616+
if(NOT "${target}" STREQUAL "${plugin_class_name}"
2617+
AND target_type STREQUAL "STATIC_LIBRARY" AND NOT QT_SKIP_PLUGIN_CLASS_NAME_WARNING)
2618+
message(WARNING "The target name '${target}' is not a valid C++ class name and"
2619+
" cannot be used as the plugin CLASS_NAME. It's converted to"
2620+
" '${plugin_class_name}' implicitly. Please adjust the related code paths"
2621+
" accordingly(e.g. Q_IMPORT_PLUGIN(...) calls) or use the CLASS_NAME argument"
2622+
" explicitly. Setting QT_SKIP_PLUGIN_CLASS_NAME_WARNING to ON suppresses this"
2623+
" warning.")
2624+
endif()
26162625
else()
26172626
set(plugin_class_name "${arg_CLASS_NAME}")
26182627
endif()
@@ -2628,7 +2637,7 @@ function(qt6_add_plugin target)
26282637

26292638
_qt_internal_is_c_identifier(is_c_indentifier "${plugin_class_name}")
26302639
if(NOT is_c_indentifier)
2631-
message(FATAL_ERROR "The provided or calculated plugin CLASS_NAME '${plugin_class_name}' of"
2640+
message(FATAL_ERROR "The provided plugin CLASS_NAME '${plugin_class_name}' of"
26322641
" the '${target}' target is not a valid C++ class name. Please use only valid C++"
26332642
" identifiers."
26342643
)

0 commit comments

Comments
 (0)