CMake Tutorial EP 3 | Git Submodules (adding glfw windowing library example)

  Рет қаралды 82,885

Code, Tech, and Tutorials

Code, Tech, and Tutorials

3 жыл бұрын

full CMake playlist: • CMake Tutorial EP 1 | ...
Find me, support me:
Stream: / overridetheprogram
Patreon: / codetechtuts
One time donations: www.paypal.com/paypalme/matte...
Shop via my Amazon Affiliates Link: amzn.to/3bVQ9X0
Business inquiries: codetechtuts@gmail.com
Thanks for coming to the channel to check out a video on Code, Tech, and Tutorials.

Пікірлер: 108
@flotsamjones6541
@flotsamjones6541 3 жыл бұрын
The -D predates CMake and is part of gcc syntax for a definition which gets translated to a #define statement. Other executables (like java) use this convention as well for injecting variables (of one kind or another) in from the command line.
@nubnubbud
@nubnubbud 2 жыл бұрын
I was trying to build GLFW into my project from a git submodule for 9 hours, learned compiling, learned linking, learned cmake, with the first and second tutorial... I spent 3 hours searching about how things were seen by various linkers and whatnot... then I noticed there was a 3rd tutorial episode.
@observant6953
@observant6953 2 жыл бұрын
16:00 in target_link_libraries you reference other targets, in this case glfw specifies a target. This comes from the call to add_library() in external/glfw/src/CMakeLists.txt. In that CMakeLists.txt file you can see that they somehow set the name of the target library to glfw3 (for whatever reason), but the beauty of using targets is that you don't need to care about how it is actually called. You work only with the target name which can be completely different than the library name.
@priyanshu_hiro
@priyanshu_hiro Жыл бұрын
Damm 3 weeks old answer on 2 years old video. looks I really watch it at the right time. Please pin the above comment Code, Tech, and Tutorials.
@chashmal10
@chashmal10 Жыл бұрын
@@priyanshu_hiro I would recommend reading the docs to whatever CMake functions are used in the video. Then you would know that it isn't the isn't the lib name, its the target name.
@lucas0sz
@lucas0sz 8 ай бұрын
Apparently they set the "OUTPUT_NAME" property (used by CMake to determine the actual filename) on the "glfw" target to "GLFW_LIB_NAME", which in turn is set to "glfw" or "glfw3" based on a condition.
@bruhgamer317
@bruhgamer317 3 жыл бұрын
don't know if i suck at finding it but this was the only good tutorial on git submodules, thanks a lot
@EricFontaineJazz
@EricFontaineJazz 2 жыл бұрын
same here!
@christianoliverio5726
@christianoliverio5726 3 жыл бұрын
Thanks so much for these videos man! I know you're more of a small KZfaqr, but I don't like the other videos on KZfaq about CMake as much as yours. Your examples, even though sometimes you make a lot of errors along the way, actually help me learn a lot better, because I see what doesn't work and what does Usually it makes me learn _why._ This is very helpful for me, because I can get a sense of what under-girds the principles behind these tools. Thanks so much man!
@ashkudupi
@ashkudupi 3 жыл бұрын
Thank you for the wonderful explanation of the teeny tiny details! Great to learn as a beginner!
@GTExplosion
@GTExplosion 2 жыл бұрын
This series is so great! Really push me to tick CMake off my to-learn list!!!
@danmcfarland5284
@danmcfarland5284 3 жыл бұрын
Very well done and very helpful for the total NOOB. I enjoy the little bit of light humor. Keeps things from getting too bland.
@MoeQ_
@MoeQ_ Жыл бұрын
this play list is my main reference whenever I want to use CMake, extremally helpful
@jet665
@jet665 3 ай бұрын
I enjoy the small jokes you slip in, "git into git" and the binocular vision when something in the Cmake documentation piqued your interest in the last episode. Informative and funny, thanks for this series.
@6LayersDeep
@6LayersDeep Жыл бұрын
EXTREMELY helpful tutorial series! I've been trying to get this setup since 2014, unsuccessfully. I know I'm dumb but it's generous digital elves like you that save grace upon this wretched planet 😅
@serhiimamedov
@serhiimamedov 9 ай бұрын
Make this is top notch tutorial! This is such a complex topic and you make it look so easy.
@SrijanaRupakheti
@SrijanaRupakheti Жыл бұрын
Thank you for this tutorial, as a novice in CMake, it really helped me in my project.
@liang9to5
@liang9to5 Жыл бұрын
These courses are fantastic.
@emeka752
@emeka752 2 жыл бұрын
Awesome series. Been a great help for my project👏
@tralfamadorian6
@tralfamadorian6 3 жыл бұрын
Thank you thank you, this was the video that finally helped me get SFML configured for VSCode and CMake on a Mac.
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Glad it helped!
@Rojek121212
@Rojek121212 Жыл бұрын
this tutorial is pure gold
@elises8076
@elises8076 3 жыл бұрын
I think we use glfw instead of glfw3, because we should put here the parameter, which was used in add_library(glfw [...]) (in external/glfw/src/CMakeLists.txt,). The same was for Adder. Let me know if it's a good way of thinking about it :)
@medhavikosta3889
@medhavikosta3889 2 жыл бұрын
Yes you are right .
@clintonreisig
@clintonreisig 2 жыл бұрын
Yes, that can be done but he is trying to keep things as simple as possible because many viewers are basically at beginner level in CMake. Eventually, he covers how to add ANYTHING and several ways of doing it.
@anddero
@anddero 2 жыл бұрын
Then why is the built library named "libglfw3.a" and not "libglfw.a"?
@quant-trader-010
@quant-trader-010 Жыл бұрын
@@anddero it is because external/glfw/src/CMakeLists.txt set so in the very first line add_library(...).
@anomacti
@anomacti 2 жыл бұрын
Thanks for the great tutorial man, very well made and easy to understand.
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
Glad it helped!
@VADroidTS555
@VADroidTS555 3 жыл бұрын
This is a great series! Thank you!
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Thank you!
@JustSomeRandomIdiot
@JustSomeRandomIdiot 2 жыл бұрын
Literally trying to figure out how to setup a cross platform project for Linux/Windows that uses GLFW and CMake and just found this series, thankyou, such relief to have someone explain this in simple terms.
@AlexWong-jk9lc
@AlexWong-jk9lc 2 жыл бұрын
Amazing tutorials!
@aleksanderklepov8881
@aleksanderklepov8881 3 жыл бұрын
Good tutorial. Thank you!
@PrathameshMhatre-pl5eu
@PrathameshMhatre-pl5eu Жыл бұрын
Thanks a lot for the video. Best explanation overrall.
@1aggin_5amurai
@1aggin_5amurai Жыл бұрын
I feel like a will become the very Lord and Savior by end of this course! Great job!
@DrWho2008t101
@DrWho2008t101 3 жыл бұрын
Thanks for the video.
@eduardorocha1547
@eduardorocha1547 2 жыл бұрын
You're the man!!! So easy to follow you.
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
Thanks! glad you found it helpful
@csfinch7672
@csfinch7672 11 ай бұрын
This was very helpful. Thank you!!
@handlehandle12322
@handlehandle12322 3 жыл бұрын
Cool video and explanation
@eeminceetin
@eeminceetin Жыл бұрын
fascinating explanation, best regards
@liboyan7010
@liboyan7010 2 жыл бұрын
This is very so good lecture!!!!! Great job!!!! Thanks!
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
You're very welcome!
@ELECTRONICWALKS24
@ELECTRONICWALKS24 2 жыл бұрын
thankyou for your efforts bro...!
@anton_98
@anton_98 Жыл бұрын
Thank you very much!
@nickwu9290
@nickwu9290 2 жыл бұрын
i think in this example target_include_directories is not necessary as these header file directories from library are already included when building the libraries, and when you do the target_link_libraries it will add its interface_include_directories to the current target include_directories automatically. Nice tutorial! Really appreciate it!
@metascopeinitiatives2550
@metascopeinitiatives2550 3 жыл бұрын
I have subbed. Your channel is awesome. Thank you so much 🙏
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Thanks for the sub!
@mohamedhussien4013
@mohamedhussien4013 Жыл бұрын
Really good tutorial!!!
@CodeTechandTutorials
@CodeTechandTutorials Жыл бұрын
Thank you!
@raizoxxu
@raizoxxu 3 жыл бұрын
good tutorial!
@visclo4782
@visclo4782 Жыл бұрын
thank you
@maximkorytko8972
@maximkorytko8972 2 жыл бұрын
TY SO MUCH!!!
@gebibeshir5709
@gebibeshir5709 11 ай бұрын
Oh Zeus you're the real saviour, thy shal be thanked!
@mr.z9161
@mr.z9161 2 жыл бұрын
thanks for the awesome tutorial and didn't know he bring his twin brother to talk this time lol.
@dahuskey81
@dahuskey81 3 жыл бұрын
OMG Somebody stole your goatee, did you have it insured ? Haha 😄 another great tutorial!!
@prashantchavan2673
@prashantchavan2673 Жыл бұрын
10:21 "-D" is use for option because it's actually #define of particular macro.
@lefteror
@lefteror Жыл бұрын
Regarding cmake targets (around the 14:30 mark): target_include_directories refers to the directories that the target needs to search for its own include headers (in this case adder). If that target were to be used as a dependency of a different target (like glfw here), its directories would be transitive and be passed on (provided they are public) by just adding the cmake target in target_link_libraries. Having said that, adding another target’s directories to the target in question is kind of hijacking it to make the directories visible at compilation time. Hope this wasn’t too confusing.
@sarthaksharma4816
@sarthaksharma4816 2 жыл бұрын
My god. Thanks a ton. Sincerely.
@marbles3662
@marbles3662 3 жыл бұрын
Great tutorial. Made me subscribe to your channel. :)
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Awesome, thank you!
@2914vinayak
@2914vinayak 2 жыл бұрын
Thanks
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
Welcome
@frankaalbers1099
@frankaalbers1099 3 жыл бұрын
It probably has been mentioned below. But the target_link_directories don't seem to be needed since you actually use the names in the add_library commands and not the names of the library files. That's why you use glwf and not glwf3 since the CMakeLists.txt of GLWF uses the add_library(glfw ...) command to create the library Well, at least as a noob, that's how see to understand it
@jphvnet
@jphvnet Жыл бұрын
Exactly!
@BOURNE399
@BOURNE399 3 жыл бұрын
Thanks, Sir! I learn a LOT! Question: why is the libglfw3.a file generated in the src dir (though it involves under 'build' dir)? Is it source code? And when we include the path of libglfw3.a, why don't we need to include the 'out/build' in front of it?
@jphvnet
@jphvnet Жыл бұрын
Because he links to the CMake library (created by using add_library() inside glfw sources) which knows the path and the final name (.i.e. the 3 at the end of the name). Also, if glfw is created as STATIC or SHARED, from outside you dont need to care about .a or .so (that's a real added value about how CMake simplifies things)
@themindsethunter2168
@themindsethunter2168 Жыл бұрын
I wonder what would happen if I import two submodules with options having conflicting names, and I want to have one of them ON and other OFF.
@thevladislove4624
@thevladislove4624 3 жыл бұрын
Thanks for the very helpful tutorial! What about libs like GLEW ? That don't have CMakeLists.txt in treir repos ? How can you add them as a submodule ? or is there a different approach for those ? Thx and keep up and the good work!
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
You can, it can get a little complicated though and will vary from case to case. In my video on bgfx I use submodules and cmake to include bgfx and bgfx doesn't use cmake so that is one example. I'll try to cover more of this in upcoming cmake tutorials.
@aleksandrpaniutin4028
@aleksandrpaniutin4028 2 жыл бұрын
glfw3 is a library name but cmake needs a target, which is glfw.
@vladyslavtkach2209
@vladyslavtkach2209 3 жыл бұрын
Do not try to add multiple directories via one add_subdirectory() command (it is not even plural!!!) as i tried to. It works, but only the first directory is added which results in linking errors!!!
@jinkoofy
@jinkoofy 3 жыл бұрын
A change needed in CMakeLists.txt (line 29): "external_modules/glfw" --> "external/glfw".
@maximilien7737
@maximilien7737 2 жыл бұрын
but he did change it during the video right ?
@kb-zealot
@kb-zealot Жыл бұрын
re: 10:22 why "D" is option. The -D* is probably mimicking the way that g++ does macro [D]efinitions
@jasio583
@jasio583 5 ай бұрын
where I can find the source code? It's no longer in the description.
@leimiles18
@leimiles18 2 жыл бұрын
Hi, thanks for the tut, I wonder what does this "#!" mean, and when I use it on my windows, the command just won't work, tells me '#!' is not recognized as an internal or external command....
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
It's a Linux bash thing. On Windows unless you're using WSL and a Linux console, you might have to do something different
@giangbuitam4868
@giangbuitam4868 3 жыл бұрын
Firstly , Thank you for great tutorial ! I have a question. I add git submodules glad and sdl2. when glad build , it build a glad.c and glad.h so i can't target_include it in cmake . How can i make it work ?
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Thanks! I recall having trouble submoduling both of those as well, it has been a while since I've tried again. If I ever figure it out I'll be sure to make a video.
@giangbuitam4868
@giangbuitam4868 3 жыл бұрын
@@CodeTechandTutorials Thanks u ! I look forward to it.
@eMttiew
@eMttiew Жыл бұрын
What if my submodule only has MakeFile not CMakeLists?
@user-mv4oh8yp1y
@user-mv4oh8yp1y 2 жыл бұрын
If I remove the `target_include_directories(...)` it can still be run without problem. Any idea? btw, I think -D means Define variable
@JannisAdmek
@JannisAdmek 2 жыл бұрын
IN the cmake docs it says that `target_include_directories(...)` is rarely necessary, if you already use `link_library()`, you don't need it.
@TopConductor
@TopConductor Жыл бұрын
Maybe someone can help and explain why do we need "target_link_directories"? And what is the difference with target_link_libraries? I wrote the code without "target_link_directories", but with "target_link_libraries" and it still works just fine.
@frogbastard8108
@frogbastard8108 Жыл бұрын
target_link_directories will tell CMake what directory/folder to look for libraries for the given target. Different OS's will have their default library search paths, but target_link_directories will allow you to specify where to search before the default library search paths. target_link_libraries actually links the library files to the target so that the function definitions of the library can be used in the target. I think that this call to target_link_directories is unnecessary because of the call to add_subdirectory for glfw3
@pavelpalivec7042
@pavelpalivec7042 2 жыл бұрын
When building I got the following error: /home/pavel/Projects/olas/external/glfw/include/GLFW/glfw3.h:241:12: fatal error: GL/gl.h: No such file or directory #include . I fixed it by modification of glfw3.h, which is not the correct way I guess. Any advice, please?
@maximilien7737
@maximilien7737 2 жыл бұрын
Yes same issue, thanks for mentioning it
@maximilien7737
@maximilien7737 2 жыл бұрын
Okay so i just needed to install the libglu1-mesa-dev packages sudo apt-get update -y sudo apt-get install -y libglu1-mesa-dev
@iamgt2392
@iamgt2392 4 ай бұрын
thanks bro it WORKED!!! I was wandering aimlessly for 2-3 hours @@maximilien7737
@tamasboros1798
@tamasboros1798 3 жыл бұрын
I have a question. In main.cpp you include . Why did you include as a system library? #include "glfw3.h" seems more reasonable to me due to target_include_directories(${PROJECT_NAME} PUBLIC Adder PUBLIC external/glfw/include ) However, that solution throws me an error during compilation. What am I missing? Nice video anyway! It helps me to understand cmake much better!
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
The angle bracket includes doesn't necessary mean it is a system lib, it just means its within the projects known include directories. target_include_directories puts -I/path/to/include on the compile command for the objects so is sufficient. Quotes should work just the same really, it just searches the local directories first before checking the known includes. Hope that makes sense.
@carlosdalomba
@carlosdalomba 3 жыл бұрын
In this example, I noticed there's nothing in the folder: external/glfw/include The only thing there is another folder, GLFW, which means when I did THIS in the CMakeLists.txt file: target_include_directories(${PROJECT_NAME} PUBLIC external/glfw/include/GLFW ) it worked to do #include or #include "glfw3.h". EDIT: DON'T DO THIS, you should include the folder explicitly named "include" if there is one, to follow best-practices/C++ conventions. So in this case, you'd write: #include or #include "GLFW/glfw3.h". Sorry for the confusion!
@YourCRTube
@YourCRTube 3 жыл бұрын
@@carlosdalomba This is not correct however. You must set include dir as external/glfw/include and do #include "GLFW/glfw3.h" not just #include "glfw3.h". This is a convection, but you must follow it, because the library itself (or any other library) will follow it internally - the library will do MYNAME/myinclude, assuming the folder that contains MYNAME is added to include directories. Again this is universal assumption - if the public headers are in a folder with the same name as the library, you set the containing folder as include directory.
@carlosdalomba
@carlosdalomba 3 жыл бұрын
@@YourCRTube Ohhh I see, so it's (almost) universally assumed as a convention to include the "include" folder (if there is one)? Thanks, that makes sense then, I'll edit my comment lol >.> oops
@clintonreisig
@clintonreisig 2 жыл бұрын
@@CodeTechandTutorials Hopefully, a simple question with a simple answer. The window which appears is the old style. It says "Gears" and the only button is a exit (X) one and it is NOT a radio button but the generic one. The window is black but the header bar on top of the window is white instead of the gray one in the tutorial. I watched the video a couple more times and looked at my code but could not find the problem. Any thoughts?
@nitscheszter2062
@nitscheszter2062 2 жыл бұрын
Your videos are great; make me sub to it. I have followed this video, didn't get any error, but the window didn't pop up :( What did I miss?
@bvisonl
@bvisonl 2 жыл бұрын
git into git............... I'm dead
@vertigo6982
@vertigo6982 3 жыл бұрын
10:25 my guess D was used because D could mean "Dependency" but I dont think it means Dependency, but perhaps thats why they chose D because the options that people use could be seen as build deps.
@viktoriyamankovskaya5906
@viktoriyamankovskaya5906 2 жыл бұрын
what happened to ur hair? on previous video u were more like Jesus, i liked it better)
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
It got scissored... and its long again!
CMake Tutorial EP 4 | Versioning Source Code
10:11
Code, Tech, and Tutorials
Рет қаралды 31 М.
CMake Tutorial EP 5 | Making Libs Optional
18:21
Code, Tech, and Tutorials
Рет қаралды 24 М.
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 27 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 8 МЛН
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН
Creating and Using Libraries in CMake [Ep3]
13:51
sudocpp
Рет қаралды 10 М.
CMake Tutorial EP 2 | Libraries and Subdirectories
17:29
Code, Tech, and Tutorials
Рет қаралды 117 М.
GIT Submodules - Git Series 7
15:47
Tools on Tech
Рет қаралды 11 М.
what are git submodules? (intermediate) anthony explains #273
11:07
anthonywritescode
Рет қаралды 6 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1 МЛН
Simplified CMake Tutorial
27:47
kandodev
Рет қаралды 112 М.
Better CMake Part 6 -- Superbuilds w/ ExternalProject
21:40
Jefferson Amstutz
Рет қаралды 8 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 5 МЛН
Обморожение Пальцев Альпиниста
0:18
Илья Калин
Рет қаралды 1,5 МЛН
Unboxing MEGATRON 40th Anniversary Limited Edition Robot by Robosen
1:00
P7 Amazing Gadgets, Kitchen Utensils, Home cleaning, Inventions, Ideas part 4
0:10
Рыбаки в шоке. Рыбалка. #рыбалка  #shorts
0:20
Жизнь Рыбака
Рет қаралды 2,5 МЛН