Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Feat fetch content (bsamseth#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
doruirimescu authored Sep 5, 2021
1 parent 6d5285a commit b1f094d
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 53 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
submodules: true

- name: Configure (${{ matrix.configuration }})
run: cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=${{ matrix.configuration }}
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# This file specifies how the project should be built, using CMake.
# If you are unfamiliar with CMake, don't worry about all the details.
# The sections you might want to edit are marked as such, and
# The sections you might want to edit are marked as such, and
# the comments should hopefully make most of it clear.
#
# For many purposes, you may not need to change anything about this file.

cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.14)

# Set project name, version and laguages here. (change as needed)
# Version numbers are available by including "exampleConfig.h" in
# Version numbers are available by including "exampleConfig.h" in
# the source. See exampleConfig.h.in for some more details.
project(CPP_BOILERPLATE VERSION 1.2.3.4 LANGUAGES CXX)

Expand Down Expand Up @@ -70,10 +70,10 @@ target_enable_lto(main optimized) # enable link-time-optimization if available

# Set the properties you require, e.g. what C++ standard to use. Here applied to library and main (change as needed).
set_target_properties(
${LIBRARY_NAME} main
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
${LIBRARY_NAME} main
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

Expand Down
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/bsamseth/cpp-project.svg)](http://isitmaintained.com/project/bsamseth/cpp-project "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/bsamseth/cpp-project.svg)](http://isitmaintained.com/project/bsamseth/cpp-project "Percentage of issues still open")

# Boiler plate for C++ projects
# Boiler plate for C++ projects

This is a boiler plate for C++ projects. What you get:

Expand Down Expand Up @@ -41,16 +41,16 @@ This is a boiler plate for C++ projects. What you get:
```

Sources go in [src/](src/), header files in [include/](include/), main programs in [app/](app), and
tests go in [tests/](tests/) (compiled to `unit_tests` by default).
tests go in [tests/](tests/) (compiled to `unit_tests` by default).

If you add a new executable, say `app/hello.cpp`, you only need to add the following two lines to [CMakeLists.txt](CMakeLists.txt):
If you add a new executable, say `app/hello.cpp`, you only need to add the following two lines to [CMakeLists.txt](CMakeLists.txt):

``` cmake
add_executable(main app/main.cpp) # Name of exec. and location of file.
target_link_libraries(main PRIVATE ${LIBRARY_NAME}) # Link the executable to lib built from src/*.cpp (if it uses it).
```

You can find the example source code that builds the `main` executable in [app/main.cpp](app/main.cpp) under the `Build` section in [CMakeLists.txt](CMakeLists.txt).
You can find the example source code that builds the `main` executable in [app/main.cpp](app/main.cpp) under the `Build` section in [CMakeLists.txt](CMakeLists.txt).
If the executable you made does not use the library in [src/](src), then only the first line is needed.


Expand Down Expand Up @@ -89,20 +89,12 @@ upload this to Coveralls.io and/or Codecov.io
### Using the GitHub template
Click the `Use this template` button to make a new repository from this template.

**NB**: GitHub templates do not carry over submodules, which means you need to add those back _before_ you can build the project. Run the following after you have generated your new project:
``` bash
> git clone https://github.com/<your-username>/<your-repo-name>
> git submodule add https://github.com/onqtam/doctest.git external/doctest
> git commit -a --amend --no-edit
> git push --force
```

### From command line
When starting a new project, you probably don't want the history of this repository. To start fresh you can use
the [setup script](setup.sh) as follows:
``` bash
> git clone --recurse-submodules https://github.com/bsamseth/cpp-project # Or use ssh-link if you like.
> git clone https://github.com/bsamseth/cpp-project # Or use ssh-link if you like.
> cd cpp-project
> bash setup.sh
```
The result is a fresh Git repository with one commit adding all files from the boiler plate.
The result is a fresh Git repository with one commit adding all files from the boiler plate.
2 changes: 1 addition & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// users, this can be left out.
#ifdef ENABLE_DOCTEST_IN_LIBRARY
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
#include "doctest/doctest.h"
#endif

#include <iostream>
Expand Down
12 changes: 4 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ platform:
configuration:
- Debug
- Release

# environment:
# matrix:
# - TOOLSET: v140

matrix:
fast_finish: false

Expand All @@ -27,20 +27,16 @@ init:
- cmd: cmake --version
- cmd: msbuild /version

install:
- git submodule update --init --recursive

before_build:
- cmake . -Bbuild -A%PLATFORM% -DCMAKE_BUILD_TYPE=%configuration%

build:
project: build/CPP_BOILERPLATE.sln
parallel: true
verbosity: minimal

test_script:
- cd build
- set CTEST_OUTPUT_ON_FAILURE=1
- ctest -C %configuration%
- ctest -C %configuration%
- cd ..

12 changes: 9 additions & 3 deletions cmake/Doctest.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
if(ENABLE_DOCTESTS)
add_definitions(-DENABLE_DOCTEST_IN_LIBRARY)
endif()
include(FetchContent)
FetchContent_Declare(
DocTest
GIT_REPOSITORY "https://github.com/onqtam/doctest"
GIT_TAG "932a2ca50666138256dae56fbb16db3b1cae133a"
)

add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE ${PROJECT_SOURCE_DIR}/external/doctest/doctest)
FetchContent_MakeAvailable(DocTest)
include_directories(${DOCTEST_INCLUDE_DIR})
endif()
1 change: 0 additions & 1 deletion external/doctest
Submodule doctest deleted from 503de0
2 changes: 1 addition & 1 deletion include/example.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Dummy {


#ifdef ENABLE_DOCTEST_IN_LIBRARY
#include "doctest.h"
#include "doctest/doctest.h"
TEST_CASE("we can have tests in headers if we want")
{
Dummy d;
Expand Down
6 changes: 1 addition & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ email=$(git config user.email)
if [[ "$1" ]]; then
git commit --amend --author="$1"
else
git commit --amend --author="$name <$email>"
git commit --amend --author="$name <$email>"
fi

# Initialize submodules: This should already be done when cloning, but there are ways to muck it
# up if you do things in the wrong order. So just to be sure, we do it now.
git submodule update --init --recursive

# Remove the remote (you probably want your own instead).
git remote remove origin
2 changes: 1 addition & 1 deletion src/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool Dummy::doSomething() {


#ifdef ENABLE_DOCTEST_IN_LIBRARY
#include "doctest.h"
#include "doctest/doctest.h"
TEST_CASE("we can have tests written here, to test impl. details")
{
CHECK(true);
Expand Down
9 changes: 4 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.14)

# List all files containing tests. (Change as needed)
set(TESTFILES # All .cpp files in tests/
Expand All @@ -17,9 +17,9 @@ target_link_libraries(${TEST_MAIN} PRIVATE ${LIBRARY_NAME} doctest)
set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
target_set_warnings(${TEST_MAIN} ENABLE ALL AS_ERROR ALL DISABLE Annoying) # Set warnings (if needed).

set_target_properties(${TEST_MAIN} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
set_target_properties(${TEST_MAIN} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

Expand All @@ -30,4 +30,3 @@ add_test(

# Adds a 'coverage' target.
include(CodeCoverage)

2 changes: 1 addition & 1 deletion tests/dummy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include "example.h"

// Tests that don't naturally fit in the headers/.cpp files directly
Expand Down
2 changes: 1 addition & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "doctest/doctest.h"

// This is all that is needed to compile a test-runner executable.
// More tests can be added here, or in a new tests/*.cpp file.

0 comments on commit b1f094d

Please sign in to comment.