cmake: don't pass --gc-sections to macOS linker, use -dead_strip

When building for "linux" (~POSIX) target on macOS, the system linker
is normally used. MacOS linker doesn't recognise --gc-sections, but
has a -dead_strip flag which is equivalent.
This commit is contained in:
Ivan Grokhotkov 2021-11-16 00:04:36 +01:00
parent fd1c213be4
commit 9901fc3058
2 changed files with 6 additions and 3 deletions

View File

@ -196,6 +196,12 @@ endif()
list(APPEND link_options "-fno-lto")
if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND link_options "-Wl,-dead_strip")
else()
list(APPEND link_options "-Wl,--gc-sections")
endif()
# Placing jump tables in flash would cause issues with code that required
# to be placed in IRAM
list(APPEND compile_options "-fno-jump-tables")

View File

@ -111,13 +111,10 @@ function(__build_set_default_build_specifications)
list(APPEND cxx_compile_options "-std=gnu++11")
list(APPEND link_options "-Wl,--gc-sections")
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
endfunction()
#