Skip to content

Commit 261ae9b

Browse files
committed
ENH: Enhance Qt6 include directory resolution
Update generator environment handling Refactor CMake to improve Qt6 include path detection with duplicate removal. Add logic for dynamically collecting Qt components and include directories. Update generator commands to include accessible Qt paths for more robust environment configuration.
1 parent bbd2ed8 commit 261ae9b

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

generator/CMakeLists.txt

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,53 @@ endforeach()
5353

5454
# Determine the Qt include prefix
5555
get_target_property(_qtcore_include_dirs Qt${QT_VERSION_MAJOR}::Core INTERFACE_INCLUDE_DIRECTORIES)
56+
get_target_property(all_qt_include_dirs Qt${QT_VERSION_MAJOR}::Widgets INTERFACE_INCLUDE_DIRECTORIES)
57+
set(all_qt_include_dirs "")
58+
set(include_path_seperator ":")
5659
foreach(_qtcore_include_dir IN LISTS _qtcore_include_dirs)
5760
# Some versions of Qt may have subdirectories like "QtCore" for header files
5861
if (IS_DIRECTORY "${_qtcore_include_dir}/QtCore")
5962
set(_qt_include_prefix "${_qtcore_include_dir}")
63+
list(APPEND all_qt_include_dirs "${_qt_include_prefix}")
6064
break()
6165
else()
6266
# If frameworks, then no QtCore should be suffixed
6367
if (IS_DIRECTORY "${_qtcore_include_dir}")
6468
set(_qt_include_prefix "${_qtcore_include_dir}")
69+
list(APPEND all_qt_include_dirs "${_qt_include_prefix}")
6570
break()
6671
endif()
6772
endif()
6873
endforeach()
6974

75+
76+
77+
find_package(Qt6 COMPONENTS Core Gui Widgets Xml OpenGL Network Core5Compat REQUIRED)
78+
set(QT6_COMPONENTS Core Gui Widgets Xml OpenGL Network)
79+
set(QT6_COMPONENTS_FOUND)
80+
foreach(comp IN LISTS QT6_COMPONENTS)
81+
if(Qt6${comp}_FOUND)
82+
list(APPEND QT6_COMPONENTS_FOUND Qt6::${comp})
83+
endif()
84+
endforeach()
85+
unset(QT6_COMPONENTS)
86+
message(STATUS "Found Qt6 components: ${QT6_COMPONENTS_FOUND}")
87+
88+
# Initialize include directory list
89+
set(ALL_QT6_INCLUDE_DIRS)
90+
# Loop through each Qt6 target and collect its INTERFACE_INCLUDE_DIRECTORIES
91+
foreach(qt_target IN LISTS QT6_COMPONENTS_FOUND)
92+
get_target_property(_incs ${qt_target} INTERFACE_INCLUDE_DIRECTORIES)
93+
if(_incs)
94+
list(APPEND ALL_QT6_INCLUDE_DIRS ${_incs})
95+
endif()
96+
endforeach()
97+
unset(QT6_COMPONENTS_FOUND)
98+
99+
# Optionally remove duplicates
100+
list(REMOVE_DUPLICATES ALL_QT6_INCLUDE_DIRS)
101+
102+
70103
# Copy resource to the build tree
71104
message(STATUS "Copying resource files from ${CMAKE_CURRENT_LIST_DIR} to ${CMAKE_CURRENT_BINARY_DIR}")
72105
file(GLOB resources_files *.txt *.xml qtscript_masterinclude.h)
@@ -79,16 +112,20 @@ if(QT_VERSION_MAJOR EQUAL 5)
79112
set(gen_build_all_file "${CMAKE_CURRENT_SOURCE_DIR}/build_all.txt")
80113
else()
81114
# For Qt6, we need to generate a different master include file
82-
set(gen_build_all_file "${CMAKE_CURRENT_BINARY_DIR}/build_all_qt6.txt")
115+
set(gen_build_all_file "${CMAKE_CURRENT_BINARY_DIR}/build_all.txt")
83116
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build_all_qt6.txt ${gen_build_all_file} COPYONLY)
84117
endif()
85118

119+
120+
string(JOIN ":" CMD_LINE_COLON_SEPARATED_INCLUDE_DIRS ${ALL_QT6_INCLUDE_DIRS})
121+
set(QTDIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX} )
86122
add_custom_command(OUTPUT ${PYTHONQT_WRAPPER_SOURCES}
87-
COMMAND ${CMAKE_COMMAND} -E env QTDIR=${Qt${QT_VERSION_MAJOR}_DIR}
123+
COMMAND ${CMAKE_COMMAND} -E env QTDIR=${QTDIR} PYTHONQT_INCLUDE=${_qt_include_prefix}
88124
--modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets>
89125
$<TARGET_FILE:${PROJECT_NAME}>
90-
--qt-include-prefix="${_qt_include_prefix}"
91-
--debug-level=full
126+
# FOR DEBUGGING --dump-object-tree
127+
# FOR DEBUGGING --debug-level=full
128+
--include-paths="${CMD_LINE_COLON_SEPARATED_INCLUDE_DIRS}"
92129
--output-dir=${PYTHONQT_GENERATED_PATH}
93130
${gen_masterinclude_file} ${gen_build_all_file}
94131
COMMENT "Generating PythonQt wrapper sources: $<TARGET_FILE:${PROJECT_NAME}>"

0 commit comments

Comments
 (0)