blob: 70499958b0df0caa1c33a1ce62ae9529054d74f8 [file] [log] [blame]
Ben Clayton3c690342020-03-24 22:38:59 +00001# 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
Antonio Maioranobccfe712020-04-20 17:48:53 -040015cmake_minimum_required(VERSION 3.13)
Corentin Wallez0866b292015-12-09 13:49:40 -050016
Ben Clayton30b6b592019-08-07 15:04:11 +010017project(SwiftShader C CXX ASM)
Corentin Wallez0866b292015-12-09 13:49:40 -050018
Nicolas Capensb3e5c442021-01-20 06:16:24 +000019set(CMAKE_CXX_STANDARD 17)
Antonio Maiorano10ff4332020-12-04 11:33:34 -050020set(CXX_STANDARD_REQUIRED ON)
21# MSVC doesn't define __cplusplus by default
22if(MSVC)
23 string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
24endif()
25
Corentin Wallez0866b292015-12-09 13:49:40 -050026###########################################################
27# Detect system
28###########################################################
29
Nicolas Capens6f422092015-12-23 15:12:45 -050030if(CMAKE_SYSTEM_NAME MATCHES "Linux")
Nicolas Capens1dfcdb02020-03-12 21:12:52 +000031 set(LINUX TRUE)
Stephen Whitee6ab01f2019-04-04 14:31:25 -040032elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
Nicolas Capens1dfcdb02020-03-12 21:12:52 +000033 set(ANDROID TRUE)
Stephen Whitee6ab01f2019-04-04 14:31:25 -040034 set(CMAKE_CXX_FLAGS "-DANDROID_NDK_BUILD")
Corentin Wallez0866b292015-12-09 13:49:40 -050035elseif(WIN32)
36elseif(APPLE)
David 'Digit' Turnerd3717932019-11-19 17:54:00 +010037elseif(FUCHSIA)
38 # NOTE: Building for Fuchsia requires a Fuchsia CMake-based SDK.
39 # See https://fuchsia-review.googlesource.com/c/fuchsia/+/379673
David 'Digit' Turner08090462020-04-17 15:53:21 +020040 find_package(FuchsiaLibraries)
Corentin Wallez0866b292015-12-09 13:49:40 -050041else()
42 message(FATAL_ERROR "Platform is not supported")
43endif()
44
Nicolas Capens30cd7d42017-04-25 15:17:25 -040045if(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()
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +020051elseif(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()
Colin Samplesf63a3ab2019-06-13 12:53:09 -040057elseif(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()
Corentin Wallez0866b292015-12-09 13:49:40 -050063else()
Nicolas Capens30cd7d42017-04-25 15:17:25 -040064 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
65 set(ARCH "x86_64")
66 else()
67 set(ARCH "x86")
68 endif()
Corentin Wallez0866b292015-12-09 13:49:40 -050069endif()
70
Yilong Li14dcbed2021-01-19 16:31:21 -080071# 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
Nicolas Capens1dfcdb02020-03-12 21:12:52 +000087set(CMAKE_MACOSX_RPATH TRUE)
Nicolas Capens007c6c52017-06-09 11:21:48 -040088
Nicolas Capensd7a21cc2018-09-11 13:09:28 -040089if ((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
Ben Clayton4901ffd2019-06-27 10:39:07 +010096# 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)
Ben Clayton1e8486b2020-01-22 17:01:52 +0000102endif()
Ben Clayton4901ffd2019-06-27 10:39:07 +0100103
Corentin Wallez0866b292015-12-09 13:49:40 -0500104###########################################################
Ben Claytona9af8832019-08-14 13:09:43 +0100105# Host libraries
106###########################################################
107
Adrian Ratiuc6747d92021-07-14 14:39:20 +0300108if(LINUX)
Nicolas Capens9c16e142022-04-05 00:27:05 -0400109 include(CheckSymbolExists)
Adrian Ratiuc6747d92021-07-14 14:39:20 +0300110 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
111 check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
Nicolas Capens9c16e142022-04-05 00:27:05 -0400112
113 include(CheckIncludeFiles)
114 CHECK_INCLUDE_FILES("xcb/xcb.h" HAVE_XCB_H)
115 if(NOT HAVE_XCB_H)
116 message(WARNING "xcb/xcb.h was not found. Install the libx11-xcb-dev package "
117 "to build with WSI support for XCB surfaces.")
118 endif()
Adrian Ratiuc6747d92021-07-14 14:39:20 +0300119endif()
120
Nicolas Caramellia681d122020-07-20 23:47:56 +0200121if(SWIFTSHADER_BUILD_WSI_WAYLAND)
122 find_library(WAYLAND wayland-client)
123endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
Nicolas Caramelli08596c42020-08-01 07:55:00 +0200124if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
125 find_library(DIRECTFB directfb)
126 find_path(DIRECTFB_INCLUDE_DIR directfb/directfb.h)
127endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
Nicolas Caramelli937395c2021-01-06 21:00:18 +0100128if(SWIFTSHADER_BUILD_WSI_D2D)
129 find_library(D2D drm)
130 find_path(D2D_INCLUDE_DIR libdrm/drm.h)
131endif(SWIFTSHADER_BUILD_WSI_D2D)
Ben Claytona9af8832019-08-14 13:09:43 +0100132
133###########################################################
Nicolas Capens18b8d682017-07-25 15:31:45 -0400134# Options
135###########################################################
136
137if(NOT CMAKE_BUILD_TYPE)
138 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build: Debug Release MinSizeRel RelWithDebInfo." FORCE)
Antonio Maiorano31038ea2020-04-15 16:47:00 -0400139 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
Nicolas Capens18b8d682017-07-25 15:31:45 -0400140endif()
Nicolas Capens18b8d682017-07-25 15:31:45 -0400141
Ben Clayton5837d872020-01-20 16:23:36 +0000142function (option_if_not_defined name description default)
143 if(NOT DEFINED ${name})
144 option(${name} ${description} ${default})
145 endif()
146endfunction()
Nicolas Capens18b8d682017-07-25 15:31:45 -0400147
Ben Clayton9cc163c2020-01-20 16:26:36 +0000148function (set_if_not_defined name value)
149 if(NOT DEFINED ${name})
150 set(${name} ${value} PARENT_SCOPE)
151 endif()
152endfunction()
153
Nicolas Caramellia681d122020-07-20 23:47:56 +0200154option_if_not_defined(SWIFTSHADER_BUILD_WSI_WAYLAND "Build the Wayland WSI support" FALSE)
Nicolas Caramelli08596c42020-08-01 07:55:00 +0200155option_if_not_defined(SWIFTSHADER_BUILD_WSI_DIRECTFB "Build the DirectFB WSI support" FALSE)
Nicolas Caramelli937395c2021-01-06 21:00:18 +0100156option_if_not_defined(SWIFTSHADER_BUILD_WSI_D2D "Build the Direct-to-Display WSI support" FALSE)
Nicolas Capensf53de1a2022-02-11 10:28:19 -0500157option_if_not_defined(SWIFTSHADER_BUILD_PVR "Build the PowerVR examples" FALSE)
Nicolas Capens18b8d682017-07-25 15:31:45 -0400158
Nicolas Capens45755df2020-03-30 12:42:40 -0400159option_if_not_defined(SWIFTSHADER_BUILD_TESTS "Build unit tests" TRUE)
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000160option_if_not_defined(SWIFTSHADER_BUILD_BENCHMARKS "Build benchmarks" FALSE)
Ben Clayton5837d872020-01-20 16:23:36 +0000161
Nicolas Capensf53de1a2022-02-11 10:28:19 -0500162option_if_not_defined(SWIFTSHADER_USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Studio" TRUE)
163
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000164option_if_not_defined(SWIFTSHADER_MSAN "Build with memory sanitizer" FALSE)
165option_if_not_defined(SWIFTSHADER_ASAN "Build with address sanitizer" FALSE)
166option_if_not_defined(SWIFTSHADER_TSAN "Build with thread sanitizer" FALSE)
167option_if_not_defined(SWIFTSHADER_UBSAN "Build with undefined behavior sanitizer" FALSE)
Ben Clayton063fc022020-03-23 13:18:09 +0000168option_if_not_defined(SWIFTSHADER_EMIT_COVERAGE "Emit code coverage information" FALSE)
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000169option_if_not_defined(SWIFTSHADER_WARNINGS_AS_ERRORS "Treat all warnings as errors" TRUE)
170option_if_not_defined(SWIFTSHADER_DCHECK_ALWAYS_ON "Check validation macros even in release builds" FALSE)
171option_if_not_defined(REACTOR_EMIT_DEBUG_INFO "Emit debug info for JIT functions" FALSE)
172option_if_not_defined(REACTOR_EMIT_PRINT_LOCATION "Emit printing of location info for JIT functions" FALSE)
Antonio Maiorano6f6ca292020-11-27 15:40:15 -0500173option_if_not_defined(REACTOR_EMIT_ASM_FILE "Emit asm files for JIT functions" FALSE)
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000174option_if_not_defined(REACTOR_ENABLE_PRINT "Enable RR_PRINT macros" FALSE)
175option_if_not_defined(REACTOR_VERIFY_LLVM_IR "Check reactor-generated LLVM IR is valid even in release builds" FALSE)
Adlai Holler0320eab2021-02-17 12:29:00 -0500176# TODO(b/155148722): Remove when unconditionally instrumenting for all build systems.
177option_if_not_defined(REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION "Include JIT in MSAN instrumentation (LLVM backend)" TRUE)
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000178option_if_not_defined(SWIFTSHADER_LESS_DEBUG_INFO "Generate less debug info to reduce file size" FALSE)
179option_if_not_defined(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER "Enable Vulkan debugger support" FALSE)
180option_if_not_defined(SWIFTSHADER_ENABLE_ASTC "Enable ASTC compressed textures support" TRUE) # TODO(b/150130101)
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400181
Nicolas Capens4625f842021-12-08 14:23:59 -0500182set_if_not_defined(SWIFTSHADER_BUILD_CPPDAP ${SWIFTSHADER_ENABLE_VULKAN_DEBUGGER})
Ben Claytone693b622019-09-05 12:48:37 +0100183
Nicolas Capens5f8a16a2019-08-15 10:36:13 -0400184set(DEFAULT_REACTOR_BACKEND "LLVM")
Nicolas Capens3957b7f2018-10-15 12:54:41 -0400185set(REACTOR_BACKEND ${DEFAULT_REACTOR_BACKEND} CACHE STRING "JIT compiler back-end used by Reactor")
Martin Troiber5ff2f732022-02-25 00:17:06 +0100186set_property(CACHE REACTOR_BACKEND PROPERTY STRINGS LLVM LLVM-Submodule Subzero)
Nicolas Capens18b8d682017-07-25 15:31:45 -0400187
Antonio Maiorano6a6ae442020-07-20 14:11:48 -0400188set(DEFAULT_SWIFTSHADER_LLVM_VERSION "10.0")
Ben Claytoncafff782020-03-26 11:18:05 +0000189set(SWIFTSHADER_LLVM_VERSION ${DEFAULT_SWIFTSHADER_LLVM_VERSION} CACHE STRING "LLVM version to use")
Antonio Maiorano6a6ae442020-07-20 14:11:48 -0400190set_property(CACHE SWIFTSHADER_LLVM_VERSION PROPERTY STRINGS "10.0")
Ben Claytoncafff782020-03-26 11:18:05 +0000191
Antonio Maiorano062dc182019-12-09 11:52:31 -0500192# If defined, overrides the default optimization level of the current reactor backend.
193# Set to one of the rr::Optimization::Level enum values.
Antonio Maioranob17161a2020-11-23 11:17:22 -0500194set(REACTOR_DEFAULT_OPT_LEVEL "" CACHE STRING "Reactor default optimization level")
Antonio Maiorano062dc182019-12-09 11:52:31 -0500195set_property(CACHE REACTOR_DEFAULT_OPT_LEVEL PROPERTY STRINGS "None" "Less" "Default" "Aggressive")
196
Ben Claytoncbb5a102020-10-03 11:15:47 +0100197if(NOT DEFINED SWIFTSHADER_LOGGING_LEVEL)
198 set(SWIFTSHADER_LOGGING_LEVEL "Info" CACHE STRING "SwiftShader logging level")
199 set_property(CACHE SWIFTSHADER_LOGGING_LEVEL PROPERTY STRINGS "Verbose" "Debug" "Info" "Warn" "Error" "Fatal" "Disabled")
200endif()
201
Nicolas Capens18b8d682017-07-25 15:31:45 -0400202# LLVM disallows calling cmake . from the main LLVM dir, the reason is that
203# it builds header files that could overwrite the orignal ones. Here we
204# want to include LLVM as a subdirectory and even though it wouldn't cause
205# the problem, if cmake . is called from the main dir, the condition that
Erwin Jansend46faeb2018-11-19 16:01:37 -0800206# LLVM checkes, "CMAKE_CURRENT_SOURCE_DIR == CMAKE_CURRENT_BINARY_DIR" will be true. So we
Nicolas Capens18b8d682017-07-25 15:31:45 -0400207# disallow it ourselves too to. In addition if there are remining CMakeFiles
208# and CMakeCache in the directory, cmake .. from a subdirectory will still
209# try to build from the main directory so we instruct users to delete these
210# files when they get the error.
Erwin Jansend46faeb2018-11-19 16:01:37 -0800211if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
Nicolas Capens18b8d682017-07-25 15:31:45 -0400212 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.")
213endif()
214
Nicolas Capens1dfcdb02020-03-12 21:12:52 +0000215set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
Nicolas Capens18b8d682017-07-25 15:31:45 -0400216
217###########################################################
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400218# Directories
219###########################################################
220
Antonio Maiorano8772b422020-04-15 15:00:36 -0400221set(SWIFTSHADER_DIR ${CMAKE_CURRENT_SOURCE_DIR})
222set(SOURCE_DIR ${SWIFTSHADER_DIR}/src)
223set(THIRD_PARTY_DIR ${SWIFTSHADER_DIR}/third_party)
224set(TESTS_DIR ${SWIFTSHADER_DIR}/tests)
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400225
226###########################################################
Nicolas Capensfe5861b2018-08-03 16:01:48 -0400227# Initialize submodules
228###########################################################
229
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400230function(InitSubmodule target submodule_dir)
231 if (NOT TARGET ${target})
232 if(NOT EXISTS ${submodule_dir}/.git)
Ben Clayton55890e12020-01-31 14:07:21 +0000233 message(WARNING "
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400234 Target ${target} from submodule ${submodule_dir} missing.
Ben Clayton55890e12020-01-31 14:07:21 +0000235 Running 'git submodule update --init' to download it:
236 ")
Nicolas Capensfe5861b2018-08-03 16:01:48 -0400237
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400238 execute_process(COMMAND git -C ${SWIFTSHADER_DIR} submodule update --init ${submodule_dir})
Ben Clayton55890e12020-01-31 14:07:21 +0000239 endif()
Dan Sinclair6480d4e2019-03-11 10:48:19 -0400240 endif()
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400241endfunction()
242
Antonio Maiorano9d35d542021-02-01 16:35:07 -0500243if (SWIFTSHADER_BUILD_TESTS OR SWIFTSHADER_BUILD_BENCHMARKS)
244 set(BUILD_VULKAN_WRAPPER TRUE)
245endif()
246
247if (BUILD_VULKAN_WRAPPER)
248 InitSubmodule(glslang ${THIRD_PARTY_DIR}/glslang)
249endif()
250
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400251if (SWIFTSHADER_BUILD_TESTS)
252 InitSubmodule(gtest ${THIRD_PARTY_DIR}/googletest)
Nicolas Capensfe5861b2018-08-03 16:01:48 -0400253endif()
254
Ben Clayton55890e12020-01-31 14:07:21 +0000255if(SWIFTSHADER_BUILD_BENCHMARKS)
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400256 InitSubmodule(benchmark::benchmark ${THIRD_PARTY_DIR}/benchmark)
257endif()
Ben Clayton55890e12020-01-31 14:07:21 +0000258
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400259if(REACTOR_EMIT_DEBUG_INFO)
260 InitSubmodule(libbacktrace ${THIRD_PARTY_DIR}/libbacktrace/src)
Ben Clayton755467c2019-03-23 11:57:02 +0000261endif()
262
Nicolas Capensf53de1a2022-02-11 10:28:19 -0500263if(SWIFTSHADER_BUILD_PVR)
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400264 InitSubmodule(PVRCore ${THIRD_PARTY_DIR}/PowerVR_Examples)
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500265endif()
266
Antonio Maiorano1e2fba32020-04-15 16:02:58 -0400267if(SWIFTSHADER_BUILD_CPPDAP)
268 InitSubmodule(json ${THIRD_PARTY_DIR}/json)
269 InitSubmodule(cppdap ${THIRD_PARTY_DIR}/cppdap)
270endif()
271
Martin Troiber5ff2f732022-02-25 00:17:06 +0100272if(${REACTOR_BACKEND} STREQUAL "LLVM-Submodule")
273 InitSubmodule(llvm-submodule ${THIRD_PARTY_DIR}/llvm-project)
274endif()
275
Nicolas Capensfe5861b2018-08-03 16:01:48 -0400276###########################################################
Corentin Wallez0866b292015-12-09 13:49:40 -0500277# Convenience macros
278###########################################################
279
280# Recursively calls source_group on the files of the directory
281# so that Visual Studio has the files in a folder tree
282macro(group_all_sources directory)
Antonio Maiorano8772b422020-04-15 15:00:36 -0400283 file(GLOB files RELATIVE ${SWIFTSHADER_DIR}/${directory} ${SWIFTSHADER_DIR}/${directory}/*)
Corentin Wallez0866b292015-12-09 13:49:40 -0500284 foreach(file ${files})
Antonio Maiorano8772b422020-04-15 15:00:36 -0400285 if(IS_DIRECTORY ${SWIFTSHADER_DIR}/${directory}/${file})
Corentin Wallez0866b292015-12-09 13:49:40 -0500286 group_all_sources(${directory}/${file})
287 else()
288 string(REPLACE "/" "\\" groupname ${directory})
Antonio Maiorano8772b422020-04-15 15:00:36 -0400289 source_group(${groupname} FILES ${SWIFTSHADER_DIR}/${directory}/${file})
Corentin Wallez0866b292015-12-09 13:49:40 -0500290 endif()
291 endforeach()
292endmacro()
293
294# Takes target library and a directory where the export map is
295# and add the linker options so that only the API symbols are
296# exported.
Nicolas Capens499bb762018-06-29 13:30:57 -0400297macro(set_shared_library_export_map TARGET DIR)
Corentin Wallez0866b292015-12-09 13:49:40 -0500298 if(MSVC)
Nicolas Capens499bb762018-06-29 13:30:57 -0400299 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " /DEF:\"${DIR}/${TARGET}.def\"")
Ben Clayton8565e772019-06-10 11:58:37 +0100300 elseif(APPLE)
301 # The exported symbols list only exports the API functions and
302 # hides all the others.
303 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-exported_symbols_list ${DIR}/${TARGET}.exports")
304 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${TARGET}.exports;")
305 # Don't allow undefined symbols, unless it's a Sanitizer build.
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500306 if(NOT SWIFTSHADER_MSAN AND NOT SWIFTSHADER_ASAN AND NOT SWIFTSHADER_TSAN AND NOT SWIFTSHADER_UBSAN)
Ben Clayton8565e772019-06-10 11:58:37 +0100307 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-undefined,error")
308 endif()
David 'Digit' Turnerd3717932019-11-19 17:54:00 +0100309 elseif(LINUX OR FUCHSIA)
David 'Digit' Turner6e445042020-04-17 16:27:56 +0200310 # NOTE: The Fuchsia linker script is needed to export the vk_icdInitializeConnectToServiceCallback
311 # entry point (a private implementation detail betwen the Fuchsia Vulkan loader and the ICD).
312 if ((FUCHSIA) AND ("${TARGET}" STREQUAL "vk_swiftshader"))
313 set(LINKER_VERSION_SCRIPT "fuchsia_vk_swiftshader.lds")
314 else()
315 set(LINKER_VERSION_SCRIPT "${TARGET}.lds")
316 endif()
317
Corentin Wallez0866b292015-12-09 13:49:40 -0500318 # The version script only exports the API functions and
Nicolas Capens499bb762018-06-29 13:30:57 -0400319 # hides all the others.
David 'Digit' Turner6e445042020-04-17 16:27:56 +0200320 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=${DIR}/${LINKER_VERSION_SCRIPT}")
321 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${LINKER_VERSION_SCRIPT};")
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400322
Nicolas Capense3621dc2020-02-25 22:45:42 -0500323 # -Bsymbolic binds symbol references to their global definitions within
324 # a shared object, thereby preventing symbol preemption.
James Price126720b2020-03-03 10:20:00 -0500325 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-Bsymbolic")
Nicolas Capens517a57f2018-06-29 13:30:57 -0400326
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100327 if(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el")
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200328 # MIPS supports sysv hash-style only.
329 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--hash-style=sysv")
David 'Digit' Turnerd3717932019-11-19 17:54:00 +0100330 elseif(LINUX)
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200331 # Both hash-style are needed, because we want both gold and
332 # GNU ld to be able to read our libraries.
333 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--hash-style=both")
334 endif()
Nicolas Capens499bb762018-06-29 13:30:57 -0400335
Ben Clayton063fc022020-03-23 13:18:09 +0000336 if(NOT ${SWIFTSHADER_EMIT_COVERAGE})
337 # Gc sections is used in combination with each functions being
338 # in its own section, to reduce the binary size.
339 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections")
340 endif()
Nicolas Capens499bb762018-06-29 13:30:57 -0400341
342 # Don't allow undefined symbols, unless it's a Sanitizer build.
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500343 if(NOT SWIFTSHADER_MSAN AND NOT SWIFTSHADER_ASAN AND NOT SWIFTSHADER_TSAN AND NOT SWIFTSHADER_UBSAN)
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400344 set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined")
345 endif()
Corentin Wallez0866b292015-12-09 13:49:40 -0500346 endif()
347endmacro()
348
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500349if(SWIFTSHADER_USE_GROUP_SOURCES)
Corentin Wallez0866b292015-12-09 13:49:40 -0500350 group_all_sources(src)
351endif()
352
353###########################################################
Corentin Wallez0866b292015-12-09 13:49:40 -0500354# Compile flags
355###########################################################
356
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100357# Flags for project code (non 3rd party)
358set(SWIFTSHADER_COMPILE_OPTIONS "")
Ben Clayton063fc022020-03-23 13:18:09 +0000359set(SWIFTSHADER_LINK_FLAGS "")
360set(SWIFTSHADER_LIBS "")
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100361
Nicolas Capens6f422092015-12-23 15:12:45 -0500362macro(set_cpp_flag FLAG)
363 if(${ARGC} GREATER 1)
364 set(CMAKE_CXX_FLAGS_${ARGV1} "${CMAKE_CXX_FLAGS_${ARGV1}} ${FLAG}")
Corentin Wallez0866b292015-12-09 13:49:40 -0500365 else()
Nicolas Capens6f422092015-12-23 15:12:45 -0500366 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
Corentin Wallez0866b292015-12-09 13:49:40 -0500367 endif()
368endmacro()
369
Ben Clayton48c8a182019-05-21 20:00:20 +0100370macro(set_linker_flag FLAG)
371 if(${ARGC} GREATER 1)
Nicolas Capens5d4c9812020-07-02 10:06:25 -0400372 set(CMAKE_EXE_LINKER_FLAGS_${ARGV1} "${CMAKE_EXE_LINKER_FLAGS_${ARGV1}} ${FLAG}")
Nicolas Capens268fd732020-10-08 16:46:48 -0400373 set(CMAKE_SHARED_LINKER_FLAGS_${ARGV1} "${CMAKE_EXE_LINKER_FLAGS_${ARGV1}} ${FLAG}")
Ben Clayton48c8a182019-05-21 20:00:20 +0100374 else()
375 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
Nicolas Capens268fd732020-10-08 16:46:48 -0400376 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
Ben Clayton48c8a182019-05-21 20:00:20 +0100377 endif()
378endmacro()
379
Corentin Wallez0866b292015-12-09 13:49:40 -0500380if(MSVC)
381 set_cpp_flag("/MP")
382 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400383 add_definitions(-D_SCL_SECURE_NO_WARNINGS)
Nicolas Capens4c9f04b2019-01-31 22:09:03 -0500384 add_definitions(-D_SBCS) # Single Byte Character Set (ASCII)
Ben Clayton30b6b592019-08-07 15:04:11 +0100385 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE) # Disable MSVC warnings about std::aligned_storage being broken before VS 2017 15.8
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400386
Nicolas Capens5d4c9812020-07-02 10:06:25 -0400387 set_linker_flag("/DEBUG:FASTLINK" DEBUG)
388 set_linker_flag("/DEBUG:FASTLINK" RELWITHDEBINFO)
Nicolas Capensf554c542020-01-09 17:19:35 +0000389
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400390 # Disable specific warnings
391 # TODO: Not all of these should be disabled, but for now, we want a warning-free msvc build. Remove these one by one
392 # and fix the actual warnings in code.
393 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
394 "/wd4005" # 'identifier' : macro redefinition
395 "/wd4018" # 'expression' : signed/unsigned mismatch
Ben Clayton4d4a1902019-05-15 11:15:42 +0100396 "/wd4065" # switch statement contains 'default' but no 'case' labels
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400397 "/wd4141" # 'modifier' : used more than once
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400398 "/wd4244" # 'conversion' conversion from 'type1' to 'type2', possible loss of data
399 "/wd4267" # 'var' : conversion from 'size_t' to 'type', possible loss of data
400 "/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
401 "/wd4309" # 'conversion' : truncation of constant value
402 "/wd4624" # 'derived class' : destructor was implicitly defined as deleted because a base class destructor is inaccessible or deleted
403 "/wd4800" # 'type' : forcing value to bool 'true' or 'false' (performance warning)
404 "/wd4838" # conversion from 'type_1' to 'type_2' requires a narrowing conversion
405 "/wd5030" # attribute 'attribute' is not recognized
406 "/wd5038" # data member 'member1' will be initialized after data member 'member2' data member 'member' will be initialized after base class 'base_class'
407 )
408
409 # Treat specific warnings as errors
410 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
411 "/we4018" # 'expression' : signed/unsigned mismatch
Alexis Hetu6bd05092021-11-08 14:05:04 -0500412 "/we4062" # enumerator 'identifier' in switch of enum 'enumeration' is not handled
Antonio Maiorano23da0732019-05-14 22:32:16 -0400413 "/we4471" # 'enumeration': a forward declaration of an unscoped enumeration must have an underlying type (int assumed)
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400414 "/we4838" # conversion from 'type_1' to 'type_2' requires a narrowing conversion
415 "/we5038" # data member 'member1' will be initialized after data member 'member2' data member 'member' will be initialized after base class 'base_class'
Nicolas Capens43f1d972021-11-12 00:10:48 -0500416 "/we4101" # 'identifier' : unreferenced local variable
Antonio Maiorano5bce1f42019-05-10 16:03:49 -0400417 )
Corentin Wallez0866b292015-12-09 13:49:40 -0500418else()
Ben Claytona5f07632020-02-04 11:43:25 +0000419 # Explicitly enable these warnings.
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100420 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100421 "-Wall"
Ben Clayton8a983f72019-06-18 17:56:36 +0100422 "-Wreorder"
423 "-Wsign-compare"
424 "-Wmissing-braces"
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100425 )
Corentin Wallez0866b292015-12-09 13:49:40 -0500426
James Rumble69deca62021-07-01 11:39:34 +0100427 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
428 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
429 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
430 "-Wdeprecated-copy" # implicit copy constructor for 'X' is deprecated because of user-declared copy assignment operator.
Nicolas Capens02a91c92021-08-20 03:49:24 -0400431 )
James Rumble69deca62021-07-01 11:39:34 +0100432 endif()
433 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100434 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
Ben Clayton54709882020-04-16 10:40:08 +0100435 "-Wextra"
436 "-Wunreachable-code-loop-increment"
Ben Clayton8a983f72019-06-18 17:56:36 +0100437 "-Wunused-lambda-capture"
438 "-Wstring-conversion"
439 "-Wextra-semi"
440 "-Wignored-qualifiers"
James Rumble69deca62021-07-01 11:39:34 +0100441 "-Wdeprecated-copy" # implicit copy constructor for 'X' is deprecated because of user-declared copy assignment operator.
Nicolas Capensff91ac52021-11-29 18:29:01 +0000442 # TODO(b/208256248): Avoid exit-time destructor.
443 #"-Wexit-time-destructors" # declaration requires an exit-time destructor
Ben Claytona5f07632020-02-04 11:43:25 +0000444 )
445 endif()
446
Ben Clayton063fc022020-03-23 13:18:09 +0000447 if (SWIFTSHADER_EMIT_COVERAGE)
448 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
449 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "--coverage")
450 list(APPEND SWIFTSHADER_LIBS "gcov")
451 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
452 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fprofile-instr-generate" "-fcoverage-mapping")
453 list(APPEND SWIFTSHADER_LINK_FLAGS "-fprofile-instr-generate" "-fcoverage-mapping")
454 else()
455 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
456 endif()
457 endif()
458
Nicolas Capensd2bdde22021-06-17 22:14:37 -0400459 # Disable pedantic warnings
Ben Claytona5f07632020-02-04 11:43:25 +0000460 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
461 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
462 "-Wno-ignored-attributes" # ignoring attributes on template argument 'X'
463 "-Wno-attributes" # 'X' attribute ignored
464 "-Wno-strict-aliasing" # dereferencing type-punned pointer will break strict-aliasing rules
465 "-Wno-comment" # multi-line comment
466 )
467 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
468 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
469 "-Wno-init-list-lifetime" # assignment from temporary initializer_list does not extend the lifetime of the underlying array
470 )
471 endif()
472 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
473 list(APPEND SWIFTSHADER_COMPILE_OPTIONS
474 "-Wno-unneeded-internal-declaration" # function 'X' is not needed and will not be emitted
475 "-Wno-unused-private-field" # private field 'offset' is not used - TODO: Consider enabling this once Vulkan is further implemented.
476 "-Wno-comment" # multi-line comment
Ben Claytona7bc2b92020-03-26 11:24:49 +0000477 "-Wno-extra-semi" # extra ';' after member function definition
Ben Clayton54709882020-04-16 10:40:08 +0100478 "-Wno-unused-parameter" # unused parameter 'X'
Ben Claytona5f07632020-02-04 11:43:25 +0000479
Nicolas Capens67180a02019-06-17 15:27:03 -0400480 # Silence errors caused by unknown warnings when building with older
481 # versions of Clang. This demands checking that warnings added above
482 # are spelled correctly and work as intended!
483 "-Wno-unknown-warning-option"
Ben Clayton4ceb77d2019-04-24 12:09:59 +0100484 )
Nicolas Capens825d3442018-11-06 23:50:05 -0500485 endif()
486
Nicolas Capens499bb762018-06-29 13:30:57 -0400487 if(ARCH STREQUAL "x86")
Corentin Wallez0866b292015-12-09 13:49:40 -0500488 set_cpp_flag("-m32")
489 set_cpp_flag("-msse2")
Nicolas Capens0424edc2018-01-03 14:06:30 -0500490 set_cpp_flag("-mfpmath=sse")
491 set_cpp_flag("-march=pentium4")
492 set_cpp_flag("-mtune=generic")
Corentin Wallez0866b292015-12-09 13:49:40 -0500493 endif()
Nicolas Capens499bb762018-06-29 13:30:57 -0400494 if(ARCH STREQUAL "x86_64")
Corentin Wallez0866b292015-12-09 13:49:40 -0500495 set_cpp_flag("-m64")
496 set_cpp_flag("-fPIC")
Nicolas Capens0424edc2018-01-03 14:06:30 -0500497 set_cpp_flag("-march=x86-64")
498 set_cpp_flag("-mtune=generic")
Corentin Wallez0866b292015-12-09 13:49:40 -0500499 endif()
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200500 if(ARCH STREQUAL "mipsel")
Jiaxun Yang55275c32020-02-09 14:52:42 +0800501 set_cpp_flag("-EL")
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200502 set_cpp_flag("-march=mips32r2")
503 set_cpp_flag("-fPIC")
504 set_cpp_flag("-mhard-float")
505 set_cpp_flag("-mfp32")
Jiaxun Yang55275c32020-02-09 14:52:42 +0800506 set_cpp_flag("-mxgot")
Gordana Cmiljanovic082dfec2018-10-19 11:36:15 +0200507 endif()
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100508 if(ARCH STREQUAL "mips64el")
Jiaxun Yang55275c32020-02-09 14:52:42 +0800509 set_cpp_flag("-EL")
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100510 set_cpp_flag("-march=mips64r2")
511 set_cpp_flag("-mabi=64")
512 set_cpp_flag("-fPIC")
Jiaxun Yang55275c32020-02-09 14:52:42 +0800513 set_cpp_flag("-mxgot")
Gordana Cmiljanovic20622c02018-11-05 15:00:11 +0100514 endif()
Nicolas Capens499bb762018-06-29 13:30:57 -0400515
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500516 if(SWIFTSHADER_LESS_DEBUG_INFO)
Paul Thomson09b50792019-10-17 12:55:56 +0100517 # Use -g1 to be able to get stack traces
518 set_cpp_flag("-g -g1" DEBUG)
519 set_cpp_flag("-g -g1" RELWITHDEBINFO)
520 else()
521 # Use -g3 to have even more debug info
522 set_cpp_flag("-g -g3" DEBUG)
523 set_cpp_flag("-g -g3" RELWITHDEBINFO)
524 endif()
525
Ben Clayton09a91e42019-02-05 17:58:38 +0000526 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
527 # Treated as an unused argument with clang
528 set_cpp_flag("-s" RELEASE)
529 endif()
Corentin Wallez0866b292015-12-09 13:49:40 -0500530
531 # For distribution it is more important to be slim than super optimized
Alexis Hetu2c0546d2017-05-24 11:16:26 -0400532 set_cpp_flag("-Os" RELEASE)
533 set_cpp_flag("-Os" RELWITHDEBINFO)
Corentin Wallez0866b292015-12-09 13:49:40 -0500534
535 set_cpp_flag("-DNDEBUG" RELEASE)
536 set_cpp_flag("-DNDEBUG" RELWITHDEBINFO)
Corentin Wallez0866b292015-12-09 13:49:40 -0500537
538 # Put each variable and function in its own section so that when linking
539 # with -gc-sections unused functions and variables are removed.
540 set_cpp_flag("-ffunction-sections" RELEASE)
541 set_cpp_flag("-fdata-sections" RELEASE)
542 set_cpp_flag("-fomit-frame-pointer" RELEASE)
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400543
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500544 if(SWIFTSHADER_MSAN)
Nicolas Capens7a0ca4e2020-11-30 10:08:59 -0500545 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
546 message(FATAL_ERROR " \n"
547 " MemorySanitizer usage requires compiling with Clang.")
548 endif()
549
Nicolas Capens268fd732020-10-08 16:46:48 -0400550 if(NOT DEFINED ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH})
Nicolas Capens268fd732020-10-08 16:46:48 -0400551 message(FATAL_ERROR " \n"
552 " MemorySanitizer usage requires an instrumented build of libc++.\n"
553 " Set the SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH environment variable to the\n"
554 " build output path. See\n"
555 " https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo#instrumented-libc\n"
556 " for details on how to build an MSan instrumented libc++.")
557 endif()
558
Ben Claytondae97922019-05-17 12:09:31 +0100559 set_cpp_flag("-fsanitize=memory")
Ben Clayton48c8a182019-05-21 20:00:20 +0100560 set_linker_flag("-fsanitize=memory")
Nicolas Capens268fd732020-10-08 16:46:48 -0400561 set_cpp_flag("-stdlib=libc++")
562 set_linker_flag("-L$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/lib")
563 set_cpp_flag("-I$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/include")
564 set_cpp_flag("-I$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/include/c++/v1")
565 set_linker_flag("-Wl,-rpath,$ENV{SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH}/lib")
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500566 elseif(SWIFTSHADER_ASAN)
Ben Claytondae97922019-05-17 12:09:31 +0100567 set_cpp_flag("-fsanitize=address")
Ben Clayton48c8a182019-05-21 20:00:20 +0100568 set_linker_flag("-fsanitize=address")
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500569 elseif(SWIFTSHADER_TSAN)
Ben Claytondae97922019-05-17 12:09:31 +0100570 set_cpp_flag("-fsanitize=thread")
Ben Clayton48c8a182019-05-21 20:00:20 +0100571 set_linker_flag("-fsanitize=thread")
Sean Risserf6d3cbb2020-01-08 14:44:53 -0500572 elseif(SWIFTSHADER_UBSAN)
Ben Claytondae97922019-05-17 12:09:31 +0100573 set_cpp_flag("-fsanitize=undefined")
Ben Clayton48c8a182019-05-21 20:00:20 +0100574 set_linker_flag("-fsanitize=undefined")
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400575 endif()
Corentin Wallez0866b292015-12-09 13:49:40 -0500576endif()
577
Antonio Maiorano4b8b0782020-03-23 14:11:01 -0400578if(SWIFTSHADER_DCHECK_ALWAYS_ON)
579 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DDCHECK_ALWAYS_ON")
580endif()
581
Nicolas Capens8c13b2f2020-03-06 01:12:01 -0500582if(SWIFTSHADER_WARNINGS_AS_ERRORS)
583 if(MSVC)
584 set(WARNINGS_AS_ERRORS "/WX") # Treat all warnings as errors
585 else()
586 set(WARNINGS_AS_ERRORS "-Werror") # Treat all warnings as errors
587 endif()
588endif()
589
Nicolas Capens8dceadd2020-11-06 14:36:13 -0500590# Enable Reactor Print() functionality in Debug/RelWithDebInfo builds or when explicitly enabled.
591if(CMAKE_BUILD_TYPE MATCHES "Deb")
592 set(REACTOR_ENABLE_PRINT TRUE)
593endif()
594
Antonio Maioranof448d8e2019-04-26 16:19:16 -0400595if(REACTOR_EMIT_PRINT_LOCATION)
Antonio Maiorano415d1812020-02-11 16:22:55 -0500596 # This feature depends on REACTOR_EMIT_DEBUG_INFO and REACTOR_ENABLE_PRINT
Nicolas Capens8dceadd2020-11-06 14:36:13 -0500597 set(REACTOR_EMIT_DEBUG_INFO TRUE)
598 set(REACTOR_ENABLE_PRINT TRUE)
Antonio Maioranof448d8e2019-04-26 16:19:16 -0400599 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_EMIT_PRINT_LOCATION")
600endif()
601
Antonio Maiorano6f6ca292020-11-27 15:40:15 -0500602if(REACTOR_EMIT_ASM_FILE)
603 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_EMIT_ASM_FILE")
604endif()
605
Antonio Maioranof448d8e2019-04-26 16:19:16 -0400606if(REACTOR_EMIT_DEBUG_INFO)
607 message(WARNING "REACTOR_EMIT_DEBUG_INFO is enabled. This will likely affect performance.")
608 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_DEBUG_INFO")
609endif()
610
Antonio Maiorano415d1812020-02-11 16:22:55 -0500611if(REACTOR_ENABLE_PRINT)
612 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_PRINT")
613endif()
614
Ben Clayton5375f472019-06-24 13:33:11 +0100615if(REACTOR_VERIFY_LLVM_IR)
616 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_LLVM_IR_VERIFICATION")
617endif()
618
Antonio Maiorano062dc182019-12-09 11:52:31 -0500619if(REACTOR_DEFAULT_OPT_LEVEL)
620 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DREACTOR_DEFAULT_OPT_LEVEL=${REACTOR_DEFAULT_OPT_LEVEL}")
621endif()
622
Ben Claytoncbb5a102020-10-03 11:15:47 +0100623if(DEFINED SWIFTSHADER_LOGGING_LEVEL)
624 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DSWIFTSHADER_LOGGING_LEVEL=${SWIFTSHADER_LOGGING_LEVEL}")
625endif()
626
Nicolas Capensbf8fd5b2018-06-21 00:42:00 -0400627if(WIN32)
Corentin Wallez0866b292015-12-09 13:49:40 -0500628 add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
Nicolas Capens6f422092015-12-23 15:12:45 -0500629 set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
Corentin Wallez0866b292015-12-09 13:49:40 -0500630endif()
631
Antonio Maiorano61022762020-03-30 11:11:16 -0400632set(USE_EXCEPTIONS
633 ${REACTOR_EMIT_DEBUG_INFO} # boost::stacktrace uses exceptions
634)
635if(NOT MSVC)
636 if (${USE_EXCEPTIONS})
637 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fexceptions")
638 else()
639 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-fno-exceptions")
640 endif()
641endif()
Antonio Maiorano9418b512020-04-08 23:18:13 -0400642unset(USE_EXCEPTIONS)
Antonio Maiorano61022762020-03-30 11:11:16 -0400643
Corentin Wallez0866b292015-12-09 13:49:40 -0500644###########################################################
Antonio Maioranofa8f48d2020-03-30 16:41:48 -0400645# libbacktrace and boost
646###########################################################
647if(REACTOR_EMIT_DEBUG_INFO)
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400648 add_subdirectory(${THIRD_PARTY_DIR}/libbacktrace EXCLUDE_FROM_ALL)
649 add_subdirectory(${THIRD_PARTY_DIR}/boost EXCLUDE_FROM_ALL)
Antonio Maioranofa8f48d2020-03-30 16:41:48 -0400650endif()
651
652###########################################################
Corentin Wallez0866b292015-12-09 13:49:40 -0500653# LLVM
654###########################################################
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400655add_subdirectory(${THIRD_PARTY_DIR}/llvm-${SWIFTSHADER_LLVM_VERSION} EXCLUDE_FROM_ALL)
Antonio Maiorano0f14b7a2020-09-11 10:02:16 -0400656set_target_properties(llvm PROPERTIES FOLDER "third_party")
Ben Clayton8f71f732019-02-01 09:38:45 +0000657
Antonio Maiorano4bde1c32020-03-27 15:01:53 -0400658###########################################################
Martin Troiber5ff2f732022-02-25 00:17:06 +0100659# LLVM-Submodule
660###########################################################
661if(${REACTOR_BACKEND} STREQUAL "LLVM-Submodule")
662 set(LLVM_INCLUDE_TESTS FALSE)
663 set(LLVM_ENABLE_RTTI TRUE)
664 add_subdirectory(${THIRD_PARTY_DIR}/llvm-project/llvm EXCLUDE_FROM_ALL)
665 if(ARCH STREQUAL "aarch64")
666 llvm_map_components_to_libnames(llvm_libs orcjit aarch64asmparser aarch64codegen)
667 elseif(ARCH STREQUAL "arm")
668 llvm_map_components_to_libnames(llvm_libs orcjit armasmparser armcodegen)
669 elseif(ARCH MATCHES "mips*")
670 llvm_map_components_to_libnames(llvm_libs orcjit mipsasmparser mipscodegen)
671 elseif(ARCH STREQUAL "ppc64le")
672 llvm_map_components_to_libnames(llvm_libs orcjit powerpcasmparser powerpccodegen)
673 elseif(ARCH MATCHES "x86*")
674 llvm_map_components_to_libnames(llvm_libs orcjit x86asmparser x86codegen)
675 endif()
676 set_target_properties(${llvm_libs} PROPERTIES FOLDER "third_party")
677endif()
678
679###########################################################
Antonio Maiorano4bde1c32020-03-27 15:01:53 -0400680# Subzero
681###########################################################
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400682add_subdirectory(${THIRD_PARTY_DIR}/llvm-subzero EXCLUDE_FROM_ALL)
683add_subdirectory(${THIRD_PARTY_DIR}/subzero EXCLUDE_FROM_ALL)
Antonio Maiorano0f14b7a2020-09-11 10:02:16 -0400684set_target_properties(llvm-subzero PROPERTIES FOLDER "third_party")
685set_target_properties(subzero PROPERTIES FOLDER "third_party")
Antonio Maiorano8bce0672020-02-28 13:13:45 -0500686
687###########################################################
688# marl
689###########################################################
Nicolas Capens4625f842021-12-08 14:23:59 -0500690set(MARL_THIRD_PARTY_DIR ${THIRD_PARTY_DIR})
691add_subdirectory(${THIRD_PARTY_DIR}/marl)
692set_target_properties(marl PROPERTIES FOLDER "third_party")
Antonio Maiorano8bce0672020-02-28 13:13:45 -0500693
Ben Clayton377573c2020-04-03 20:36:40 +0100694if(MARL_THREAD_SAFETY_ANALYSIS_SUPPORTED)
695 list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-Wthread-safety")
696endif()
697
Antonio Maiorano8bce0672020-02-28 13:13:45 -0500698###########################################################
699# cppdap
700###########################################################
701if(SWIFTSHADER_BUILD_CPPDAP)
702 set(CPPDAP_THIRD_PARTY_DIR ${THIRD_PARTY_DIR})
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400703 add_subdirectory(${THIRD_PARTY_DIR}/cppdap)
Antonio Maiorano8bce0672020-02-28 13:13:45 -0500704endif()
705
Antonio Maioranob02a7082020-03-30 21:55:20 -0400706###########################################################
707# astc-encoder
708###########################################################
709if(SWIFTSHADER_ENABLE_ASTC)
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400710 add_subdirectory(${THIRD_PARTY_DIR}/astc-encoder)
Antonio Maiorano0f14b7a2020-09-11 10:02:16 -0400711 set_target_properties(astc-encoder PROPERTIES FOLDER "third_party")
Antonio Maioranob02a7082020-03-30 21:55:20 -0400712endif()
Nicolas Capens19291ef2017-01-09 13:35:14 -0500713
Nicolas Capensf53adbd2017-01-06 12:47:46 -0500714###########################################################
Antonio Maiorano8f02f582020-03-31 11:01:43 -0400715# gtest and gmock
716###########################################################
717if(SWIFTSHADER_BUILD_TESTS)
718 # For Win32, force gtest to match our CRT (shared)
719 set(gtest_force_shared_crt TRUE CACHE BOOL "" FORCE)
Nicolas Capens6d34a6c2021-12-10 12:55:44 -0500720 set(INSTALL_GTEST FALSE CACHE BOOL "" FORCE)
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400721 add_subdirectory(${THIRD_PARTY_DIR}/googletest EXCLUDE_FROM_ALL)
Antonio Maiorano8f02f582020-03-31 11:01:43 -0400722 # gtest finds python, which picks python 2 first, if present.
723 # We need to undo this so that SPIR-V can later find python3.
724 unset(PYTHON_EXECUTABLE CACHE)
Antonio Maiorano0f14b7a2020-09-11 10:02:16 -0400725 set_target_properties(gmock PROPERTIES FOLDER "third_party")
726 set_target_properties(gmock_main PROPERTIES FOLDER "third_party")
727 set_target_properties(gtest PROPERTIES FOLDER "third_party")
728 set_target_properties(gtest_main PROPERTIES FOLDER "third_party")
Antonio Maiorano8f02f582020-03-31 11:01:43 -0400729endif()
730
731###########################################################
Corentin Wallez0866b292015-12-09 13:49:40 -0500732# File Lists
733###########################################################
734
Corentin Wallez0866b292015-12-09 13:49:40 -0500735###########################################################
736# Append OS specific files to lists
737###########################################################
738
739if(WIN32)
Corentin Wallez0866b292015-12-09 13:49:40 -0500740 set(OS_LIBS odbc32 odbccp32 WS2_32 dxguid)
741elseif(LINUX)
Nicolas Capens681d97b2016-05-17 16:02:32 -0400742 set(OS_LIBS dl pthread)
Nicolas Caramellia681d122020-07-20 23:47:56 +0200743 if(SWIFTSHADER_BUILD_WSI_WAYLAND)
744 list(APPEND OS_LIBS "${WAYLAND}")
745 endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
Nicolas Caramelli08596c42020-08-01 07:55:00 +0200746 if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
747 list(APPEND OS_LIBS "${DIRECTFB}")
748 include_directories(${DIRECTFB_INCLUDE_DIR}/directfb)
749 endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
Nicolas Caramelli937395c2021-01-06 21:00:18 +0100750 if(SWIFTSHADER_BUILD_WSI_D2D)
751 list(APPEND OS_LIBS "${D2D}")
752 include_directories(${D2D_INCLUDE_DIR}/libdrm)
753 endif(SWIFTSHADER_BUILD_WSI_D2D)
David 'Digit' Turnerd3717932019-11-19 17:54:00 +0100754elseif(FUCHSIA)
755 set(OS_LIBS zircon)
Corentin Wallezcd0a4572015-12-10 15:59:28 -0500756elseif(APPLE)
757 find_library(COCOA_FRAMEWORK Cocoa)
758 find_library(QUARTZ_FRAMEWORK Quartz)
Alexis Hetud23cf632018-04-10 10:48:42 -0400759 find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
760 find_library(IOSURFACE_FRAMEWORK IOSurface)
Corentin Wallezcb586622020-03-27 17:38:29 +0100761 find_library(METAL_FRAMEWORK Metal)
762 set(OS_LIBS "${COCOA_FRAMEWORK}" "${QUARTZ_FRAMEWORK}" "${CORE_FOUNDATION_FRAMEWORK}" "${IOSURFACE_FRAMEWORK}" "${METAL_FRAMEWORK}")
Corentin Wallez0866b292015-12-09 13:49:40 -0500763endif()
764
765###########################################################
Nicolas Capens5a105bc2015-12-22 22:04:28 -0500766# SwiftShader Targets
Corentin Wallez0866b292015-12-09 13:49:40 -0500767###########################################################
768
Antonio Maioranofa8f48d2020-03-30 16:41:48 -0400769add_subdirectory(src/Reactor) # Add ReactorSubzero and ReactorLLVM targets
Nicolas Capense329f012020-03-13 14:54:21 +0000770
Ben Claytonb99bc1f2019-04-15 13:56:08 -0400771if(${REACTOR_BACKEND} STREQUAL "LLVM")
Nicolas Capens0adcf042022-02-06 08:17:42 -0500772 add_library(Reactor ALIAS ReactorLLVM)
Martin Troiber5ff2f732022-02-25 00:17:06 +0100773elseif(${REACTOR_BACKEND} STREQUAL "LLVM-Submodule")
774 add_library(Reactor ALIAS ReactorLLVMSubmodule)
Nicolas Capensf53adbd2017-01-06 12:47:46 -0500775elseif(${REACTOR_BACKEND} STREQUAL "Subzero")
Nicolas Capens0adcf042022-02-06 08:17:42 -0500776 add_library(Reactor ALIAS ReactorSubzero)
Nicolas Capensf53adbd2017-01-06 12:47:46 -0500777else()
Martin Troiber5ff2f732022-02-25 00:17:06 +0100778 message(FATAL_ERROR "REACTOR_BACKEND must be 'LLVM', 'LLVM-Submodule' or 'Subzero'")
Nicolas Capensf53adbd2017-01-06 12:47:46 -0500779endif()
Corentin Wallez0866b292015-12-09 13:49:40 -0500780
Nicolas Capens4625f842021-12-08 14:23:59 -0500781if (NOT TARGET SPIRV-Tools)
782 # This variable is also used by SPIRV-Tools to locate SPIRV-Headers
783 set(SPIRV-Headers_SOURCE_DIR "${THIRD_PARTY_DIR}/SPIRV-Headers")
784 set(SPIRV_SKIP_TESTS TRUE CACHE BOOL "" FORCE)
785 set(SPIRV_SKIP_EXECUTABLES TRUE CACHE BOOL "" FORCE)
786 add_subdirectory(${THIRD_PARTY_DIR}/SPIRV-Tools) # Add SPIRV-Tools target
Corentin Wallez0866b292015-12-09 13:49:40 -0500787endif()
788
Nicolas Capens4625f842021-12-08 14:23:59 -0500789# Add a vk_base interface library for shared vulkan build options.
790# TODO: Create src/Base and make this a lib target, and move stuff from
791# src/Vulkan into it that is needed by vk_pipeline, vk_device, and vk_wsi.
792add_library(vk_base INTERFACE)
793
794if(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER)
795 target_compile_definitions(vk_base INTERFACE "ENABLE_VK_DEBUGGER")
Corentin Wallez0866b292015-12-09 13:49:40 -0500796endif()
797
Nicolas Capens4625f842021-12-08 14:23:59 -0500798if(WIN32)
799 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_WIN32_KHR")
800elseif(LINUX)
Nicolas Capens9c16e142022-04-05 00:27:05 -0400801 if(HAVE_XCB_H)
Nicolas Capens4625f842021-12-08 14:23:59 -0500802 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_XCB_KHR")
David 'Digit' Turnerd3717932019-11-19 17:54:00 +0100803 endif()
Nicolas Capens4625f842021-12-08 14:23:59 -0500804 if(SWIFTSHADER_BUILD_WSI_WAYLAND)
805 if(WAYLAND)
806 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_WAYLAND_KHR")
Ben Clayton1e8486b2020-01-22 17:01:52 +0000807 endif()
Nicolas Capens4625f842021-12-08 14:23:59 -0500808 endif(SWIFTSHADER_BUILD_WSI_WAYLAND)
809 if(SWIFTSHADER_BUILD_WSI_DIRECTFB)
810 if(DIRECTFB AND DIRECTFB_INCLUDE_DIR)
811 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_DIRECTFB_EXT")
Ben Clayton1e8486b2020-01-22 17:01:52 +0000812 endif()
Nicolas Capens4625f842021-12-08 14:23:59 -0500813 endif(SWIFTSHADER_BUILD_WSI_DIRECTFB)
814 if(SWIFTSHADER_BUILD_WSI_D2D)
815 if(D2D)
816 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_DISPLAY_KHR")
817 endif()
818 endif(SWIFTSHADER_BUILD_WSI_D2D)
819elseif(APPLE)
820 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_MACOS_MVK")
821 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_METAL_EXT")
822elseif(FUCHSIA)
823 target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_FUCHSIA")
824else()
825 message(FATAL_ERROR "Platform does not support Vulkan yet")
826endif()
Nicolas Capensd3545372019-08-09 13:59:18 -0400827
Nicolas Capens4625f842021-12-08 14:23:59 -0500828add_subdirectory(src/System) # Add vk_system target
829add_subdirectory(src/Pipeline) # Add vk_pipeline target
830add_subdirectory(src/WSI) # Add vk_wsi target
831add_subdirectory(src/Device) # Add vk_device target
832add_subdirectory(src/Vulkan) # Add vk_swiftshader target
Ben Claytonac736122020-03-24 17:48:31 +0000833
Nicolas Capens4625f842021-12-08 14:23:59 -0500834if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND # turbo-cov is only useful for clang coverage info
835 SWIFTSHADER_EMIT_COVERAGE)
836 add_subdirectory(${TESTS_DIR}/regres/cov/turbo-cov)
Nicolas Capens29a98092019-04-03 14:35:10 -0400837endif()
Chris Forbes3d27f2e2018-09-26 09:24:39 -0700838
Corentin Wallez0866b292015-12-09 13:49:40 -0500839###########################################################
Nicolas Capens29a98092019-04-03 14:35:10 -0400840# Sample programs and tests
Corentin Wallez0866b292015-12-09 13:49:40 -0500841###########################################################
842
Antonio Maiorano79248ab2020-07-23 11:24:33 -0400843# TODO(b/161976310): Add support for building PowerVR on MacOS
Nicolas Capensf53de1a2022-02-11 10:28:19 -0500844if(APPLE AND SWIFTSHADER_BUILD_PVR)
Antonio Maiorano79248ab2020-07-23 11:24:33 -0400845 message(WARNING "Building PowerVR examples for SwiftShader is not yet supported on Apple platforms.")
846 set(SWIFTSHADER_BUILD_PVR FALSE)
847endif()
848
Nicolas Capensf53de1a2022-02-11 10:28:19 -0500849if(SWIFTSHADER_BUILD_PVR)
Nicolas Capens51b28002020-01-30 16:41:00 -0500850 if(UNIX AND NOT APPLE)
851 set(PVR_WINDOW_SYSTEM XCB)
Nicolas Capens7e857092020-03-06 13:21:10 -0500852
853 # Set the RPATH of the next defined build targets to $ORIGIN,
854 # allowing them to load shared libraries from the execution directory.
855 set(CMAKE_BUILD_RPATH "$ORIGIN")
Nicolas Capens51b28002020-01-30 16:41:00 -0500856 endif()
857
Nicolas Capens13943ba2020-03-17 22:36:24 -0400858 set(PVR_BUILD_EXAMPLES TRUE CACHE BOOL "Build the PowerVR SDK Examples" FORCE)
Nicolas Capens4625f842021-12-08 14:23:59 -0500859 set(PVR_BUILD_OPENGLES_EXAMPLES FALSE CACHE BOOL "Build the OpenGLES PowerVR SDK Examples" FORCE)
860 set(PVR_BUILD_VULKAN_EXAMPLES TRUE CACHE BOOL "Build the Vulkan PowerVR SDK Examples" FORCE)
861 set(PVR_BUILD_OPENCL_EXAMPLES FALSE CACHE BOOL "Build the OpenCL PowerVR SDK Examples" FORCE)
862 set(PVR_BUILD_OPENGLES2_EXAMPLES FALSE CACHE BOOL "Only build OpenGL ES 2.0 examples" FORCE)
Antonio Maioranoda4315d2020-04-15 13:49:56 -0400863 add_subdirectory(${THIRD_PARTY_DIR}/PowerVR_Examples)
Nicolas Capens51b28002020-01-30 16:41:00 -0500864
Nicolas Capens51b28002020-01-30 16:41:00 -0500865 # Samples known to work well
866 set(PVR_VULKAN_TARGET_GOOD
867 VulkanBumpmap
Nicolas Capens3702e012020-03-30 09:08:47 -0400868 VulkanExampleUI
869 VulkanGaussianBlur
Nicolas Capens51b28002020-01-30 16:41:00 -0500870 VulkanGlass
871 VulkanGnomeHorde
872 VulkanHelloAPI
873 VulkanImageBasedLighting
Nicolas Capens3702e012020-03-30 09:08:47 -0400874 VulkanIntroducingPVRUtils
Nicolas Capens51b28002020-01-30 16:41:00 -0500875 VulkanMultiSampling
Nicolas Capens3702e012020-03-30 09:08:47 -0400876 VulkanNavigation2D
877 VulkanParticleSystem
Nicolas Capens51b28002020-01-30 16:41:00 -0500878 VulkanSkinning
879 )
880
881 set(PVR_VULKAN_TARGET_OTHER
882 VulkanDeferredShading
883 VulkanDeferredShadingPFX
Nicolas Capens51b28002020-01-30 16:41:00 -0500884 VulkanGameOfLife
Nicolas Capens51b28002020-01-30 16:41:00 -0500885 VulkanIBLMapsGenerator
886 VulkanIMGTextureFilterCubic
887 VulkanIntroducingPVRShell
Nicolas Capens51b28002020-01-30 16:41:00 -0500888 VulkanIntroducingPVRVk
889 VulkanIntroducingUIRenderer
890 VulkanMultithreading
Nicolas Capens51b28002020-01-30 16:41:00 -0500891 VulkanNavigation3D
Nicolas Capens51b28002020-01-30 16:41:00 -0500892 VulkanPostProcessing
893 VulkanPVRScopeExample
894 VulkanPVRScopeRemote
895 )
896
897 set(PVR_TARGET_OTHER
898 glslang
899 glslangValidator
900 glslang-default-resource-limits
Nicolas Capens51b28002020-01-30 16:41:00 -0500901 OSDependent
Nicolas Capens51b28002020-01-30 16:41:00 -0500902 pugixml
903 PVRAssets
904 PVRCamera
905 PVRCore
906 PVRPfx
907 PVRShell
Nicolas Capens51b28002020-01-30 16:41:00 -0500908 PVRUtilsVk
909 PVRVk
910 SPIRV
911 spirv-remap
912 SPVRemapper
913 uninstall
914 )
915
916 set(PVR_VULKAN_TARGET
917 ${PVR_VULKAN_TARGET_GOOD}
918 ${PVR_VULKAN_TARGET_OTHER}
919 )
920
921 foreach(pvr_target ${PVR_VULKAN_TARGET})
922 add_dependencies(${pvr_target} vk_swiftshader)
923 endforeach()
924
Nicolas Capens4625f842021-12-08 14:23:59 -0500925 foreach(pvr_target ${PVR_VULKAN_TARGET_GOOD})
Nicolas Capens51b28002020-01-30 16:41:00 -0500926 set_target_properties(${pvr_target} PROPERTIES FOLDER Samples)
927 endforeach()
928
Nicolas Capens4625f842021-12-08 14:23:59 -0500929 foreach(pvr_target ${PVR_TARGET_OTHER} ${PVR_VULKAN_TARGET_OTHER})
Nicolas Capens51b28002020-01-30 16:41:00 -0500930 set_target_properties(${pvr_target} PROPERTIES FOLDER Samples/PowerVR-Build)
931 endforeach()
Corentin Wallezcb586622020-03-27 17:38:29 +0100932endif()
Nicolas Capensf324fe52020-06-05 16:10:07 -0400933
Antonio Maiorano9d35d542021-02-01 16:35:07 -0500934if(BUILD_VULKAN_WRAPPER)
935 if (NOT TARGET glslang)
936 add_subdirectory(${THIRD_PARTY_DIR}/glslang)
937 endif()
938 add_subdirectory(${TESTS_DIR}/VulkanWrapper) # Add VulkanWrapper target
939endif()
940
Nicolas Capensf324fe52020-06-05 16:10:07 -0400941if(SWIFTSHADER_BUILD_TESTS)
942 add_subdirectory(${TESTS_DIR}/ReactorUnitTests) # Add ReactorUnitTests target
Nicolas Capensf324fe52020-06-05 16:10:07 -0400943 add_subdirectory(${TESTS_DIR}/MathUnitTests) # Add math-unittests target
944 add_subdirectory(${TESTS_DIR}/SystemUnitTests) # Add system-unittests target
945endif()
946
947if(SWIFTSHADER_BUILD_BENCHMARKS)
948 if (NOT TARGET benchmark::benchmark)
949 set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE)
950 add_subdirectory(${THIRD_PARTY_DIR}/benchmark)
Antonio Maiorano0f14b7a2020-09-11 10:02:16 -0400951 set_target_properties(benchmark PROPERTIES FOLDER "third_party")
952 set_target_properties(benchmark_main PROPERTIES FOLDER "third_party")
Nicolas Capensf324fe52020-06-05 16:10:07 -0400953 endif()
954
Nicolas Capensf7e7cc52022-02-06 08:51:05 -0500955 add_subdirectory(${TESTS_DIR}/PipelineBenchmarks) # Add PipelineBenchmarks target
Nicolas Capensf324fe52020-06-05 16:10:07 -0400956 add_subdirectory(${TESTS_DIR}/ReactorBenchmarks) # Add ReactorBenchmarks target
957 add_subdirectory(${TESTS_DIR}/SystemBenchmarks) # Add system-benchmarks target
958 add_subdirectory(${TESTS_DIR}/VulkanBenchmarks) # Add VulkanBenchmarks target
959endif()
960
Nicolas Capens4625f842021-12-08 14:23:59 -0500961if(SWIFTSHADER_BUILD_TESTS)
Nicolas Capensf324fe52020-06-05 16:10:07 -0400962 add_subdirectory(${TESTS_DIR}/VulkanUnitTests) # Add VulkanUnitTests target
963endif()