GithubHelp home page GithubHelp logo

clarking / cmake-project-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mmorse1217/cmake-project-template

0.0 0.0 0.0 139 KB

A base C++ project built with CMake

License: MIT License

C++ 97.88% CMake 2.12%

cmake-project-template's Introduction

CMake C++ Project Template build

A base C++ project built with documented CMakeLists.txt

This project is meant to be a ready-built setup that can be used to build a C++ project with a library, tests and executables that can be installed and exported for other users to import with find_package(CMakeDemo). Tests are written with the Catch library. There is a simple version of a find module in cmake for the project, FindCMakeDemo.cmake, that searches several environment variables and /usr/local for installations of CMakeDemo. There is also a baseline CMakeDemo-config.cmake file to support transitive dependencies when the project is found via find_package.

Prerequisites

  • CMake >=3.1
  • A C/C++ compiler (tested with gcc 7.5.0)
  • Catch (v2.11.3 is included in tests/; overwrite with a more updated version)

How to use the template for your project

  1. Fork the repo
  2. Add your source files to the project. Place source code in src/, header files in include/, and test code in tests/.
  3. Add the names of all source files in the project to the CMakeLists.txt in the src/, include/ and tests/ directories.
  4. Rename all instances of CMakeDemo and CMAKEDEMO in all CMake-related files with your desired project name. This includes all CMakeLists.txt and the files in `cmake/'.
  5. Build, compile and run your code.

Compiling, installing and running your code

To compile the project, run the following in the project root:

    mkdir build
    cd build
    cmake ..
    make

To install the project in /usr/local/, run the following in the build/ directory created above:

    make install

To run unit tests via CTest, again run the following in the build/ directory:

    make test

or

    ctest

To add additional dependencies via find_package, be sure to also include them in cmake/CMakeDemo-config.cmake. LAPACK is included as an example. To import a project built with this template in another CMake project, be sure to add the cmake/FindCMakeDemo.cmake file to that project's cmake/ directory.

File structure:

    ├── CMakeLists.txt
    ├── LICENSE
    ├── README.md
    ├── cmake
    │   ├── CMakeDemo-config.cmake
    │   └── FindCMakeDemo.cmake
    ├── include
    │   ├── CMakeLists.txt
    │   └── source_file.hpp
    ├── src
    │   ├── CMakeLists.txt
    │   └── source_file.cpp
    └── tests
        ├── CMakeLists.txt
        ├── catch.hpp
        └── test_cmake_demo.cpp

Helpful links:

cmake-project-template's People

Contributors

mmorse1217 avatar

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.