adding a file to an ESP-IDF project under VScode?

chriskuku
Posts: 9
Joined: Fri Mar 29, 2024 5:49 pm

adding a file to an ESP-IDF project under VScode?

Postby chriskuku » Mon Apr 08, 2024 12:41 pm

How do I add a source file to an existing project under Vscode/ESP-IDF?

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: adding a file to an ESP-IDF project under VScode?

Postby MicroController » Mon Apr 08, 2024 2:50 pm

Build System:
Add all source files (.c,.cpp) to the list of SRCS in idf_component_register(...) in the (main) component's CMakeLists.txt file.

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: adding a file to an ESP-IDF project under VScode?

Postby mbratch » Mon Apr 08, 2024 6:06 pm

It depends upon how your current `CMakeLists.txt` specifies the files.

For example, if it globs them like this:

Code: Select all

file(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/main/*.*)

idf_component_register(SRCS ${app_sources})
Then you just need to add the file to the `main` folder and you're good to go. Otherwise, if they source files are explicitly listed, or specified in some other way that would not capture your new file, you need to update the `idf_component_register` argument to capture it.

chriskuku
Posts: 9
Joined: Fri Mar 29, 2024 5:49 pm

Re: adding a file to an ESP-IDF project under VScode?

Postby chriskuku » Mon Apr 08, 2024 8:20 pm

MicroController wrote:
Mon Apr 08, 2024 2:50 pm
Build System:
Add all source files (.c,.cpp) to the list of SRCS in idf_component_register(...) in the (main) component's CMakeLists.txt file.
Actually, when I'm using command line tools, I wouldn't mind editing some CMakeLists.txt, but since I'm working under a GUI based tool (VSCode), I was more thinking of using a menu function "Add File to project" like one is doing in Visual Studio or other GUI based IDEs.

Putting everything in main/... is ok so far.

mtraven
Posts: 28
Joined: Thu Jul 07, 2022 3:34 am

Re: adding a file to an ESP-IDF project under VScode?

Postby mtraven » Tue Apr 09, 2024 8:31 pm

it is a little tricky, isn't it?
There is a add component command that uses IDF's repository to get components, IDF native and 3rd party(if listed). If the Library you need is listed, thats probably the simplest/safest. You can use github to get a library too(see project manifest). You can read the details of component manager https://docs.espressif.com/projects/esp ... nager.html:
Once added, those libraries will show up in a folder called "managed_components". As implied, those are managed internally. a full clean & build delete those download fresh copies. If you try to modify those,at all, it will warn you.

opt 2: limited, but easy.

1. in your project folder, make the folder "components".
2. dump the folder containing your library(and its own cmake), in components
3. #inlcude "myLibrary."

ps "components" is a magic name, dont change it.
What everyone else was suggesting ought to work too, sounds like you wanted something simpler.

Who is online

Users browsing this forum: No registered users and 165 guests