Skip to content

Instantly share code, notes, and snippets.

@lyarbean
Last active January 24, 2016 09:46
Show Gist options
  • Save lyarbean/8f9fb5ced2aa92e44780 to your computer and use it in GitHub Desktop.
Save lyarbean/8f9fb5ced2aa92e44780 to your computer and use it in GitHub Desktop.
## If you have a prefix inculde header (says precompile.h) for all module of your project,
## then together with Cotire, do set(GLOBAL PROPERTY COTIRE_CXX_PREFIX_HEADER_INIT_DEFAULT precompile.h)
## and then add_cotire(target_module)
function (add_cotire _target)
get_property(_pch_target GLOBAL PROPERTY COTIRE_CXX_PCH_TARGET)
get_property(_pch_header GLOBAL PROPERTY COTIRE_CXX_PREFIX_HEADER_INIT_DEFAULT)
if("${_pch_target}" STREQUAL "")
set_target_properties(${_target} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${_pch_header})
cotire(${_target})
message("COTIRE_CXX_PCH_TARGET ${_target}")
set_property(GLOBAL PROPERTY COTIRE_CXX_PCH_TARGET ${_target})
else()
set_target_properties(${_target} PROPERTIES COTIRE_ENABLE_PRECOMPILED_HEADER FALSE)
get_target_property(_pch_file ${_pch_target} COTIRE_CXX_PREFIX_HEADER)
get_target_property(_is_enabled ${_pch_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
if(_is_enabled)
target_compile_options(${_target} BEFORE PRIVATE -include ${_pch_file} -Winvalid-pch -D${_pch_target}_EXPORTS)
message("${_target} uses ${_pch_file}")
else()
## Fallback to -include
set_target_properties(${_target} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${_pch_header})
message("${_target} -include ${_pch_header}")
endif()
cotire(${_target})
endif()
endfunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment