Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions CMake/cotire.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <targetname>_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)
Expand Down Expand Up @@ -2829,6 +2841,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)
Expand Down Expand Up @@ -2883,11 +2907,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
Expand Down Expand Up @@ -3947,6 +3980,16 @@ else()
"Defaults to empty."
)

define_property(
TARGET PROPERTY "COTIRE_<LANG>_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."
Expand Down Expand Up @@ -4051,4 +4094,4 @@ else()

message (STATUS "cotire ${COTIRE_CMAKE_MODULE_VERSION} loaded.")

endif()
endif()
11 changes: 9 additions & 2 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down