Hi,

If qt6 is built with clang, QMAKE_SPEC defaults to linux-clang.
However, if we try to build, for example, "app-benchmarks/i7z" with gcc,
if will fail with:

> g++: error: unrecognized command-line option
'-fno-direct-access-external-data'

This suggests that setting QMAKE_CC / QMAKE_CXX / ... alone is not
sufficient for qmake to select the correct compiler. See the test
case below:

> # cat a.pro
> message(QMAKE_CC is $$QMAKE_CC)
> clang {
>         message("clang is true")
> } else {
>         message("clang is false")
> }
> # /usr/lib64/qt6/bin/qmake a.pro
> Project MESSAGE: QMAKE_CC is clang
> Project MESSAGE: clang is true
> # /usr/lib64/qt6/bin/qmake a.pro QMAKE_CC=gcc
> Project MESSAGE: QMAKE_CC is gcc
> Project MESSAGE: clang is true

After adding "-spec linux-g++",

> # /usr/lib64/qt6/bin/qmake a.pro QMAKE_CC=gcc -spec linux-g++
> Project MESSAGE: QMAKE_CC is gcc
> Project MESSAGE: clang is false

Please note: for now, we only handle Linux with GCC or Clang.

Closes: https://bugs.gentoo.org/960633
Signed-off-by: Z. Liu <[email protected]>
---
 eclass/qmake-utils.eclass | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/eclass/qmake-utils.eclass b/eclass/qmake-utils.eclass
index 5c5fa8dcb047..7c4abf53b685 100644
--- a/eclass/qmake-utils.eclass
+++ b/eclass/qmake-utils.eclass
@@ -185,6 +185,23 @@ qt6_get_qmake_args() {
        EOF
 }

+# @FUNCTION: qt6_get_qmake_spec
+# @DESCRIPTION:
+# Echoes the QMAKESPEC matched with compiler, nothing if is same to the
default
+qt6_get_qmake_spec() {
+       local QMAKE_SPEC=
+       local QMAKE_SPEC_DEF=$("$(qt6_get_bindir)"/qmake -query QMAKE_SPEC)
+       if [[ $(uname -s) == "Linux" ]] ; then
+               if tc-is-gcc ; then
+                       QMAKE_SPEC="linux-g++"
+               elif tc-is-clang ; then
+                       QMAKE_SPEC="linux-clang"
+               fi
+       fi
+
+       [[ "${QMAKE_SPEC}" != "${QMAKE_SPEC_DEF}" ]] && echo
"${QMAKE_SPEC}" || return
+}
+
 # @FUNCTION: eqmake6
 # @USAGE: [arguments for qmake]
 # @DESCRIPTION:
@@ -202,6 +219,16 @@ eqmake6() {

        local -a args
        mapfile -t args <<<"$(qt6_get_qmake_args)"
+
+       local QMAKE_SPEC="$(qt6_get_qmake_spec)"
+
+       [[ -z ${QMAKE_SPEC} ]] || {
+               args+=(
+                       -spec
+                       ${QMAKE_SPEC}
+               )
+       }
+
        # NB: we're passing literal quotes in but qmake doesn't seem to mind
        "$(qt6_get_bindir)"/qmake -makefile "${args[@]}" "$@"

--
2.45.2

Reply via email to