This repository provides helpers for setting up C++ projects using CMake in a quick and elegant way.
Howewer, it also makes several assumptions, and will report errors if those aren't met:
If a project mets these requirements this script allow a zero-configuration setup and offer:
cmake/ccf
include(ccf_init)
at the startccf_end()
at the endUnless otherwise specified, init will automatically add the following third parties:
During its run the script will check for several common configuration files to exists. If they don't it'll create them based on a template.
These files are:
.gitignore
.clang-format
.clang-tidy
bt.py
ccf_cpp_extension("cxx")
- reports error if a C++ file uses a different extensionccf_h_extension("hxx", "hpp")
- reports error if a H file uses a non listed extensionccf_tidy_executable(...)
- uses a custom tidy instead of the system oneFor any supported third party in the 3rd-party
forder, add:
ccf_3p(<name> <TAG|COMMIT> <ref>)
or ccf_3p(<name> DEFAULT)
Third party libraries usually expect the sources to be found under _3p/name
, as a shallow submodule.
It'll ensure that:
These scripts assume a simple module structure, where:
ns_folder\
target_folder\
include\
internal_include\
src\
tests\
test_executable_1\
include\
internal_include\
src\
CMakeLists.txt
test_executable_2\
...
test_library_1\
include\
internal_include\
src\
CMakeLists.txt
CMakeLists.txt
CMakeLists.txt
ccf_add_all(NAMESPACE)
in the main CMakeListsa_ns
a_ns/target_folder
a_ns/target_folder
add_subdirectory
entry to the parent directoryccf_ns
/ccf_target
call to the CMakeLists.txt in the new directorytests
ccf_ns()
ccf_add_all(TARGET)
(created automatically)
ccf_ns()
ccf_target(EXECUTABLE) # or STATIC_LIBRARY/DYNAMIC_LIBRARY
#ccf_depends(some-other-target)
(created automatically with EXECUTABLE, without comments)
The build relies on GLOB_RECURSE
and CONFIGURE_DEPENDS
, nothing else has to be specified.
The alternative was to add a sanity check to ccf_end
to check that there are no missing undocumented files - and then this makes more sense.
Executables assume that the main.cpp
or main.cxx
file contains the main
function of the program, and that it doesn't
contain anything else - it is only a starting point.
This is to support writing tests against executables:
an executable is an object library containing everything but the main, and an executable target using both.
Tests use the object library.
ccf_ns()
ccf_target(EXECUTABLE) # or STATIC_LIBRARY/DYNAMIC_LIBRARY
ccf_test()
#ccf_test(additional_test_name param1 param2 param3)
ccf_depends(catch2)
ccf_depends(parent-target)
(created automacitally with EXECUTABLE, without comments)