Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: zephyr_library_amend feature #19980

Merged

Conversation

tejlmand
Copy link
Collaborator

@tejlmand tejlmand commented Oct 21, 2019

Summary

With module support in Zephyr: https://docs.zephyrproject.org/latest/guides/modules.html?highlight=modules#modules-external-projects

more code will be located out of tree.
This means that in some cases, Kconfig settings may be set to yes and thus create a zephyr_library, but no file is place in the lib.

As example, high level settings for a driver might result in a zephyr_library is selected for creation, but the code for the specific driver is located out-of-tree.

This can result in an empty CMake library with the following error:

CMake Error at /projects/github/ncs/zephyr/cmake/extensions.cmake:411 (add_library):                       
  No SOURCES given to target: drivers__entropy
Call Stack (most recent call first):
  /projects/github/ncs/zephyr/cmake/extensions.cmake:388 (zephyr_library_named)
  /projects/github/ncs/zephyr/drivers/entropy/CMakeLists.txt:3 (zephyr_library)

This commit introduces the cmake extension zephyr_library_amend which offers
a generic way to add files from out-of-tree into a Zephyr library and still use the existing zephyr cmake extension functions.

This function allows for adding files in an out-of-tree Zephyr module
to a zephyr library created in zephyr repo CMake files.

As example:
drivers/entropy/CMakeLists.txt creates an zephyr library as:

zephyr_library()

only available to zephyr itself.

The amend function allows to amend to such a lib, by creating a
CMakeLists.txt file following identical folder structure in a Zephyr
Module: <zephyr_module_oot>/drivers/entropy/CMakeLists.txt

zephyr_library_amend()
zephyr_library_sources_if_kconfig(entropy_oot_driver.c) # Sources are amended to the original library

Requirement when using zephyr_library_amend.

  1. If original zephyr CMakeList.txt is located in:
    ${ZEPHYR_BASE}/drivers/entropy
    then the amending CMakeLists.txt must be located in
    <ZEPHYR_MODULE_DIR>/drivers/entropy

This PR is related to: #14527

Signed-off-by: Torsten Rasmussen Torsten.Rasmussen@nordicsemi.no

This commit introduces the cmake extension zephyr_library_amend.

This function allows for adding files in an out-of-tree Zephyr module
to a zephyr library created in zephyr repo CMake files.

As example:
drivers/entropy/CMakeLists.txt creates an zephyr library as:
zephyr_library()
only available to zephyr itself.

The amend function allows to amend to such a lib, by creating a
CMakeLists.txt file following identical folder structure in a Zephyr
Module:
<zephyr_module_oot>/drivers/entropy/CMakeLists.txt
zephyr_library_amend()
zephyr_library_sources() # Sources are amended to the original library

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Copy link
Collaborator

@thomasstenersen thomasstenersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment, otherwise it looks good to me 👍

cmake/extensions.cmake Show resolved Hide resolved
@carlescufi carlescufi merged commit f0fa7b8 into zephyrproject-rtos:master Oct 21, 2019
@tejlmand tejlmand deleted the cmake_zephyr_library_amend branch December 9, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants