{"id":33219,"date":"2023-11-16T18:19:50","date_gmt":"2023-11-16T18:19:50","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=33219"},"modified":"2023-11-16T18:19:50","modified_gmt":"2023-11-16T18:19:50","slug":"debug-vcpkg-portfiles-in-cmake-script-mode-with-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/debug-vcpkg-portfiles-in-cmake-script-mode-with-visual-studio-code\/","title":{"rendered":"Debug vcpkg portfiles in CMake script mode with Visual Studio Code"},"content":{"rendered":"<p><span data-contrast=\"auto\">We recently announced support for <\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/introducing-cmake-debugger-in-vs-code-debug-your-cmake-scripts-using-open-source-cmake-debugger\/\"><span data-contrast=\"none\">debugging the CMake language using the VS Code CMake Tools extension<\/span><\/a><span data-contrast=\"auto\">. Now in version 1.16 of the extension, you can fine-tune the debugger configuration using a launch.json file. This enables debugging in CMake script mode in addition to the existing debugging of CMake project generation.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/manual\/cmake-language.7.html#scripts\"><span data-contrast=\"none\">CMake script mode<\/span><\/a><span data-contrast=\"auto\"> is an alternative way of running CMake that does not generate a build system, but instead uses the CMake language as a general-purpose scripting language. While script mode is not widely used (although there are <\/span><a href=\"https:\/\/github.com\/64\/cmake-raytracer\"><span data-contrast=\"none\">fun esoteric examples<\/span><\/a><span data-contrast=\"auto\">), it is the mechanism that powers <\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/registries-bring-your-own-libraries-to-vcpkg\/#4-test-your-new-vcpkg-port-using-overlays\"><span data-contrast=\"none\">vcpkg portfiles<\/span><\/a><span data-contrast=\"auto\">. vcpkg uses portfiles to know how to acquire, build, and install libraries. Through a combination of the new <\/span><a href=\"https:\/\/github.com\/microsoft\/vcpkg-tool\/pull\/1173\"><span data-contrast=\"none\">experimental \u201c&#8211;x-cmake-debug\u201d vcpkg option<\/span><\/a><span data-contrast=\"auto\"> and CMake Tools, it\u2019s now possible to debug these portfiles in VS Code. This is helpful when adding a library to the vcpkg catalog.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h3>Debugging vcpkg portfiles<\/h3>\n<p><span class=\"TextRun SCXW78103072 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW78103072 BCX8\">As an example, <\/span><span class=\"NormalTextRun SCXW78103072 BCX8\">we\u2019ll<\/span> <span class=\"NormalTextRun SCXW78103072 BCX8\">explore how to debug the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">vcpkg<\/span> <span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">portfile<\/span><span class=\"NormalTextRun SCXW78103072 BCX8\"> for <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">zlib<\/span><span class=\"NormalTextRun SCXW78103072 BCX8\">. First, ensure you have <\/span><strong><span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">CMake<\/span><\/strong><span class=\"NormalTextRun SCXW78103072 BCX8\"><strong> Tools 1.16<\/strong> and <\/span><strong><span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">CMake<\/span><\/strong><span class=\"NormalTextRun SCXW78103072 BCX8\"><strong> 3.27<\/strong> installed. Next, clone<\/span><span class=\"NormalTextRun SCXW78103072 BCX8\"> the<\/span> <span class=\"NormalTextRun SpellingErrorV2Themed SCXW78103072 BCX8\">vcpkg<\/span> <span class=\"NormalTextRun SCXW78103072 BCX8\">repo <\/span><span class=\"NormalTextRun SCXW78103072 BCX8\">and open it in VS Code.<\/span><\/span><span class=\"EOP SCXW78103072 BCX8\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<blockquote>\n<pre>&gt; git clone https:\/\/github.com\/microsoft\/vcpkg\r\n&gt; cd vcpkg\r\n&gt; .\\bootstrap-vcpkg.bat (or bootstrap-vcpkg.sh on Linux)\r\n&gt; code .<\/pre>\n<\/blockquote>\n<p>We&#8217;ll use a <code>tasks.json<\/code> to define a task that installs the <code>zlib<\/code> library <span class=\"NormalTextRun SCXW253659739 BCX8\">with the <code>--x-<\/code><\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">cmake<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">-debug <\/span><\/code><span class=\"NormalTextRun SCXW253659739 BCX8\">option<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\"> and a <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">launch.json<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\"> file to configure <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\"> Tools<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\"> to attach to the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">zlib<\/span> <span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">portfile<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\"> as <\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">it\u2019s<\/span> <span class=\"NormalTextRun SCXW253659739 BCX8\">being <\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">run<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">. In VS Code, create a new \u201c.<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">vscode<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">\u201d directory<\/span><span class=\"NormalTextRun SCXW253659739 BCX8\">. Add the following <\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">tasks.json<\/span><\/code><span class=\"NormalTextRun SCXW253659739 BCX8\"> and <\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW253659739 BCX8\">launch.json<\/span><\/code><span class=\"NormalTextRun SCXW253659739 BCX8\"> files to this directory.<\/span><\/p>\n<p><strong>tasks.json<\/strong><\/p>\n<pre><span data-contrast=\"auto\">{<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 \"version\": \"2.0.0\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 \"tasks\": [<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"label\": \"Reinstall zlib\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"type\": \"shell\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"isBackground\": true,<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"command\": \"&amp; \\\"${workspaceFolder}\/vcpkg.exe\\\" remove zlib; &amp; \\\"${workspaceFolder}\/vcpkg.exe\\\" install zlib --no-binarycaching --x-cmake-debug \\\\\\\\.\\\\pipe\\\\portfile_debugging\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"problemMatcher\": [<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"pattern\": [<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"regexp\": \"\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"file\": 1,<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"location\": 2,<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"message\": 3<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ],<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"background\": {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"activeOnStart\": true,<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"beginsPattern\": \".\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"endsPattern\": \"Waiting for debugger client to connect\"<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ]<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 ]<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">}<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/pre>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\nThe important parts of the configuration are the command, which removes <span class=\"NormalTextRun SpellingErrorV2Themed SCXW92960476 BCX8\">zlib<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> if <\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">it\u2019s<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> already installed and then reinstalls it, and the <\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW92960476 BCX8\">endsPattern<\/span><\/code><span class=\"NormalTextRun SCXW92960476 BCX8\">,<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> which tells VS Code when it can consider the task complete. <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW92960476 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> will output the \u201cWaiting for debugger client to connect\u201d string as soon as <\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">it has finished initializing the debugger. The rest of the <\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW92960476 BCX8\">problemMatcher<\/span><\/code><span class=\"NormalTextRun SCXW92960476 BCX8\">\u00a0<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">values are<\/span> <span class=\"NormalTextRun SCXW92960476 BCX8\">required<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> to <\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">satisfy<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> VS Code\u2019s launch configuration <\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">schema but<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\"> are not used in this example.<\/span><span class=\"NormalTextRun SCXW92960476 BCX8\">\u00a0<\/span><\/span><\/p>\n<p><strong>launch.json<\/strong><\/p>\n<pre><span data-contrast=\"auto\">{<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 \"version\": \"0.2.0\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 \"configurations\": [<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"type\": \"cmake\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"request\": \"launch\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"name\": \"Debug zlib portfile\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"cmakeDebugType\": \"external\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"pipeName\": \"\\\\\\\\.\\\\pipe\\\\portfile_debugging\",<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"preLaunchTask\": \"Reinstall zlib\"<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">\u00a0\u00a0\u00a0 ]<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">}<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/pre>\n<p>This CMake Debugging configuration <span class=\"TextRun SCXW260554212 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW260554212 BCX8\">uses <\/span><span class=\"NormalTextRun SCXW260554212 BCX8\">a <\/span><code><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">cmakeDebugType<\/span><\/code><span class=\"NormalTextRun SCXW260554212 BCX8\">\u00a0<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\">of <code>external<\/code>,<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\"> meaning the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\"> Tools extension is not responsible for launching <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\"> (in this case <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">vcpkg<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\"> is<\/span> <span class=\"NormalTextRun SCXW260554212 BCX8\">launching <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\">). <\/span><span class=\"NormalTextRun SCXW260554212 BCX8\">Notice how we use the same pipe name as the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW260554212 BCX8\">vcpkg<\/span><span class=\"NormalTextRun SCXW260554212 BCX8\"> install task.<\/span><\/span><\/p>\n<p><span class=\"EOP SCXW260554212 BCX8\" data-ccp-props=\"{}\"><span class=\"TextRun SCXW166107251 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW166107251 BCX8\">Finally, <\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">open ports\/<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">zlib<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">\/<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">portfile.cmake<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\"> and set a breakpoint <\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">on line 2 (the call to <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">vcpkg_from_github<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">). In the <\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">VS Code Run and Debug view, select the <strong>Debug <\/strong><\/span><strong><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">zlib<\/span> <span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">portfile<\/span><\/strong><span class=\"NormalTextRun SCXW166107251 BCX8\">\u00a0configuration and click the play button to start debugging. VS Code will automatically <\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">run the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">vcpkg<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\"> install task<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\"> until the debugger is ready for client connections, then start a debugging session. At this point <\/span><span class=\"NormalTextRun SCXW166107251 BCX8\">it\u2019s<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\"> possible to step through the <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW166107251 BCX8\">portfile<\/span><span class=\"NormalTextRun SCXW166107251 BCX8\"> and inspect variables.<\/span><\/span><span class=\"EOP SCXW166107251 BCX8\" data-ccp-props=\"{}\">\u00a0<\/span><\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile.png\"><img decoding=\"async\" class=\" wp-image-33223 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile-1024x672.png\" alt=\"Debugging your portfile.cmake using the CMake debugger\" width=\"871\" height=\"572\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile-1024x672.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile-300x197.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile-768x504.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/vcpkg-portfile.png 1414w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/a><\/p>\n<h3>Debugging in CMake script mode without a configuration<\/h3>\n<p><span class=\"TextRun SCXW163181656 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW163181656 BCX8\">It\u2019s<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\"> also possible to <\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">quickly<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\"> debug <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\"> scripts without a <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">launch.json<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\"> configuration. This can be a handy way <\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">to experiment with <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\"> commands. To try it, create a new <\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">file named &#8220;<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">debugging<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">_example<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW163181656 BCX8\">.cmake&#8221;<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">\u00a0in VS Code<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">, <\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">open it in the editor<\/span><span class=\"NormalTextRun SCXW163181656 BCX8\">, and add this content:<\/span><\/span><span class=\"EOP SCXW163181656 BCX8\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><strong>debugging_example.cmake<\/strong><\/p>\n<pre><span data-contrast=\"auto\">set(WORLD \"World!\")<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span>\r\n\r\n<span data-contrast=\"auto\">message(STATUS \"Hello ${WORLD}\")<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:240,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/pre>\n<p>Set a breakpoint on line 1 of this file. <span class=\"NormalTextRun SCXW126331513 BCX8\"> In the Run and Debug view, select the <\/span><strong><span class=\"NormalTextRun SCXW126331513 BCX8\">\u201c<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW126331513 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\"> Debugger\u2026&#8221; <\/span><\/strong><span class=\"NormalTextRun SCXW126331513 BCX8\">option<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\"> from the <\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">debug configuration dropdown<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\"> and <\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">choose <strong>\u201c<\/strong><\/span><strong><span class=\"NormalTextRun SpellingErrorV2Themed SCXW126331513 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">: <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW126331513 BCX8\">CMake<\/span><\/strong><span class=\"NormalTextRun SCXW126331513 BCX8\"><strong> Script\u201d<\/strong> from the quick pick menu. Click the play button and the <\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">script will start running under the debugger, with no <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW126331513 BCX8\">launch.json<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\"> configuration <\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">needed<\/span><span class=\"NormalTextRun SCXW126331513 BCX8\">!<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script.png\"><img decoding=\"async\" class=\"wp-image-33224 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script-1024x674.png\" alt=\"Debugging a CMake script with the CMake debugger without a launch.json\" width=\"844\" height=\"555\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script-1024x674.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script-300x198.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script-768x506.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/11\/debugging-cmake-script.png 1414w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/a><\/p>\n<h3>What&#8217;s next?<\/h3>\n<p><span class=\"TextRun SCXW120395587 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW120395587 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW120395587 BCX8\"> script mode debugging currently only <\/span><span class=\"NormalTextRun SCXW120395587 BCX8\">works<\/span><span class=\"NormalTextRun SCXW120395587 BCX8\"> in VS Code, but we are planning to bring the same functionality to Visual Studio<\/span><span class=\"NormalTextRun SCXW120395587 BCX8\"> in a future release. Learn more about <\/span><span class=\"NormalTextRun SCXW120395587 BCX8\">all the options for debugging <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW120395587 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW120395587 BCX8\"> scripts in <\/span><\/span><a class=\"Hyperlink SCXW120395587 BCX8\" href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/blob\/main\/docs\/debug.md\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW120395587 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW120395587 BCX8\" data-ccp-charstyle=\"Hyperlink\">our documentation<\/span><\/span><\/a><span class=\"TextRun SCXW120395587 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW120395587 BCX8\">.<\/span><\/span><span class=\"EOP SCXW120395587 BCX8\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h3>Send us your feedback!<\/h3>\n<p><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">We hope this helps your <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW75582342 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW75582342 BCX8\"> workflows in VS Code.<\/span> <span class=\"NormalTextRun SCXW75582342 BCX8\">Download the\u202f<\/span><\/span><a class=\"Hyperlink SCXW75582342 BCX8\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cmake-tools\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW75582342 BCX8\" data-ccp-charstyle=\"Hyperlink\">CMake\u202fTools extension\u202f<\/span><\/span><\/a><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">for Visual Studio Code and let us know what you think. We would love to see what you contribute to our\u202f<\/span><\/span><a class=\"Hyperlink SCXW75582342 BCX8\" href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW75582342 BCX8\" data-ccp-charstyle=\"Hyperlink\">repo<\/span><\/span><\/a><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">\u202fand are active on reviews and collaboration. If you have any issues, please file an issue to our repo\u202f<\/span><\/span><a class=\"Hyperlink SCXW75582342 BCX8\" href=\"https:\/\/github.com\/microsoft\/vscode-cmake-tools\/issues\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW75582342 BCX8\" data-ccp-charstyle=\"Hyperlink\">here<\/span><\/span><\/a><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">. Comment below or reach us via email at\u202f<\/span><\/span><a class=\"Hyperlink SCXW75582342 BCX8\" href=\"mailto:visualcpp@microsoft.com\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW75582342 BCX8\" data-ccp-charstyle=\"Hyperlink\">visualcpp@microsoft.com<\/span><\/span><\/a><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">\u202for via\u202fTwitter at\u202f<\/span><\/span><a class=\"Hyperlink SCXW75582342 BCX8\" href=\"https:\/\/twitter.com\/visualc\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW75582342 BCX8\" data-ccp-charstyle=\"Hyperlink\">@VisualC<\/span><\/span><\/a><span class=\"TextRun SCXW75582342 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW75582342 BCX8\">.<\/span><\/span><span class=\"EOP SCXW75582342 BCX8\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We recently announced support for debugging the CMake language using the VS Code CMake Tools extension. Now in version 1.16 of the extension, you can fine-tune the debugger configuration using a launch.json file. This enables debugging in CMake script mode in addition to the existing debugging of CMake project generation.\u00a0 CMake script mode is an [&hellip;]<\/p>\n","protected":false},"author":72332,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266,272],"tags":[],"class_list":["post-33219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","category-vcpkg"],"acf":[],"blog_post_summary":"<p>We recently announced support for debugging the CMake language using the VS Code CMake Tools extension. Now in version 1.16 of the extension, you can fine-tune the debugger configuration using a launch.json file. This enables debugging in CMake script mode in addition to the existing debugging of CMake project generation.\u00a0 CMake script mode is an [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/33219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/72332"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=33219"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/33219\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=33219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=33219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=33219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}