misc: support api generated dependency for multiarch source

Fix dependency issues where multi-arch file is using API generated file.

Type: improvement
Change-Id: I5d4af7a630529bc138c35841723e38938f36d963
Signed-off-by: Ole Troan <ot@cisco.com>
diff --git a/src/cmake/api.cmake b/src/cmake/api.cmake
index f3af687..6747285 100644
--- a/src/cmake/api.cmake
+++ b/src/cmake/api.cmake
@@ -49,6 +49,7 @@
     add_custom_target(${t} ALL DEPENDS ${OUTPUT_HEADERS})
     add_dependencies(api_headers ${t})
   endif()
+
 endfunction()
 
 function(vpp_generate_api_json_header file dir component)
@@ -160,12 +161,15 @@
     get_filename_component(name ${file} NAME)
     list(APPEND header_files
       ${file}.h
+      ${file}_enum.h
+      ${file}_types.h
       ${file}.json
       ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.h
       ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.hpp
     )
   endforeach()
   add_custom_target(${target} DEPENDS ${header_files})
+  add_dependencies(api_headers ${target})
 endfunction()
 
 add_custom_target(api_headers
diff --git a/src/cmake/cpu.cmake b/src/cmake/cpu.cmake
index b3f9f0e..623c9de 100644
--- a/src/cmake/cpu.cmake
+++ b/src/cmake/cpu.cmake
@@ -125,14 +125,21 @@
   endif()
 endif()
 
-macro(vpp_library_set_multiarch_sources lib deps)
+macro(vpp_library_set_multiarch_sources lib)
+  cmake_parse_arguments(ARG
+    ""
+    ""
+    "SOURCES;DEPENDS"
+    ${ARGN}
+  )
+
   foreach(V ${MARCH_VARIANTS})
     list(GET V 0 VARIANT)
     list(GET V 1 VARIANT_FLAGS)
     set(l ${lib}_${VARIANT})
-    add_library(${l} OBJECT ${ARGN})
-    if("${deps}")
-      add_dependencies(${l} ${deps})
+    add_library(${l} OBJECT ${ARG_SOURCES})
+    if(ARG_DEPENDS)
+      add_dependencies(${l} ${ARG_DEPENDS})
     endif()
     set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
     target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}")
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index 3f17e30..fdd3469 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -46,7 +46,7 @@
   endif()
 
   if(ARG_MULTIARCH_SOURCES)
-    vpp_library_set_multiarch_sources(${lib} "${ARG_DEPENDS}" ${ARG_MULTIARCH_SOURCES})
+    vpp_library_set_multiarch_sources(${lib} DEPENDS ${ARG_DEPENDS} SOURCES ${ARG_MULTIARCH_SOURCES})
   endif()
 
   if(ARG_API_FILES)
@@ -65,6 +65,10 @@
     endforeach()
   endif()
 
+  if(NOT VPP_EXTERNAL_PROJECT)
+    add_dependencies(${lib} api_headers)
+  endif()
+
   if(ARG_DEPENDS)
     add_dependencies(${lib} ${ARG_DEPENDS})
   endif()
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index aca90ab..9b0383f 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -34,28 +34,29 @@
   vpp_add_api_files(${plugin_name} plugins ${PLUGIN_COMPONENT} ${PLUGIN_API_FILES})
   foreach(f ${PLUGIN_API_FILES})
     get_filename_component(dir ${f} DIRECTORY)
-    list(APPEND api_includes ${f}.h ${f}.json)
+    list(APPEND api_includes ${f}.h ${f}_enum.h ${f}_types.h ${f}.json)
     install(
-      FILES ${CMAKE_CURRENT_BINARY_DIR}/${f}.h
+      FILES
+      ${CMAKE_CURRENT_BINARY_DIR}/${f}.h
       ${CMAKE_CURRENT_BINARY_DIR}/${f}_enum.h
       ${CMAKE_CURRENT_BINARY_DIR}/${f}_types.h
       DESTINATION include/vpp_plugins/${name}/${dir}
       COMPONENT ${PLUGIN_DEV_COMPONENT}
     )
   endforeach()
