Skip to content

Build SOFA using Conda

Olivier Roussel edited this page Apr 30, 2024 · 5 revisions

This tutorial will help you setting up a development environment to compile SOFA from sources within a conda environment. All the required dependencies will be installed by conda as conda packages and in a dedicated isolated conda environment.

If you do not want to build SOFA from source but are rather interested in installing SOFA as a conda package (to use SOFA binaries or consume SOFA a development library, for example if you are a SOFA plugin developer), please check this page instead.

Setup conda

Install miniforge conda distribution

If you are new to conda or do not have a recent conda version, consider installing last version of miniforge available here. Miniforge is a conda distribution maintained by the conda-forge community, which is the most active open-source conda community. Miniforge is also preconfigured to use the conda-forge channel by default.

Create & activate conda environment

Let's assume we will develop in an environment named sofa-dev-env.

conda create -n sofa-dev-env
conda activate sofa-dev-env

Install SOFA dependencies

  1. Download the conda environment yaml file corresponding to your platform from available ones from here
wget https://github.com/sofa-framework/conda-ci/blob/master/.github/workflows/conda/sofa/environment_<platform>.yml

by replacing <platform> by one of the following availables ones (linux-64, osx-64, win-64).

Note that osx-arm64 platform is currently being added and should be available soon.

  1. Update your conda environment

This yaml file contains SOFA dependencies for your platform as a list of conda packages. We will install all these packages in our conda environment by:

conda env update --name sofa-dev-env --file environment_<platform>.yml

by substituing <platform> with the one you downloaded before.

You can also use this file to install these conda packages manually through the conda install command.

Compile SOFA

cmake -S <sofa_source_dir> -B <sofa_build_dir> -DCMAKE_PREFIX_PATH="$CONDA_PREFIX;$CONDA_PREFIX/lib/cmake" -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
make
make install

Remarks:

  • This will install SOFA in the root directory of our conda environment (i.e. $CONDA_PREFIX directory, defined by your current active environment) which is recommended to provide a good separation of you install. If you need to compile other sources that will use this SOFA installation, you should use a cmake command with the following base:
cmake -S <source_dir> -B <build_dir> -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
  • Specifying the CMAKE_PREFIX_PATH is required only here because we want to change the default installation dir with CMAKE_INSTALL_PREFIX
  • The tricky $CONDA_PREFIX/lib/cmake additionnal value set to CMAKE_PREFIX_PATH is due to the Qt dependency which install itself with non-standard directories.