Skip to content

Commit

Permalink
Use CMake's builtin functionality for PCHs
Browse files Browse the repository at this point in the history
`glslang_pch()` did manual mangling of the compiler flags to enable pre-compiled headers.
I couldn't get this approach to work with the `MachineIndependent` subdirectory, but fortunately CMake has added first-class support for precompiled headers in 3.16, which does work with subdirectories.

Moved `glslang_pch()` to the other global function declarations.

`glslang_pch()` is a no-op when using CMake earlier than `3.16`.

CMake's PCH implementation does not need the `pch.cpp` files, so just remove them.
  • Loading branch information
ben-clayton committed Jul 7, 2020
1 parent 3604be1 commit 3a5e523
Show file tree
Hide file tree
Showing 7 changed files with 11 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
21 changes: 9 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,15 @@ 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.
function(glslang_pch target pch)
if(NOT CMAKE_VERSION VERSION_LESS "3.16")
target_precompile_headers(${target} PRIVATE ${pch})
endif()
endfunction(glslang_pch)

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 3a5e523

Please sign in to comment.