|
| 1 | +# Building PhASAR |
| 2 | + |
| 3 | + |
| 4 | +It is recommended to compile PhASAR yourself in order to get the full C++ experience and to have full control over the build mode. |
| 5 | +However, you may also want to try out one of the pre-built versions of PhASAR or the Docker container. |
| 6 | + |
| 7 | +As a shortcut for the very first PhASAR build on your system, you can use our [bootstrap](./bootstrap.sh) script. |
| 8 | +Please note that you must have python installed for the script to work properly. |
| 9 | + |
| 10 | +```bash |
| 11 | +./bootstrap.sh |
| 12 | +``` |
| 13 | + |
| 14 | +Note: If you want to do changes within PhASAR, it is recommended to build it in Debug mode: |
| 15 | + |
| 16 | +```bash |
| 17 | +./bootstrap.sh -DCMAKE_BUILD_TYPE=Debug |
| 18 | +``` |
| 19 | + |
| 20 | +The bootstrap script may ask for superuser permissions (to install the dependencies); however it is not recommended to start the whole script with `sudo`. |
| 21 | + |
| 22 | +For subsequent builds, see [Compiling PhASAR](#compiling-phasar-if-not-already-done-using-the-installation-scripts). |
| 23 | + |
| 24 | +### Compiling PhASAR (if not already done using the bootstrap script) |
| 25 | + |
| 26 | +Set the system's variables for the C and C++ compiler to clang: |
| 27 | + |
| 28 | +```bash |
| 29 | +export CC=/usr/local/bin/clang |
| 30 | +export CXX=/usr/local/bin/clang++ |
| 31 | +``` |
| 32 | + |
| 33 | +You may need to adjust the paths according to your system. When you cloned PhASAR from Github you need to initialize PhASAR's submodules before building it: |
| 34 | + |
| 35 | +```bash |
| 36 | +git submodule update --init |
| 37 | +``` |
| 38 | + |
| 39 | +If you downloaded PhASAR as a compressed release (e.g. .zip or .tar.gz) you can use the `init-submodules-release.sh` script that manually clones the required submodules: |
| 40 | + |
| 41 | +```bash |
| 42 | +utils/init-submodules-release.sh |
| 43 | +``` |
| 44 | + |
| 45 | +Navigate into the PhASAR directory. The following commands will do the job and compile the PhASAR framework: |
| 46 | + |
| 47 | +```bash |
| 48 | +mkdir build |
| 49 | +cd build/ |
| 50 | +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. |
| 51 | +ninja -j $(nproc) # or use a different number of cores to compile it |
| 52 | +sudo ninja install # only if you wish to install PhASAR system wide |
| 53 | +``` |
| 54 | + |
| 55 | +When you have used the `bootstrap.sh` script to install PhASAR, the above steps are already done. |
| 56 | +Use them as a reference if you wish to modify PhASAR and recompile it. |
| 57 | + |
| 58 | +After compilation using cmake the following two binaries can be found in the build/tools directory: |
| 59 | + |
| 60 | ++ `phasar-cli` - the PhASAR command-line tool (previously called `phasar-llvm`) that provides access to analyses that are already implemented within PhASAR. Use this if you don't want to build an own tool on top of PhASAR. |
| 61 | ++ `myphasartool` - an example tool that shows how tools can be build on top of PhASAR |
| 62 | + |
| 63 | +Please be careful and check if errors occur during the compilation. |
| 64 | + |
| 65 | +When using CMake to compile PhASAR the following optional parameters can be used: |
| 66 | + |
| 67 | +| Parameter : Type| Effect | |
| 68 | +|-----------|--------| |
| 69 | +| **BUILD_SHARED_LIBS** : BOOL | Build shared libraries -- Not recommended anymore. You may want to use PHASAR_BUILD_DYNLIB instead (default is OFF) | |
| 70 | +| **PHASAR_BUILD_DYNLIB** : BOOL | Build one fat shared library (default is OFF) | |
| 71 | +| **CMAKE_BUILD_TYPE** : STRING | Build PhASAR in 'Debug', 'RelWithDebInfo' or 'Release' mode (default is 'Debug') | |
| 72 | +| **CMAKE_INSTALL_PREFIX** : PATH | Path where PhASAR will be installed if "ninja install” is invoked or the “install” target is built (default is /usr/local/phasar) | |
| 73 | +| **PHASAR_CUSTOM_CONFIG_INSTALL_DIR** : PATH | If set, customizes the directory, where configuration files for PhASAR are installed (default is /usr/local/.phasar-config)| |
| 74 | +| **PHASAR_ENABLE_DYNAMIC_LOG** : BOOL|Makes it possible to switch the logger on and off at runtime (default is ON)| |
| 75 | +| **PHASAR_BUILD_DOC** : BOOL | Build PhASAR documentation (default is OFF) | |
| 76 | +| **PHASAR_BUILD_UNITTESTS** : BOOL | Build PhASAR unit tests (default is ON) | |
| 77 | +| **PHASAR_BUILD_IR** : BOOL | Build PhASAR IR (required for running the unit tests) (default is ON) | |
| 78 | +| **PHASAR_BUILD_OPENSSL_TS_UNITTESTS** : BOOL | Build PhASAR unit tests that require OpenSSL (default is OFF) | |
| 79 | +| **PHASAR_ENABLE_PAMM** : STRING | Enable the performance measurement mechanism ('Off', 'Core' or 'Full', default is Off) | |
| 80 | +| **PHASAR_ENABLE_PIC** : BOOL | Build Position-Independed Code (default is ON) | |
| 81 | +| **PHASAR_ENABLE_WARNINGS** : BOOL | Enable compiler warnings (default is ON) | |
| 82 | +| **CMAKE_CXX_STANDARD** : INT|Build phasar in C++17 or C++20 mode (default is 17)| |
| 83 | + |
| 84 | +You can use these parameters either directly or modify the installer-script `bootstrap.sh` |
| 85 | + |
| 86 | +#### A Remark on Compile Time |
| 87 | + |
| 88 | +C++'s long compile times are always a pain. As shown in the above, when using cmake the compilation can easily be run in parallel, resulting in shorter compilation times. Make use of it! |
| 89 | + |
| 90 | +### Running a Test Solver |
| 91 | + |
| 92 | +To test if everything works as expected please run the following command: |
| 93 | + |
| 94 | +`$ phasar-cli -m test/llvm_test_code/basic/module_cpp.ll -D ifds-solvertest` |
| 95 | + |
| 96 | +You can find the `phasar-cli` tool in the build-tree under `tools/phasar-cli`. |
| 97 | + |
| 98 | +If you obtain output other than a segmentation fault or an exception terminating the program abnormally everything works as expected. |
| 99 | + |
| 100 | +### Building PhASAR on a MacOS System |
| 101 | + |
| 102 | +Due to unfortunate updates to MacOS and the handling of C++, especially on the newer M1 processors, we can't support native development on Mac. |
| 103 | +The easiest solution to develop PhASAR on a Mac right now is to use [dockers development environments](https://docs.docker.com/desktop/dev-environments/). Clone this repository as described in their documentation. Afterwards, you have to login once manually, as a root user by running `docker exec -it -u root <container name> /bin/bash` to complete the rest of the build process as described in this readme (install submodules, run bootstrap.sh, ...). |
| 104 | +Now you can just attach your docker container to VS Code or any other IDE, which supports remote development. |
| 105 | + |
| 106 | +## Installation |
| 107 | + |
| 108 | +PhASAR can be installed using the installer scripts as explained in the following. |
| 109 | +However, you do not need to install PhASAR in order to use it. |
| 110 | + |
| 111 | +### Installing PhASAR on an Ubuntu System |
| 112 | + |
| 113 | +In the following, we would like to give an complete example of how to install |
| 114 | +PhASAR using an Ubuntu or Unix-like system. |
| 115 | + |
| 116 | +Therefore, we provide an installation script. To install PhASAR, just navigate to the top-level |
| 117 | +directory of PhASAR and use the following command: |
| 118 | + |
| 119 | +```bash |
| 120 | +./bootstrap.sh --install |
| 121 | +``` |
| 122 | + |
| 123 | +The bootstrap script may ask for superuser permissions. |
| 124 | + |
| 125 | +Done! |
| 126 | + |
| 127 | +If You have already built phasar, you can just invoke |
| 128 | +```bash |
| 129 | +sudo ninja install |
| 130 | +``` |
0 commit comments