Do I have to create or edit the CMakeLists.txt files after I tried to add new files and edit the project files?

Hi All,

Sorry to ask this question, I just learned a little about cmake. 

Now I wanted to add a few src files based on the light switch example in SES.  Do I have to create or edit the CMakeLists.txt files for my new added files? 

Currently I used the configuration of the light switch example (using gcc), and didn't change anything for the cmakelists.txt files. I builded the project successfully.

Is it right?  I wanna know how to create or edit the cmakelists.txt files for my project or Is there a nother way to build the project?  Any suggestions will be helpful.

Thanks in advance.

Parents
  • Hi,

    You can add custom src files to your CMakeLists.txt if it already exists. Below is an illustration of how the CMakeLists.txt of the Hello_world sample has been modified to also include a custom file. Remember to change "src/my_custom_code_files.c" to the destination and name of the code you want to add.

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    
    target_sources(app PRIVATE
        src/main.c
        src/my_custom_files
        )
    

    If you dont have a CMakeList, you need to create one. Take a look at an existing sample to see how it is set up!

    Let me know if this clarifies things for you,


    Kind regards,
    Andreas

  • Hi AHaug,

    Thanks for you patience for my question.

    I am still confused that I didn't add all the new files in the exsiting cmakelists.txt in the light_switch example (all new files have been added in the segger project), but when I click Build->Build light_switch_xxx, building was successfullly and it seemed that it worked well, so  I don't know why it can work well. 

    How does the SES use the cmakelists.txt while building the project like I did?  I tried to understand the material "Building with SEGGER Embedded Studio""from the infocenter.  Maybe I misunderstood something?

  • Hi,

    CMakeLists.txt is used by CMake to generete the build files for a specific environment such as your project or application. SEGGER Embedded Studio as well as nRF Connect Extension for Visual Studio Code are both using nRF Connect SDK (NCS) and CMake works the same way.

    From topic 3 in our nRF Connect SDK fundamentals course on our academy pages you can see that 

    "CMake

    In the nRF Connect SDK, all applications are CMake projects. This means that the application controls the configuration and build process of itself, Zephyr and all sourced libraries. The file CMakeLists.txt is the main CMake project file and the source of this build process configuration."

    Let me know if this clarifies things for you,

    Kind regards,
    Andreas

  • Hi AHaug,

    Thank you very much. 

    I really lack knowledge of cmake. I followed the instruction of this page Nordic Semiconductor Infocenter.  Entered the build folder and issue cmake like this below, and got the following errors. I have installed all the required softwares and added them to the path. I used the nrf5 sdk for mesh 5.0.  I didn't change anything for the test. 

    ...\mesh sdk\nrf5_SDK_for_Mesh_v5.0.0_src\examples\light_switch\server\build>cmake -G Ninja -DGENERATE_SES_PROJECTS=ON -DPLATFORM=nrf52832_xxAA -DSOFTDEVICE=s132_7.2.0 ..
    CMake Warning (dev) in CMakeLists.txt:
    No project() command is present. The top-level CMakeLists.txt file must
    contain a literal, direct call to the project() command. Add a line of
    code such as

    project(ProjectName)

    near the top of the file, but after cmake_minimum_required().

    CMake is pretending there is a "project(Project)" command on the first
    line.
    This warning is for project developers. Use -Wno-dev to suppress it.

    -- The C compiler identification is GNU 8.1.0
    -- The CXX compiler identification is GNU 8.1.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: C:/mingw-w64/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: C:/mingw-w64/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/c++.exe - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    CMake Error at CMakeLists.txt:54 (set_target_link_options):
    Unknown CMake command "set_target_link_options".


    CMake Warning (dev) in CMakeLists.txt:
    No cmake_minimum_required command is present. A line of code such as

    cmake_minimum_required(VERSION 3.23)

    should be added at the top of the file. The version specified may be lower
    if you wish to support older CMake versions for this project. For more
    information run "cmake --help-policy CMP0000".
    This warning is for project developers. Use -Wno-dev to suppress it.

    -- Configuring incomplete, errors occurred!
    See also "...../mesh sdk/nrf5_SDK_for_Mesh_v5.0.0_src/examples/light_switch/server/build/CMakeFiles/CMakeOutput.log".

    I used the build->build light_switch_... and could get the .hex file and .elf file successfully. Have I missed something or misunderstood something?  Of course I can use the successfully method to build and get the .hex, but I still want to get the root cause for this problem.

  • followed this page "Building the stack and examples" from the infocenter.

  • Hi, 

    Young said:
    ...\mesh sdk\nrf5_SDK_for_Mesh_v5.0.0_src

    My bad, I did not see that you were working with nRF5 SDK for Mesh v5.0.0.  The tutorial I sent in my previous reply is for nRF Connect SDK which is not the same as nRF5 SDK. 

    Now I wanted to add a few src files based on the light switch example in SES.  Do I have to create or edit the CMakeLists.txt files for my new added files? 

    According to my colleague you can edit and change projects without editing cmakelist, as they are not used for older nRF5 SDK projects. Instead you can build together in SES. As for nRF5 SDK for Mesh v5 you can do either, meaning that both building the projects with SES and you can use CMake. Using CMake requires that you have set up the environment properly and if done so it should work similarly as in NCS with regard to configuring the cmakelist

    From your error you have:

    Young said:
    No cmake_minimum_required command is present. A line of code such as

    This means that you need to add a line that states a minimum version that cmake is going to look for/use. You can fix this by adding cmake_minimum_required(VERSION x.x) at the top of the top-level cmakelists.txt in your project application (remember to replace x.x with a version that you are using. 

    I will take a closer look on how the switch sample in mesh is set up, but in the meanwhile you can try the suggestions above,

    Kind regards,
    Andreas

Reply
  • Hi, 

    Young said:
    ...\mesh sdk\nrf5_SDK_for_Mesh_v5.0.0_src

    My bad, I did not see that you were working with nRF5 SDK for Mesh v5.0.0.  The tutorial I sent in my previous reply is for nRF Connect SDK which is not the same as nRF5 SDK. 

    Now I wanted to add a few src files based on the light switch example in SES.  Do I have to create or edit the CMakeLists.txt files for my new added files? 

    According to my colleague you can edit and change projects without editing cmakelist, as they are not used for older nRF5 SDK projects. Instead you can build together in SES. As for nRF5 SDK for Mesh v5 you can do either, meaning that both building the projects with SES and you can use CMake. Using CMake requires that you have set up the environment properly and if done so it should work similarly as in NCS with regard to configuring the cmakelist

    From your error you have:

    Young said:
    No cmake_minimum_required command is present. A line of code such as

    This means that you need to add a line that states a minimum version that cmake is going to look for/use. You can fix this by adding cmake_minimum_required(VERSION x.x) at the top of the top-level cmakelists.txt in your project application (remember to replace x.x with a version that you are using. 

    I will take a closer look on how the switch sample in mesh is set up, but in the meanwhile you can try the suggestions above,

    Kind regards,
    Andreas

Children
No Data
Related