tools: Improve chip target detection

This commit is contained in:
simon.chupin
2021-10-27 18:14:59 +02:00
parent e6db26cc40
commit bca79c75d5
2 changed files with 12 additions and 2 deletions

View File

@@ -444,7 +444,11 @@ macro(project project_name)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map")
target_link_libraries(${project_elf} "-Wl,--cref" "-Wl,--Map=\"${mapfile}\"") set(idf_target "${IDF_TARGET}")
string(TOUPPER ${idf_target} idf_target)
target_link_libraries(${project_elf} "-Wl,--cref" "-Wl,--defsym=IDF_TARGET_${idf_target}=0"
"-Wl,--Map=\"${mapfile}\"")
unset(idf_target)
endif() endif()
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY

View File

@@ -263,12 +263,18 @@ def detect_target_chip(map_file: Iterable) -> str:
''' Detect target chip based on the target archive name in the linker script part of the MAP file ''' ''' Detect target chip based on the target archive name in the linker script part of the MAP file '''
scan_to_header(map_file, 'Linker script and memory map') scan_to_header(map_file, 'Linker script and memory map')
RE_TARGET = re.compile(r'project_elf_src_(.*)\.c.obj') RE_TARGET = re.compile(r'IDF_TARGET_(\S*) =')
# For back-compatible with cmake in idf version before 5.0
RE_TARGET_CMAKEv4x = re.compile(r'project_elf_src_(\S*)\.c.obj')
# For back-compatible with make # For back-compatible with make
RE_TARGET_MAKE = re.compile(r'^LOAD .*?/xtensa-([^-]+)-elf/') RE_TARGET_MAKE = re.compile(r'^LOAD .*?/xtensa-([^-]+)-elf/')
for line in map_file: for line in map_file:
match_target = RE_TARGET.search(line) match_target = RE_TARGET.search(line)
if match_target:
return match_target.group(1).lower()
match_target = RE_TARGET_CMAKEv4x.search(line)
if match_target: if match_target:
return match_target.group(1) return match_target.group(1)