Code Monkey home page Code Monkey logo

cpp_start's Introduction

cpp_start

Gitter CI Quality Gate Status

cpp_start is a cmake - C++ starter project.

Build

$ git clone https://github.com/soerenPeters/cpp_start.git
$ cd cpp_start && mkdir build && cd build
$ cmake ..
$ make
$ ctest

CMake Options

  • BUILD_SHARED_LIBS : Build all targets as shared libraries in this project. (ON)
  • CS_BUILD_WARNINGS_AS_ERRORS : Make all warnings into errors. (OFF)
  • CS_BUILD_UNIT_TESTS : Create unit test targets. (ON)
  • CS_ENABLE_CATCH2 : Fetch and link the unit-Test against catch2. (ON)
  • CS_ENABLE_GTEST : Fetch and link the unit-tests against googletest. (ON)
  • CS_ENABLE_COVERAGE : Add the --coverage compiler flag. (OFF)
  • CS_ENABLE_CLANG_TIDY : Enable clang-tidy checks. (OFF)
  • CS_ENABLE_CPPCHECK : Enable cppcheck. (OFF)
  • CS_ENABLE_INCLUDE_WHAT_YOU_USE: "Enable Include what you use. (OFF)
  • CS_USE_OPENMP : use OpenMP. (OFF)
  • CS_USE_MPI : use MPI. (OFF)

Compiler flags

Compiler flags can be set individually for each compiler in "CMake/compilerflags/CS_COMPILER_FLAGS_CXX .cmake". The following cmake lists will be set as private properties for each target:

  • CS_COMPILER_FLAGS_CXX
  • CS_COMPILER_FLAGS_CXX_DEBUG
  • CS_COMPILER_FLAGS_CXX_RELEASE
  • CS_COMPILER_DEFINITION
  • CS_LINK_OPTIONS

Github workflow:

Set up Sonarcloud:

  • link the github project on sonarcloud.io
  • generate a security token on sonarcloud.io: User > My Account > Security
  • add this token as a github project secret with the name SONAR_TOKEN

Note: sonar-project.properties needs to be adapted individually. Further information can be found here in the sonarcloud docs. To exclude the test files from the sonarcloud code coverage report, the test files must be named after the pattern 'sonar.coverage.exclusions'.

Dependencies

There are dependencies on the following projects. These are fetched into the build order during cmake.

Further dependencies are not included. If they are enable in a cmake option they must be provided within the environment.

  • Boost
  • OpenMP
  • MPI
  • cppcheck
  • clang-tidy
  • lizard

Usage

Add new targets

  • create a new folder in the src/ directory (e.g. by copying the adder directory.)
  • add a new CMakeLists.txt file and the corresponding source and test files
project(project_name CXX)

set(TARGET_NAME
        my_target_name)

set(SOURCE_FILES
        foo.cpp)

set(TEST_FILES
        test_foo.cpp)

set(PUBLIC_LINK)

set(PRIVATE_LINK)

add_target()
  • add an add_subdirectory() in the root CMakeLists.txt

If the option BUILD_UNIT_TESTS is set to ON and TEST_FILES are added in the CMakeLists, cmake will create a test executable target with the name <my_target_name>Test and add it to ctest.

Use in other projects

This cmake template can easily be used in other projects:

include(FetchContent)
FetchContent_Declare(
        cpp_start
        GIT_REPOSITORY https://github.com/soerenpeters/cpp_start.git
        GIT_TAG        v0.1-alpha
)
FetchContent_Populate(cpp_start)

include(${CMAKE_BINARY_DIR}/_deps/cpp_start-src/CMake/cpp_starter.cmake)

An example usage can be found here.

cpp_start's People

Contributors

gitter-badger avatar soerenpeters avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

gitter-badger

cpp_start's Issues

Adds catch support.

Let the cmake user choose if he wants to have catch or gtest as an unit testing framework.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.