Skip to content

Commit

Permalink
Merge pull request #18 from TomVer99/feature/version-2.0.0
Browse files Browse the repository at this point in the history
Feature/version 2.0.0
  • Loading branch information
TomVer99 authored May 20, 2023
2 parents 75e8868 + 16ea970 commit 288e82d
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 172 deletions.
3 changes: 3 additions & 0 deletions .github/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enhancement: ['feature/*', 'feat/*', 'enhancement/*']
bug: ['bug/*', 'fix/*', 'fixes/*', 'bugfix/*', 'bugfixes/*']
documentation: ['docs/*', 'doc/*', 'documentation/*']
116 changes: 20 additions & 96 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,44 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ opened, reopened, review_requested, ready_for_review ]
workflow_dispatch:
inputs:
reason:
description: 'Reason/Run name'
required: true
default: 'Manual trigger'
debug_linux:
description: 'Build and test on Linux using debug configuration'
required: true
type: boolean
default: true
release_linux:
description: 'Build and test on Linux using release configuration'
required: true
type: boolean
default: true
debug_windows:
description: 'Build and test on Windows using debug configuration'
required: true
type: boolean
default: false
release_windows:
description: 'Build and test on Windows using release configuration'
required: true
type: boolean
default: false

run-name: ${{ inputs.reason || github.event.pull_request.title || github.event.head_commit.message || 'unexpected workflow trigger' }}

jobs:
build_debug_and_test_linux:

if: ${{ (github.event_name != 'workflow_dispatch') || (github.event.inputs.debug_linux == 'true') }}
env:
SKIP_CI: false

jobs:
check:
runs-on: ubuntu-latest

env:
BUILD_TYPE: Debug

outputs:
skip-ci: ${{ env.SKIP_CI }}
steps:

- uses: actions/checkout@v3

- name: configure
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}

build_release_and_test_linux:

if: ${{ (github.event_name != 'workflow_dispatch') || (github.event.inputs.release_linux == 'true') }}
- id: name-check
name: Check PR name
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^doc\/.*$|^docs\/.*$|^no-ci\/.*$ ]]; then
echo "Skipping CI for documentation-only PR"
echo "SKIP_CI=true" >> $GITHUB_ENV
exit 0
fi
build_debug_and_test_linux:
needs: check
if: ${{ needs.check.outputs.skip-ci == 'false' }}
runs-on: ubuntu-latest

env:
BUILD_TYPE: Release
BUILD_TYPE: Debug

steps:

- uses: actions/checkout@v3

- name: configure
Expand All @@ -79,50 +49,4 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}

build_debug_and_test_windows:

if: ${{ (github.event_name != 'workflow_dispatch') || (github.event.inputs.debug_windows == 'true') }}

runs-on: windows-latest

env:
BUILD_TYPE: Debug

steps:

- uses: actions/checkout@v3

- name: configure
run: cmake -B ${{github.workspace}}\build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}\build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}\build
run: ctest -C ${{env.BUILD_TYPE}}

build_release_and_test_windows:

if: ${{ (github.event_name != 'workflow_dispatch') || (github.event.inputs.release_windows == 'true') }}

runs-on: windows-latest

env:
BUILD_TYPE: Release

steps:

- uses: actions/checkout@v3

- name: configure
run: cmake -B ${{github.workspace}}\build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}\build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}\build
run: ctest -C ${{env.BUILD_TYPE}}
run: ctest -j18 -C ${{env.BUILD_TYPE}} -T test --output-on-failure
4 changes: 1 addition & 3 deletions .github/workflows/Code-Hygiene.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Code Hygiene

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ opened, reopened, review_requested, ready_for_review ]
workflow_dispatch:
inputs:
reason:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PR Labeler
on:
pull_request:
types: [ opened, reopened ]

permissions:
contents: read

jobs:
pr-labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: TimonVS/pr-labeler-action@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/pr-labeler.yml
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
set(CMakeMinimumVersion 3.22.1)

cmake_minimum_required(VERSION ${CMakeMinimumVersion})
cmake_minimum_required(VERSION 3.22.1)

set(ProjectName CHANGE_ME) # <Var name> <Name of the project>
set(ProjectRunName ${ProjectName}_Run) # <Var name> <Name of the executable>
set(ProjectTestName ${ProjectName}_Test) # <Var name> <Name of the executable>

project(${ProjectName} C CXX) # project uses C and C++ languages
# set output directories for executables and libraries
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release/executables )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release/libraries )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release/libraries )

project(${ProjectName} C CXX) # project uses C and C++ languages
set(CMAKE_C_STANDARD 99) # C standard is C99
set(CMAKE_CXX_STANDARD 17) # C++ standard is C++17
set(CMAKE_CXX_STANDARD 20) # C++ standard is C++20
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wall -Wextra -Wpedantic)
# add_compile_options(-Werror)
elseif(MSVC)
add_compile_options(/W4)
# add_compile_options(/WX)
endif()

enable_testing()

# get google test
include(FetchContent)

# get google test
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# C(++) W/ CMake and Google Test using GitHub actions Template

