From 18f491a19290f9d1a62ba4b4f759b9e9d54fd215 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 24 Apr 2025 16:46:11 +0200 Subject: [PATCH] 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 --- src/corelib/Qt6CoreMacros.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index f2e9824cf9f..4ebb6423183 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2612,7 +2612,16 @@ function(qt6_add_plugin target) set(plugin_class_name "") if (NOT "${arg_PLUGIN_TYPE}" STREQUAL "qml_plugin") if (NOT arg_CLASS_NAME) - set(plugin_class_name "${target}") + string(MAKE_C_IDENTIFIER "${target}" plugin_class_name) + if(NOT "${target}" STREQUAL "${plugin_class_name}" + AND target_type STREQUAL "STATIC_LIBRARY" AND NOT QT_SKIP_PLUGIN_CLASS_NAME_WARNING) + message(WARNING "The target name '${target}' is not a valid C++ class name and" + " cannot be used as the plugin CLASS_NAME. It's converted to" + " '${plugin_class_name}' implicitly. Please adjust the related code paths" + " accordingly(e.g. Q_IMPORT_PLUGIN(...) calls) or use the CLASS_NAME argument" + " explicitly. Setting QT_SKIP_PLUGIN_CLASS_NAME_WARNING to ON suppresses this" + " warning.") + endif() else() set(plugin_class_name "${arg_CLASS_NAME}") endif() @@ -2628,7 +2637,7 @@ function(qt6_add_plugin target) _qt_internal_is_c_identifier(is_c_indentifier "${plugin_class_name}") if(NOT is_c_indentifier) - message(FATAL_ERROR "The provided or calculated plugin CLASS_NAME '${plugin_class_name}' of" + message(FATAL_ERROR "The provided plugin CLASS_NAME '${plugin_class_name}' of" " the '${target}' target is not a valid C++ class name. Please use only valid C++" " identifiers." )