Enforce that plugins can't be used as library dependencies

We want to use the libraries in different projects where the plugins
are not present.

Change-Id: I51382ac7cfcf06871ac99a6b53b84840ca39bf00
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Marco Bubke
2024-08-22 12:56:33 +02:00
parent b37f8cfca2
commit 40f462cf07
2 changed files with 30 additions and 0 deletions

View File

@@ -129,6 +129,9 @@ function(add_qtc_library name)
"CONDITION;DEPENDS;PUBLIC_DEPENDS;DEFINES;PUBLIC_DEFINES;INCLUDES;SYSTEM_INCLUDES;PUBLIC_INCLUDES;PUBLIC_SYSTEM_INCLUDES;SOURCES;EXPLICIT_MOC;SKIP_AUTOMOC;EXTRA_TRANSLATIONS;PROPERTIES;PRIVATE_COMPILE_OPTIONS;PUBLIC_COMPILE_OPTIONS" ${ARGN}
)
check_library_dependencies(${_arg_DEPENDS})
check_library_dependencies(${_arg_PUBLIC_DEPENDS})
get_default_defines(default_defines_copy ${_arg_ALLOW_ASCII_CASTS})
if (${_arg_UNPARSED_ARGUMENTS})
@@ -336,6 +339,9 @@ function(add_qtc_plugin target_name)
${ARGN}
)
check_library_dependencies(${_arg_DEPENDS})
check_library_dependencies(${_arg_PUBLIC_DEPENDS})
if (${_arg_UNPARSED_ARGUMENTS})
message(FATAL_ERROR "add_qtc_plugin had unparsed arguments")
endif()
@@ -560,6 +566,8 @@ function(add_qtc_plugin target_name)
${_arg_PROPERTIES}
)
set_property(TARGET ${target_name} APPEND PROPERTY EXPORT_PROPERTIES "QTC_PLUGIN_CLASS_NAME")
if (NOT _arg_SKIP_PCH)
enable_pch(${target_name})
endif()
@@ -615,6 +623,9 @@ function(extend_qtc_plugin target_name)
return()
endif()
check_library_dependencies(${_arg_DEPENDS})
check_library_dependencies(${_arg_PUBLIC_DEPENDS})
extend_qtc_target(${target_name} ${ARGN})
endfunction()
@@ -624,6 +635,9 @@ function(extend_qtc_library target_name)
return()
endif()
check_library_dependencies(${_arg_DEPENDS})
check_library_dependencies(${_arg_PUBLIC_DEPENDS})
extend_qtc_target(${target_name} ${ARGN})
endfunction()

View File

@@ -361,6 +361,10 @@ function(find_dependent_plugins varName)
if(NOT TARGET ${i})
continue()
endif()
get_property(_class_name TARGET "${i}" PROPERTY QTC_PLUGIN_CLASS_NAME)
if (NOT _class_name)
message(SEND_ERROR "${i} is a library, not a plugin!")
endif()
set(_dep)
get_property(_dep TARGET "${i}" PROPERTY _arg_DEPENDS)
if (_dep)
@@ -377,6 +381,18 @@ function(find_dependent_plugins varName)
set("${varName}" ${_RESULT} PARENT_SCOPE)
endfunction()
function(check_library_dependencies)
foreach(i ${ARGN})
if (NOT TARGET ${i})
continue()
endif()
get_property(_class_name TARGET "${i}" PROPERTY QTC_PLUGIN_CLASS_NAME)
if (_class_name)
message(SEND_ERROR "${i} is a plugin, not a library!")
endif()
endforeach()
endfunction()
function(enable_pch target)
if (BUILD_WITH_PCH)
# Skip PCH for targets that do not use the expected visibility settings: