Importing External Embedded CMake Projects in VisualGDB

This tutorial shows how use VisualGDB to build and debug existing Embedded CMake projects that are not based on the VisualGDB’s embedded framework (i.e. do not utilize find_bsp() and other similar statements). We will show how to import a very basic STM32 project into VisualGDB, and will explain the differences between the imported project and a CMake-based project created from scratch.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:
  2. Enter the name and location of the VisualGDB project you would like to create. The VisualGDB project will store high-level settings (such as IntelliSense or debugging settings) and can be placed in the same directory as the existing CMake project, or in any other location. In this tutorial we will place it in the parent directory (C:\tutorials\visualgdb\ARM\CMake\ImportedProjectDemo where the existing CMake project is checked out to C:\tutorials\visualgdb\ARM\CMake\ImportedProjectDemo\ExistingProject):
  3. On the first page of VisualGDB wizard, select “Import a project built with command-line tools -> Import a CMake project with Advanced CMake Project Subsystem“:
  4. On the next page select the toolchain and the device you would like to target. that it will be used to configure IntelliSense/debugging, but will not affect the build process, unless the existing CMakeLists.txt files explicitly read the toolchain location from the TOOLCHAIN_ROOT variable:
  5. On the next page of the wizard enter the location of the project you are importing: Note that normally VisualGDB will try to generate a toolchain.cmake file defining the toolchain selected in the wizard and will pass it to CMake via the CMAKE_TOOLCHAIN_FILE variable. If you want to override this behavior, enable the “use existing CMAKE_TOOLCHAIN_FILE” checkbox and point to your existing toolchain.cmake file (or leave the path empty if your toolchain information is hardcoded in CMakeLists.txt).
  6. Click “Finish” to complete the project importing. You will now be able to build it as a regular Embedded project:
  7. Set a breakpoint in main() and press F5 to begin debugging. VisualGDB will program the FLASH memory and launch the application. The breakpoint in main() will trigger, letting you examine the program state:
  8. Unlike the Advanced Embedded CMake projects managed by VisualGDB, imported CMake projects will not use the Sysprogs embedded framework, so changing the device via VisualGDB Project Properties, or adding/removing frameworks will not affect CMakeLists.txt files. Instead, you would need to edit low-level target settings (e.g. preprocessor definitions or CFLAGS) via target properties, or by editing CMakeLists.txt directly:The rest of the project editing functionality (e.g. adding/removing targets or source files) will work as expected.

If you are looking for a better integration between CMake and embedded tools, please consider creating an embedded project using the Sysprogs Embedded Framework as shown in this tutorial.