Fixes for SPIR-V kernel generation via CMake

This PR depends on #160, which implements building `generate_cc_embed_data`. The PR does not implement `iree_glsl_cc_library`, but I think that can be refactored after getting the complete compiler or samples target working.

Closes #164

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/164 from marbre:cmake-3 3705c9e46d15aae0f3f5b0e3df003e84f733e77a
PiperOrigin-RevId: 284875458
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac9b1bb..9112989 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,6 +92,7 @@
 add_subdirectory(iree/vm)
 
 if(${IREE_BUILD_COMPILER})
+  add_subdirectory(third_party/glslang EXCLUDE_FROM_ALL)
   add_subdirectory(iree/compiler)
 endif()
 
diff --git a/iree/compiler/Translation/SPIRV/CMakeLists.txt b/iree/compiler/Translation/SPIRV/CMakeLists.txt
index 2ae8217..630411f 100644
--- a/iree/compiler/Translation/SPIRV/CMakeLists.txt
+++ b/iree/compiler/Translation/SPIRV/CMakeLists.txt
@@ -50,8 +50,9 @@
     iree::compiler::Serialization
     iree::compiler::Transforms
     iree::compiler::Transforms::Sequencer
-    # TODO(benvanik): generate filetoc for kernels.
+    # TODO(marbre): Use instead of Kernels target, as soon as build with iree_glsl_cc_library
     #iree::compiler::Translation::SPIRV::Kernels
+    iree_compiler_Translation_SPIRV_Kernels
     iree::compiler::Utils
     iree::schemas
     iree::schemas::spirv_executable_def_cc_fbs
diff --git a/iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt b/iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt
index 38b7f3d..f2633b1 100644
--- a/iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt
+++ b/iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt
@@ -23,3 +23,30 @@
 #    "reduce_untiled.comp"
 #   PUBLIC
 # )
+
+add_custom_command(
+  OUTPUT matmul.spv
+  COMMAND glslangValidator -V "${CMAKE_CURRENT_SOURCE_DIR}/matmul.comp" -o matmul.spv
+  DEPENDS glslangValidator
+)
+
+add_custom_command(
+  OUTPUT reduce_untiled.spv
+  COMMAND glslangValidator -V "${CMAKE_CURRENT_SOURCE_DIR}/reduce_untiled.comp" -o reduce_untiled.spv
+  DEPENDS glslangValidator
+)
+
+add_custom_command(
+  OUTPUT Kernels.h Kernels.cc
+  COMMAND generate_cc_embed_data matmul.spv reduce_untiled.spv
+          --output_header=Kernels.h
+          --output_impl=Kernels.cc
+          --identifier=Kernels
+          --cpp_namespace=mlir::iree_compiler::spirv_kernels
+          --flatten
+  DEPENDS generate_cc_embed_data
+          matmul.spv
+          reduce_untiled.spv
+)
+
+add_library(iree_compiler_Translation_SPIRV_Kernels STATIC Kernels.cc)
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index 08a729b..f8770d8 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -45,8 +45,7 @@
       ${_ALWAYSLINK_LIBS}
       iree::compiler::Translation::Interpreter
       iree::compiler::Translation::Sequencer
-      # TODO(benvanik): get the SPIR-V translation working.
-      #iree::compiler::Translation::SPIRV
+      iree::compiler::Translation::SPIRV
       MLIRTranslateClParser
   )