Skip to content

Commit c5dd84a

Browse files
SebastianBoecarlescufi
authored andcommitted
cmake: Added function for parsing gcc dependency metadata
Added a function that can parse the dependency information given when invoking gcc with the argument '-M'. This could be used to manually add dependencies detected when preprocessing a file. Signed-off-by: Sebastian Bøe <[email protected]>
1 parent ecf06de commit c5dd84a

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

cmake/extensions.cmake

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# 3.1. *_ifdef
1818
# 3.2. *_ifndef
1919
# 3.3. *_option compiler compatibility checks
20+
# 3.3.1 Toolchain integration
2021
# 3.4. Debugging CMake
2122
# 3.5. File system management
2223

@@ -1244,7 +1245,7 @@ function(zephyr_compile_options_ifndef feature_toggle)
12441245
endif()
12451246
endfunction()
12461247

1247-
# 3.2. *_option Compiler-compatibility checks
1248+
# 3.3. *_option Compiler-compatibility checks
12481249
#
12491250
# Utility functions for silently omitting compiler flags when the
12501251
# compiler lacks support. *_cc_option was ported from KBuild, see
@@ -1334,6 +1335,45 @@ function(target_ld_options target scope)
13341335
endforeach()
13351336
endfunction()
13361337

1338+
# 3.3.1 Toolchain integration
1339+
#
1340+
# 'toolchain_parse_make_rule' is a function that parses the output of
1341+
# 'gcc -M'.
1342+
#
1343+
# The argument 'input_file' is in input parameter with the path to the
1344+
# file with the dependency information.
1345+
#
1346+
# The argument 'include_files' is an output parameter with the result
1347+
# of parsing the include files.
1348+
function(toolchain_parse_make_rule input_file include_files)
1349+
file(READ ${input_file} input)
1350+
1351+
# The file is formatted like this:
1352+
# empty_file.o: misc/empty_file.c \
1353+
# nrf52840_pca10056/nrf52840_pca10056.dts \
1354+
# nrf52840_qiaa.dtsi
1355+
1356+
# Get rid of the backslashes
1357+
string(REPLACE "\\" ";" input_as_list ${input})
1358+
1359+
# Pop the first line and treat it specially
1360+
list(GET input_as_list 0 first_input_line)
1361+
string(FIND ${first_input_line} ": " index)
1362+
math(EXPR j "${index} + 2")
1363+
string(SUBSTRING ${first_input_line} ${j} -1 first_include_file)
1364+
list(REMOVE_AT input_as_list 0)
1365+
1366+
list(APPEND result ${first_include_file})
1367+
1368+
# Add the other lines
1369+
list(APPEND result ${input_as_list})
1370+
1371+
# Strip away the newlines and whitespaces
1372+
list(TRANSFORM result STRIP)
1373+
1374+
set(${include_files} ${result} PARENT_SCOPE)
1375+
endfunction()
1376+
13371377
# 3.4. Debugging CMake
13381378

13391379
# Usage:

0 commit comments

Comments
 (0)