Use CMakeLists file to check the nRF Connect SDK version

Hello,

With the CMakeLists file, is it possible to make an error during compilation if the SDK version is not the correct one?

Example:
I am developing an application which is based on the nRF Connect SDK V2.5.0 and I am pushing my project on Github.
If one of my colleagues retrieves my project but the SDK version he has installed on his PC is v2.3.0, how could I use the CMakeLists.txt file of my application to generate an error during compilation for force it to update the version of its SDK?

Thank you

Parents
  • Hi,

    I recommend creating your application as a workspace application instead of freestanding. With workspace applications, the application has a west manifest file that specifies the nRF Connect SDK version. With this, your colleagues can check which SDK version you are using in the west.yml file, and they can run a west update to get the correct version.

    I recommend looking at the guide for creating a workspace application in Creating an nRF Connect SDK application. The nRF Connect for VS Code extension sets everything up for you if you follow the steps there.

    But to answer your question, you can set a required nRF Connect SDK version and check the version in the nrf/VERSION file by adding the following to the application's CMakeLists.txt:

    set(REQUIRED_NRF_VERSION "2.6.1")
    
    set(NRF_VERSION_FILE "$ENV{ZEPHYR_BASE}/../nrf/VERSION")
    file(STRINGS "${NRF_VERSION_FILE}" NRF_VERSION LIMIT_COUNT 1)
    
    if(NOT NRF_VERSION STREQUAL REQUIRED_NRF_VERSION)
        message(FATAL_ERROR "Incorrect nRF Connect SDK version! Expected version ${REQUIRED_NRF_VERSION}, but found version ${NRF_VERSION}. Stopping the build process.")
    endif()

    Simply change REQUIRED_NRF_VERSION to the version you want to use. It will give a CMake error and stop the build if the incorrect version is used:

    Best regards,
    Marte

Reply
  • Hi,

    I recommend creating your application as a workspace application instead of freestanding. With workspace applications, the application has a west manifest file that specifies the nRF Connect SDK version. With this, your colleagues can check which SDK version you are using in the west.yml file, and they can run a west update to get the correct version.

    I recommend looking at the guide for creating a workspace application in Creating an nRF Connect SDK application. The nRF Connect for VS Code extension sets everything up for you if you follow the steps there.

    But to answer your question, you can set a required nRF Connect SDK version and check the version in the nrf/VERSION file by adding the following to the application's CMakeLists.txt:

    set(REQUIRED_NRF_VERSION "2.6.1")
    
    set(NRF_VERSION_FILE "$ENV{ZEPHYR_BASE}/../nrf/VERSION")
    file(STRINGS "${NRF_VERSION_FILE}" NRF_VERSION LIMIT_COUNT 1)
    
    if(NOT NRF_VERSION STREQUAL REQUIRED_NRF_VERSION)
        message(FATAL_ERROR "Incorrect nRF Connect SDK version! Expected version ${REQUIRED_NRF_VERSION}, but found version ${NRF_VERSION}. Stopping the build process.")
    endif()

    Simply change REQUIRED_NRF_VERSION to the version you want to use. It will give a CMake error and stop the build if the incorrect version is used:

    Best regards,
    Marte

Children
No Data
Related