The most perfect tutorial on cmake and make. It rightly takes half of a video to build up to the requirement of the tool.
@muddyexport5639Ай бұрын
Used it and others w/ 42 yrs as programmer, analysry manager, director , and now, retired from code for a living to code for fun. It always was fun - they paid me to have fun!!!.
@lorinczhuff2022Ай бұрын
I know how to write C programs, but I've always had big training wheels. As I started to dig deeper, I've come across the term Cmake, but never had a clue what it was. Thank you for your clear introduction.
@markrobinson2648Ай бұрын
Long time C# developer but doing some c/c++ as a hobby. This is the best make/cmake introduction I have seen, thanks!
@bartdemeulmeester4662Ай бұрын
Thanks Gary, make was a bit of a mystery to me this really sorted it out.
@djpenton779Ай бұрын
Very useful, thanks! I have been retired for years now, but made my living as a software developer for decades. I wrote almost entirely in C, and worked on projects that required a lot of effort to construct and maintain the makefile. In recent years I began returned to programming as a hobby, including tinkering with MCUs. When I discovered that CMake is now a thing, I was quite daunted. Oh no - another meta level of build system to learn. So I avoided it. But I guess it's time to bite the bullet and learn it, because I have pretty much hit the limit with arduino IDE. So once again , thanks for this intro to CMake.
@toby9999Ай бұрын
I have been using C and C++ since the 90s and have never touched a make file. It's just such an archaic concept when we have automation tools. Can you imagine constructing a make file for a project with 10,000 files? Thing is, CMake is also pretty bad. I've literally spent days trying to get CMake working.
@GaryExplainsАй бұрын
@toby9999 Interesting comment. How did you build projects with 10,000 files without a build system?
@djpenton779Ай бұрын
@@GaryExplains My last job as a software guy was for a company in Calgary, Alberta. This was an ill-fated (an ill-conceived) effort to produce a message-passing based operating system, and ALL of the application layers on top of it, to implement large scale SCADA systems. I came to the company late in the game, and became something of a Cassandra because it quickly became obvious to me that the basic structure of the software was completely unworkable. (Imagine a software team of 20 people trying to implement linux, X11, the Chrome browser, and all the glue as one monolithic system. Nope....) IIRC, the software - from the lowest hardware level up - was built using make, and a dauntingly complicated makefile. Coding and maintaining this alone was a major effort. At that time in my career I had never heard of CMake, and don't actually know whether it existed. This build strategy was in microcosm representative of the project's design flaws, but was not its biggest flaw.
@frankleonhardt3337Ай бұрын
(Useful tip in last paragraph) I've been using make since System V but have wondered about cmake. This was a great explanation, as the man pages are, well, long and don't encourage reading. I'm not convinced, as make is quick to set up for small/medium projects (default rules). What's always been tricky (for over 40 years) is knowing what the dependencies are in order to define the rules! Clang/LLVM (and I think gcc) has the -M option that can list the dependencies in Makefile format, but not cmake. And it's not in the standard man page! Just run cc -M test.c (or whatever) and it'll list what goes in to making it. -MM is the same, but without header files.
@talideon21 күн бұрын
cmake is best compared to GNU Auto tools, mind.
@hiankunАй бұрын
All the great content are free and I have nothing to complain. But (sorry) this other than some AI stuff is what I have expected from Gary. Thank you for the effort. The explanation was crystal clear!
@nashaut7635Ай бұрын
👍 Fun fact: GNU make provides a (huge) set of default rules. If the executable is made of a single source file (not limited to C or C++) then you don't need a Makefile at all. Just run "make hellow". The executable base name must be that of the source file, it's the only requirement. More precisely, the executable name is derived from the source base name.
@rajmajumdar5253Ай бұрын
Wait what really?
@nashaut7635Ай бұрын
@@rajmajumdar5253 Yup. Just try it. Note that default flags will be used unless you pass them to make or via the environment. Example: `make CFLAGS=-Os -Wall hellow`.
@windysynth4 күн бұрын
I wish I had watched this first! My first look at cmake was to build opencv on widows--not for the faint of heart. This video gave me the overview I needed. Thanks so much!
@GaryExplains4 күн бұрын
I'm glad you found it helpful!
@mohitsethi35099 күн бұрын
THIS IS THE VIDEDO !!!! THIS IS IT.
@bertblankenstein3738Ай бұрын
In addition to not having to type and tell gcc to compile all the files by using make/cmake, you also avoid recompiling items that were not updated/touched since the last time they were compiled. This saves a lot of computer time and was probably more important in the good old days.
@HyyskanPolttajaАй бұрын
Thank you Gary. Please continue explaining Cmake further. BTW, the random example gives the same result every time. Even on my computer I get the same sequence [ 0.767554, 1.104780, 1.069596, 1.084488, 0.245279 ,0.580639, 0.292428, 1.135251, 0.902894, 0.226394 ] . Not very random... 😁
@GaryExplainsАй бұрын
As with all Pseudo-Random Number Generators (PRNGs), they just use a mathematical algorithms to generate numbers. Without providing a seed (which this program doesn't do) then they will always generate the same sequences.
@zorabixunАй бұрын
Gary, that is strange, why is that implemented if resulting the same effect 🙉 .. when i started computing on ZX81 it was very good random numbers generator, we were doing tests with colours, or symbols, Later on, i was using Atari 520 ST, and it was lighting fast with numbers never repeated .. I'm missing these computers, so romantic times, exciting and i was soooo happy to exchange software listings with friends to see results, testing days, and days, sorting programs, etc 🌞 On ATARI 520-ST compilers GFA-Basic ultra fast, objective, Pascal, Mark Williams C compiler with a system like Linux .. Thanks 🎉
@GaryExplainsАй бұрын
The program isn't the important thing here, but the build system. As I mentioned to the OP, a seed needs to be provided to every PRNG. On many systems (but not all) the seed is automatically set on the first call to get a random number, the seed is often based on the current time and therefore different every time the program runs.
@rmfeldАй бұрын
@@zorabixun It can sometimes be helpful to generate a random but repeatable sequence of numbers to have the same conditions on every run. Therefore delivering the seed to the random number generator is an extra and depending on your application optional step.
@ElectronicFanArmАй бұрын
Loved this thanks Gary for sharing ❤
@GaryExplainsАй бұрын
Glad you enjoyed it
@RocktCityTimАй бұрын
Thanks, Gary. This is outstanding - this saves me days of explaining CMake for new hires. How about a similar look at the GNU autotools? There are still loads of projects using them.
@philb1466Ай бұрын
As an absolute beginner this video was very useful and informative! Thank you!
@GaryExplainsАй бұрын
Glad it was helpful!
@drfrancintoshАй бұрын
wonderful video! I really need an introduction to CMAKE… I do think you glossed over the biggest feature of make and make files… And that is it understands when a file has been touched or modified and only compiles the things it needs to in order to generate the output… It does this by comparing the timestamps on the file modification time… Great video I've been long time subscriber your explainers are the best keep doing what you're doing! And continue to success!
@OmidAtaollahiАй бұрын
watched a few times. enjoyed the simpilicity and clarity in your tutorials.❤❤ It feels good learning with gary
@GaryExplainsАй бұрын
Awesome! Thank you!
@gregholloway2656Ай бұрын
Great video Gary, it is appreciated! If you make a followup video, could you explain a little about what those other cmake files are in the build directory? And of course, a bit more about the options in the CMakeLists.txt file. 👍
@djsbriscoeАй бұрын
Thanks. Could you do a similar beginners guide to setting up your first github/gitlab project on a home network NAS or local hard drive? Or maybe you've already covered this?
@interweb340121 күн бұрын
Perfect explanation for beginners.
@jonathandawson3091Ай бұрын
Despite having used cmake many times, I learnt a few things. For example I did not even know CMake is for Crossplatform Make. Also the examples for more complicated Makefile were top notch where the interested person could look up or just understand looking at it (e.g. %.o: %.c). Absolutely amazing video, always so pleasant to watch Gary's videos.
@robby3467Ай бұрын
That's mostly how we use it... to create project files for MS Visual Studio when importing an open source library. But it sucks. It does an awful job of it, and that's only with a lot of luck. Mostly it just fails with errors. And as I commented somewhere else, it always fills the source tree with absolute paths. Terrible idea. The documentation is also shocking.
@jonathandawson3091Ай бұрын
@@robby3467 Yeah. CMakeLists.txt name is also weird. I still don't know what PRIVATE does. Things like add dependencies are given after add_executable which is weird. I think it grew out of some person who just hacked something quickly to suit his needs. I don't think it's the best, but unfortunately it has become standard. Maybe the best way to dethrone it is to go one step up and now make a CMakeLists.txt generator with a saner syntax.
@roysigurdkarlsbakk3842Ай бұрын
Very nice - thanks!
@RoboticsDIYАй бұрын
Thank you, this video is very much appreciated. I have some programming background - I learnt Borland Pascal in school and in first course at university... have done a tiny bit of PHP and JavaScript, some small projects on Arduino. But since I moved to work in UK... I have in a way wasted 10 years doing manual labour jobs. I want to move back to electronics and programming, I'm slowly working on starting my KZbin channel. I have wanted to learn C/C++ and need it for electronics projects, and especially now with Raspberry, I have to learn how to compile programs from source on Linux. So I have heard about GCC, have some rough idea about it all, but this video is a conspectus of how to say - missing peaces to link it all together.
@bertblankenstein3738Ай бұрын
Thank you. This is good info. I can compile basic projects, and used make 30 y ago and have forgotten the bit I knew then. This will certainly help.
@dabdoube92Ай бұрын
I love this back to basics series. Gary is great again !
@jecelassumpcaojr890Ай бұрын
A key difference between a build system like make and a shell script is what you illustrated at the end by deleting a few lines from "random.h": make compares the dates of any files it knows how to generate with the dates of the files that depends on and only runs the rules if the generated file is older. A shell script would run all the rules every time. Some viewers might have missed that when you edited "random.h" make ran the rules to generate "random.o" and "main" but not the rule to generate "main.o" since that was newer than "main.c"
@henrikoldcornАй бұрын
This video seems to be approaching optimum for explaining these tools! Good length, depth and clarity, like a glass dild… Seriously though, it’s great.
@animalshorts4377Ай бұрын
Thank you!
@GaryExplainsАй бұрын
You're welcome!
@kev2020-z9sАй бұрын
Thank you for your excellent explanation keep up the great work.
@GaryExplainsАй бұрын
Glad it was helpful!
@NotMarkKnopflerАй бұрын
This is very useful. Is CMAKE installed on Linux by default or do we need to download it? 👍
@ColaholikerАй бұрын
That likely depends on the distribution you are using. But if it isn't installed yet and you use anything that traces back to Debian, a sudo apt install cmake will fix that for you. I would think that pretty much any modern distribution at least has it available in their repository.
@andrew121410Ай бұрын
Thank you, I was always confused about the difference between GCC & Make & CMake but this explains everything. I do hope one day C & C++ will get a default package manager like with Java you have maven and gradle so easy to use both.
@GaryExplainsАй бұрын
Glad it was helpful!
@toby9999Ай бұрын
I use MS Visual Studio on Windows 99.9999% of the time. It does all of that stuff for you and way more. It even integrates Clang / LLVM for those who don't like MSVC. If you rename a file or add a file, it'll automatically handle that, etc.
@sumitkamble_10 күн бұрын
clean and clear explanation
@GaryExplains10 күн бұрын
Glad you found it helpful!
@andrewgrant788Ай бұрын
Ninja is the way to go with CMake. It works on Windows and MacOS as well as Linux.
@ezrakoperАй бұрын
Thanks. Very useful
@mohsenzare251129 күн бұрын
Nice video! consider also go to more advance stuff about cmake! like variables or if statement and ...
@cdkslakkend5742Ай бұрын
You see, this is what makes Linux interesting as opposed to the other OS's and their tools. At least, you can then go to another level and start looking at other types of source files that make up smaller linux programs and learn how the build process proceeds so that installing from source has a more meaningful impact in terms of comprehension.
@GaryExplainsАй бұрын
I get your point and I agree, but technically it isn't Linux that makes this possible, but open source in general. For example, you can look at and compile and install htop on macOS or FreeBSD.
@karolkotula927915 күн бұрын
Thanks Gary for great tutorial :) Small contribution from myself: if you want to use cmake for your Visual Studio compiler, then: 1. cmake in your build_vs subdirectory, with command: cmake -G "Visual Studio 17 2022" .. 2. build created solution with msbuild: MSBuild.exe hellow.sln -p:Configuration=Release
@bookappointmenioАй бұрын
Thank you well explained 💌
@grahamm7408Ай бұрын
Awesome intro! Next stop, the Linux kernel 😅
@behrampatel4872Ай бұрын
This is such an approachable tutorial. Thank you for Making this ;) Edit 01 - This is probably the best C-make for beginners tutorial out there. Full stop. End Edit 01 I had one question. Just like random.h which needs to be compiled , the Math.h is also a header file. So why did we need to link against that instead of also compiling that header ? Thanks,
@GaryExplainsАй бұрын
The functions defined on math.h are not part of the standard C library, so you need to link again libm explicitly. So I am not linking against the header but to the library that has the functions defined in the header.
@behrampatel4872Ай бұрын
@@GaryExplains got it. Thanks for the clarification. Just FYI i'm here because I want to integrate a plugin for Unreal Engine . Specifically to integrate a recent version of OpenCV. All documentation & videos on the topic are years old so it's become difficult. So this kind of knowledge (building from source, DLL etc ) is very essential. Thanks and god speed.
@harrypehkonenАй бұрын
This morning, I bumped into CMake and started looking into learning enough about it to be able to use it, but then I was distracted by the build system for Zig.
@manishgautam2424Ай бұрын
loves to see it
@dragonfly-7Ай бұрын
Hey Gary, thanks for your great contribution ! One question: In the video you did mention several times Visual Studio but you did not explicitly mention "Visual Studio Code" or vscode. What about this environment ?
@nameless5724Ай бұрын
Thank You for sharing.
@tushar8133Ай бұрын
Excellent!
@alexwright6038Ай бұрын
Thank you, a good starting point for a beginner. I learnt to use Borland Turbo Pascal, that was my language of choice. I mainly work with hardware, I need to get more used to software tools. Do you gave an example of using VS code to program a pi pico in C/c++?
@byronwatkins2565Ай бұрын
How do we organize larger projects? Most projects have trees of directories filled with files and a single config/make sequence to compile them all.
@toby9999Ай бұрын
One of the projects I work on has 6000 folders and 90,000 files. There's no way I'd be using a toy-like utility like CMake for that, and we don't.
@ColaholikerАй бұрын
The way i do it is to setup directories for everything that makes sense to go together, and then each directory gets its own CMakeLists.txt to build a library out of these files, and the main CMakeLists.txt includes all the directories ti get those files to be active and links the libraries I have created. (I do embedded work, we can't have dynamic/shared libraries, all needs to be statically linked)
@negart774426 күн бұрын
Thanks for tge video. I wanna use cmake for cmocka.
@grimvian18 күн бұрын
Interesting but with my clumsy fingers and weird dyslectic issues I'm using an IDE with all the settings I need. I never understood why many prefer to write instead of clicking on a button. I'm also using pragma once.
@mohitsethi-w7k9 күн бұрын
FOLKS THIS IS THE VIDEO, DONT GO SEARCHING ANYMORE.
@XentheraАй бұрын
Nice Rush video length
@gurusunu1105Ай бұрын
Thanks 👍
@guilherme5094Ай бұрын
👍👍Thanks sir!
@An.IndividualАй бұрын
How do you get around the fact that we didn't create random.h in the 2nd demo?
@GaryExplainsАй бұрын
I don't understand. What do you mean?
@An.IndividualАй бұрын
@@GaryExplains 2:44 2nd line is #include "random.h" so the compiler will try to open a file called random.h which we didn't create ?
@GaryExplainsАй бұрын
I did create it, I just didn't show it. It is the same random.h file I show later in the video.
@negart774426 күн бұрын
@4:25 thanks for the video ❤ why don't we have math.o same as other two. Why is it -lm? What makes math lib and random lib different?
@GaryExplains26 күн бұрын
Random lib is made by us, math lib is provided by the system.
@svenvandevelde1Ай бұрын
Thank you
@GaryExplainsАй бұрын
You're welcome
@mahmoud173726 күн бұрын
what about zig and opinion on as a c compiler drop in replacement
@GaryExplains26 күн бұрын
I did a video on that.
@abiuniverseАй бұрын
Does it also work with Fortran
@JamesTJosephАй бұрын
The best book to learn CMake is “Professional CMake by Craig Scott”.
@robby3467Ай бұрын
"Professional" and "CMake" should never go together is one sentence :)
@JamesTJosephАй бұрын
@@robby3467 apparently it is the best book with free new editions 😌
@talideon21 күн бұрын
@@robby3467Better than Autotools hell though, however bad the CMake language itself is. I'd use Meson for builds if I could, if only because it's less crufty.
@simonbooth4888Ай бұрын
No external library linking explanation which is the most confusing bit when using third patry add-ons. i.e. need a follow up
@GaryExplainsАй бұрын
External library like libm?
@simonbooth4888Ай бұрын
@@GaryExplains External libraries like display drivers on a pico
@talideon21 күн бұрын
@@simonbooth4888That's a matter of how those third party libraries are installed as part of the project. If the complier doesn't need -I and -L to find the headers and library binaries, it's no different from linking to libm. If they provide pkg-config files, there's find_package(PkgConfig), which gives you the pkg_check_modules(...) command to discover the paths and compile flags. If cmake knows about the library in question, it has other ways (I'm typing on a phone, so can't recall the commands off the top of my head). If it's a vendored library, then your root CMakeLists.txt should pull in the vendored library as another target. Dealing with vendored libraries is really something that would be covered as part of a video on project organisation, though.
@talideon21 күн бұрын
If you want a more in depth explanation, "Modern CMake with C++" is a good choice.
@irlshrekАй бұрын
I went Rust and never looked back
@robby3467Ай бұрын
I tried Rust and I did look back.
@fdfgsaАй бұрын
CMake is one of the reasons I now use Rust
@robby3467Ай бұрын
CMake sucks, right? We found it always filled the source tree with absolute paths. There should be a way to create relative paths but could never find anything that worked.
@4k1ra-f9yАй бұрын
I'm so confused how cmake work on raspberry pi pico
@h_pranav_nayakАй бұрын
It doesn't "work" on the pico You cross compile code on your PC and then flash the binaries on the pico
@4k1ra-f9yАй бұрын
@@h_pranav_nayak its working when I trying flash the led, but I'm so confused how to setup cmakelist.txt for my environment, actually i want someone teaching how cmakelist.txt work on raspberry pi pico, how to setup the directory, i have many of problem how to setup the lib on cmakelist...I ready done to add lib on cmakelist code, but when try to running, the error showing "lib not found", and i try search use "locate lib" it shows the existence of the library
@fuzzyheadedfreak9 күн бұрын
Why numbers not random?
@GaryExplains9 күн бұрын
It is a pseudo random number generator. All pseudo random number generators create the same sequence until the "seed" is changed.
@fuzzyheadedfreak8 күн бұрын
@@GaryExplains Groovy, thanks.
@BangkokBubonagliaАй бұрын
Thanks for this series Gary. A request. Please do a video on how to control all the make flags using cmake. For instance, I hate that cmake always hides the real gcc compile commands. I absolutely loathe that. I want to see the 1000 character long actual gcc commands as they are executed. How do I force cmake NOT to hide that?. It builds this complex structure of hierarchical Makefiles, and I never know how any code is actually being built. The options to cmake are where all the utility lies. As someone who grew up on make, it is incredibly frustrating not to be able to see what is happening when I compile a project.
@ColaholikerАй бұрын
There is an option to control CMake's verbosity (and of course the verbosity of the output it produces. I don't remember what it is, as I only tried it once and didn't really see the benefit over a mostly silent build that only shows warnings and errors (or in my usual project setup only errors since I treat warnings as errors and set my compiler to nag a lot). I found it easily when I googled for it. So if you prefer to see tons of text scroll by, CMake has got you covered. 😉 I am not saying that either of the two is better, I think this is mostly a matter of personal preference.
@mikechappell4156Ай бұрын
What was random.h? You included it, but never showed it.
@GaryExplainsАй бұрын
I do show it, but later in the video when I demonstrate what the build system does when you change a files it is just a declaration for the random function. 1 line of code.
@mikechappell4156Ай бұрын
@@GaryExplains Thanks. I saw when I finished the video. I just initially got the compile error for the missing file, but it was easy enough to dummy something in until you exposed it.
@michelealessandrini3421Ай бұрын
Can you possibly cram more ads in your videos?
@GaryExplainsАй бұрын
Eh? I don't cram in the ads, Google does that and it is automatic. Yes, I enable ads, but after that it is all Google, not me.
@michelealessandrini3421Ай бұрын
@@GaryExplains I had to see a dozen ads in a 20 min video, stopping every couple of minutes, ok that you deserve a revenue for your work, but over a certain limit I'm no longer motivated in following a youtuber.
@GaryExplainsАй бұрын
I understand. But as I said it is Google that picks how many ads are shown and where. Not me. Remember that Google gets a much larger fraction of the advert revenue than the video creator. Your beef is with Google, not me.
@weiSaneАй бұрын
Cmake is such a pathetic messy build tool. No wonder a lot of beginners get overwhelmed when trying to learn C++ and they just go for much more newer better fleshed out languages with far much better build tools. We have to be thankful though because the languages that came after learned from mistakes made by the earlier ones.
@tushar8133Ай бұрын
fatal error: 'random.h' file not found I have main.c and random.c in the directory Ether I run this command - gcc -c main.c Or this command - gcc -o main main.c random.c -lm Both are giving same error.
@GaryExplainsАй бұрын
You need random.h as well. I show it at one point in the video. It is just a header for that random function.
@jussiheinoАй бұрын
I will unsubscribe if you don't change the "demo"-intermission jingle! I would be deaf if wearing headphones. Super loud on my laptop speakers. Otherwise, good cover of basics! liked!
@toby9999Ай бұрын
Sorry to be so blunt, but CMake is an absolute piece of garbage (in my opinion). I've spent too many hours, if not days, tearing my hair out or turning it grey, trying to beat CMake into submission. Worst piece of build tooling I've had the misfortune of meeting in over 25 years of software development. It never works out of the box. It's a piece of crap. Even watching this video... I feel the stress. Sorry, but I just had to vent. Is this really the best the open source community can do? It's still an archaic process. This is 2024. That said, you provided a nice overview.
@andrewgrant788Ай бұрын
Don’t agree at all. CMake is an excellent build tool compared to alternatives like GNU autotools. The CMake team works with the major C++ compiler teams and Microsoft’s cross platform tools in Visual Studio rely on CMake. They also have a package manager vcpkg which integrates with CMake. That said, in my view the best IDE for working with CMake is CLion from JetBrains. If you wish to avoid hair loss it is the best option, the integrated CMake debugger is excellent.
@var67Ай бұрын
What's the alternative, do you use Meson? Can you give a specific example where Meson, or another system, works better for you than Cmake? (I have no experience with Meson and not much with Cmake.)
@arkeynserhayn8370Ай бұрын
Can you please provide reasons of why you think this way? For one i see people complain about it's scripting sytanx, and even while its true, it's not a huge deal for me; what else do you think is wrong with cmake?
@talideon21 күн бұрын
You haven't been subjected to the hell that is GNU Autotools, then?