Skip to content

Instantly share code, notes, and snippets.

@devhawk
Last active October 25, 2018 22:21
Show Gist options
  • Select an option

  • Save devhawk/f393e6d21f350c03954391b1531f9e37 to your computer and use it in GitHub Desktop.

Select an option

Save devhawk/f393e6d21f350c03954391b1531f9e37 to your computer and use it in GitHub Desktop.
cmake function to configure MSVC precompiled header support
function(TARGET_CONFIG_MSVC_PCH target pch_cpp pch_header)
set(pch_output_file "\"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pch\"")
get_target_property(sources ${target} SOURCES)
foreach(file ${sources})
if (${file} STREQUAL ${pch_cpp})
set_source_files_properties(${file}
PROPERTIES
COMPILE_FLAGS " /Yc${pch_header} /Fp${pch_output_file}"
OBJECT_OUTPUTS ${PROJECT_NAME}.pch)
else()
set_source_files_properties(${file}
PROPERTIES
COMPILE_FLAGS " /Yu${pch_header} /Fp${pch_output_file}"
OBJECT_DEPENDS ${PROJECT_NAME}.pch)
endif()
endforeach()
set_target_properties(${target} PROPERTIES PCH_OUTPUT_FILE ${pch_output_file})
set_property(GLOBAL APPEND PROPERTY PCH_OUTPUT_FILES ${pch_output_file})
endfunction(TARGET_CONFIG_MSVC_PCH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment