cotire
cotire copied to clipboard
Want to use the precompiled header of other binary target
For example, want to use the same precompiled header in order to compile many example codes quickly.
Cotire dose not support this function, so I implemented the command shown below by using cotire private commands:
# HACK: shared precompiled header
function(use_shared_pch target origin)
# origin prefix header
get_target_property(origin_prefix_header ${origin} COTIRE_CXX_PREFIX_HEADER)
# make target pch flags
cotire_make_pch_file_path(CXX ${CMAKE_CURRENT_SOURCE_DIR} ${origin} origin_pch_file)
cotire_add_prefix_pch_inclusion_flags(
CXX ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}
${origin_prefix_header} ${origin_pch_file}
target_pch_flags
)
set_property(TARGET ${target} APPEND_STRING PROPERTY COMPILE_FLAGS ${target_pch_flags})
endfunction()
add_executable(example1 example1.cpp)
cotire(example1)
add_executable(example2 example2.cpp)
use_shared_pch(example2 example1)
add_executable(example3 example3.cpp)
use_shared_pch(example3 example1)
shared pch fails in msvc