Cmake Make Debug

From the command palette in VS Code, run the CMake: Debug Target command, press the keyboard shortcut Ctrl+F5, or press the Debug button in the status bar. See the CMake:Target debugging and launching page for more information. Pass command-line arguments to the debugger. See Debug using a launch.json file. Set up include paths for C IntelliSense. Enabling this variable is equivalent to using cmake -debug-find with the added ability to enable debugging for a subset of find calls. Set (CMAKEFINDDEBUGMODE TRUE) findprogram (.) set. Feb 04, 2020 Run cmake with: -DCMAKEBUILDTYPE=Debug Release') endif setproperty(GLOBAL PROPERTY DEBUGCONFIGURATIONS Debug) Line 5 is true if and only if a multi configuration build is being made, while line 7 (only being affected by single configurations) checks that a build type was specified. With CMake, it’s generally recommended to do an “out of source” build. Create your CMakeLists.txt in the root of your project. Then from the root of your project: mkdir Release cd Release cmake -DCMAKEBUILDTYPE=Release. Make And for Debug (again from the root of your project): mkdir Debug cd Debug cmake -DCMAKEBUILDTYPE=Debug.

-->

Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the Version drop-down located above the table of contents to Visual Studio 2017 or Visual Studio 2019.

This topic describes how to add a Linux configuration to a CMake project that targets either a remote Linux system or Windows Subsystem for Linux (WSL). It continues the series that began with Create a Linux CMake project in Visual Studio. If you are using MSBuild, instead, see Configure a Linux MSBuild Project in Visual Studio

Add a Linux configuration

A configuration can be used to target different platforms (Windows, WSL, a remote system) with the same source code. A configuration is also used to set your compilers, pass environment variables, and customize how CMake is invoked. The CMakeSettings.json file specifies some or all of the properties listed in Customize CMake settings, plus additional properties that control the build settings on the remote Linux machine.

To change the default CMake settings in Visual Studio 2017, choose CMake > Change CMake Settings > CMakeLists.txt from the main menu. Or, right-click CMakeLists.txt in Solution Explorer and choose Change CMake Settings. Visual Studio then creates a new CMakeSettings.json file in your root project folder. To make changes, open the file and modify it directly. For more information, see Customize CMake settings.

The default configuration for Linux-Debug in Visual Studio 2017 (and Visual Studio 2019 version 16.0) looks like this:

To change the default CMake settings in Visual Studio 2019, from the main toolbar, open the Configuration dropdown and choose Manage Configurations.

This command opens the CMake Settings Editor, which you can use to edit the CMakeSettings.json file in your root project folder. You can also open the file with the JSON editor by clicking the Edit JSON button in the editor. For more information, see Customize CMake Settings.

Cmake

The default Linux-Debug configuration in Visual Studio 2019 version 16.1, and later, looks like this:

In Visual Studio 2019 version 16.6 or later, Ninja is the default generator for configurations targeting a remote system or WSL. For more information, see this post on the C++ Team Blog.

For more information about these settings, see CMakeSettings.json reference.

When you do a build:

  • If you're targeting a remote system, Visual Studio chooses the first remote system in the list under Tools > Options > Cross Platform > Connection Manager by default for remote targets.
  • If no remote connections are found, you're prompted to create one. For more information, see Connect to your remote Linux computer.

Choose a Linux target

When you open a CMake project folder, Visual Studio parses the CMakeLists.txt file and specifies a Windows target of x86-Debug. To target a remote Linux system, you'll change the project settings based on your Linux compiler. For example, if you are using GCC on Linux and compiling with debug info, you'll chose: Linux-GCC-Debug or Linux-GCC-Release.

If you specify a remote Linux target, your source is copied to the remote system.

After you select a target, CMake runs automatically on the Linux system to generate the CMake cache for your project:

Target Windows Subsystem for Linux

If you're targeting Windows Subsystem for Linux (WSL), you don't need to add a remote connection.

To target WSL, select Manage Configurations in the configuration dropdown in the main toolbar:

The CMakeSettings.json window appears.

Press Add Configuration (the green '+' button) and then choose Linux-GCC-Debug or Linux-GCC-Release if using GCC. Use the Clang variants if you are using the Clang/LLVM toolset. Press Select and then Ctrl+S to save the configuration.

Visual Studio 2019 version 16.1 When you target WSL, Visual Studio doesn't need to copy source files and maintain two synchronous copies of your build tree because the compiler on Linux has direct access to your source files in the mounted Windows file system.

IntelliSense

Accurate C++ IntelliSense requires access to the C++ headers referenced by your C++ source files. Visual Studio automatically uses the headers referenced by a CMake project from Linux to Windows to provide a full-fidelity IntelliSense experience. For more information, see IntelliSense for remote headers.

Locale setting

Visual Studio language settings aren't propagated to Linux targets because Visual Studio doesn't manage or configure installed packages. Messages shown in the Output window, such as build errors, are shown using the language and locale of the Linux target. You'll need to configure your Linux targets for the desired locale.

Additional settings

Cmake Debug Release

Use the following settings to run commands on the Linux system before and after building, and before CMake generation. The values can be any command that is valid on the remote system. The output is piped back to Visual Studio.

Cmake Make Debug Video

Next steps

Cmake Generate Debug Info

See also

Cmake Make Debug Output

Working with project properties
Customize CMake settings
CMake predefined configuration reference