Skip to content

Commit 2aba39d

Browse files
kesyogfabiobaltieri
authored andcommitted
cmake: Define zephyr_generated_headers as an interface library
Define `zephyr_generated_headers` as an interface library rather than a custom target. This allows CMake libraries to depend on this target AND propagate the dependency if needed using target_link_libraries. Example: If some user header includes offsets.h, even transitively, then offsets.h must be generated before any source file that includes that header is compiled. This can be captured by defining a library `foo` for the header with a public link dependency on zephyr_generated_headers using `target_link_libraries(foo zephyr_generated_headers)`. The ordering dependency on the generated offsets.h header will then propagate to `foo` and any libraries that link against `foo`, even transitively. This was not possible before this CL because one cannot use custom targets as public link dependencies with target_link_libraries. Signed-off-by: Kesavan Yogeswaran <[email protected]>
1 parent b629658 commit 2aba39d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,13 @@ add_custom_target(${DEVICE_API_LD_TARGET}
956956
zephyr_linker_include_generated(CMAKE ${DEVICE_API_LINKER_SECTIONS_CMAKE})
957957

958958
# Add a pseudo-target that is up-to-date when all generated headers
959-
# are up-to-date.
959+
# are up-to-date. Libraries containing files that include these headers can use
960+
# add_dependencies or target_link_libraries against this target to ensure that
961+
# generated headers are up-to-date before the libraries are built. This ordering
962+
# dependency can be propagated to these libraries' dependenents via the PUBLIC
963+
# or INTERFACE option of target_link_libraries.
960964

961-
add_custom_target(zephyr_generated_headers)
965+
add_library(zephyr_generated_headers INTERFACE)
962966
add_dependencies(zephyr_generated_headers
963967
offsets_h version_h
964968
)
@@ -1055,8 +1059,10 @@ if(CONFIG_LLEXT)
10551059
# Weak definitions for these must be added at the end of the link order
10561060
# to avoid shadowing actual implementations.
10571061
add_library(syscall_weakdefs syscall_weakdefs_llext.c)
1058-
add_dependencies(syscall_weakdefs zephyr_generated_headers)
1059-
target_link_libraries(syscall_weakdefs zephyr_interface)
1062+
target_link_libraries(syscall_weakdefs
1063+
zephyr_generated_headers
1064+
zephyr_interface
1065+
)
10601066
list(APPEND NO_WHOLE_ARCHIVE_LIBS syscall_weakdefs)
10611067
endif()
10621068

0 commit comments

Comments
 (0)