Skip to content

Commit 0f0b49b

Browse files
committed
PrecompiledHeader.cmake: fix building pch for sources outside current dir
1 parent d1b44d1 commit 0f0b49b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

PrecompiledHeader.cmake

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ function(add_precompiled_header _target _input)
9393

9494
if(MSVC)
9595

96-
set(_cxx_path "$<CONFIG>/${_target}_cxx_pch")
97-
set(_c_path "$<CONFIG>/${_target}_c_pch")
96+
set(_cxx_path "${_target}_cxx_pch")
97+
set(_c_path "${_target}_c_pch")
9898
file(MAKE_DIRECTORY "${_cxx_path}")
9999
file(MAKE_DIRECTORY "${_c_path}")
100100
set(_pch_cxx_header "${_cxx_path}/${_input}")
101-
set(_pch_cxx_pch "${_cxx_path}/${_input_we}.pch")
101+
set(_pch_cxx_pch "${_cxx_path}/${_input_we}-$<CONFIG>.pch")
102102
set(_pch_c_header "${_c_path}/${_input}")
103-
set(_pch_c_pch "${_c_path}/${_input_we}.pch")
103+
set(_pch_c_pch "${_c_path}/${_input_we}-$<CONFIG>.pch")
104104
get_filename_component(_input_abs ${_input} ABSOLUTE)
105105

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

118+
get_filename_component(_source_abs ${_source} ABSOLUTE)
119+
get_filename_component(_source_dir ${_source_abs} DIRECTORY)
120+
file(RELATIVE_PATH _input_rel ${_source_dir} ${_input_abs})
121+
118122
if(_source STREQUAL "${_PCH_SOURCE_CXX}")
119-
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yc${_input}\"")
123+
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yc${_input_rel}\"")
120124
set(_pch_source_cxx_found TRUE)
121125
set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_cxx_pch}")
122126
elseif(_source STREQUAL "${_PCH_SOURCE_C}")
123-
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yc${_input}\"")
127+
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yc${_input_rel}\"")
124128
set(_pch_source_c_found TRUE)
125129
set_source_files_properties("${_source}" PROPERTIES OBJECT_OUTPUTS "${_pch_c_pch}")
126130
else()
127131
if(_source MATCHES \\.\(cpp|cxx|cc\)$)
128-
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yu${_input}\"")
132+
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" \"/Yu${_input_rel}\"")
129133
set(_pch_source_cxx_needed TRUE)
130134
set_source_files_properties("${_source}" PROPERTIES OBJECT_DEPENDS "${_pch_cxx_pch}")
131135
else()
132-
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yu${_input}\"")
136+
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" \"/Yu${_input_rel}\"")
133137
set(_pch_source_c_needed TRUE)
134138
set_source_files_properties("${_source}" PROPERTIES OBJECT_DEPENDS "${_pch_c_pch}")
135139
endif()
136140
if(_PCH_FORCEINCLUDE)
137-
get_filename_component(_source_abs ${_source} ABSOLUTE)
138-
get_filename_component(_source_dir ${_source_abs} DIRECTORY)
139-
file(RELATIVE_PATH _input_rel ${_source_dir} ${_input_abs})
140141
set(_pch_compile_flags "${_pch_compile_flags} \"/FI${_input_rel}\"")
141142
endif(_PCH_FORCEINCLUDE)
142143
endif()

0 commit comments

Comments
 (0)