Custom tool doesn't parse successfully

The main function for my custom tool looks like this:
CommonOptionsParser optionsParser(argc, argv, gMyToolCategory);
RefactoringTool tool(optionsParser.getCompilations(), optionsParser.getSourcePathList());
MyToolActionFactory factory{tool};
auto a = tool.runAndSave(&factory);

In ClangTool::run(), when I get to the line “assert(!CommandLine.empty());” I see that the CompileCommand and CommandLine variables in my custom tool match those from clang-tidy built from the same source. The only difference is CommandLine[0], which names my tool rather than clang-tidy.

What is confusing me is that the behavior of Invocation.run() differs between the two programs. In clang-tidy it runs perfectly (no warnings, no errors). In my tool I get a lot of errors of the form:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\immintrin.h(764,28) : error:
invalid token in macro parameter list
#define _mm256_loadu2_m128(/* float const* */ hiaddr, \

It seems that there must be something that I am missing when checking to see if my program is executing in a similar manner to clang-tidy. What other variables, functions, etc. should I check to try to debug my problem?

I have tracked this a little further. In ToolInvocation::run() I see that CC1Args for clang-tidy has “-resource-dir D:\WorkingDir\build\MyTool\trunk\llvmbuild\Debug\bin..\lib\clang\3.8.0”, which directory exists. CC1Args for my tool has “-resource-dir D:\WorkingDir\build\MyTool\Debug..\lib\clang\3.8.0”, which does not exist.

I assume that this difference has something to do with the build system. My CMake file to build my tool looks like this (fragment):

set(BUILD_SHARED_LIBS OFF)
add_subdirectory(${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvm ${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvmbuild EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${TMP_BUILD_SHARED_LIBS})

include_directories(${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvm/tools/clang/include
${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvm/include
${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvmbuild/tools/clang/include
${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvmbuild/include
${CMAKE_BINARY_DIR}/${CLANG_VERSION}/llvm/utils/unittest/googletest/include
)

add_library(Lib${ToolName} SHARED
${ToolSources}
${ToolSourceHeaders}
${ToolIncludeHeaders}
)
add_executable(${ToolName}
Source/Main.cpp
)

target_link_libraries(Lib${ToolName}
clangTooling
)

Hi Daniel,

These are Clang's so-called built-in headers. The intrinsic header
names are the same for MSVC, so if you don't have Clang's headers
available, it will find MSVC's, and Clang can't parse them completely.

All tools need to ship with the Clang built-in headers, unfortunately.

http://clang.llvm.org/docs/LibTooling.html#libtooling-builtin-includes

- Kim

That looks like exactly my problem. I copied the lib directory so that both paths are valid, and everything works.

Can anyone suggest how to fix my CMake script so that either the build puts the lib directory in the correct location (relative to my tool) or so that my tool looks for the lib directory where the build puts it?