-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMake: Add support for auto-importing plugins in CMake
This commit adds transitive dependencies to the plugins, so that a sane set of default plugins get auto-imported when linking against a module. It also provides a new function, qt5_import_plugins(), which allows you to override the set of plugins that get imported. The decision of whether or not to import a specific plugin is based on several custom target properties and a very clever generator expression. Note that this change only imports plugins on static Qt builds. It does nothing on shared Qt builds, as the shared libraries already have their own plugin import mechanism. [ChangeLog][CMake] Added ability to auto-import non-qml plugins on CMake builds Task-number: QTBUG-38913 Task-number: QTBUG-76562 Change-Id: I2d6c8908b521cf6ba1ebbbc33a87cb7ddd9935cf Reviewed-by: Simon Hausmann <[email protected]>
- Loading branch information
1 parent
ef74730
commit 63d9cd1
Showing
44 changed files
with
1,308 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <QtPlugin> | ||
Q_IMPORT_PLUGIN($$CMAKE_PLUGIN_NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,102 @@ | ||
|
||
add_library(Qt5::$$CMAKE_PLUGIN_NAME MODULE IMPORTED) | ||
|
||
!!IF !isEmpty(CMAKE_STATIC_TYPE) | ||
set(_Qt5$${CMAKE_PLUGIN_NAME}_MODULE_DEPENDENCIES \"$${CMAKE_PLUGIN_MODULE_DEPS}\") | ||
|
||
foreach(_module_dep ${_Qt5$${CMAKE_PLUGIN_NAME}_MODULE_DEPENDENCIES}) | ||
if(NOT Qt5${_module_dep}_FOUND) | ||
find_package(Qt5${_module_dep} | ||
$$VERSION ${_Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT} | ||
${_Qt5$${CMAKE_MODULE_NAME}_DEPENDENCIES_FIND_QUIET} | ||
${_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_REQUIRED} | ||
PATHS \"${CMAKE_CURRENT_LIST_DIR}/..\" NO_DEFAULT_PATH | ||
) | ||
endif() | ||
endforeach() | ||
|
||
!!IF !isEmpty(CMAKE_RELEASE_TYPE) | ||
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\") | ||
!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) | ||
_qt5_$${CMAKE_MODULE_NAME}_process_prl_file( | ||
\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_RELEASE_LIB_DEPENDENCIES | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_RELEASE_LINK_FLAGS | ||
) | ||
!!ELSE | ||
_qt5_$${CMAKE_MODULE_NAME}_process_prl_file( | ||
\"$${CMAKE_PLUGIN_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_RELEASE_LIB_DEPENDENCIES | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_RELEASE_LINK_FLAGS | ||
) | ||
!!ENDIF | ||
!!ENDIF | ||
|
||
!!IF !isEmpty(CMAKE_DEBUG_TYPE) | ||
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\") | ||
!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) | ||
_qt5_$${CMAKE_MODULE_NAME}_process_prl_file( | ||
\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_DEBUG_LIB_DEPENDENCIES | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_DEBUG_LINK_FLAGS | ||
) | ||
!!ELSE | ||
_qt5_$${CMAKE_MODULE_NAME}_process_prl_file( | ||
\"$${CMAKE_PLUGIN_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_DEBUG_LIB_DEPENDENCIES | ||
_Qt5$${CMAKE_PLUGIN_NAME}_STATIC_DEBUG_LINK_FLAGS | ||
) | ||
!!ENDIF | ||
!!ENDIF | ||
|
||
set_property(TARGET Qt5::$$CMAKE_PLUGIN_NAME PROPERTY INTERFACE_SOURCES | ||
\"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}_$${CMAKE_PLUGIN_NAME}_Import.cpp\" | ||
) | ||
!!ENDIF | ||
|
||
!!IF !isEmpty(CMAKE_RELEASE_TYPE) | ||
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE}) | ||
!!ENDIF | ||
!!IF !isEmpty(CMAKE_DEBUG_TYPE) | ||
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE}) | ||
!!ENDIF | ||
|
||
list(APPEND Qt5$${CMAKE_MODULE_NAME}_PLUGINS Qt5::$$CMAKE_PLUGIN_NAME) | ||
set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY QT_ALL_PLUGINS_$${CMAKE_PLUGIN_TYPE_ESCAPED} Qt5::$${CMAKE_PLUGIN_NAME}) | ||
!!IF !isEmpty(CMAKE_STATIC_TYPE) | ||
# $<GENEX_EVAL:...> wasn\'t added until CMake 3.12, so put a version guard around it | ||
if(CMAKE_VERSION VERSION_LESS \"3.12\") | ||
set(_manual_plugins_genex \"$<TARGET_PROPERTY:QT_PLUGINS>\") | ||
set(_plugin_type_genex \"$<TARGET_PROPERTY:QT_PLUGINS_$${CMAKE_PLUGIN_TYPE_ESCAPED}>\") | ||
set(_no_plugins_genex \"$<TARGET_PROPERTY:QT_NO_PLUGINS>\") | ||
else() | ||
set(_manual_plugins_genex \"$<GENEX_EVAL:$<TARGET_PROPERTY:QT_PLUGINS>>\") | ||
set(_plugin_type_genex \"$<GENEX_EVAL:$<TARGET_PROPERTY:QT_PLUGINS_$${CMAKE_PLUGIN_TYPE_ESCAPED}>>\") | ||
set(_no_plugins_genex \"$<GENEX_EVAL:$<TARGET_PROPERTY:QT_NO_PLUGINS>>\") | ||
endif() | ||
set(_user_specified_genex | ||
\"$<IN_LIST:Qt5::$$CMAKE_PLUGIN_NAME,${_manual_plugins_genex};${_plugin_type_genex}>\" | ||
) | ||
string(CONCAT _plugin_genex | ||
\"$<$<OR:\" | ||
# Add this plugin if it\'s in the list of manual plugins or plugins for the type | ||
\"${_user_specified_genex},\" | ||
# Add this plugin if the list of plugins for the type is empty, the PLUGIN_EXTENDS | ||
# is either empty or equal to the module name, and the user hasn\'t blacklisted it | ||
\"$<AND:\" | ||
\"$<STREQUAL:${_plugin_type_genex},>,\" | ||
\"$<OR:\" | ||
\"$<STREQUAL:$<TARGET_PROPERTY:Qt5::$${CMAKE_PLUGIN_NAME},QT_PLUGIN_EXTENDS>,Qt5::$${CMAKE_MODULE_NAME}>,\" | ||
\"$<STREQUAL:$<TARGET_PROPERTY:Qt5::$${CMAKE_PLUGIN_NAME},QT_PLUGIN_EXTENDS>,>\" | ||
\">,\" | ||
\"$<NOT:$<IN_LIST:Qt5::$${CMAKE_PLUGIN_NAME},${_no_plugins_genex}>>\" | ||
\">\" | ||
\">:Qt5::$$CMAKE_PLUGIN_NAME>\" | ||
) | ||
set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY INTERFACE_LINK_LIBRARIES | ||
${_plugin_genex} | ||
) | ||
set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} APPEND PROPERTY INTERFACE_LINK_LIBRARIES | ||
\"$${CMAKE_PLUGIN_QT5_MODULE_DEPS}\" | ||
) | ||
!!ENDIF | ||
set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_TYPE \"$$CMAKE_PLUGIN_TYPE\") | ||
set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_EXTENDS \"$$CMAKE_PLUGIN_EXTENDS\") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
TARGET = mock1plugin | ||
|
||
HEADERS += qmock1plugin.h | ||
SOURCES += qmock1plugin.cpp | ||
QT = mockplugins1 | ||
|
||
PLUGIN_TYPE = mockplugin | ||
PLUGIN_CLASS_NAME = QMock1Plugin | ||
load(qt_plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "qmock1plugin.h" | ||
|
||
QT_BEGIN_NAMESPACE | ||
|
||
QString QMock1Plugin::pluginName() const | ||
{ | ||
return "QMock1Plugin"; | ||
} | ||
|
||
QT_END_NAMESPACE |
Oops, something went wrong.