A simple, cross-platform, and continuously integrated C 14 project template.
Making cross platform C projects is widely known to be a troublesome ambition. This project attempts to demystify many of the common problems related to creating such a structure by providing a simple template that achieves this purpose.
(Unfortunately, a setup script isn't currently available but is being worked on in #3. Until it is, however, these steps have to be followed manually.)
In order to use this project, all you have to do is follow a few (Ok, more than a few) simple steps:
git clone
this project into a directory of choice.- Open the file
.codedocs
and replace the variablesPROJECT_NAME
,PROJECT_NUMBER
, andPROJECT_NUMBER
with their corresponding values. - Open the file
.travis.yml
, and replace the encrypted Coverity Scan token with the one for your project. In addition, modify the variables in the following section with their corresponding values:project: name: "arnavb/cpp14-project-template" description: "A cross-platform C 14 project template" notification_email: [email protected]
- In
./CMakeLists.txt
, modify:Project-Name
to match your project name.Project-Name_VERSION_MAJOR
,Project-Name_VERSION_MINOR
, andProject-Name_VERSION_PATCH
to match the versioning of your project. Make sure to modify the names of the variables as well!- Modify
PROJ_NAME
to be the name of your project. - Do the same for
PROJECT_DESCRIPTION
. - If you are building just a library, then remove
${CMAKE_SOURCE_DIR}/src/main.cpp
fromCOVERAGE_EXCLUDES
. - Modify the
LIBRARY_SOURCES
variable to match your project sources. Excludemain.cpp
, if it exists. - If you are building a standalone library, then remove the following lines:
And later on in the file, remove:
add_executable(Project-Name main.cpp) # The main executable target_link_libraries(Project-Name Project-Name-lib) # Link our sources to the executable
# Install the built library and executable into the appropriate directory install(TARGETS Project-Name DESTINATION bin)
- Change the name
Project-Name
andProject-Name-lib
to match your project name. - Change:
to match the new folder name for your project, as described in step 8.
install(FILES ${CMAKE_BINARY_DIR}/include/project-abbr/config.hpp DESTINATION include/project-abbr) # Install our configuration file
- Modify
LICENSE
to match your software license. - Modify this file (
README.md
) to match the details of your project. You may want to keep the build steps, however. - Open the folder
doc
. Then:- Delete all the markdown pages from this directory and replace them with your own.
- If a main page is needed, it needs to be in a file called
main_page.md
.
- Open the folder
include
. Then:- Change the name of the folder
project-abbr
to something that matches your project (name or abbreviation). Delete all the files exceptconfig.hpp.in
in this directory and replace them with your public include files, if they exist.
- Change the name of the folder
- Open the folder
src
. Then:- Remove all of the
.cpp
files in this folder and replace them with your source files and private includes.
- Remove all of the
- Open the folder
test
. Then:- Replace all the files in this directory except for
test_runner.cpp
with your doctest unit testing files. - In
test/CMakeLists.txt
, changeProject-Name-lib
to match the new name of your library. In addition, modify theTEST_SOURCES
variable to match your new test files.
- Replace all the files in this directory except for
- Delete the by default hidden
.git
folder and then rungit init
to get a new repository!
For details on how to set up the various continuous integration tools used in this project, check the documentation.
The following tools must be preinstalled before using this template:
CMake
(At least v3.1): For building the code.Doxygen
: For generating documentation.LCOV
: For generating code coverage.
In the snippets below, CONFIGURATION
needs to be a valid CMake configuration.
mkdir build && cd build
cmake -D<options> -DCMAKE_BUILD_TYPE=CONFIGURATION ..
make
make install
mkdir build && cd build
cmake -D<options> ..
cmake --build --config CONFIGURATION .
cmake --build --target INSTALL --config CONFIGURATION .
For more details on configuration options and build targets, see the documentation.
In order to run the tests, the option BUILD_TESTS
needs to be set to ON
during configuration. Then, invoking the tests is as simple as running:
ctest
In order to get the test coverage of the code, the option ENABLE_COVERAGE
needs to be set to ON
during configuration. In addition, CMAKE_BUILD_TYPE
should be set to Debug
(code coverage isn't supported for multi-config generators yet). Then, a coverage report can be generated by running:
make coverage
The resulting coverage will be placed in a directory called coverage
in the build folder.
The documentation for this project (sample code and usage of this project) is hosted on codedocs.xyz.
Documentation about build targets, CMake options, the directory structure used, and documentation are all available in the link above.
To the extent possible under law, Arnav Borborah has waived all copyright and related or neighboring rights to C 14 Project Template. This work is published from: United States.
The above basically means that while you do not have to give me attribution for this template, it would be gladly appreciated!