Skip to content

cmake: fix finding Qt private headers with Qt >=6.10#53

Open
whitslack wants to merge 1 commit into
movableink:masterfrom
whitslack:fix-private-headers
Open

cmake: fix finding Qt private headers with Qt >=6.10#53
whitslack wants to merge 1 commit into
movableink:masterfrom
whitslack:fix-private-headers

Conversation

@whitslack
Copy link
Copy Markdown

Qt private header directories only get added to the include search path when the Qt6::${component}Private library is added to the target.

@whitslack whitslack force-pushed the fix-private-headers branch 2 times, most recently from 2cf6add to 5420bec Compare January 16, 2026 10:11
whitslack referenced this pull request in Tatsh/tatsh-overlay Jan 17, 2026
Signed-off-by: Andrew Udvare <audvare@gmail.com>
@whitslack whitslack marked this pull request as ready for review January 17, 2026 10:46
@Tatsh
Copy link
Copy Markdown

Tatsh commented Jan 17, 2026

This gets past the configure stage and gets 99% into the build but fails for me:

webkit-1ab4d21d082e89fe1837c0279467a6da18c78cf0/Tools/QtTestBrowser/launcherwindow.h:47:10: fatal error: private/qeventpoint_p.h: No such file or directory
   47 | #include <private/qeventpoint_p.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~

This file does exist for me at /usr/include/qt6/QtGui/6.10.1/QtGui/private/qeventpoint_p.h but I am assuming the include path is not being set properly.

The command has these -isystem flags:

-isystem /usr/include/qt6/QtGui \
-isystem /usr/include/qt6 \
-isystem /usr/include/qt6/QtCore \
-isystem /usr/include/qt6/QtDBus \
-isystem /usr/include/qt6/QtNetwork \
-isystem /usr/include/qt6/QtWidgets \
-isystem /usr/lib64/qt6/mkspecs/linux-g++ \
-isystem /usr/include/qt6/QtPrintSupport \

All of the -I flags are only referencing directories in the source.

-isystem /usr/include/qt6/QtGui/6.10.1/QtGui \
-isystem /usr/include/qt6/QtGui/6.10.1 \
-isystem /usr/include/qt6/QtCore/6.10.1 \

If I run this manually with the above added, it compiles that file.

Tatsh added a commit to Tatsh/tatsh-overlay that referenced this pull request Jan 17, 2026
Related-to: movableink/webkit#53
Signed-off-by: Andrew Udvare <audvare@gmail.com>
@Tatsh
Copy link
Copy Markdown

Tatsh commented Jan 17, 2026

@whitslack
Copy link
Copy Markdown
Author

whitslack commented Jan 17, 2026

@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 NetworkPrivateCorePrivate is required here? Your error message only mentioned a private header from GuiPrivate.

@Tatsh
Copy link
Copy Markdown

Tatsh commented Jan 18, 2026

I assume you mean CorePrivate. Once I ran with the GuiPrivate includes another error occurred regarding CorePrivate.

@whitslack
Copy link
Copy Markdown
Author

@Tatsh: Yes, I did. And does it not work if you append to QtTestBrowser_PRIVATE_LIBRARIES (rather than QtTestBrowser_LIBRARIES)? (The former will not be propagated to dependent targets.)

@whitslack whitslack force-pushed the fix-private-headers branch from 5420bec to 949c35a Compare January 18, 2026 00:20
Qt private header directories only get added to the include search path
when the "Qt6::${component}Private" library is added to the target.
@whitslack whitslack force-pushed the fix-private-headers branch from 949c35a to 02ec306 Compare May 11, 2026 19:50
Copy link
Copy Markdown
Author

@whitslack whitslack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merged fixes are a good start, but they miss some key points. See comments.

Comment on lines 73 to 99
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()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 45 to +63
@@ -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 ()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants