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 VkDeviceMemoryExternalLinux.hpp 50 VkEvent.hpp 51 VkFence.hpp 52 VkFormat.cpp 53 VkFormat.hpp 54 VkFramebuffer.cpp 55 VkFramebuffer.hpp 56 VkGetProcAddress.cpp 57 VkGetProcAddress.hpp 58 VkImage.cpp 59 VkImage.hpp 60 VkImageView.cpp 61 VkImageView.hpp 62 VkInstance.cpp 63 VkInstance.hpp 64 VkMemory.cpp 65 VkMemory.hpp 66 VkObject.hpp 67 VkPhysicalDevice.cpp 68 VkPhysicalDevice.hpp 69 VkPipeline.cpp 70 VkPipeline.hpp 71 VkPipelineCache.cpp 72 VkPipelineCache.hpp 73 VkSpecializationInfo.cpp 74 VkSpecializationInfo.hpp 75 VkPipelineLayout.cpp 76 VkPipelineLayout.hpp 77 VkPromotedExtensions.cpp 78 VkQueryPool.cpp 79 VkQueryPool.hpp 80 VkQueue.cpp 81 VkQueue.hpp 82 VkRenderPass.cpp 83 VkRenderPass.hpp 84 VkSampler.cpp 85 VkSampler.hpp 86 VkSemaphore.cpp 87 VkSemaphore.hpp 88 VkSemaphoreExternalFuchsia.hpp 89 VkSemaphoreExternalLinux.hpp 90 VkShaderModule.cpp 91 VkShaderModule.hpp 92 VkStringify.cpp 93 VkStringify.hpp 94 VkTimelineSemaphore.cpp 95 VkTimelineSemaphore.hpp 96 VulkanPlatform.hpp 97) 98 99if(WIN32) 100 list(APPEND VULKAN_SRC_FILES 101 Vulkan.rc 102 ) 103endif() 104 105if(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER) 106 list(APPEND VULKAN_SRC_FILES 107 Debug/Context.cpp 108 Debug/Context.hpp 109 Debug/Debug.cpp 110 Debug/EventListener.cpp 111 Debug/EventListener.hpp 112 Debug/File.cpp 113 Debug/File.hpp 114 Debug/ID.hpp 115 Debug/Location.hpp 116 Debug/Server.cpp 117 Debug/Server.hpp 118 Debug/Thread.cpp 119 Debug/Thread.hpp 120 Debug/TypeOf.cpp 121 Debug/TypeOf.hpp 122 Debug/Value.cpp 123 Debug/Value.hpp 124 Debug/Variable.cpp 125 Debug/Variable.hpp 126 Debug/WeakMap.hpp 127 ) 128endif() 129 130set(VULKAN_COMPILE_OPTIONS "") 131if(FUCHSIA) 132 # At the moment, the Fuchsia build uses unofficial VK_STRUCTURE_TYPE_XX 133 # constants that are defined as macros in <vulkan/fuchsia_extras.h>. When 134 # these appear in switch() cases, the compiler complains that the values 135 # are not part of the VkStructureType enum. Silence this warning, until 136 # the constants are upstreamed to the official Vulkan headers. 137 list(APPEND VULKAN_COMPILE_OPTIONS "-Wno-switch") 138endif() 139 140set(VULKAN_LINKER_FLAGS "") 141if(FUCHSIA) 142 # On Fuchsia, the Vulkan ICD is loaded into a process sandbox that doesn't 143 # have system libraries available, so ensure it does not depend on libc++.so. 144 list(APPEND VULKAN_LINKER_FLAGS "-static-libstdc++") 145endif() 146 147add_library(vk_swiftshader SHARED 148 ${VULKAN_SRC_FILES} 149) 150 151set_target_properties(vk_swiftshader PROPERTIES 152 POSITION_INDEPENDENT_CODE 1 153 FOLDER "SwiftShader VK" 154 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 155 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 156) 157 158target_include_directories(vk_swiftshader 159 PRIVATE 160 ".." 161) 162 163target_compile_options(vk_swiftshader 164 PRIVATE 165 ${ROOT_PROJECT_COMPILE_OPTIONS} 166 ${VULKAN_COMPILE_OPTIONS} 167) 168 169target_compile_definitions(vk_swiftshader 170 PRIVATE 171 "VK_EXPORT=" 172 $<$<CONFIG:Debug>:"DEBUGGER_WAIT_DIALOG"> 173) 174 175target_link_options(vk_swiftshader 176 PRIVATE 177 ${SWIFTSHADER_LINK_FLAGS} 178 ${VULKAN_LINKER_FLAGS} 179) 180 181target_link_libraries(vk_swiftshader 182 PRIVATE 183 vk_system 184 vk_pipeline 185 vk_device 186 vk_wsi 187 ${Reactor} 188 marl 189 ${OS_LIBS} 190 ${SWIFTSHADER_LIBS} 191 $<$<BOOL:${SWIFTSHADER_ENABLE_VULKAN_DEBUGGER}>:cppdap> 192) 193 194set_shared_library_export_map(vk_swiftshader ${CMAKE_CURRENT_SOURCE_DIR}) 195 196if(WIN32) 197 set(VULKAN_API_LIBRARY_NAME "vulkan-1.dll") 198elseif(LINUX) 199 set(VULKAN_API_LIBRARY_NAME "libvulkan.so.1") 200elseif(APPLE) 201 set(VULKAN_API_LIBRARY_NAME "libvulkan.dylib") 202elseif(FUCHSIA) 203 set(VULKAN_API_LIBRARY_NAME "libvulkan.so") 204else() 205 message(FATAL_ERROR "Platform does not support Vulkan yet") 206endif() 207 208add_custom_command( 209 TARGET vk_swiftshader 210 POST_BUILD 211 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/ 212 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/ 213 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/${VULKAN_API_LIBRARY_NAME} 214 215 # Copy to ${CMAKE_BINARY_DIR}/bin so the library sits next to the PVR samples. 216 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/bin 217 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/bin/${VULKAN_API_LIBRARY_NAME} 218) 219 220# The vk_swiftshader_icd.json manifest file will point to ICD_LIBRARY_PATH. 221# Set ICD_LIBRARY_PATH to be a relative path similar to "./libvk_swiftshader.so", so both files can be moved. 222# A relative path is relative to the manifest file. 223set(ICD_LIBRARY_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}") 224if(WIN32) 225 # The path is output to a JSON file, which requires backslashes to be escaped. 226 set(ICD_LIBRARY_PATH ".\\\\${ICD_LIBRARY_PATH}") 227else() 228 set(ICD_LIBRARY_PATH "./${ICD_LIBRARY_PATH}") 229endif() 230configure_file( 231 "vk_swiftshader_icd.json.tmpl" 232 "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/vk_swiftshader_icd.json" 233) 234