1cmake_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 7set(BUILD_IN_NDK OFF) 8if (CMAKE_CURRENT_SOURCE_DIR MATCHES "sources/third_party/vulkan/src") 9 set(BUILD_IN_NDK ON) 10endif() 11 12set(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 17if (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) 30else () 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") 38endif() 39set(COMMON_DIR "${SRC_DIR}/build-android/generated") 40 41set(CMAKE_CXX_clone "${CMAKE_CXX_FLAGS}") 42set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR \ 43 -fvisibility=hidden") 44include_directories(${SRC_DIR}/include 45 ${COMMON_DIR}/include 46 ${SRC_DIR}/layers 47 ${SRC_DIR}/loader) 48add_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) 53set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}") 54 55# assume shaderc already built externally 56add_library(SPIRV-Tools-prebuilt STATIC IMPORTED) 57set_target_properties(SPIRV-Tools-prebuilt PROPERTIES IMPORTED_LOCATION 58 ${SPIRV_LIB}) 59 60# build core_validation layers which including shader validation 61set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR \ 62 -fvisibility=hidden") 63add_library(VkLayer_core_validation SHARED 64 ${SRC_DIR}/layers/core_validation.cpp 65 ${SRC_DIR}/layers/descriptor_sets.cpp 66 ${SRC_DIR}/layers/buffer_validation.cpp 67 ${SRC_DIR}/layers/shader_validation.cpp 68 ${SRC_DIR}/layers/vk_layer_table.cpp 69 ${SRC_DIR}/layers/xxhash.c) 70target_include_directories(VkLayer_core_validation PRIVATE 71 ${SRC_DIR}/include 72 ${SRC_DIR}/layers 73 ${COMMON_DIR}/include 74 ${SRC_DIR}/loader 75 ${EXTERNAL_DIR}/glslang 76 ${EXTERNAL_DIR}/spirv-tools/include) 77target_link_libraries(VkLayer_core_validation PRIVATE 78 log layer_utils SPIRV-Tools-prebuilt) 79 80add_library(VkLayer_parameter_validation SHARED 81 ${COMMON_DIR}/include/parameter_validation.cpp 82 ${SRC_DIR}/layers/parameter_validation_utils.cpp 83 ${SRC_DIR}/layers/vk_layer_table.cpp) 84target_include_directories(VkLayer_parameter_validation PRIVATE 85 ${SRC_DIR}/include 86 ${COMMON_DIR}/include 87 ${SRC_DIR}/layers 88 ${SRC_DIR}/loader) 89target_link_libraries(VkLayer_parameter_validation PRIVATE log layer_utils) 90 91add_library(VkLayer_object_tracker SHARED 92 ${COMMON_DIR}/include/object_tracker.cpp 93 ${SRC_DIR}/layers/object_tracker_utils.cpp 94 ${SRC_DIR}/layers/vk_layer_table.cpp) 95target_include_directories(VkLayer_object_tracker PRIVATE 96 ${SRC_DIR}/include 97 ${SRC_DIR}/layers 98 ${COMMON_DIR}/include 99 ${SRC_DIR}/loader) 100target_link_libraries(VkLayer_object_tracker PRIVATE log layer_utils) 101 102add_library(VkLayer_threading SHARED 103 ${SRC_DIR}/layers/threading.cpp 104 ${SRC_DIR}/layers/vk_layer_table.cpp) 105target_include_directories(VkLayer_threading PRIVATE 106 ${SRC_DIR}/include 107 ${SRC_DIR}/layers 108 ${COMMON_DIR}/include 109 ${SRC_DIR}/loader) 110target_link_libraries(VkLayer_threading PRIVATE log layer_utils) 111 112add_library(VkLayer_unique_objects SHARED 113 ${SRC_DIR}/layers/unique_objects.cpp 114 ${SRC_DIR}/layers/vk_layer_table.cpp) 115target_include_directories(VkLayer_unique_objects PRIVATE 116 ${SRC_DIR}/include 117 ${SRC_DIR}/layers 118 ${COMMON_DIR}/include 119 ${SRC_DIR}/loader) 120target_link_libraries(VkLayer_unique_objects PRIVATE log layer_utils) 121 122set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}") 123