[CMake] Check whether C++ headers are self-sufficient

Christoph Grüninger foss at grueninger.de
Sat Mar 14 08:19:21 EDT 2015


Dear CMakers,
I want to have all my C++ headers self-sufficient (self-contained),
i.e., a header can be included without additional includes. This is not
only handy but also part of Google's C++ styleguide [2].

It would be great to have a make target (let's call it headercheck),
that can check for this, by compiling a simple test.cc file for each
current_header.h:
  #include <config.h>
  #include "current_header.h"
  #include "current_header.h"

Additionally it would be great to have such a target for every folder
(checking all headers recursively) and every header that is explicitly
passed as an argument.

We tried this with CMake: We generate a test.cc file per header and
create a library for every cc file. The problem is, that we get hundreds
of additional targets, we generate a lot of folders and files which can
increase our build directory size by an order of magnitude and it does
not work properly on a per file or per directory basis.

What do you think, is there a good way to have such a target headercheck
with CMake? Or would it be better to include it as a CTest? Or better as
an external (bash) script as proposed in [1]?

If it can be done in a good way with CMake, would it be of interest to
include it as a feature in CMake? Or as an external project similar to
UseLATEX.cmake?

Bye
Christoph

[1]
http://stackoverflow.com/questions/1892043/self-sufficient-header-files-in-c-c
[2]
http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Self_contained_Headers

-- 
When you die, that does not mean that you lose to cancer,
you beat cancer by how you live, why you live, and in the
manner in which you live.      -- Stuart Scott, 1965-2015


More information about the CMake mailing list