Warning, /frameworks/extra-cmake-modules/modules/ECMQueryQt.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2014 Rohan Garg <rohan16garg@gmail.com>
0002 # SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
0003 # SPDX-FileCopyrightText: 2014-2016 Aleix Pol <aleixpol@kde.org>
0004 # SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 # SPDX-FileCopyrightText: 2022 Ahmad Samir <a.samir78@gmail.com>
0006 #
0007 # SPDX-License-Identifier: BSD-3-Clause
0008 #[=======================================================================[.rst:
0009 ECMQueryQt
0010 ---------------
0011 This module can be used to query the installation paths used by Qt.
0012
0013 For Qt5 this uses ``qmake``, and for Qt6 this used ``qtpaths`` (the latter has built-in
0014 support to query the paths of a target platform when cross-compiling).
0015
0016 This module defines the following function:
0017 ::
0018
0019 ecm_query_qt(<result_variable> <qt_variable> [TRY])
0020
0021 Passing ``TRY`` will result in the method not making the build fail if the executable
0022 used for querying has not been found, but instead simply print a warning message and
0023 return an empty string.
0024
0025 Example usage:
0026
0027 .. code-block:: cmake
0028
0029 include(ECMQueryQt)
0030 ecm_query_qt(bin_dir QT_INSTALL_BINS)
0031
0032 If the call succeeds ``${bin_dir}`` will be set to ``<prefix>/path/to/bin/dir`` (e.g.
0033 ``/usr/lib64/qt/bin/``).
0034
0035 Since: 5.93
0036 #]=======================================================================]
0037
0038 include(${CMAKE_CURRENT_LIST_DIR}/QtVersionOption.cmake)
0039 include(CheckLanguage)
0040 check_language(CXX)
0041 if (CMAKE_CXX_COMPILER)
0042 # Enable the CXX language to let CMake look for config files in library dirs.
0043 # See: https://gitlab.kitware.com/cmake/cmake/-/issues/23266
0044 enable_language(CXX)
0045 endif()
0046
0047 if (QT_MAJOR_VERSION STREQUAL "5")
0048 # QUIET to accommodate the TRY option
0049 find_package(Qt${QT_MAJOR_VERSION}Core QUIET)
0050 if(TARGET Qt5::qmake)
0051 get_target_property(_qmake_executable_default Qt5::qmake LOCATION)
0052
0053 set(QUERY_EXECUTABLE ${_qmake_executable_default}
0054 CACHE FILEPATH "Location of the Qt5 qmake executable")
0055 set(_exec_name_text "Qt5 qmake")
0056 set(_cli_option "-query")
0057 endif()
0058 elseif(QT_MAJOR_VERSION STREQUAL "6")
0059 # QUIET to accommodate the TRY option
0060 find_package(Qt6 COMPONENTS CoreTools QUIET CONFIG)
0061 if (TARGET Qt6::qtpaths)
0062 get_target_property(_qtpaths_executable Qt6::qtpaths LOCATION)
0063
0064 set(QUERY_EXECUTABLE ${_qtpaths_executable}
0065 CACHE FILEPATH "Location of the Qt6 qtpaths executable")
0066 set(_exec_name_text "Qt6 qtpaths")
0067 set(_cli_option "--query")
0068 endif()
0069 endif()
0070
0071 function(ecm_query_qt result_variable qt_variable)
0072 set(options TRY)
0073 set(oneValueArgs)
0074 set(multiValueArgs)
0075
0076 cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0077
0078 if(NOT QUERY_EXECUTABLE)
0079 if(ARGS_TRY)
0080 set(${result_variable} "" PARENT_SCOPE)
0081 message(STATUS "No ${_exec_name_text} executable found. Can't check ${qt_variable}")
0082 return()
0083 else()
0084 message(FATAL_ERROR "No ${_exec_name_text} executable found. Can't check ${qt_variable} as required")
0085 endif()
0086 endif()
0087 execute_process(
0088 COMMAND ${QUERY_EXECUTABLE} ${_cli_option} "${qt_variable}"
0089 RESULT_VARIABLE return_code
0090 OUTPUT_VARIABLE output
0091 )
0092 if(return_code EQUAL 0)
0093 string(STRIP "${output}" output)
0094 file(TO_CMAKE_PATH "${output}" output_path)
0095 set(${result_variable} "${output_path}" PARENT_SCOPE)
0096 else()
0097 message(WARNING "Failed call: ${QUERY_EXECUTABLE} ${_cli_option} ${qt_variable}")
0098 message(FATAL_ERROR "${_exec_name_text} call failed: ${return_code}")
0099 endif()
0100 endfunction()