Use Qt CMake APIs to exclude files from Unity Build

This is a bit of a cleanup, mainly around unity build, and a few other
minor things:

- I replaced the direct inclusion of sources files using
  `set_source_files_properties`, and instead used
  `NO_UNITY_BUILD_SOURCES` when possible. In most cases, they are being
  excluded in their respective `qt_internal_extend_target` but sometimes
  I had to make a new extension.
- In few cases, we had to manually exclude the NO_PCH files, so, I
  instead passed them directly to the NO_PCH_SOURCES which also exclude
  them from the unity build as well.
- Removed a few unnecessary ""

Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I466576592c1d115a2da4d88672c1e4b9f995f2ed
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Amir Masoud Abdol 2023-03-30 16:49:00 +02:00
parent c19504e708
commit 7e074bd8a0
7 changed files with 57 additions and 76 deletions

View File

@ -315,6 +315,13 @@ qt_internal_add_module(Core
# despite the fact that appropriate checks are in place to avoid that!
tools/qshareddata.cpp tools/qshareddata.h
text/qlocale.cpp text/qlocale.h
global/qglobal.cpp # undef qFatal
global/qlogging.cpp # undef qFatal
text/qstringconverter.cpp # enum Data
tools/qcryptographichash.cpp # KeccakNISTInterface/Final
NO_PCH_SOURCES
compat/removed_api.cpp
global/qsimd.cpp
DEFINES
QT_NO_FOREACH
QT_NO_USING_NAMESPACE
@ -342,15 +349,6 @@ qt_internal_add_module(Core
)
_qt_internal_setup_deploy_support()
set(corelib_no_pch_sources
compat/removed_api.cpp
global/qsimd.cpp
)
foreach(src ${corelib_no_pch_sources})
qt_update_ignore_pch_source(Core ${src})
endforeach()
add_dependencies(Core qmodule_pri)
if (NOT QT_NAMESPACE STREQUAL "")
@ -523,7 +521,6 @@ qt_internal_extend_target(Core CONDITION WIN32
kernel/qwinregistry.cpp kernel/qwinregistry_p.h
plugin/qsystemlibrary.cpp plugin/qsystemlibrary_p.h
thread/qthread_win.cpp
# DEFINES # special case: remove
LIBRARIES
advapi32
authz
@ -541,6 +538,19 @@ qt_internal_extend_target(Core CONDITION WIN32
userenv
)
qt_internal_extend_target(Core CONDITION WIN32
NO_UNITY_BUILD_SOURCES
global/qsimd.cpp # Q_DECL_INIT_PRIORITY
serialization/qcborvalue.cpp # various windows.h clashes
serialization/qjsoncbor.cpp
serialization/qjsonvalue.cpp
serialization/qxmlstream.cpp
text/qbytearray.cpp
text/qlatin1stringmatcher.cpp
text/qunicodetools.cpp
tools/qhash.cpp # Q_DECL_INIT_PRIORITY
)
if(NOT WIN32)
### Qt7: remove
# Make qwineventnotifier.h available on non-Windows platforms too for code bases that include
@ -941,6 +951,8 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_process AND UNIX
SOURCES
../3rdparty/forkfd/forkfd.h
io/forkfd_qt.cpp
NO_UNITY_BUILD_SOURCES
io/forkfd_qt.cpp # EINTR_LOOP macro clashes
INCLUDE_DIRECTORIES
../3rdparty/forkfd
)
@ -1115,6 +1127,8 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_cborstreamreader
qt_internal_extend_target(Core CONDITION QT_FEATURE_cborstreamwriter
SOURCES
serialization/qcborstreamwriter.cpp serialization/qcborstreamwriter.h
NO_UNITY_BUILD_SOURCES
serialization/qcborstreamwriter.cpp # CBOR macro clashes
)
qt_internal_extend_target(Core CONDITION QT_FEATURE_mimetype
@ -1295,31 +1309,11 @@ set_source_files_properties(
thread/qmutex_unix.cpp
PROPERTIES HEADER_FILE_ONLY ON) # special case: These files are included by qmutex.cpp!
set_source_files_properties(serialization/qcborstreamwriter.cpp # CBOR macro clashes
io/forkfd_qt.cpp # EINTR_LOOP macro clashes
global/qglobal.cpp # undef qFatal
global/qlogging.cpp # undef qFatal
text/qstringconverter.cpp # enum Data
tools/qcryptographichash.cpp # KeccakNISTInterface/Final
${corelib_no_pch_sources} # NO_PCH_SOURCES
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
# Remove QT_NO_CAST_TO_ASCII to ensure that the symbols are included in the library.
if(WIN32)
get_target_property(defines Core COMPILE_DEFINITIONS)
list(REMOVE_ITEM defines QT_NO_CAST_TO_ASCII)
set_target_properties(Core PROPERTIES COMPILE_DEFINITIONS "${defines}")
set_source_files_properties(global/qsimd.cpp # Q_DECL_INIT_PRIORITY
serialization/qcborvalue.cpp # various windows.h clashes
serialization/qjsoncbor.cpp
serialization/qjsonvalue.cpp
serialization/qxmlstream.cpp
text/qbytearray.cpp
text/qlatin1stringmatcher.cpp
text/qunicodetools.cpp
tools/qhash.cpp # Q_DECL_INIT_PRIORITY
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
qt_internal_apply_gc_binaries_conditional(Core PUBLIC)

View File

@ -275,7 +275,7 @@ qt_internal_add_module(Gui
PRIVATE_MODULE_INTERFACE
Qt::CorePrivate
NO_PCH_SOURCES
"painting/qdrawhelper.cpp"
painting/qdrawhelper.cpp
PRECOMPILED_HEADER
"kernel/qt_gui_pch.h"
GENERATE_CPP_EXPORTS
@ -292,9 +292,6 @@ set(qpdf_resource_files
"painting/qpdfa_metadata.xml"
)
set_source_files_properties(painting/qdrawhelper.cpp # NO_PCH_SOURCES
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
if(WIN32 OR (UNIX AND NOT APPLE))
set_target_properties(Gui PROPERTIES UNITY_BUILD OFF) # X11 define clashes/Windows oddities.
endif()

View File

@ -379,24 +379,23 @@ qt_internal_extend_target(Network CONDITION QNX PUBLIC_LIBRARIES socket) # speci
qt_internal_extend_target(Network CONDITION SOLARIS PUBLIC_LIBRARIES socket nsl)
if (WIN32)
set_source_files_properties(Network # include windows.h (causing clashes with "interface" define)
kernel/qauthenticator.cpp
kernel/qdnslookup_win.cpp
kernel/qhostaddress.cpp
kernel/qhostinfo.cpp
kernel/qhostinfo_win.cpp
kernel/qnetconmonitor_win.cpp
kernel/qnetworkinterface_win.cpp
kernel/qnetworkproxy_win.cpp
socket/qabstractsocket.cpp
socket/qlocalserver.cpp
socket/qlocalserver_win.cpp
socket/qlocalsocket_win.cpp
socket/qnativesocketengine.cpp
socket/qnativesocketengine_win.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
qt_internal_extend_target(Network CONDITION WIN32
NO_UNITY_BUILD_SOURCES
kernel/qauthenticator.cpp
kernel/qdnslookup_win.cpp
kernel/qhostaddress.cpp
kernel/qhostinfo.cpp
kernel/qhostinfo_win.cpp
kernel/qnetconmonitor_win.cpp
kernel/qnetworkinterface_win.cpp
kernel/qnetworkproxy_win.cpp
socket/qabstractsocket.cpp
socket/qlocalserver.cpp
socket/qlocalserver_win.cpp
socket/qlocalsocket_win.cpp
socket/qnativesocketengine.cpp
socket/qnativesocketengine_win.cpp
)
# include the snippet projects for developer-builds
if(QT_FEATURE_private_tests)

View File

@ -33,6 +33,8 @@ qt_internal_add_module(OpenGL
qopenglvertexarrayobject.cpp qopenglvertexarrayobject.h qopenglvertexarrayobject_p.h
qopenglwindow.cpp qopenglwindow.h
qtopenglglobal.h
NO_UNITY_BUILD_SOURCES
qopengltextureblitter.cpp # qDebug()<< ambiguities
DEFINES
QT_NO_FOREACH
QT_NO_USING_NAMESPACE
@ -48,17 +50,14 @@ qt_internal_add_module(OpenGL
GENERATE_CPP_EXPORTS
)
# qDebug()<< ambiguities
set_source_files_properties(qopengltextureblitter.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
if(APPLE)
set_source_files_properties(qopenglversionfunctionsfactory.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
## Scopes:
#####################################################################
qt_internal_extend_target(OpenGL CONDITION APPLE
NO_UNITY_BUILD_SOURCES
qopenglversionfunctionsfactory.cpp
)
qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_opengles2
SOURCES
qopenglfunctions_es2.cpp qopenglfunctions_es2.h

View File

@ -59,7 +59,7 @@ qt_internal_extend_target(PrintSupport CONDITION MACOS
${FWApplicationServices}
Cups::Cups
NO_PCH_SOURCES
"platform/macos/qcocoaprintersupport.mm"
platform/macos/qcocoaprintersupport.mm
)
qt_internal_extend_target(PrintSupport CONDITION WIN32
@ -74,13 +74,9 @@ qt_internal_extend_target(PrintSupport CONDITION WIN32
comdlg32
winspool
NO_PCH_SOURCES
"platform/windows/qwindowsprintersupport.cpp"
platform/windows/qwindowsprintersupport.cpp
)
set_source_files_properties(platform/macos/qcocoaprintersupport.mm # NO_PCH_SOURCES
platform/windows/qwindowsprintersupport.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printpreviewwidget
SOURCES
kernel/qpaintengine_preview.cpp kernel/qpaintengine_preview_p.h
@ -188,15 +184,14 @@ qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printdialog AND UNIX
dialogs/qprintpropertieswidget.ui
dialogs/qprintsettingsoutput.ui
dialogs/qprintwidget.ui
NO_UNITY_BUILD_SOURCES
dialogs/qprintdialog_unix.cpp # Clashes with CUPS headers
INCLUDE_DIRECTORIES
${QtBase_SOURCE_DIR}/src/plugins/printsupport/cups
ENABLE_AUTOGEN_TOOLS
uic
)
# Clashes with CUPS headers
set_source_files_properties(dialogs/qprintdialog_unix.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printpreviewdialog
SOURCES
dialogs/qprintpreviewdialog.cpp dialogs/qprintpreviewdialog.h

View File

@ -38,9 +38,6 @@ qt_internal_add_module(Sql
GENERATE_CPP_EXPORTS
)
set_source_files_properties(compat/removed_api.cpp # NO_PCH_SOURCES
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
## Scopes:
#####################################################################

View File

@ -68,10 +68,10 @@ qt_internal_add_module(Widgets
GENERATE_CPP_EXPORTS
)
if(APPLE)
set_source_files_properties(kernel/qapplication.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
qt_internal_extend_target(Widgets CONDITION APPLE
NO_UNITY_BUILD_SOURCES
kernel/qapplication.cpp
)
# Resources:
set(qstyle_resource_files