build: conditional dependency handling of depfile 73/41173/4
authorOle Troan <[email protected]>
Fri, 21 Jun 2024 15:17:09 +0000 (17:17 +0200)
committerOle Tr�an <[email protected]>
Mon, 24 Jun 2024 10:39:43 +0000 (10:39 +0000)
Older distributions like Ubuntu 20.04 uses an old version
of cmake that does not handle absolute paths.
Leave .api dependency handling like before, i.e.
not handle interdependency between .api files for those older
builds.

Type: fix
Change-Id: I3f15a4506f6c95fca7a5b00893dc354cbed42a29
Signed-off-by: Ole Troan <[email protected]>
src/cmake/api.cmake

index cbda400..999bbf9 100644 (file)
@@ -47,15 +47,27 @@ function(vpp_generate_api_c_header file)
 
   get_filename_component(barename ${file} NAME)
 
+# Define a variable for common apigen arguments
+set(COMMON_ARGS
+  OUTPUT ${OUTPUT_HEADERS}
+  COMMAND mkdir -p ${output_dir}
+  COMMAND ${PYENV} ${VPP_APIGEN}
+  ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --outputdir ${output_dir} --output ${output_name} -MF ${dependency_file}
+  DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${VPPAPIGEN_SUBMODULES}
+  COMMENT "Generating API header ${output_name}"
+)
+
+if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
   add_custom_command (
-    OUTPUT ${OUTPUT_HEADERS}
-    COMMAND mkdir -p ${output_dir}
-    COMMAND ${PYENV} ${VPP_APIGEN}
-    ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --outputdir ${output_dir} --output ${output_name} -MF ${dependency_file}
-    DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${VPPAPIGEN_SUBMODULES}
-    COMMENT "Generating API header ${output_name}"
+    ${COMMON_ARGS}
     DEPFILE ${dependency_file}
   )
+else()
+  message(WARNING "Your CMake version does not support DEPFILE. Consider upgrading to CMake 3.20 or later for improved dependency handling.")
+  add_custom_command (
+    ${COMMON_ARGS}
+  )
+endif()
   set(t ${barename}_deps)
 
   if (NOT TARGET ${t})