From c55481c8b8710e481bc2684ef85f9b72278fdb8a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 27 Feb 2025 18:06:41 +0100 Subject: [PATCH 1/2] qt5.functions: fix typos in docstrings --- projects/qt5.functions.cmake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/qt5.functions.cmake b/projects/qt5.functions.cmake index 2aac09e5f..dafa41a74 100644 --- a/projects/qt5.functions.cmake +++ b/projects/qt5.functions.cmake @@ -8,8 +8,8 @@ _superbuild_get_qt5_plugin_install_context( Date: Thu, 27 Feb 2025 17:31:39 +0100 Subject: [PATCH 2/2] qt6: add `qt6.functions` module Helps with packaging Qt6. --- projects/qt6.functions.cmake | 149 +++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 projects/qt6.functions.cmake diff --git a/projects/qt6.functions.cmake b/projects/qt6.functions.cmake new file mode 100644 index 000000000..35d8343aa --- /dev/null +++ b/projects/qt6.functions.cmake @@ -0,0 +1,149 @@ +#[==[.md +``` +_superbuild_get_qt6_plugin_install_context( ) +``` + +**Warning** Internal function, see `superbuild_get_qt6_plugin_install_paths` and +`superbuild_get_qt6_plugin_optional_module_install_paths` + +Returns the absolute path containing all Qt6 plugin directories, +as well as the extension for these plugins. Because path and +extensions can change according to the current platform and whether +or not we use Qt system, this function eases the work for us. +#]==] +function (_superbuild_get_qt6_plugin_install_context out_path out_ext) + if (USE_SYSTEM_qt6 AND UNIX) + set(qt6_no_package_paths) + if (APPLE) + list(APPEND qt6_no_package_paths + "/usr/lib/cmake/Qt6") + elseif (UNIX) + list(APPEND qt6_no_package_paths + "/lib/cmake/Qt6" + "/lib64/cmake/Qt6" + "/usr/lib/cmake/Qt6" + "/usr/lib64/cmake/Qt6" + "/usr/local/lib/cmake/Qt6" + "/usr/local/lib64/cmake/Qt6") + endif () + + # The package will not be installing Qt6 since it is provided by the + # system; do not install the plugins. + if (Qt6_DIR IN_LIST qt6_no_package_paths) + return () + endif () + endif () + + if (USE_SYSTEM_qt6) + if (NOT Qt6_DIR) + message(FATAL_ERROR + "Installing plugins from a system Qt6 requires `Qt6_DIR` to be set.") + endif () + + set(qt6_base_libdir "${Qt6_DIR}/../..") + if (EXISTS "${qt6_base_libdir}/qt6") + # This is the layout for Linux distributions. + set(qt6_base_libdir "${qt6_base_libdir}/qt6") + elseif (EXISTS "${qt6_base_libdir}/../plugins") + # This is the layout for Qt binaries. + set(qt6_base_libdir "${qt6_base_libdir}/..") + elseif (EXISTS "${qt6_base_libdir}/../libexec/qt6") + # This is the layout for MacPorts. + set(qt6_base_libdir "${qt6_base_libdir}/../libexec/qt6") + endif () + else () + set(qt6_base_libdir "${superbuild_install_location}") + endif () + + set(qt6_plugin_path "${qt6_base_libdir}/plugins") + if (WIN32) + set(qt6_plugin_ext ".dll") + elseif (APPLE) + set(qt6_plugin_ext ".dylib") + elseif (UNIX) + set(qt6_plugin_ext ".so") + else () + message(FATAL_ERROR + "Unknown Qt6 plugin path for this platform.") + endif () + + set("${out_path}" "${qt6_plugin_path}" PARENT_SCOPE) + set("${out_ext}" "${qt6_plugin_ext}" PARENT_SCOPE) +endfunction() + +#[==[.md +``` +superbuild_get_qt6_plugin_install_paths( ) +``` + +Returns a list of absolute path of Qt6 plugins to install from a list of +required plugin. This input list take the form of the dynamic library name +with no extension but with their parent folder. + +Also see : superbuild_install_qt6_optional_plugin_directory_paths + +Example : + +``` + superbuild_get_qt6_plugin_install_paths(output_paths + "platforms/libqminimal;renderers/libopenglrenderer") +``` +#]==] +function (superbuild_get_qt6_plugin_install_paths output) + _superbuild_get_qt6_plugin_install_context(qt6_plugin_path qt6_plugin_ext) + + set(plugin_paths) + foreach (plugin IN LISTS ARGN) + set(plugin_path "${qt6_plugin_path}/${plugin}${qt6_plugin_ext}") + if (NOT EXISTS "${plugin_path}") + message(FATAL_ERROR + "Unable to find the ${plugin} plugin at ${plugin_path} from Qt6 under ${qt6_plugin_path}.") + endif () + + list(APPEND plugin_paths + "${plugin_path}") + endforeach () + + set("${output}" "${plugin_paths}" PARENT_SCOPE) +endfunction () + +#[==[.md +``` +superbuild_get_qt6_plugin_optional_module_install_paths( ) +``` + +Returns a list of absolute path of Qt6 plugins to install from a list of +required plugin directories. This function will not fail if a directory does +not exist, and will install every plugin it will find under the given +directories. + +Also see: superbuild_get_qt6_plugin_install_paths + +Example : + +``` + superbuild_get_qt6_plugin_optional_module_install_paths(output_paths + "platforms;renderers") +``` +#]==] +function (superbuild_get_qt6_plugin_optional_module_install_paths output) + _superbuild_get_qt6_plugin_install_context(qt6_plugin_path qt6_plugin_ext) + + set(plugin_paths) + foreach(directory IN LISTS ARGN) + set(directory_abs_path "${qt6_plugin_path}/${directory}") + if (EXISTS "${directory_abs_path}") + file(GLOB plugins + "${directory_abs_path}/*${qt6_plugin_ext}") + foreach(plugin IN LISTS plugins) + get_filename_component(stripped_plugin "${plugin}" NAME_WE) + list(APPEND plugin_paths + "${directory}/${stripped_plugin}") + endforeach() + else() + message(STATUS "Qt6 plugin directory ${directory} not found, ignoring ..") + endif() + endforeach() + + set("${output}" "${plugin_paths}" PARENT_SCOPE) +endfunction () -- GitLab