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...
(resolved) simple cmake question (using subdirectories)
(resolved) simple cmake question (using subdirectories)
Last edited by mzimmers on Fri Sep 17, 2021 4:43 pm, edited 1 time in total.
Re: simple cmake question (using subdirectories)
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:
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
Re: simple cmake question (using subdirectories)
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:
What is "app_sources" and where is it defined?
Thank you.
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)
Thank you.
Re: simple cmake question (using subdirectories)
Look for SRC_DIRS and INCLUDE_DIRS in the linked Build System docs.
Re: simple cmake question (using subdirectories)
Hi boarchuz -
I just tried this:
And now I get a build error:
I tried it with and without the "./"...same results. Any idea what I'm doing wrong?
Thanks...
I just tried this:
Code: Select all
SRC_DIRS
"new_code"
"new_code/common"
INCLUDE_DIRS
"."
"./new_code"
"./new_code/common"
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()'
Thanks...
Re: simple cmake question (using subdirectories)
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
Try the suggestions in this section: https://docs.espressif.com/projects/esp ... tal-builds
Re: simple cmake question (using subdirectories)
Thanks, boarchuz. I think this line says it all:
Thanks for the help on this.
If that's how it should be done, then that's how I'll do it.This preference reflects the CMake best practice of manually listing source files.
Thanks for the help on this.
Who is online
Users browsing this forum: Baidu [Spider] and 272 guests