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
60set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR \
61                     -fvisibility=hidden")
62add_library(VkLayer_khronos_validation SHARED
63        ${SRC_DIR}/layers/core_validation.cpp
64        ${SRC_DIR}/layers/drawdispatch.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        ${COMMON_DIR}/include/parameter_validation.cpp
73        ${SRC_DIR}/layers/parameter_validation_utils.cpp
74        ${COMMON_DIR}/include/object_tracker.cpp
75        ${SRC_DIR}/layers/object_tracker_utils.cpp
76        ${COMMON_DIR}/include/thread_safety.cpp
77        ${SRC_DIR}/layers/xxhash.c)
78target_compile_definitions(VkLayer_khronos_validation PUBLIC "BUILD_KHRONOS_VALIDATION;BUILD_CORE_VALIDATION;BUILD_PARAMETER_VALIDATION;BUILD_OBJECT_TRACKER;BUILD_THREAD_SAFETY;LAYER_CHASSIS_CAN_WRAP_HANDLES")
79target_include_directories(VkLayer_khronos_validation PRIVATE
80        ${SRC_DIR}/include
81        ${SRC_DIR}/layers
82        ${COMMON_DIR}/include
83        ${SRC_DIR}/loader
84        ${EXTERNAL_DIR}/glslang
85        ${EXTERNAL_DIR}/spirv-tools/include)
86target_link_libraries(VkLayer_khronos_validation PRIVATE
87        log layer_utils SPIRV-Tools-prebuilt)
88if (NOT BUILD_IN_NDK)
89    set(SPIRV_OPT_LIB
90        "${SRC_DIR}/build-android/third_party/shaderc/android_test/obj/local/${ANDROID_ABI}/libSPIRV-Tools-opt.a")
91    add_library(SPIRV-Tools-opt-prebuilt STATIC IMPORTED)
92    set_target_properties(SPIRV-Tools-opt-prebuilt PROPERTIES IMPORTED_LOCATION
93        ${SPIRV_OPT_LIB})
94    target_link_libraries(VkLayer_khronos_validation PRIVATE
95        SPIRV-Tools-opt-prebuilt)
96endif()
97
98add_library(VkLayer_core_validation SHARED
99        ${SRC_DIR}/layers/core_validation.cpp
100        ${SRC_DIR}/layers/drawdispatch.cpp
101        ${SRC_DIR}/layers/convert_to_renderpass2.cpp
102        ${SRC_DIR}/layers/descriptor_sets.cpp
103        ${SRC_DIR}/layers/buffer_validation.cpp
104        ${SRC_DIR}/layers/shader_validation.cpp
105        ${SRC_DIR}/layers/gpu_validation.cpp
106        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp
107        ${COMMON_DIR}/include/chassis.cpp
108        ${SRC_DIR}/layers/xxhash.c)
109target_compile_definitions(VkLayer_core_validation PUBLIC "BUILD_CORE_VALIDATION")
110target_include_directories(VkLayer_core_validation PRIVATE
111        ${SRC_DIR}/include
112        ${SRC_DIR}/layers
113        ${COMMON_DIR}/include
114        ${SRC_DIR}/loader
115        ${EXTERNAL_DIR}/glslang
116        ${EXTERNAL_DIR}/spirv-tools/include)
117target_link_libraries(VkLayer_core_validation PRIVATE
118        log layer_utils SPIRV-Tools-prebuilt)
119if (NOT BUILD_IN_NDK)
120    set(SPIRV_OPT_LIB
121        "${SRC_DIR}/build-android/third_party/shaderc/android_test/obj/local/${ANDROID_ABI}/libSPIRV-Tools-opt.a")
122    add_library(SPIRV-Tools-opt-prebuilt STATIC IMPORTED)
123    set_target_properties(SPIRV-Tools-opt-prebuilt PROPERTIES IMPORTED_LOCATION
124        ${SPIRV_OPT_LIB})
125    target_link_libraries(VkLayer_core_validation PRIVATE
126        SPIRV-Tools-opt-prebuilt)
127endif()
128
129add_library(VkLayer_parameter_validation SHARED
130        ${COMMON_DIR}/include/parameter_validation.cpp
131        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp
132        ${COMMON_DIR}/include/chassis.cpp
133        ${SRC_DIR}/layers/parameter_validation_utils.cpp)
134target_compile_definitions(VkLayer_parameter_validation PUBLIC "BUILD_PARAMETER_VALIDATION")
135target_include_directories(VkLayer_parameter_validation PRIVATE
136        ${SRC_DIR}/include
137        ${COMMON_DIR}/include
138        ${SRC_DIR}/layers
139        ${SRC_DIR}/loader)
140target_link_libraries(VkLayer_parameter_validation PRIVATE log layer_utils)
141
142add_library(VkLayer_object_tracker SHARED
143        ${COMMON_DIR}/include/object_tracker.cpp
144        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp
145        ${COMMON_DIR}/include/chassis.cpp
146        ${SRC_DIR}/layers/object_tracker_utils.cpp)
147target_compile_definitions(VkLayer_object_tracker PUBLIC "BUILD_OBJECT_TRACKER")
148target_include_directories(VkLayer_object_tracker PRIVATE
149        ${SRC_DIR}/include
150        ${SRC_DIR}/layers
151        ${COMMON_DIR}/include
152        ${SRC_DIR}/loader)
153target_link_libraries(VkLayer_object_tracker PRIVATE log layer_utils)
154
155add_library(VkLayer_threading SHARED
156        ${COMMON_DIR}/include/thread_safety.cpp
157        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp
158        ${COMMON_DIR}/include/chassis.cpp)
159target_compile_definitions(VkLayer_threading PUBLIC "BUILD_THREAD_SAFETY")
160target_include_directories(VkLayer_threading PRIVATE
161        ${SRC_DIR}/include
162        ${SRC_DIR}/layers
163        ${COMMON_DIR}/include
164        ${SRC_DIR}/loader)
165target_link_libraries(VkLayer_threading PRIVATE log layer_utils)
166
167add_library(VkLayer_unique_objects SHARED
168        ${COMMON_DIR}/include/layer_chassis_dispatch.cpp
169        ${COMMON_DIR}/include/chassis.cpp)
170target_compile_definitions(VkLayer_object_tracker PUBLIC "LAYER_CHASSIS_CAN_WRAP_HANDLES")
171target_include_directories(VkLayer_unique_objects PRIVATE
172        ${SRC_DIR}/include
173        ${SRC_DIR}/layers
174        ${COMMON_DIR}/include
175        ${SRC_DIR}/loader)
176target_link_libraries(VkLayer_unique_objects PRIVATE log layer_utils)
177
178set(CMAKE_CXX_FLAGS "${CMAKE_CXX_clone}")
179