1 cmake_minimum_required(VERSION 3.4.1) 2 3 # Validation layers could be built with code from 4 # github repo OR 5 # ndk's snapshot 6 # The file structure for glslang spir-V is different, adding BUILD_IN_NDK variable 7 set(BUILD_IN_NDK OFF) 8 if (CMAKE_CURRENT_SOURCE_DIR MATCHES "sources/third_party/vulkan/src") 9 set(BUILD_IN_NDK ON) 10 endif() 11 12 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror \ 13 -Wno-unused-function -Wno-unused-const-variable \ 14 -Wno-c++98-compat-pedantic -DVK_PROTOTYPES \ 15 -DVK_USE_PLATFORM_ANDROID_KHR") 16 17 if (BUILD_IN_NDK) 18 # NDK directory structure: 19 # $ANDROID_NDK/sources/third_party/ 20 # vulkan/src 21 # shaderc/third_party (for glslang & spirv-tools ) 22 # this build uses combined lib libshaderc.a for libSPIRV-Tools.a purpose 23 get_filename_component(SRC_DIR 24 "${ANDROID_NDK}/sources/third_party/vulkan/src" ABSOLUTE) 25 get_filename_component(EXTERNAL_DIR 26 "${SRC_DIR}/../../shaderc/third_party" ABSOLUTE) 27 get_filename_component(SPIRV_LIB 28 "${SRC_DIR}/../../shaderc/libs/${ANDROID_STL}/${ANDROID_ABI}/libshaderc.a" 29 ABSOLUTE) 30 else () 31 # github directory structure: 32 # ${SRC_DIR} 33 # ${SRC_DIR}/build-android/external (for glslang, spirv-tools & shaderc ) 34 get_filename_component(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../.." ABSOLUTE) 35 set(EXTERNAL_DIR "${SRC_DIR}/build-android/third_party/shaderc/third_party") 36 set(SPIRV_LIB 37 "${SRC_DIR}/build-android/third_party/shaderc/android_test/obj/local/${ANDROID_ABI}/libSPIRV-Tools.a") 38 endif() 39 set(COMMON_DIR "${SRC_DIR}/build-android/generated") 40 41 set(CMAKE_CXX_clone "${CMAKE_CXX_FLAGS}") 42 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR \ 43 -fvisibility=hidden") 44 include_directories(${SRC_DIR}/include 45 ${COMMON_DIR}/include 46 ${SRC_DIR}/layers 47 ${SRC_DIR}/loader) 48 add_library(layer_utils STATIC 49 ${SRC_DIR}/layers/vk_layer_config.cpp 50 ${SRC_DIR}/layers/vk_layer_extension_utils.cpp 51 ${SRC_DIR}/layers/vk_layer_utils.cpp 52 ${SRC_DIR}/layers/vk_format_utils.cpp) 53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}") 54 55 # assume shaderc already built externally 56 add_library(SPIRV-Tools-prebuilt STATIC IMPORTED) 57 set_target_properties(SPIRV-Tools-prebuilt PROPERTIES IMPORTED_LOCATION 58 ${SPIRV_LIB}) 59 60 # build core_validation layers which including shader validation 61 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR \ 62 -fvisibility=hidden") 63 add_library(VkLayer_core_validation SHARED 64 ${SRC_DIR}/layers/core_validation.cpp 65 ${SRC_DIR}/layers/convert_to_renderpass2.cpp 66 ${SRC_DIR}/layers/descriptor_sets.cpp 67 ${SRC_DIR}/layers/buffer_validation.cpp 68 ${SRC_DIR}/layers/shader_validation.cpp 69 ${SRC_DIR}/layers/gpu_validation.cpp 70 ${COMMON_DIR}/include/layer_chassis_dispatch.cpp 71 ${COMMON_DIR}/include/chassis.cpp 72 ${SRC_DIR}/layers/xxhash.c) 73 target_compile_definitions(VkLayer_core_validation PUBLIC "BUILD_CORE_VALIDATION") 74 target_include_directories(VkLayer_core_validation PRIVATE 75 ${SRC_DIR}/include 76 ${SRC_DIR}/layers 77 ${COMMON_DIR}/include 78 ${SRC_DIR}/loader 79 ${EXTERNAL_DIR}/glslang 80 ${EXTERNAL_DIR}/spirv-tools/include) 81 target_link_libraries(VkLayer_core_validation PRIVATE 82 log layer_utils SPIRV-Tools-prebuilt) 83 if (NOT BUILD_IN_NDK) 84 set(SPIRV_OPT_LIB 85 "${SRC_DIR}/build-android/third_party/shaderc/android_test/obj/local/${ANDROID_ABI}/libSPIRV-Tools-opt.a") 86 add_library(SPIRV-Tools-opt-prebuilt STATIC IMPORTED) 87 set_target_properties(SPIRV-Tools-opt-prebuilt PROPERTIES IMPORTED_LOCATION 88 ${SPIRV_OPT_LIB}) 89 target_link_libraries(VkLayer_core_validation PRIVATE 90 SPIRV-Tools-opt-prebuilt) 91 endif() 92 93 add_library(VkLayer_parameter_validation SHARED 94 ${COMMON_DIR}/include/parameter_validation.cpp 95 ${COMMON_DIR}/include/layer_chassis_dispatch.cpp 96 ${COMMON_DIR}/include/chassis.cpp 97 ${SRC_DIR}/layers/parameter_validation_utils.cpp) 98 target_compile_definitions(VkLayer_parameter_validation PUBLIC "BUILD_PARAMETER_VALIDATION") 99 target_include_directories(VkLayer_parameter_validation PRIVATE 100 ${SRC_DIR}/include 101 ${COMMON_DIR}/include 102 ${SRC_DIR}/layers 103 ${SRC_DIR}/loader) 104 target_link_libraries(VkLayer_parameter_validation PRIVATE log layer_utils) 105 106 add_library(VkLayer_object_tracker SHARED 107 ${COMMON_DIR}/include/object_tracker.cpp 108 ${COMMON_DIR}/include/layer_chassis_dispatch.cpp 109 ${COMMON_DIR}/include/chassis.cpp 110 ${SRC_DIR}/layers/object_tracker_utils.cpp) 111 target_compile_definitions(VkLayer_object_tracker PUBLIC "BUILD_OBJECT_TRACKER") 112 target_include_directories(VkLayer_object_tracker PRIVATE 113 ${SRC_DIR}/include 114 ${SRC_DIR}/layers 115 ${COMMON_DIR}/include 116 ${SRC_DIR}/loader) 117 target_link_libraries(VkLayer_object_tracker PRIVATE log layer_utils) 118 119 add_library(VkLayer_threading SHARED 120 ${COMMON_DIR}/include/thread_safety.cpp 121 ${COMMON_DIR}/include/layer_chassis_dispatch.cpp 122 ${COMMON_DIR}/include/chassis.cpp 123 target_compile_definitions(VkLayer_threading PUBLIC "BUILD_THREAD_SAFETY") 124 target_include_directories(VkLayer_threading PRIVATE 125 ${SRC_DIR}/include 126 ${SRC_DIR}/layers 127 ${COMMON_DIR}/include 128 ${SRC_DIR}/loader) 129 target_link_libraries(VkLayer_threading PRIVATE log layer_utils) 130 131 add_library(VkLayer_unique_objects SHARED 132 ${COMMON_DIR}/include/layer_chassis_dispatch.cpp) 133 ${COMMON_DIR}/include/chassis.cpp) 134 target_compile_definitions(VkLayer_object_tracker PUBLIC "LAYER_CHASSIS_CAN_WRAP_HANDLES") 135 target_include_directories(VkLayer_unique_objects PRIVATE 136 ${SRC_DIR}/include 137 ${SRC_DIR}/layers 138 ${COMMON_DIR}/include 139 ${SRC_DIR}/loader) 140 target_link_libraries(VkLayer_unique_objects PRIVATE log layer_utils) 141 142 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}") 143