CMake: use GCC dependency generation for DAPSS files

This commit is contained in:
2026-06-14 11:28:51 -04:00
parent e261787cfe
commit bb83a86fe0
+17 -9
View File
@@ -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
)