CMake in esp-idf

aygh4266
Posts: 24
Joined: Mon Mar 04, 2024 10:33 am

CMake in esp-idf

Postby aygh4266 » Mon Oct 28, 2024 10:12 am

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]
Last edited by aygh4266 on Mon Oct 28, 2024 11:19 am, edited 1 time in total.

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: CMake in esp-idf

Postby ok-home » Mon Oct 28, 2024 10:53 am


aygh4266
Posts: 24
Joined: Mon Mar 04, 2024 10:33 am

Re: CMake in esp-idf

Postby aygh4266 » 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

aygh4266
Posts: 24
Joined: Mon Mar 04, 2024 10:33 am

Re: CMake in esp-idf

Postby aygh4266 » Tue Oct 29, 2024 10:56 am

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)

Who is online

Users browsing this forum: Google [Bot], MicroController and 158 guests