From 82281a7fb4c0ed174f3a4b562ca64db74df3e834 Mon Sep 17 00:00:00 2001 From: fkorsa Date: Thu, 11 Jan 2018 12:45:03 +0100 Subject: [PATCH 1/3] Add the possibility to specify the PCH host file (e.g. stdafx.cpp) to cotire, so that it doesn't have to be the first file passed to add_library or add_executable. --- CMake/cotire.cmake | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/CMake/cotire.cmake b/CMake/cotire.cmake index 62cd23d..9badb64 100644 --- a/CMake/cotire.cmake +++ b/CMake/cotire.cmake @@ -2829,6 +2829,18 @@ function (cotire_compute_unity_max_number_of_includes _target _maxIncludesVar) set (${_maxIncludesVar} ${_maxIncludes} PARENT_SCOPE) endfunction() +function (cotire_get_source_list_without_host_file _hostFile _sourceFiles _sourceFilesWithoutHostFile) + get_filename_component(realPathToHostFile ${_hostFile} REALPATH) + set(outputList "") + foreach(sourceFile ${_sourceFiles}) + get_filename_component(realPathToFile ${sourceFile} REALPATH) + if (NOT ${realPathToHostFile} STREQUAL ${realPathToFile}) + list(APPEND outputList ${sourceFile}) + endif() + endforeach() + set(${_sourceFilesWithoutHostFile} ${outputList} PARENT_SCOPE) +endfunction() + function (cotire_process_target_language _language _configurations _target _wholeTarget _cmdsVar) set (${_cmdsVar} "" PARENT_SCOPE) get_target_property(_targetSourceFiles ${_target} SOURCES) @@ -2883,11 +2895,20 @@ function (cotire_process_target_language _language _configurations _target _whol if (_targetUsePCH) cotire_make_pch_file_path(${_language} ${_target} _pchFile) if (_pchFile) - # first file in _sourceFiles is passed as the host file + # check for user provided prefix header files + get_property(_hostHeaderFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_HOST_INIT) + set(_hostFile "") + if (_hostHeaderFile) + set(_hostFile ${_hostHeaderFile}) + else() + # first file in _sourceFiles is passed as the host file + list(GET _sourceFiles 0 _hostFile) + endif() + cotire_get_source_list_without_host_file(${_hostFile} "${_sourceFiles}" sourceFilesWithoutHostFile) cotire_setup_pch_file_compilation( - ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_pchFile}" ${_sourceFiles}) + ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_pchFile}" "${_hostFile}" ${sourceFilesWithoutHostFile}) cotire_setup_pch_file_inclusion( - ${_language} ${_target} ${_wholeTarget} "${_prefixFile}" "${_pchFile}" ${_sourceFiles}) + ${_language} ${_target} ${_wholeTarget} "${_prefixFile}" "${_pchFile}" "${_hostFile}" ${sourceFilesWithoutHostFile}) endif() elseif (_prefixHeaderFiles) # user provided prefix header must be included unconditionally @@ -3947,6 +3968,16 @@ else() "Defaults to empty." ) + define_property( + TARGET PROPERTY "COTIRE__PREFIX_HEADER_HOST_INIT" + BRIEF_DOCS "User provided host file to be used instead of the first one in the sources list." + FULL_DOCS + "If set, cotire will the given source file as a host file for precompiled header creation." + "If not set, cotire will use the first file passed as parameter to add_library or add_executable as host file." + "The property can be set to a user provided PCH host file (e.g., stdafx.cpp)." + "Defaults to empty." + ) + define_property( TARGET PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT" INHERITED BRIEF_DOCS "Define strategy for setting up unity target's link libraries." @@ -4051,4 +4082,4 @@ else() message (STATUS "cotire ${COTIRE_CMAKE_MODULE_VERSION} loaded.") -endif() +endif() \ No newline at end of file From 0414e9f8e1d1e000a5a07f5274d21bafedf7ab1f Mon Sep 17 00:00:00 2001 From: fkorsa Date: Thu, 11 Jan 2018 12:46:11 +0100 Subject: [PATCH 2/3] Include automoc'ed files into the list of source files considered for PCH, so that they benefit from the compilation boost. --- CMake/cotire.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMake/cotire.cmake b/CMake/cotire.cmake index 9badb64..7db587b 100644 --- a/CMake/cotire.cmake +++ b/CMake/cotire.cmake @@ -254,6 +254,18 @@ function (cotire_filter_language_source_files _language _target _sourceFilesVar message (STATUS "Cotired ${_target} ${_language} sources: ${_cotiredSourceFiles}") endif() endif() + 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 _automoc.cpp file + if (CMAKE_VERSION VERSION_LESS "3.8.0") + list (APPEND _sourceFiles "${CMAKE_CURRENT_BINARY_DIR}/${_target}_automoc.cpp") + else() + list (APPEND _sourceFiles "${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen/mocs_compilation.cpp") + endif() + endif() set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE) set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE) set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE) From 90fdf3c6def0a062b6db00225a4079add61ab9d1 Mon Sep 17 00:00:00 2001 From: fkorsa Date: Thu, 11 Jan 2018 12:53:02 +0100 Subject: [PATCH 3/3] Modified the manual to document the use of the new property COTIRE_CXX_PREFIX_HEADER_HOST_INIT. --- MANUAL.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index af1f1fe..461ce34 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -340,8 +340,15 @@ file. The path is interpreted relative to the target source directory: cotire(example) If the prefix header `stdafx.h` needs an accompanying source file (e.g., `stdafx.cpp`) in order -to be precompiled properly, that source file needs to be the first one on the list of source -files in the target's `add_executable` or `add_library` call. +to be precompiled properly, you should set the target property `COTIRE_CXX_PREFIX_HEADER_HOST_INIT` +to this file: + + set_target_properties(example PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "stdafx.h") + set_target_properties(example PROPERTIES COTIRE_CXX_PREFIX_HEADER_HOST_INIT "stdafx.cpp") + cotire(example) + +Otherwise, that source file needs to be the first one on the list of source files in the target's +`add_executable` or `add_library` call. The property `COTIRE_CXX_PREFIX_HEADER_INIT` can also be set to a list of header files which will then make up the contents of the generated prefix header.