CppProject
is a template for a simple CMake-based C++ project. It can be used as the basis for new projects: remember to change all instances of CppProject
to your new project name. An example CMake module is available to make it easy to include your project in other CMake-based projects (should be customized): FindCppProject.cmake.
- General directory structure common to C++ projects
- Example of CMake module (
cmake/Modules/FindCppProject.cmake
) - Testing framework (Catch)
- Install script (
make install
) - CPack script for packaging (
make package
) - Automatic API documentation (Doxygen)
- Continuous Integration (Travis CI)
- Code coverage analysis (Coveralls) (
make coverage
) - Example of how to include external dependencies (using
ExternalProject
module) - Separate file to specify location of project files (
ProjectFiles.cmake
)
To install this project, please ensure that you have installed the following (install guides are provided on the respective websites):
- Git
- A C++ compiler, e.g., GCC, clang, MinGW
- CMake
- Doxygen (optional)
- Gcov (optional)
- LCOV (optional)
CppProject
does not depend on any libraries. The following library is optional (see Build options
):
- CATCH (unit testing library necessary for
BUILD_TESTS
build option)
This dependency will be downloaded and configured automagically if not already present locally (requires an internet connection).
Run the following commands to download, build, and install this project. Substitute "project_name" with the name of your project (if you leave it out, the repository will be cloned to a local folder called "cpp-project"). This will customize the project targets for you. Note that "project_name" must not contain spaces! The --depth 1
parameter passed to git clone
ensures that the git history is not downloaded. In case you would like to preserve the history of this project, omit that option.
git clone https://www.github.com/kartikkumar/cpp-project --depth 1 <project_name>
cd <project_name>
git submodule init && git submodule update
mkdir build && cd build
cmake -DPROJECT_NAME=<project_name> .. && cmake --build .
To install the header files, run the following from within the build
directory:
make install
Note that dependencies are installed by fetching them online, in case they cannot be detected on your local system. If the build process fails, check the error log given. Typically, building fails due to timeout. Simply run the cmake --build .
command once more.
You can pass the following, general command-line options when running CMake:
-DPROJECT_SUMMARY
: set short string summary for your project-DPROJECT_VENDOR_NAME
: set short string name for vendor of your project-DPROJECT_VENDOR_CONTACT
: set short string email address for vendor of your project-DCMAKE_INSTALL_PREFIX[=$install_dir]
: set path prefix for install script (make install
); if not set, defaults to usual locations-DBUILD_SHARED_LIBS=[ON|OFF (default)]
: build shared libraries instead of static-DBUILD_MAIN[=ON|OFF (default)]
: build the main-function-DBUILD_DOXYGEN_DOCS[=ON|OFF (default)]
: build the Doxygen documentation (LaTeX must be installed withamsmath
package)-DBUILD_TESTS[=ON|OFF (default)]
: build tests (execute tests from build-directory usingctest -V
)-DBUILD_DEPENDENCIES[=ON|OFF (default)]
: force local build of dependencies, instead of first searching system-wide usingfind_package()
The following command is conditional and can only be set if BUILD_TESTS = ON
:
-DBUILD_COVERAGE_ANALYSIS[=ON|OFF (default)]
: build code coverage using Gcov and LCOV (both must be installed; requires GCC compiler; execute coverage analysis from build-directory usingmake coverage
)
Pass these options either directly to the cmake ..
build command or run ccmake ..
instead to bring up the interface that can be used to toggle options.
This project has been set up with a specific file/folder structure in mind. The following describes some important features of this setup:
cmake/Modules
: ContainsCMake
modules, includingFindCppProject.cmake
template for project-specific module.docs
: Contains project-specific docs in Markdown that are also parsed by Doxygen. This sub-directory includesglobal_todo.md
, which contains a global list of TODO items for project that appear on TODO list generated in Doxygen documentationdoxydocs
: HTML output generated by building Doxygen documentationinclude/CppProject
: Project header files (*.hpp)scripts
: Shell scripts used in Travis CI buildsrc
: Project source files (*.cpp), includingmain.cpp
, which contains example main-function for project buildtest
: Project test source files (*.cpp), includingtestCppProject.cpp
, which contains include for Catch.travis.yml
: Configuration file for Travis CI build, including static analysis using Coverity Scan and code coverage using CoverallsCMakeLists.txt
: mainCMakelists.txt
file for project (should not need to be modified for basic build)Dependencies.cmake
: list of dependencies and automated build, triggered if dependency cannot be found locallyDoxyfile.in
: Doxygen configuration file, adapted for generic use within project build (should not need to be modified)LICENSE.md
: license file for project (copyright statement needs to be edited)ProjectFiles.cmake
: list of project source files to buildREADME.md
: project readme file, parsed as main page for Doxygen documentation
Once you've made your great commits:
- Fork
CppProject
- Create a topic branch -
git checkout -b my_branch
- Push to your branch -
git push origin my_branch
- Create a Pull Request from your branch
- That's it!
The copyright holders are not liable for any damage(s) incurred due to improper use of CppProject
.