# Installing OpenPASS

This section describes how compile and run openPASS. Please make sure that all prerequisites have been properly installed according to section Installing Prerequisites. If you have strictly followed the instructions, the installed source packages should be located on your machine under `C:\OpenPASS\thirdParty` for Windows and `~/OpenPASS/thirdParty` for Linux. If there is a path deviation, the following commands must be adjusted.

To keep the installation process of openPASS as simple as possible, we again recommend a specific folder structure. If you have strictly followed and will follow the recommended paths of this guide, no command modifications are necessary.

- Recommended checkout path of openPASS repository: `C:\simopenpass`

- Recommended dependendy directory within the openPASS repository: `C:\simopenpass\deps\thirdParty`

- Recommended installation directory of openPASS: `C:\OpenPASS\bin\core`

- Recommended checkout path of openPASS repository: `~/simopenpass`

- Recommended dependendy directory within the openPASS repository: `~/simopenpass/deps/thirdParty`

- Recommended installation directory of openPASS: `/usr/local/OpenPASS/bin/core`

The above directory structure will be created by following the instructions of this guide.

1. Clone OpenPASS repository

   As described above, the checkout path of the repository is assumed to be the default `simopenpass`.

   Start `MinGW 64-bit` shell

       cd /C/
       git clone https://gitlab.eclipse.org/eclipse/simopenpass/simopenpass.git

   Note

   As stated in Installing the Build Environment, the windows programming tools suffer from a path length restriction. This error manifests as strange file not found compile errors. It is therefore recommended to use a short path for source code checkout, e.g. a drive letter. This can also be done by the windows command subst.

   Start `Bash` shell

       cd ~
       git clone https://gitlab.eclipse.org/eclipse/simopenpass/simopenpass.git

2. Navigate into repository and checkout main branch

       cd simopenpass
       git checkout main

3. Create directory structure

       mkdir -p deps/thirdParty

4. Navigate into directory where installed prerequisites are located

       cd /C/OpenPASS/thirdParty

       cd ~/OpenPASS/thirdParty

5. Copy prerequisites into repository (c.f. Installing Prerequisites)

       cp -r osi /C/simopenpass/deps/thirdParty
       cp -r protobuf /C/simopenpass/deps/thirdParty
       cp -r protobuf-shared /C/simopenpass/deps/thirdParty
       cp -r FMILibrary /C/simopenpass/deps/thirdParty

       cp -r osi ~/simopenpass/deps/thirdParty
       cp -r protobuf ~/simopenpass/deps/thirdParty
       cp -r protobuf-shared ~/simopenpass/deps/thirdParty
       cp -r FMILibrary ~/simopenpass/deps/thirdParty

   Once prerequisites are in place, all third party dependencies within `simopenpass` can be resolved by `CMake`. For `CMake` builds, each installed prerequisite, which is located in its own subdirectory under

   - `C:\simopenpass\deps\thirdParty` for Windows and

   - `~/simopenpass/deps/thirdParty` for Linux,

   can be referenced by its path. The reference is made via the CMAKE_PREFIX_PATH environmental variable, which holds a list of directories specifying the installed prerequisite. This will be explained in more detail in the following.

6. Navigate back into repository

       cd /C/simopenpass

       cd ~/simopenpass

7. Create build directory and navigate into it

       mkdir build
       cd build

8. Prepare build

   OpenPASS links against shared libraries, which are located in the paths specified by `CMAKE_PREFIX_PATH`. To be able to install OpenPASS with resolved dependencies, all libraries found under the paths have to be copied right next to the executable during the installation step. This is done by setting `INSTALL_EXTRA_RUNTIME_DEPS=ON`. If you have followed the instructions strictly, no changes are necessary.

       cmake -G "MSYS Makefiles" \
       -D CMAKE_PREFIX_PATH="C:/msys64/mingw64/bin;C:/simopenpass/deps/thirdParty/FMILibrary;C:/simopenpass/deps/thirdParty/osi;C:/simopenpass/deps/thirdParty/protobuf;C:/simopenpass/deps/thirdParty/protobuf-shared" \
       -D CMAKE_INSTALL_PREFIX=C:/OpenPASS/bin/core \
       -D CMAKE_BUILD_TYPE=Release \
       -D USE_CCACHE=ON \
       -D WITH_DEBUG_POSTFIX=OFF \
       -D OPENPASS_ADJUST_OUTPUT=OFF \
       -D INSTALL_EXTRA_RUNTIME_DEPS=ON \
       -D CMAKE_C_COMPILER=gcc \
       -D CMAKE_CXX_COMPILER=g++ \
       ..

   Note

   By specifying `INSTALL_EXTRA_RUNTIME_DEPS=ON`, runtime dependencies will be copied to the installation directory when running `make install`. This applies to all dependencies located in the paths specified in `CMAKE_PREFIX_PATH`.

       cmake -D CMAKE_PREFIX_PATH="$HOME/simopenpass/deps/thirdParty/FMILibrary;$HOME/simopenpass/deps/thirdParty/osi;$HOME/simopenpass/deps/thirdParty/protobuf;$HOME/simopenpass/deps/thirdParty/protobuf-shared" \
       -D CMAKE_INSTALL_PREFIX=/usr/local/OpenPASS/bin/core \
       -D CMAKE_BUILD_TYPE=Release \
       -D USE_CCACHE=ON \
       -D WITH_DEBUG_POSTFIX=OFF \
       -D OPENPASS_ADJUST_OUTPUT=OFF \
       -D INSTALL_EXTRA_RUNTIME_DEPS=ON \
       -D CMAKE_C_COMPILER=gcc-9 \
       -D CMAKE_CXX_COMPILER=g++-9 \
       ..

   Note

   For a build that goes beyond the default settings, see CMake Variables and Options for more available variables and options that can be set.

9. Optional: Build and execute unit tests

   Starting from `simopenpass/build`:

       make test ARGS="--output-on-failure -j3"

   Note

   ARGS is optional, but recommended. Adjust parallel build flag `-j3` based on your system.

10. Build documentation

    Starting from `simopenpass/build`:

        make doc

    Note

    Currently the documentation must be built before openPASS can be successfully installed if the CMake variable WITH_DOC=ON (default).

11. Build simulation core

    Starting from `simopenpass/build`:

        make -j3 install

    Note

    Again, adjust parallel build flag `-j3` based on your system.

12. Fix installation (we’re working on that…)

        cp /C/OpenPASS/bin/core/bin/* /C/OpenPASS/bin/core

        cp /usr/local/OpenPASS/bin/core/bin/* /usr/local/OpenPASS/bin/core