Skip to content

Commit

Permalink
Merge pull request #2327 from ben-clayton/fix-pch
Browse files Browse the repository at this point in the history
Use CMake's builtin functionality for pre-compiled headers
  • Loading branch information
johnkslang authored Jul 9, 2020
2 parents 29c9135 + 31cad22 commit 5aaa0c2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 121 deletions.
2 changes: 0 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ cc_library(
"glslang/MachineIndependent/preprocessor/*.cpp",
],
exclude = [
"glslang/HLSL/pch.cpp",
"glslang/HLSL/pch.h",
"glslang/MachineIndependent/pch.cpp",
"glslang/MachineIndependent/pch.h",
],
) + [
Expand Down
25 changes: 13 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ if(USE_CCACHE)
endif(CCACHE_FOUND)
endif()

# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
macro(glslang_pch SRCS PCHCPP)
if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH)
set(PCH_NAME "$(IntDir)\\pch.pch")
# make source files use/depend on PCH_NAME
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
# make PCHCPP file compile and generate PCH_NAME
set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
list(APPEND ${SRCS} "${PCHCPP}")
endif()
endmacro(glslang_pch)

project(glslang)

if(ENABLE_CTEST)
Expand Down Expand Up @@ -255,6 +243,19 @@ function(glslang_only_export_explicit_symbols target)
endif()
endfunction()

# glslang_pch() adds precompiled header rules to <target> for the pre-compiled
# header file <pch>. As target_precompile_headers() was added in CMake 3.16,
# this is a no-op if called on earlier versions of CMake.
if(NOT CMAKE_VERSION VERSION_LESS "3.16")
function(glslang_pch target pch)
target_precompile_headers(${target} PRIVATE ${pch})
endfunction()
else()
function(glslang_pch target pch)
endfunction()
message(NOTICE "Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds")
endif()

if(NOT TARGET SPIRV-Tools-opt)
set(ENABLE_OPT OFF)
endif()
Expand Down
2 changes: 1 addition & 1 deletion glslang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ endif(ENABLE_HLSL)
add_library(MachineIndependent STATIC ${MACHINEINDEPENDENT_SOURCES} ${MACHINEINDEPENDENT_HEADERS})
set_property(TARGET MachineIndependent PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET MachineIndependent PROPERTY FOLDER glslang)
glslang_pch(SOURCES MachineIndependent/pch.cpp)
glslang_pch(MachineIndependent MachineIndependent/pch.h)

target_link_libraries(MachineIndependent PRIVATE OGLCompiler OSDependent GenericCodeGen)

Expand Down
35 changes: 0 additions & 35 deletions glslang/HLSL/pch.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions glslang/MachineIndependent/pch.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion gtests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ if(BUILD_TESTING)
${CMAKE_CURRENT_SOURCE_DIR}/Remap.FromFile.cpp)
endif()

glslang_pch(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp)

add_executable(glslangtests ${TEST_SOURCES})
glslang_pch(glslangtests ${CMAKE_CURRENT_SOURCE_DIR}/pch.h)
set_property(TARGET glslangtests PROPERTY FOLDER tests)
glslang_set_link_args(glslangtests)
if(ENABLE_GLSLANG_INSTALL)
Expand Down
35 changes: 0 additions & 35 deletions gtests/pch.cpp

This file was deleted.

0 comments on commit 5aaa0c2

Please sign in to comment.