-  add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_includes})
+  add_library(${plugin_name} SHARED ${api_includes} ${PLUGIN_SOURCES})
   set_target_properties(${plugin_name} PROPERTIES NO_SONAME 1)
   target_compile_options(${plugin_name} PRIVATE "-fvisibility=hidden")
   target_compile_options (${plugin_name} PRIVATE "-ffunction-sections")
   target_compile_options (${plugin_name} PRIVATE "-fdata-sections")
   target_link_libraries (${plugin_name} "-Wl,--gc-sections")
   set(deps "")
-  if(PLUGIN_API_FILES)
-    list(APPEND deps ${plugin_name}_api_headers)
-  endif()
   if(NOT VPP_EXTERNAL_PROJECT)
     list(APPEND deps vpp_version_h api_headers)
   endif()
+  if(PLUGIN_API_FILES)
+    list(APPEND deps ${plugin_name}_api_headers)
+  endif()
   if(deps)
     add_dependencies(${plugin_name} ${deps})
   endif()
@@ -63,7 +64,7 @@
     PREFIX ""
     LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_plugins)
   if(PLUGIN_MULTIARCH_SOURCES)
-    vpp_library_set_multiarch_sources(${plugin_name} "${deps}" ${PLUGIN_MULTIARCH_SOURCES})
+    vpp_library_set_multiarch_sources(${plugin_name} SOURCES ${PLUGIN_MULTIARCH_SOURCES} DEPENDS ${deps})
   endif()
   if(PLUGIN_LINK_LIBRARIES)
     target_link_libraries(${plugin_name} ${PLUGIN_LINK_LIBRARIES})
@@ -86,12 +87,12 @@
     add_library(${test_plugin_name} SHARED ${PLUGIN_API_TEST_SOURCES}
 		${api_includes})
     set_target_properties(${test_plugin_name} PROPERTIES NO_SONAME 1)
-    if(PLUGIN_API_FILES)
-      add_dependencies(${test_plugin_name} ${plugin_name}_api_headers)
-    endif()
     if(NOT VPP_EXTERNAL_PROJECT)
       add_dependencies(${test_plugin_name} api_headers)
     endif()
+    if(PLUGIN_API_FILES)
+      add_dependencies(${test_plugin_name} ${plugin_name}_api_headers)
+    endif()
     set_target_properties(${test_plugin_name} PROPERTIES
       PREFIX ""
       LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vpp_api_test_plugins)
diff --git a/src/plugins/nat/CMakeLists.txt b/src/plugins/nat/CMakeLists.txt
index d3f3eac..8fefadf 100644
--- a/src/plugins/nat/CMakeLists.txt
+++ b/src/plugins/nat/CMakeLists.txt
@@ -143,8 +143,11 @@
 add_vpp_plugin(pnat
   SOURCES
   pnat/pnat.c
+  pnat/pnat_node.c
   pnat/pnat_cli.c
   pnat/pnat_api.c
+
+  MULTIARCH_SOURCES
   pnat/pnat_node.c
 
   API_FILES
diff --git a/src/plugins/nat/pnat/pnat_node.c b/src/plugins/nat/pnat/pnat_node.c
index 0209b49..ec505cf 100644
--- a/src/plugins/nat/pnat/pnat_node.c
+++ b/src/plugins/nat/pnat/pnat_node.c
@@ -44,6 +44,7 @@
     return pnat_node_inline(vm, node, frame, PNAT_IP4_OUTPUT, VLIB_TX);
 }
 
+#ifndef CLIB_MARCH_VARIANT
 VLIB_REGISTER_NODE(pnat_input_node) = {
     .name = "pnat-input",
     .vector_size = sizeof(u32),
@@ -67,6 +68,7 @@
     .error_counters = pnat_error_counters,
     .sibling_of = "pnat-input",
 };
+#endif
 
 /* Hook up features */
 VNET_FEATURE_INIT(pnat_input, static) = {