Skip to content

Commit

Permalink
disable unity builds if automatic Qt processing is used
Browse files Browse the repository at this point in the history
  • Loading branch information
sakra committed Mar 17, 2018
1 parent bbe7af6 commit cec55d8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 189 deletions.
47 changes: 17 additions & 30 deletions CMake/cotire.cmake
Expand Up @@ -2815,6 +2815,9 @@ function (cotire_make_target_message _target _languages _disableMsg _targetMsgVa
else()
set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build.")
endif()
if (_disableMsg)
set (_targetMsg "${_targetMsg} ${_disableMsg}")
endif()
else()
if (_excludedStr)
set (_targetMsg "${_languagesStr} target ${_target} cotired ${_excludedStr}.")
Expand Down Expand Up @@ -2904,6 +2907,20 @@ function (cotire_choose_target_languages _target _targetLanguagesVar _wholeTarge
set (_targetUsePCH FALSE)
endif()
endif()
if (_targetAddSCU)
# disable unity builds if automatic Qt processing is used
get_target_property(_targetAutoMoc ${_target} AUTOMOC)
get_target_property(_targetAutoUic ${_target} AUTOUIC)
get_target_property(_targetAutoRcc ${_target} AUTORCC)
if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
if (_disableMsg)
set (_disableMsg "${_disableMsg} Target uses automatic CMake Qt processing.")
else()
set (_disableMsg "Target uses automatic CMake Qt processing.")
endif()
set (_targetAddSCU FALSE)
endif()
endif()
set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER ${_targetUsePCH})
set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD ${_targetAddSCU})
cotire_make_target_message(${_target} "${_targetLanguages}" "${_disableMsg}" _targetMsg ${_allExcludedSourceFiles})
Expand Down Expand Up @@ -3138,21 +3155,6 @@ function (cotire_setup_unity_build_target _languages _configurations _target)
# determine unity target sources
set (_unityTargetSources "")
cotire_collect_unity_target_sources(${_target} "${_languages}" _unityTargetSources)
# handle automatic Qt processing
get_target_property(_targetAutoMoc ${_target} AUTOMOC)
get_target_property(_targetAutoUic ${_target} AUTOUIC)
get_target_property(_targetAutoRcc ${_target} AUTORCC)
if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
# if the original target sources are subject to CMake's automatic Qt processing,
# also include implicitly generated <targetname>_automoc.cpp file
if (CMAKE_VERSION VERSION_LESS "3.8.0")
list (APPEND _unityTargetSources "${_target}_automoc.cpp")
set_property (SOURCE "${_target}_automoc.cpp" PROPERTY GENERATED TRUE)
else()
list (APPEND _unityTargetSources "${_target}_autogen/moc_compilation.cpp")
set_property (SOURCE "${_target}_autogen/moc_compilation.cpp" PROPERTY GENERATED TRUE)
endif()
endif()
# prevent AUTOMOC, AUTOUIC and AUTORCC properties from being set when the unity target is created
set (CMAKE_AUTOMOC OFF)
set (CMAKE_AUTOUIC OFF)
Expand All @@ -3166,21 +3168,6 @@ function (cotire_setup_unity_build_target _languages _configurations _target)
else()
add_library(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
endif()
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# depend on original target's automoc target, if it exists
if (TARGET ${_target}_automoc)
add_dependencies(${_unityTargetName} ${_target}_automoc)
endif()
else()
if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
# depend on the original target's implicity generated <targetname>_automoc target
if (CMAKE_VERSION VERSION_LESS "3.8.0")
add_dependencies(${_unityTargetName} ${_target}_automoc)
else()
add_dependencies(${_unityTargetName} ${_target}_autogen)
endif()
endif()
endif()
# copy output location properties
set (_outputDirProperties
ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>
Expand Down
14 changes: 2 additions & 12 deletions MANUAL.md
Expand Up @@ -616,16 +616,8 @@ the property value from its enclosing directory. To make all targets in the proj

### using cotire with Qt

Cotire is compatible with both Qt4 and Qt5 projects that use CMake as build system.

If a CMake target's `AUTOMOC` or `AUTOUIC` properties are set, the generated unity target will
automatically add a dependency to the implicitly generated `<targetname>_automoc` target to ensure
that `moc` and `uic` are run on the individual source files.

The unity target will also include the implicitly generated `<targetname>_automoc.cpp` source file.

The `Patches` directory contains examples for the [Qt4][fsedit_qt4] and [Qt5][fsedit_qt5] based
variants of the *FSEditor* sample Qt application.
Cotire is compatible with both Qt projects that use CMake as build system, provided Qt targets
do not use CMake automatic moc, uid or rcc scanning.

### installing files generated by unity targets

Expand Down Expand Up @@ -779,8 +771,6 @@ Cotire is not compatible with [Xoreax IncrediBuild][XGE].
[ccch]:https://ccache.samba.org/
[ccch_pch]:https://ccache.samba.org/manual.html#_precompiled_headers
[clang_pch]:http://clang.llvm.org/docs/UsersManual.html#precompiled-headers
[fsedit_qt4]:http://www.vikingsoft.eu/fseditor.html
[fsedit_qt5]:https://github.com/joonhwan/fsedit-qt5
[gcc_pch]:https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
[msvc_pch]:https://msdn.microsoft.com/en-us/library/szfdksca(v=vs.90).aspx
[msvc_pch_create]:https://msdn.microsoft.com/en-us/library/7zc28563(v=vs.90).aspx
Expand Down
74 changes: 0 additions & 74 deletions Patches/fsedit-qt5.patch

This file was deleted.

68 changes: 0 additions & 68 deletions Patches/fseditor-1.0.patch

This file was deleted.

9 changes: 4 additions & 5 deletions README.md
Expand Up @@ -22,7 +22,6 @@ features
* Leverages native precompiled header generation features of IDEs (Visual Studio and Xcode).
* Compatible with CMake's [cross-compiling][ccrc] support.
* Compatible with compiler wrappers like [ccache][ccch].
* Applicable to CMake based Qt projects.
* Tested with Windows, Linux and OS X.
* MIT licensed.

Expand Down Expand Up @@ -117,8 +116,8 @@ known issues

[ccch]:https://ccache.samba.org/
[ccrc]:https://cmake.org/Wiki/CMake_Cross_Compiling
[cgwn]:http://www.cygwin.com/
[clang]:http://clang.llvm.org/
[cgwn]:https://www.cygwin.com/
[clang]:https://clang.llvm.org/
[cmk]:https://cmake.org/download/
[gcc]:https://gcc.gnu.org/
[manual]:https://github.com/sakra/cotire/blob/master/MANUAL.md
Expand All @@ -131,7 +130,7 @@ known issues
[xcdt]:https://developer.apple.com/xcode/
[PCHH]:https://gcc.gnu.org/wiki/PCHHaters
[EoUB]:https://engineering-game-dev.com/2009/12/15/the-evils-of-unity-builds/
[jom]:http://wiki.qt.io/Jom
[jom]:https://wiki.qt.io/Jom
[intel]:https://software.intel.com/en-us/c-compilers
[XGE]:https://www.incredibuild.com/
[shrp]:http://unriskinsight.blogspot.co.at/2014/09/sharpen-your-tools.html
[shrp]:https://unriskinsight.blogspot.co.at/2014/09/sharpen-your-tools.html

0 comments on commit cec55d8

Please sign in to comment.