<div dir="ltr">I also have this implemented - in my case, the headers are fine to include in a .cpp with just a do-nothing main function and build into an executable, testing linking too.<br><div><br></div><div><a href="https://github.com/rpavlik/util-headers/blob/master/tests/cleanbuild/CMakeLists.txt">https://github.com/rpavlik/util-headers/blob/master/tests/cleanbuild/CMakeLists.txt</a><br></div><div><br></div><div>Ryan</div></div><br><div class="gmail_quote">On Sat, Mar 14, 2015 at 8:56 AM Robert Maynard <<a href="mailto:robert.maynard@kitware.com">robert.maynard@kitware.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have worked on projects where we do something fairly similar. The significant difference is that we create only a single executable per directory. All told is it a fairly simple and looks something like:<div><br></div><div># Builds a source file and an executable that does nothing other than</div><div># compile the given header files.</div><div>function(add_header_test name)</div><div>  set(hfiles ${ARGN})</div><div>  set(suffix ".cpp")</div><div>  set(cxxfiles)</div><div>  foreach (header ${ARGN})</div><div>    string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}" "" header "${header}")</div><div>    get_filename_component(headername ${header} NAME_WE)</div><div>    set(src ${CMAKE_CURRENT_BINARY_DIR}/TestBuild_${name}_${headername}${suffix})</div><div>    configure_file(${SMTK_SOURCE_DIR}/CMake/<a href="http://TestBuild.cxx.in" target="_blank">TestBuild.cxx.in</a> ${src} @ONLY)</div><div>    set(cxxfiles ${cxxfiles} ${src})</div><div>  endforeach (header)</div><div><br></div><div>  add_library(TestBuild_${name} ${cxxfiles} ${hfiles})</div><div>  target_include_directories(TestBuild_${name} ${CMAKE_CURRENT_BINARY_DIR})</div><div>  set_source_files_properties(${hfiles} PROPERTIES HEADER_FILE_ONLY TRUE)</div><div>endfunction(add_header_test)  </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 14, 2015 at 8:19 AM, Christoph Grüninger <span dir="ltr"><<a href="mailto:foss@grueninger.de" target="_blank">foss@grueninger.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear CMakers,<br>
I want to have all my C++ headers self-sufficient (self-contained),<br>
i.e., a header can be included without additional includes. This is not<br>
only handy but also part of Google's C++ styleguide [2].<br>
<br>
It would be great to have a make target (let's call it headercheck),<br>
that can check for this, by compiling a simple test.cc file for each<br>
current_header.h:<br>
  #include <config.h><br>
  #include "current_header.h"<br>
  #include "current_header.h"<br>
<br>
Additionally it would be great to have such a target for every folder<br>
(checking all headers recursively) and every header that is explicitly<br>
passed as an argument.<br>
<br>
We tried this with CMake: We generate a test.cc file per header and<br>
create a library for every cc file. The problem is, that we get hundreds<br>
of additional targets, we generate a lot of folders and files which can<br>
increase our build directory size by an order of magnitude and it does<br>
not work properly on a per file or per directory basis.<br>
<br>
What do you think, is there a good way to have such a target headercheck<br>
with CMake? Or would it be better to include it as a CTest? Or better as<br>
an external (bash) script as proposed in [1]?<br>
<br>
If it can be done in a good way with CMake, would it be of interest to<br>
include it as a feature in CMake? Or as an external project similar to<br>
UseLATEX.cmake?<br>
<br>
Bye<br>
Christoph<br>
<br>
[1]<br>
<a href="http://stackoverflow.com/questions/1892043/self-sufficient-header-files-in-c-c" target="_blank">http://stackoverflow.com/questions/1892043/self-sufficient-header-files-in-c-c</a><br>
[2]<br>
<a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Self_contained_Headers" target="_blank">http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Self_contained_Headers</a><br>
<br>
--<br>
When you die, that does not mean that you lose to cancer,<br>
you beat cancer by how you live, why you live, and in the<br>
manner in which you live.      -- Stuart Scott, 1965-2015<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>
--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/<u></u>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/<u></u>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/<u></u>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/<u></u>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/<u></u>mailman/listinfo/cmake</a></blockquote></div>