(resolved) simple cmake question (using subdirectories)

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(resolved) simple cmake question (using subdirectories)

Postby mzimmers » Wed Sep 15, 2021 5:16 pm

Hi all -

I'm in the process of porting an application to the ESP32. For convenience, I'd like to add a subdirectory to the main directory, to contain a bunch of code I'm using from an older project. But my build is failing at the configuration step.

I don't want to create a new component; I just want to use selected files from my "new_code" subdirectory. Can someone tell me the correct method for this? I tried adding a "add_subdirectory" command to my main CMakeLists.txt file, but that didn't work.

Thanks...
Last edited by mzimmers on Fri Sep 17, 2021 4:43 pm, edited 1 time in total.

User avatar
fasani
Posts: 195
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: simple cmake question (using subdirectories)

Postby fasani » Fri Sep 17, 2021 12:39 pm

Maybe it will be the best that you upload this code in Github if you don't mind sharing.
Because like this is hard to understand what you are trying to do and how is your local setup.

But from the top of my head it will be possible to do this with CMake. Anyways if you add it "as a component" it will also work.
As a reference here is the main directory of one of my IDF repositories.
Make sure to give a detailed read to the "Build system" since there this kind of details are well explained. At least I find always refreshing to give this a second read.

From the Build system page:
Optional “components” directory contains components that are part of the project. A project does not have to contain custom components of this kind, but it can be useful for structuring reusable code or including third party components that aren’t part of ESP-IDF. Alternatively, EXTRA_COMPONENT_DIRS can be set in the top-level CMakeLists.txt to look for components in other places. If you have a lot of source files in your project, we recommend grouping most into components instead of putting them all in “main”.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: simple cmake question (using subdirectories)

Postby mzimmers » Fri Sep 17, 2021 2:28 pm

Hi fasani -

Thanks for the reply. I looked at your github pages, and they were helpful. My situation is similar, except I want my main CMakeLists.txt file to pick up many of the files in a subdirectory, not just one (as in your demo/). Is there some way to form a configuration file to tell cmake "just take these listed files?"

Also, I saw in another of your files this line:

Code: Select all

idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "include" REQUIRES esp_adc_cal)
What is "app_sources" and where is it defined?

Thank you.

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: simple cmake question (using subdirectories)

Postby boarchuz » Fri Sep 17, 2021 3:35 pm

Look for SRC_DIRS and INCLUDE_DIRS in the linked Build System docs.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: simple cmake question (using subdirectories)

Postby mzimmers » Fri Sep 17, 2021 3:51 pm

Hi boarchuz -

I just tried this:

Code: Select all

SRC_DIRS
"new_code"
"new_code/common"

INCLUDE_DIRS 
"."
"./new_code"
"./new_code/common"
And now I get a build error:

Code: Select all

/home/mzimmers/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/mzimmers/cpfluidra/fw/build/../main/main.cpp:61: undefined reference to `Wifi::Wifi()'
I tried it with and without the "./"...same results. Any idea what I'm doing wrong?

Thanks...

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: simple cmake question (using subdirectories)

Postby boarchuz » Fri Sep 17, 2021 4:32 pm

There could be a lot of reasons for that, we don't have enough info.

Try the suggestions in this section: https://docs.espressif.com/projects/esp ... tal-builds

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: simple cmake question (using subdirectories)

Postby mzimmers » Fri Sep 17, 2021 4:43 pm

Thanks, boarchuz. I think this line says it all:
This preference reflects the CMake best practice of manually listing source files.
If that's how it should be done, then that's how I'll do it.

Thanks for the help on this.

Who is online

Users browsing this forum: awegel, Bing [Bot] and 111 guests