CMake: fix macOS build when Qt5 and Qt6 are both installed

When both qt (qt@6) and qt5 are installed via Homebrew, the build fails:

    FAILED: ui/qt/CMakeFiles/qtui.dir/qtui_autogen/mocs_compilation.cpp.o
    ...
    In file included from ui/qt/qtui_autogen/mocs_compilation.cpp:2:
    In file included from ui/qt/qtui_autogen/EWIEGA46WW/moc_about_dialog.cpp:10:
    In file included from ui/qt/qtui_autogen/EWIEGA46WW/../../../../../repos/wireshark/ui/qt/about_dialog.h:15:
    In file included from /Users/pwu/repos/wireshark/ui/qt/models/astringlist_list_model.h:15:
    In file included from /usr/local/opt/qt5/lib/QtCore.framework/Headers/QAbstractTableModel:1:
    In file included from /usr/local/opt/qt5/lib/QtCore.framework/Headers/qabstractitemmodel.h:43:
    In file included from /usr/local/include/QtCore/qvariant.h:43:
    In file included from /usr/local/include/QtCore/qatomic.h:41:
    /usr/local/include/QtCore/qglobal.h:667:26: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
             typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> &&
                        ~~~~~^

That qvariant.h header is from Qt 6 which is backwards incompatible:

    /usr/local/include/QtCore -> ../Cellar/qt/6.0.2/include/QtCore

It appears that `<qt5 prefix>/include` must be explicitly included as
the default Qt5 include directories does not cover this:

    $ find /usr/local -lname '*include/QtCore' -ls
    ... /usr/local/include/QtCore -> ../Cellar/qt/6.0.2/include/QtCore
    $ find /usr/local -name qvariant.h -ls
    ... /usr/local/Cellar/qt@5/5.15.2/lib/QtCore.framework/Versions/5/Headers/qvariant.h
    ... /usr/local/Cellar/qt/6.0.2/lib/QtCore.framework/Versions/A/Headers/qvariant.h
    $ find /usr/local -name QtCore -lname '*Headers' -ls
    ... /usr/local/Cellar/qt@5/5.15.2/include/QtCore -> ../lib/QtCore.framework/Headers
    ... /usr/local/Cellar/qt/6.0.2/include/QtCore -> ../lib/QtCore.framework/Headers
    $ ls -la /usr/local/opt/qt5
    ... /usr/local/opt/qt5 -> ../Cellar/qt@5/5.15.2
This commit is contained in:
Peter Wu 2021-03-10 18:01:09 +01:00
parent c295e8a149
commit 785657d9b8
1 changed files with 9 additions and 0 deletions

View File

@ -1194,6 +1194,15 @@ if(BUILD_wireshark)
list(APPEND QT_INCLUDE_DIRS ${${_qt_package}_INCLUDE_DIRS})
list(APPEND QT_COMPILE_DEFINITIONS ${${_qt_package}_COMPILE_DEFINITIONS})
endforeach()
if(APPLE AND "/usr/local/opt/qt5/lib/QtCore.framework" IN_LIST Qt5Core_INCLUDE_DIRS)
# When qt@6 and qt@5 are both installed via Homebrew,
# /usr/local/include/QtCore/qvariant.h points to Qt 6 headers.
# Normally the Headers from `-iframework /usr/local/opt/qt5/lib`
# should be used, but `-isystem /usr/local/include` (via
# Libgcrypt and others) seems to prioritized, resulting in use
# of the Qt6 headers. Resolve this by explicit including Qt5.
list(APPEND QT_INCLUDE_DIRS /usr/local/opt/qt5/include)
endif()
set(QT_FOUND ON)
if(Qt5MacExtras_FOUND)
set(QT_MACEXTRAS_LIB 1)