Initial commit

This commit is contained in:
Alex Selimov 2025-03-24 03:40:34 +00:00
commit acd9614350
12 changed files with 2720 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# Builds
build/
# Google Tests
tests/lib/
# Jet Brains
.idea/
cmake-build-debug/

38
CMakeLists.txt Normal file
View File

@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.9)
project(MyProject)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES main.cpp)
add_executable(${CMAKE_PROJECT_NAME}_run ${SOURCE_FILES})
include_directories(src)
add_subdirectory(src)
add_subdirectory(tests)
target_link_libraries(${CMAKE_PROJECT_NAME}_run ${CMAKE_PROJECT_NAME}_lib)
# Doxygen Build
option(BUILD_DOC "Build Documentation" ON)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(BUILD_DOC_DIR ${CMAKE_SOURCE_DIR}/build/docs)
if(NOT EXISTS ${BUILD_DOC_DIR})
file(MAKE_DIRECTORY ${BUILD_DOC_DIR})
endif()
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen buld started")
add_custom_target(Doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else(DOXYGEN_FOUND)
message("Doxygen needs to be installed to generate the documentation.")
endif(DOXYGEN_FOUND)

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Timothy Helton
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

80
README.md Normal file
View File

@ -0,0 +1,80 @@
# C++ Project Template
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:
- Directory Structure
- Make Build (CMake)
- Unit Test Framework (Google Test)
- API Documentation (Doxygen)
Feel free to fork this repository and tailor it to suit you.
## Procedure
1. Download Bash script to create new C++ projects
```bash
curl -O https://raw.githubusercontent.com/TimothyHelton/cpp_project_template/master/new_cpp_project.sh
chmod u+x new_cpp_project.sh
```
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)
```
- 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
NewProject to use C++ 11.
```cmake
set(CMAKE_CXX_STANDARD 11)
```
1. Update project name and description in the `Doxyfile` located in the `docs`
directory.
1. Update line `PROJECT_NAME`
1. This name will appear on each documentation page.
1. Update line `PROJECT_NUMBER`
1. This is the version number of your project.
1. Update line `PROJECT_BRIEF`
1. Any text entered here will also appear on each documentation page.
Try not to make this one too long.
1. Reload the top CMake file.
## 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
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.
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.
1. Mark the `src` directory as `Project Sources and Headers`
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
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. 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](https://github.com/TimothyHelton/cpp_project_template/issues).
Hope you find this template useful and enjoy learning C++!

33
create_project.sh Normal file
View 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

2473
docs/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

3
main.cpp Normal file
View File

@ -0,0 +1,3 @@
int main() {
return 0;
}

20
new_cpp_project.sh Normal file
View 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}

17
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,17 @@
project(${CMAKE_PROJECT_NAME}_lib)
set(HEADER_FILES
)
set(SOURCE_FILES
)
if (EXISTS ${SOURCE_FILES})
# The library contains header and source files.
add_library(${CMAKE_PROJECT_NAME}_lib STATIC
${SOURCE_FILES}
${HEADER_FILES}
)
else()
# The library only contains header files.
add_library(${CMAKE_PROJECT_NAME}_lib INTERFACE)
endif()

13
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
project(${CMAKE_PROJECT_NAME}_tests)
# 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)
add_subdirectory(unit_tests)

View File

@ -0,0 +1,8 @@
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(Unit_Tests_run
test_example.cpp
)
target_link_libraries(Unit_Tests_run gtest gtest_main)
target_link_libraries(Unit_Tests_run ${CMAKE_PROJECT_NAME}_lib)

View File

@ -0,0 +1,5 @@
#include "gtest/gtest.h"
TEST(Example, Equals) {
EXPECT_EQ(1, 1);
}