Page 1 of 1

CMake in esp-idf

Posted: Mon Oct 28, 2024 10:12 am
by aygh4266
hello everyone,

I am currently working on structuring my project using CMake into multiple layers, such as “Drivers” and “Abstraction.”

Each layer must have its own subdirectory and associated CMakeLists.txt file. However, I am facing some challenges in properly configuring CMake to recognize and build each subdirectory, as well as linking dependencies between the layers.

How can I register the subdirectories in ESP-IDF using CMake ? because I have used the standard CMake Commands and they haven't been recognized.

Any help will be appreciated
  1. [
  2. project-root/
  3.         - CMakeLists.txt
  4.         - Drivers/
  5.               - diver_1
  6.                      driver_1.c
  7.                      driver_1.h
  8.                      CMakelists.txt
  9.               - driver_2
  10.                      driver_2.c
  11.                      driver_2.h
  12.                      CMakelists.txt
  13.               - CMakeLists.txt
  14.        - Abstraction/
  15.               - CMakeLists.txt]

Re: CMake in esp-idf

Posted: Mon Oct 28, 2024 10:53 am
by ok-home

Re: CMake in esp-idf

Posted: Tue Oct 29, 2024 10:29 am
by aygh4266
ok-home wrote:
Mon Oct 28, 2024 10:53 am
The best way
https://docs.espressif.com/projects/esp ... ystem.html
I have an issue with the subdirectory. I need to structure the project into subdirectories, which are not components. In each subdirectory there is components I have registered successfully. The problem is CMake doesn't recognize the components because they are located in the subdirectory and not directly under components.

Is there any CMakelists.txt file to be added in the subdirectory ?

For example

Code: Select all

components
       -drivers (subdirectory)
              -component1
                   -CMakelists.txt
                    -component1.c
                     -include 
                         -component1.h

Re: CMake in esp-idf

Posted: Tue Oct 29, 2024 10:56 am
by aygh4266
aygh4266 wrote:
Tue Oct 29, 2024 10:29 am
ok-home wrote:
Mon Oct 28, 2024 10:53 am
The best way
https://docs.espressif.com/projects/esp ... ystem.html
I have an issue with the subdirectory. I need to structure the project into subdirectories, which are not components. In each subdirectory there is components I have registered successfully. The problem is CMake doesn't recognize the components because they are located in the subdirectory and not directly under components.

Is there any CMakelists.txt file to be added in the subdirectory ?

For example

Code: Select all

components
       -drivers (subdirectory)
              -component1
                   -CMakelists.txt
                    -component1.c
                     -include 
                         -component1.h
Issue has been solved.

EXTRA_COMPONENT_DIRS can be set in the top-level CMakeLists.txt to look for components in other places.

Code: Select all

cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(EXTRA_COMPONENT_DIRS 
    ${CMAKE_SOURCE_DIR}/components/drivers/component1
)
project(app-template)