@@ -31,51 +31,74 @@ endif()
3131macro (configure_linker_script linker_script_gen linker_pass_define)
3232 set (extra_dependencies ${ARGN} )
3333
34- # Different generators deal with depfiles differently.
35- if (CMAKE_GENERATOR STREQUAL "Unix Makefiles" )
36- # Note that the IMPLICIT_DEPENDS option is currently supported only
37- # for Makefile generators and will be ignored by other generators.
38- set (linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT} )
39- elseif (CMAKE_GENERATOR STREQUAL "Ninja" )
40- # Using DEPFILE with other generators than Ninja is an error.
41- set (linker_script_dep DEPFILE ${PROJECT_BINARY_DIR} /${linker_script_gen} .dep)
34+ if (CONFIG_CMAKE_LINKER_GENERATOR)
35+ if ("${linker_pass_define} " STREQUAL "-DLINKER_ZEPHYR_PREBUILT" )
36+ set (PASS 1)
37+ elseif ("${linker_pass_define} " STREQUAL "-DLINKER_ZEPHYR_FINAL;-DLINKER_PASS2" )
38+ set (PASS 2)
39+ endif ()
40+
41+ add_custom_command (
42+ OUTPUT ${linker_script_gen}
43+ COMMAND ${CMAKE_COMMAND}
44+ -DPASS=${PASS}
45+ -DFORMAT="$<TARGET_PROPERTY:linker,FORMAT>"
46+ -DENTRY="$<TARGET_PROPERTY:linker,ENTRY>"
47+ -DMEMORY_REGIONS="$<TARGET_PROPERTY:linker,MEMORY_REGIONS>"
48+ -DGROUPS="$<TARGET_PROPERTY:linker,GROUPS>"
49+ -DSECTIONS="$<TARGET_PROPERTY:linker,SECTIONS>"
50+ -DSECTION_SETTINGS="$<TARGET_PROPERTY:linker,SECTION_SETTINGS>"
51+ -DSYMBOLS="$<TARGET_PROPERTY:linker,SYMBOLS>"
52+ -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR} /${linker_script_gen}
53+ -P ${ZEPHYR_BASE} /cmake/linker/ld/ld_script.cmake
54+ )
4255 else ()
43- # TODO: How would the linker script dependencies work for non-linker
44- # script generators.
45- message (STATUS "Warning; this generator is not well supported. The
46- Linker script may not be regenerated when it should." )
47- set (linker_script_dep "" )
48- endif ()
56+ # Different generators deal with depfiles differently.
57+ if (CMAKE_GENERATOR STREQUAL "Unix Makefiles" )
58+ # Note that the IMPLICIT_DEPENDS option is currently supported only
59+ # for Makefile generators and will be ignored by other generators.
60+ set (linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT} )
61+ elseif (CMAKE_GENERATOR STREQUAL "Ninja" )
62+ # Using DEPFILE with other generators than Ninja is an error.
63+ set (linker_script_dep DEPFILE ${PROJECT_BINARY_DIR} /${linker_script_gen} .dep)
64+ else ()
65+ # TODO: How would the linker script dependencies work for non-linker
66+ # script generators.
67+ message (STATUS "Warning; this generator is not well supported. The
68+ Linker script may not be regenerated when it should." )
69+ set (linker_script_dep "" )
70+ endif ()
4971
50- zephyr_get_include_directories_for_lang(C current_includes)
51- get_filename_component (base_name ${CMAKE_CURRENT_BINARY_DIR} NAME )
52- get_property (current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
53-
54- add_custom_command (
55- OUTPUT ${linker_script_gen}
56- DEPENDS
57- ${LINKER_SCRIPT}
58- ${AUTOCONF_H}
59- ${extra_dependencies}
60- # NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
61- ${linker_script_dep}
62- COMMAND ${CMAKE_C_COMPILER}
63- -x assembler-with-cpp
64- ${NOSYSDEF_CFLAG}
65- -MD -MF ${linker_script_gen} .dep -MT ${base_name} /${linker_script_gen}
66- -D_LINKER
67- -D_ASMLANGUAGE
68- -imacros ${AUTOCONF_H}
69- ${current_includes}
70- ${current_defines}
71- ${linker_pass_define}
72- -E ${LINKER_SCRIPT}
73- -P # Prevent generation of debug `#line' directives.
74- -o ${linker_script_gen}
75- VERBATIM
76- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
77- COMMAND_EXPAND_LISTS
78- )
72+ zephyr_get_include_directories_for_lang(C current_includes)
73+ get_filename_component (base_name ${CMAKE_CURRENT_BINARY_DIR} NAME )
74+ get_property (current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
75+
76+ add_custom_command (
77+ OUTPUT ${linker_script_gen}
78+ DEPENDS
79+ ${LINKER_SCRIPT}
80+ ${AUTOCONF_H}
81+ ${extra_dependencies}
82+ # NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
83+ ${linker_script_dep}
84+ COMMAND ${CMAKE_C_COMPILER}
85+ -x assembler-with-cpp
86+ ${NOSYSDEF_CFLAG}
87+ -MD -MF ${linker_script_gen} .dep -MT ${base_name} /${linker_script_gen}
88+ -D_LINKER
89+ -D_ASMLANGUAGE
90+ -imacros ${AUTOCONF_H}
91+ ${current_includes}
92+ ${current_defines}
93+ ${linker_pass_define}
94+ -E ${LINKER_SCRIPT}
95+ -P # Prevent generation of debug `#line' directives.
96+ -o ${linker_script_gen}
97+ VERBATIM
98+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
99+ COMMAND_EXPAND_LISTS
100+ )
101+ endif ()
79102endmacro ()
80103
81104# Force symbols to be entered in the output file as undefined symbols
0 commit comments