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