• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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)
73target_compile_definitions(VkLayer_core_validation PUBLIC "BUILD_CORE_VALIDATION")
74target_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)
81target_link_libraries(VkLayer_core_validation PRIVATE
82        log layer_utils SPIRV-Tools-prebuilt)
83if (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)
91endif()
92
93add_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)
98target_compile_definitions(VkLayer_parameter_validation PUBLIC "BUILD_PARAMETER_VALIDATION")
99target_include_directories(VkLayer_parameter_validation PRIVATE
100        ${SRC_DIR}/include
101        ${COMMON_DIR}/include
102        ${SRC_DIR}/layers
103        ${SRC_DIR}/loader)
104target_link_libraries(VkLayer_parameter_validation PRIVATE log layer_utils)
105
106add_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)
111target_compile_definitions(VkLayer_object_tracker PUBLIC "BUILD_OBJECT_TRACKER")
112target_include_directories(VkLayer_object_tracker PRIVATE
113        ${SRC_DIR}/include
114        ${SRC_DIR}/layers
115        ${COMMON_DIR}/include
116        ${SRC_DIR}/loader)
117target_link_libraries(VkLayer_object_tracker PRIVATE log layer_utils)
118
119add_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
123target_compile_definitions(VkLayer_threading PUBLIC "BUILD_THREAD_SAFETY")
124target_include_directories(VkLayer_threading PRIVATE
125        ${SRC_DIR}/include
126        ${SRC_DIR}/layers
127        ${COMMON_DIR}/include
128        ${SRC_DIR}/loader)
129target_link_libraries(VkLayer_threading PRIVATE log layer_utils)
130
131add_library(VkLayer_unique_objects SHARED
132        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp)
133        ${COMMON_DIR}/include/chassis.cpp)
134target_compile_definitions(VkLayer_object_tracker PUBLIC "LAYER_CHASSIS_CAN_WRAP_HANDLES")
135target_include_directories(VkLayer_unique_objects PRIVATE
136        ${SRC_DIR}/include
137        ${SRC_DIR}/layers
138        ${COMMON_DIR}/include
139        ${SRC_DIR}/loader)
140target_link_libraries(VkLayer_unique_objects PRIVATE log layer_utils)
141
142set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}")
143