cmake: fix finding Qt private headers with Qt >=6.10#53
Conversation
2cf6add to
5420bec
Compare
Signed-off-by: Andrew Udvare <audvare@gmail.com>
|
This gets past the configure stage and gets 99% into the build but fails for me: This file does exist for me at The command has these All of the If I run this manually with the above added, it compiles that file. |
Related-to: movableink/webkit#53 Signed-off-by: Andrew Udvare <audvare@gmail.com>
|
Please consider adding https://github.com/Tatsh/tatsh-overlay/blob/master/dev-qt/qtwebkit/files/qtwebkit-fix-qttestbrowser-build.patch to this PR. |
|
@Tatsh: Thank you for testing. I wasn't building with tests enabled, so I didn't catch the missing piece. Do you know for certain that |
|
I assume you mean CorePrivate. Once I ran with the GuiPrivate includes another error occurred regarding CorePrivate. |
|
@Tatsh: Yes, I did. And does it not work if you append to |
5420bec to
949c35a
Compare
Qt private header directories only get added to the include search path
when the "Qt6::${component}Private" library is added to the target.
949c35a to
02ec306
Compare
whitslack
left a comment
There was a problem hiding this comment.
The merged fixes are a good start, but they miss some key points. See comments.
| macro(CHECK_Qt6_PRIVATE_INCLUDE_DIRS _qt_component _header) | ||
| # Qt6 provides private headers via Qt6::${_qt_component}Private target | ||
| find_package(Qt6${_qt_component}Private QUIET CONFIG) | ||
| set(CMAKE_REQUIRED_LIBRARIES Qt6::${_qt_component}) | ||
|
|
||
| if (NOT TARGET Qt6::${_qt_component}Private) | ||
| message(FATAL_ERROR "Qt6::${_qt_component}Private target not found. Please make sure Qt6 private headers are installed.") | ||
| endif() | ||
| # Qt 6.10+ provides private headers via Qt6::${_qt_component}Private target | ||
| if (Qt6${_qt_component}_VERSION VERSION_GREATER_EQUAL 6.10) | ||
| find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS ${_qt_component}Private) | ||
| list(APPEND CMAKE_REQUIRED_LIBRARIES Qt6::${_qt_component}Private) | ||
| endif () | ||
|
|
||
| set(INCLUDE_TEST_SOURCE | ||
| " | ||
| #include <${_header}> | ||
| int main() { return 0; } | ||
| " | ||
| ) | ||
|
|
||
| # Use the Private target directly - it provides the include dirs automatically | ||
| set(CMAKE_REQUIRED_LIBRARIES Qt6::${_qt_component} Qt6::${_qt_component}Private) | ||
|
|
||
| check_cxx_source_compiles("${INCLUDE_TEST_SOURCE}" Qt6${_qt_component}_PRIVATE_HEADER_FOUND) | ||
|
|
||
| unset(INCLUDE_TEST_SOURCE) | ||
| unset(CMAKE_REQUIRED_LIBRARIES) | ||
|
|
||
| if (NOT Qt6${_qt_component}_PRIVATE_HEADER_FOUND) | ||
| message(FATAL_ERROR "Header ${_header} is not found. Please make sure that: | ||
| 1. Private headers of Qt6${_qt_component} are installed | ||
| 2. Qt6${_qt_component}Private package is available") | ||
| endif () | ||
| endmacro() |
There was a problem hiding this comment.
The *Private targets were only added starting in Qt 6.10, so you need a VERSION_GREATER_EQUAL conditional.
Also, if you specify REQUIRED in the find_package call, then you don't need to write an explicit FATAL_ERROR message.
| @@ -55,6 +54,13 @@ if (TARGET Qt6::PrintSupport) | |||
| list(APPEND QtTestBrowser_LIBRARIES Qt6::PrintSupport) | |||
| endif () | |||
|
|
|||
| if (Qt6Core_VERSION VERSION_GREATER_EQUAL 6.10) | |||
| list(APPEND QtTestBrowser_PRIVATE_LIBRARIES Qt6::CorePrivate) | |||
| endif () | |||
| if (Qt6Gui_VERSION VERSION_GREATER_EQUAL 6.10) | |||
| list(APPEND QtTestBrowser_PRIVATE_LIBRARIES Qt6::GuiPrivate) | |||
| endif () | |||
|
|
|||
There was a problem hiding this comment.
Qt6::GuiPrivate does not belong in QtTestBrowser_LIBRARIES, as it would "infect" dependents with the private dependency. Put it in QtTestBrowser_PRIVATE_LIBRARIES so it will not be transitory.
Qt private header directories only get added to the include search path when the
Qt6::${component}Privatelibrary is added to the target.