Add Files to Project - nxp-mcuxpresso/vscode-for-mcux GitHub Wiki
This experimental feature simplifies the process of adding files to your project. Source files added through this feature will also be automatically included in the project's CMakeLists.txt.
To enable this functionality:
- Open User Settings in VS Code.
- Navigate to Extensions, then go to MCUXpresso for VS Code.
- Check the box for Enable Add Files to Project.
Adding Files via Drag and Drop
You can drag and drop files or folders directly into your project. Here's how it works: The extension will scan all the dropped files/folders and detect all the source files, even those nested within directories. At this point, the extension asks how to handle the sources, copy or link:
- Copy: Source files are copied to the target location and added to CMakeLists.txt; all dragged files/folders even if not a source will be copied as well.
- Link: Source files are not copied, but they are still added to CMakeLists.txt. nothing is copied inside the project.
- Cancel: Aborts the drag and drop process.
If no source files were detected, all the dragged files and folders will simply be copied into the drop destination and CMakeLists.txt remains unchanged.
Adding Files via Context Menu
You can also add files using the "Add File(s) to Project" context menu.
This context menu option is available:
- at the project level: Files are added to the root of the project.
- Inside the "Project Files" category, for each item. If selected for a directory, new files are added inside that directory. If selected for a file, new files are added next to the selected file.
This method only supports adding files (not folders). If source files are detected, you’ll be prompted to choose between copying or linking them. If no source files are found, the files are simply copied to the target location.
Updating CMakeLists.txt
All detected source files that were copied or linked to the project are automatically added to the project's CMakeLists.txt. The inserted section is marked with timestamped comments at the beginning and the end of the block.
Source file entries added to CMakeLists.txt are relative either to the root of the project or to the SDK/repository, depending on their location. For all project types except Matter, if the added source file is located within the project's SDK or repository, its entry will be relative to that location. Otherwise, the entry will be relative to the root of the project or the location of the CMakeLists.txt file.