In this video, we'll go over the steps necessary to create our own
custom project template.
The idea here is that we can create our own project template
and then when we create new projects, we can use this template as the starting point.
So that way we'll have our c++ file written,
all the compiler settings and all the project settings as we want.
The example I'm going to do here is on Microsoft windows.
If you're on macOS 10 or Linux,
use the settings that we used in the video where we configured code lite.
They're going to be exactly the same as we did there.
Okay. So let's do it. It's really easy to do.
You can see I've got a blank CodeLite interface here.
And I want to create a new workspace.
So I'm going to select new workspace.
Now if you've already got a workspace that's open, you can certainly use that one.
But I want to create a new one that way you see me do it a couple more times
and you get used to it. So I'm going to select c++ for my worksheet based type
and click okay.
I'm going to give the workspace a name. I'm just going to call it MyWorkspace,
just like that.
Make sure that this is checked here. Again, you guys know all about the naming convention.
No spaces. No special characters
and no international characters. I'm going to click okay,
and you can see MyWorkspace is set up here.
One quick tip, you can right click on MyWorkspace
and select workspace settings.
And then you can go to code completion right here.
This tab right here, you can select c++14 or c++17.
I'm going to select 17.
And what that'll do is as you type in the editor,
it'll try to figure out what you want to type and really help you out sometimes with
some suggestions. So I'm just going to select okay.
You don't have to do that but it's pretty nice to do.
All right. So now let's create our project.
Just like we did before, I'm going to right click on the workspace,
new, new project.
What's my project name? I'm just going to call it project1 again.
Create the project in its own folder. Category is console.
Type is simple executable g++.
My compiler is my mingw64 compiler.
My debugger is the GNU gdb debugger and the build system is default.
Okay. So everything we did before
has persisted here, which is nice. So I'm going to click okay.
And you can see that my project1 has been created over here in my workspace on the left.
And now I'm going to go to the c++ file.
I'm going to get rid of this guy that's here.
And I'm going to replace it with the code very similar to the code we wrote before.
The only difference is that it says "My template" instead of Hello Testing right here.
Now this is the code that I want to save for my template code.
This code can be anything you want.
In this case, I'm just going to use a real simple
include iostream with a main and I'm displaying My template.
Now what we want to do is we want to set up our project settings,
just like we did before. So I'm going to select project1,
right click on it, go to settings
and I'm going to go to my compiler,
and I'm going to set up my c++ compiler options.
I'm going to enable c++ 17. All compiler warnings,
optimize for debugging and produce debugging information,
just like we did before. I'm going to click okay. Then I'm going to go to linker.
And for linker options, I'm going to use -static.
That's it. I'm going to apply
and hit okay.
That's it we're good to go now. What I'm going to do now is
build my project to make sure that it runs okay before I save it as a template.
So let's do that now. I'm going to build and run the project.
There's my template displaying in the console,
press any key to continue that's what i want. So it looks like
we had a successful build and run.
We can click on build down here in the output view.
You can see we've got zero errors, zero warnings.
You could see the switches that we set are all set up. So that's perfect.
Now what we want to do is we want to save this project and its settings
as a template. So that when we create new projects,
we don't have to do this over and over again.
So I'm going to right click on project1
and then select save as template.
And now we get this little dialog.
What's my project name? I'm just going to call this CPP-Template,
just like that.
Now what's the project category? We can really choose anything we want,
but there is one category that's pretty nice and it's a user template category.
And what I want to do is I want to store my template in that category. So I'm going to select it
and then here you can type anything you want.I'm just going to say Frank's
CPP Template.
And select okay.
That's it. My template is now good to go.
So how do I use it? Well, I need to create a new project.
So let's do that again.
I'm going to close this up just so we're nice and clean here, and I'm going to go to MyWorkspace,
right click new,
new project again.
I'm going to call this project2.
Again, you can name this anything you like.
Now for category, instead of console,
I'm going to pick user templates. That's where I saved my template.
And then for type, you can see my CPP template right here.
That's the one I just created. So I'm going to select that.
Okay, pretty easy. And I had you if you had saved it in the console category,
then when you select console and then click on type, you would see your
template here. But I saved it in user templates
and it's right here CPP template.
This is filled in for me already.
I'm using the MinGW compiler, the GNU debugger and the default build system.
When I click okay, project2 will show up here.
And it should have all the settings that project1 had
because we created it from that template. But we'll double check.
So I'm going to click okay. There's project2.
Now you'll notice that project1 is bold and italicized.
CodeLite uses the active project model,
which means that it builds and runs the active project.
The active project is project1. You can see that it's bold and italicized.
If We want project2 to be the active project, we can right click on it
and set it as the active project,
right here make active
or we could just double click on it which is what I do. I just double click on it,
now you can see that project2 is the active project.
So let's take a look at the source code, it should be that my template string being displayed.
There it is. So we've created project2 based on the template we just created.
If I right click on project2 and I look at my settings,
I should see my compiler flags. There they are.
And I should see my linker flag right there the static.
So it's exactly the way I want.
So you can see it's really easy to create new projects based on this template,
and you don't have to set these compiler flags or this link or flag
ever again.
So that's pretty much it. We can run project2 now.
I'm going to build, build and run.
And there's my template again. Everything's good.
If you're not sure which is the active project, which one is running,
you can always look over here. It's the bold italicized one is the active project.
And then you could also look in your build output and you can see it's building project2.
So if you think
maybe you're modifying this source code here this is the one for project1 and
you run it and you're getting the wrong output, this is probably why.
Remember, CodeLite builds and runs the active project. That's really important.
And you could see the project, right here project2
was the one that was just built and run.
Okay. So that's it. We're all set, and we're ready to start coding.