Add open-source drivers/libraries to projects using CMake and ExternalProject_Add()

Hi

I have been studying the nRF Connect SDK and taking the courses at Nordic Dev Academy. In the Zephyr Fundamentals course, as I don't have the sensors used in lesson 6 about I2C, I decided to use the sensors I have with me: the BNO055 IMU sensor.

But I'm also trying to dig even deeper and explore CMake at the same time.

I solve the exercise using the Bosch BNO055 IMU sensor, but I believe this question applies to any type of open-source library that I want to integrate into my projects. First, I downloaded the bno055.c and bno055.h files from the Bosch BNO055 IMU sensor github repository, added the files to my project directory and in the main.c file I included the header file:

#include "bno055.h"

I then integrated the bno055 driver into my project using functions from the Zephyr I2C API such as i2c_write(), i2c_read(), and i2c_write_read(). I was able to build the project without any problems and flash my nRF52840DK.

However, I want to set up a build system using the CMakeLists.txt file to make sure I can download and integrate the sensor files at build time and thus ensure that the project is always tracking the sensor's github repository. This is important in situations where the library has a bug fix or some improvement and automatically the project is updated with the new improvements in the next build process.

So, for this I configured the following CMakeLists.txt file:

make_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(my_project)

# Add your application source files
target_sources(app PRIVATE src/main.c)

# Include ExternalProject module
include(ExternalProject)

# Set the directory where the external project will be downloaded and built
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)

# Define the ExternalProject for the external repository
ExternalProject_Add(
    BNO055_driver  
    PREFIX ${EXTERNAL_INSTALL_LOCATION}/BNO055_driver
    GIT_REPOSITORY "https://github.com/boschsensortec/BNO055_driver.git" 
    GIT_TAG master 
    UPDATE_COMMAND ""  # Skip update step
    CONFIGURE_COMMAND ""  # Skip configure step
    BUILD_COMMAND ""  # Skip build step
    INSTALL_COMMAND ""  # Skip install step
)

# Get the source directory of the external project
ExternalProject_Get_Property(BNO055_driver SOURCE_DIR)

# Include the directory containing the header file
include_directories(${SOURCE_DIR})

# Optionally, you can add a dependency on the external project to ensure it's built before your application
add_dependencies(app BNO055_driver)

When I build the project, the build system is able to download the files from the github repository to my laptop but then the build system stops and have the following error:

