Enable precompiled headers for spirv-tools(-shared) and some unit tests (#2026)

This commit is contained in:
Jeff Bolz 2018-11-06 08:26:23 -06:00 committed by Steven Perron
parent f2cc71e5cb
commit 60fac96c6b
19 changed files with 214 additions and 15 deletions

View File

@ -212,6 +212,18 @@ if (${SPIRV_CHECK_CONTEXT})
add_definitions(-DSPIRV_CHECK_CONTEXT) add_definitions(-DSPIRV_CHECK_CONTEXT)
endif() endif()
# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
macro(PCH SRCS PCHPREFIX)
if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio")
set(PCH_NAME "$(IntDir)\\${PCHPREFIX}.pch")
# make source files use/depend on PCH_NAME
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yu${PCHPREFIX}.h /FI${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
# make PCHPREFIX.cpp file compile and generate PCH_NAME
set_source_files_properties("${PCHPREFIX}.cpp" PROPERTIES COMPILE_FLAGS "/Yc${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
list(APPEND ${SRCS} "${PCHPREFIX}.cpp")
endif()
endmacro(PCH)
add_subdirectory(external) add_subdirectory(external)
add_subdirectory(source) add_subdirectory(source)

View File

@ -184,10 +184,10 @@ set_source_files_properties(
PROPERTIES OBJECT_DEPENDS "${ENUM_STRING_MAPPING_CPP_DEPENDS}") PROPERTIES OBJECT_DEPENDS "${ENUM_STRING_MAPPING_CPP_DEPENDS}")
set_source_files_properties( set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/extension.h ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
PROPERTIES HEADER_FILE_ONLY TRUE) PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties( set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/extension.h ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
PROPERTIES OBJECT_DEPENDS "${EXTENSION_H_DEPENDS}") PROPERTIES OBJECT_DEPENDS "${EXTENSION_H_DEPENDS}")
set(SPIRV_TOOLS_BUILD_VERSION_INC set(SPIRV_TOOLS_BUILD_VERSION_INC
@ -209,6 +209,11 @@ add_custom_target(spirv-tools-build-version
DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC}) DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC})
set_property(TARGET spirv-tools-build-version PROPERTY FOLDER "SPIRV-Tools build") set_property(TARGET spirv-tools-build-version PROPERTY FOLDER "SPIRV-Tools build")
list(APPEND PCH_DEPENDS ${ENUM_STRING_MAPPING_CPP_DEPENDS} ${OPCODE_CPP_DEPENDS} ${OPERAND_CPP_DEPENDS} ${EXTENSION_H_DEPENDS} ${EXTINST_CPP_DEPENDS} ${SPIRV_TOOLS_BUILD_VERSION_INC})
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/pch_source.cpp
PROPERTIES OBJECT_DEPENDS "${PCH_DEPENDS}")
add_subdirectory(comp) add_subdirectory(comp)
add_subdirectory(opt) add_subdirectory(opt)
add_subdirectory(link) add_subdirectory(link)
@ -340,6 +345,8 @@ set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp
PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}") PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}")
PCH(SPIRV_SOURCES pch_source)
add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES}) add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES})
spvtools_default_compile_options(${SPIRV_TOOLS}) spvtools_default_compile_options(${SPIRV_TOOLS})
target_include_directories(${SPIRV_TOOLS} target_include_directories(${SPIRV_TOOLS}

View File

@ -188,18 +188,10 @@ set(SPIRV_TOOLS_OPT_SOURCES
if(MSVC) if(MSVC)
# Enable parallel builds across four cores for this lib # Enable parallel builds across four cores for this lib
add_definitions(/MP4) add_definitions(/MP4)
# Enable precompiled header
if (CMAKE_GENERATOR MATCHES "^Visual Studio")
set(PCH_NAME "$(IntDir)\\pch.pch")
else()
set(PCH_NAME "pch.pch")
endif()
set_source_files_properties(${SPIRV_TOOLS_OPT_SOURCES} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
set_source_files_properties(pch.cpp PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
list(APPEND SPIRV_TOOLS_OPT_SOURCES "pch.cpp")
endif() endif()
PCH(SPIRV_TOOLS_OPT_SOURCES pch_source_opt)
add_library(SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SOURCES}) add_library(SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SOURCES})
spvtools_default_compile_options(SPIRV-Tools-opt) spvtools_default_compile_options(SPIRV-Tools-opt)

View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "pch_source_opt.h"

15
source/pch_source.cpp Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "pch_source.h"

15
source/pch_source.h Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "source/val/validation_state.h"

View File

@ -30,12 +30,16 @@ endif()
function(add_spvtools_unittest) function(add_spvtools_unittest)
if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main) if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main)
set(one_value_args TARGET) set(one_value_args TARGET PCH_FILE)
set(multi_value_args SRCS LIBS ENVIRONMENT) set(multi_value_args SRCS LIBS ENVIRONMENT)
cmake_parse_arguments( cmake_parse_arguments(
ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN}) ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
set(target test_${ARG_TARGET}) set(target test_${ARG_TARGET})
add_executable(${target} ${ARG_SRCS}) set(SRC_COPY ${ARG_SRCS})
if (DEFINED ARG_PCH_FILE)
PCH(SRC_COPY ${ARG_PCH_FILE})
endif()
add_executable(${target} ${SRC_COPY})
spvtools_default_compile_options(${target}) spvtools_default_compile_options(${target})
if(${COMPILER_IS_LIKE_GNU}) if(${COMPILER_IS_LIKE_GNU})
target_compile_options(${target} PRIVATE -Wno-undef) target_compile_options(${target} PRIVATE -Wno-undef)
@ -147,6 +151,8 @@ set(TEST_SOURCES
unit_spirv.cpp unit_spirv.cpp
) )
PCH(TEST_SOURCES pch_test)
add_spvtools_unittest( add_spvtools_unittest(
TARGET spirv_unit_tests TARGET spirv_unit_tests
SRCS ${TEST_SOURCES} SRCS ${TEST_SOURCES}

View File

@ -27,4 +27,5 @@ add_spvtools_unittest(TARGET dominator_analysis
unreachable_for.cpp unreachable_for.cpp
unreachable_for_post.cpp unreachable_for_post.cpp
LIBS SPIRV-Tools-opt LIBS SPIRV-Tools-opt
PCH_FILE pch_test_opt_dom
) )

View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "pch_test_opt_dom.h"

View File

@ -0,0 +1,25 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "gmock/gmock.h"
#include "source/opt/iterator.h"
#include "source/opt/loop_dependence.h"
#include "source/opt/loop_descriptor.h"
#include "source/opt/pass.h"
#include "source/opt/scalar_analysis.h"
#include "source/opt/tree_iterator.h"
#include "test/opt/assembly_builder.h"
#include "test/opt/function_utils.h"
#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"

View File

@ -37,4 +37,5 @@ add_spvtools_unittest(TARGET opt_loops
unroll_simple.cpp unroll_simple.cpp
unswitch.cpp unswitch.cpp
LIBS SPIRV-Tools-opt LIBS SPIRV-Tools-opt
PCH_FILE pch_test_opt_loop
) )

