Skip to content

Commit

Permalink
fix: install specific plugins instead of the whole directory for shar…
Browse files Browse the repository at this point in the history
…ed builds
  • Loading branch information
BartSte committed Feb 17, 2024
1 parent 242b9c8 commit 22433d7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 80 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include(${CMAKE_SOURCE_DIR}/cmake/Version.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/Constants.cmake)

cmake_minimum_required(VERSION 3.5)
project(snapshot LANGUAGES CXX)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ more information.

# TODO:

- [ ] currently, all plugins are installed, the regexes are not working.
- [ ] Configure `cmake --install` for both static and shared qt builds. This is
needed after building the project from source.
- [ ] Ensure that the tarball can also be made using the --shared option.
Expand Down
6 changes: 1 addition & 5 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ add_executable(snapshot_bin main.cpp
target_link_libraries(snapshot_bin PRIVATE snapshot)

install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/run_snapshot DESTINATION .)
install(
TARGETS snapshot_bin
DESTINATION .
RUNTIME_DEPENDENCIES DIRECTORIES ${FFMPEG_LIBRARY_DIRS} POST_EXCLUDE_REGEXES
${EXCLUDE_C_LIBS_REGEX})
install_with_runtime_dependencies(snapshot_bin)

if(QT6_LIB_TYPE STREQUAL "SHARED_LIBRARY")
install_qt_shared_plugins()
Expand Down
43 changes: 21 additions & 22 deletions cmake/Build.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
include(${CMAKE_SOURCE_DIR}/cmake/Find.cmake)

# cmake-format: off
# When building the project with a static Qt6 library, we need to link the
# Libva library to the Qt6 FFmpeg media plugin. This is necessary because
# otherwise some symbols are not found when linking the snapshot.
# cmake-format: on
macro(link_libva_to_ffmpeg_plugin)
find_libva() # creates Libva::va/va-drm/va-x11/va-wayland
get_target_property(QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES
Qt6::QFFmpegMediaPlugin INTERFACE_LINK_LIBRARIES)
list(APPEND QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES Libva::va
Libva::va-drm Libva::va-x11 Libva::va-wayland)
set_target_properties(
Qt6::QFFmpegMediaPlugin
PROPERTIES INTERFACE_LINK_LIBRARIES
"${QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES}")
endmacro()

# cmake-format: off
# When building the project with a static Qt6 library, we need to link the
# following components statically as well:
Expand All @@ -31,20 +14,19 @@ macro(target_link_libraries_static_qt)
set(PLATFORM_PLUGINS
Qt6::QEglFSIntegrationPlugin
Qt6::QLinuxFbIntegrationPlugin
Qt6::QMinimalEglIntegrationPlugin
Qt6::QMinimalIntegrationPlugin
Qt6::QOffscreenIntegrationPlugin
Qt6::QVkKhrDisplayIntegrationPlugin
Qt6::QVncIntegrationPlugin
Qt6::QWaylandEglPlatformIntegrationPlugin
Qt6::QWaylandIntegrationPlugin
Qt6::QXcbIntegrationPlugin)

set(MULTIMEDIA_PLUGINS Qt6::QFFmpegMediaPlugin)

link_libva_to_ffmpeg_plugin()

# Plugins are not linked automatically when building with a static Qt6
# library, so we need to link them manually.
list(APPEND LINK_LIBS FFmpeg::FFmpeg Qt6::QFFmpegMediaPlugin
list(APPEND LINK_LIBS FFmpeg::FFmpeg ${MULTIMEDIA_PLUGINS}
${PLATFORM_PLUGINS})
target_link_libraries(snapshot PUBLIC ${LINK_LIBS})

Expand All @@ -56,8 +38,25 @@ macro(target_link_libraries_static_qt)
${PLATFORM_PLUGINS}
INCLUDE_BY_TYPE
multimedia
Qt6::QFFmpegMediaPlugin
${MULTIMEDIA_PLUGINS}
EXCLUDE
Qt6::QGstreamerMediaPlugin
NO_DEFAULT)
endmacro()

# cmake-format: off
# When building the project with a static Qt6 library, we need to link the
# Libva library to the Qt6 FFmpeg media plugin. This is necessary because
# otherwise some symbols are not found when linking the snapshot.
# cmake-format: on
macro(link_libva_to_ffmpeg_plugin)
find_libva() # creates Libva::va/va-drm/va-x11/va-wayland
get_target_property(QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES
${MULTIMEDIA_PLUGINS} INTERFACE_LINK_LIBRARIES)
list(APPEND QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES Libva::va
Libva::va-drm Libva::va-x11 Libva::va-wayland)
set_target_properties(
${MULTIMEDIA_PLUGINS}
PROPERTIES INTERFACE_LINK_LIBRARIES
"${QT6_QFFMPEGMEDIAPLUGIN_INTERFACE_LINK_LIBRARIES}")
endmacro()
7 changes: 0 additions & 7 deletions cmake/Constants.cmake

This file was deleted.

