steps:
- bash: |
    wget https://github.com/phracker/MacOSX-SDKs/releases/download/10.13/MacOSX$(target_platform).sdk.tar.xz
    tar Jxvf MacOSX$(target_platform).sdk.tar.xz
  displayName: Install MacOSX $(target_platform) SDK
- script: |
    echo "Removing homebrew from Azure to avoid conflicts."
    curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew
    chmod +x ~/uninstall_homebrew
    ~/uninstall_homebrew -fq
    rm ~/uninstall_homebrew
  displayName: Remove homebrew
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    sudo chown -R ${USER} ${CONDA}
    mkdir -p $HOME/.matplotlib
    echo -e "backend: TkAgg\n" > $HOME/.matplotlib/matplotlibrc
    conda config --set always_yes yes --set changeps1 no
    conda update -q conda
    conda create --name rdkit_build $(compiler) cmake \
        boost-cpp=$(boost_version) boost=$(boost_version) \
        py-boost=$(boost_version) libboost=$(boost_version) \
        numpy matplotlib cairo pillow eigen pandas
  displayName: Setup build environment
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    export SDKROOT="$(pwd)/MacOSX$(target_platform).sdk/"
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    mkdir build && cd build && \
    cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DRDK_INSTALL_INTREE=ON \
    -DRDK_INSTALL_STATIC_LIBS=OFF \
    -DRDK_BUILD_CPP_TESTS=ON \
    -DRDK_BUILD_PYTHON_WRAPPERS=ON \
    -DRDK_USE_BOOST_REGEX=ON \
    -DRDK_BUILD_COORDGEN_SUPPORT=ON \
    -DRDK_OPTIMIZE_NATIVE=ON \
    -DRDK_BUILD_TEST_GZIP=ON \
    -DRDK_BUILD_FREESASA_SUPPORT=ON \
    -DRDK_BUILD_AVALON_SUPPORT=ON \
    -DRDK_BUILD_INCHI_SUPPORT=ON \
    -DRDK_BUILD_SWIG_WRAPPERS=OFF \
    -DRDK_SWIG_STATIC=OFF \
    -DRDK_BUILD_THREADSAFE_SSS=ON \
    -DRDK_TEST_MULTITHREADED=ON \
    -DBoost_NO_SYSTEM_PATHS=ON \
    -DCMAKE_OSX_SYSROOT=${SDKROOT} \
    -DCMAKE_OSX_DEPLOYMENT_TARGET=$(target_platform) \
    -DRDK_BOOST_PYTHON3_NAME=$(python_name) \
    -DPYTHON_EXECUTABLE=${CONDA_PREFIX}/bin/python3 \
    -DCMAKE_INCLUDE_PATH="${CONDA_PREFIX}/include" \
    -DCMAKE_LIBRARY_PATH="${CONDA_PREFIX}/lib"
  displayName: Configure build (Run CMake)
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    export SDKROOT="$(pwd)/MacOSX$(target_platform).sdk/"
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    cd build
    make -j $( $(number_of_cores) ) install
  displayName: Build
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    export RDBASE=`pwd`
    export PYTHONPATH=${RDBASE}:${PYTHONPATH}
    export DYLD_FALLBACK_LIBRARY_PATH=${RDBASE}/lib:${RDBASE}/rdkit:${CONDA_PREFIX}/lib:${DYLD_FALLBACK_LIBRARY_PATH}
    export SDKROOT="$(pwd)/MacOSX$(target_platform).sdk/"
    export CONDA_BUILD_SYSROOT=${SDKROOT}
    export QT_QPA_PLATFORM='offscreen'
    cd build
    ctest -j $( $(number_of_cores) ) --output-on-failure -T Test
  displayName: Run tests
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'CTest'
    testResultsFiles: 'build/Testing/*/Test.xml'
    testRunTitle: $(system.phasedisplayname) CTest Test Run
