A CMake Include Rule for IDEs
Published in Cmake
When creating a CMakeLists.txt file we would like to only list the .cpp files in the add_executable and add_library commands. Whilst this is sufficient to compile the code (and should be enough for any IDE) most IDE's today will exhibit limited functionality unless the header files are also included in the add_executable and add_library commands.
A simple workaround that preserves the best of both worlds is to create a dummy rule that includes all the headers but doesn't actually do anything. better yet, we can make the rule locate all the headers with a simple GLOB expression:
# Dummy target for IDE's
FILE (GLOB_RECURSE all_headers_for_ides
${CMAKE_SOURCE_DIR}/**/*.hpp
${CMAKE_SOURCE_DIR}/**/*.h)
ADD_CUSTOM_TARGET(ide_includes SOURCES ${all_headers_for_ides})