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