Simplified CMake Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 มิ.ย. 2024
  • CMake is a complex beast and hopefully I make it simple and easy to understand in this tutorial while also utilizing somewhat Modern CMake features. There's a ton of different ways to do things so it's crucial to ditch some of the more outdated ways of doing things.
    You can follow along here: codevion.github.io/#!cpp/cmak...
    My C++ setup for CMake here: • Setting up (Neo)vim fo...
    #build #modern #cmake #cpp
    Quicklinks:
    00:00 - Intro
    00:43 - Hello World
    03:55 - Clearing up clutter
    04:47 - Vim plugin
    06:05 - Header files
    09:53 - More source files
    13:52 - Custom Library
    17:30 - Depending on a CMake ready lib
    21:10 - Depending on a lib manually
    26:46 - CPM
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 113

  • @honey_sukesan
    @honey_sukesan 4 หลายเดือนก่อน +4

    This is a great, simplified CMake tutorial. Highly recommended for all C++ developers who need to get a flavour of CMake in half an hour.

  • @Gornius
    @Gornius 2 ปีที่แล้ว +17

    Simple, quick, knowledge-packed, easy to understand and to follow tutorial. I went from complete magic to understanding CMakeLists in 30 minutes! Thanks a lot!

  • @iLeno
    @iLeno 2 ปีที่แล้ว +8

    This is the best video on C++ by far, every other people just run into coding, but no one actually takes the time to explain how to compile and automate the compilation of your projects. Very well done.

  • @gabrielgardin2592
    @gabrielgardin2592 3 ปีที่แล้ว +33

    Very loud keyboard. But great video!

    • @hotmandead1
      @hotmandead1 2 ปีที่แล้ว +4

      True mechanical

    • @polisbaba
      @polisbaba 2 ปีที่แล้ว +1

      @@hotmandead1 What is your keyboard?

    • @hotmandead1
      @hotmandead1 2 ปีที่แล้ว +1

      @@polisbaba keychron Q1

    • @raulcardona.
      @raulcardona. 2 ปีที่แล้ว +2

      Amazing video! Love the keyboard ASMR

  • @TheHenkrik
    @TheHenkrik 2 ปีที่แล้ว

    Really, really good tutorial! Great explanations, easy-to-follow and yet you still manage to add enough detail that one can imagine how to begin to scale this up beyond simple "hello world"-style projects. Thank you.

  • @ankit14245
    @ankit14245 3 ปีที่แล้ว +39

    This is the best CMake tutorial and the best part it is in Linux. Waiting for the next parts eagerly. It would be great, if you create content on - creating subdirectories using CMake, git, CDash and CTest.

  • @everett7903
    @everett7903 3 ปีที่แล้ว +6

    I concur with what most people are saying, this is definitely a good introduction and directly applicable to a project I'm working on at work.

  • @user-qw4vi2wm8w
    @user-qw4vi2wm8w 3 หลายเดือนก่อน

    Perfect tutorial! You cover all the stuff a programmer wants to know in a very short and clear manner.

  • @peacemode2574
    @peacemode2574 2 ปีที่แล้ว +2

    Best tutorial of Cmake for beginners on YT I'm not exaggerating.

  • @ancientstraits9288
    @ancientstraits9288 2 ปีที่แล้ว

    I still come back to this tutorial whenever I have to setup a new CMake project.

  • @StannyObelisk
    @StannyObelisk 3 ปีที่แล้ว +2

    This is scrumptious. Thank you :)

  • @pooriaheidary6204
    @pooriaheidary6204 2 ปีที่แล้ว

    By far, The most fluent cmake tutorial on youtube.

  • @Roule_n_Scratche
    @Roule_n_Scratche 2 ปีที่แล้ว

    Thanks for putting chapters, its very useful

  • @simonedeangelis
    @simonedeangelis 2 ปีที่แล้ว

    Really amazing video! so clear! thank you so much!

  • @lahianmoronta8698
    @lahianmoronta8698 2 ปีที่แล้ว

    Okay this is actually really helpfull. just added a project name to a txt file that didn't work but now it does, does take a bit before you understand but its actually pretty easy.

  • @mala235813
    @mala235813 3 ปีที่แล้ว

    Thank you! Excellent tutorial.

  • @amitozazad1584
    @amitozazad1584 3 ปีที่แล้ว +1

    Great explanation!

  • @liminal6823
    @liminal6823 2 ปีที่แล้ว

    Excellent tutorial. Thanks.

  • @Franfran722
    @Franfran722 ปีที่แล้ว

    Thé only cmake tutorial that really helped me

  • @hts2425
    @hts2425 2 ปีที่แล้ว

    very good explanations, thanks so much

  • @prasobhprakasan5921
    @prasobhprakasan5921 2 ปีที่แล้ว +1

    Thank you very much for the knowledge

  • @tunacici
    @tunacici ปีที่แล้ว

    Thanks for amazing video. Helped a lot

  • @DjSt3rios
    @DjSt3rios ปีที่แล้ว

    Great video, thank you so much for sharing your knowledge! You got a new sub 🙂

  • @lucasrodrigues9766
    @lucasrodrigues9766 ปีที่แล้ว

    The best tutorial, thanks.

  • @alexandriati9060
    @alexandriati9060 3 ปีที่แล้ว

    Very nice tutorial

  • @why1978
    @why1978 2 ปีที่แล้ว

    Excellent tutorial , keep those keys clicking

  • @andychess
    @andychess ปีที่แล้ว

    Excellent video thank you very much!

  •  3 ปีที่แล้ว

    Thank you for sharing.

  • @newsgo1876
    @newsgo1876 ปีที่แล้ว

    Thank you so much!!! Finally I can understand the CMake rather than call it fxxking-but-cant-get-rid-of magic.

  • @kirkpennock2997
    @kirkpennock2997 ปีที่แล้ว

    One thing, cmake seems to have alot of variables that are not defined but are availible to use, like your example of the SFML, where do you find those ${SFML_LIBRARIES} name and ${SFML_DEPENDENCIES}?

  • @xxbomelxx874
    @xxbomelxx874 ปีที่แล้ว

    WTF, why is this better that than the original c++ tutorial?? 😅

  • @shrikant_paliwal
    @shrikant_paliwal 2 ปีที่แล้ว

    Best Video Thanks man !

  • @duvvuindirapriya9052
    @duvvuindirapriya9052 6 หลายเดือนก่อน

    You are Demi God to me 😭😭😭. Thankyou for this awesome Content. Will you able to do more content like this for helping people around.

  • @ihebmzoughi4841
    @ihebmzoughi4841 2 ปีที่แล้ว

    the best

  • @herbertwestiron
    @herbertwestiron 3 ปีที่แล้ว

    Thanks for the tutorial. Helped me alot!

  • @saurabhpradhan1069
    @saurabhpradhan1069 2 ปีที่แล้ว

    Love the key board sound. Great content.

  • @Jedlmind
    @Jedlmind 2 ปีที่แล้ว

    Thank you!

  • @canerbaba387
    @canerbaba387 2 ปีที่แล้ว

    thanks for the tutorial. how is it possible to add header files to the project as well as source files?

    • @kandodev
      @kandodev  2 ปีที่แล้ว +1

      Just target_include_directories to add further include dirs for your target.

  • @Engineer2261
    @Engineer2261 ปีที่แล้ว

    I have target_sources in my example cmake file whereas you use add_executable. Which one is recommended?

  • @ANOCEANGROUND
    @ANOCEANGROUND ปีที่แล้ว

    The flow was spot on. At last I can now feel comfortable with cMake. Sir, you just earned my subscription. I tip my hat to you.

  • @Master-yn6ie
    @Master-yn6ie 3 ปีที่แล้ว

    Nice, can't wait for the next episode in the series.

  • @michaelmueller9635
    @michaelmueller9635 3 ปีที่แล้ว

    thx, this is useful

  • @malusmundus-9605
    @malusmundus-9605 2 ปีที่แล้ว

    I love you. Thank you.

  • @godDIEmanLIVE
    @godDIEmanLIVE 2 ปีที่แล้ว +1

    Great work man. Really got me started. One tip: don't use custom vim mappings in tutorials. Took me a while to got my bash-script running, because I was a bit confused on where cmake --build should be run and how etc.

  • @sonyerric2
    @sonyerric2 2 ปีที่แล้ว +1

    what is the command that clears up the clutter at 4:11 ?

  • @gurunadhan2666
    @gurunadhan2666 ปีที่แล้ว

    Amazing

  • @07ucs051
    @07ucs051 2 ปีที่แล้ว

    I am stuck with this error when I try to use find_package() for SFML.
    By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
    asked CMake to find a package configuration file provided by "SFML", but
    CMake did not find one.
    Could not find a package configuration file provided by "SFML" (requested
    version 2) with any of the following names:
    SFMLConfig.cmake
    sfml-config.cmake
    Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
    "SFML_DIR" to a directory containing one of the above files. If "SFML"
    provides a separate development package or SDK, be sure it has been
    installed.
    What should I do next? In which files I should make changes?
    It would be very much helpful if you could help me with this error. I am using Deb(Ubuntu).

  • @Kay-bm3xs
    @Kay-bm3xs 3 ปีที่แล้ว +3

    I think it's a great video but I can't follow your commands at all if I'm new to all this stuff.

  • @lainarte
    @lainarte 2 ปีที่แล้ว

    coc still gives me an error when I #include "headerfile", but I can make it and the executable works fine. How can I remove the errors from nvim?
    EDIT: By installing the vim-cmake plugin everything started working.

  • @fran12659
    @fran12659 ปีที่แล้ว

    very nice video thanks for sharing.
    PS: Your keyboard is quite loud for the voice volume.

  • @sadashivsahoo
    @sadashivsahoo 3 ปีที่แล้ว

    Hi
    How to find atlas(automatically tuned linear algebra software) in cmake v3.19

  • @noiseflow4306
    @noiseflow4306 ปีที่แล้ว

    fucking amazing my guy

  • @lifeless9768
    @lifeless9768 3 ปีที่แล้ว

    Thank you so much!

  • @mrqwakgames
    @mrqwakgames ปีที่แล้ว

    Where's the donate button to get this guy a quiet keyboard?! ;)

    • @mrqwakgames
      @mrqwakgames ปีที่แล้ว

      (great tutorial btw)

  • @testforcomment
    @testforcomment 2 ปีที่แล้ว

    good CMake tutorial and it looks you are an i3wm user.
    but have several off-topic questions.
    Question0. what is the tool you are using to play the slide? during the whole tutorial
    Question1. how did you configure your shell to add an underscore to the file name like dot(.) and CMakeList.txt th-cam.com/video/mKZ-i-UfGgQ/w-d-xo.html
    Question2. what is the plugin of vim support offset display in the left gutter? th-cam.com/video/mKZ-i-UfGgQ/w-d-xo.html
    Question3. what is the plugin doing the [Indexing 50% 1/2] at the left bottom corner th-cam.com/video/mKZ-i-UfGgQ/w-d-xo.html
    Question4. what is the plugin for marking the error line based on build command output? th-cam.com/video/mKZ-i-UfGgQ/w-d-xo.html

    • @kandodev
      @kandodev  2 ปีที่แล้ว

      Hey,
      0: marp (I'll have a small video on it soon)
      1: Provided automatically by github.com/sorin-ionescu/prezto (might be my p10k theme? I'm actually not sure on that)
      3,4,5: all of these done by CoC. I have a tutorial series on this: th-cam.com/video/ViHgyApE9zM/w-d-xo.html& (although I'm working on an updated one with neovim lsp instead)

  • @yashmanwani6232
    @yashmanwani6232 2 ปีที่แล้ว

    I wish you covered how to make separate debug and release executables with cmake.

    • @kandodev
      @kandodev  2 ปีที่แล้ว +2

      I’m planning an advanced/modern use video for cmake!

    • @yashmanwani6232
      @yashmanwani6232 2 ปีที่แล้ว

      @@kandodev thanks

    • @maxmccord9883
      @maxmccord9883 5 หลายเดือนก่อน

      @@kandodev are you still planning an advanced video? 😇 your video was extremely helpful to me and I'd love to see more!

  • @Antagon666
    @Antagon666 ปีที่แล้ว +1

    Jesus, your fingers just fly on the keyboard.

  • @chandusai3120
    @chandusai3120 ปีที่แล้ว

    No CMAKE_CXX_COMPILER could be found.
    Tell CMake where to find the compiler by setting either the environment
    variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
    to the compiler, or to the compiler name if it is in the PATH.
    this error i got how to resolve

    • @Canoxix
      @Canoxix 4 หลายเดือนก่อน

      'build-essentials' package

  • @moeenkamali1288
    @moeenkamali1288 4 หลายเดือนก่อน

    please give me model of keyboard you are using :)

  • @itsnotallrainbowsandunicor1505
    @itsnotallrainbowsandunicor1505 2 ปีที่แล้ว

    Hmm, I am using ubuntu and the part @4:27 with cmake ../ did not work for me.

  • @antonfernando8409
    @antonfernando8409 2 ปีที่แล้ว

    cool

  • @helium73
    @helium73 2 หลายเดือนก่อน

    I'm able to make Makefiles that work but not with cmake. When I tried using cmake it generated a huge ugly makefile that didn't work.

  • @miaomiao1415
    @miaomiao1415 3 ปีที่แล้ว

    only thanks can I say

  • @mxolisixulu8035
    @mxolisixulu8035 ปีที่แล้ว

    Thst's why he's gettin paid for it

  • @user-bo6ht7bl1b
    @user-bo6ht7bl1b 8 หลายเดือนก่อน

    please
    Desktop environment name?

  • @Ruddens
    @Ruddens 3 ปีที่แล้ว

    nice tutorial , i find cmake is not too difficute

  • @ratgirlflora
    @ratgirlflora ปีที่แล้ว

    28 minutes im going to literally turn into a fish

  • @zitronenfresser7089
    @zitronenfresser7089 2 ปีที่แล้ว

    Unfortunately your vim plugin does not work and i have no idea why

  • @ManuelGx2
    @ManuelGx2 2 ปีที่แล้ว

    Scared me at 9:14

  • @dynamicgecko1213
    @dynamicgecko1213 2 ปีที่แล้ว

    Very informative and well-structured video. Your keyboard and breathing sounds are very distracting sometimes though.

  • @jackier8266
    @jackier8266 2 ปีที่แล้ว +1

    Nice tutorial. But the speed of command typing is too fast for new users.

  • @yarin1
    @yarin1 3 ปีที่แล้ว

    wow!

  • @edinetgrunhed6000
    @edinetgrunhed6000 ปีที่แล้ว

    how to implement in windows?

    • @kandodev
      @kandodev  ปีที่แล้ว

      Best way to just use WSL in windows and follow the unix path.

  • @kandodev
    @kandodev  3 ปีที่แล้ว +3

    One important thing I missed. Please add a CONFIGURE_DEPENDS flag to the recursive glob so that it looks like: file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp). This is necessary to make sure CMake regenerates the list of files every time. (Not as efficient but beats listing source files manually!) Note that you should also bump up the min version to 3.12 when this flag was added.
    Edit: Some dependencies (like the latest SFML version in Ubuntu, Thanks Alex) will use imported targets instead of result variables. In those cases, after find_package, all you have to do is link to the sfml lib: l;ike sfml-graphics

    • @alexreinking
      @alexreinking 3 ปีที่แล้ว +1

      It doesn't beat listing source files manually because manual source file listing is the *only* correct way to do it. See the docs: cmake.org/cmake/help/latest/command/file.html#glob
      1. The developers have explicitly stated that it is wrong to do this. That should give you pause. If you encounter an issue, the developers will likely not be receptive to fixing it for you, but will rather tell you to list your sources.
      2. CONFIGURE_DEPENDS is not guaranteed to work. (See point 1)
      3. If globbing fails, you will have a difficult time figuring out what extra source file got added or removed.
      4. Globbing, especially recursive globbing, is slow and gets worse the more files you have. This is a real issue on Windows.
      5. Globbing is particularly likely to fail when doing git bisects, switching branches, or performing other source control operations that move file timestamps backward.
      Ignore this at your own peril.

    • @kandodev
      @kandodev  3 ปีที่แล้ว +1

      @@alexreinking In my experience, I've had a lot more issues when listing files manually (imagine listing 1000 source files and trying to figure out if you missed one) than I've ever had from globbing. Even if configure_depends doesn't work, literally cleaning and rebuilding still works every time. What do you mean by globbing failure in 3? Globbing is such a small factor in terms of build time that the slightly slower builds are worth the hassle free build experience. For 5., I suggest not committing build artifacts since they are ephemeral and should be re-built locally.

    • @alexreinking
      @alexreinking 3 ปีที่แล้ว

      @@kandodev Cleaning and rebuilding every time is absolutely unreasonable _especially_ when you have "1000 source files"! I shouldn't have to explain the utility of incremental builds.
      I could see using a glob to _migrate_ an existing project to CMake, but editing one line in a file is not fraught with issues relating to "missing one" source file and having the build fail. Once the build is working, you should still replace the glob with its result.
      Again, globbing is not fast on Windows and isn't insignificant. It can take several seconds. Globbing can fail in several ways, especially during file-system invasive operations like VCS bisects. It can pick up files you didn't intend.

    • @kandodev
      @kandodev  3 ปีที่แล้ว +1

      Sorry but expecting people to manually maintain an explicit list of hundreds of source files is absolutely insane. And there’s no point in talking about whether something is minimally or reasonably slow without more quantifiable numbers in specific scenarios.

    • @alexreinking
      @alexreinking 3 ปีที่แล้ว

      @@kandodev Take it up with the CMake devs, then. That is not ergonomic does not change the fact that it is the ONLY way to list source files efficiently and correctly in all scenarios. At least you should not be teaching people to glob without understanding the reasons it is discouraged by the devs. "CMake is not supposed to be your build system" is (a) not true and (b) doesn't communicate the very real things you trade off when you glob.

  • @cedricortencio8362
    @cedricortencio8362 ปีที่แล้ว

    I'm convinced that the big investors and analysts are trying to scare us to keep us poor and ignorant to the market.. because its steady

  • @LS-cb7lg
    @LS-cb7lg 2 ปีที่แล้ว

    good tutorial but im confused by your fast typing xD

  • @nightghost87
    @nightghost87 2 ปีที่แล้ว

    Good video, only minus your keyboard is louder than your voice..........

  • @itayalmoznino5192
    @itayalmoznino5192 3 ปีที่แล้ว

    HI!
    thanks for the video, and the series as a whole. It helped me setup vim as a nice c++ development platform :)
    I have ran to a problem with the CMakeGenerate and CmakeBuild. I have this small sfml project that im working on. it has only two files, and currently no header files.
    in the generation phase it says it found the sfml library files, but in the build phase it does not recognize any of them :'>(
    I would greatly appreciate if you or anyone watching could take a quick look on the screenshots I added and suggest a solution!! :)
    not for the faint of heart:
    imgur.com/a/ILCKumw
    thanks!!

    • @kandodev
      @kandodev  3 ปีที่แล้ว +1

      Hi, yeah sfml was probably a bad example for me to pick here since the modern versions of the library switch from the _INCLUDE_DIRS and _LIBRARIES to imported targets. So you can just do:
      target_link_libraries( sfml::system sfml::window sfml::graphics)
      instead of using SFML_LIBRARIES and the _INCLUDE_DIRS.
      I'm gonna make a video on some of these modern configurations soon.

    • @itayalmoznino5192
      @itayalmoznino5192 3 ปีที่แล้ว

      @@kandodev Wow thank you very much man!
      it worked (instead of sfml::system it is sfml-system etc.)
      thanks :)

  • @edwardzdankiewicz9068
    @edwardzdankiewicz9068 6 หลายเดือนก่อน

    The keyboard is too loud speaker too quiet. Hard to hear speaker when he is typing

  • @CannibalWarthog
    @CannibalWarthog ปีที่แล้ว

    2:37

  • @hexagonist23
    @hexagonist23 2 ปีที่แล้ว

    Uses vi. The most unpractical file editor.

  • @rhts420
    @rhts420 หลายเดือนก่อน

    Who finds the keyboard typing annoying ?

  • @dr_bodling
    @dr_bodling 10 หลายเดือนก่อน

    Gosh, your keyboard sounds like a damn typewriter. Very distracting......nice info though.

  • @Autom_te
    @Autom_te 9 หลายเดือนก่อน

    your keyboard is very loud and annoying

  • @markharrington5826
    @markharrington5826 11 หลายเดือนก่อน

    Excellent video thank you Very well presented and by far one of the best Ive seen on cmake That really has been of help to people like myself
    Would you also credit chatGPT couldn't come up a solution for cmake with GTK3 C which i thought was quite amusing and after some 5 hours trying to find a solution I found the solution myself by A: watching your video and B: viewing other solutions from which I derived a working solution in under half an hour
    Just shows you and they suggest AI is good I beg to differ thanking you for your time an effort as without people like yourself we wouldn't know the answers