dutow / ccf

Helper modules for CMake
1 stars 0 forks source link

Cancellar CMake framework

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:

Setup:

Unless 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:

Optional configuration

Third party libraries:

For 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:

Build structure:

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

Adding new targets (full automatic)

Adding new targets (manual listing)

Adding tests

CMakeLists in ns_folder

ccf_ns()
ccf_add_all(TARGET)

(created automatically)

CMakeLists in target_folder

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.

CMakeLists in a test folder

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)