Warning, /education/gcompris/cmake/qt_helper.cmake is written in an unsupported language. File is not indexed.

0001 #=============================================================================
0002 # SPDX-FileCopyrightText: 2014 Thibaut ROMAIN <thibrom@gmail.com>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 #=============================================================================
0006 function(getQtPluginPaths _plugin_target _absolute_path _subdir _file)
0007   getQtPluginsPath(_qt_plugins_path)
0008   get_target_property(_plugin_path ${_plugin_target} LOCATION)
0009   if(NOT _plugin_path)
0010     message(FATAL_ERROR "Could not find ${_plugin_target} plugin path")
0011   endif()
0012   get_filename_component(_plugin_file ${_plugin_path} NAME)
0013   get_filename_component(_plugin_dir ${_plugin_path} PATH)
0014   file(RELATIVE_PATH _plugin_subdir ${_qt_plugins_path} ${_plugin_dir})
0015   set(${_absolute_path} ${_plugin_path} PARENT_SCOPE)
0016   set(${_subdir} ${_plugin_subdir} PARENT_SCOPE)
0017   set(${_file} ${_plugin_file} PARENT_SCOPE)
0018 endfunction()
0019 
0020 # Determine Qt5's plugin-path deriving from lib-dir and trying different
0021 # locations corresponding to different directory layouts, e.g.:
0022 #
0023 # Debian:
0024 #   /usr/lib/i386-linux-gnu/libQt5Qml.so.5.4.1
0025 #   /usr/lib/i386-linux-gnu/qt5/plugins/
0026 # Opensuse:
0027 #   /usr/lib64/libQt5Multimedia.so.5
0028 #   /usr/lib64/qt5/plugins/
0029 # Archlinux:
0030 #   /usr/lib/libQt5Qml.so.5.15
0031 #   /usr/lib/qt/plugins/
0032 # Qt installer:
0033 #   /opt/Qt5.5.1/5.5/gcc/lib/libQt5Qml.so.5.5.1
0034 #   /opt/Qt5.5.1/5.5/gcc/plugins/
0035 #
0036 # The qml/-dir is always a sibling of the plugins/ dir.
0037 function(getQtPluginsPath _path)
0038   get_target_property(_lib_file Qt5::Qml LOCATION)
0039   get_filename_component(_lib_dir ${_lib_file} PATH)
0040   # try $_lib_dir/qt5/plugins (Debian/Opensuse)
0041   set(_plugin_root ${_lib_dir}/qt5/plugins)
0042   if(NOT IS_DIRECTORY ${_plugin_root})
0043     # try $_lib_dir/qt/plugins (Archlinux)
0044     set(_plugin_root ${_lib_dir}/qt/plugins)
0045     if(NOT IS_DIRECTORY ${_plugin_root})
0046       # try $_lib_dir/../plugins (Qt installer)
0047       get_filename_component(_lib_dir_base ${_lib_dir} PATH)
0048       if(APPLE)
0049         set(_plugin_root ${_lib_dir_base}/../plugins)
0050       else()
0051         set(_plugin_root ${_lib_dir_base}/plugins)
0052       endif()
0053     endif()
0054   endif()
0055   set(${_path} ${_plugin_root} PARENT_SCOPE)
0056 endfunction()
0057 
0058 function(getQtQmlPath _path)
0059   getQtPluginsPath(_qt_plugins_path)
0060   get_filename_component(_root ${_qt_plugins_path} PATH)
0061   set(${_path} ${_root}/qml PARENT_SCOPE)
0062 endfunction()
0063 
0064 function(installQtPlugin _plugin _dest_dir _lib)
0065   getQtPluginPaths(${_plugin} _absolute_path _plugin_subdir _plugin_file)
0066   #needed to build with msys2
0067   if(MINGW)
0068     string(REGEX REPLACE "share/qt5/" "" _plugin_subdir ${_plugin_subdir})
0069   endif()
0070   install(FILES ${_absolute_path} DESTINATION ${_dest_dir}/${_plugin_subdir})
0071   set(_lib "\${CMAKE_INSTALL_PREFIX}/${_dest_dir}/${_plugin_subdir}/${_plugin_file}" PARENT_SCOPE)
0072 endfunction()
0073 
0074 function(installQtPlugin2 _plugin _dest_dir _lib)
0075   get_filename_component(_plugin_file ${_plugin} NAME)
0076   set(_ext ${CMAKE_SHARED_LIBRARY_SUFFIX})
0077   get_filename_component(_plugin_subdir ${_plugin} PATH)
0078   get_filename_component(_plugin_subdir_root ${_plugin_subdir} PATH)
0079   getQtPluginsPath(_qt_plugin_path)
0080   install(DIRECTORY ${_qt_plugin_path}/${_plugin_subdir} DESTINATION ${_dest_dir}/${_plugin_subdir_root})
0081   if(CMAKE_HOST_WIN32)
0082     set(_dbg_suffix "d")
0083   else()
0084     set(_dbg_suffix "_debug")
0085   endif()
0086   set(_install_path \${CMAKE_INSTALL_PREFIX}/${_dest_dir}/${_plugin_subdir})
0087   if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
0088     install(CODE "file(REMOVE \"${_install_path}/${_plugin_file}${_ext}\")")
0089     set(_plugin_file ${_plugin_file}${_dbg_suffix}${_ext})
0090   else()
0091     install(CODE "file(REMOVE \"${_install_path}/${_plugin_file}${_dbg_suffix}${_ext}\")")
0092     set(_plugin_file ${_plugin_file}${_ext})
0093   endif()
0094   set(_lib "${_install_path}/${_plugin_file}" PARENT_SCOPE)
0095 endfunction()
0096 
0097 function(installQmlPlugin _plugin _dest_dir _lib)
0098   get_filename_component(_plugin_file ${_plugin} NAME)
0099   set(_ext ${CMAKE_SHARED_LIBRARY_SUFFIX})
0100   get_filename_component(_qml_subdir ${_plugin} PATH)
0101   get_filename_component(_qml_subdir_root ${_qml_subdir} PATH)
0102   getQtQmlPath(_qt_qml_path)
0103   install(DIRECTORY ${_qt_qml_path}/${_qml_subdir} DESTINATION ${_dest_dir}/${_qml_subdir_root})
0104   if(CMAKE_HOST_WIN32)
0105     set(_dbg_suffix "d")
0106   else()
0107     set(_dbg_suffix "_debug")
0108   endif()
0109   set(_install_path \${CMAKE_INSTALL_PREFIX}/${_dest_dir}/${_qml_subdir})
0110   if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
0111     install(CODE "file(REMOVE \"${_install_path}/${_plugin_file}${_ext}\")")
0112     set(_plugin_file ${_plugin_file}${_dbg_suffix}${_ext})
0113   else()
0114     install(CODE "file(REMOVE \"${_install_path}/${_plugin_file}${_dbg_suffix}${_ext}\")")
0115     set(_plugin_file ${_plugin_file}${_ext})
0116   endif()
0117   set(_lib "${_install_path}/${_plugin_file}" PARENT_SCOPE)
0118 endfunction()