User Tools

Site Tools


visual_studio_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
visual_studio_code [2020/04/10 13:41]
josepma
visual_studio_code [2020/05/14 09:10] (current)
swiftb0y update to include configs for compiling and debugging from within vscode
Line 1: Line 1:
 +====== Setting up Visual Studio Code for Mixxx development ======
 +
 **Visual Studio Code** is a free open source code editor / IDE that is easy to set-up.\\ **Visual Studio Code** is a free open source code editor / IDE that is easy to set-up.\\
-It is a completely different editor than [[Visual Studio Community]]+It is a completely different editor than [[Visual Studio Community]]. \\ 
 +VSCode is very well suited for [[midi_scripting|Controller Scripting]] as well as 
 +[[start#​developer_documentation|working on Mixxx'​s core with C++]].
  
-Follow this instructions to set-up Visual Studio Code for Mixxx development.+===== Setting ​up VScode ​for C++ ===== 
 + 
 +Note: Most of this guide will assume that you have a folder named `cbuild` in the root folder 
 +of the locally cloned repository. This is where cmake will put the buildfiles and build the 
 +mixxx binary. If you want to use a different folder, you need to adapt the paths present in 
 +the config file templates given.
  
   - Check out Mixxx source and build it.   - Check out Mixxx source and build it.
Line 10: Line 19:
   - Select File -> Open... and open the mixxx source folder.   - Select File -> Open... and open the mixxx source folder.
     * Visual Studio Code saves it's configuration in a folder named .vscode in the mixxx source folder. Next time you want to work on mixxx you only need to open the mixxx source folder again.     * Visual Studio Code saves it's configuration in a folder named .vscode in the mixxx source folder. Next time you want to work on mixxx you only need to open the mixxx source folder again.
-  - Configure ​the c++ extension to enable code completion. + 
-    - Create a folder named .vscode in the mixxx root folder ​(if not already ​created). +==== Enabling autocompletion ==== 
-    - Inside this folder, create a file named settings.json (if not already created)+Put the following text into your `c_cpp_properties.json` (or create it if it doesn'​t exist already) ​into the `.vscode` ​folder. 
-    - Add the following content to this file: <​code>​+<​code ​javascript>
 { {
-    "C_Cpp.default.cStandard":​ "​c11",​ +    "configurations":​ [ 
-    "C_Cpp.default.cppStandard":​ "c++11", +        { 
-    "C_Cpp.default.compileCommands":​ "​${workspaceFolder}/​compile_commands.json"​+            "​name":​ "​Linux",​ 
 +            "​compilerPath":​ "/​usr/​bin/​gcc",​ 
 +            "cStandard":​ "​c11",​ 
 +            "​cppStandard":​ "c++17", 
 +            "​intelliSenseMode":​ "​gcc-x64",​ 
 +            ​"​compileCommands":​ "​${workspaceFolder}/cbuild/​compile_commands.json"​ 
 +        } 
 +    ], 
 +    "​version":​ 4
 } }
 </​code>​ </​code>​
 +For this to properly work, its important to enable generation of the compilation database while running CMake.
 +The build and config tasks following do this automatically for you.
 +
 +==== Compiling ====
 +
 +Unfortunately,​ I'm not able to create configs for building Mixxx through VScode on anything other
 +than Linux. So this section assumes you are running VScode on Linux. You should also have read the
 +[[compiling_on_linux#​cmake|compiling on linux guide with cmake]] to properly grasp the following section.
 +
 +=== Generating buildfiles and compiling mixxx ===
 +
 +Use the following `tasks.json` config (located in `.vscode`) to be able to generate buildfiles and compile linux from within VScode:
 +<code javascript>​
 +{
 +    // See https://​go.microsoft.com/​fwlink/?​LinkId=733558
 +    // for the documentation about the tasks.json format
 +    "​version":​ "​2.0.0",​
 +    "​tasks":​ [
 +        {
 +            "​label":​ "CMake generate buildfiles",​
 +            "​type":​ "​shell",​
 +            "​group":​ "​build",​
 +            "​options":​ {
 +                "​cwd":​ "​cbuild"​
 +            },
 +            "​command":​ "​cmake",​
 +            "​args":​ [
 +                "​-DCMAKE_INSTALL_PREFIX=/​usr/​local",​
 +                // add any further arguments for CMake here
 +                ​
 +                // generate debug build
 +                "​-DCMAKE_BUILD_TYPE=Debug",​
 +                "​-DDEBUG_ASSERTIONS_FATAL=ON",​
 +                "​-DOPTIMIZE=native",​
 +                // generate compile_commands.json
 +                "​-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",​
 +                "​${workspaceFolder}"​
 +            ],
 +            "​problemMatcher":​ []
 +        },
 +        {
 +            "​label":​ "CMake compile",​
 +            "​type":​ "​shell",​
 +            "​command":​ "cmake --build . --parallel $(nproc)",​
 +            "​group":​ {
 +                "​kind":​ "​build",​
 +                "​isDefault":​ true
 +            },
 +            "​options":​ {
 +                "​cwd":​ "​cbuild"​
 +            },
 +            "​problemMatcher":​ []
 +        }
 +    ]
 +}
 +</​code>​
 +This will add the "CMake generate buildfiles"​ and "CMake compile"​ tasks to VScode. Both can be invoked in the command prompt accessible via [CTLR]+[Shift]+P. The "CMake compile"​ can also be invoked directly by pressing [CTLR]+[Shift]+B.
 +
 +==== Debugging ====
 +Add this to your `launch.json` file to add debugging capabilities (based on gdb) to vscode.
 +
 +<code javascript>​
 +{
 +    // Use IntelliSense to learn about possible attributes.
 +    // Hover to view descriptions of existing attributes.
 +    // For more information,​ visit: https://​go.microsoft.com/​fwlink/?​linkid=830387
 +    "​version":​ "​0.2.0",​
 +    "​configurations":​ [
 +        {
 +            "​name":​ "(gdb) Launch",​
 +            "​type":​ "​cppdbg",​
 +            "​request":​ "​launch",​
 +            "​program":​ "​${workspaceFolder}/​cbuild/​mixxx",​
 +            "​args":​ [
 +                "​--resourcePath res/",
 +                "​--debugAssertBreak"​
 +                // add more args here (for example a custom --settingsPath)
 +            ],
 +            "​stopAtEntry":​ false,
 +            "​cwd":​ "​${workspaceFolder}",​
 +            "​environment":​ [],
 +            "​externalConsole":​ false,
 +            "​MIMode":​ "​gdb",​
 +            "​setupCommands":​ [
 +                {
 +                    "​description":​ "​Enable pretty-printing for gdb",
 +                    "​text":​ "​-enable-pretty-printing",​
 +                    "​ignoreFailures":​ true
 +                }
 +            ]
 +        }
 +    ]
 +}
 +</​code>​
 +
 +You should now be able to launch Mixxx with gdb attached by pressing `F5`. If you want to know
 +more about debugging, Microsoft has a guide which introduces to into VScodes debugging capabilities:​ https://​code.visualstudio.com/​docs/​editor/​debugging
  
 (([[https://​devblogs.microsoft.com/​cppblog/​building-your-c-application-with-visual-studio-code/​|Building your C++ application with Visual Studio Code]])) (([[https://​devblogs.microsoft.com/​cppblog/​building-your-c-application-with-visual-studio-code/​|Building your C++ application with Visual Studio Code]]))
visual_studio_code.txt · Last modified: 2020/05/14 09:10 by swiftb0y