82 changes: 42 additions & 40 deletions cmake/Install.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
function(install_with_runtime_dependencies binary)
# Compatability with the following C libraries across linux distributions is
# assumed. Use this constant in the install command to exclude these libraries
# from the installation.
set(exclude_c_libs_regex
".*ld-linux.*\\.so.*" ".*libc\\.so.*" ".*libm\\.so.*" ".*libdbm\\.so.*"
".*libpthread\\.so.*")

install(
TARGETS ${binary}
DESTINATION .
RUNTIME_DEPENDENCIES DIRECTORIES ${FFMPEG_LIBRARY_DIRS}
POST_EXCLUDE_REGEXES ${exclude_c_libs_regex})
endfunction()

# When Qt is built as a shared library, the platform plugins must be installed
# alongside the application in the directories that have the same name as in the
# qt source.
macro(install_qt_shared_plugins)

# Natually, we need X11 and Wayland support. Eglfs and Linuxfb are also needed
# as a Raspberry Pi may require them. Offscreen is usefull when you do not
# have a display available. Lets also support vulkan.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/platforms/
DESTINATION platforms
PATTERN "libqeglfs-.*"
PATTERN "libqlinuxfb.*"
PATTERN "libqoffscreen.*"
PATTERN "libqvkkhrdisplay.*"
PATTERN "libqwayland-.*"
PATTERN "libqxcb.*")
FILES ${QT6_TOP_DIR}/plugins/platforms/libqeglfs.so
${QT6_TOP_DIR}/plugins/platforms/libqlinuxfb.so
${QT6_TOP_DIR}/plugins/platforms/libqoffscreen.so
${QT6_TOP_DIR}/plugins/platforms/libqvkkhrdisplay.so
${QT6_TOP_DIR}/plugins/platforms/libqwayland-egl.so
${QT6_TOP_DIR}/plugins/platforms/libqwayland-generic.so
${QT6_TOP_DIR}/plugins/platforms/libqxcb.so
DESTINATION platforms)

# Support both egl and glx.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/xcbglintegrations/
DESTINATION xcbglintegrations
PATTERN "libqxcb-.*-integration\\.*")
install(DIRECTORY ${QT6_TOP_DIR}/plugins/xcbglintegrations/
DESTINATION xcbglintegrations)

# Support all the wayland graphics integrations.
# Support all the wayland graphics integrations, except emulation.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/
DESTINATION wayland-graphics-integration-client
PATTERN "libdmabuf-server\\..*"
PATTERN "libdrm-egl-server\\..*"
PATTERN "libqt-plugin-wayland-egl\\..*"
PATTERN "libshm-emulation-server\\..*"
PATTERN "libvulkan-server\\..*")
FILES
${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/libdmabuf-server.so
${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/libdrm-egl-server.so
${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/libqt-plugin-wayland-egl.so
${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/libvulkan-server.so
DESTINATION wayland-graphics-integration-client)

# X11 support for eglfs can be used by Raspberry Pi.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/egldeviceintegrations/
DESTINATION egldeviceintegrations
PATTERN "libqeglfs-x11-.*")
FILES
${QT6_TOP_DIR}/plugins/egldeviceintegrations/libqeglfs-x11-integration.so
DESTINATION egldeviceintegrations)

# Support all shells
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/wayland-shell-integration/
DESTINATION wayland-shell-integration
PATTERN ".*-shell\\..*"
PATTERN ".*-shell-v1\\..*"
PATTERN ".*-shell-plugin\\..*")
install(DIRECTORY ${QT6_TOP_DIR}/plugins/wayland-shell-integration/
DESTINATION wayland-shell-integration)

# Only saving as jpeg is supported.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/imageformats/
DESTINATION imageformats
PATTERN "libqjpeg\\..*")
# Jpeg is needded for image support.
install(FILES ${QT6_TOP_DIR}/plugins/imageformats/libqjpeg.so
DESTINATION imageformats)

# Only ffmpeg is supported.
install(
DIRECTORY ${QT6_TOP_DIR}/plugins/multimedia/
DESTINATION multimedia
PATTERN "libffmpegmediaplugin\\..*")

install(FILES ${QT6_TOP_DIR}/plugins/multimedia/libffmpegmediaplugin.so
DESTINATION multimedia)
endmacro()
8 changes: 3 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(${CMAKE_SOURCE_DIR}/cmake/Install.cmake)

find_package(Qt6 REQUIRED COMPONENTS Test)
include(GoogleTest)
include(FetchContent)
Expand All @@ -18,8 +20,4 @@ set_tests_properties(tests_bin PROPERTIES ENVIRONMENT

install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/run_tests DESTINATION .)
install(DIRECTORY static DESTINATION .)
install(
TARGETS tests_bin
DESTINATION .
RUNTIME_DEPENDENCIES DIRECTORIES ${FFMPEG_LIBRARY_DIRS} POST_EXCLUDE_REGEXES
${EXCLUDE_C_LIBS_REGEX})
install_with_runtime_dependencies(tests_bin)

0 comments on commit 22433d7

Please sign in to comment.