Compare commits
10 Commits
7c78897f19
...
8408036078
Author | SHA1 | Date | |
---|---|---|---|
|
8408036078 | ||
|
290e15157e | ||
|
84c40f85d6 | ||
|
f53eb3a5f3 | ||
|
9143e3808e | ||
|
c76236dc8b | ||
|
f3ee95c476 | ||
|
aba1e0d295 | ||
|
4ed070789f | ||
|
ab5df877fc |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
# Builds
|
||||
build/
|
||||
|
||||
# Google Tests
|
||||
googletest-master/
|
||||
._googletest-master
|
||||
tests/lib/
|
||||
|
||||
# Jet Brains
|
||||
.idea/
|
||||
|
43
README.md
43
README.md
@ -2,7 +2,7 @@
|
||||
When setting out on a new project in C++ there are a few configuration steps
|
||||
which need to be completed prior to actually getting down to writing code.
|
||||
This repository is going to be a C++ project template that already has the
|
||||
following components:
|
||||
following components:
|
||||
|
||||
- Directory Structure
|
||||
- Make Build (CMake)
|
||||
@ -12,11 +12,16 @@ following components:
|
||||
Feel free to fork this repository and tailor it to suit you.
|
||||
|
||||
## Procedure
|
||||
1. Clone the Repository
|
||||
1. Download Bash script to create new C++ projects
|
||||
```bash
|
||||
git clone
|
||||
curl -O https://raw.githubusercontent.com/TimothyHelton/cpp_project_template/master/new_cpp_project.sh
|
||||
chmod u+x new_cpp_project.sh
|
||||
```
|
||||
1. In the top level **CMakeLists.txt**:
|
||||
1. Create new C++ project
|
||||
```bash
|
||||
./new_cpp_project.sh NewProjectName
|
||||
```
|
||||
1. In the project top level **CMakeLists.txt**:
|
||||
1. Line 2: Change the variable **MyProject** to the name of your project.
|
||||
```cmake
|
||||
project(NewProject)
|
||||
@ -24,19 +29,11 @@ Feel free to fork this repository and tailor it to suit you.
|
||||
- This variable will be used in a couple of different places.
|
||||
- MyProject_run: will be the main executable name
|
||||
- MyProject_lib: will be the project library name
|
||||
1. Line 4: Set the version of C++ to use. For example let's set up the
|
||||
CoolProject to use C++ 11.
|
||||
1. Line 4: Set the version of C++ to use. For example, let's set up the
|
||||
NewProject to use C++ 11.
|
||||
```cmake
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
```
|
||||
1. Clone Google Test project into the `test/lib` directory.
|
||||
```bash
|
||||
git clone git@github.com:google/googletest.git MyProject/tests/lib
|
||||
```
|
||||
1. Rename the Google Test main directory to `googletest-master`.
|
||||
```bash
|
||||
mv MyProject/tests/lib/googletest MyProject/tests/lib/googletest-master
|
||||
```
|
||||
1. Update project name and description in the `Doxyfile` located in the `docs`
|
||||
directory.
|
||||
1. Update line `PROJECT_NAME`
|
||||
@ -50,34 +47,34 @@ directory.
|
||||
|
||||
## CLION IDE Specific Instructions
|
||||
I started using an IDE from [JET Brains](https://www.jetbrains.com/) tailored
|
||||
for Python called [PyCharm](https://www.jetbrains.com/pycharm/), and thought
|
||||
for Python called [PyCharm](https://www.jetbrains.com/pycharm/) and thought
|
||||
it helped me write better code.
|
||||
I'd been wanting to learn C++ and decided to give JET Brains C/C++ IDE called
|
||||
[CLion](https://www.jetbrains.com/clion/) a try.
|
||||
The code completion, interactive suggestions, debugger, introspection tools,
|
||||
and built in test execution are very handy.
|
||||
The code completion, interactive suggestions, debugger, introspection tools,
|
||||
and built-in test execution are very handy.
|
||||
There are a couple extra details to set when using this IDE.
|
||||
|
||||
1. The IDE allows you to mark directories with their desired purpose.
|
||||
To mark a directory right click on the directory name in the `Project` window
|
||||
and select `Mark Directory as` from the drop down menu.
|
||||
and select `Mark Directory as` from the drop-down menu.
|
||||
1. Mark the `src` directory as `Project Sources and Headers`
|
||||
1. Mark the `tests/lib/googletest-master` directory as `Library Files`
|
||||
1. Mark the `tests/lib/googletest` directory as `Library Files`
|
||||
1. Setup the `Run/Debug Configuration` by selecting `Edit Configurations...`
|
||||
from the pull down menu from the run button (green triangle) in the upper right
|
||||
from the pull-down menu from the run button (green triangle) in the upper right
|
||||
corner.
|
||||
1. Update Doxygen Build to execute the unit test suite.
|
||||
1. Select Doxygen from the Application menu on the left.
|
||||
1. Choose the **executable** for Doxygen to be `Unit_Tests_run`.
|
||||
1. Create a `Google Test` configuration
|
||||
1. In the upper left corner select the plus symbol.
|
||||
1. Chose `Google Test` from the drop down menu.
|
||||
1. Chose `Google Test` from the drop-down menu.
|
||||
1. Set **Name** to `Unit Tests`.
|
||||
1. Set **Target** to `Unit_Tests_run`.
|
||||
|
||||
|
||||
## Wrap Up
|
||||
That should be all it takes to start writing code.
|
||||
If you find any issues or bugs with this repository please file an issue on
|
||||
GitHub.
|
||||
[GitHub](https://github.com/TimothyHelton/cpp_project_template/issues).
|
||||
|
||||
Hope you find this template useful and enjoy learning C++!
|
33
create_project.sh
Normal file
33
create_project.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Exit if name argument is not given
|
||||
if [ -z "$*" ]; then
|
||||
echo "A project name argument must be provided."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
NAME=$1
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
# Clone template repository
|
||||
git clone https://github.com/TimothyHelton/cpp_project_template
|
||||
|
||||
# Create bare repository
|
||||
git --bare init ${NAME}
|
||||
|
||||
# Push template master branch to bare repository
|
||||
cd cpp_project_template
|
||||
git push ../${NAME} +master:master
|
||||
|
||||
# Convert bare repository into a normal repository
|
||||
cd ../${NAME}
|
||||
mkdir .git
|
||||
mv * .git
|
||||
git config --local --bool core.bare false
|
||||
git reset --hard
|
||||
|
||||
# Clean Up
|
||||
rm -rf ../cpp_project_template ../create_project.sh
|
20
new_cpp_project.sh
Normal file
20
new_cpp_project.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Exit if name argument is not given
|
||||
if [ -z "$*" ]; then
|
||||
echo "A project name argument must be provided."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
NAME=$1
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
# Download latest version of the build file
|
||||
curl -O https://raw.githubusercontent.com/TimothyHelton/cpp_project_template/master/create_project.sh
|
||||
chmod u+x create_project.sh
|
||||
|
||||
# Create Project
|
||||
./create_project.sh ${NAME}
|
@ -1,7 +1,12 @@
|
||||
project(${CMAKE_PROJECT_NAME}_tests)
|
||||
|
||||
if(NOT EXISTS lib/googletest)
|
||||
file(MAKE_DIRECTORY lib/googletest)
|
||||
# Clone Google Test
|
||||
set(GOOGLETEST_DIR ${CMAKE_SOURCE_DIR}/tests/lib/googletest)
|
||||
if(NOT EXISTS ${GOOGLETEST_DIR})
|
||||
find_package(Git REQUIRED)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} clone https://github.com/google/googletest ${GOOGLETEST_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
add_subdirectory(lib/googletest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user