1cmake_minimum_required (VERSION 2.8.11) 2 3macro(run_vk_helper subcmd) 4 add_custom_command(OUTPUT ${ARGN} 5 COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk_helper.py --${subcmd} ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h --abs_out_dir ${CMAKE_CURRENT_BINARY_DIR} 6 DEPENDS ${PROJECT_SOURCE_DIR}/vk_helper.py ${PROJECT_SOURCE_DIR}/include/vulkan/vulkan.h 7 ) 8endmacro() 9 10macro(run_vk_layer_xml_generate dependency output) 11 add_custom_command(OUTPUT ${output} 12 COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/lvl_genvk.py -registry ${PROJECT_SOURCE_DIR}/vk.xml ${output} 13 DEPENDS ${PROJECT_SOURCE_DIR}/vk.xml ${PROJECT_SOURCE_DIR}/generator.py ${PROJECT_SOURCE_DIR}/${dependency} ${PROJECT_SOURCE_DIR}/lvl_genvk.py ${PROJECT_SOURCE_DIR}/reg.py 14 ) 15endmacro() 16 17set(LAYER_JSON_FILES 18 VkLayer_core_validation 19 VkLayer_image 20 VkLayer_object_tracker 21 VkLayer_unique_objects 22 VkLayer_parameter_validation 23 VkLayer_swapchain 24 VkLayer_threading 25 ) 26 27if (WIN32) 28 if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)) 29 if (CMAKE_GENERATOR MATCHES "^Visual Studio.*") 30 foreach (config_file ${LAYER_JSON_FILES}) 31 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json) 32 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/${config_file}.json dst_json) 33 add_custom_target(${config_file}-json ALL 34 COMMAND copy ${src_json} ${dst_json} 35 VERBATIM 36 ) 37 add_dependencies(${config_file}-json ${config_file}) 38 endforeach(config_file) 39 else() 40 foreach (config_file ${LAYER_JSON_FILES}) 41 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json) 42 FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json) 43 add_custom_target(${config_file}-json ALL 44 COMMAND copy ${src_json} ${dst_json} 45 VERBATIM 46 ) 47 add_dependencies(${config_file}-json ${config_file}) 48 endforeach(config_file) 49 endif() 50 endif() 51else() 52 # extra setup for out-of-tree builds 53 if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)) 54 foreach (config_file ${LAYER_JSON_FILES}) 55 add_custom_target(${config_file}-json ALL 56 COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json 57 VERBATIM 58 ) 59 add_dependencies(${config_file}-json ${config_file}) 60 endforeach(config_file) 61 endif() 62endif() 63 64# Add targets for JSON file install on Linux. 65# Need to remove the "./" from the library path before installing to /etc. 66if(UNIX) 67 foreach (config_file ${LAYER_JSON_FILES}) 68 add_custom_target(${config_file}-staging-json ALL 69 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json 70 COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json 71 COMMAND sed -i -e "/\"library_path\":/s$./libVkLayer$libVkLayer$" ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json 72 VERBATIM 73 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json 74 ) 75 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json DESTINATION /etc/vulkan/explicit_layer.d) 76 endforeach(config_file) 77endif() 78 79if (WIN32) 80 macro(add_vk_layer target) 81 add_custom_command(OUTPUT VkLayer_${target}.def 82 COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk-generate.py ${DisplayServer} win-def-file VkLayer_${target} layer > VkLayer_${target}.def 83 DEPENDS ${PROJECT_SOURCE_DIR}/vk-generate.py ${PROJECT_SOURCE_DIR}/vulkan.py 84 ) 85 add_library(VkLayer_${target} SHARED ${ARGN} VkLayer_${target}.def) 86 target_link_Libraries(VkLayer_${target} VkLayer_utils) 87 add_dependencies(VkLayer_${target} generate_dispatch_table_helper generate_vk_layer_helpers generate_enum_string_helper VkLayer_utils) 88 endmacro() 89else() 90 macro(add_vk_layer target) 91 add_library(VkLayer_${target} SHARED ${ARGN}) 92 target_link_Libraries(VkLayer_${target} VkLayer_utils) 93 add_dependencies(VkLayer_${target} generate_dispatch_table_helper generate_vk_layer_helpers generate_enum_string_helper VkLayer_utils) 94 set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL") 95 install(TARGETS VkLayer_${target} DESTINATION lib) 96 endmacro() 97endif() 98 99include_directories( 100 ${CMAKE_CURRENT_SOURCE_DIR} 101 ${CMAKE_CURRENT_SOURCE_DIR}/../loader 102 ${CMAKE_CURRENT_SOURCE_DIR}/../include/vulkan 103 ${CMAKE_CURRENT_BINARY_DIR} 104) 105 106if (WIN32) 107 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS") 108 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS") 109 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj") 110 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj") 111else() 112 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare") 113 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare") 114endif() 115 116add_custom_command(OUTPUT vk_dispatch_table_helper.h 117 COMMAND ${PYTHON_CMD} ${PROJECT_SOURCE_DIR}/vk-generate.py AllPlatforms dispatch-table-ops layer > vk_dispatch_table_helper.h 118 DEPENDS ${PROJECT_SOURCE_DIR}/vk-generate.py ${PROJECT_SOURCE_DIR}/vulkan.py) 119 120run_vk_helper(gen_enum_string_helper vk_enum_string_helper.h) 121run_vk_helper(gen_struct_wrappers 122 vk_struct_string_helper.h 123 vk_struct_string_helper_cpp.h 124 vk_struct_string_helper_no_addr.h 125 vk_struct_string_helper_no_addr_cpp.h 126 vk_struct_size_helper.h 127 vk_struct_size_helper.c 128 vk_struct_wrappers.h 129 vk_struct_wrappers.cpp 130 vk_safe_struct.h 131# Don't list vk_safe_struct.cpp as OUTPUT to avoid duplicate builds. 132# If listed here use of it for add_library will cause it to be created 133# independently of custom target generate_vk_layer_helpers . 134# That breaks parallel builds. 135# vk_safe_struct.cpp 136) 137 138# Let gen_struct_wrappers really create vk_safe_struct.cpp 139add_custom_command(OUTPUT vk_safe_struct.cpp 140 COMMAND echo defer making vk_safe_struct.cpp 141) 142 143set_source_files_properties( 144 vk_struct_string_helper.h 145 vk_struct_string_helper_cpp.h 146 vk_struct_string_helper_no_addr.h 147 vk_struct_string_helper_no_addr_cpp.h 148 vk_struct_size_helper.h 149 vk_struct_size_helper.c 150 vk_struct_wrappers.h 151 vk_struct_wrappers.cpp 152 vk_safe_struct.h 153 vk_safe_struct.cpp 154 PROPERTIES GENERATED TRUE) 155 156add_custom_target(generate_enum_string_helper DEPENDS 157 vk_enum_string_helper.h 158) 159 160add_custom_target(generate_dispatch_table_helper DEPENDS 161 vk_dispatch_table_helper.h 162) 163 164add_custom_target(generate_vk_layer_helpers DEPENDS 165 vk_struct_string_helper.h 166 vk_struct_string_helper_no_addr.h 167 vk_struct_string_helper_cpp.h 168 vk_struct_string_helper_no_addr_cpp.h 169 vk_struct_size_helper.h 170 vk_struct_size_helper.c 171 vk_struct_wrappers.h 172 vk_struct_wrappers.cpp 173 vk_safe_struct.h 174 vk_safe_struct.cpp 175) 176 177run_vk_layer_xml_generate(threading_generator.py thread_check.h) 178run_vk_layer_xml_generate(parameter_validation_generator.py parameter_validation.h) 179run_vk_layer_xml_generate(unique_objects_generator.py unique_objects_wrappers.h) 180 181# Layer Utils Library 182# For Windows, we use a static lib because the Windows loader has a fairly restrictive loader search 183# path that can't be easily modified to point it to the same directory that contains the layers. 184if (WIN32) 185 add_library(VkLayer_utils STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp) 186else() 187 add_library(VkLayer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp) 188 install(TARGETS VkLayer_utils DESTINATION lib) 189endif() 190 191add_vk_layer(core_validation core_validation.cpp vk_layer_table.cpp vk_safe_struct.cpp descriptor_sets.cpp) 192add_vk_layer(object_tracker object_tracker.cpp vk_layer_table.cpp) 193add_vk_layer(image image.cpp vk_layer_table.cpp) 194add_vk_layer(swapchain swapchain.cpp vk_layer_table.cpp) 195# generated 196add_vk_layer(threading threading.cpp thread_check.h vk_layer_table.cpp) 197add_vk_layer(unique_objects unique_objects.cpp unique_objects_wrappers.h vk_layer_table.cpp vk_safe_struct.cpp) 198add_vk_layer(parameter_validation parameter_validation.cpp parameter_validation.h vk_layer_table.cpp) 199 200# Core validation has additional dependencies 201target_include_directories(VkLayer_core_validation PRIVATE ${GLSLANG_SPIRV_INCLUDE_DIR}) 202target_include_directories(VkLayer_core_validation PRIVATE ${SPIRV_TOOLS_INCLUDE_DIR}) 203target_link_libraries(VkLayer_core_validation ${SPIRV_TOOLS_LIBRARIES}) 204