Skip to content

Commit 4869cbe

Browse files
committed
[commontk] cmake: Address build error by partially reverting AUTOMOC changes
Partially reverts dd82ba4 ("[commontk] cmake: Simplify build-system leveraging AUTOMOC capability", 2025-10-23) to fix a build error reported when AUTOMOC merges all `moc_*.cpp` into one Translation Unit (TU) (`<target>_autogen/mocs_compilation*.cpp`). This change includes: - Reverting to manual specification of moc sources. - Disabling AUTOMOC for specified sources to avoid QMetaTypeId specialization conflicts. This fixes the following error: ``` In file included from /path/to/Support/Qt/6.9.1/gcc_64/include/QtCore/qvariant.h:10, from /path/to/Support/Qt/6.9.1/gcc_64/include/QtCore/qmetaobject.h:10, from /path/to/Support/Qt/6.9.1/gcc_64/include/QtCore/QMetaMethod:1, from /path/to/Projects/PythonQt-CTK/src/PythonQtUtils.h:49, from /path/to/Projects/PythonQt-CTK/src/PythonQt.h:46, from /path/to/Projects/PythonQt-CTK-cmake-Qt6-Release/PythonQt_autogen/CRAGYDUSE3/../../../CTK-Qt6-build/PythonQtGenerator-output-6.9.1/generated_cpp/com_trolltech_qt_core/com_trolltech_qt_core0.h:1, from /path/to/Projects/PythonQt-CTK-cmake-Qt6-Release/PythonQt_autogen/CRAGYDUSE3/moc_com_trolltech_qt_core0.cpp:9, from /path/to/Projects/PythonQt-CTK-cmake-Qt6-Release/PythonQt_autogen/mocs_compilation.cpp:2: /path/to/Support/Qt/6.9.1/gcc_64/include/QtPrintSupport/qprintengine.h:12:1: error: specialization of ‘QMetaTypeId<QMarginsF>’ after instantiation 12 | Q_DECLARE_METATYPE(QMarginsF) | ^~~~~~~~~~~~~~~~~~ /path/to/Support/Qt/6.9.1/gcc_64/include/QtPrintSupport/qprintengine.h:12:1: error: redefinition of ‘struct QMetaTypeId<QMarginsF>’ /path/to/Support/Qt/6.9.1/gcc_64/include/QtCore/qmetatype.h:1232:8: note: previous definition of ‘struct QMetaTypeId<QMarginsF>’ ```
1 parent 9d9d06c commit 4869cbe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ set(headers
243243
extensions/PythonQt_QtAll/PythonQt_QtAll.h
244244
)
245245

246+
#-----------------------------------------------------------------------------
247+
# Headers that should run through moc
248+
249+
set(moc_sources
250+
)
251+
246252
#-----------------------------------------------------------------------------
247253
# Add extra sources
248254

@@ -265,13 +271,22 @@ foreach(qtlib ${qtlibs})
265271
list(APPEND sources ${PythonQt_GENERATED_PATH}/${file_prefix}${index}.cpp)
266272
endif()
267273

274+
# Headers that should run through moc
275+
if(EXISTS ${PythonQt_GENERATED_PATH}/${file_prefix}${index}.h)
276+
list(APPEND moc_sources ${PythonQt_GENERATED_PATH}/${file_prefix}${index}.h)
277+
endif()
278+
268279
endforeach()
269280

270281
list(APPEND sources ${PythonQt_GENERATED_PATH}/${file_prefix}_init.cpp)
271282

272283
endif()
273284
endforeach()
274285

286+
#-----------------------------------------------------------------------------
287+
# Do wrapping
288+
qt_wrap_cpp(sources ${moc_sources})
289+
275290
#-----------------------------------------------------------------------------
276291
# Configure header
277292

@@ -300,6 +315,11 @@ set_target_properties(PythonQt
300315
AUTOMOC TRUE
301316
)
302317

318+
# Disable AUTOMOC for specified moc sources to avoid QMetaTypeId specialization conflicts.
319+
foreach(moc_source IN LISTS moc_sources)
320+
set_property(SOURCE ${moc_source} PROPERTY SKIP_AUTOMOC ON)
321+
endforeach()
322+
303323
target_compile_definitions(PythonQt
304324
PRIVATE
305325
$<$<BOOL:${PythonQt_DEBUG}>:PYTHONQT_DEBUG>

0 commit comments

Comments
 (0)