1.4 Test project – syntax check with a Clang tool
For our first test project, we will create a simple Clang tool that runs the compiler and checks the syntax for the provided source file. We will create a so-called out-of-tree LLVM project, that is, a project that will use LLVM but will be located outside the main LLVM source tree.
Several actions are required to create the project:
The required LLVM libraries and headers have to be built and installed
We have to create a build configuration file for our test project
The source code that uses LLVM has to be created
We will start with the first step and install the Clang support libraries and headers. We will use the following configuration command for CMake:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_USE_LINKER=gold -DLLVM_USE_SPLIT_DWARF=ON -DBUILD_SHARED_LIBS=ON ../llvm
Figure 1.12: LLVM CMake configuration...