Skip to content

Commit

Permalink
Use Qt CMake APIs to exclude files from Unity Build
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
amirmasoudabdol committed Apr 3, 2023
1 parent c19504e commit 7e074bd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 76 deletions.
54 changes: 24 additions & 30 deletions src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
35 changes: 17 additions & 18 deletions src/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions src/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 4 additions & 9 deletions src/printsupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#####################################################################

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e074bd

Please sign in to comment.