• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15cmake_minimum_required(VERSION 3.13)
16
17project(SwiftShader C CXX ASM)
18
19set(CMAKE_CXX_STANDARD 17)
20set(CXX_STANDARD_REQUIRED ON)
21# MSVC doesn't define __cplusplus by default
22if(MSVC)
23    string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
24endif()
25
26###########################################################
27# Detect system
28###########################################################
29
30if(CMAKE_SYSTEM_NAME MATCHES "Linux")
31    set(LINUX TRUE)
32elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
33    set(ANDROID TRUE)
34    set(CMAKE_CXX_FLAGS "-DANDROID_NDK_BUILD")
35elseif(WIN32)
36elseif(APPLE)
37elseif(FUCHSIA)
38    # NOTE: Building for Fuchsia requires a Fuchsia CMake-based SDK.
39    # See https://fuchsia-review.googlesource.com/c/fuchsia/+/379673
40    find_package(FuchsiaLibraries)
41else()
42    message(FATAL_ERROR "Platform is not supported")
43endif()
44
45if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch")
46    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
47        set(ARCH "aarch64")
48    else()
49        set(ARCH "arm")
50    endif()
51elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips*")
52    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
53        set(ARCH "mips64el")
54    else()
55        set(ARCH "mipsel")
56    endif()
57elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc*")
58    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
59        set(ARCH "ppc64le")
60    else()
61        message(FATAL_ERROR "Architecture is not supported")
62    endif()
63else()
64    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
65        set(ARCH "x86_64")
66    else()
67        set(ARCH "x86")
68    endif()
69endif()
70
71# Cross compiling on macOS. The cross compiling architecture should override
72# auto-detected system architecture settings.
73if(CMAKE_OSX_ARCHITECTURES)
74    if(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
75        set(ARCH "aarch64")
76    elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
77        set(ARCH "x86_64")
78    elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
79        set(ARCH "x86")
80    else()
81        message(FATAL_ERROR "Architecture ${CMAKE_OSX_ARCHITECTURES} is not "
82                            "supported. Only one architecture (arm64, x86_64 "
83                            "or i386) could be specified at build time.")
84    endif()
85endif()
86
87set(CMAKE_MACOSX_RPATH TRUE)
88
89if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
90  message(WARNING "Visual Studio generators use the x86 host compiler by "
91                  "default, even for 64-bit targets. This can result in linker "
92                  "instability and out of memory errors. To use the 64-bit "
93                  "host compiler, pass -Thost=x64 on the CMake command line.")
94endif()
95
96# Use CCache if available
97find_program(CCACHE_FOUND ccache)
98if(CCACHE_FOUND)
99    message(STATUS "Using ccache")
100    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
101    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
102endif()
103
104###########################################################
105# Host libraries
106###########################################################
107
108include(CheckSymbolExists)
109if(LINUX)
110    check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
111    check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
112endif()
113
114find_library(X11 X11)
115find_library(XCB xcb)
116if(SWIFTSHADER_BUILD_WSI_WAYLAND)
117    find_library(WAYLAND wayland-client)
118endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
119if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
120    find_library(DIRECTFB directfb)
121    find_path(DIRECTFB_INCLUDE_DIR directfb/directfb.h)
122endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
123if(SWIFTSHADER_BUILD_WSI_D2D)
124    find_library(D2D drm)
125    find_path(D2D_INCLUDE_DIR libdrm/drm.h)
126endif(SWIFTSHADER_BUILD_WSI_D2D)
127
128###########################################################
129# Options
130###########################################################
131
132if(NOT CMAKE_BUILD_TYPE)
133    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build: Debug Release MinSizeRel RelWithDebInfo." FORCE)
134    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
135endif()
136
137function (option_if_not_defined name description default)
138    if(NOT DEFINED ${name})
139        option(${name} ${description} ${default})
140    endif()
141endfunction()
142
143function (set_if_not_defined name value)
144    if(NOT DEFINED ${name})
145        set(${name} ${value} PARENT_SCOPE)
146    endif()
147endfunction()
148
149option_if_not_defined(SWIFTSHADER_BUILD_EGL "Build the EGL library" TRUE)
150option_if_not_defined(SWIFTSHADER_BUILD_GLESv2 "Build the OpenGL ES 2 library" TRUE)
151option_if_not_defined(SWIFTSHADER_BUILD_VULKAN "Build the Vulkan library" TRUE)
152option_if_not_defined(SWIFTSHADER_BUILD_WSI_WAYLAND "Build the Wayland WSI support" FALSE)
153option_if_not_defined(SWIFTSHADER_BUILD_WSI_DIRECTFB "Build the DirectFB WSI support" FALSE)
154option_if_not_defined(SWIFTSHADER_BUILD_WSI_D2D "Build the Direct-to-Display WSI support" FALSE)
155option_if_not_defined(SWIFTSHADER_BUILD_PVR "Build the PowerVR examples" TRUE)
156option_if_not_defined(SWIFTSHADER_GET_PVR "Check out the PowerVR submodule" FALSE)
157option_if_not_defined(SWIFTSHADER_BUILD_ANGLE "Build angle" FALSE)
158
159option_if_not_defined(SWIFTSHADER_USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Studio" TRUE)
160
161option_if_not_defined(SWIFTSHADER_BUILD_TESTS "Build unit tests" TRUE)
162option_if_not_defined(SWIFTSHADER_BUILD_BENCHMARKS "Build benchmarks" FALSE)
163
164option_if_not_defined(SWIFTSHADER_MSAN "Build with memory sanitizer" FALSE)
165option_if_not_defined(SWIFTSHADER_ASAN "Build with address sanitizer" FALSE)
166option_if_not_defined(SWIFTSHADER_TSAN "Build with thread sanitizer" FALSE)
167option_if_not_defined(SWIFTSHADER_UBSAN "Build with undefined behavior sanitizer" FALSE)
168option_if_not_defined(SWIFTSHADER_EMIT_COVERAGE "Emit code coverage information" FALSE)
169option_if_not_defined(SWIFTSHADER_WARNINGS_AS_ERRORS "Treat all warnings as errors" TRUE)
170option_if_not_defined(SWIFTSHADER_DCHECK_ALWAYS_ON "Check validation macros even in release builds" FALSE)
171option_if_not_defined(REACTOR_EMIT_DEBUG_INFO "Emit debug info for JIT functions" FALSE)
172option_if_not_defined(REACTOR_EMIT_PRINT_LOCATION "Emit printing of location info for JIT functions" FALSE)
173option_if_not_defined(REACTOR_EMIT_ASM_FILE "Emit asm files for JIT functions" FALSE)
174option_if_not_defined(REACTOR_ENABLE_PRINT "Enable RR_PRINT macros" FALSE)
175option_if_not_defined(REACTOR_VERIFY_LLVM_IR "Check reactor-generated LLVM IR is valid even in release builds" FALSE)
176# TODO(b/155148722): Remove when unconditionally instrumenting for all build systems.
177option_if_not_defined(REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION "Include JIT in MSAN instrumentation (LLVM backend)" TRUE)
178option_if_not_defined(SWIFTSHADER_LESS_DEBUG_INFO "Generate less debug info to reduce file size" FALSE)
179option_if_not_defined(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER "Enable Vulkan debugger support" FALSE)
180option_if_not_defined(SWIFTSHADER_ENABLE_ASTC "Enable ASTC compressed textures support" TRUE)  # TODO(b/150130101)
181
182set(BUILD_MARL ${SWIFTSHADER_BUILD_VULKAN})
183
184if(${SWIFTSHADER_BUILD_VULKAN} AND ${SWIFTSHADER_ENABLE_VULKAN_DEBUGGER})
185    set_if_not_defined(SWIFTSHADER_BUILD_CPPDAP TRUE)
186else()
187    set_if_not_defined(SWIFTSHADER_BUILD_CPPDAP FALSE)
188endif()
189
190set(DEFAULT_REACTOR_BACKEND "LLVM")
191set(REACTOR_BACKEND ${DEFAULT_REACTOR_BACKEND} CACHE STRING "JIT compiler back-end used by Reactor")
192set_property(CACHE REACTOR_BACKEND PROPERTY STRINGS LLVM Subzero)
193
194set(DEFAULT_SWIFTSHADER_LLVM_VERSION "10.0")
195set(SWIFTSHADER_LLVM_VERSION ${DEFAULT_SWIFTSHADER_LLVM_VERSION} CACHE STRING "LLVM version to use")
196set_property(CACHE SWIFTSHADER_LLVM_VERSION PROPERTY STRINGS "10.0")
197
198# If defined, overrides the default optimization level of the current reactor backend.
199# Set to one of the rr::Optimization::Level enum values.
200set(REACTOR_DEFAULT_OPT_LEVEL "" CACHE STRING "Reactor default optimization level")
201set_property(CACHE REACTOR_DEFAULT_OPT_LEVEL PROPERTY STRINGS "None" "Less" "Default" "Aggressive")
202
203if(NOT DEFINED SWIFTSHADER_LOGGING_LEVEL)
204    set(SWIFTSHADER_LOGGING_LEVEL "Info" CACHE STRING "SwiftShader logging level")
205    set_property(CACHE SWIFTSHADER_LOGGING_LEVEL PROPERTY STRINGS "Verbose" "Debug" "Info" "Warn" "Error" "Fatal" "Disabled")
206endif()
207
208# LLVM disallows calling cmake . from the main LLVM dir, the reason is that
209# it builds header files that could overwrite the orignal ones. Here we
210# want to include LLVM as a subdirectory and even though it wouldn't cause
211# the problem, if cmake . is called from the main dir, the condition that
212# LLVM checkes, "CMAKE_CURRENT_SOURCE_DIR == CMAKE_CURRENT_BINARY_DIR" will be true. So we
213# disallow it ourselves too to. In addition if there are remining CMakeFiles
214# and CMakeCache in the directory, cmake .. from a subdirectory will still
215# try to build from the main directory so we instruct users to delete these
216# files when they get the error.
217if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
218    message(FATAL_ERROR "In source builds are not allowed by LLVM, please create a build/ directory and build from there. You may have to delete the CMakeCache.txt file and CMakeFiles directory that are next to the CMakeLists.txt.")
219endif()
220
221set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
222
223###########################################################
224# Directories
225###########################################################
226
227set(SWIFTSHADER_DIR ${CMAKE_CURRENT_SOURCE_DIR})
228set(SOURCE_DIR ${SWIFTSHADER_DIR}/src)
229set(THIRD_PARTY_DIR ${SWIFTSHADER_DIR}/third_party)
230set(TESTS_DIR ${SWIFTSHADER_DIR}/tests)
231
232###########################################################
233# Initialize submodules
234###########################################################
235
236function(InitSubmodule target submodule_dir)
237    if (NOT TARGET ${target})
238        if(NOT EXISTS ${submodule_dir}/.git)
239            message(WARNING "
240        Target ${target} from submodule ${submodule_dir} missing.
241        Running 'git submodule update --init' to download it:
242            ")
243
244            execute_process(COMMAND git -C ${SWIFTSHADER_DIR} submodule update --init ${submodule_dir})
245        endif()
246    endif()
247endfunction()
248
249if (SWIFTSHADER_BUILD_TESTS OR SWIFTSHADER_BUILD_BENCHMARKS)
250    set(BUILD_VULKAN_WRAPPER TRUE)
251endif()
252
253if (BUILD_VULKAN_WRAPPER)
254    InitSubmodule(glslang ${THIRD_PARTY_DIR}/glslang)
255endif()
256
257if (SWIFTSHADER_BUILD_TESTS)
258    InitSubmodule(gtest ${THIRD_PARTY_DIR}/googletest)
259endif()
260
261if(SWIFTSHADER_BUILD_BENCHMARKS)
262    InitSubmodule(benchmark::benchmark ${THIRD_PARTY_DIR}/benchmark)
263endif()
264
265if(REACTOR_EMIT_DEBUG_INFO)
266    InitSubmodule(libbacktrace ${THIRD_PARTY_DIR}/libbacktrace/src)
267endif()
268
269if(SWIFTSHADER_GET_PVR)
270    InitSubmodule(PVRCore ${THIRD_PARTY_DIR}/PowerVR_Examples)
271    set(SWIFTSHADER_GET_PVR FALSE CACHE BOOL "Check out the PowerVR submodule" FORCE)
272endif()
273if(EXISTS ${THIRD_PARTY_DIR}/PowerVR_Examples/.git)
274    set(HAVE_PVR_SUBMODULE TRUE)
275endif()
276
277if(SWIFTSHADER_BUILD_CPPDAP)
278    InitSubmodule(json ${THIRD_PARTY_DIR}/json)
279    InitSubmodule(cppdap ${THIRD_PARTY_DIR}/cppdap)
280endif()
281
282if(SWIFTSHADER_BUILD_ANGLE)
283    InitSubmodule(angle ${THIRD_PARTY_DIR}/angle/angle)
284endif()
285
286###########################################################
287# Convenience macros
288###########################################################
289
290# Recursively calls source_group on the files of the directory
291# so that Visual Studio has the files in a folder tree
292macro(group_all_sources directory)
293    file(GLOB files RELATIVE ${SWIFTSHADER_DIR}/${directory} ${SWIFTSHADER_DIR}/${directory}/*)
294    foreach(file ${files})
295        if(IS_DIRECTORY ${SWIFTSHADER_DIR}/${directory}/${file})
296            group_all_sources(${directory}/${file})
297        else()
298            string(REPLACE "/" "\\" groupname ${directory})
299            source_group(${groupname} FILES ${SWIFTSHADER_DIR}/${directory}/${file})
300        endif()
301    endforeach()
302endmacro()
303
304# Takes target library and a directory where the export map is
305# and add the linker options so that only the API symbols are
306# exported.
307macro(set_shared_library_export_map TARGET DIR)
308    if(MSVC)
309        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " /DEF:\"${DIR}/${TARGET}.def\"")
310    elseif(APPLE)
311        # The exported symbols list only exports the API functions and
312        # hides all the others.
313        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-exported_symbols_list ${DIR}/${TARGET}.exports")
314        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${TARGET}.exports;")
315        # Don't allow undefined symbols, unless it's a Sanitizer build.
316        if(NOT SWIFTSHADER_MSAN AND NOT SWIFTSHADER_ASAN AND NOT SWIFTSHADER_TSAN AND NOT SWIFTSHADER_UBSAN)
317            set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-undefined,error")
318        endif()
319    elseif(LINUX OR FUCHSIA)
320        # NOTE: The Fuchsia linker script is needed to export the vk_icdInitializeConnectToServiceCallback
321        # entry point (a private implementation detail betwen the Fuchsia Vulkan loader and the ICD).
322        if ((FUCHSIA) AND ("${TARGET}" STREQUAL "vk_swiftshader"))
323          set(LINKER_VERSION_SCRIPT "fuchsia_vk_swiftshader.lds")
324        else()
325          set(LINKER_VERSION_SCRIPT "${TARGET}.lds")
326        endif()
327
328        # The version script only exports the API functions and
329        # hides all the others.
330        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=${DIR}/${LINKER_VERSION_SCRIPT}")
331        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${LINKER_VERSION_SCRIPT};")
332
333        # -Bsymbolic binds symbol references to their global definitions within
334        # a shared object, thereby preventing symbol preemption.
335        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS "  -Wl,-Bsymbolic")
336
337        if(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el")
338          # MIPS supports sysv hash-style only.
339          set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--hash-style=sysv")
340        elseif(LINUX)
341          # Both hash-style are needed, because we want both gold and
342          # GNU ld to be able to read our libraries.
343          set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--hash-style=both")
344        endif()
345
346        if(NOT ${SWIFTSHADER_EMIT_COVERAGE})
347            # Gc sections is used in combination with each functions being
348            # in its own section, to reduce the binary size.
349            set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections")
350        endif()
351
352        # Don't allow undefined symbols, unless it's a Sanitizer build.
353        if(NOT SWIFTSHADER_MSAN AND NOT SWIFTSHADER_ASAN AND NOT SWIFTSHADER_TSAN AND NOT SWIFTSHADER_UBSAN)
354            set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined")
355        endif()
356    endif()
357endmacro()
358
359if(SWIFTSHADER_USE_GROUP_SOURCES)
360    group_all_sources(src)
361endif()
362
363###########################################################
364# Compile flags
365###########################################################
366
367# Flags for project code (non 3rd party)
368set(SWIFTSHADER_COMPILE_OPTIONS "")
369set(SWIFTSHADER_LINK_FLAGS "")
370set(SWIFTSHADER_LIBS "")
371
372macro(set_cpp_flag FLAG)
373    if(${ARGC} GREATER 1)
374        set(CMAKE_CXX_FLAGS_${ARGV1} "${CMAKE_CXX_FLAGS_${ARGV1}} ${FLAG}")
375    else()
376        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
377    endif()
378endmacro()
379
380macro(set_linker_flag FLAG)
381    if(${ARGC} GREATER 1)
382        set(CMAKE_EXE_LINKER_FLAGS_${ARGV1} "${CMAKE_EXE_LINKER_FLAGS_${ARGV1}} ${FLAG}")
383        set(CMAKE_SHARED_LINKER_FLAGS_${ARGV1} "${CMAKE_EXE_LINKER_FLAGS_${ARGV1}} ${FLAG}")
384    else()
385        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
386        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
387    endif()
388endmacro()
389
390if(MSVC)
391    set_cpp_flag("/MP")
392    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
393    add_definitions(-D_SCL_SECURE_NO_WARNINGS)
394    add_definitions(-D_SBCS)  # Single Byte Character Set (ASCII)
395    add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)  # Disable MSVC warnings about std::aligned_storage being broken before VS 2017 15.8
396
397    set_linker_flag("/DEBUG:FASTLINK" DEBUG)
398    set_linker_flag("/DEBUG:FASTLINK" RELWITHDEBINFO)
399
400    # Disable specific warnings
401    # TODO: Not all of these should be disabled, but for now, we want a warning-free msvc build. Remove these one by one
402    #       and fix the actual warnings in code.
403    list(APPEND SWIFTSHADER_COMPILE_OPTIONS
404        "/wd4005" # 'identifier' : macro redefinition
405        "/wd4018" # 'expression' : signed/unsigned mismatch
406        "/wd4065" # switch statement contains 'default' but no 'case' labels
407        "/wd4141" # 'modifier' : used more than once
408        "/wd4244" # 'conversion' conversion from 'type1' to 'type2', possible loss of data
409        "/wd4267" # 'var' : conversion from 'size_t' to 'type', possible loss of data
410        "/wd4291" # 'void X new(size_t,unsigned int,unsigned int)': no matching operator delete found; memory will not be freed if initialization throws an exception
411        "/wd4309" # 'conversion' : truncation of constant value
412        "/wd4624" # 'derived class' : destructor was implicitly defined as deleted because a base class destructor is inaccessible or deleted
413        "/wd4800" # 'type' : forcing value to bool 'true' or 'false' (performance warning)
414        "/wd4838" # conversion from 'type_1' to 'type_2' requires a narrowing conversion
415        "/wd5030" # attribute 'attribute' is not recognized
416        "/wd5038" # data member 'member1' will be initialized after data member 'member2' data member 'member' will be initialized after base class 'base_class'
417    )
418
419    # Treat specific warnings as errors
420    list(APPEND SWIFTSHADER_COMPILE_OPTIONS
421        "/we4018" # 'expression' : signed/unsigned mismatch
422        "/we4062" # enumerator 'identifier' in switch of enum 'enumeration' is not handled
423        "/we4471" # 'enumeration': a forward declaration of an unscoped enumeration must have an underlying type (int assumed)
424        "/we4838" # conversion from 'type_1' to 'type_2' requires a narrowing conversion
425        "/we5038" # data member 'member1' will be initialized after data member 'member2' data member 'member' will be initialized after base class 'base_class'
426        "/we4101" # 'identifier' : unreferenced local variable
427    )
428else()
429    # Explicitly enable these warnings.
430    list(APPEND SWIFTSHADER_COMPILE_OPTIONS
431        "-Wall"
432        "-Wreorder"
433        "-Wsign-compare"
434        "-Wmissing-braces"
435    )
436
437    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
438        if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
439            list(APPEND SWIFTSHADER_COMPILE_OPTIONS
440                "-Wdeprecated-copy"  # implicit copy constructor for 'X' is deprecated because of user-declared copy assignment operator.
441            )
442        endif()
443    elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
444        list(APPEND SWIFTSHADER_COMPILE_OPTIONS
445            "-Wextra"
446            "-Wunreachable-code-loop-increment"
447            "-Wunused-lambda-capture"
448            "-Wstring-conversion"
449            "-Wextra-semi"
450            "-Wignored-qualifiers"
451            "-Wdeprecated-copy"  # implicit copy constructor for 'X' is deprecated because of user-declared copy assignment operator.
452            # TODO(b/208256248): Avoid exit-time destructor.
453            #"-Wexit-time-destructors"  # declaration requires an exit-time destructor
454        )
455    endif()
456
457    if (SWIFTSHADER_EMIT_COVERAGE)
458        if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
459            list(APPEND SWIFTSHADER_COMPILE_OPTIONS "--coverage")
460            list(APPEND SWIFTSHADER_LIBS "gcov")
461        elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
462            list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fprofile-instr-generate" "-fcoverage-mapping")
463            list(APPEND SWIFTSHADER_LINK_FLAGS "-fprofile-instr-generate" "-fcoverage-mapping")
464        else()
465            message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
466        endif()
467    endif()
468
469    # Disable pedantic warnings
470    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
471        list(APPEND SWIFTSHADER_COMPILE_OPTIONS
472            "-Wno-ignored-attributes"   # ignoring attributes on template argument 'X'
473            "-Wno-attributes"           # 'X' attribute ignored
474            "-Wno-strict-aliasing"      # dereferencing type-punned pointer will break strict-aliasing rules
475            "-Wno-comment"              # multi-line comment
476        )
477        if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
478            list(APPEND SWIFTSHADER_COMPILE_OPTIONS
479                "-Wno-init-list-lifetime"  # assignment from temporary initializer_list does not extend the lifetime of the underlying array
480            )
481        endif()
482    elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
483        list(APPEND SWIFTSHADER_COMPILE_OPTIONS
484            "-Wno-unneeded-internal-declaration"  # function 'X' is not needed and will not be emitted
485            "-Wno-unused-private-field"           # private field 'offset' is not used - TODO: Consider enabling this once Vulkan is further implemented.
486            "-Wno-comment"                        # multi-line comment
487            "-Wno-extra-semi"                     # extra ';' after member function definition
488            "-Wno-unused-parameter"               # unused parameter 'X'
489
490            # Silence errors caused by unknown warnings when building with older
491            # versions of Clang. This demands checking that warnings added above
492            # are spelled correctly and work as intended!
493            "-Wno-unknown-warning-option"
494        )
495    endif()
496
497    if(ARCH STREQUAL "x86")
498        set_cpp_flag("-m32")
499        set_cpp_flag("-msse2")
500        set_cpp_flag("-mfpmath=sse")
501        set_cpp_flag("-march=pentium4")
502        set_cpp_flag("-mtune=generic")
503    endif()
504    if(ARCH STREQUAL "x86_64")
505        set_cpp_flag("-m64")
506        set_cpp_flag("-fPIC")
507        set_cpp_flag("-march=x86-64")
508        set_cpp_flag("-mtune=generic")
509    endif()
510    if(ARCH STREQUAL "mipsel")
511        set_cpp_flag("-EL")
512        set_cpp_flag("-march=mips32r2")
513        set_cpp_flag("-fPIC")
514        set_cpp_flag("-mhard-float")
515        set_cpp_flag("-mfp32")
516        set_cpp_flag("-mxgot")
517    endif()
518    if(ARCH STREQUAL "mips64el")
519        set_cpp_flag("-EL")
520        set_cpp_flag("-march=mips64r2")
521        set_cpp_flag("-mabi=64")
522        set_cpp_flag("-fPIC")
523        set_cpp_flag("-mxgot")
524    endif()
525
526    if(SWIFTSHADER_LESS_DEBUG_INFO)
527        # Use -g1 to be able to get stack traces
528        set_cpp_flag("-g -g1" DEBUG)
529        set_cpp_flag("-g -g1" RELWITHDEBINFO)
530    else()
531        # Use -g3 to have even more debug info
532        set_cpp_flag("-g -g3" DEBUG)
533        set_cpp_flag("-g -g3" RELWITHDEBINFO)
534    endif()
535
536    if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
537        # Treated as an unused argument with clang
538        set_cpp_flag("-s" RELEASE)
539    endif()
540
541    # For distribution it is more important to be slim than super optimized
542    set_cpp_flag("-Os" RELEASE)
543    set_cpp_flag("-Os" RELWITHDEBINFO)
544
545    set_cpp_flag("-DNDEBUG" RELEASE)
546    set_cpp_flag("-DNDEBUG" RELWITHDEBINFO)
547    set_cpp_flag("-DANGLE_DISABLE_TRACE" RELEASE)
548    set_cpp_flag("-DANGLE_DISABLE_TRACE" RELWITHDEBINFO)
549
550    # Put each variable and function in its own section so that when linking
551    # with -gc-sections unused functions and variables are removed.
552    set_cpp_flag("-ffunction-sections" RELEASE)
553    set_cpp_flag("-fdata-sections" RELEASE)
554    set_cpp_flag("-fomit-frame-pointer" RELEASE)
555
556    if(SWIFTSHADER_MSAN)
557        if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
558            message(FATAL_ERROR " \n"
559                    " MemorySanitizer usage requires compiling with Clang.")
560        endif()
561
562        if(NOT DEFINED ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH})
563            message(FATAL_ERROR " \n"
564                    " MemorySanitizer usage requires an instrumented build of libc++.\n"
565                    " Set the SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH environment variable to the\n"
566                    " build output path. See\n"
567                    " https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo#instrumented-libc\n"
568                    " for details on how to build an MSan instrumented libc++.")
569        endif()
570
571        set_cpp_flag("-fsanitize=memory")
572        set_linker_flag("-fsanitize=memory")
573        set_cpp_flag("-stdlib=libc++")
574        set_linker_flag("-L$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/lib")
575        set_cpp_flag("-I$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/include")
576        set_cpp_flag("-I$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/include/c++/v1")
577        set_linker_flag("-Wl,-rpath,$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/lib")
578    elseif(SWIFTSHADER_ASAN)
579        set_cpp_flag("-fsanitize=address")
580        set_linker_flag("-fsanitize=address")
581    elseif(SWIFTSHADER_TSAN)
582        set_cpp_flag("-fsanitize=thread")
583        set_linker_flag("-fsanitize=thread")
584    elseif(SWIFTSHADER_UBSAN)
585        set_cpp_flag("-fsanitize=undefined")
586        set_linker_flag("-fsanitize=undefined")
587    endif()
588endif()
589
590if(SWIFTSHADER_DCHECK_ALWAYS_ON)
591    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DDCHECK_ALWAYS_ON")
592endif()
593
594if(SWIFTSHADER_WARNINGS_AS_ERRORS)
595    if(MSVC)
596        set(WARNINGS_AS_ERRORS "/WX")  # Treat all warnings as errors
597    else()
598        set(WARNINGS_AS_ERRORS "-Werror")  # Treat all warnings as errors
599    endif()
600endif()
601
602# Enable Reactor Print() functionality in Debug/RelWithDebInfo builds or when explicitly enabled.
603if(CMAKE_BUILD_TYPE MATCHES "Deb")
604    set(REACTOR_ENABLE_PRINT TRUE)
605endif()
606
607if(REACTOR_EMIT_PRINT_LOCATION)
608    # This feature depends on REACTOR_EMIT_DEBUG_INFO and REACTOR_ENABLE_PRINT
609    set(REACTOR_EMIT_DEBUG_INFO TRUE)
610    set(REACTOR_ENABLE_PRINT TRUE)
611    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_EMIT_PRINT_LOCATION")
612endif()
613
614if(REACTOR_EMIT_ASM_FILE)
615    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_EMIT_ASM_FILE")
616endif()
617
618if(REACTOR_EMIT_DEBUG_INFO)
619    message(WARNING "REACTOR_EMIT_DEBUG_INFO is enabled. This will likely affect performance.")
620    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_DEBUG_INFO")
621endif()
622
623if(REACTOR_ENABLE_PRINT)
624    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_PRINT")
625endif()
626
627if(REACTOR_VERIFY_LLVM_IR)
628    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_LLVM_IR_VERIFICATION")
629endif()
630
631if(REACTOR_DEFAULT_OPT_LEVEL)
632    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DREACTOR_DEFAULT_OPT_LEVEL=${REACTOR_DEFAULT_OPT_LEVEL}")
633endif()
634
635if(DEFINED SWIFTSHADER_LOGGING_LEVEL)
636    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DSWIFTSHADER_LOGGING_LEVEL=${SWIFTSHADER_LOGGING_LEVEL}")
637endif()
638
639if(WIN32)
640    add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
641    set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
642endif()
643
644set(USE_EXCEPTIONS
645    ${REACTOR_EMIT_DEBUG_INFO} # boost::stacktrace uses exceptions
646)
647if(NOT MSVC)
648    if (${USE_EXCEPTIONS})
649        list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fexceptions")
650    else()
651        list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fno-exceptions")
652    endif()
653endif()
654unset(USE_EXCEPTIONS)
655
656###########################################################
657# libbacktrace and boost
658###########################################################
659if(REACTOR_EMIT_DEBUG_INFO)
660    add_subdirectory(${THIRD_PARTY_DIR}/libbacktrace EXCLUDE_FROM_ALL)
661    add_subdirectory(${THIRD_PARTY_DIR}/boost EXCLUDE_FROM_ALL)
662endif()
663
664###########################################################
665# LLVM
666###########################################################
667add_subdirectory(${THIRD_PARTY_DIR}/llvm-${SWIFTSHADER_LLVM_VERSION} EXCLUDE_FROM_ALL)
668set_target_properties(llvm PROPERTIES FOLDER "third_party")
669
670###########################################################
671# Subzero
672###########################################################
673add_subdirectory(${THIRD_PARTY_DIR}/llvm-subzero EXCLUDE_FROM_ALL)
674add_subdirectory(${THIRD_PARTY_DIR}/subzero EXCLUDE_FROM_ALL)
675set_target_properties(llvm-subzero PROPERTIES FOLDER "third_party")
676set_target_properties(subzero PROPERTIES FOLDER "third_party")
677
678###########################################################
679# marl
680###########################################################
681if(BUILD_MARL)
682    set(MARL_THIRD_PARTY_DIR ${THIRD_PARTY_DIR})
683    add_subdirectory(${THIRD_PARTY_DIR}/marl)
684    set_target_properties(marl PROPERTIES FOLDER "third_party")
685endif()
686
687if(MARL_THREAD_SAFETY_ANALYSIS_SUPPORTED)
688    list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-Wthread-safety")
689endif()
690
691###########################################################
692# cppdap
693###########################################################
694if(SWIFTSHADER_BUILD_CPPDAP)
695    set(CPPDAP_THIRD_PARTY_DIR ${THIRD_PARTY_DIR})
696    add_subdirectory(${THIRD_PARTY_DIR}/cppdap)
697endif()
698
699###########################################################
700# astc-encoder
701###########################################################
702if(SWIFTSHADER_ENABLE_ASTC)
703    add_subdirectory(${THIRD_PARTY_DIR}/astc-encoder)
704    set_target_properties(astc-encoder PROPERTIES FOLDER "third_party")
705endif()
706
707###########################################################
708# gtest and gmock
709###########################################################
710if(SWIFTSHADER_BUILD_TESTS)
711    # For Win32, force gtest to match our CRT (shared)
712    set(gtest_force_shared_crt TRUE CACHE BOOL "" FORCE)
713    add_subdirectory(${THIRD_PARTY_DIR}/googletest EXCLUDE_FROM_ALL)
714    # gtest finds python, which picks python 2 first, if present.
715    # We need to undo this so that SPIR-V can later find python3.
716    unset(PYTHON_EXECUTABLE CACHE)
717    set_target_properties(gmock PROPERTIES FOLDER "third_party")
718    set_target_properties(gmock_main PROPERTIES FOLDER "third_party")
719    set_target_properties(gtest PROPERTIES FOLDER "third_party")
720    set_target_properties(gtest_main PROPERTIES FOLDER "third_party")
721endif()
722
723###########################################################
724# File Lists
725###########################################################
726
727###########################################################
728# Append OS specific files to lists
729###########################################################
730
731if(WIN32)
732    set(OS_LIBS odbc32 odbccp32 WS2_32 dxguid)
733elseif(LINUX)
734    set(OS_LIBS dl pthread)
735    if(SWIFTSHADER_BUILD_WSI_WAYLAND)
736        list(APPEND OS_LIBS "${WAYLAND}")
737    endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
738    if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
739        list(APPEND OS_LIBS "${DIRECTFB}")
740        include_directories(${DIRECTFB_INCLUDE_DIR}/directfb)
741    endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
742    if(SWIFTSHADER_BUILD_WSI_D2D)
743        list(APPEND OS_LIBS "${D2D}")
744        include_directories(${D2D_INCLUDE_DIR}/libdrm)
745    endif(SWIFTSHADER_BUILD_WSI_D2D)
746elseif(FUCHSIA)
747    set(OS_LIBS zircon)
748elseif(APPLE)
749    find_library(COCOA_FRAMEWORK Cocoa)
750    find_library(QUARTZ_FRAMEWORK Quartz)
751    find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
752    find_library(IOSURFACE_FRAMEWORK IOSurface)
753    find_library(METAL_FRAMEWORK Metal)
754    set(OS_LIBS "${COCOA_FRAMEWORK}" "${QUARTZ_FRAMEWORK}" "${CORE_FOUNDATION_FRAMEWORK}" "${IOSURFACE_FRAMEWORK}" "${METAL_FRAMEWORK}")
755endif()
756
757###########################################################
758# SwiftShader Targets
759###########################################################
760
761add_subdirectory(src/Reactor) # Add ReactorSubzero and ReactorLLVM targets
762
763if(${REACTOR_BACKEND} STREQUAL "LLVM")
764    set(Reactor ReactorLLVM)
765elseif(${REACTOR_BACKEND} STREQUAL "Subzero")
766    set(Reactor ReactorSubzero)
767else()
768    message(FATAL_ERROR "REACTOR_BACKEND must be 'LLVM' or 'Subzero'")
769endif()
770
771add_subdirectory(src/Common) # Add gl_common target
772add_subdirectory(src/Main) # Add gl_main target
773add_subdirectory(src/Shader) # Add gl_shader target
774add_subdirectory(src/Renderer) # Add gl_renderer target
775
776# Combine all gl_* targets into an interface target
777# along with other dependencies
778add_library(gl_swiftshader_core INTERFACE)
779target_link_libraries(gl_swiftshader_core INTERFACE
780    # Transitively depends on shader, main, core, Reactor,
781    # OS_LIBS and SWIFTSHADER_LIBS
782    gl_renderer
783)
784
785add_subdirectory(src/OpenGL/common EXCLUDE_FROM_ALL) # Add libGLESCommon target
786add_subdirectory(src/OpenGL/compiler EXCLUDE_FROM_ALL) # Add GLCompiler target
787
788if(SWIFTSHADER_BUILD_EGL)
789    add_subdirectory(src/OpenGL/libEGL) # Add libEGL target
790endif()
791
792if(SWIFTSHADER_BUILD_GLESv2)
793    add_subdirectory(src/OpenGL/libGLESv2) # Add libGLESv2 target
794endif()
795
796if(SWIFTSHADER_BUILD_VULKAN)
797    if (NOT TARGET SPIRV-Tools)
798        # This variable is also used by SPIRV-Tools to locate SPIRV-Headers
799        set(SPIRV-Headers_SOURCE_DIR "${THIRD_PARTY_DIR}/SPIRV-Headers")
800        set(SPIRV_SKIP_TESTS TRUE CACHE BOOL "" FORCE)
801        set(SPIRV_SKIP_EXECUTABLES TRUE CACHE BOOL "" FORCE)
802        add_subdirectory(${THIRD_PARTY_DIR}/SPIRV-Tools) # Add SPIRV-Tools target
803    endif()
804
805    # Add a vk_base interface library for shared vulkan build options.
806    # TODO: Create src/Base and make this a lib target, and move stuff from
807    # src/Vulkan into it that is needed by vk_pipeline, vk_device, and vk_wsi.
808    add_library(vk_base INTERFACE)
809
810    if(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER)
811        target_compile_definitions(vk_base INTERFACE "ENABLE_VK_DEBUGGER")
812    endif()
813
814    if(WIN32)
815        target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_WIN32_KHR")
816    elseif(LINUX)
817        if(X11)
818            target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_XLIB_KHR")
819        endif()
820        if(XCB)
821            target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_XCB_KHR")
822        endif()
823        if(SWIFTSHADER_BUILD_WSI_WAYLAND)
824            if(WAYLAND)
825                target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_WAYLAND_KHR")
826            endif()
827        endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
828        if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
829            if(DIRECTFB AND DIRECTFB_INCLUDE_DIR)
830                target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_DIRECTFB_EXT")
831            endif()
832        endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
833        if(SWIFTSHADER_BUILD_WSI_D2D)
834            if(D2D)
835                target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_DISPLAY_KHR")
836            endif()
837        endif(SWIFTSHADER_BUILD_WSI_D2D)
838    elseif(APPLE)
839        target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_MACOS_MVK")
840        target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_METAL_EXT")
841    elseif(FUCHSIA)
842        target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_FUCHSIA")
843    else()
844        message(FATAL_ERROR "Platform does not support Vulkan yet")
845    endif()
846
847    add_subdirectory(src/System) # Add vk_system target
848    add_subdirectory(src/Pipeline) # Add vk_pipeline target
849    add_subdirectory(src/WSI) # Add vk_wsi target
850    add_subdirectory(src/Device) # Add vk_device target
851    add_subdirectory(src/Vulkan) # Add vk_swiftshader target
852
853    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND # turbo-cov is only useful for clang coverage info
854       SWIFTSHADER_EMIT_COVERAGE)
855        add_subdirectory(${TESTS_DIR}/regres/cov/turbo-cov)
856    endif()
857
858endif()
859
860if(SWIFTSHADER_BUILD_ANGLE)
861    add_subdirectory(${THIRD_PARTY_DIR}/angle)
862
863    # Make angle depend on vk_swiftshader so we can test SWANGLE
864    if (TARGET vk_swiftshader)
865        add_dependencies(angle vk_swiftshader)
866    endif()
867endif()
868
869
870###########################################################
871# Sample programs and tests
872###########################################################
873
874# TODO(b/161976310): Add support for building PowerVR on MacOS
875if(APPLE AND HAVE_PVR_SUBMODULE AND SWIFTSHADER_BUILD_PVR)
876    message(WARNING "Building PowerVR examples for SwiftShader is not yet supported on Apple platforms.")
877    set(SWIFTSHADER_BUILD_PVR FALSE)
878endif()
879
880if(HAVE_PVR_SUBMODULE AND SWIFTSHADER_BUILD_PVR)
881    if(UNIX AND NOT APPLE)
882        set(PVR_WINDOW_SYSTEM XCB)
883
884        # Set the RPATH of the next defined build targets to $ORIGIN,
885        # allowing them to load shared libraries from the execution directory.
886        set(CMAKE_BUILD_RPATH "$ORIGIN")
887    endif()
888
889    set(PVR_BUILD_EXAMPLES TRUE CACHE BOOL "Build the PowerVR SDK Examples" FORCE)
890    add_subdirectory(${THIRD_PARTY_DIR}/PowerVR_Examples)
891
892    # Samples known to work well
893    set(PVR_VULKAN_TARGET_GOOD
894        VulkanBumpmap
895        VulkanExampleUI
896        VulkanGaussianBlur
897        VulkanGlass
898        VulkanGnomeHorde
899        VulkanHelloAPI
900        VulkanImageBasedLighting
901        VulkanIntroducingPVRUtils
902        VulkanMultiSampling
903        VulkanNavigation2D
904        VulkanParticleSystem
905        VulkanSkinning
906    )
907
908    set(PVR_GLES_TARGET_GOOD
909        OpenGLESHelloAPI
910        OpenGLESIntroducingPVRUtils
911        OpenGLESNavigation2D
912    )
913
914    set(PVR_VULKAN_TARGET_OTHER
915        VulkanDeferredShading
916        VulkanDeferredShadingPFX
917        VulkanGameOfLife
918        VulkanIBLMapsGenerator
919        VulkanIMGTextureFilterCubic
920        VulkanIntroducingPVRShell
921        VulkanIntroducingPVRVk
922        VulkanIntroducingUIRenderer
923        VulkanMultithreading
924        VulkanNavigation3D
925        VulkanPostProcessing
926        VulkanPVRScopeExample
927        VulkanPVRScopeRemote
928    )
929
930    set(PVR_GLES_TARGET_OTHER
931        OpenGLESDeferredShading
932        OpenGLESGaussianBlur
933        OpenGLESImageBasedLighting
934        OpenGLESIMGFramebufferDownsample
935        OpenGLESIMGTextureFilterCubic
936        OpenGLESIntroducingPVRCamera
937        OpenGLESIntroducingPVRShell
938        OpenGLESIntroducingUIRenderer
939        OpenGLESMultiviewVR
940        OpenGLESNavigation3D
941        OpenGLESOpenCLExample
942        OpenGLESParticleSystem
943        OpenGLESPostProcessing
944        OpenGLESPVRScopeExample
945        OpenGLESPVRScopeRemote
946        OpenGLESSkinning
947    )
948
949    set(PVR_TARGET_OTHER
950        glslang
951        glslangValidator
952        glslang-default-resource-limits
953        OGLCompiler
954        OSDependent
955        OpenCLMatrixMultiplication
956        pugixml
957        PVRAssets
958        PVRCamera
959        PVRCore
960        PVRPfx
961        PVRShell
962        PVRUtilsGles
963        PVRUtilsVk
964        PVRVk
965        SPIRV
966        spirv-remap
967        SPVRemapper
968        uninstall
969    )
970
971    set(PVR_VULKAN_TARGET
972        ${PVR_VULKAN_TARGET_GOOD}
973        ${PVR_VULKAN_TARGET_OTHER}
974    )
975
976    set(PVR_GLES_TARGET
977        ${PVR_GLES_TARGET_GOOD}
978        ${PVR_GLES_TARGET_OTHER}
979    )
980
981    foreach(pvr_target ${PVR_VULKAN_TARGET})
982        add_dependencies(${pvr_target} vk_swiftshader)
983    endforeach()
984
985    foreach(pvr_target ${PVR_GLES_TARGET})
986        add_dependencies(${pvr_target} libGLESv2_deprecated)
987        add_dependencies(${pvr_target} libEGL_deprecated)
988    endforeach()
989
990    foreach(pvr_target ${PVR_VULKAN_TARGET_GOOD} ${PVR_GLES_TARGET_GOOD})
991        set_target_properties(${pvr_target} PROPERTIES FOLDER Samples)
992    endforeach()
993
994    foreach(pvr_target ${PVR_TARGET_OTHER} ${PVR_VULKAN_TARGET_OTHER} ${PVR_GLES_TARGET_OTHER})
995        set_target_properties(${pvr_target} PROPERTIES FOLDER Samples/PowerVR-Build)
996    endforeach()
997
998    # Make angle target depend on PowerVR GL examples
999    if (TARGET angle)
1000        foreach(pvr_target ${PVR_GLES_TARGET})
1001            add_dependencies(angle ${pvr_target})
1002        endforeach()
1003    endif()
1004endif()
1005
1006if(BUILD_VULKAN_WRAPPER)
1007    if (NOT TARGET glslang)
1008        add_subdirectory(${THIRD_PARTY_DIR}/glslang)
1009    endif()
1010    add_subdirectory(${TESTS_DIR}/VulkanWrapper) # Add VulkanWrapper target
1011endif()
1012
1013if(SWIFTSHADER_BUILD_TESTS)
1014    add_subdirectory(${TESTS_DIR}/ReactorUnitTests) # Add ReactorUnitTests target
1015    add_subdirectory(${TESTS_DIR}/GLESUnitTests) # Add gles-unittests target
1016    add_subdirectory(${TESTS_DIR}/MathUnitTests) # Add math-unittests target
1017    add_subdirectory(${TESTS_DIR}/SystemUnitTests) # Add system-unittests target
1018endif()
1019
1020if(SWIFTSHADER_BUILD_BENCHMARKS)
1021    if (NOT TARGET benchmark::benchmark)
1022        set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE)
1023        add_subdirectory(${THIRD_PARTY_DIR}/benchmark)
1024        set_target_properties(benchmark PROPERTIES FOLDER "third_party")
1025        set_target_properties(benchmark_main PROPERTIES FOLDER "third_party")
1026    endif()
1027
1028    add_subdirectory(${TESTS_DIR}/ReactorBenchmarks) # Add ReactorBenchmarks target
1029    add_subdirectory(${TESTS_DIR}/SystemBenchmarks) # Add system-benchmarks target
1030    add_subdirectory(${TESTS_DIR}/VulkanBenchmarks) # Add VulkanBenchmarks target
1031endif()
1032
1033if(SWIFTSHADER_BUILD_TESTS AND SWIFTSHADER_BUILD_VULKAN)
1034    add_subdirectory(${TESTS_DIR}/VulkanUnitTests) # Add VulkanUnitTests target
1035endif()
1036