Skip to content

Commit

Permalink
cmake: move specs compiler and linker flags to toolchain properties
Browse files Browse the repository at this point in the history
Moving specs argument to compiler and linker properties so that the
compiler and linker in use can decide how the flags are mapped / handled
for the compiler and linker in use.

This avoids specifying `--specs=spec.picolibc` for clang which prints a
warning about an unused argument.

Signed-off-by: Torsten Rasmussen <[email protected]>
  • Loading branch information
tejlmand authored and fabiobaltieri committed Oct 4, 2024
1 parent 102b3fc commit 9d835fe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmake/compiler/clang/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,5 @@ set_compiler_property(PROPERTY warning_error_coding_guideline
)

set_compiler_property(PROPERTY no_global_merge "-mno-global-merge")

set_compiler_property(PROPERTY specs)
4 changes: 4 additions & 0 deletions cmake/compiler/compiler_flags_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ set_compiler_property(PROPERTY warning_shadow_variables)
# Compiler flags to avoid recognizing built-in functions
set_compiler_property(PROPERTY no_builtin)
set_compiler_property(PROPERTY no_builtin_malloc)

# Compiler flag for defining specs. Used only by gcc, other compilers may keep
# this undefined.
set_compiler_property(PROPERTY specs)
2 changes: 2 additions & 0 deletions cmake/compiler/gcc/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,5 @@ set_compiler_property(PROPERTY warning_shadow_variables -Wshadow)

set_compiler_property(PROPERTY no_builtin -fno-builtin)
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)

set_compiler_property(PROPERTY specs -specs=)
2 changes: 2 additions & 0 deletions cmake/linker/ld/gcc/linker_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ add_link_options(-gdwarf-4)

# Extra warnings options for twister run
set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings)

set_linker_property(PROPERTY specs -specs=)
4 changes: 4 additions & 0 deletions cmake/linker/linker_flags_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ set_property(TARGET linker PROPERTY no_relax)

# Linker flag for enabling relaxation of address optimization for jump calls.
set_property(TARGET linker PROPERTY relax)

# Linker flag for defining specs. Defined only by gcc, when gcc is used as
# front-end for ld.
set_compiler_property(PROPERTY specs)
5 changes: 2 additions & 3 deletions lib/libc/picolibc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ if(NOT CONFIG_PICOLIBC_USE_MODULE)
# Use picolibc provided with the toolchain. This requires a new enough
# toolchain so that the version of picolibc supports auto-detecting a
# Zephyr build (via the __ZEPHYR__ macro) to expose the Zephyr C API

zephyr_compile_options(--specs=picolibc.specs)
zephyr_libc_link_libraries(--specs=picolibc.specs)
zephyr_compile_options(PROPERTY specs picolibc.specs)
zephyr_link_libraries(PROPERTY specs picolibc.specs)
if(CONFIG_PICOLIBC_IO_FLOAT)
zephyr_compile_definitions(PICOLIBC_DOUBLE_PRINTF_SCANF)
zephyr_link_libraries(-DPICOLIBC_DOUBLE_PRINTF_SCANF)
Expand Down

0 comments on commit 9d835fe

Please sign in to comment.