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 15set(ROOT_PROJECT_COMPILE_OPTIONS 16 ${SWIFTSHADER_COMPILE_OPTIONS} 17 ${WARNINGS_AS_ERRORS} 18) 19 20set(VULKAN_SRC_FILES 21 libVulkan.cpp 22 main.cpp 23 resource.h 24 Version.hpp 25 VkBuffer.cpp 26 VkBuffer.hpp 27 VkBufferView.cpp 28 VkBufferView.hpp 29 VkCommandBuffer.cpp 30 VkCommandBuffer.hpp 31 VkCommandPool.cpp 32 VkCommandPool.hpp 33 VkConfig.hpp 34 VkDebugUtilsMessenger.cpp 35 VkDebugUtilsMessenger.hpp 36 VkDescriptorPool.cpp 37 VkDescriptorPool.hpp 38 VkDescriptorSet.cpp 39 VkDescriptorSet.hpp 40 VkDescriptorSetLayout.cpp 41 VkDescriptorSetLayout.hpp 42 VkDescriptorUpdateTemplate.cpp 43 VkDescriptorUpdateTemplate.hpp 44 VkDestroy.hpp 45 VkDevice.cpp 46 VkDevice.hpp 47 VkDeviceMemory.cpp 48 VkDeviceMemory.hpp 49 VkDeviceMemoryExternalHost.cpp 50 VkDeviceMemoryExternalHost.hpp 51 VkDeviceMemoryExternalLinux.hpp 52 VkEvent.hpp 53 VkFence.hpp 54 VkFormat.cpp 55 VkFormat.hpp 56 VkFramebuffer.cpp 57 VkFramebuffer.hpp 58 VkGetProcAddress.cpp 59 VkGetProcAddress.hpp 60 VkImage.cpp 61 VkImage.hpp 62 VkImageView.cpp 63 VkImageView.hpp 64 VkInstance.cpp 65 VkInstance.hpp 66 VkMemory.cpp 67 VkMemory.hpp 68 VkObject.hpp 69 VkPhysicalDevice.cpp 70 VkPhysicalDevice.hpp 71 VkPipeline.cpp 72 VkPipeline.hpp 73 VkPipelineCache.cpp 74 VkPipelineCache.hpp 75 VkPrivateData.hpp 76 VkSpecializationInfo.cpp 77 VkSpecializationInfo.hpp 78 VkPipelineLayout.cpp 79 VkPipelineLayout.hpp 80 VkPromotedExtensions.cpp 81 VkQueryPool.cpp 82 VkQueryPool.hpp 83 VkQueue.cpp 84 VkQueue.hpp 85 VkRenderPass.cpp 86 VkRenderPass.hpp 87 VkSampler.cpp 88 VkSampler.hpp 89 VkSemaphore.cpp 90 VkSemaphore.hpp 91 VkSemaphoreExternalFuchsia.hpp 92 VkSemaphoreExternalLinux.hpp 93 VkShaderModule.cpp 94 VkShaderModule.hpp 95 VkStringify.cpp 96 VkStringify.hpp 97 VkStructConversion.hpp 98 VkTimelineSemaphore.cpp 99 VkTimelineSemaphore.hpp 100 VulkanPlatform.hpp 101) 102 103if(WIN32) 104 list(APPEND VULKAN_SRC_FILES 105 Vulkan.rc 106 ) 107endif() 108 109if(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER) 110 list(APPEND VULKAN_SRC_FILES 111 Debug/Context.cpp 112 Debug/Context.hpp 113 Debug/Debug.cpp 114 Debug/EventListener.cpp 115 Debug/EventListener.hpp 116 Debug/File.cpp 117 Debug/File.hpp 118 Debug/ID.hpp 119 Debug/Location.hpp 120 Debug/Server.cpp 121 Debug/Server.hpp 122 Debug/Thread.cpp 123 Debug/Thread.hpp 124 Debug/TypeOf.cpp 125 Debug/TypeOf.hpp 126 Debug/Value.cpp 127 Debug/Value.hpp 128 Debug/Variable.cpp 129 Debug/Variable.hpp 130 Debug/WeakMap.hpp 131 ) 132endif() 133 134set(VULKAN_COMPILE_OPTIONS "") 135if(FUCHSIA) 136 # At the moment, the Fuchsia build uses unofficial VK_STRUCTURE_TYPE_XX 137 # constants that are defined as macros in <vulkan/fuchsia_extras.h>. When 138 # these appear in switch() cases, the compiler complains that the values 139 # are not part of the VkStructureType enum. Silence this warning, until 140 # the constants are upstreamed to the official Vulkan headers. 141 list(APPEND VULKAN_COMPILE_OPTIONS "-Wno-switch") 142endif() 143if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 144 list(APPEND VULKAN_COMPILE_OPTIONS 145 # TODO(b/208256248): Avoid exit-time destructor. 146 #"-Wexit-time-destructors" # declaration requires an exit-time destructor 147 ) 148endif() 149 150set(VULKAN_LINKER_FLAGS "") 151if(FUCHSIA) 152 # On Fuchsia, the Vulkan ICD is loaded into a process sandbox that doesn't 153 # have system libraries available, so ensure it does not depend on libc++.so. 154 list(APPEND VULKAN_LINKER_FLAGS "-static-libstdc++") 155endif() 156 157add_library(vk_swiftshader SHARED 158 ${VULKAN_SRC_FILES} 159) 160 161set_target_properties(vk_swiftshader PROPERTIES 162 POSITION_INDEPENDENT_CODE 1 163 FOLDER "SwiftShader VK" 164 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 165 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 166) 167 168target_include_directories(vk_swiftshader 169 PRIVATE 170 ".." 171) 172 173target_compile_options(vk_swiftshader 174 PRIVATE 175 ${ROOT_PROJECT_COMPILE_OPTIONS} 176 ${VULKAN_COMPILE_OPTIONS} 177) 178 179target_compile_definitions(vk_swiftshader 180 PRIVATE 181 "VK_EXPORT=" 182 $<$<CONFIG:Debug>:"DEBUGGER_WAIT_DIALOG"> 183) 184 185target_link_options(vk_swiftshader 186 PRIVATE 187 ${SWIFTSHADER_LINK_FLAGS} 188 ${VULKAN_LINKER_FLAGS} 189) 190 191target_link_libraries(vk_swiftshader 192 PRIVATE 193 vk_system 194 vk_pipeline 195 vk_device 196 vk_wsi 197 Reactor 198 marl 199 ${OS_LIBS} 200 ${SWIFTSHADER_LIBS} 201 $<$<BOOL:${SWIFTSHADER_ENABLE_VULKAN_DEBUGGER}>:cppdap> 202) 203 204set_shared_library_export_map(vk_swiftshader ${CMAKE_CURRENT_SOURCE_DIR}) 205 206# The name of the application-facing library. Usually this would be the Vulkan Loader, 207# which then loads the Installable Client Driver (ICD), see: 208# https://www.lunarg.com/tutorial-overview-of-vulkan-loader-layers/ 209# But SwiftShader can also be loaded directlty by the application. This enables using 210# SwiftShader without requiring a Loader to be installed, and simplifies testing and 211# debugging. ${VULKAN_API_LIBRARY_NAME} is the name of this drop-in API library. 212if(WIN32) 213 set(VULKAN_API_LIBRARY_NAME "vulkan-1.dll") 214elseif(LINUX) 215 set(VULKAN_API_LIBRARY_NAME "libvulkan.so.1") 216elseif(APPLE) 217 set(VULKAN_API_LIBRARY_NAME "libvulkan.dylib") 218elseif(FUCHSIA) 219 set(VULKAN_API_LIBRARY_NAME "libvulkan.so") 220else() 221 message(FATAL_ERROR "Platform does not support Vulkan yet") 222endif() 223 224add_custom_command( 225 TARGET vk_swiftshader 226 POST_BUILD 227 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/ 228 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/ 229 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/${VULKAN_API_LIBRARY_NAME} 230 231 # Copy to ${CMAKE_BINARY_DIR}/bin so the library sits next to the PVR samples. 232 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin 233 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/bin/${VULKAN_API_LIBRARY_NAME} 234) 235 236# The SWIFTSHADER_VULKAN_API_LIBRARY_INSTALL_PATH environment variable can be set to a path 237# where we'd like the drop-in API library to be installed. For example for testing with dEQP 238# this could be something like C:/src/deqp/build/external/vulkancts/modules/vulkan/Debug/ 239if(DEFINED ENV{SWIFTSHADER_VULKAN_API_LIBRARY_INSTALL_PATH}) 240 add_custom_command( 241 TARGET vk_swiftshader 242 POST_BUILD 243 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> $ENV{SWIFTSHADER_VULKAN_API_LIBRARY_INSTALL_PATH}${VULKAN_API_LIBRARY_NAME} 244 ) 245endif() 246 247# The vk_swiftshader_icd.json manifest file will point to ICD_LIBRARY_PATH. 248# Set ICD_LIBRARY_PATH to be a relative path similar to "./libvk_swiftshader.so", so both files can be moved. 249# A relative path is relative to the manifest file. 250set(ICD_LIBRARY_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}") 251if(WIN32) 252 # The path is output to a JSON file, which requires backslashes to be escaped. 253 set(ICD_LIBRARY_PATH ".\\\\${ICD_LIBRARY_PATH}") 254else() 255 set(ICD_LIBRARY_PATH "./${ICD_LIBRARY_PATH}") 256endif() 257configure_file( 258 "vk_swiftshader_icd.json.tmpl" 259 "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/vk_swiftshader_icd.json" 260) 261