tests: vlog: generate techmaps and pass it to yosys

Signed-off-by: Karol Gugala <kgugala@antmicro.com>
diff --git a/fig28-lutff-pair/CMakeLists.txt b/fig28-lutff-pair/CMakeLists.txt
index 75930bf..7b8e578 100644
--- a/fig28-lutff-pair/CMakeLists.txt
+++ b/fig28-lutff-pair/CMakeLists.txt
@@ -2,4 +2,4 @@
 add_subdirectory(ff)
 add_subdirectory(omux)
 add_file_target(FILE pair.sim.v SCANNER_TYPE verilog)
-v2x_test_both(NAME pair TOP_MODULE pair)
+v2x_test_both(NAME pair TOP_MODULE pair TECHMAPS omux/omux.techmap.v)
diff --git a/v2x_tests.cmake b/v2x_tests.cmake
index 0c34fe4..d0869e7 100644
--- a/v2x_tests.cmake
+++ b/v2x_tests.cmake
@@ -154,10 +154,12 @@
   #
   # NAME name of the test.
   # TOP_MODULE name of the top verilog module that has to be tested.
+  # TECHMAPS [optional] list of techmaps files to be used when synthesizing the design
   #
   # Usage: v2x_test_model(NAME <test_name> TOP_MODULE <top_module.v>) (All fields are required)
 
   set(oneValueArgs NAME TOP_MODULE)
+  set(multiValueArgs TECHMAPS)
   cmake_parse_arguments(
     V2X_TEST_BOTH
     "${options}"
@@ -172,6 +174,41 @@
   set(SRC ${NAME}.sim.v)
   v2x(NAME ${NAME} SRCS ${SRC} TOP_MODULE ${TOP_MODULE})
 
+  set(MERGED_TECHMAP_FILE "${NAME}.techmap.merged.v")
+  set(MERGED_TECHMAP "${MERGED_TECHMAP_FILE}")
+  set(TECHMAP_INPUT "")
+  set(TECHMAP_DEPS "")
+  foreach(MAP ${V2X_TEST_BOTH_TECHMAPS})
+    list(
+      APPEND
+      TECHMAP_INPUT
+      ${MAP}
+    )
+    append_file_dependency(TECHMAP_DEPS ${MAP})
+  endforeach()
+
+  if(NOT ${TECHMAP_INPUT} STREQUAL "")
+    add_custom_command(
+      OUTPUT "${MERGED_TECHMAP}"
+      DEPENDS ${TECHMAP_DEPS}
+      COMMAND
+      cat ${TECHMAP_INPUT} > ${MERGED_TECHMAP}
+      WORKING_DIRECTORY
+        ${CMAKE_CURRENT_BINARY_DIR}
+    )
+  else()
+    # if there are no techmaps to merge, create an empty .v file so Yosys is happy
+    add_custom_command(
+      OUTPUT "${MERGED_TECHMAP}"
+      COMMAND
+        touch ${MERGED_TECHMAP}
+      WORKING_DIRECTORY
+        ${CMAKE_CURRENT_BINARY_DIR}
+    )
+  endif()
+
+  add_file_target(FILE "${MERGED_TECHMAP}" GENERATED)
+
   v2x_test_generic(NAME ${NAME} TYPE pb_type)
   v2x_test_generic(NAME ${NAME} TYPE model)
   vpr_test_pb_type(NAME ${NAME} TOP_MODULE ${TOP_MODULE})