Skip to content

Commit 17d8bfb

Browse files
mbolivar-nordicSebastianBoe
authored andcommitted
cmake: tweak linker source initialization
The current approach with a global property is a little hacky and doesn't reflect the intent of the zephyr_linker_sources() call in boilerplate.cmake. Add a separate helper for initializing the files to at least avoid using the global property. It would be even nicer to manage these as generated files which the link steps depend on, but this is a start. Signed-off-by: Marti Bolivar <[email protected]>
1 parent f338f47 commit 17d8bfb

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

cmake/app/boilerplate.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ add_custom_target(
8686
# Equivalent to rm -rf build/*
8787
)
8888

89-
# Dummy add to generate files.
90-
zephyr_linker_sources(SECTIONS)
89+
# Zephyr's linker scripts are the result of running the C preprocessor
90+
# on per-architecture files. These files can include various sources from
91+
# around the zephyr tree using the zephyr_linker_sources() mechanism.
92+
# This helper is used to set up these files.
93+
zephyr_init_linker_sources()
9194

9295
# The BOARD can be set by 3 sources. Through environment variables,
9396
# through the cmake CLI, and through CMakeLists.txt.

cmake/extensions.cmake

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -841,26 +841,16 @@ endfunction()
841841
# Friendly reminder: Beware of the different ways the location counter ('.')
842842
# behaves inside vs. outside section definitions.
843843
function(zephyr_linker_sources location)
844-
# Set up the paths to the destination files. These files are #included inside
845-
# the global linker.ld.
844+
# Set up the paths to the destination files. These files are
845+
# #included inside the global linker.ld. Keep these settings in sync
846+
# with zephyr_init_linker_sources().
846847
set(snippet_base "${__build_dir}/include/generated")
847848
set(sections_path "${snippet_base}/snippets-sections.ld")
848849
set(ram_sections_path "${snippet_base}/snippets-ram-sections.ld")
849850
set(noinit_path "${snippet_base}/snippets-noinit.ld")
850851
set(rwdata_path "${snippet_base}/snippets-rwdata.ld")
851852
set(rodata_path "${snippet_base}/snippets-rodata.ld")
852853

853-
# Clear destination files if this is the first time the function is called.
854-
get_property(cleared GLOBAL PROPERTY snippet_files_cleared)
855-
if (NOT DEFINED cleared)
856-
file(WRITE ${sections_path} "")
857-
file(WRITE ${ram_sections_path} "")
858-
file(WRITE ${noinit_path} "")
859-
file(WRITE ${rwdata_path} "")
860-
file(WRITE ${rodata_path} "")
861-
set_property(GLOBAL PROPERTY snippet_files_cleared true)
862-
endif()
863-
864854
# Choose destination file, based on the <location> argument.
865855
if ("${location}" STREQUAL "SECTIONS")
866856
set(snippet_path "${sections_path}")
@@ -896,6 +886,21 @@ function(zephyr_linker_sources location)
896886
endforeach()
897887
endfunction(zephyr_linker_sources)
898888

889+
# Private helper to initialize zephyr_linker_sources()
890+
function(zephyr_init_linker_sources)
891+
set(snippet_base "${__build_dir}/include/generated")
892+
set(sections_path "${snippet_base}/snippets-sections.ld")
893+
set(ram_sections_path "${snippet_base}/snippets-ram-sections.ld")
894+
set(noinit_path "${snippet_base}/snippets-noinit.ld")
895+
set(rwdata_path "${snippet_base}/snippets-rwdata.ld")
896+
set(rodata_path "${snippet_base}/snippets-rodata.ld")
897+
898+
file(WRITE ${sections_path} "")
899+
file(WRITE ${ram_sections_path} "")
900+
file(WRITE ${noinit_path} "")
901+
file(WRITE ${rwdata_path} "")
902+
file(WRITE ${rodata_path} "")
903+
endfunction()
899904

900905
# Helper function for CONFIG_CODE_DATA_RELOCATION
901906
# Call this function with 2 arguments file and then memory location

0 commit comments

Comments
 (0)