Skip to content

Commit

Permalink
samples: external_lib: Include --target in exported build flags
Browse files Browse the repository at this point in the history
Appropriately setting the `--target` flag is necessary when using clang
and building for a target other than the default. Zephyr generally
accomplishes this by setting the CMAKE_<LANG>_COMPILER_TARGET variables and
allowing cmake to automatically provide the `--target` flag when building.

For the external_lib sample, however, cmake can't add the flag and it was
not otherwise exported. As such, clang typically threw errors when building
this sample for any non-default targets due to mismatches between
target-specific flags and the default target.

To fix this, ensure we select the correct target by checking if
CMAKE_C_COMPILER_TARGET has been defined and adding
`--target=<triple>` to the list of flags that are exported if so.

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
  • Loading branch information
jonathonpenix authored and carlescufi committed Jul 31, 2024
1 parent 6c7d836 commit 4ddd3eb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion samples/application_development/external_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
zephyr_get_compile_options_for_lang_as_string( C options)

if(DEFINED CMAKE_C_COMPILER_TARGET)
set(target_flag "--target=${CMAKE_C_COMPILER_TARGET}")
endif()

set(external_project_cflags
"${includes} ${definitions} ${options} ${system_includes}"
"${target_flag} ${includes} ${definitions} ${options} ${system_includes}"
)

include(ExternalProject)
Expand Down

0 comments on commit 4ddd3eb

Please sign in to comment.