sw:vec_iree: Update emitC targets (Improved)

sw:vec_iree: Update emitC targets

This is an improved version of https://spacebeaker-review.googlesource.com/c/shodan/sw/vec-iree/+/15880

Match https://github.com/google/iree/pull/7929

Change-Id: I038cd98c62020f3cf2719facba90a33d28e75308
diff --git a/cmake/springbok_c_module.cmake b/cmake/springbok_c_module.cmake
index e111263..29c1ae4 100644
--- a/cmake/springbok_c_module.cmake
+++ b/cmake/springbok_c_module.cmake
@@ -74,10 +74,11 @@
 
   set(_RULE_C_NAME "${_RULE_NAME}_c")
   set(_LIB_NAME "${_PACKAGE_NAME}_${_RULE_C_NAME}")
-  set(_GEN_TARGET "${_LIB_NAME}_gen")
   set(_O_FILE_NAME ${_RULE_C_NAME}.o)
   set(_H_FILE_NAME ${_RULE_C_NAME}.h)
-  set(_EMITC_FILE_NAME ${_RULE_NAME}_emitc.h)
+  set(_RULE_EMITC_NAME "${_RULE_NAME}_emitc")
+  set(_EMITC_LIB_NAME "${_PACKAGE_NAME}_${_RULE_EMITC_NAME}")
+  set(_EMITC_FILE_NAME ${_RULE_EMITC_NAME}.h)
 
   ## Example with VM C module.
   # Setup args for iree-translate.
@@ -107,31 +108,39 @@
     DEPENDS ${_TRANSLATE_TOOL_EXECUTABLE} ${_MLIR_SRC} ${_LINKER_TOOL_EXECUTABLE}
   )
 
-  add_custom_target(
-    ${_GEN_TARGET}
-    DEPENDS
-      "${_EMITC_FILE_NAME}"
+  add_library(${_LIB_NAME}
+    STATIC
+    ${_O_FILE_NAME}
   )
 
-   add_library(${_LIB_NAME}
-   STATIC
-   ${_O_FILE_NAME}
-  )
-  add_dependencies(${_LIB_NAME} ${_GEN_TARGET})
-
   SET_TARGET_PROPERTIES(
     ${_LIB_NAME}
     PROPERTIES
-    LINKER_LANGUAGE C
+      LINKER_LANGUAGE C
+  )
+
+  add_library(${_EMITC_LIB_NAME}
+    STATIC
+    ${_EMITC_FILE_NAME}
+  )
+  target_compile_definitions(${_EMITC_LIB_NAME} PUBLIC EMITC_IMPLEMENTATION)
+
+  SET_TARGET_PROPERTIES(
+    ${_EMITC_LIB_NAME}
+    PROPERTIES
+      LINKER_LANGUAGE C
   )
 
   # Alias the iree_package_name library to iree::package::name.
   # This lets us more clearly map to Bazel and makes it possible to
   # disambiguate the underscores in paths vs. the separators.
   add_library(${_PACKAGE_NS}::${_RULE_C_NAME} ALIAS ${_LIB_NAME})
+  add_library(${_PACKAGE_NS}::${_RULE_EMITC_NAME} ALIAS ${_EMITC_LIB_NAME})
   iree_package_dir(_PACKAGE_DIR)
   if(${_RULE_C_NAME} STREQUAL ${_PACKAGE_DIR})
     add_library(${_PACKAGE_NS} ALIAS ${_LIB_NAME})
   endif()
-
+  if(${_RULE_EMITC_NAME} STREQUAL ${_PACKAGE_DIR})
+    add_library(${_PACKAGE_NS} ALIAS ${_EMITC_LIB_NAME})
+  endif()
 endfunction()
diff --git a/samples/simple_vec_mul/CMakeLists.txt b/samples/simple_vec_mul/CMakeLists.txt
index c6149ba..c4bcd03 100644
--- a/samples/simple_vec_mul/CMakeLists.txt
+++ b/samples/simple_vec_mul/CMakeLists.txt
@@ -58,15 +58,6 @@
     "LINKER:--defsym=__stack_size__=20k"
 )
 
-iree_cc_library(
-  NAME
-    simple_float_mul_emitc
-  HDRS
-    "simple_float_mul_c_module_static_emitc.h"
-  DEFINES
-    "EMITC_IMPLEMENTATION"
-)
-
 iree_cc_binary(
   NAME
     simple_float_vec_mul_emitc_static
@@ -74,7 +65,7 @@
     "float_vec.c"
   DEPS
     ::simple_float_mul_c_module_static_c
-    ::simple_float_mul_emitc
+    ::simple_float_mul_c_module_static_emitc
     samples::util::util_emitc
   LINKOPTS
     "LINKER:--defsym=__stack_size__=20k"
@@ -94,15 +85,6 @@
     "LINKER:--defsym=__stack_size__=20k"
 )
 
-iree_cc_library(
-  NAME
-    simple_int_mul_emitc
-  HDRS
-    "simple_int_mul_c_module_static_emitc.h"
-  DEFINES
-    "EMITC_IMPLEMENTATION"
-)
-
 iree_cc_binary(
   NAME
     simple_int_vec_mul_emitc_static
@@ -110,7 +92,7 @@
     "int_vec.c"
   DEPS
     ::simple_int_mul_c_module_static_c
-    ::simple_int_mul_emitc
+    ::simple_int_mul_c_module_static_emitc
     samples::util::util_emitc
   LINKOPTS
     "LINKER:--defsym=__stack_size__=20k"