Move reusable Vulkan code from VulkanBenchmarks to new VulkanWrapper library

This will allow us to reuse this code across unit tests and benchmarks.

Bug: b/176981107
Change-Id: Ie5ea3708cb959dbd0189658b42f01bad998ae94a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51869
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6d243b8..a880c50 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -984,6 +984,11 @@
 endif()
 
 if(SWIFTSHADER_BUILD_BENCHMARKS)
+    if (NOT TARGET glslang)
+        add_subdirectory(${THIRD_PARTY_DIR}/glslang)
+    endif()
+    add_subdirectory(${TESTS_DIR}/VulkanWrapper) # Add VulkanWrapper target
+
     if (NOT TARGET benchmark::benchmark)
         set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE)
         add_subdirectory(${THIRD_PARTY_DIR}/benchmark)
@@ -991,10 +996,6 @@
         set_target_properties(benchmark_main PROPERTIES FOLDER "third_party")
     endif()
 
-    if (NOT TARGET glslang)
-        add_subdirectory(${THIRD_PARTY_DIR}/glslang)
-    endif()
-
     add_subdirectory(${TESTS_DIR}/ReactorBenchmarks) # Add ReactorBenchmarks target
     add_subdirectory(${TESTS_DIR}/SystemBenchmarks) # Add system-benchmarks target
     add_subdirectory(${TESTS_DIR}/VulkanBenchmarks) # Add VulkanBenchmarks target
