Giter Site home page Giter Site logo

cppprojecttemplate's Introduction

CppProjectTemplate

linux vs2019 vs2017 mingw

C++ CMake project template with Hunter package manager

Prerequisite

  • CMake >= 3.21.0
  • C++ compiler (gcc, msvc, mingw)
  • IDE related (optional, only for VSCode)
    • VSCode
    • VSCode plugin - C/C++
    • VSCode plugin - CMake
    • VSCode plugin - CMake Tools

For MinGW users:

Please remember to set the MinGW to the PATH environment.

Getting Started

This template is based on CMake and aimed to minimize the CMake build script programming effort for the developer.

But we still recommend the users of this template to learn the CMake language.

Create C++ repo

  1. Press the Use this template from CppProjectTemplate
  2. Fill repo name & description
  3. Press Create repository from template

Use with VSCode

Here is a flow from CMake configure to Run & Debug the code.

  1. Install the VSCode and related plugins(See Prerequisite)
  2. Clone your repo to local & open with VSCode
  3. CMake: Select a Kit, select your compiler toolchain. select kit
  4. CMake configure build type (optional). CMake build type
  5. Build. Build
  6. If CMake asks for the configuration to the IntelliSense, press Don't Allow. (This template generate c_cpp_properties.json for IntelliSense) CMakeTools IntelliSense
  7. Press Run and Debug. Run and debug
  8. Select executable. select executable
  9. Add breakpoint in source code
  10. Press Start debugging.

Add new executable source code

  1. Add new .cpp/.c code under src.
  2. reconfigure, done.

See src/CppProjectTemplate/example.cpp for example.

Add new library source code

  1. Add new .cpp/.c code under src.
  2. Add cmake file with same name as source, for example: src/mycode.cpp, src/mycode.cmake
  3. Edit cmake file, add following content:
# src/<your file name>.cmake
include(cmake/scheme/lib.cmake)

Import 3rd party package

  1. Open cmake/packages.cmake
  2. Add hunter package. For example, add fmt package:
# ...The existing item in packages.cmake
hunter_add_package(fmt)
find_package(fmt CONFIG REQUIRED)
  1. All the source code can use the imported library directly, no needs to write link script.
  • Other examples can be found in src/packages.cmake.
  • All available packages can be found here.
  • All package import examples can be found here.

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.