1 00:00:05,500 --> 00:00:09,300 In this video, we'll go over the steps necessary to create our own 2 00:00:09,300 --> 00:00:10,800 custom project template. 3 00:00:11,700 --> 00:00:15,700 The idea here is that we can create our own project template 4 00:00:15,700 --> 00:00:20,470 and then when we create new projects, we can use this template as the starting point. 5 00:00:20,770 --> 00:00:24,070 So that way we'll have our c++ file written, 6 00:00:24,070 --> 00:00:27,570 all the compiler settings and all the project settings as we want. 7 00:00:28,450 --> 00:00:31,810 The example I'm going to do here is on Microsoft windows. 8 00:00:31,810 --> 00:00:34,510 If you're on macOS 10 or Linux, 9 00:00:34,510 --> 00:00:38,500 use the settings that we used in the video where we configured code lite. 10 00:00:38,800 --> 00:00:41,300 They're going to be exactly the same as we did there. 11 00:00:43,300 --> 00:00:46,100 Okay. So let's do it. It's really easy to do. 12 00:00:46,100 --> 00:00:49,600 You can see I've got a blank CodeLite interface here. 13 00:00:49,600 --> 00:00:51,600 And I want to create a new workspace. 14 00:00:52,100 --> 00:00:53,700 So I'm going to select new workspace. 15 00:00:53,700 --> 00:00:57,000 Now if you've already got a workspace that's open, you can certainly use that one. 16 00:00:57,000 --> 00:01:00,100 But I want to create a new one that way you see me do it a couple more times 17 00:01:00,100 --> 00:01:04,650 and you get used to it. So I'm going to select c++ for my worksheet based type 18 00:01:04,650 --> 00:01:06,090 and click okay. 19 00:01:06,090 --> 00:01:10,090 I'm going to give the workspace a name. I'm just going to call it MyWorkspace, 20 00:01:10,390 --> 00:01:11,640 just like that. 21 00:01:12,040 --> 00:01:15,940 Make sure that this is checked here. Again, you guys know all about the naming convention. 22 00:01:15,940 --> 00:01:18,540 No spaces. No special characters 23 00:01:18,540 --> 00:01:22,540 and no international characters. I'm going to click okay, 24 00:01:22,540 --> 00:01:25,140 and you can see MyWorkspace is set up here. 25 00:01:25,140 --> 00:01:28,140 One quick tip, you can right click on MyWorkspace 26 00:01:28,140 --> 00:01:30,140 and select workspace settings. 27 00:01:30,800 --> 00:01:32,800 And then you can go to code completion right here. 28 00:01:32,800 --> 00:01:37,460 This tab right here, you can select c++14 or c++17. 29 00:01:37,460 --> 00:01:39,060 I'm going to select 17. 30 00:01:39,060 --> 00:01:42,060 And what that'll do is as you type in the editor, 31 00:01:42,260 --> 00:01:46,160 it'll try to figure out what you want to type and really help you out sometimes with 32 00:01:46,160 --> 00:01:48,760 some suggestions. So I'm just going to select okay. 33 00:01:49,160 --> 00:01:51,360 You don't have to do that but it's pretty nice to do. 34 00:01:51,360 --> 00:01:53,460 All right. So now let's create our project. 35 00:01:53,460 --> 00:01:56,660 Just like we did before, I'm going to right click on the workspace, 36 00:01:56,660 --> 00:01:58,660 new, new project. 37 00:01:59,760 --> 00:02:03,760 What's my project name? I'm just going to call it project1 again. 38 00:02:04,260 --> 00:02:08,360 Create the project in its own folder. Category is console. 39 00:02:08,360 --> 00:02:11,660 Type is simple executable g++. 40 00:02:11,660 --> 00:02:15,360 My compiler is my mingw64 compiler. 41 00:02:15,660 --> 00:02:20,320 My debugger is the GNU gdb debugger and the build system is default. 42 00:02:20,520 --> 00:02:22,520 Okay. So everything we did before 43 00:02:22,520 --> 00:02:26,420 has persisted here, which is nice. So I'm going to click okay. 44 00:02:26,920 --> 00:02:31,120 And you can see that my project1 has been created over here in my workspace on the left. 45 00:02:31,120 --> 00:02:33,560 And now I'm going to go to the c++ file. 46 00:02:33,560 --> 00:02:36,330 I'm going to get rid of this guy that's here. 47 00:02:36,330 --> 00:02:40,530 And I'm going to replace it with the code very similar to the code we wrote before. 48 00:02:40,530 --> 00:02:44,330 The only difference is that it says "My template" instead of Hello Testing right here. 49 00:02:44,990 --> 00:02:47,990 Now this is the code that I want to save for my template code. 50 00:02:47,990 --> 00:02:49,990 This code can be anything you want. 51 00:02:49,990 --> 00:02:52,990 In this case, I'm just going to use a real simple 52 00:02:52,990 --> 00:02:56,290 include iostream with a main and I'm displaying My template. 53 00:02:57,090 --> 00:02:59,590 Now what we want to do is we want to set up our project settings, 54 00:02:59,590 --> 00:03:03,390 just like we did before. So I'm going to select project1, 55 00:03:03,390 --> 00:03:06,590 right click on it, go to settings 56 00:03:07,290 --> 00:03:08,950 and I'm going to go to my compiler, 57 00:03:09,450 --> 00:03:12,450 and I'm going to set up my c++ compiler options. 58 00:03:14,650 --> 00:03:18,850 I'm going to enable c++ 17. All compiler warnings, 59 00:03:19,450 --> 00:03:22,250 optimize for debugging and produce debugging information, 60 00:03:22,250 --> 00:03:26,650 just like we did before. I'm going to click okay. Then I'm going to go to linker. 61 00:03:27,310 --> 00:03:31,110 And for linker options, I'm going to use -static. 62 00:03:32,910 --> 00:03:34,910 That's it. I'm going to apply 63 00:03:35,570 --> 00:03:36,560 and hit okay. 64 00:03:37,560 --> 00:03:40,660 That's it we're good to go now. What I'm going to do now is 65 00:03:40,660 --> 00:03:44,960 build my project to make sure that it runs okay before I save it as a template. 66 00:03:44,960 --> 00:03:48,560 So let's do that now. I'm going to build and run the project. 67 00:03:50,560 --> 00:03:53,110 There's my template displaying in the console, 68 00:03:53,110 --> 00:03:56,710 press any key to continue that's what i want. So it looks like 69 00:03:56,710 --> 00:03:58,510 we had a successful build and run. 70 00:03:58,510 --> 00:04:01,010 We can click on build down here in the output view. 71 00:04:01,010 --> 00:04:04,410 You can see we've got zero errors, zero warnings. 72 00:04:04,410 --> 00:04:08,010 You could see the switches that we set are all set up. So that's perfect. 73 00:04:08,410 --> 00:04:12,410 Now what we want to do is we want to save this project and its settings 74 00:04:12,410 --> 00:04:15,290 as a template. So that when we create new projects, 75 00:04:15,290 --> 00:04:17,490 we don't have to do this over and over again. 76 00:04:17,490 --> 00:04:20,490 So I'm going to right click on project1 77 00:04:20,490 --> 00:04:23,290 and then select save as template. 78 00:04:25,650 --> 00:04:27,450 And now we get this little dialog. 79 00:04:27,450 --> 00:04:31,950 What's my project name? I'm just going to call this CPP-Template, 80 00:04:34,050 --> 00:04:35,050 just like that. 81 00:04:35,050 --> 00:04:39,150 Now what's the project category? We can really choose anything we want, 82 00:04:39,150 --> 00:04:43,350 but there is one category that's pretty nice and it's a user template category. 83 00:04:43,850 --> 00:04:48,350 And what I want to do is I want to store my template in that category. So I'm going to select it 84 00:04:48,850 --> 00:04:52,150 and then here you can type anything you want.I'm just going to say Frank's 85 00:04:52,550 --> 00:04:54,750 CPP Template. 86 00:04:55,450 --> 00:04:56,750 And select okay. 87 00:04:57,450 --> 00:05:00,450 That's it. My template is now good to go. 88 00:05:00,450 --> 00:05:03,810 So how do I use it? Well, I need to create a new project. 89 00:05:03,810 --> 00:05:05,310 So let's do that again. 90 00:05:05,610 --> 00:05:09,970 I'm going to close this up just so we're nice and clean here, and I'm going to go to MyWorkspace, 91 00:05:09,970 --> 00:05:10,960 right click new, 92 00:05:11,760 --> 00:05:14,360 new project again. 93 00:05:15,590 --> 00:05:17,790 I'm going to call this project2. 94 00:05:18,190 --> 00:05:20,190 Again, you can name this anything you like. 95 00:05:20,190 --> 00:05:22,790 Now for category, instead of console, 96 00:05:22,790 --> 00:05:26,790 I'm going to pick user templates. That's where I saved my template. 97 00:05:27,690 --> 00:05:32,050 And then for type, you can see my CPP template right here. 98 00:05:32,050 --> 00:05:35,350 That's the one I just created. So I'm going to select that. 99 00:05:36,010 --> 00:05:40,010 Okay, pretty easy. And I had you if you had saved it in the console category, 100 00:05:40,010 --> 00:05:44,410 then when you select console and then click on type, you would see your 101 00:05:44,410 --> 00:05:48,010 template here. But I saved it in user templates 102 00:05:48,810 --> 00:05:51,310 and it's right here CPP template. 103 00:05:51,810 --> 00:05:53,410 This is filled in for me already. 104 00:05:53,410 --> 00:05:58,110 I'm using the MinGW compiler, the GNU debugger and the default build system. 105 00:05:58,110 --> 00:06:01,770 When I click okay, project2 will show up here. 106 00:06:01,770 --> 00:06:04,370 And it should have all the settings that project1 had 107 00:06:04,370 --> 00:06:07,670 because we created it from that template. But we'll double check. 108 00:06:07,670 --> 00:06:10,970 So I'm going to click okay. There's project2. 109 00:06:11,520 --> 00:06:15,520 Now you'll notice that project1 is bold and italicized. 110 00:06:15,880 --> 00:06:19,280 CodeLite uses the active project model, 111 00:06:19,280 --> 00:06:23,280 which means that it builds and runs the active project. 112 00:06:23,480 --> 00:06:28,180 The active project is project1. You can see that it's bold and italicized. 113 00:06:28,780 --> 00:06:32,980 If We want project2 to be the active project, we can right click on it 114 00:06:33,580 --> 00:06:36,180 and set it as the active project, 115 00:06:36,430 --> 00:06:37,930 right here make active 116 00:06:38,430 --> 00:06:41,430 or we could just double click on it which is what I do. I just double click on it, 117 00:06:42,030 --> 00:06:45,430 now you can see that project2 is the active project. 118 00:06:45,930 --> 00:06:50,130 So let's take a look at the source code, it should be that my template string being displayed. 119 00:06:50,790 --> 00:06:55,450 There it is. So we've created project2 based on the template we just created. 120 00:06:56,110 --> 00:06:59,110 If I right click on project2 and I look at my settings, 121 00:06:59,910 --> 00:07:02,910 I should see my compiler flags. There they are. 122 00:07:03,910 --> 00:07:07,210 And I should see my linker flag right there the static. 123 00:07:07,210 --> 00:07:09,510 So it's exactly the way I want. 124 00:07:09,510 --> 00:07:13,910 So you can see it's really easy to create new projects based on this template, 125 00:07:13,910 --> 00:07:17,570 and you don't have to set these compiler flags or this link or flag 126 00:07:17,570 --> 00:07:18,370 ever again. 127 00:07:18,370 --> 00:07:21,250 So that's pretty much it. We can run project2 now. 128 00:07:21,250 --> 00:07:23,050 I'm going to build, build and run. 129 00:07:23,950 --> 00:07:26,850 And there's my template again. Everything's good. 130 00:07:26,850 --> 00:07:30,750 If you're not sure which is the active project, which one is running, 131 00:07:30,750 --> 00:07:35,740 you can always look over here. It's the bold italicized one is the active project. 132 00:07:35,740 --> 00:07:40,240 And then you could also look in your build output and you can see it's building project2. 133 00:07:40,900 --> 00:07:42,600 So if you think 134 00:07:42,600 --> 00:07:47,300 maybe you're modifying this source code here this is the one for project1 and 135 00:07:47,700 --> 00:07:50,700 you run it and you're getting the wrong output, this is probably why. 136 00:07:50,700 --> 00:07:55,100 Remember, CodeLite builds and runs the active project. That's really important. 137 00:07:55,100 --> 00:07:57,900 And you could see the project, right here project2 138 00:07:57,900 --> 00:07:59,500 was the one that was just built and run. 139 00:08:00,300 --> 00:08:03,300 Okay. So that's it. We're all set, and we're ready to start coding.