diff --git a/tests/VulkanBenchmarks/CMakeLists.txt b/tests/VulkanBenchmarks/CMakeLists.txt
index ca7708e..9186bd6 100644
--- a/tests/VulkanBenchmarks/CMakeLists.txt
+++ b/tests/VulkanBenchmarks/CMakeLists.txt
@@ -22,22 +22,8 @@
 )
 
 set(VULKAN_BENCHMARKS_SRC_FILES
-    Buffer.cpp
-    Buffer.hpp
-    Framebuffer.cpp
-    Framebuffer.hpp
-    Image.cpp
-    Image.hpp
     main.cpp
-    Swapchain.cpp
-    Swapchain.hpp
-    Util.cpp
-    Util.hpp
     VulkanBenchmarks.cpp
-    VulkanHeaders.cpp
-    VulkanHeaders.hpp
-    Window.cpp
-    Window.hpp
 )
 
 add_executable(VulkanBenchmarks
@@ -48,16 +34,8 @@
     message(FATAL_ERROR "Missing required target: benchmark::benchmark")
 endif()
 
-if (NOT TARGET glslang)
-    message(FATAL_ERROR "Missing required target: glslang")
-endif()
-
-if (NOT TARGET glslang-default-resource-limits)
-    message(FATAL_ERROR "Missing required target: glslang-default-resource-limits")
-endif()
-
-if (NOT TARGET SPIRV)
-    message(FATAL_ERROR "Missing required target: SPIRV")
+if (NOT TARGET VulkanWrapper)
+    message(FATAL_ERROR "Missing required target: VulkanWrapper")
 endif()
 
 add_dependencies(VulkanBenchmarks
@@ -87,8 +65,6 @@
 target_link_libraries(VulkanBenchmarks
     PRIVATE
         benchmark::benchmark
-        glslang
-        glslang-default-resource-limits
-        SPIRV
+        VulkanWrapper
         ${ROOT_PROJECT_LINK_LIBRARIES}
 )
diff --git a/tests/VulkanBenchmarks/Buffer.cpp b/tests/VulkanWrapper/Buffer.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Buffer.cpp
rename to tests/VulkanWrapper/Buffer.cpp
diff --git a/tests/VulkanBenchmarks/Buffer.hpp b/tests/VulkanWrapper/Buffer.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Buffer.hpp
rename to tests/VulkanWrapper/Buffer.hpp
diff --git a/tests/VulkanWrapper/CMakeLists.txt b/tests/VulkanWrapper/CMakeLists.txt
new file mode 100644
index 0000000..b7851c7
--- /dev/null
+++ b/tests/VulkanWrapper/CMakeLists.txt
@@ -0,0 +1,78 @@
+# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(ROOT_PROJECT_COMPILE_OPTIONS
+    ${WARNINGS_AS_ERRORS}
+)
+
+set(VULKAN_WRAPPER_SRC_FILES
+    Buffer.hpp
+    Framebuffer.hpp
+    Image.hpp
+    Swapchain.hpp
+    Util.hpp
+    VulkanHeaders.hpp
+    Window.hpp
+    Buffer.cpp
+    Framebuffer.cpp
+    Image.cpp
+    Swapchain.cpp
+    Util.cpp
+    VulkanHeaders.cpp
+    Window.cpp
+)
+
+add_library(VulkanWrapper STATIC
+    ${VULKAN_WRAPPER_SRC_FILES}
+)
+
+if (NOT TARGET glslang)
+    message(FATAL_ERROR "Missing required target: glslang")
+endif()
+
+if (NOT TARGET glslang-default-resource-limits)
+    message(FATAL_ERROR "Missing required target: glslang-default-resource-limits")
+endif()
+
+if (NOT TARGET SPIRV)
+    message(FATAL_ERROR "Missing required target: SPIRV")
+endif()
+
+set_target_properties(VulkanWrapper PROPERTIES
+    FOLDER "Benchmarks"
+    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
+)
+
+target_include_directories(VulkanWrapper
+    PUBLIC
+        "."
+        "${SWIFTSHADER_DIR}/include"
+)
+
+target_compile_options(VulkanWrapper
+    PRIVATE
+        ${ROOT_PROJECT_COMPILE_OPTIONS}
+)
+
+target_link_options(VulkanWrapper
+    PRIVATE
+        ${SWIFTSHADER_LINK_FLAGS}
+)
+
+target_link_libraries(VulkanWrapper
+    PUBLIC
+        glslang
+        glslang-default-resource-limits
+        SPIRV
+)
diff --git a/tests/VulkanBenchmarks/Framebuffer.cpp b/tests/VulkanWrapper/Framebuffer.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Framebuffer.cpp
rename to tests/VulkanWrapper/Framebuffer.cpp
diff --git a/tests/VulkanBenchmarks/Framebuffer.hpp b/tests/VulkanWrapper/Framebuffer.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Framebuffer.hpp
rename to tests/VulkanWrapper/Framebuffer.hpp
diff --git a/tests/VulkanBenchmarks/Image.cpp b/tests/VulkanWrapper/Image.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Image.cpp
rename to tests/VulkanWrapper/Image.cpp
diff --git a/tests/VulkanBenchmarks/Image.hpp b/tests/VulkanWrapper/Image.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Image.hpp
rename to tests/VulkanWrapper/Image.hpp
diff --git a/tests/VulkanBenchmarks/Swapchain.cpp b/tests/VulkanWrapper/Swapchain.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Swapchain.cpp
rename to tests/VulkanWrapper/Swapchain.cpp
diff --git a/tests/VulkanBenchmarks/Swapchain.hpp b/tests/VulkanWrapper/Swapchain.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Swapchain.hpp
rename to tests/VulkanWrapper/Swapchain.hpp
diff --git a/tests/VulkanBenchmarks/Util.cpp b/tests/VulkanWrapper/Util.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Util.cpp
rename to tests/VulkanWrapper/Util.cpp
diff --git a/tests/VulkanBenchmarks/Util.hpp b/tests/VulkanWrapper/Util.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Util.hpp
rename to tests/VulkanWrapper/Util.hpp
diff --git a/tests/VulkanBenchmarks/VulkanHeaders.cpp b/tests/VulkanWrapper/VulkanHeaders.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/VulkanHeaders.cpp
rename to tests/VulkanWrapper/VulkanHeaders.cpp
diff --git a/tests/VulkanBenchmarks/VulkanHeaders.hpp b/tests/VulkanWrapper/VulkanHeaders.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/VulkanHeaders.hpp
rename to tests/VulkanWrapper/VulkanHeaders.hpp
diff --git a/tests/VulkanBenchmarks/Window.cpp b/tests/VulkanWrapper/Window.cpp
similarity index 100%
rename from tests/VulkanBenchmarks/Window.cpp
rename to tests/VulkanWrapper/Window.cpp
diff --git a/tests/VulkanBenchmarks/Window.hpp b/tests/VulkanWrapper/Window.hpp
similarity index 100%
rename from tests/VulkanBenchmarks/Window.hpp
rename to tests/VulkanWrapper/Window.hpp