Visual Studio Code C++ Workflow: Optimize Your Setup with CMake Presets - The 2024 Ultimate Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone and welcome to this video in this one we wanted to explore the concept of cimic presets and see how they help you and more importunately how you take advantage of them inside of Visual Studio code let's open the project we did in the last video I think I still have it opened here no this is one this one is using cimc presets but we can open the previous one so cake with K I think this was the project this is what we did in the last video and we used a bunch of cats but one of the main reasons I prefer to use a cake is that it is really everywhere in C++ and it is supported by a lot of idees the way we have this project set up it is going to be understood by some idees but there is still a chance that some ID is going to pick a wrango compiler that you don't support in your C++ project and there really needs a way to tell idees the configurations that they can use to build your project to really show this idea I am going to try and open this project inside of visual studio and we're going to see what happens I am going to open Microsoft Visual Studio on my system here and I am going to try and open this project so open a project or a solution I am going to click on that and I am going to go to the location where I have my project here so we can go to uh let's go open the previous project that we did see with kit and we are going to open this and and and if we hit open we see that it's not even opening this it wants us to open the build folder which is not going to contain anything that we want so what do we do let's try to open a local folder and again go to that location and choose the project and try to open it it is going to open the folder it is going to bring those files in it is going to open the project and we can build it if we hit build and say build all you see that the project is going to be built and we can run it so if we select the rooster exe as a startup item it is going to run and you see that it is doing whatever we want the application to do this is one of the powers of cake you can use it across many idees now this is working because Microsoft Visual Studio has good support for CM but not all idas are going to easily understand what is happening here and another thing is that you can see that it is just automatically using Microsoft Visual Studio but it is going to take out the option to for example build with GCC on Windows if we happen to need this option here so that's one of the motivations of using cimic presets it's a way that simic provides to tell projects or idees the configurations that you want your project to use okay let's go back to the project inside of Visual Studio code what we can do now is to add a cake preset file and that file is going to be contained mean options we want to use in this project and configurations that are going to be easily picked up by IDE and everything is going to be much better let's go to the documentation and say CAC presets and you can click on this and really read all you want about this they say that one problem that CAC users often face is sharing settings with other people for common ways to configure a project this may be done to support CI bus and all kinds of crazy things but they say that they provide CAC presets as a solution and to use CAC preset you can set up a CAC preset dojon file or a CAC user preset dojon file and these files are going to be merged together to put together a configuration that you use there are a few kinds of presets you can use in cimic there are configure presets there are build presets there are test preset and other presets as you see in the documentation here but in this video we will be focusing on configure presets and build presets if you want to learn about test presets and how you use them I have them covered in my C Series so make sure to check that out in the description below if you are interested but for now I am going to open a project that is using simic presets so let's file open folder and open project 4 with CAC preset I am not going to start this from scratch because you already know a bit about CAC we covered the CAC list.txt file in the last video so all this project is doing really is adding this C presets that Json file and you can get this file from the git repository of this project now you may think that this preset is a bit complex or convoluted and you are right I myself can't write this file properly I have to get help from many places I think I got this file from a project that I follow on GitHub I think it is called endless Sky you can check it out on GitHub what I did is I took the preset file in that project and used it as a starting point to do my preset here my configure presets are going to be setting up a few compilers that my project support here and in cake presets you can have presets inher it from other presets in this case we have the base preset which is hidden okay you see that the hidden property is set to true it is going to set up the generator that we want to use again if you want to learn about generators I would recommend you check out my CX series we're going to go into the details but this doesn't matter it is just a thing that is used by cic to set up your project and you have to make sure you have it installed if you want to use it you can search in Google how to install Ninja on windows so install Ninja on Windows and you will see ways to install it I think what we are using on my Windows machine is installed as part of the wind Libs libraries that we installed let's go to see and look at MW to confirm if we go to Ben and go to a section with n we should find ninja I think it is installed in this location but I am not sure so so let's make sure where is n yes we have Ninja here and it is what we are using this is really cool we can call it from the terminal if we want so let's do terminal and call ninja ninja version and we are going to report the ninja version that we are using here so this is a build system that cake is going to call to build your project and my basic configuration here is using that build system you see that we can specify the location where the build files are going to go in this case we want to go in the source directory go in the build folder and then set up another folder with the preset name and the preset name is just going to be this value that you specify here we also have a Windows preset which is going to be inheriting from the base preset and because we are inheriting we will be getting all these properties here for example we will be inheriting the generator we will be inheriting this binary dur we will be inheriting a lot of stuff from this base configuration preset here if I may say it like that we specify the architecture that our application is going to be built for we specify a few cash variables you can specify cach variables in a c make preset file we just want to build our application in debug mode and we specify that we want to be using the compiler from Microsoft again if you want to learn about these things in detail I have a few videos in my cic series you may check them out but I also strongly suggest you read the documentation because they say more than I can say in a video like this so we have a configuration which is going to be building using the compiler from Microsoft I also have a configuration that is going to be targeting the Mac OS and it is going to be using the clang compiler on a Mac so if you're trying to build this project on a Mac and select to use this preset the IDE you are using is going to know that it is going to be using these configurations here it is going to build in the bug mode it is going to use the Clank compiler and everything is going to fall in place on Linux we will be using the g++ compiler to build this project and this is how you set up the settings that your project is going to be built with and the good thing about CAC presets is that ID is now to hun for this file in your project and use the settings in here to build your project and everything is going to be really in place for example if your project doesn't support clang you may take it out you may just set up presets for the compilers that you support and this is really really cool I have to say that you don't have to use presets they are just an addition that help your project play well with Ides but I find myself using them a lot because they make my life easier if I take my project for example from Visual Studio code to work on it inside Microsoft Visual Studio or C lion or any other IDE that supports cmake and C++ we have a few configuration presets configure presets that's what they are called in cake but if you go down you see that we also have build presets and these are going to be used in the build stage of your project project you can just use these I have here and then change your project later on if you happen to need more but I tried to really give you the basics one you need on each operating system so on Windows we will be using the compiler from Microsoft on Linux we will be using g++ and on Mac we will be using the clango compiler which is embedded in your clang tool set for C++ once we have this set up how do we build the project using preset well you go through the command pet so let's do view command pallet we can say cake select configure preset okay so this is what you will select here if you click it is going to read the configurations that you have in your CAC presets and you see that it has detected that we are on Windows and it is just going to give me the windows base preset if I select it notice things that are going to happen in my status bar here the configure preset is going to be set to Windows base and it is going to be picking up build presets it is going to pick up the clean build preset by default but I can change it so to select the build preset you can also do view command pette and say select World preset so can you can say select World preset I am going to select this here and it is going to give me a few options there is a clean build which is going to C clean and remove artifacts before you build your project but I am going to just select the veros build because I can do that notice that the veros build is going to be using ninja behind the scenes so make sure you have that and once you have selected a configure preset and the build preset as you can see in the status bar here you can just hit the build button so let's hit that this is going to kick off the build you see that the build finished with exit Code Zero which is a good sign that our build was successful and we can hit the Run button to start running the application you see that it is going to run and do whatever we want to do we can even debug the application the usual thing really let's set up a break point on line 23 and hit the debug button below here and if we do that we see that we have hit our breakpoint we can see the local variables we can hover over values to see things inside we can really do all kinds of crazy things we can even step step through things and this is going to work really fine cmake presets are going to make your life easy as a cmake C++ developer let's close our debugging session and open this project from Microsoft Visual Studio and show you that we can really do the same things here and have a nice experience with our project which is based on cake using presets so what I can do I can close off visual studio code here and open Microsoft Visual Studio and I am going to open a local folder again now I am going to go into sandbox and go to the location where I have the project that uses presets I am going to select the folder now you see that it can show me my build presets I can do a clean build I can do a rose build okay so I can use this things here and these are coming from my CAC preset file and this is really cool let's try to build the project we can do build and build all it is going to say that the build succeeded I can select the started item which is going to be the rooster executable I can run it it is going to do whatever we want to do in there and let's bring back our IDE go in the main CPP file maybe set up a break point inside of Visual Studio this is how you set up a break point and you can start debugging so debug start debugging and we are going to hit the break point and we can see the same information here I really want you to see the power of using zic it is easy to take your project from a visual studio code and build it in another IDE that support cake this is really Priceless as a C++ developer you don't want to be logged into any editor or Ide at this time a visual studio code happens to be good but nothing says that it is going to be still good or your best choice in two years ahead if a visual studio code goes away you can just use another IDE or you can even build your projects from the command line using zic but I don't want to go there because this is going to scare off a lot of people and I want you to really have a good experience with cake if you want to see that make sure to check out my cimx series and again I am going to link to that in the description below this is really all I had to share in this video showing you how cic presets are an option you can take the project I have on GitHub and use it as a starting point and modify it for example you can add your own classes you can do all kinds of crazy things in the last video I showed you that you can add new files to the project using CAC you just have to put in a few header files and then in the CAC list.txt file modify your add executable command to add those other files here for example if you have a person. CPP file added you can add it like this and it is going to be picked up by cake and used and this is really cool if you got any value out of this video please make sure to like share and subscribe let me know what you think in the comments below I am going to stop here guys and I will see you next time
Info
Channel: LearnQtGuide
Views: 775
Rating: undefined out of 5
Keywords: cmake, cplusplus, c++, cmake presets, build, run, debug
Id: 2nAoYarq_r4
Channel Id: undefined
Length: 16min 19sec (979 seconds)
Published: Sat Jan 20 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.