Sysprogs forums › Forums › VisualGDB › Making an embedded project on existing CMake build is not a smooth process
- This topic has 1 reply, 2 voices, and was last updated 6 hours, 48 minutes ago by support.
-
AuthorPosts
-
January 27, 2025 at 16:29 #36338curtis.hendrixParticipant
I’ve been trying to convert our build system over to CMake while still using Visual Studio with VisualGDB, and I keep running into issues when trying to create or use a VisualGDB Embedded advanced CMake project. In all of these scenarios, I’m using the “Import a project built with command-line tools” when creating the project, and selecting the “Import a CMake project with Advanced CMake Project Subsystem”. The firmware is already buildable from the command line, and a CMakePresets.json is used for configuration.
There’s 2 buildPresets in the CMakePresets.json file, Debug and Release. Doing a clean debug build from the command line is as simple as running
cmake --preset Debug
cmake --build --preset Debug
Same is true for the Release configuration. All of the information that CMake needs, like the toolchain, build type, generator, binary directories, and a few custom variables are located within the CMakePresets.json file.
On to the issues…
- Cannot create the project directly in the directory where the CMakeLists.txt file is located. I’d like to have the .sln file and the .vgdbcmake files located in the same directory as the CMakeLists.txt and CMakePresets.json file, but that’s not allowed during project creation. Creating a new project that uses an existing CMakeLists.txt file has to be created a new, empty directory. I’m not sure if this a Visual Studio or a VisualGDB limitation.
- Is the Device Selection tab really needed? Importing an existing CMakeLists.txt file strongly implies that all of the build settings have been setup and configured within the CMakeLists.txt file.
- The “CMake Binary” directory will reset to the default at %localappdata%\VisualGDB\CMake\bin\cmake.exe if the New Embedded Project Wizard is backed up to the “project type” and then taken forward again to the “Import CMake Project” step. In addition, re-setting the CMake Binary directory is ignored if you go back in the wizard and then forwards again.
- From what I can tell, selecting the “Use existing CMake presets instead of configuring CMake directly” option in the “Import CMake Project” step when creating the new project is broken. The project is created with the “Cmake Presets” option under “CMake Build Settings” in the VisualGDB project settings, but CMakePresets.json is completely ignored. For example, CMakePresets.json specifies that Ninja should be the generator, but VisualGDB defaults to using Unix Makefiles. VisualGDB also thinks there’s a MinSizeRel and a RelWithDebugInfo configuration, but CMakePresets.json only defines Debug and Release.
<div>
<div><LoadCMakePresets>true</LoadCMakePresets> is present in the <Build></Build> block within the .vgdbcmake file.</div>
</div>
<div></div> - I’m not exactly sure when in the project setup / configuration process this happens, but it looks like VisualGDB will create a new copy of CMakeLists.txt, and rename the original to CMakeLists.txt.old. Changing from “CMake Presets” to “Project File” under “Store build settings in” selection in the VisualGDB Project Settings->Cmake Build Settings will cause this to happen. This makes me nervous, because that implies VisualGDB may edit CMakeLists.txt directly. I can’t have VisualGDB making unexpected edits to CMakeLists.txt because not everyone on my team wants to have to use VisualGDB.
<some time later…/>
Okay I think I may have found the missing piece. At some point while I was futzing around with various options (I think it was primarily switching between the 2 “Store build settings in” in the VisualGDB Project Properties), I closed Visual Studio and re-opened the solution, and like magic, everything mostly started working. This looks like there is some kind of caching issue with VisualGDB when importing a CMake project. This was really frustrating.
Looks like the only issue I have left is Running Build->Rebuild will fail with the error “<build directory> is not a directory. The project is configured to “Delete build folder” for its “Clean mode”. From looking at the build output log, VisualGDB is NOT running
CMake --preset <Preset>
before it tries to runCMake --build <Binary dir>
when Rebuilding.January 30, 2025 at 17:12 #36356supportKeymasterHi,
Thanks for the detailed feedback. We have addressed most of the issues in this build: VisualGDB-6.0.107.5295.msi. Specifically:
- We have added a checkbox for relocating the project file to the imported project’s directory, similar to imported STM32Cube/IAR/Keil projects. It is located under the import mode selection switches.
- The device selection tab is needed because many parts of VisualGDB (debug engine, tracing engine, live memory engine, etc) can enable various optimizations if the device type is known. You don’t strictly need to set it and can proceed with the empty “manual” mode or pick any similar device, but you may end up needing to manually fine-tune debugging or configure other parts of VisualGDB.
- The CMake binary is pre-loaded based on other settings from the previous page (e.g. whether you are building it remotely). We could theoretically add logic for checking whether these settings got changed after changing the CMake path, but given that the non-default paths are used rarely, going back and forth through the pages is also not very common, and the workaround is trivial, we would rather not add any additional complexity to that part.
- There was indeed a bug with the CMake presets. Importing a preset without a build directory would show a rather generic error message, and if you configured the directory manually, it would not be applied until you reopen the project. We have fixed both issues: instead of the generic message, VisualGDB now clearly asks if you want to review/adjust the presets (where the missing value is immediately highlighted), and the changes are properly applied without having to reopen the project.
-
AuthorPosts
- You must be logged in to reply to this topic.