From bb83a86fe0185cd91cd8297daee5bf18dc0627ff Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 14 Jun 2026 11:28:51 -0400 Subject: [PATCH] CMake: use GCC dependency generation for DAPSS files --- cmake/DAPSS.cmake | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cmake/DAPSS.cmake b/cmake/DAPSS.cmake index 9749c0c..fcf4ac3 100644 --- a/cmake/DAPSS.cmake +++ b/cmake/DAPSS.cmake @@ -54,13 +54,12 @@ function(add_daps_target target_name) list(APPEND include_flags "-I${include_dir}") endforeach() - # Add current source directory to includes if it's not already there - if(source_dir) - list(APPEND include_flags "-I${source_dir}") - endif() + list(APPEND include_flags "-I${CMAKE_CURRENT_SOURCE_DIR}") - # Convert list to space-separated string - string(REPLACE ";" " " include_flags_str "${include_flags}") + # Add source subdirectory to includes when SOURCES lists a path prefix + if(source_dir) + list(APPEND include_flags "-I${CMAKE_CURRENT_SOURCE_DIR}/${source_dir}") + endif() # Find C compiler if not already set if(NOT CMAKE_C_COMPILER) @@ -70,11 +69,20 @@ function(add_daps_target target_name) endif() endif() - # Create custom command to preprocess the file + set(depfile "${output_file}.d") + + # Preprocess with -MD so #included .dapss files become build dependencies + # (e.g. body specs that #include ../elp_4k_usb_cam.dapss). add_custom_command( OUTPUT ${output_file} - COMMAND sh -c "\"${CMAKE_C_COMPILER}\" -E -P -x c ${include_flags_str} \"${CMAKE_CURRENT_SOURCE_DIR}/${source_file}\" > \"${output_file}\"" - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source_file} + COMMAND "${CMAKE_C_COMPILER}" + -E -P -x c + ${include_flags} + -MD -MQ "${output_file}" -MF "${depfile}" + -o "${output_file}" + "${CMAKE_CURRENT_SOURCE_DIR}/${source_file}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${source_file}" + DEPFILE "${depfile}" COMMENT "Preprocessing ${source_file} to ${base_name}.daps" VERBATIM )