unicorn/docs/COMPILE.md

131 lines
3.4 KiB
Markdown
Raw Normal View History

This HOWTO introduces how to build Unicorn2 natively on Linux/Mac/Windows or cross-build to Windows from Linux host.
2021-10-05 23:53:05 +03:00
Note: Please run `make clean` before you switch to `dev` branch.
## Native build on Linux/macOS
This builds Unicorn2 on Linux/macOS. Note that this also applies to Apple Silicon M1 users.
- Install `cmake` and `pkg-config` with your favorite package manager:
Ubuntu:
``` bash
2021-10-05 23:53:05 +03:00
sudo apt install cmake pkg-config
2021-10-03 17:14:44 +03:00
```
macOS:
```bash
2021-10-05 23:53:05 +03:00
brew install cmake pkg-config
2021-10-03 17:14:44 +03:00
```
- Build with the following commands.
```bash
2021-10-05 23:53:05 +03:00
mkdir build; cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
2021-10-03 17:14:44 +03:00
```
2021-10-05 23:53:05 +03:00
## Native build on Windows, with MSVC
2021-10-03 17:14:44 +03:00
This builds Unicorn2 on Windows, using Microsoft MSVC compiler.
2021-10-03 17:14:44 +03:00
- Require `cmake` & `Microsoft Visual Studio`.
- From Visual Studio Command Prompt, build with the following commands.
```bash
2021-10-03 17:14:44 +03:00
mkdir build; cd build
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
nmake
2021-10-03 17:14:44 +03:00
```
Note, other generators like `Ninja` and `Visual Studio 16 2019` would also work.
2021-10-03 17:14:44 +03:00
2021-10-05 23:53:05 +03:00
```bash
mkdir build; cd build
cmake .. -G "Visual Studio 16 2019" -A "win32" -DCMAKE_BUILD_TYPE=Release
msbuild unicorn.sln -p:Plaform=Win32 -p:Configuration=Release
2021-10-03 17:14:44 +03:00
```
2021-10-05 23:53:05 +03:00
## Cross build with NDK
2022-02-13 11:54:38 +03:00
To cross-build and run Unicorn2 on the Android platform, firstly you need to download [NDK](https://developer.android.com/ndk/downloads).
2021-10-05 23:53:05 +03:00
For newer NDK, please make sure your cmake version is above 3.19.
Then generate the project like:
```bash
mkdir build; cd build;
cmake .. -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=$ABI -DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION
make
```
You may get the possible values from this [page](https://developer.android.com/ndk/guides/cmake).
Unicorn2 support cross-build for `armeabi-v7a`, `arm64-v8a`, `x86` and `x86_64`.
2022-02-13 11:54:38 +03:00
Note the build is only tested and guaranteed to work under Linux and macOS, however, other systems may still work.
2021-10-05 23:53:05 +03:00
## Cross build from Linux host to Windows, with Mingw
2021-10-03 17:14:44 +03:00
This cross-builds Unicorn2 from **Linux host** to Windows, using `Mingw` compiler.
2021-10-03 17:14:44 +03:00
- Install required package.
2021-10-05 23:53:05 +03:00
```bash
sudo apt install mingw-w64-x86-64-dev
2021-10-03 17:14:44 +03:00
```
- Build Unicorn and samples with the following commands.
2021-10-05 23:53:05 +03:00
```bash
mkdir build; cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=../mingw64-w64.cmake
make
2021-10-03 17:14:44 +03:00
```
2021-10-05 23:53:05 +03:00
## Native build on Windows host, with MSYS2/Mingw
2021-10-03 17:14:44 +03:00
This builds Unicorn2 on **Windows host**, using **MSYS2/Mingw** compiler.
2021-10-03 17:14:44 +03:00
This requires MSYS2 to be installed on the Windows machine. You need to download & install MSYS2 from https://www.msys2.org.
2021-10-03 17:14:44 +03:00
Then from MSYS2 console, install packages below:
2021-10-03 17:14:44 +03:00
2021-10-05 23:53:05 +03:00
```bash
2022-02-13 11:54:38 +03:00
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
2021-10-03 17:14:44 +03:00
```
- Build Unicorn and samples with the following commands.
2021-10-05 23:53:05 +03:00
```bash
2022-02-13 11:54:38 +03:00
export PATH=/mingw64/bin:$PATH
2021-10-03 17:14:44 +03:00
mkdir build; cd build
2022-02-13 11:54:38 +03:00
/mingw64/bin/cmake .. -G "Ninja"
ninja -C .
2021-10-03 17:14:44 +03:00
```
Note that the way to build on MSYS changes as time goes, please keep in mind that always use the cmake shipped with mingw64 and choose MSYS Makefiles.
2021-10-03 17:14:44 +03:00
2021-10-05 23:53:05 +03:00
## Cross build from Linux host to other architectures
2021-10-03 17:14:44 +03:00
This cross-builds Unicorn2 from **Linux host** to other architectures, using a cross compiler.
2021-10-03 17:14:44 +03:00
- Install cross compiler package. For example, cross-compile to ARM requires the below command.
2021-10-03 17:14:44 +03:00
2021-10-05 23:53:05 +03:00
```bash
sudo apt install gcc-arm-linux-gnueabihf
2021-10-03 17:14:44 +03:00
```
- Build Unicorn and samples with the following commands. The compiler name differs according to your targets.
2021-10-03 17:14:44 +03:00
2021-10-05 23:53:05 +03:00
```bash
mkdir build; cd build
cmake .. -DCMAKE_C_COMPILER=gcc-arm-linux-gnueabihf
make
2021-10-03 17:14:44 +03:00
```