View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "pch_test_opt_loop.h"

View File

@ -0,0 +1,25 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "gmock/gmock.h"
#include "source/opt/iterator.h"
#include "source/opt/loop_dependence.h"
#include "source/opt/loop_descriptor.h"
#include "source/opt/pass.h"
#include "source/opt/scalar_analysis.h"
#include "source/opt/tree_iterator.h"
#include "test/opt/assembly_builder.h"
#include "test/opt/function_utils.h"
#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"

View File

@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "pch.h" #include "pch_test.h"

18
test/pch_test.h Normal file
View File

@ -0,0 +1,18 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "gmock/gmock.h"
#include "source/spirv_constant.h"
#include "test/test_fixture.h"
#include "test/unit_spirv.h"

View File

@ -38,6 +38,7 @@ add_spvtools_unittest(TARGET val_abcde
val_ext_inst_test.cpp val_ext_inst_test.cpp
${VAL_TEST_COMMON_SRCS} ${VAL_TEST_COMMON_SRCS}
LIBS ${SPIRV_TOOLS} LIBS ${SPIRV_TOOLS}
PCH_FILE pch_test_val
) )
add_spvtools_unittest(TARGET val_limits add_spvtools_unittest(TARGET val_limits
@ -59,6 +60,7 @@ add_spvtools_unittest(TARGET val_ijklmnop
val_primitives_test.cpp val_primitives_test.cpp
${VAL_TEST_COMMON_SRCS} ${VAL_TEST_COMMON_SRCS}
LIBS ${SPIRV_TOOLS} LIBS ${SPIRV_TOOLS}
PCH_FILE pch_test_val
) )
add_spvtools_unittest(TARGET val_stuvw add_spvtools_unittest(TARGET val_stuvw
@ -72,4 +74,5 @@ add_spvtools_unittest(TARGET val_stuvw
val_webgpu_test.cpp val_webgpu_test.cpp
${VAL_TEST_COMMON_SRCS} ${VAL_TEST_COMMON_SRCS}
LIBS ${SPIRV_TOOLS} LIBS ${SPIRV_TOOLS}
PCH_FILE pch_test_val
) )

15
test/val/pch_test_val.cpp Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "pch_test_val.h"

19
test/val/pch_test_val.h Normal file
View File

@ -0,0 +1,19 @@
// Copyright (c) 2018 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string>
#include "gmock/gmock.h"
#include "test/unit_spirv.h"
#include "test/val/val_fixtures.h"