Debian Codegraph @

third_party/spirv-tools/external/CMakeLists.txt

raw
1 # Copyright (c) 2015-2016 The Khronos Group Inc.
2 #
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Utility functions for pushing & popping variables.
17 function(push_variable var val)
18 set("${var}_SAVE_STACK" "${${var}}" "${${var}_SAVE_STACK}" PARENT_SCOPE)
19 set(${var} ${val} PARENT_SCOPE)
20 endfunction()
21 function(pop_variable var)
22 set(save_stack "${${var}_SAVE_STACK}")
23 list(GET save_stack 0 val)
24 list(REMOVE_AT save_stack 0)
25 set("${var}_SAVE_STACK" "${save_stack}" PARENT_SCOPE)
26 set(${var} ${val} PARENT_SCOPE)
27 endfunction()
28
29 if (DEFINED SPIRV-Headers_SOURCE_DIR)
30 # This allows flexible position of the SPIRV-Headers repo.
31 set(SPIRV_HEADER_DIR ${SPIRV-Headers_SOURCE_DIR})
32 else()
33 if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers)
34 set(SPIRV_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers)
35 else()
36 set(SPIRV_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers)
37 endif()
38 endif()
39
40 if (IS_DIRECTORY ${SPIRV_HEADER_DIR})
41 # TODO(dneto): We should not be modifying the parent scope.
42 set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV_HEADER_DIR}/include PARENT_SCOPE)
43
44 # Add SPIRV-Headers as a sub-project if it isn't already defined.
45 # Do this so enclosing projects can use SPIRV-Headers_SOURCE_DIR to find
46 # headers to include.
47 if (NOT DEFINED SPIRV-Headers_SOURCE_DIR)
48 # Filament specific changes
49 #set(SPIRV_HEADERS_SKIP_INSTALL ON)
50 #set(SPIRV_HEADERS_SKIP_EXAMPLES ON)
51 # End Filament specific changes
52 add_subdirectory(${SPIRV_HEADER_DIR})
53 endif()
54 else()
55 message(FATAL_ERROR
56 "SPIRV-Headers was not found - please checkout a copy under external/.")
57 endif()
58
59 if (NOT ${SPIRV_SKIP_TESTS})
60 # Find gmock if we can. If it's not already configured, then try finding
61 # it in external/googletest.
62 if (TARGET gmock)
63 message(STATUS "Google Mock already configured")
64 else()
65 set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
66 if(EXISTS ${GMOCK_DIR})
67 if(MSVC)
68 # Our tests use ::testing::Combine. Work around a compiler
69 # detection problem in googletest, where that template is
70 # accidentally disabled for VS 2017.
71 # See https://github.com/google/googletest/issues/1352
72 add_definitions(-DGTEST_HAS_COMBINE=1)
73 endif()
74 if(WIN32)
75 option(gtest_force_shared_crt
76 "Use shared (DLL) run-time lib even when Google Test is built as static lib."
77 ON)
78 endif()
79 # gtest requires special defines for building as a shared
80 # library, simply always build as static.
81 push_variable(BUILD_SHARED_LIBS 0)
82 add_subdirectory(${GMOCK_DIR} EXCLUDE_FROM_ALL)
83 pop_variable(BUILD_SHARED_LIBS)
84 endif()
85 endif()
86 if (TARGET gmock)
87 set(GTEST_TARGETS
88 gtest
89 gtest_main
90 gmock
91 gmock_main
92 )
93 foreach(target ${GTEST_TARGETS})
94 set_property(TARGET ${target} PROPERTY FOLDER GoogleTest)
95 endforeach()
96 endif()
97
98 # Find Effcee and RE2, for testing.
99
100 # First find RE2, since Effcee depends on it.
101 # If already configured, then use that. Otherwise, prefer to find it under 're2'
102 # in this directory.
103 if (NOT TARGET re2)
104 # If we are configuring RE2, then turn off its testing. It takes a long time and
105 # does not add much value for us. If an enclosing project configured RE2, then it
106 # has already chosen whether to enable RE2 testing.
107 set(RE2_BUILD_TESTING OFF CACHE STRING "Run RE2 Tests")
108 if (NOT RE2_SOURCE_DIR)
109 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/re2)
110 set(RE2_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/re2" CACHE STRING "RE2 source dir" )
111 endif()
112 endif()
113 endif()
114
115 if (NOT TARGET effcee)
116 # Expect to find effcee in this directory.
117 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/effcee)
118 # If we're configuring RE2 (via Effcee), then turn off RE2 testing.
119 if (NOT TARGET re2)
120 set(RE2_BUILD_TESTING OFF)
121 endif()
122 if (MSVC)
123 # SPIRV-Tools uses the shared CRT with MSVC. Tell Effcee to do the same.
124 set(EFFCEE_ENABLE_SHARED_CRT ON)
125 endif()
126 set(EFFCEE_BUILD_SAMPLES OFF CACHE BOOL "Do not build Effcee examples")
127 if (NOT TARGET effcee)
128 set(EFFCEE_BUILD_TESTING OFF CACHE BOOL "Do not build Effcee test suite")
129 endif()
130 push_variable(BUILD_SHARED_LIBS 0) # effcee does not export any symbols for building as a DLL. Always build as static.
131 add_subdirectory(effcee EXCLUDE_FROM_ALL)
132 pop_variable(BUILD_SHARED_LIBS)
133 set_property(TARGET effcee PROPERTY FOLDER Effcee)
134 # Turn off warnings for effcee and re2
135 set_property(TARGET effcee APPEND PROPERTY COMPILE_OPTIONS -w)
136 set_property(TARGET re2 APPEND PROPERTY COMPILE_OPTIONS -w)
137 endif()
138 endif()
139 endif()
140
141 if(SPIRV_BUILD_FUZZER)
142
143 function(backup_compile_options)
144 get_property(
145 SPIRV_TOOLS_BACKUP_EXTERNAL_COMPILE_OPTIONS
146 DIRECTORY
147 PROPERTY COMPILE_OPTIONS
148 )
149 endfunction()
150
151 function(restore_compile_options)
152 set_property(
153 DIRECTORY
154 PROPERTY COMPILE_OPTIONS
155 ${SPIRV_TOOLS_BACKUP_EXTERNAL_COMPILE_OPTIONS}
156 )
157 endfunction()
158
159 if(NOT TARGET protobuf::libprotobuf OR NOT TARGET protobuf::protoc)
160
161 set(SPIRV_TOOLS_PROTOBUF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/protobuf/cmake)
162 if (NOT IS_DIRECTORY ${SPIRV_TOOLS_PROTOBUF_DIR})
163 message(
164 FATAL_ERROR
165 "protobuf not found - please checkout a copy under external/.")
166 endif()
167 set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disable protobuf tests")
168 set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Do not build protobuf static runtime")
169
170 backup_compile_options()
171
172 if (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
173 add_compile_options(-Wno-inconsistent-missing-override)
174 endif()
175
176 add_subdirectory(${SPIRV_TOOLS_PROTOBUF_DIR} EXCLUDE_FROM_ALL)
177
178 restore_compile_options()
179
180 endif()
181 endif()