Importing CMake Linux projects to VisualGDB

This tutorial shows how to import Linux CMake projects to VisualGDB. We will demonstrate this by downloading the MySql database engine source code, building it with VisualGDB, debugging the client application and using Code Map and other IntelliSense features to explore the code.

Before you begin, download MySql source code to your Linux machine and unpack it.

  1. Start Visual Studio and launch the VisualGDB Linux Project Wizard:01-prjname
  2. In the Linux Project wizard select “Import a project -> Import a CMake project”:02-import
  3. On the next page select the computer where you have unpacked the MySql source code:03-compname
  4. Then select “The sources are already on the Linux computer” and enter the source directory:04-dir
  5. In this tutorial we will keep the source files directly on the Linux machine and access them from Windows via shared folders. To setup this automatically, select the first item on the Source Code Access page and click “Setup”:05-samba
  6. Select the directory you want to share on the Linux machine and provide the share name, user name and password:06-share
  7. Once you click OK, VisualGDB will create the share and display the overview of the Windows and Linux paths:07-map
  8. On the last page specify build subdirectories for Debug and Release configurations. You can use the ../subdir syntax to specify directories outside the source directory:08-import
  9. Click “Finish” to build the project then build it with Ctrl-Shift-B:09-project
  10. If you don’t have MySql installed on that machine, install it manually by running the following commands in the build directory:
  11. Now we can debug the MySql client. Open VisualGDB Project Properties and go to the Debug Settings page. Then check the “Run debugger as root” checkbox:10-sudo
  12. Hit F10 to step into the main() function:14-codemap
  13. As the MySql project is large and has a lot of targets distributed among multiple CMake files, VisualGDB won’t auto-detect the executable to debug. Instead it allow selecting one explicitly. Specify the mysql client binary and press OK:10-selectappYou can change the primary executable later on the CMake page of VisualGDB Project Properties.
  14. The debugging will start at the main() function:11-debug
  15. You can use the normal Visual Studio debugging functionality to debug the code. If you are using the Clang IntelliSense engine, you can right-click in your code and select “Preprocess Selected Lines” to automatically see behind non-trivial preprocessor macros:12-prepro
  16. When importing CMake projects, VisualGDB will configure CMake to generate a <project directory>\VisualGDBCache\<project>-<config>\compile_commands.json file with all build command lines and will configure IntelliSense based on that file. If you encounter strange IntelliSense errors, check that file to see whether the command line mentioned in it is up to date:13-commands
  17. You can also use Code Map provided by the Clang IntelliSense engine to quickly visualize the relations between different parts of your code:14-codemap