1# Copyright 2018 The Amber Authors. 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(AMBER_SOURCES 16 amber.cc 17 amberscript/parser.cc 18 buffer.cc 19 command.cc 20 command_data.cc 21 descriptor_set_and_binding_parser.cc 22 engine.cc 23 executor.cc 24 float16_helper.cc 25 format.cc 26 parser.cc 27 pipeline.cc 28 pipeline_data.cc 29 recipe.cc 30 result.cc 31 sampler.cc 32 script.cc 33 shader.cc 34 shader_compiler.cc 35 sleep.cc 36 tokenizer.cc 37 type.cc 38 type_parser.cc 39 value.cc 40 verifier.cc 41 virtual_file_store.cc 42 vkscript/command_parser.cc 43 vkscript/datum_type_parser.cc 44 vkscript/parser.cc 45 vkscript/section_parser.cc 46) 47 48if (${Vulkan_FOUND}) 49 add_subdirectory(vulkan) 50 list(APPEND AMBER_SOURCES vulkan_engine_config.cc) 51endif() 52if (${Dawn_FOUND}) 53 add_subdirectory(dawn) 54 list(APPEND AMBER_SOURCES dawn_engine_config.cc) 55endif() 56 57if (${AMBER_ENABLE_DXC}) 58 list(APPEND AMBER_SOURCES dxc_helper.cc) 59endif() 60 61if (${AMBER_ENABLE_CLSPV}) 62 list(APPEND AMBER_SOURCES clspv_helper.cc) 63endif() 64 65add_library(libamber ${AMBER_SOURCES}) 66amber_default_compile_options(libamber) 67target_include_directories(libamber PRIVATE 68 "${CMAKE_BINARY_DIR}" 69 ${SPIRV-Headers_SOURCE_DIR}/include) 70set_target_properties(libamber PROPERTIES OUTPUT_NAME "amber") 71 72if (${AMBER_ENABLE_DXC}) 73 target_include_directories(libamber PRIVATE 74 "${PROJECT_SOURCE_DIR}/third_party/dxc/include" 75 "${CMAKE_BINARY_DIR}/third_party/dxc/include" 76 ) 77 78 add_dependencies(libamber dxcompiler) 79 target_link_libraries(libamber 80 dxcompiler 81 LLVMDxcSupport 82 LLVMHLSL 83 LLVMOption 84 LLVMSupport 85 ) 86 87 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 88 target_compile_options(libamber PRIVATE 89 -fms-extensions 90 -Wno-language-extension-token 91 -fexceptions 92 ) 93 endif() 94endif() 95 96if (${AMBER_ENABLE_CLSPV}) 97 target_include_directories(libamber PRIVATE 98 "${clspv_SOURCE_DIR}/clspv/include" 99 ) 100 101 target_link_libraries(libamber 102 clspv_core 103 clspv_passes 104 ) 105endif() 106 107if (${AMBER_ENABLE_SPIRV_TOOLS}) 108 target_link_libraries(libamber SPIRV-Tools) 109endif() 110 111if (${AMBER_ENABLE_SHADERC}) 112 target_link_libraries(libamber shaderc SPIRV) 113endif() 114 115if (NOT MSVC AND NOT ANDROID AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "QNX") 116 target_link_libraries(libamber pthread) 117endif() 118 119if (${Vulkan_FOUND}) 120 target_link_libraries(libamber libamberenginevulkan) 121 target_include_directories(libamber PRIVATE "${VulkanHeaders_INCLUDE_DIR}") 122 123 if (${VULKAN_CTS_HEADER} AND DEFINED AMBER_CTS_INL_DIR) 124 target_include_directories(libamber PRIVATE "${AMBER_CTS_INL_DIR}") 125 endif() 126endif() 127if (${Dawn_FOUND}) 128 target_link_libraries(libamber libamberenginedawn) 129endif() 130 131if (${AMBER_ENABLE_TESTS}) 132 set(TEST_SRCS 133 amberscript/parser_attach_test.cc 134 amberscript/parser_bind_test.cc 135 amberscript/parser_buffer_test.cc 136 amberscript/parser_clear_color_test.cc 137 amberscript/parser_clear_depth_test.cc 138 amberscript/parser_clear_stencil_test.cc 139 amberscript/parser_clear_test.cc 140 amberscript/parser_compile_options_test.cc 141 amberscript/parser_copy_test.cc 142 amberscript/parser_depth_test.cc 143 amberscript/parser_device_feature_test.cc 144 amberscript/parser_expect_test.cc 145 amberscript/parser_extension_test.cc 146 amberscript/parser_framebuffer_test.cc 147 amberscript/parser_image_test.cc 148 amberscript/parser_pipeline_test.cc 149 amberscript/parser_pipeline_set_test.cc 150 amberscript/parser_repeat_test.cc 151 amberscript/parser_run_test.cc 152 amberscript/parser_sampler_test.cc 153 amberscript/parser_set_test.cc 154 amberscript/parser_shader_opt_test.cc 155 amberscript/parser_shader_test.cc 156 amberscript/parser_stencil_test.cc 157 amberscript/parser_blend_test.cc 158 amberscript/parser_struct_test.cc 159 amberscript/parser_subgroup_size_control_test.cc 160 amberscript/parser_test.cc 161 amberscript/parser_viewport_test.cc 162 buffer_test.cc 163 command_data_test.cc 164 descriptor_set_and_binding_parser_test.cc 165 executor_test.cc 166 float16_helper_test.cc 167 format_test.cc 168 pipeline_test.cc 169 result_test.cc 170 script_test.cc 171 shader_compiler_test.cc 172 tokenizer_test.cc 173 type_parser_test.cc 174 type_test.cc 175 verifier_test.cc 176 virtual_file_store_test.cc 177 vkscript/command_parser_test.cc 178 vkscript/datum_type_parser_test.cc 179 vkscript/parser_test.cc 180 vkscript/section_parser_test.cc 181 ../samples/ppm.cc 182 ../samples/ppm_test.cc 183 ) 184 185 if (${Vulkan_FOUND}) 186 list(APPEND TEST_SRCS 187 vulkan/vertex_buffer_test.cc 188 vulkan/pipeline_test.cc) 189 endif() 190 191 if (${Dawn_FOUND}) 192 list(APPEND TEST_SRCS dawn/pipeline_info_test.cc) 193 endif() 194 195 add_executable(amber_unittests ${TEST_SRCS}) 196 197 if (NOT MSVC) 198 target_compile_options(amber_unittests PRIVATE 199 -Wno-global-constructors 200 -Wno-weak-vtables 201 ) 202 endif() 203 204 target_include_directories(amber_unittests PRIVATE 205 ${gmock_SOURCE_DIR}/include) 206 target_link_libraries(amber_unittests libamber gmock_main) 207 amber_default_compile_options(amber_unittests) 208 add_test(NAME amber_unittests COMMAND amber_unittests) 209 210 if (${Vulkan_FOUND}) 211 target_include_directories(amber_unittests PRIVATE "${VulkanHeaders_INCLUDE_DIR}" "${CMAKE_BINARY_DIR}") 212 endif() 213 214 if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 215 # vulkan/vulkan.h defines VK_NULL_HANDLE as 0u and that also serves as a null pointer. 216 # Disable Clang's warning that will alwaays fire on that. This is required to build 217 # with XCode 10. 218 target_compile_options(amber_unittests PRIVATE -Wno-zero-as-null-pointer-constant) 219 endif() 220endif() 221