This project, derivative of the CMake Tutorial, is aimed at showing a preferred "common" CMake/C++ project structure.
If your project is mulit-language, and you absolutely have to keep them together, make the root one level above, and create folders such as "cpp" and "ruby", or "python", etc.
By "exporting a component" we mean that the component is meant to be consumed by other projects or developers. IE. it's public, not private to the project.
For the simplicity sake, we'll build a tool that for every input number prints out if it's divisible by a particular number, that can also be supplied as an argument that would override the default value of 2. We'll call this tool divisible, and that name will now be our project's name too.
Our goal is to have a working binary, such as :
$ bin/divis [ -h/--help ] [ -m/--modulo ] [ -d/--denominator N ] value
# eg:
$ bin/divis -d 17 34
yes, 17 x 2 is 34
$ bin/divis -d 10 -m 45
45 modulo 10 is 5
And C++ usage:
#include <iostream>
#include <divisible>
std::cout << Divisible.new(int denominator).modulo();
Sources:
src/*
— C++ code that ultimately compiles into a library- We'll also build a library
libdivisible.a
and install intolib/
src/CLI.cpp
C++ CLI interface parser that parses arguments and flags passed to a binary- a tiny
src/main.cpp
that calls into the CLI, which then calls the library.
Tests:
- A
test
folder with the automated tests and fixtures that mimics the directory structure ofsrc
. - For every C++ file in
src/A/B/<name>.cpp
there is a corresponding test filetest/A/B/<name>_test.cpp
- Tests compile into a single binary
test/bin/runner
that is run on a command line to run the tests. test/lib
folder with a git submodule intest/lib/googletest
, and possibly other libraries.
Here is the structure proposed here:
divisible/
CMakeLists.txt -> Top level CMake file
bin/ -> exported compiled executables
doc/ -> and compiled documentation
usage/ -> documentation folder for how to use the tool
design/ -> documentation folder for the developers of the tool
include/ -> externally exported header files
name/
lib/ -> compiled library we are exporting
extern/ -> external libraries if they must be included
src/ -> sources of the project
CLI.cpp -> the CLI argument parser/wrapper
main.cpp -> small main.cpp that calls into the CLI module
divisible/ -> cmake project that produces divisible library
CMakeLists.txt
Divisible.cpp
Divisible.h
test/ -> sources for all the tests
bin/ -> where the binary `test-runner` is installed
lib/ -> where any external libraries live
googletest/ -> most importantly, our googletest library as a submodule
src/
util/ -> any bash tools, build wrappers, etc.
TBD.
Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/cmake-project-template
CMake Project Template is © 2017 Konstantin Gredeskoul, available as open source under the terms of the MIT License.