I found some discussion around problems with anonymous namespaces and using CMAKE_UNITY_BUILD from about a year ago [1]. I’m using CMake 3.21 and the project runs Qt’s QtQuick compiler over all of the QML source files to generate cpp. It seems to be strictly those files that have compilation errors when I try to enable the unity build. Many other non-qml-based source files have anonymous namespaces and they seem to be just fine.
EDIT: I just used basic default settings and batch mode.
e.g.
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCBottomSelectionTray_qml.cpp(1082) : error C2084: function 'QV4::ReturnedValue `anonymous-namespace'::jsfunction_53(QV4::ExecutionEngine *)' already has a body
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCUpDownSpinner_qml.cpp(1313) : see previous definition of 'jsfunction_53'
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCBottomSelectionTray_qml.cpp(1097) : error C2084: function 'QV4::ReturnedValue `anonymous-namespace'::jsfunction_54(QV4::ExecutionEngine *)' already has a body
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCUpDownSpinner_qml.cpp(1336) : see previous definition of 'jsfunction_54'
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCBottomSelectionTray_qml.cpp(1105) : error C2084: function 'QV4::ReturnedValue `anonymous-namespace'::jsfunction_55(QV4::ExecutionEngine *)' already has a body
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCUpDownSpinner_qml.cpp(1401) : see previous definition of 'jsfunction_55'
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCBottomSelectionTray_qml.cpp(1120) : error C2084: function 'QV4::ReturnedValue `anonymous-namespace'::jsfunction_56(QV4::ExecutionEngine *)' already has a body
C:/Projects/build-AEPP-VS2013-Debug/eSW/Qt/QtCommon/BCControls/BCUpDownSpinner_qml.cpp(1478) : see previous definition of 'jsfunction_56'
Is it best to avoid unity builds completely in cases like this? I was just trying out various ways to speed up build times.