Skip to content

Commit 5f347ee

Browse files
mped-oticonaescolar
authored andcommitted
cmake: move configure_linker_script to ld/target.cmake
While configure_linker_script() may be useful for other linkers, it currently only aimed at GNU ld. To really be useful among different linkers, we would need to abstract its usage of the C preprocessor. We can do this later, if needed. No functional change expected. Signed-off-by: Mark Ruvald Pedersen <[email protected]>
1 parent fbcea17 commit 5f347ee

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

CMakeLists.txt

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -408,52 +408,6 @@ endif()
408408

409409
configure_file(version.h.in ${PROJECT_BINARY_DIR}/include/generated/version.h)
410410

411-
# Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}
412-
macro(configure_linker_script linker_script_gen linker_pass_define)
413-
set(extra_dependencies ${ARGN})
414-
415-
# Different generators deal with depfiles differently.
416-
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
417-
# Note that the IMPLICIT_DEPENDS option is currently supported only
418-
# for Makefile generators and will be ignored by other generators.
419-
set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
420-
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
421-
# Using DEPFILE with other generators than Ninja is an error.
422-
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_script_gen}.dep)
423-
else()
424-
# TODO: How would the linker script dependencies work for non-linker
425-
# script generators.
426-
message(STATUS "Warning; this generator is not well supported. The
427-
Linker script may not be regenerated when it should.")
428-
set(linker_script_dep "")
429-
endif()
430-
431-
zephyr_get_include_directories_for_lang(C current_includes)
432-
get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME)
433-
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
434-
435-
add_custom_command(
436-
OUTPUT ${linker_script_gen}
437-
DEPENDS
438-
${LINKER_SCRIPT}
439-
${extra_dependencies}
440-
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
441-
${linker_script_dep}
442-
COMMAND ${CMAKE_C_COMPILER}
443-
-x assembler-with-cpp
444-
${NOSYSDEF_CFLAG}
445-
-MD -MF ${linker_script_gen}.dep -MT ${base_name}/${linker_script_gen}
446-
${current_includes}
447-
${current_defines}
448-
${linker_pass_define}
449-
-E ${LINKER_SCRIPT}
450-
-P # Prevent generation of debug `#line' directives.
451-
-o ${linker_script_gen}
452-
VERBATIM
453-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
454-
)
455-
endmacro()
456-
457411
# Error-out when the deprecated naming convention is found (until
458412
# after 1.14.0 has been released)
459413
foreach(path

cmake/linker/ld/target.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,55 @@ find_program(CMAKE_LINKER ${CROSS_COMPILE}ld PATH ${TOOLCHAIN_HOME} NO_
44

55
set_ifndef(LINKERFLAGPREFIX -Wl)
66

7+
8+
# Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}
9+
# NOTE: ${linker_script_gen} will be produced at build-time; not at configure-time
10+
macro(configure_linker_script linker_script_gen linker_pass_define)
11+
set(extra_dependencies ${ARGN})
12+
13+
# Different generators deal with depfiles differently.
14+
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
15+
# Note that the IMPLICIT_DEPENDS option is currently supported only
16+
# for Makefile generators and will be ignored by other generators.
17+
set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
18+
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
19+
# Using DEPFILE with other generators than Ninja is an error.
20+
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_script_gen}.dep)
21+
else()
22+
# TODO: How would the linker script dependencies work for non-linker
23+
# script generators.
24+
message(STATUS "Warning; this generator is not well supported. The
25+
Linker script may not be regenerated when it should.")
26+
set(linker_script_dep "")
27+
endif()
28+
29+
zephyr_get_include_directories_for_lang(C current_includes)
30+
get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME)
31+
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
32+
33+
add_custom_command(
34+
OUTPUT ${linker_script_gen}
35+
DEPENDS
36+
${LINKER_SCRIPT}
37+
${extra_dependencies}
38+
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
39+
${linker_script_dep}
40+
COMMAND ${CMAKE_C_COMPILER}
41+
-x assembler-with-cpp
42+
${NOSYSDEF_CFLAG}
43+
-MD -MF ${linker_script_gen}.dep -MT ${base_name}/${linker_script_gen}
44+
${current_includes}
45+
${current_defines}
46+
${linker_pass_define}
47+
-E ${LINKER_SCRIPT}
48+
-P # Prevent generation of debug `#line' directives.
49+
-o ${linker_script_gen}
50+
VERBATIM
51+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
52+
)
53+
endmacro()
54+
55+
756
# Load toolchain_ld-family macros
857
include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_base.cmake)
958
include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_baremetal.cmake)

0 commit comments

Comments
 (0)