diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-08-19 11:42:12 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-08-24 16:10:31 +0200 |
commit | 3c1125d9fe41332087ab6213a5514426109ead08 (patch) | |
tree | 5fe8b70215d3b6caad6e6b6cfa30eb67bc607c43 /examples/widgets/tools/styleplugin | |
parent | 511bbbdfc0c048936336e0e7923cfd002ea05d38 (diff) |
CMake: Create plugin initializers for static user plugins
Previously we only created object library static plugin initializers
for Qt plugins only, not user-project plugins.
The reason was that if a user tried to install the plugin target via
an export set, CMake would error out saying that the _init library is
not part of the same export set.
Introduce an OUTPUT_TARGETS option that would allow projects to get
the name of the generated _init target, so they can install it if
needed.
This was already done for qt6_add_qml_module, so we just introduce the
same option for qt6_add_plugin.
Now user static plugins will have an _init target created, which will
be propagated to consumers whenever the consumers link against the
plugin itself.
We also need an internal option to disable this propagation, because
it's handled a bit differently for Qt plugins which can be linked
either via finalizers or via usage requirements.
Amends 91c65dd80cdd2de666448c14202c0c63718152b6
As a result of the implementation change, cleanup example projects
to ensure that they build successfully (the important part is
specifying the CLASS_NAME).
Only plugandpaint works properly with both shared and static Qt
builds.
echoplugin works with a shared Qt build, but not a static one due to
some assumptions in the C++ code about shared plugins.
styleplugin doesn't seem to work properly neither with shared Qt
builds nor static Qt builds, at least on macOS. But it builds fine.
For some reason even if the plugin is found, the style is not applied.
Amends 4caac1feea025b0ad496141e8f16ab88c04c2caa
Pick-to: 6.2
Task-number: QTBUG-80863
Task-number: QTBUG-92933
Change-Id: I6f631cda9566229b7a63992b23d7d7fa50303eeb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'examples/widgets/tools/styleplugin')
3 files changed, 16 insertions, 58 deletions
diff --git a/examples/widgets/tools/styleplugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/CMakeLists.txt index 6d3549dcad..33412f5306 100644 --- a/examples/widgets/tools/styleplugin/CMakeLists.txt +++ b/examples/widgets/tools/styleplugin/CMakeLists.txt @@ -1,19 +1,15 @@ -# Generated from styleplugin.pro. - -# special case begin cmake_minimum_required(VERSION 3.16) project(styleplugin LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +find_package(Qt6 COMPONENTS Widgets) set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) -set(INSTALL_EXAMPLEDIR "examples") +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() -find_package(Qt6 COMPONENTS Widgets) -# special case end +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/styleplugin") add_subdirectory(stylewindow) add_subdirectory(plugin) diff --git a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt b/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt index c33188d228..30a06231c1 100644 --- a/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt +++ b/examples/widgets/tools/styleplugin/plugin/CMakeLists.txt @@ -1,34 +1,14 @@ -# Generated from plugin.pro. - -cmake_minimum_required(VERSION 3.16) -project(simplestyleplugin LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/styleplugin/styles") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_plugin(simplestyleplugin) +qt_add_plugin(simplestyleplugin + CLASS_NAME SimpleStylePlugin +) target_sources(simplestyleplugin PRIVATE simplestyle.cpp simplestyle.h simplestyleplugin.cpp simplestyleplugin.h ) set_target_properties(simplestyleplugin PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/stylewindow/styles" ) -target_link_libraries(simplestyleplugin PUBLIC +target_link_libraries(simplestyleplugin PRIVATE Qt::Core Qt::Gui Qt::Widgets @@ -36,6 +16,5 @@ target_link_libraries(simplestyleplugin PUBLIC install(TARGETS simplestyleplugin RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) diff --git a/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt b/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt index 264913f967..168c41fb60 100644 --- a/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt +++ b/examples/widgets/tools/styleplugin/stylewindow/CMakeLists.txt @@ -1,24 +1,3 @@ -# Generated from stylewindow.pro. - -cmake_minimum_required(VERSION 3.16) -project(styleplugin LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/styleplugin") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - qt_add_executable(styleplugin main.cpp stylewindow.cpp stylewindow.h @@ -27,14 +6,18 @@ set_target_properties(styleplugin PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(styleplugin PUBLIC +target_link_libraries(styleplugin PRIVATE Qt::Core Qt::Gui Qt::Widgets ) +if(NOT QT6_IS_SHARED_LIBS_BUILD) + target_link_libraries(styleplugin PRIVATE + simplestyleplugin + ) +endif() install(TARGETS styleplugin RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) |