Page 1 of 1

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

Posted: Mon Apr 08, 2024 12:41 pm
by chriskuku
How do I add a source file to an existing project under Vscode/ESP-IDF?

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

Posted: Mon Apr 08, 2024 2:50 pm
by MicroController
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.

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

Posted: Mon Apr 08, 2024 6:06 pm
by mbratch
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.

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

Posted: Mon Apr 08, 2024 8:20 pm
by chriskuku
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.

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

Posted: Tue Apr 09, 2024 8:31 pm
by mtraven
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.