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