add_definitions(-DAPI_NAME="Vulkan")
+# Fetch header version from vulkan_core.h
+file(STRINGS "${VulkanHeaders_INCLUDE_DIRS}/vulkan/vulkan_core.h" lines REGEX "^#define VK_HEADER_VERSION [0-9]+")
+list(LENGTH lines len)
+if(${len} EQUAL 1)
+ string(REGEX MATCHALL "[0-9]+" vk_header_version ${lines})
+else()
+ message(FATAL_ERROR "Unable to fetch version from vulkan.h")
+endif()
+
if(BUILD_LOADER)
add_subdirectory(loader)
endif()
check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader_cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/loader_cmake_config.h)
-# Fetch header version from vulkan_core.h
-file(STRINGS "${VulkanHeaders_INCLUDE_DIRS}/vulkan/vulkan_core.h" lines REGEX "^#define VK_HEADER_VERSION [0-9]+")
-list(LENGTH lines len)
-if(${len} EQUAL 1)
- string(REGEX MATCHALL "[0-9]+" vk_header_version ${lines})
-else()
- message(FATAL_ERROR "Unable to fetch version from vulkan.h")
-endif()
-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN)
set(DisplayServer Win32)
cmake_minimum_required(VERSION 2.8.11)
-set(LAYER_JSON_FILES VkLayer_wrap_objects VkLayer_test VkLayer_meta)
+set(TARGET_NAMES VkLayer_wrap_objects VkLayer_test VkLayer_meta)
set(VK_LAYER_RPATH /usr/lib/x86_64-linux-gnu/vulkan/layer:/usr/lib/i386-linux-gnu/vulkan/layer)
set(CMAKE_INSTALL_RPATH ${VK_LAYER_RPATH})
-if(WIN32)
- if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
- add_custom_target(mk_test_layer_config_dir ALL
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
- set_target_properties(mk_test_layer_config_dir PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})
- foreach(config_file ${LAYER_JSON_FILES})
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
- if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/${config_file}.json dst_json)
- else()
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json)
- endif()
- add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
- add_dependencies(${config_file}-json mk_test_layer_config_dir)
- set_target_properties(${config_file}-json PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})
- endforeach(config_file)
- endif()
-elseif(APPLE)
- # extra setup for out-of-tree builds
- if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
- if(CMAKE_GENERATOR MATCHES "^Xcode.*")
- add_custom_target(mk_test_layer_config_dir ALL
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
- foreach(config_file ${LAYER_JSON_FILES})
- add_custom_target(${config_file}-json ALL
- DEPENDS mk_test_layer_config_dir
- COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json $<CONFIG>
- VERBATIM)
- endforeach(config_file)
- else()
- foreach(config_file ${LAYER_JSON_FILES})
- add_custom_target(${config_file}-json ALL
- COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
- VERBATIM)
- endforeach(config_file)
- endif()
- endif()
-else()
- # extra setup for out-of-tree builds
- if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
- foreach(config_file ${LAYER_JSON_FILES})
- add_custom_target(${config_file}-json ALL COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json VERBATIM)
- endforeach(config_file)
- endif()
-endif()
-
if(WIN32)
macro(add_vk_layer target)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkLayer_${target}.def DEF_FILE)
set(TEST_SRCS test.cpp vk_layer_table.cpp vk_layer_extension_utils.cpp)
add_vk_layer(test ${TEST_SRCS})
+
+# The output file needs Unix "/" separators or Windows "\" separators
+# On top of that, Windows separators actually need to be doubled because the json format uses backslash escapes
+file(TO_NATIVE_PATH "./" RELATIVE_PATH_PREFIX)
+string(REPLACE "\\" "\\\\" RELATIVE_PATH_PREFIX "${RELATIVE_PATH_PREFIX}")
+
+# Run each .json.in file through the generator
+# We need to create the generator.cmake script so that the generator can be run at compile time, instead of configure time
+# Running at compile time lets us use cmake generator expressions (TARGET_FILE_NAME and TARGET_FILE_DIR, specifically)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/generator.cmake" "configure_file(\"\${INPUT_FILE}\" \"\${OUTPUT_FILE}\")")
+foreach(TARGET_NAME ${TARGET_NAMES})
+ set(CONFIG_DEFINES
+ -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/json/${TARGET_NAME}.json.in"
+ -DVK_VERSION=1.1.${vk_header_version}
+ )
+ # If this json file is not a metalayer, get the needed properties from that target
+ if(TARGET ${TARGET_NAME})
+ set(CONFIG_DEFINES ${CONFIG_DEFINES}
+ -DOUTPUT_FILE="$<TARGET_FILE_DIR:${TARGET_NAME}>/${TARGET_NAME}.json"
+ -DRELATIVE_LAYER_BINARY="${RELATIVE_PATH_PREFIX}$<TARGET_FILE_NAME:${TARGET_NAME}>"
+ )
+ # If this json file is a metalayer, make the output path match the test layer, and there is no layer binary file
+ else()
+ set(CONFIG_DEFINES ${CONFIG_DEFINES}
+ -DOUTPUT_FILE="$<TARGET_FILE_DIR:VkLayer_test>/${TARGET_NAME}.json"
+ )
+ endif()
+ add_custom_target(${TARGET_NAME}-json ALL COMMAND ${CMAKE_COMMAND} ${CONFIG_DEFINES} -P "${CMAKE_CURRENT_BINARY_DIR}/generator.cmake")
+endforeach()
--- /dev/null
+{
+ "file_format_version" : "1.1.1",
+ "layer" : {
+ "name": "VK_LAYER_LUNARG_meta",
+ "type": "GLOBAL",
+ "api_version": "@VK_VERSION@",
+ "implementation_version": "1",
+ "description": "LunarG Test Metalayer",
+ "component_layers": [
+ "VK_LAYER_LUNARG_wrap_objects",
+ "VK_LAYER_LUNARG_test"
+ ]
+ }
+}
--- /dev/null
+{
+ "file_format_version" : "1.0.0",
+ "layer" : {
+ "name": "VK_LAYER_LUNARG_test",
+ "type": "GLOBAL",
+ "library_path": "@RELATIVE_LAYER_BINARY@",
+ "api_version": "@VK_VERSION@",
+ "implementation_version": "1",
+ "description": "LunarG Test Layer",
+ "enable_environment": {
+ "ENABLE_LAYER_TEST_1": "enable"
+ },
+ "disable_environment": {
+ "DISABLE_LAYER_TEST_1": ""
+ }
+ }
+}
--- /dev/null
+{
+ "file_format_version" : "1.0.0",
+ "layer" : {
+ "name": "VK_LAYER_LUNARG_wrap_objects",
+ "type": "GLOBAL",
+ "library_path": "@RELATIVE_LAYER_BINARY@",
+ "api_version": "@VK_VERSION@",
+ "implementation_version": "1",
+ "description": "LunarG Dispatchable Object Wrapping Layer"
+ }
+}
+++ /dev/null
-{
- "file_format_version" : "1.1.1",
- "layer" : {
- "name": "VK_LAYER_LUNARG_meta",
- "type": "GLOBAL",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Metalayer",
- "component_layers": [
- "VK_LAYER_LUNARG_wrap_objects",
- "VK_LAYER_LUNARG_test"
- ]
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_test",
- "type": "GLOBAL",
- "library_path": "./libVkLayer_test.so",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Layer",
- "enable_environment": {
- "ENABLE_LAYER_TEST_1": "enable"
- },
- "disable_environment": {
- "DISABLE_LAYER_TEST_1": ""
- }
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_wrap_objects",
- "type": "GLOBAL",
- "library_path": "./libVkLayer_wrap_objects.so",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Dispatchable Object Wrapping Layer"
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.1.1",
- "layer" : {
- "name": "VK_LAYER_LUNARG_meta",
- "type": "GLOBAL",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Metalayer",
- "component_layers": [
- "VK_LAYER_LUNARG_wrap_objects",
- "VK_LAYER_LUNARG_test"
- ]
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_test",
- "type": "GLOBAL",
- "library_path": "./libVkLayer_test.dylib",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Layer",
- "enable_environment": {
- "ENABLE_LAYER_TEST_1": "enable"
- },
- "disable_environment": {
- "DISABLE_LAYER_TEST_1": ""
- }
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_wrap_objects",
- "type": "GLOBAL",
- "library_path": "./libVkLayer_wrap_objects.dylib",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Dispatchable Object Wrapping Layer"
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.1.1",
- "layer" : {
- "name": "VK_LAYER_LUNARG_meta",
- "type": "GLOBAL",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Metalayer",
- "component_layers": [
- "VK_LAYER_LUNARG_wrap_objects",
- "VK_LAYER_LUNARG_test"
- ]
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_test",
- "type": "GLOBAL",
- "library_path": ".\\libVkLayer_test.dll",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Test Layer",
- "enable_environment": {
- "ENABLE_LAYER_TEST_1": "enable"
- },
- "disable_environment": {
- "DISABLE_LAYER_TEST_1": ""
- }
- }
-}
+++ /dev/null
-{
- "file_format_version" : "1.0.0",
- "layer" : {
- "name": "VK_LAYER_LUNARG_wrap_objects",
- "type": "GLOBAL",
- "library_path": ".\\VkLayer_wrap_objects.dll",
- "api_version": "1.1.79",
- "implementation_version": "1",
- "description": "LunarG Dispatchable Object Wrapping Layer"
- }
-}