bsamseth / cpp-project Goto Github PK
View Code? Open in Web Editor NEWBoiler plate template for C++ projects, with CMake, Doctest, Travis CI, Appveyor, Github Actions and coverage reports.
License: The Unlicense
Boiler plate template for C++ projects, with CMake, Doctest, Travis CI, Appveyor, Github Actions and coverage reports.
License: The Unlicense
Hi there.
Is there a website for this repo?
Because if you don't have, well, this repo can simply be turned into a website right away. Others will discover this project in that website.
Steps:
Go to Settings and look for GitHub Pages
, scroll down. That's almost at the bottom.
You will see there: Branch:none
, so you should change that to master
because you have a README.md
file in the master repo. This will be your page. Click Save
first.
Then click Choose a theme
, you select a predefined theme of your site.
Visit your site now! The URL will be https://bsamseth.github.io/cpp-project
.
If you were amazed by that, simply read the documentation about GitHub Pages.
Thx a lot for sharing the repo! I have been trying to find a repo template for cpp with support for CI and your repo is a great template for my project.
However, I was unable to run cmake .. -DCMAKE_BUILD_TYPE=coverage
after following the steps.
The error is as follow
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done-- Found Doxygen: /usr/bin/doxygen (found version "1.8.13") found components: doxygen dot
-- IPO is supported
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Object library target "example" may not link to anything.
-- Configuring incomplete, errors occurred!
See also "/workspaces/PoissonDiscSampling/build/CMakeFiles/CMakeOutput.log".
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=coverage^C
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# cd ../^C
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# rm -rf ./*
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=coverage -DENABLE_DOCTESTS=OFF
CMake Error: The source directory "/workspaces/PoissonDiscSampling/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build/build# cd ..
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# rm -rf ./*
root@c067bbd707d0:/workspaces/PoissonDiscSampling/build# cmake .. -DCMAKE_BUILD_TYPE=coverage -DENABLE_DOCTESTS=OFF
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.13") found components: doxygen dot
-- IPO is supported
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Object library target "engine" may not link to anything.
-- Configuring incomplete, errors occurred!
Thought it might be related to the git submodule status, I try using git submodule add
to manually add doctest but still no luck.
code to reproduce (cmake version 3.10.2):
git clone https://github.com/bsamseth/cpp-project.git
cd cpp-project
sh setup.sh
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=coverage
Github Action would also return failure during build step, see here
I think the CMake minimum required version should be set to 3.12 because of using target_link_libraries with object libraries.
I got the following on CMake v 3.10 :
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Object library target "engine" may not link to anything.
Which is gone by updating to the latest version.
More on this:
https://gitlab.kitware.com/cmake/cmake/-/issues/18010
https://gitlab.kitware.com/cmake/cmake/-/issues/14778
Is a new feature that github added today https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/
I trty to add Conan.cmake
in cmake
directory.
if(${PROJECT_NAME}_ENABLE_CONAN)
#
# Setup Conan requires and options here:
#
set(${PROJECT_NAME}_CONAN_REQUIRES "")
set(${PROJECT_NAME}_CONAN_OPTIONS "")
#
# If `conan.cmake` (from https://github.com/conan-io/cmake-conan) does not exist, download it.
#
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(
STATUS
"Downloading conan.cmake from https://github.com/conan-io/cmake-conan..."
)
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.16/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
)
message(STATUS "Cmake-Conan downloaded succesfully.")
endif()
message(${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_add_remote(NAME bincrafters
URL
https://api.bintray.com/conan/bincrafters/public-conan
)
conan_cmake_run(
REQUIRES
${CONAN_REQUIRES}
OPTIONS
${CONAN_OPTIONS}
BASIC_SETUP
CMAKE_TARGETS # Individual targets to link to
BUILD
missing
)
message("Conan is setup and all requires have been installed.")
endif()
then add option in root CMakeLists.txt
option(${PROJECT_NAME}_ENABLE_CONAN "Enable the Conan package manager for this project." ON)
...
include(Conan)
conanfile.txt
[requires]
fmt/7.0.3
[generators]
cmake
If add CONAN_PKG::fmt
to
target_link_libraries(main PRIVATE ${LIBRARY_NAME})
like this:
target_link_libraries(main PRIVATE ${LIBRARY_NAME} PUBLIC CONAN_PKG::fmt)
CMake build failed:
CMake Error at CMakeLists.txt:69 (add_executable):
Target "main" links to target "CONAN_PKG::fmt" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
Any suggestion?
Build with Debug mode in CLion, make doc
failed with:
make: *** No rule to make target 'doc'. Stop.
Hi,
Overall, I find this repository useful but I have to ask - how could I get verbose information after make test
(failed and succeed cases)?
Right now I use ./unit_tests
for more information or I go into build/Testing/Temporary/LastTest.log
for detailed outputs. I would like to see it automatically after make test
thought.
Best regards
Lukasz
-- The C compiler identification is AppleClang 10.0.0.10001044
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default to Debug
-- Building with the following extra flags: -Wall -Wextra
CMake Error at cmake/CodeCoverage.cmake:58 (MESSAGE):
Compiler is not GNU gcc or Clang! Aborting...
Call Stack (most recent call first):
CMakeLists.txt:94 (include)
-- Configuring incomplete, errors occurred!
See also "/Users/lee/Studio/git/cpp-project/build/CMakeFiles/CMakeOutput.log".
Hi bsamseth,
First of all, thank you for this boilerplate which gives me a good idea on how to organise folder and cmake, however i have an issue when following your steps, when running the command: make i get this error
[ 16%] Building CXX object CMakeFiles/test.dir/src/example.cpp.o In file included from /home/tom/Projects/test/src/example.cpp:1: /home/tom/Projects/test/include/example.h:22:10: fatal error: doctest.h: No such file or directory 22 | #include "doctest.h" | ^~~~~~~~~~~ compilation terminated. make[2]: *** [CMakeFiles/test.dir/build.make:63: CMakeFiles/test.dir/src/example.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:452: CMakeFiles/test.dir/all] Error 2 make: *** [Makefile:95: all] Error 2
Any idea what is happening here?
In CMakeLists.txt
file, line 12 should be
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
instead of
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
,
I found this out after I tried to debug main.cpp
,
breakpoints could not be set because flag -g was not set.
Same with line 17, should be
set(CMAKE_CXX_FLAGS "-Wall -O2")
Also, after you pull googletest, all paths to googletest need one more segment googletest,
For example
{PROJECT_SOURCE_DIR}/external/googletest
should become
{PROJECT_SOURCE_DIR}/external/googletest/googletest
and so on.
Great boilerplate repo, very useful.
It would be great to add commands to this template for code formatting.
Probably using a clang-format
or some other suitable utility.
make fmt # formating code
make fmt-check # check format code
i have this file in include/abin.hpp
#ifndef ABIN_VEC_HPP
#define ABIN_VEC_HPP
namespace Vectorial
{
const int NODO_NULO = -1;
template <typename T>
class Abin
{
public:
typedef int nodo;
explicit Abin(int max);
Abin(const Abin<T> &a);
Abin<T> &operator=(const Abin<T> &a);
void insertarRaiz(const T &e);
void eliminarRaiz();
void insertarHijoIzquierdo(nodo n, const T &e);
void insertarHijoDerecho(nodo n, const T &e);
void eliminarHijoIzquierdo(nodo n);
void eliminarHijoDerecho(nodo n);
bool vacio() const { return size == 0; }
const T &elemento(nodo n) const;
T &elemento(nodo n);
nodo raiz() { return (size > 0) ? 0 : NODO_NULO; }
nodo padre(nodo n) const;
nodo hijoIzquierdo(nodo n) const;
nodo hijoDerecho(nodo n) const;
~Abin() { delete[] nodos; }
private:
int max_size;
int size;
class celda
{
public:
T elemento;
nodo padre, h_izq, h_dch;
celda(const T &elto, nodo p = NODO_NULO, nodo h_d = NODO_NULO, nodo h_i = NODO_NULO) : elemento{elto}, padre{p}, h_izq{h_i}, h_dch{h_d} {}
celda(const celda &) = default;
celda &operator=(const celda &) = default;
};
celda *nodos;
};
} // namespace Vectorial
#endif
and this one in src/abin.cpp
#include "abin.hpp"
#include <algorithm>
#include <cassert>
template <typename T>
Vectorial::Abin<T>::Abin(int max) : max_size{max}, size{0}, nodos{new celda[max]} {}
template <typename T>
Vectorial::Abin<T>::Abin(const Abin<T> &a) : nodos{new celda[a.max_size]}, max_size{a.max_size}, size{a.size}
{
std::copy(a.nodos, a.nodos + (a.size - 1), nodos);
}
template <typename T>
void Vectorial::Abin<T>::insertarRaiz(const T &e)
{
assert(size == 0);
nodos[size++] = celda(e);
}
template <typename T>
void Vectorial::Abin<T>::insertarHijoIzquierdo(nodo n, const T &e)
{
assert(n >= 0 && n < size);
assert(nodos[n].h_izq == NODO_NULO);
assert(size < max_size);
nodos[n].h_izq = size;
nodos[size++] = celda(e, n);
}
template <typename T>
void Vectorial::Abin<T>::insertarHijoDerecho(nodo n, const T &e)
{
assert(n >= 0 && n < size);
assert(nodos[n].h_dch == NODO_NULO);
assert(size < max_size);
nodos[n].h_dch = size;
nodos[size++] = celda(e, n);
}
template <typename T>
void Vectorial::Abin<T>::eliminarHijoIzquierdo(nodo n)
{
auto h_izq = nodos[n].h_izq;
assert(n >= 0 && n < size);
assert(h_izq != NODO_NULO);
assert(nodos[h_izq].h_izq == NODO_NULO &&
nodos[h_izq].h_dch == NODO_NULO);
if (h_izq != size - 1)
{
nodos[h_izq] = nodos[size - 1];
if (nodos[nodos[h_izq].padre].h_izq == size - 1)
nodos[nodos[h_izq].padre].h_izq = h_izq;
else
nodos[nodos[h_izq].padre].h_dch = h_izq;
if (nodos[h_izq].h_izq != NODO_NULO)
nodos[nodos[h_izq].h_izq].padre = h_izq;
if (nodos[h_izq].h_dch != NODO_NULO)
nodos[nodos[h_izq].h_dch].padre = h_izq;
}
nodos[h_izq] = NODO_NULO;
--size;
}
template <typename T>
void Vectorial::Abin<T>::eliminarHijoDerecho(nodo n)
{
auto h_dch = nodos[n].h_dch;
assert(n >= 0 && n < size);
assert(h_dch != NODO_NULO);
assert(nodos[h_dch].h_dch == NODO_NULO &&
nodos[h_dch].h_izq == NODO_NULO);
if (h_dch != size - 1)
{
nodos[h_dch] = nodos[size - 1];
if (nodos[nodos[h_dch].padre].h_dch == size - 1)
nodos[nodos[h_dch].padre].h_dch = h_dch;
else
nodos[nodos[h_dch].padre].h_izq = h_dch;
if (nodos[h_dch].h_izq != NODO_NULO)
nodos[nodos[h_dch].h_izq].padre = h_dch;
if (nodos[h_dch].h_dch != NODO_NULO)
nodos[nodos[h_dch].h_dch].padre = h_dch;
}
nodos[h_dch] = NODO_NULO;
--size;
}
template <typename T>
inline void Vectorial::Abin<T>::eliminarRaiz()
{
assert(size == 1);
size = 0;
}
template <typename T>
inline const T &Vectorial::Abin<T>::elemento(nodo n) const
{
assert(n >= 0 && n < size);
return nodos[n].elemento;
}
template <typename T>
inline T &Vectorial::Abin<T>::elemento(nodo n)
{
assert(n >= 0 && n < size);
return nodos[n].elemento;
}
template <typename T>
inline typename Vectorial::Abin<T>::nodo Vectorial::Abin<T>::padre(nodo n) const
{
assert(n >= 0 && n < size);
return nodos[n].padre;
}
template <typename T>
inline typename Vectorial::Abin<T>::nodo Vectorial::Abin<T>::hijoIzquierdo(nodo n) const
{
assert(n >= 0 && n < size);
return nodos[n].h_izq;
}
template <typename T>
inline typename Vectorial::Abin<T>::nodo Vectorial::Abin<T>::hijoDerecho(nodo n) const
{
assert(n >= 0 && n < size);
return nodos[n].h_dch;
}
template <typename T>
Vectorial::Abin<T> &Vectorial::Abin<T>::operator=(const Abin<T> &a)
{
if (this != &a)
{
if (max_size < a.max_size)
{
delete[] nodos;
max_size = a.max_size;
nodos = new celda[max_size];
}
size = a.size;
std::copy(a.nodos, a.nodos + (a.size - 1), nodos);
}
return *this;
}
When i call the constructor i getting this error:
[build] FAILED: main.x
[build] : && /usr/bin/clang++ -Wall -Wextra -g -O0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/main.x.dir/app/main.cpp.o -o main.x libengine.a && :
[build] Undefined symbols for architecture x86_64:
[build] "Vectorial::Abin<int>::Abin(int)", referenced from:
[build] _main in main.cpp.o
[build] ld: symbol(s) not found for architecture x86_64
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
and my app/main.cpp
#include <iostream>
#include "abin.hpp"
using namespace Vectorial;
int main()
{
Abin<int> A(2);
std::cout << A.vacio() << std::endl;
}
I'd like to have a parallel branch with a setup using C++20 modules instead of header files. At some later point, this would be merged to master.
As I don't personally have experience with modules in C++ yet, this would be great to get help with as a pull request.
Got assigned a project to make a program that handles passport applicants in the order the come for regulars and give priority to some special applicants and the program has to use a tree to store applicants info and later transfer it's content to priority queue that handles scheduling. Pls I need help
6 warnings
macos-clang
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
Show more Show less
macos-clang
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
Show more Show less
linux-gcc
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
Show more Show less
linux-gcc
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
Show more Show less
windows-msvc
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
Show more Show less
windows-msvc
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
Hi!
Very interesting and very helpful repository! Thank you for sharing it!
Do you plan to add support for different compilers and examples of usage for Windows users?
Thank you!
Click Use this template
create new repo:
2020-08-08T15:16:55.1289136Z ##[group]Run cmake --build build
2020-08-08T15:16:55.1289456Z �[36;1mcmake --build build�[0m
2020-08-08T15:16:55.1337574Z shell: /bin/bash -e {0}
2020-08-08T15:16:55.1337732Z ##[endgroup]
2020-08-08T15:16:55.1546923Z Scanning dependencies of target engine
2020-08-08T15:16:55.1581962Z [ 16%] Building CXX object CMakeFiles/engine.dir/src/example.cpp.o
2020-08-08T15:16:55.1781727Z In file included from /home/runner/work/cpp-test/cpp-test/src/example.cpp:1:0:
2020-08-08T15:16:55.1782976Z /home/runner/work/cpp-test/cpp-test/include/example.h:22:10: fatal error: doctest.h: No such file or directory
2020-08-08T15:16:55.1783777Z #include "doctest.h"
2020-08-08T15:16:55.1784241Z ^~~~~~~~~~~
2020-08-08T15:16:55.1784692Z compilation terminated.
2020-08-08T15:16:55.1792650Z make[2]: *** [CMakeFiles/engine.dir/src/example.cpp.o] Error 1
2020-08-08T15:16:55.1794332Z CMakeFiles/engine.dir/build.make:79: recipe for target 'CMakeFiles/engine.dir/src/example.cpp.o' failed
2020-08-08T15:16:55.1798801Z make[1]: *** [CMakeFiles/engine.dir/all] Error 2
2020-08-08T15:16:55.1799744Z CMakeFiles/Makefile2:143: recipe for target 'CMakeFiles/engine.dir/all' failed
2020-08-08T15:16:55.1801984Z make: *** [all] Error 2
2020-08-08T15:16:55.1802504Z Makefile:111: recipe for target 'all' failed
2020-08-08T15:16:55.1810499Z ##[error]Process completed with exit code 2.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.