repo: Rework test layers to use cmake generators
authorLenny Komow <lenny@lunarg.com>
Fri, 13 Jul 2018 17:57:34 +0000 (11:57 -0600)
committerLenny Komow <lenny@lunarg.com>
Thu, 19 Jul 2018 16:09:40 +0000 (10:09 -0600)
Change-Id: I6a09049619b7155e9f5331f0267d39f1edd42d38

15 files changed:
CMakeLists.txt
loader/CMakeLists.txt
tests/layers/CMakeLists.txt
tests/layers/json/VkLayer_meta.json.in [new file with mode: 0644]
tests/layers/json/VkLayer_test.json.in [new file with mode: 0644]
tests/layers/json/VkLayer_wrap_objects.json.in [new file with mode: 0644]
tests/layers/linux/VkLayer_meta.json [deleted file]
tests/layers/linux/VkLayer_test.json [deleted file]
tests/layers/linux/VkLayer_wrap_objects.json [deleted file]
tests/layers/macos/VkLayer_meta.json [deleted file]
tests/layers/macos/VkLayer_test.json [deleted file]
tests/layers/macos/VkLayer_wrap_objects.json [deleted file]
tests/layers/windows/VkLayer_meta.json [deleted file]
tests/layers/windows/VkLayer_test.json [deleted file]
tests/layers/windows/VkLayer_wrap_objects.json [deleted file]

index 4fbb795e6d991a3aa25d6baed46b26a9e0f528e0..b5dc17fe4b3b2fe085d89986023ef6b45632368f 100644 (file)
@@ -210,6 +210,15 @@ endif()
 
 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()
index a5bbc1d0b01fbab6d074d884e8527694110e2073..b8c806598f7c26f158f431ffdb5f75726ddfa3ab 100644 (file)
@@ -28,15 +28,6 @@ check_function_exists(secure_getenv HAVE_SECURE_GETENV)
 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)
index fa62d57489799168e33faa4c8928649e9b15fdb7..78e45b3381d5fecff106193ccccb651e73b434b7 100644 (file)
 
 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)
@@ -114,3 +68,32 @@ add_vk_layer(wrap_objects ${WRAP_SRCS})
 
 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()
diff --git a/tests/layers/json/VkLayer_meta.json.in b/tests/layers/json/VkLayer_meta.json.in
new file mode 100644 (file)
index 0000000..7511bce
--- /dev/null
@@ -0,0 +1,14 @@
+{
+    "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"
+        ]
+    }
+}
diff --git a/tests/layers/json/VkLayer_test.json.in b/tests/layers/json/VkLayer_test.json.in
new file mode 100644 (file)
index 0000000..054b547
--- /dev/null
@@ -0,0 +1,17 @@
+{
+    "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": ""
+        }
+    }
+}
diff --git a/tests/layers/json/VkLayer_wrap_objects.json.in b/tests/layers/json/VkLayer_wrap_objects.json.in
new file mode 100644 (file)
index 0000000..d33154c
--- /dev/null
@@ -0,0 +1,11 @@
+{
+    "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"
+    }
+}
diff --git a/tests/layers/linux/VkLayer_meta.json b/tests/layers/linux/VkLayer_meta.json
deleted file mode 100644 (file)
index 3a87b38..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-    "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"
-        ]
-    }
-}
diff --git a/tests/layers/linux/VkLayer_test.json b/tests/layers/linux/VkLayer_test.json
deleted file mode 100644 (file)
index f77f949..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-    "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": ""
-        }
-    }
-}
diff --git a/tests/layers/linux/VkLayer_wrap_objects.json b/tests/layers/linux/VkLayer_wrap_objects.json
deleted file mode 100644 (file)
index 754b72f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-    "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"
-    }
-}
diff --git a/tests/layers/macos/VkLayer_meta.json b/tests/layers/macos/VkLayer_meta.json
deleted file mode 100644 (file)
index 3a87b38..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-    "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"
-        ]
-    }
-}
diff --git a/tests/layers/macos/VkLayer_test.json b/tests/layers/macos/VkLayer_test.json
deleted file mode 100644 (file)
index 74746a6..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-    "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": ""
-        }
-    }
-}
diff --git a/tests/layers/macos/VkLayer_wrap_objects.json b/tests/layers/macos/VkLayer_wrap_objects.json
deleted file mode 100644 (file)
index ed85109..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-    "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"
-    }
-}
diff --git a/tests/layers/windows/VkLayer_meta.json b/tests/layers/windows/VkLayer_meta.json
deleted file mode 100644 (file)
index 3a87b38..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-    "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"
-        ]
-    }
-}
diff --git a/tests/layers/windows/VkLayer_test.json b/tests/layers/windows/VkLayer_test.json
deleted file mode 100644 (file)
index 2f4b7aa..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-    "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": ""
-        }
-    }
-}
diff --git a/tests/layers/windows/VkLayer_wrap_objects.json b/tests/layers/windows/VkLayer_wrap_objects.json
deleted file mode 100644 (file)
index 1b177b7..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-    "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"
-    }
-}