Skip to content

Commit

Permalink
PrecompiledHeader.cmake: fix building pch for sources outside current…
Browse files Browse the repository at this point in the history
… dir
  • Loading branch information
andrzejc committed Feb 12, 2017
1 parent d1b44d1 commit 0f0b49b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions PrecompiledHeader.cmake
Expand Up @@ -93,14 +93,14 @@ function(add_precompiled_header _target _input)

if(MSVC)

set(_cxx_path "$<CONFIG>/${_target}_cxx_pch")
set(_c_path "$<CONFIG>/${_target}_c_pch")
set(_cxx_path "${_target}_cxx_pch")
set(_c_path "${_target}_c_pch")
file(MAKE_DIRECTORY "${_cxx_path}")
file(MAKE_DIRECTORY "${_c_path}")
set(_pch_cxx_header "${_cxx_path}/${_input}")
set(_pch_cxx_pch "${_cxx_path}/${_input_we}.pch")
set(_pch_cxx_pch "${_cxx_path}/${_input_we}-$<CONFIG>.pch")
set(_pch_c_header "${_c_path}/${_input}")
set(_pch_c_pch "${_c_path}/${_input_we}.pch")
set(_pch_c_pch "${_c_path}/${_input_we}-$<CONFIG>.pch")
get_filename_component(_input_abs ${_input} ABSOLUTE)

get_target_property(sources ${_target} SOURCES)
Expand All @@ -115,28 +115,29 @@ function(add_precompiled_header _target _input)
set(_pch "${_pch_c_pch}")
endif()

get_filename_component(_source_abs ${_source} ABSOLUTE)
get_filename_component(_source_dir ${_source_abs} DIRECTORY)
file(RELATIVE_PATH _input_rel ${_source_dir} ${_input_abs})

if(_source STREQUAL "${_PCH_SOURCE_CXX}")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yc${_input}\"")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yc${_input_rel}\"")
set(_pch_source_cxx_found TRUE)
set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_cxx_pch}")
elseif(_source STREQUAL "${_PCH_SOURCE_C}")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yc${_input}\"")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yc${_input_rel}\"")
set(_pch_source_c_found TRUE)
set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_c_pch}")
else()
if(_source MATCHES \\.\(cpp|cxx|cc\)$)
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yu${_input}\"")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yu${_input_rel}\"")
set(_pch_source_cxx_needed TRUE)
set_source_files_properties("${_source}" PROPERTIES OBJECT_DEPENDS "${_pch_cxx_pch}")
else()
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yu${_input}\"")
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yu${_input_rel}\"")
set(_pch_source_c_needed TRUE)
set_source_files_properties("${_source}" PROPERTIES OBJECT_DEPENDS "${_pch_c_pch}")
endif()
if(_PCH_FORCEINCLUDE)
get_filename_component(_source_abs ${_source} ABSOLUTE)
get_filename_component(_source_dir ${_source_abs} DIRECTORY)
file(RELATIVE_PATH _input_rel ${_source_dir} ${_input_abs})
set(_pch_compile_flags "${_pch_compile_flags} \"/FI${_input_rel}\"")
endif(_PCH_FORCEINCLUDE)
endif()
Expand Down

0 comments on commit 0f0b49b

Please sign in to comment.