summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@qt.io>2021-03-23 15:48:56 +1100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-29 10:56:07 +0000
commitb296202831e8f1bb3a3fda1159289199a7097a71 (patch)
tree3e537398a6bd322a5a69532dd725d128f9dbd103 /src/corelib
parent4e624996a777e9a509338ae25e8a30944fa3963e (diff)
Refactor qt_internal_add_plugin() and qt6_add_plugin()
Remove code duplication by calling qt6_add_plugin() from qt_internal_add_plugin(). Separate out the public and internal arguments for the variables defined in QtBuild.cmake for these functions. Provide them via commands instead for greater robustness. This separation allows other Qt repos to access the appropriate set of keywords where they define commands that forward on to *_add_plugin() in their implementations. Retain the old variables for now to simplify the integration steps for updating other repos. The old variables can be removed once there are no more references left to them in any repo. Task-number: QTBUG-88763 Change-Id: I0105523afd95995923bd20fc963d245bbb15d34d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit aa4a1006cbccbc180c600f9b4dc9e882bb5ed5ca) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/Qt6CoreMacros.cmake99
1 files changed, 79 insertions, 20 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index fc8ae6a74f..9e9b0f1e56 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -423,6 +423,43 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
endfunction()
endif()
+function(_qt_internal_apply_win_prefix_and_suffix target)
+ if(WIN32)
+ # Table of prefix / suffixes for MSVC libraries as qmake expects them to be created.
+ # static - Qt6EdidSupport.lib (platform support libraries / or static QtCore, etc)
+ # shared - Qt6Core.dll
+ # shared import library - Qt6Core.lib
+ # module aka Qt plugin - qwindows.dll
+ # module import library - qwindows.lib
+ #
+ # The CMake defaults are fine for us.
+
+ # Table of prefix / suffixes for MinGW libraries as qmake expects them to be created.
+ # static - libQt6EdidSupport.a (platform support libraries / or static QtCore, etc)
+ # shared - Qt6Core.dll
+ # shared import library - libQt6Core.a
+ # module aka Qt plugin - qwindows.dll
+ # module import library - libqwindows.a
+ #
+ # CMake for Windows-GNU platforms defaults the prefix to "lib".
+ # CMake for Windows-GNU platforms defaults the import suffix to ".dll.a".
+ # These CMake defaults are not ok for us.
+
+ # This should cover both MINGW with GCC and CLANG.
+ if(NOT MSVC)
+ set_property(TARGET "${target}" PROPERTY IMPORT_SUFFIX ".a")
+
+ get_target_property(target_type ${target} TYPE)
+ if(target_type STREQUAL "STATIC_LIBRARY")
+ set_property(TARGET "${target}" PROPERTY PREFIX "lib")
+ else()
+ set_property(TARGET "${target}" PROPERTY PREFIX "")
+ set_property(TARGET "${target}" PROPERTY IMPORT_PREFIX "lib")
+ endif()
+ endif()
+ endif()
+endfunction()
+
set(_Qt6_COMPONENT_PATH "${CMAKE_CURRENT_LIST_DIR}/..")
# This function is currently in Technical Preview.
@@ -1383,17 +1420,44 @@ function(_qt_internal_process_resource target resourceName)
endif()
endfunction()
+macro(_qt_internal_get_add_plugin_keywords option_args single_args multi_args)
+ set(${option_args}
+ STATIC
+ )
+ set(${single_args}
+ TYPE
+ CLASS_NAME
+ OUTPUT_NAME
+ )
+ set(${multi_args})
+endmacro()
+
# This function is currently in Technical Preview.
# It's signature and behavior might change.
function(qt6_add_plugin target)
- cmake_parse_arguments(arg
- "STATIC"
- "OUTPUT_NAME;CLASS_NAME;TYPE"
- ""
- ${ARGN}
- )
- if (arg_STATIC)
+ _qt_internal_get_add_plugin_keywords(opt_args single_args multi_args)
+
+ # TODO: Transitional use only, replaced by CLASS_NAME. Remove this once
+ # all other repos have been updated to use CLASS_NAME.
+ list(APPEND single_args CLASSNAME)
+
+ cmake_parse_arguments(PARSE_ARGV 1 arg "${opt_args}" "${single_args}" "${multi_args}")
+
+ # Handle the inconsistent CLASSNAME/CLASS_NAME keyword naming between commands
+ if(arg_CLASSNAME)
+ if(arg_CLASS_NAME AND NOT arg_CLASSNAME STREQUAL arg_CLASS_NAME)
+ message(FATAL_ERROR
+ "Both CLASSNAME and CLASS_NAME were given and were different. "
+ "Only one of the two should be used."
+ )
+ endif()
+ set(arg_CLASS_NAME "${arg_CLASSNAME}")
+ unset(arg_CLASSNAME)
+ endif()
+
+ if (arg_STATIC OR NOT BUILD_SHARED_LIBS)
add_library(${target} STATIC)
+ target_compile_definitions(${target} PRIVATE QT_STATICPLUGIN)
else()
add_library(${target} MODULE)
if(APPLE)
@@ -1401,10 +1465,7 @@ function(qt6_add_plugin target)
# but Qt plugins are actually suffixed with .dylib.
set_property(TARGET "${target}" PROPERTY SUFFIX ".dylib")
endif()
- if(WIN32)
- # CMake sets for Windows-GNU platforms the suffix "lib"
- set_property(TARGET "${target}" PROPERTY PREFIX "")
- endif()
+ _qt_internal_apply_win_prefix_and_suffix(${target})
endif()
set(output_name ${target})
@@ -1422,22 +1483,20 @@ function(qt6_add_plugin target)
endif()
# Derive the class name from the target name if it's not explicitly specified.
+ # Don't set it for qml plugins though.
set(plugin_class_name "")
- if (NOT arg_CLASS_NAME)
- set(plugin_class_name "${target}")
- else()
- set(plugin_class_name "${arg_CLASS_NAME}")
+ if (NOT "${arg_TYPE}" STREQUAL "qml_plugin")
+ if (NOT arg_CLASS_NAME)
+ set(plugin_class_name "${target}")
+ else()
+ set(plugin_class_name "${arg_CLASS_NAME}")
+ endif()
endif()
set_target_properties(${target} PROPERTIES QT_PLUGIN_CLASS_NAME "${plugin_class_name}")
- set(static_plugin_define "")
- if (arg_STATIC)
- set(static_plugin_define "QT_STATICPLUGIN")
- endif()
target_compile_definitions(${target} PRIVATE
QT_PLUGIN
QT_DEPRECATED_WARNINGS
- ${static_plugin_define}
)
endfunction()