Compile part of a matter application as static library

This question is analog to  Compile part of application as static library but related to a Matter application. In this case, I'd like to separate the compilation of all Matter/CHIP related application parts from my own application code, e.g., to use strict compiler flags for my own code which fail for the Matter/CHIP application parts.

My CMakeLists.txt looks as follows:

The last part is the relevant bit: chip_configure_data_model adds files from the Matter/CHIP repository to the given target, in this case still "app". What I'd like to do is the following (only repeating the relevant bits):

CMake detects the files and adds them to the library "app-chip", but it doesn't find the include paths for the Zephyr module Matter/CHIP. I can resolve it by copying the corresponding part from the "kernel.cmake", but I was wondering if there's a cleaner way to provide the required paths for a module to an application library:

This isn't very clean since it breaks immediately if "kernel.cmake" or some module setup in Zephyr breaks. Is there something like "target_link_libraries(app-chip PUBLIC zephyr_interface)" for Zephyr modules?

  • After stumbling through include and linking order problems, this is what I've come up with.

    Sadly, this doesn't help my use case since compiler errors are propagated through includes. And since C++ uses header files for implementation, and since I'm still using Matter/CHIP includes in my sources the compiler screams at me for stuff that I'm not responsible for (shadowed variables, unused parameters, etc.).

    The cleanest solution would of course still be to separate the Matter/CHIP parts into a module or somehow else _completely_ decouple Matter/CHIP from other more strict implementation parts.

  • Hi, 

    Do you fix the issue?

    -Amanda H.

  • Works for my current use-case, yes.