File tree 5 files changed +80
-0
lines changed
5 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -918,3 +918,26 @@ function(_qt_internal_configure_file mode)
918
918
919
919
configure_file ("${input_file} " "${arg_OUTPUT} " @ONLY)
920
920
endfunction ()
921
+
922
+ # The function checks if `value` is a valid C indentifier.
923
+ #
924
+ # Synopsis
925
+ #
926
+ # _qt_internal_is_c_identifier(<out_var> <value>)
927
+ #
928
+ # Arguments
929
+ #
930
+ # `out_var`
931
+ # Variable name for the evaluation result.
932
+ #
933
+ # `value`
934
+ # The string for the evaluation.
935
+ function (_qt_internal_is_c_identifier out_var value )
936
+ string (MAKE_C_IDENTIFIER "${value} " value_valid)
937
+
938
+ if (value AND "${value} " STREQUAL "${value_valid} " )
939
+ set (${out_var} "TRUE" PARENT_SCOPE)
940
+ else ()
941
+ set (${out_var} "FALSE" PARENT_SCOPE)
942
+ endif ()
943
+ endfunction ()
Original file line number Diff line number Diff line change @@ -2626,6 +2626,14 @@ function(qt6_add_plugin target)
2626
2626
endif ()
2627
2627
endif ()
2628
2628
2629
+ _qt_internal_is_c_identifier(is_c_indentifier "${plugin_class_name} " )
2630
+ if (NOT is_c_indentifier)
2631
+ message (FATAL_ERROR "The provided or calculated plugin CLASS_NAME '${plugin_class_name} ' of"
2632
+ " the '${target} ' target is not a valid C++ class name. Please use only valid C++"
2633
+ " identifiers."
2634
+ )
2635
+ endif ()
2636
+
2629
2637
set_target_properties (${target} PROPERTIES QT_PLUGIN_CLASS_NAME "${plugin_class_name} " )
2630
2638
2631
2639
# Create a plugin initializer object library for static plugins.
Original file line number Diff line number Diff line change @@ -482,5 +482,35 @@ if(NOT QNX AND NOT WASM AND NOT (WIN32 AND QT_BUILD_MINIMAL_STATIC_TESTS)
482
482
_qt_internal_test_expect_pass(test_qt_add_ui_11)
483
483
endif ()
484
484
485
+ # Valid plugin names
486
+ set (valid_plugin_class_names
487
+ TestPluginNameUpper
488
+ Test_Plugin_Name
489
+ _Test_plugin_name
490
+ testpluginnamelower
491
+ Test0PluginName
492
+ )
493
+ foreach (plugin_class_name IN LISTS valid_plugin_class_names)
494
+ _qt_internal_test_expect_pass(test_plugin_class_name
495
+ TESTNAME test_plugin_class_name_${plugin_class_name}
496
+ BUILD_OPTIONS
497
+ -DPLUGIN_CLASS_NAME=${plugin_class_name}
498
+ )
499
+ endforeach ()
500
+
501
+ # Invalid plugin names
502
+ set (invalid_plugin_class_names
503
+ 0TestPluginName
504
+ Test -Plugin-Name
505
+ Test .plugin.name
506
+ )
507
+ foreach (plugin_class_name IN LISTS invalid_plugin_class_names)
508
+ _qt_internal_test_expect_fail(test_plugin_class_name
509
+ TESTNAME test_plugin_class_name_${plugin_class_name}
510
+ BUILD_OPTIONS
511
+ -DPLUGIN_CLASS_NAME=${plugin_class_name}
512
+ )
513
+ endforeach ()
514
+
485
515
# Add all tests using CMake's RunCMake test module
486
516
add_subdirectory (RunCMake)
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2025 The Qt Company Ltd.
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+
4
+ cmake_minimum_required (VERSION 3.20)
5
+
6
+ project (test_plugin_class_name_${PLUGIN_CLASS_NAME} LANGUAGES CXX)
7
+
8
+ find_package (Qt6Core REQUIRED)
9
+
10
+ configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /plugin.cpp.in"
11
+ "${CMAKE_CURRENT_BINARY_DIR} /plugin.cpp" @ONLY)
12
+
13
+ qt_add_plugin(test_plugin CLASS_NAME ${PLUGIN_CLASS_NAME} "${CMAKE_CURRENT_BINARY_DIR} /plugin.cpp" )
Original file line number Diff line number Diff line change
1
+ // Copyright (C) 2025 The Qt Company Ltd.
2
+ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
+
4
+ class @PLUGIN_CLASS_NAME@ {
5
+ // noop
6
+ };
You can’t perform that action at this time.
0 commit comments