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