Skip to content

Instantly share code, notes, and snippets.

@kbinani
Created November 21, 2016 01:58
Show Gist options
  • Save kbinani/3e55feb6e4615d3624af90c5eaf57c33 to your computer and use it in GitHub Desktop.
Save kbinani/3e55feb6e4615d3624af90c5eaf57c33 to your computer and use it in GitHub Desktop.
macro(add_msvc_precompiled_header PrecompiledHeader PrecompiledSource SourcesVar)
if(MSVC)
get_filename_component(PrecompiledBasename ${PrecompiledHeader} NAME_WE)
set(PrecompiledBinary "$(IntDir)/${PrecompiledBasename}.pch")
set(Sources ${${SourcesVar}})
set_source_files_properties(${PrecompiledSource}
PROPERTIES COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_OUTPUTS "${PrecompiledBinary}")
set_source_files_properties(${Sources}
PROPERTIES COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /FI\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_DEPENDS "${PrecompiledBinary}")
list(APPEND ${SourcesVar} ${PrecompiledSource})
list(APPEND ${SourcesVar} ${PrecompiledHeader})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FI\"${PrecompiledHeader}\"")
endif()
endmacro(add_msvc_precompiled_header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment