diff --git a/PrecompiledHeader.cmake b/PrecompiledHeader.cmake index 1e578d2..9449ffa 100644 --- a/PrecompiledHeader.cmake +++ b/PrecompiledHeader.cmake @@ -102,11 +102,11 @@ function(add_precompiled_header _target _input) set(_pch "${_pch_c_pch}") endif() - if(_source STREQUAL "${_PCH_SOURCE_CXX}") + if(_source STREQUAL "${_PCH_SOURCE_CXX}" OR _source MATCHES "^.*[\/]${_PCH_SOURCE_CXX}$") set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yc${_input}\"") set(_pch_source_cxx_found TRUE) set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_cxx_pch}") - elseif(_source STREQUAL "${_PCH_SOURCE_C}") + elseif(_source STREQUAL "${_PCH_SOURCE_C}" OR _source MATCHES "^.*[\/]${_PCH_SOURCE_C}$") set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yc${_input}\"") set(_pch_source_c_found TRUE) set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_c_pch}") @@ -149,7 +149,21 @@ function(add_precompiled_header _target _input) if(CMAKE_COMPILER_IS_GNUCXX) get_filename_component(_name ${_input} NAME) - set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") + + #find pch header + get_target_property(sources ${_target} SOURCES) + foreach(_source ${sources}) + if(_source MATCHES "^.*[\/]${_input}$") + set(_PCH_HEADER_WITH_PATH ${_source}) + endif() + endforeach() + + if(_PCH_HEADER_WITH_PATH) + set(_pch_header "${_PCH_HEADER_WITH_PATH}") + else() + set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") + endif() + set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch") set(_pchfile "${_pch_binary_dir}/${_input}") set(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch/${_name}.gch")