File tree 5 files changed +44
-30
lines changed
5 files changed +44
-30
lines changed Original file line number Diff line number Diff line change @@ -96,20 +96,19 @@ if(SYSROOT_DIR)
96
96
set (LIBC_LIBRARY_DIR "\" ${SYSROOT_DIR} \" /lib/${NEWLIB_DIR} " )
97
97
endif ()
98
98
99
- # This libgcc code is partially duplicated in compiler/*/target.cmake
100
- execute_process (
101
- COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
102
- OUTPUT_VARIABLE LIBGCC_FILE_NAME
103
- OUTPUT_STRIP_TRAILING_WHITESPACE
104
- )
105
-
106
- assert_exists(LIBGCC_FILE_NAME)
107
-
108
- get_filename_component (LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY )
109
-
110
- assert_exists(LIBGCC_DIR)
99
+ # Search for filename in default compiler library path
111
100
112
- set_linker_property(PROPERTY lib_include_dir "-L\" ${LIBGCC_DIR} \" " )
101
+ function (library_file_path filename i)
102
+ execute_process (
103
+ COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} ${OPTIMIZATION_FLAG} --print-file-name ${filename}
104
+ OUTPUT_VARIABLE filepath
105
+ OUTPUT_STRIP_TRAILING_WHITESPACE
106
+ )
107
+ if (${filepath} STREQUAL ${filename} )
108
+ set (filepath "" )
109
+ endif ()
110
+ set (${i} "${filepath} " PARENT_SCOPE)
111
+ endfunction ()
113
112
114
113
# For CMake to be able to test if a compiler flag is supported by the
115
114
# toolchain we need to give CMake the necessary flags to compile and
Original file line number Diff line number Diff line change @@ -45,18 +45,29 @@ else()
45
45
list (APPEND TOOLCHAIN_C_FLAGS "-m32" )
46
46
endif ()
47
47
48
+ # Search for filename in default compiler library path
49
+
50
+ function (library_file_path filename i)
51
+ execute_process (
52
+ COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} ${OPTIMIZATION_FLAG} --print-file-name ${filename}
53
+ OUTPUT_VARIABLE filepath
54
+ OUTPUT_STRIP_TRAILING_WHITESPACE
55
+ )
56
+ set (${i} ${filepath} PARENT_SCOPE)
57
+ endfunction ()
58
+
59
+ # Add -lgcc if available
48
60
49
61
# This libgcc code is partially duplicated in compiler/*/target.cmake
50
62
execute_process (
51
63
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
52
- OUTPUT_VARIABLE LIBGCC_FILE_NAME
64
+ OUTPUT_VARIABLE libgcc_file_name
53
65
OUTPUT_STRIP_TRAILING_WHITESPACE
54
66
)
55
67
56
- get_filename_component (LIBGCC_DIR ${LIBGCC_FILE_NAME } DIRECTORY )
68
+ get_filename_component (libgcc_dir ${libgcc_file_name } DIRECTORY )
57
69
58
- list (APPEND LIB_INCLUDE_DIR "-L\" ${LIBGCC_DIR} \" " )
59
- if (LIBGCC_DIR)
70
+ if (libgcc_dir)
60
71
list (APPEND TOOLCHAIN_LIBS gcc)
61
72
endif ()
62
73
Original file line number Diff line number Diff line change @@ -40,16 +40,16 @@ foreach(file_name include/stddef.h include-fixed/limits.h)
40
40
list (APPEND NOSTDINC ${_OUTPUT} )
41
41
endforeach ()
42
42
43
- # This libgcc code is partially duplicated in compiler/*/target.cmake
44
- execute_process (
45
- COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
46
- OUTPUT_VARIABLE LIBGCC_FILE_NAME
47
- OUTPUT_STRIP_TRAILING_WHITESPACE
48
- )
43
+ # Search for filename in default compiler library path
49
44
50
- get_filename_component (LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY )
51
-
52
- list (APPEND LIB_INCLUDE_DIR "-L\" ${LIBGCC_DIR} \" " )
45
+ function (library_file_path filename i)
46
+ execute_process (
47
+ COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} ${OPTIMIZATION_FLAG} --print-file-name ${filename}
48
+ OUTPUT_VARIABLE filepath
49
+ OUTPUT_STRIP_TRAILING_WHITESPACE
50
+ )
51
+ set (${i} ${filepath} PARENT_SCOPE)
52
+ endfunction ()
53
53
54
54
# For CMake to be able to test if a compiler flag is supported by the
55
55
# toolchain we need to give CMake the necessary flags to compile and
Original file line number Diff line number Diff line change @@ -164,10 +164,12 @@ macro(toolchain_linker_finalize)
164
164
165
165
set (cpp_link "${common_link} " )
166
166
if (NOT "${ZEPHYR_TOOLCHAIN_VARIANT} " STREQUAL "host" )
167
- if (CONFIG_CPP_EXCEPTIONS AND LIBGCC_DIR)
167
+ library_file_path(crtbegin.o CRTBEGIN_PATH)
168
+ library_file_path(crtend.o CRTEND_PATH)
169
+ if (CONFIG_CPP_EXCEPTIONS AND CRTBEGIN_PATH AND CRTEND_PATH)
168
170
# When building with C++ Exceptions, it is important that crtbegin and crtend
169
171
# are linked at specific locations.
170
- set (cpp_link "<LINK_FLAGS> ${LIBGCC_DIR} /crtbegin.o ${link_libraries} ${LIBGCC_DIR} /crtend.o " )
172
+ set (cpp_link "<LINK_FLAGS> ${CRTBEGIN_PATH} ${link_libraries} ${CRTEND_PATH} " )
171
173
endif ()
172
174
endif ()
173
175
set (CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> ${cpp_link} " )
Original file line number Diff line number Diff line change @@ -11,14 +11,16 @@ find_program(CMAKE_LINKER xt-ld ${LD_SEARCH_PATH})
11
11
12
12
set_ifndef(LINKERFLAGPREFIX -Wl)
13
13
14
- if (CONFIG_CPP_EXCEPTIONS)
14
+ library_file_path(crtbegin.o CRTBEGIN_PATH)
15
+ library_file_path(crtend.o CRTEND_PATH)
16
+ if (CONFIG_CPP_EXCEPTIONS AND CRTBEGIN_PATH AND CRTEND_PATH)
15
17
# When building with C++ Exceptions, it is important that crtbegin and crtend
16
18
# are linked at specific locations.
17
19
# The location is so important that we cannot let this be controlled by normal
18
20
# link libraries, instead we must control the link command specifically as
19
21
# part of toolchain.
20
22
set (CMAKE_CXX_LINK_EXECUTABLE
21
- "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> ${LIBGCC_DIR} /crtbegin.o <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${LIBGCC_DIR} /crtend.o " )
23
+ "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> ${CRTBEGIN_PATH} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${CRTEND_PATH} " )
22
24
endif ()
23
25
24
26
# Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}
You can’t perform that action at this time.
0 commit comments