-- Configuring done (4.4s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build
-- west build: building application
[1/183] Preparing syscall dependency handling

[4/183] Generating include/generated/version.h
-- Zephyr version: 3.3.99 (/opt/nordic/ncs/v2.4.0/zephyr), build: v3.3.99-ncs1
[159/183] Performing download step (git clone) for 'BNO055_driver'
Cloning into 'BNO055_driver'...
Already on 'master'
Your branch is up to date with 'origin/master'.
[173/183] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr_pre0.map 
: && ccache /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -L/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  /opt/nordic/ncs/v2.4.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.17.a && cd /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -E echo
/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/src/main.c:35: undefined reference to `bno055_init'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /opt/homebrew/bin/cmake --build /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build

Bellow you can see the directory of main.c and the directory where the CMake download the bno055.c and bno55.h files:

fund_less6_exer1_exer2/fund_less6_exer2/build/external/BNO055_driver/src/BNO055_driver/bno055.h
fund_less6_exer1_exer2/fund_less6_exer2/build/external/BNO055_driver/src/BNO055_driver/bno055.c
fund_less6_exer1_exer2/fund_less6_exer2/src/main.c

Parents Reply Children
  • Hi


    Thanks for your response. Unfortunately, adding the instructions you suggested didn't solve the problem.


    zephyr_include_directories(${SOURCE_DIR})


    The error looks the same:

    -- west build: making build dir /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build pristine
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2
    -- CMake version: 3.26.3
    -- Using NCS Toolchain 2.4.0 for building. (/opt/nordic/ncs/toolchains/4ef6631da0/cmake)
    -- Found Python3: /opt/nordic/ncs/toolchains/4ef6631da0/bin/python3 (found suitable exact version "3.9.6") found components: Interpreter 
    -- Cache files will be written to: /Users/my_user/Library/Caches/zephyr
    -- Zephyr version: 3.3.99 (/opt/nordic/ncs/v2.4.0/zephyr)
    -- Found west (found suitable version "1.0.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.16.0 (/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.0 (/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk)
    -- Found Dtc: /opt/nordic/ncs/toolchains/4ef6631da0/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") 
    -- Found BOARD.dts: /opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/nrf52840dk_nrf52840.overlay
    -- Generated zephyr.dts: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/dts.cmake
    Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/prj.conf'
    Configuration saved to '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/.config'
    Kconfig header saved to '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at /opt/nordic/ncs/v2.4.0/zephyr/CMakeLists.txt:838 (message):
      No SOURCES given to Zephyr library: lib__libc__common
    
      Excluding target from build.
    
    
    -- Configuring done (5.0s)
    -- Generating done (0.1s)
    -- Build files have been written to: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build
    -- west build: building application
    [1/183] Preparing syscall dependency handling
    
    [4/183] Generating include/generated/version.h
    -- Zephyr version: 3.3.99 (/opt/nordic/ncs/v2.4.0/zephyr), build: v3.3.99-ncs1
    [63/183] Performing download step (git clone) for 'BNO055_driver'
    Cloning into 'BNO055_driver'...
    Already on 'master'
    Your branch is up to date with 'origin/master'.
    [173/183] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -L/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  /opt/nordic/ncs/v2.4.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.17.a && cd /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -E echo
    /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
    /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/src/main.c:35: undefined reference to `bno055_init'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/homebrew/bin/cmake --build /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build
    

  • You'll need to add the c-file manually as well. Try something like this:

    target_sources(app PRIVATE ${SOURCE_DIR}/bno055.c)

     

    Kind regards,

    Håkon

  • I just follow your suggestion and the error now is different:

    -- west build: making build dir /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build pristine
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2
    -- CMake version: 3.26.3
    -- Using NCS Toolchain 2.4.0 for building. (/opt/nordic/ncs/toolchains/4ef6631da0/cmake)
    -- Found Python3: /opt/nordic/ncs/toolchains/4ef6631da0/bin/python3 (found suitable exact version "3.9.6") found components: Interpreter 
    -- Cache files will be written to: /Users/my_user/Library/Caches/zephyr
    -- Zephyr version: 3.3.99 (/opt/nordic/ncs/v2.4.0/zephyr)
    -- Found west (found suitable version "1.0.0", minimum required is "0.7.1")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.16.0 (/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.0 (/opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk)
    -- Found Dtc: /opt/nordic/ncs/toolchains/4ef6631da0/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") 
    -- Found BOARD.dts: /opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/nrf52840dk_nrf52840.overlay
    -- Generated zephyr.dts: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/dts.cmake
    Parsing /opt/nordic/ncs/v2.4.0/zephyr/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.4.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/prj.conf'
    Configuration saved to '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/.config'
    Kconfig header saved to '/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at /opt/nordic/ncs/v2.4.0/zephyr/CMakeLists.txt:838 (message):
      No SOURCES given to Zephyr library: lib__libc__common
    
      Excluding target from build.
    
    
    -- Configuring done (5.0s)
    CMake Error at /opt/nordic/ncs/v2.4.0/zephyr/cmake/modules/extensions.cmake:424 (add_library):
      Cannot find source file:
    
        /Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build/external/BNO055_driver/src/BNO055_driver/bno055.c
    Call Stack (most recent call first):
      /opt/nordic/ncs/v2.4.0/zephyr/cmake/modules/kernel.cmake:210 (zephyr_library_named)
      /opt/nordic/ncs/v2.4.0/zephyr/cmake/modules/zephyr_default.cmake:124 (include)
      /opt/nordic/ncs/v2.4.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /opt/nordic/ncs/v2.4.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:2 (find_package)
    
    
    -- Generating done (0.1s)
    CMake Generate step failed.  Build files cannot be regenerated correctly.
    FATAL ERROR: command exited with status 1: /opt/homebrew/bin/cmake -DWEST_PYTHON=/opt/nordic/ncs/toolchains/4ef6631da0/opt/[email protected]/bin/python3.9 -B/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2/build -GNinja -DBOARD=nrf52840dk_nrf52840 -S/Users/my_user/Documents/Projects/nRFConnectSDK-ZephyrRTOS-Fundamentals/fund_less6_exer1_exer2/fund_less6_exer2

  • Hi,

     

    Where did you place the line in CMakeLists.txt?

    Can you share your full .txt file?

     

    Kind regards,

    Håkon

  • My CMakeLists.txt 

    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(i2c_exercise2)
    
    # Add your application source files
    target_sources(app PRIVATE src/main.c)
    
    # Include ExternalProject module
    include(ExternalProject)
    
    # Set the directory where the external project will be downloaded and built
    set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)
    
    # Define the ExternalProject for the external repository
    ExternalProject_Add(
        BNO055_driver  
        PREFIX ${EXTERNAL_INSTALL_LOCATION}/BNO055_driver
        GIT_REPOSITORY "https://github.com/boschsensortec/BNO055_driver.git"
        GIT_TAG "master" 
        UPDATE_COMMAND ""  # Skip update step
        CONFIGURE_COMMAND ""  # Skip configure step
        BUILD_COMMAND ""  # Skip build step
        INSTALL_COMMAND ""  # Skip install step
    )
    
    # Get the source directory of the external project
    ExternalProject_Get_Property(BNO055_driver SOURCE_DIR)
    
    # Include the directory containing the header file
    zephyr_include_directories(${SOURCE_DIR})
    # add the c-file
    target_sources(app PRIVATE ${SOURCE_DIR}/bno055.c)
    
    # Optionally, you can add a dependency on the external project to ensure it's built before your application
    add_dependencies(app BNO055_driver)
    

    I was reading about Zephyr Submodules here. Should BNO055_driver be a new Zephyr Submodule?

Related