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.

(cherry picked from commit 4ddd3eb)

Original-Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
GitOrigin-RevId: 4ddd3eb
Change-Id: Ibaa6e632c08b711d28a428c51fe6560b8885cf36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5752461
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
jonathonpenix authored and Chromeos LUCI committed Jul 31, 2024
1 parent 5366f4f commit 615e83a
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 615e83a

Please sign in to comment.