How to CMake Good - 0c - Using Visual Studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome to how to seem a good part zero see that's right we're back to zero because we're talking about something a little different today so far all of my work has been done on my Linux box but Windows users are important too so I'm going to show you how you can use C make with Visual Studio and there's actually two different ways of doing that you can use Visual Studio with a solution file or you can open the C make directory directly in Visual Studio I have a project that's already using C make right here and I want to generate a build for it using Visual Studio so I'm going to open up a command window and change into that directory just like on Linux we're gonna make der bilt when changing to build and I'm going to use the C make command line to generate a visual studio project since I already have Visual Studio installed I can just invoke C make regularly and it'll know to generate a visual studio solution now you can see it's generating a solution for Visual Studio 15 2017 15 is the actual version number of this Visual Studio 2017 release here it's using the CL compiler exactly as we expected to if I open up my file at browser and I go to build we can see the generated Visual Studio files the one you'll want to open will be the main dot SLN I'll double click on that and it'll launch Visual Studio 2017 Community Edition CMake generates a visual studio solution where each target is a different sub project if I expand a target I can see its header files source files and the cmakelists dot txt that generated that target all the source files associated with the target are in here but no other source files are this is why you should list all your header files and source files associated with a target so that's IDs are able to recognize that a source file belongs to a target and it'll be visible in the project's outline view we can right click on a project and say build to build the project this will build the target associated with that project and all targets that it depends on here's our build we can see it compiled files and then it succeeds at the very beginning it runs a special project called zero check this is the project that will check if C makes configuration data is out of date and it needs to regenerate the Visual Studio project all projects will depend on this zero check project you can also build the zero check project yourself to manually regenerate the configuration from within visual studio without having to build any projects now that it's compiled the project we can now run as executable by right-clicking on it clicking set a start up project and then starting the debugger it'll ask us to build it you might want to check the do not show this dialogue again button so that it will automatically rebuild relevant targets when you need to debug them I'll say yes for now it's compiling the executable it launches it in the debugger and it's done that's a pretty simple executable let's expand its main file and set a breakpoint here we are in the debugger debugging our CMake target you may know that CMake generates a variety of build types appear there's a small drop-down which includes the build types that see make is generated for us if I go back to simple data CPP and I make a special block like this visual studio will automatically colorize this block section but it's disabled if I change the build mode to release Visual Studio has recolor as this block because as it is now disabled by the release mode note that I did not have to rerun see make to change the build type Visual Studio solutions already know about all of the build types C make was not rerun when I changed the build type C make just generated a project which contains all of the information needed to build all of the builds all in a single pass this is different from make files or ninja files where you need to rerun C make to change the type of build this is called a multi comp generator and will delve into those a little more in a later video if I go to the file explorer will see a directory called examples and the subdirectory called debug this is where Visual Studio generated the executable that I just ran it's generated in a subdirectory called debug because Visual Studio allows us to build the release mode within the same build tree I've set the build up to release and if I run the build and then I go back to the file explorer it's now created a release directory with another simple exe in it this way you can have both debug and release executables side by side and switch between them quickly now I'll show you how to build this project from the command line I'll say clean solution and it will remove all of the built files now close visual studio and go back to the command line our project is still there and we can still build it using C make C make - - build dot and then we say what configuration we want to build - - config debug Sameach will run the underlying msbuild build tool in order to build this visual studio solution C make natively understands how to drive MS build to build it's generated projects this means you can use Visual Studio solutions without even having an installation of Visual Studio present the visual c++ build tools are sufficient to generate and build Visual Studio solutions without having the actual IDE installed you can also build specific targets by using the - - target flag I'll build the simple target that we built from Visual Studio you can see it ran the build for the single target it was already up to date so if we changed the configuration to release it'll actually rerun the build it's only compiling the needed targets that are necessary to produce the target I asked for and now we'll do something a little bit special we don't even need to generate a visual studio solution to use Visual Studio then my build directory I'll clear it all out I'll go to my source directory right click and say open in Visual Studio Visual Studio detects the C make lists txt and is able to open it natively without any special commands needing to be run it shows us the file system structure in the solution Explorer as if it had generated a real solution in the C make output we can see that it ran C make for us and generated a new build directory in a temporary path it also generated for ninja which is a very very special tool that I'm going to get into in another video it also used an embedded version of C make this contains some special patches from the visual studio developers to support visual studio in this way that's all I wanted to show for now check the video description for any addenda errata important links or extra information in the next video I'll show how you can use visual c++ without using Visual Studio or MS build until next time keep see making good
Info
Channel: vector-of-bool
Views: 36,119
Rating: 4.7796144 out of 5
Keywords: cmake, visual studio, tutorial, windows
Id: 6aiV7Z9NRhk
Channel Id: undefined
Length: 7min 30sec (450 seconds)
Published: Sun Aug 12 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.