Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pbentes authored Dec 19, 2024
0 parents commit 5d4725d
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
54 changes: 54 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build

on:
push:
branches: [ main ]
paths-ignore:
- 'Docs/**'
- '**.md'
pull_request:
branches: [ main ]
paths-ignore:
- 'Docs/**'
- '**.md'

jobs:
linux-clang:
runs-on: ubuntu-22.04
name: Linux Clang
strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]

steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Configure CMake
run: cmake -B ${{github.workspace}}/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=clang++ .
- name: Build
run: cmake --build ${{github.workspace}}/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -j 2
- name: Test
working-directory: ${{github.workspace}}/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
run: ./tests/tests

msvc_cl:
runs-on: windows-latest
name: Visual Studio CL
strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]

steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Configure CMake
run: cmake -B ${{github.workspace}}/VS2022_CL -G "Visual Studio 17 2022" -A x64 .
- name: Build
run: msbuild VS2022_CL\Project.sln /property:Configuration=${{matrix.build_type}}
- name: Test
working-directory: ${{github.workspace}}\VS2022_CL\tests\${{matrix.build_type}}
run: .\tests.exe
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
.cache
.vs
build
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_FOLDER Dependencies)
add_subdirectory("vendor")
set(CMAKE_FOLDER /)

add_subdirectory("core")
add_subdirectory("app")
add_subdirectory("tests")

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "app")
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

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 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.

For more information, please refer to <https://unlicense.org>
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[![Build](https://github.com/pbentes/ProjectTemplate/actions/workflows/build.yml/badge.svg)](https://github.com/pbentes/ProjectTemplate/actions/workflows/build.yml)
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/pbentes/projecttemplate)](https://www.codefactor.io/repository/github/pbentes/projecttemplate)
![GitHub License](https://img.shields.io/github/license/pbentes/ProjectTemplate)

# C++ Project Starter Template

This is a quick-start project template for C++ projects which utilise a core/app project architecture. There are two included projects - one called core, and one called app. CMake is used to generate project files.

Core builds into a static library and is meant to contain common code intended for use in multiple applications. App builds into an executable and links the Core static library, as well as provides an include path to core's code.

## Getting Started

1) Clone this repository or use the "Use this template" button on GitHub to quickly set up your own repository based on this template
2) App/ and Core/ are the two projects - you can edit the names of these folders and their contents to suit
3) The three included CMake build files are CMakeLists.txt, core/CMakeLists.txt and app/CMakeLists.txt - you can edit these to customise your build configurations, edit the names of your projects and workspace/solution, etc.
4) Create a build folder, cd into it and run `cmake ..` to generate a project

To build the project run the following commands:

```
cmake -S . -B build
cmake --build build
```

## Included

- Some example code (in app/src, core/src and tests/src) to provide a starting point
- An example of how to use CMake to fetch dependencies in the vendor folder
- An example test written using the [GoogleTest](https://google.github.io/googletest/) library
- .gitignore to ignore project files and binaries
- Github Actions to check for build status and run the tests

## License

UNLICENSE (see UNLICENSE.txt for more details)

## Credits

This project template is inspired by TheCherno's [Project Template](https://github.com/TheCherno/ProjectTemplate/tree/master) using Premake5.
26 changes: 26 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.16)

set(ProjectName "app")
project(${ProjectName})

link_directories(
${core_BINARY_DIR}
)

file(GLOB_RECURSE APP_SRC
"src/*.cpp"
"src/*.h"
)

add_executable(${ProjectName} ${APP_SRC})

add_dependencies(${ProjectName} core)

target_include_directories( ${ProjectName}
PUBLIC ${core_SOURCE_DIR}/src
PUBLIC ${app_SOURCE_DIR}/src
)

target_link_libraries(${ProjectName}
PUBLIC core
)
6 changes: 6 additions & 0 deletions app/src/App.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Core.h"

int main()
{
Core::PrintHelloWorld();
}
15 changes: 15 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)

set(ProjectName "core")
project(${ProjectName})

file(GLOB_RECURSE CORE_SRC
"src/*.cpp"
"src/*.h"
)

add_library(${ProjectName} STATIC ${CORE_SRC})

target_include_directories( ${ProjectName}
PRIVATE ${core_SOURCE_DIR}/include
)
15 changes: 15 additions & 0 deletions core/src/Core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Core.h"

#include <iostream>

namespace Core {
void PrintHelloWorld()
{
std::cout << "Hello World!\n";
std::cin.get();
}

int AddInts(int a, int b) {
return a + b;
}
}
6 changes: 6 additions & 0 deletions core/src/Core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace Core {
void PrintHelloWorld();
int AddInts(int a, int b);
}
30 changes: 30 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.16)
enable_testing()

set(ProjectName "tests")
project(${ProjectName})

link_directories(
${core_BINARY_DIR}
)

file(GLOB_RECURSE TEST_SRC
"src/*.cpp"
"src/*.h"
)

add_executable(${ProjectName} ${TEST_SRC})
add_dependencies(${ProjectName} core)

target_include_directories( ${ProjectName}
PUBLIC ${core_SOURCE_DIR}/src
PUBLIC ${googletest_SOURCE_DIR}/googletest/include
)

target_link_libraries(${ProjectName}
PUBLIC core
PUBLIC GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(${ProjectName})
7 changes: 7 additions & 0 deletions tests/src/HelloTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>

#include <Core.h>

TEST(Core, AddInts) {
EXPECT_EQ(Core::AddInts(5, 3), 8);
}
4 changes: 4 additions & 0 deletions vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.16)
include(FetchContent)

include(google_test.cmake)
10 changes: 10 additions & 0 deletions vendor/google_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.16)
include(FetchContent)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

0 comments on commit 5d4725d

Please sign in to comment.