2

Context:

I am trying to add an external library which uses CMake to my Zephyr project. I have explored the modules documentation, but this does not seem a good fit as I am unable to modify the upstream library and would like to avoid forking.

To add the library, I am using FetchContent in my Cmake file. This is working successfully and I am able to download and build the files.

Problem: When linking, I encounter a "Conflicting CPU architectures" error. After inspecting into compile_commands.json, I can see the libraries source code is not receiving the same CMAKE_ARGS as the other files, leading to the architecture mismatch.

I am looking for the suggested way of adding external libraries to a zephyr project, without using the module system.

FetchContent_Declare(
        my-lib
        GIT_REPOSITORY git@github.com:<HostRepo>/<repoName>.git
        GIT_TAG v0.1.7
)

FetchContent_MakeAvailable(my-lib)

target_link_libraries(app PRIVATE my-lib)
Cole Murray
  • 546
  • 6
  • 12
  • There is no general answer. It strongly depends on what library you are adding. Or, depends on how do you can/want build the library that you are adding. – KamilCuk Jan 17 '22 at 21:55

1 Answers1

0

I recommend doing the repo fetching with a toplevel west.yml manifest and including your lib with add_library() or the appropriate cmake function.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Zoyolin
  • 25
  • 5