![C](https://img.shields.io/badge/c-%2300599C.svg?style=for-the-badge&logo=c&logoColor=white)
![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=for-the-badge&logo=c%2B%2B&logoColor=white)
![CMake](https://img.shields.io/badge/CMake-%2300599C.svg?style=for-the-badge&logo=cmake&logoColor=white)
![GitHub Actions](https://img.shields.io/badge/github%20actions-%2300599C.svg?style=for-the-badge&logo=githubactions&logoColor=white)

---

![Release](https://img.shields.io/github/v/release/TomVer99/C-CPP_CMake_GTest-GithubActions?label=Release&style=flat-square)

![Maintained](https://img.shields.io/maintenance/yes/2022?label=Maintained&style=flat-square)
![Maintained](https://img.shields.io/maintenance/yes/2023?label=Maintained&style=flat-square)
![Issues](https://img.shields.io/github/issues-raw/TomVer99/C-CPP_CMake_GTest-GithubActions?label=Issues&style=flat-square)
[![CI](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fatrox%2Fsync-dotenv%2Fbadge&label=CI&style=flat-square)](https://actions-badge.atrox.dev/TomVer99/C-CPP_CMake_GTest-GithubActions/CI)
[![Code-Hygiene](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fatrox%2Fsync-dotenv%2Fbadge&label=Code-Hygiene&style=flat-square)](https://actions-badge.atrox.dev/TomVer99/C-CPP_CMake_GTest-GithubActions/Code-Hygiene)
Expand All @@ -11,8 +18,17 @@

## Description

This template is meant to be used as a starting point for C/C++ projects using CMake and Google Test. It also includes GitHub Actions workflows to build and test the project plus check for code hygiene.
This template is meant to be used as a starting point for C/C++ projects using CMake and Google Test.

It includes:

* CMake setup for building a library and an executable
* Google Test setup for unit testing
* GitHub Actions setup for CI
* Only runs on PR creation and on Review requests
* GitHub Actions setup for Code Hygiene (Just end of file newlines for now)
* Automatic Labeling of Pull Requests

## Wiki
## Wiki (outdated)

The WiKi contains a lot of information about the template. Please check it out [here](https://github.com/TomVer99/C-CPP_CMake_GTest-GithubActions/wiki) or via the WiKi button at the top of the webpage.
37 changes: 15 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
cmake_minimum_required(VERSION ${CMakeMinimumVersion})
add_executable(${ProjectRunName} main.cpp)

# Add headers here. If no headers, leave empty.
set(Headers
example.hpp
# All the libs need to be linked here to make them available to the executable
target_link_libraries(${ProjectRunName} PRIVATE
ExampleLib
ExampleNestedTopLib
ExampleNestedBottomLib
)

# Add sources here. If no sources, leave empty.
set(Sources
example.cpp
)

# Builds a static library for gtest
add_library(${ProjectName} STATIC ${Sources} ${Headers})
set(PROJECT_LIB_EXAMPLE_NAME exampleLib)
add_library(${PROJECT_LIB_EXAMPLE_NAME} INTERFACE)

# Builds an executable to run
add_executable(${ProjectRunName} main.cpp ${Sources} ${Headers})
# All the libs need to be linked here to make them available to the library
target_link_libraries(${PROJECT_LIB_EXAMPLE_NAME} INTERFACE
ExampleLib
ExampleNestedTopLib
ExampleNestedBottomLib
)

# Adds a subdirectory to the project
add_subdirectory(Example)

# Links code to test. Simply add more libraries after the example.
# This is not folder specific.
# target_link_libraries(${ProjectName} ExampleLib ExampleLib2)
target_link_libraries(${ProjectName} ExampleLib)

# Same as above, but for the executable
target_link_libraries(${ProjectRunName} ExampleLib)
add_subdirectory(NestedDirExample)
13 changes: 6 additions & 7 deletions src/Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
cmake_minimum_required(VERSION ${CMakeMinimumVersion})

# Add headers here
set(Headers
example2.hpp
example.hpp
)

# Add sources here
set(Sources
example2.cpp
example.cpp
)

# Makes a library from the sources and headers. First argument is the name of the library (used in src/CMakeLists.txt).
add_library(ExampleLib STATIC ${Sources} ${Headers})

target_include_directories(ExampleLib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/NestedDirExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(Headers
nestedTop.hpp
)

set(Sources
nestedTop.cpp
)

add_library(ExampleNestedTopLib STATIC ${Sources} ${Headers})

target_include_directories(ExampleNestedTopLib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

add_subdirectory(NestedDir)
17 changes: 17 additions & 0 deletions src/NestedDirExample/NestedDir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(Headers
nestedBottom.hpp
)

set(Sources
nestedBottom.cpp
)

add_library(ExampleNestedBottomLib STATIC ${Sources} ${Headers})

target_link_libraries(ExampleNestedBottomLib PRIVATE
ExampleNestedTopLib
)

target_include_directories(ExampleNestedBottomLib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
Loading

0 comments on commit 288e82d

Please sign in to comment.