Components folder with multiple subfolders

mbastida
Posts: 7
Joined: Wed Jul 06, 2022 6:55 am

Components folder with multiple subfolders

Postby mbastida » Wed Sep 28, 2022 5:47 am

Hi, I would need to better structure my code by creating subfolders in the components folder. But no matter what I try I always get errors.

So far I have this structure working and compiling ocrrectly:
components
-component1
--component1.cpp
--component1.h
-component2
--component2.cpp
--component2.h

But now I would like to have something like this:
components
-lowlevel
--component1
---component1.cpp
---component1.h
--component2
---component2.cpp
---component2.h
-component3
--component3.cpp
--component3.h

I have trying changing the cmakelist.txt from:

Code: Select all

set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../components")
to:

Code: Select all

list(APPEND EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../components/lowlevel" "${CMAKE_CURRENT_SOURCE_DIR}/../../../components")
But the compiler doesn't find component1.cpp which is in the lowlevel folder inside components

Any idea? :D

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: Components folder with multiple subfolders

Postby gtjoseph » Wed Sep 28, 2022 2:38 pm

I just tried it and it works for me. You do only need the one "set" and it has to be after the cmake_minimum_required and before the include statement.

Code: Select all

cmake_minimum_required(VERSION 3.16)
set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../components/lowlevel" "${CMAKE_CURRENT_SOURCE_DIR}/../../../components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
What version of ESP-IDF are you using?

Who is online

Users browsing this forum: No registered users and 36 guests