(intro music)
Frank: 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 templates.
And when we create our projects,
we can use this template as the starting point.
That way we'll have a proper main.cpp file.
We'll have all our switches set,
we'll have our environment set.
Alright, so let's get started.
First thing you need to do is open up a workspace.
I've got a workspace already open, I already created
I should say I'm gonna open it now.
I'm gonna say open workspace.
If you don't have a workspace at all
you could just say File, New Workspace.
So I'll open the workspace that I've got.
It's on my desktop and it's called CPPWorkspace.
So I'll open that.
And the first thing you wanna do is
you want to add a project.
So you wanna right click on your workspace
and say New, New Project.
Now here you've got the New Project Wizard
and you've got different examples.
You can create GUI applications, console applications,
you can have user templates and so forth.
What we want to do is,
we want to use the simple executable g++ template
that comes with CodeLite.
And we want to tweak that our own way.
And then what we want to do is we want to create
our own template in here that we can choose.
And we could put it in console or
we can put it here in user templates.
We could put it wherever we'd like.
Okay? But before we do that, we need to create a project.
So let's do that.
I'm gonna select console and let's use the g++
simple executable console template.
I'll press next.
The project name, it doesn't really matter.
I'll just say sample since we're gonna save it
as a template anyway, and I'll select next.
We wanna make sure our compiler is set up correctly.
Here I'm using MinGW and the gdb debugger.
I'll select finish.
And that creates our project.
You can see here's the source file
and here's the CPP file,
which is really C code and not c++ code.
But we'll fix all this in a minute.
So, first thing we wanna do is
we wanna get rid of this and let's write
a simple c++ program.
So same one we've been writing all along.
So we'll say include
iostream,
we'll include iostream since we're gonna probably use it
in most of the projects that we write.
Then we have our main function,
and again it's int main open, close parens,
and then an open curly
which will be automatically closed by Codelite.
Here we can indent in by just pressing tab
and we could say std::cout.
And then the insertion operator followed by the string
"Hello world".
And you can type anything you like here for "Hello World".
And we'll do also an std::endl;.
This prints a new line.
That way when we display "Hello World", the cursor will go
to the next line on the console.
And then finally we'll just return zero like we always do.
That's it.
I'm going to save this.
So I'm gonna press control S here.
So I've just done that and saved it.
Now we'll set some compiler settings and we'll do
this the one time and then we'll save it
as a project template.
So let's go to the sample project, the actual project name
and we'll right click go down to Settings,
Global Settings.
And we wanna make sure we've got those two compiler
options set.
So we're gonna right click on those three little dots
here on the button.
You wanna select that button and click, and we
wanna make sure that we've got our all warnings enabled on
and our C++ 14 standard on.
Press okay.
Then you wanna come to where it says code completion
and select that and select enable C++ 14 standard.
Apply.
And that's it.
Now what we can do is we can come
to the project again, right click and say
Save as Template.
So I'll select that.
And what's the project name?
This could be anything we want.
We could just say Frank template
or template for course or any name you like.
Rather than that, I'm just gonna say Frank.
Let's see,
g++ console
template.
I think it's pretty picky about spaces,
so I'm just gonna use those dashes.
And it is a console application.
We could that if, if you leave it as console
it'll be in the console group.
I'm actually gonna change that to user template.
And then you can give any description you want.
I'll just say Frank's console template.
That's it. I'll select Okay.
And now we've got a new template that's stored.
So, if I go back to my workspace
and I wanna create a new project.
Now, let me close all this up.
I'm gonna right click and say New Project.
And now you can go down to your templates
and go down to your User templates.
Right here.
And you should see that one we just created right here.
So we can just select that.
Next, I'll just say project one,
select Next.
Keep the defaults for the compilers and finish.
At this point, you can double click here to
make that project the active project.
And we'll look at the main.cpp.
You can see it's the main CPP that we just typed.
Also, if you right click
on the project and you go down to the settings
you can see a code completion is C++ 14.
And the global settings have the appropriate
compiler flags that we need.
That's it.
We'll test this real quick.
Let's run.
Build, and execute and Hello World.
That's it. So now you've got a project
you're all set up.
You can create as many of these as you like.
Tweak the settings as far as you like.
It's really up to you to decide what you wanna do
with the project templates.
But for this course, include iostream.
Give yourself a main.
You may or may not want this line right here,
since you know you're probably gonna get rid
of it anyway when we start writing other code.
But at a minimum, do something like that.
When you create a new project,
you'll be ready to start coding.