Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pch files in subdirs in VS and GNU #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions PrecompiledHeader.cmake
Expand Up @@ -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}")
Expand Down Expand Up @@ -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")
Expand Down