CMake: Emit coverage-toolchain.txt file next to ICD json

When `SWIFTSHADER_EMIT_COVERAGE` is enabled, generate a new `coverage-toolchain.txt` text file next to the `vk_swiftshader_icd.json` file. This file contains a path to the C++ compiler toolchain used to build swiftshader, so that the regres tooling can locate the llvm tools used to parse the coverage data.

Bug: b/152192800
Change-Id: I3aa718206c3262bcd05e13e854002dea8f40801f
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42889
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f39cde5..1912aa9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1339,6 +1339,19 @@
         "${VULKAN_DIR}/vk_swiftshader_icd.json.tmpl"
         "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/vk_swiftshader_icd.json"
     )
+
+    if(SWIFTSHADER_EMIT_COVERAGE)
+        # Emit a coverage-toolchain.txt file next to the vk_swiftshader_icd.json
+        # file so that regres can locate the LLVM toolchain used to build the
+        # .so file. With this, the correct llvm-cov and llvm-profdata tools
+        # from the same toolchain can be located.
+        get_filename_component(COMPILER_TOOLCHAIN_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
+        file(WRITE
+            "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/coverage-toolchain.txt"
+            "${COMPILER_TOOLCHAIN_DIR}"
+        )
+    endif()
+
 endif()
 
 ###########################################################