1. Obtain the source code
git clone --depth 1 https://github.com/llvm/llvm-project.git
Copy the code
Configure and build LLVM and Clang
The default shell of the new mackOS is ZSH, so execute the following command on the terminal:
echo 'export OSX_COMMANDLINE_SDKROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"' >> ~/.zshrc
Copy the code
After executing the above command, you can open the ZSHRC file to see if the address you just entered is correct
open ~/.zshrc
Copy the code
Then execute:
source ~/.zshrc
Copy the code
⚠ ️ note: time to look at the second step in the implementation of the/Library/Developer/CommandLineTools/SDKs/MacOSX. The SDK? If no, install it in time:
xcode-select --install
Copy the code
Otherwise, subsequent configurations will be affected.
3. Install Cmake using BREW
brew install cmake
Copy the code
If you are prompted to install it, you may or may not update it
Begin to build
3, create Xcode project: llvm-project: create llvm-project: create Xcode project:
cmake -G Xcode -j 6 -DLLVM_ENABLE_PROJECTS='libcxx; libc++; clang; lldb' -DLLDB_USE_SYSTEM_DEBUGSERVER=ON -DLLDB_TEST_COMPILER=clang++ -DCMAKE_OSX_SYSROOT=$OSX_COMMANDLINE_SDKROOT .. /llvmCopy the code
Some common build system generators:
Ninja
: most of thellvm
Developers all use itNinja
Unix Makefiles
: Used to generate andmake
Compatible parallelismmakefile
Visual Studio
: used to generateVisual Studio
Projects and solutionsXcode
: used to generateXcode
project
Here we use the Xcode -j parameter to specify the number of CPU cores to use. For example, six are used in the above instruction. According to their own computer situation designated.
This process takes a little longer
Xcode related configuration
Go to the build directory and open llvm. xcodeproj. Go to Xcode and a pop-up prompt will be displayed
Automatically Create Schemes otherwise they will introduce unnecessary Schemes and slow down Xcode. Principle: Introduce the scheme you use. 3. Create scheme and select LLDB for Target.
The first time ⚠️ runs, we need to compile to regenerate debug symbols, and then Run Without Building; This means that when your code doesn’t change, you don’t need to recompile and just run the existing executable.
⚠️ When using a project compiled by someone else, just execute the following commands:
cmake -G Xcode -j 6 -DLLVM_ENABLE_PROJECTS='libcxx; libc++; clang; lldb' -DLLDB_USE_SYSTEM_DEBUGSERVER=ON -DLLDB_TEST_COMPILER=clang++ -DCMAKE_OSX_SYSROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" .. /llvmCopy the code
Error immediately: you will need to delete CMakeCache. TXT in llvm-project/build directory and re-execute the above command.