Welcome to the repo! Here we have the base code to get you started with creating a basic code analysis tool using LLVM and its Libtooling framework.
To generate the required boilerplate structure and install the necessary dependencies, simply run
./setup.sh
In order to use the script, you need to have either the apt
or brew
package managers installed on your system.
Note that for some Linux distributions the version of
cmake
that will be installed by the package managers is insufficient to build the LLVM libraries. In this case, you will need to install an updated version ofcmake
yourself - details about this can be found here.
If you would like to manually set up the development environment, do the following:
-
Install the necessary build tools (
git
,cmake
andninja
)sudo apt install git cmake ninja-build
sudo brew install git cmake ninja-build
-
Clone the LLVM repository
git clone \ https://github.com/llvm/llvm-project.git \ --branch llvmorg-12.0.1
-
Create a new project directory under
llvm-project/clang-tools-extra
and copy the provided source code into itcp -r \ ./src \ ./llvm-project/clang-tools-extra/uqcs_demo
-
Register the project under
llvm-project/clang-tools-extra/CMakeLists.txt
echo -e "\nadd_subdirectory(uqcs_demo)\n" >> \ ./llvm-project/clang-tools-extra/CMakeLists.txt
-
Create a new
build
directory and move into itmkdir ./llvm-project/build cd ./llvm-project/build
-
Run the
cmake
initialisation sequencecmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \ -DCMAKE_BUILD_TYPE:STRING=Release
-
Build the project (from within the
build
directory)ninja uqcs_demo
When the project is built, the resulting executable (uqcs_demo
)
will be located under llvm-project/build/bin
.
When you've made changes to the source code under
llvm-project/clang-tools-extra/uqcs_demo
you can rebuild
the final executable by running the following from the
build
directory:
ninja uqcs_demo