| 1 |
# SPDX-FileCopyrightText: 2014 Rohan Garg <[email protected]> |
| 2 |
# SPDX-FileCopyrightText: 2014 Alex Merry <[email protected]> |
| 3 |
# SPDX-FileCopyrightText: 2014-2016 Aleix Pol <[email protected]> |
| 4 |
# SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <[email protected]> |
| 5 |
# SPDX-FileCopyrightText: 2022 Ahmad Samir <[email protected]> |
| 6 |
# |
| 7 |
# SPDX-License-Identifier: BSD-3-Clause |
| 8 |
#[=======================================================================[.rst: |
| 9 |
ECMQueryQt |
| 10 |
--------------- |
| 11 |
This module can be used to query the installation paths used by Qt. |
| 12 |
|
| 13 |
For Qt5 this uses ``qmake``, and for Qt6 this used ``qtpaths`` (the latter has built-in |
| 14 |
support to query the paths of a target platform when cross-compiling). |
| 15 |
|
| 16 |
This module defines the following function: |
| 17 |
:: |
| 18 |
|
| 19 |
ecm_query_qt(<result_variable> <qt_variable> [TRY]) |
| 20 |
|
| 21 |
Passing ``TRY`` will result in the method not making the build fail if the executable |
| 22 |
used for querying has not been found, but instead simply print a warning message and |
| 23 |
return an empty string. |
| 24 |
|
| 25 |
Example usage: |
| 26 |
|
| 27 |
.. code-block:: cmake |
| 28 |
|
| 29 |
include(ECMQueryQt) |
| 30 |
ecm_query_qt(bin_dir QT_INSTALL_BINS) |
| 31 |
|
| 32 |
If the call succeeds ``${bin_dir}`` will be set to ``<prefix>/path/to/bin/dir`` (e.g. |
| 33 |
``/usr/lib64/qt/bin/``). |
| 34 |
|
| 35 |
Since: 5.93 |
| 36 |
#]=======================================================================] |
| 37 |
|
| 38 |
include(CheckLanguage) |
| 39 |
check_language(CXX) |
| 40 |
if (CMAKE_CXX_COMPILER) |
| 41 |
# Enable the CXX language to let CMake look for config files in library dirs. |
| 42 |
# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23266 |
| 43 |
enable_language(CXX) |
| 44 |
endif() |
| 45 |
|
| 46 |
if (QT_VERSION_MAJOR STREQUAL "5") |
| 47 |
set(_exec_name_text "Qt5 qmake") |
| 48 |
if(TARGET Qt5::qmake) |
| 49 |
get_target_property(_qmake_executable_default Qt5::qmake LOCATION) |
| 50 |
|
| 51 |
set(QUERY_EXECUTABLE ${_qmake_executable_default}) |
| 52 |
set(_cli_option "-query") |
| 53 |
endif() |
| 54 |
else () |
| 55 |
set(_exec_name_text "Qt6 qtpaths") |
| 56 |
if (TARGET Qt6::qtpaths) |
| 57 |
get_target_property(_qtpaths_executable Qt6::qtpaths LOCATION) |
| 58 |
|
| 59 |
set(QUERY_EXECUTABLE ${_qtpaths_executable}) |
| 60 |
set(_cli_option "--query") |
| 61 |
endif() |
| 62 |
endif() |
| 63 |
|
| 64 |
function(ecm_query_qt result_variable qt_variable) |
| 65 |
set(options TRY) |
| 66 |
set(oneValueArgs) |
| 67 |
set(multiValueArgs) |
| 68 |
|
| 69 |
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 70 |
|
| 71 |
if(NOT QUERY_EXECUTABLE) |
| 72 |
if(ARGS_TRY) |
| 73 |
set(${result_variable} "" PARENT_SCOPE) |
| 74 |
message(STATUS "No ${_exec_name_text} executable found. Can't check ${qt_variable}") |
| 75 |
return() |
| 76 |
else() |
| 77 |
message(FATAL_ERROR "No ${_exec_name_text} executable found. Can't check ${qt_variable} as required") |
| 78 |
endif() |
| 79 |
endif() |
| 80 |
execute_process( |
| 81 |
COMMAND ${QUERY_EXECUTABLE} ${_cli_option} "${qt_variable}" |
| 82 |
RESULT_VARIABLE return_code |
| 83 |
OUTPUT_VARIABLE output |
| 84 |
) |
| 85 |
if(return_code EQUAL 0) |
| 86 |
string(STRIP "${output}" output) |
| 87 |
file(TO_CMAKE_PATH "${output}" output_path) |
| 88 |
set(${result_variable} "${output_path}" PARENT_SCOPE) |
| 89 |
else() |
| 90 |
message(WARNING "Failed call: ${QUERY_EXECUTABLE} ${_cli_option} ${qt_variable}") |
| 91 |
message(FATAL_ERROR "${_exec_name_text} call failed: ${return_code}") |
| 92 |
endif() |
| 93 |
endfunction() |