CMake: Add qt6_add_plugin public API
This patch adds a publicly callable qt6_add_plugin() API to create plugins. This API is meant to cover cases such as the plugandpaint example. This patch also renames qt_add_plugin to qt_internal_add_plugin in order to avoid clashes with the public API. To avoid breaking the existing projects, a compatibility wrapper function is enabled by default unless QT_DISABLE_QT_ADD_PLUGIN_COMPATIBILITY is specified. Fixes: QTBUG-82961 Change-Id: If5b564a8406c90434f1bdad0b8df76d3e6626b5f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>bb10
parent
26a0a89421
commit
6fbeef4c6b
|
|
@ -2634,7 +2634,7 @@ endfunction()
|
|||
function(qt_internal_check_directory_or_type name dir type default result_var)
|
||||
if ("x${dir}" STREQUAL x)
|
||||
if("x${type}" STREQUAL x)
|
||||
message(FATAL_ERROR "qt_add_plugin called without setting either TYPE or ${name}.")
|
||||
message(FATAL_ERROR "qt_internal_add_plugin called without setting either TYPE or ${name}.")
|
||||
endif()
|
||||
set(${result_var} "${default}" PARENT_SCOPE)
|
||||
else()
|
||||
|
|
@ -2686,12 +2686,12 @@ set(__qt_add_plugin_multi_args
|
|||
# This is the main entry point for defining Qt plugins.
|
||||
# A CMake target is created with the given target. The TYPE parameter is needed to place the
|
||||
# plugin into the correct plugins/ sub-directory.
|
||||
function(qt_add_plugin target)
|
||||
function(qt_internal_add_plugin target)
|
||||
qt_internal_module_info(module "${target}")
|
||||
|
||||
qt_internal_set_qt_known_plugins("${QT_KNOWN_PLUGINS}" "${target}")
|
||||
|
||||
qt_parse_all_arguments(arg "qt_add_plugin"
|
||||
qt_parse_all_arguments(arg "qt_internal_add_plugin"
|
||||
"${__qt_add_plugin_optional_args};SKIP_INSTALL"
|
||||
"${__qt_add_plugin_single_args}"
|
||||
"${__qt_add_plugin_multi_args}"
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ macro(qt_examples_build_begin)
|
|||
# annotate where each example is installed to, to be able to derive a relative rpath, and it
|
||||
# seems there's no way to query such information from CMake itself.
|
||||
set(CMAKE_INSTALL_RPATH "${_default_install_rpath}")
|
||||
set(QT_DISABLE_QT_ADD_PLUGIN_COMPATIBILITY TRUE)
|
||||
endmacro()
|
||||
|
||||
macro(qt_examples_build_end)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,5 @@ add_subdirectory(undoframework)
|
|||
|
||||
if(QT_FEATURE_library) # special case
|
||||
add_subdirectory(echoplugin)
|
||||
# FIXME: Currently broken # special case
|
||||
# Fails to link (ld: error: undefined symbol: qt_static_plugin_BasicToolsPlugin()) # special case
|
||||
#add_subdirectory(plugandpaint) # special case
|
||||
add_subdirectory(plugandpaint) # special case
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ find_package(Qt6 COMPONENTS Core)
|
|||
find_package(Qt6 COMPONENTS Gui)
|
||||
find_package(Qt6 COMPONENTS Widgets)
|
||||
|
||||
add_library(pnp_basictools MODULE
|
||||
qt6_add_plugin(pnp_basictools STATIC)
|
||||
target_sources(pnp_basictools PRIVATE
|
||||
basictoolsplugin.cpp basictoolsplugin.h
|
||||
)
|
||||
target_include_directories(pnp_basictools PUBLIC
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ find_package(Qt6 COMPONENTS Core)
|
|||
find_package(Qt6 COMPONENTS Gui)
|
||||
find_package(Qt6 COMPONENTS Widgets)
|
||||
|
||||
add_library(pnp_basictools MODULE
|
||||
qt_add_plugin(pnp_basictools STATIC)
|
||||
target_sources(pnp_basictools PRIVATE
|
||||
basictoolsplugin.cpp basictoolsplugin.h
|
||||
)
|
||||
target_include_directories(pnp_basictools PUBLIC
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ find_package(Qt6 COMPONENTS Core)
|
|||
find_package(Qt6 COMPONENTS Gui)
|
||||
find_package(Qt6 COMPONENTS Widgets)
|
||||
|
||||
add_library(pnp_extrafilters MODULE
|
||||
qt_add_plugin(pnp_extrafilters)
|
||||
target_sources(pnp_extrafilters PRIVATE
|
||||
extrafiltersplugin.cpp extrafiltersplugin.h
|
||||
)
|
||||
target_include_directories(pnp_extrafilters PUBLIC
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ find_package(Qt6 COMPONENTS Core)
|
|||
find_package(Qt6 COMPONENTS Gui)
|
||||
find_package(Qt6 COMPONENTS Widgets)
|
||||
|
||||
add_library(pnp_extrafilters MODULE
|
||||
qt_add_plugin(pnp_extrafilters)
|
||||
target_sources(pnp_extrafilters PRIVATE
|
||||
extrafiltersplugin.cpp extrafiltersplugin.h
|
||||
)
|
||||
target_include_directories(pnp_extrafilters PUBLIC
|
||||
|
|
|
|||
|
|
@ -1135,3 +1135,57 @@ function(QT6_PROCESS_RESOURCE target resourceName)
|
|||
set(${rcc_OUTPUT_TARGETS} "${output_targets}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(qt6_add_plugin target)
|
||||
cmake_parse_arguments(arg
|
||||
"STATIC"
|
||||
"OUTPUT_NAME"
|
||||
""
|
||||
${ARGN}
|
||||
)
|
||||
if (arg_STATIC)
|
||||
add_library(${target} STATIC)
|
||||
else()
|
||||
add_library(${target} MODULE)
|
||||
if(APPLE)
|
||||
# CMake defaults to using .so extensions for loadable modules, aka plugins,
|
||||
# but Qt plugins are actually suffixed with .dylib.
|
||||
set_property(TARGET "${target}" PROPERTY SUFFIX ".dylib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(output_name ${target})
|
||||
if (arg_OUTPUT_NAME)
|
||||
set(output_name ${arg_OUTPUT_NAME})
|
||||
endif()
|
||||
set_property(TARGET "${target}" PROPERTY OUTPUT_NAME "${output_name}")
|
||||
|
||||
if (ANDROID)
|
||||
qt_android_apply_arch_suffix("${target}")
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
LIBRARY_OUTPUT_NAME "plugins_${arg_TYPE}_${output_name}"
|
||||
)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
|
||||
function(qt_add_plugin)
|
||||
if (NOT DEFINED QT_DISABLE_QT_ADD_PLUGIN_COMPATIBILITY
|
||||
OR NOT QT_DISABLE_QT_ADD_PLUGIN_COMPATIBILITY)
|
||||
qt_internal_add_plugin(${ARGV})
|
||||
else()
|
||||
qt6_add_plugin(${ARGV})
|
||||
endif()
|
||||
endfunction()
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ def set_up_cmake_api_calls():
|
|||
|
||||
api[2]["qt_extend_target"] = "qt_extend_target"
|
||||
api[2]["qt_add_module"] = "qt_add_module"
|
||||
api[2]["qt_add_plugin"] = "qt_add_plugin"
|
||||
api[2]["qt_add_plugin"] = "qt_internal_add_plugin"
|
||||
api[2]["qt_add_tool"] = "qt_add_tool"
|
||||
api[2]["qt_add_test"] = "qt_add_test"
|
||||
api[2]["qt_add_test_helper"] = "qt_add_test_helper"
|
||||
|
|
@ -3396,7 +3396,11 @@ def write_example(
|
|||
add_target += " INSTALL_LOCATION ${INSTALL_EXAMPLEDIR}\n)\n\n"
|
||||
add_target += f"target_sources({binary_name} PRIVATE"
|
||||
else:
|
||||
add_target = f"add_library({binary_name} MODULE"
|
||||
add_target = f"qt_add_plugin({binary_name}"
|
||||
if "static" in scope.get("CONFIG"):
|
||||
add_target += " STATIC"
|
||||
add_target += ")\n"
|
||||
add_target += f"target_sources({binary_name} PRIVATE"
|
||||
|
||||
else:
|
||||
add_target = f'add_{"qt_gui_" if gui else ""}executable({binary_name}'
|
||||
|
|
|
|||
Loading…
Reference in New Issue