Custom implementation for a source file in the NRF connect SDK/ Zephyr

Hi,

I need to make a few changes in the nRF Connect SDK's (particularly Zephyr's) source files to achieve certain functionality. I have made these changes in the SDK folder itself and tested the implementation and it works fine for us.

I now want a way by which I would be able to tell the CMAKE build system to ignore a particular source file in the SDK and use my custom source file instead, which I have placed in my project folder. I want to do this so that I don't have to provide a patch to all the developers in my team and I want to easily upgrade SDK as and when they are available. Our project is based on the matter-lock example provided by Nordic - NCS v2.1.0.

Path of the source file - C:\ncs\v2.1.0\zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt\src\zephyr_img_mgmt.c

Things that I have tried:

I have tried to make changes in the CMakeLists.txt located in my project to be able to do this. I added the following lines:

    get_filename_component(ZEPHYR_IMG_MGMT $ENV{ZEPHYR_BASE}/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c ABSOLUTE)
    list(REMOVE_ITEM SOURCES "${ZEPHYR_IMG_MGMT}")
    #list(REMOVE_ITEM lib_srcs "${ZEPHYR_IMG_MGMT}")
    
I have also added following line to add the source file located in my project folder:
     target_sources(app PRIVATE src/zephyr_img_mgmt.c)
 
But this gives me errors as it finds multiple definitions from both my project's source file and the SDK's source file. It isn't excluding the SDK's source file. Please help me with this.
If I comment the src/zephyr_img_mgmt.c in the CMakeLists.txt located at C:\ncs\v2.1.0\zephyr\subsys\mgmt\mcumgr\lib\cmd\img_mgmt the build system does not include the source file from the SDK and builds/works properly with the source file located in my project folder.
Screen-shot of how I have commented the source file in CMakeLists.txt:
But this change is again done in the SDK, and I don't want that.
Is there a way in which I can make the build system ignore this source file from SDK and instead use my own custom implementation? 
Parents Reply Children
No Data
Related