I'm trying to integrate clang-tidy and am attempting to dynamically establish the include directories. My cmake looks like:
if(UNIX)
file(GLOB_RECURSE ALL_CXX_SOURCE_FILES *.cpp *.hpp)
file(GLOB_RECURSE ALL_HEADERS *.hpp)
set(ALL_INCLUDE_DIRECTORIES "")
foreach (_headerFile ${ALL_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
if(ALL_INCLUDE_DIRECTORIES STREQUAL "")
set(ALL_INCLUDE_DIRECTORIES "-I${_dir}")
else()
set(ALL_INCLUDE_DIRECTORIES "-I${_dir} ${ALL_INCLUDE_DIRECTORIES}")
endif()
endforeach()
message(${ALL_INCLUDE_DIRECTORIES})
add_custom_target(clang-tidy COMMAND /usr/bin/clang-tidy ${ALL_CXX_SOURCE_FILES} -checks=* -- -std=c++11 ${ALL_INCLUDE_DIRECTORIES})
endif()
The ${ALL_INCLUDE_DIRECTORIES} does not appear to expand correctly in the add_custom_target because the 'make clang-tidy' reports errors for not finding the headers at the include paths. However, if I use the output from message(${ALL_INCLUDE_DIRECTORIES}) to replace the ${ALL_INCLUDE_DIRECTORIES} in the add_custom_target I do not get these errors and clang-tidy appears to find the headers.