platform:
  - x64

image:
  - Visual Studio 2015

configuration:
  - Debug

install:
  - set CONDA_ENV=build
  - C:\Miniconda3-x64\Scripts\activate base
  - conda config --set always_yes yes
  - conda create --channel conda-forge
                 --name %CONDA_ENV%
                 cmake
                 deepdiff
                 intel-openmp=2018.0.3
                 mkl-devel=2018.0.3
                 mpmath
                 networkx
                 ninja
                 numpy
                 pybind11
                 pytest
                 python=3.6
  - conda clean --all
  - activate %CONDA_ENV%
  - conda install --channel psi4
                 qcelemental
  - conda list

before_build:
  - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
  - set SOURCE_FOLDER=%APPVEYOR_BUILD_FOLDER%
  - set BUILD_FOLDER=%SOURCE_FOLDER%\build
  - set INSTALL_FOLDER=%SOURCE_FOLDER%\install
  - mkdir %BUILD_FOLDER% & cd %BUILD_FOLDER%
  - cmake -G Ninja
          -DCMAKE_BUILD_TYPE=%CONFIGURATION%
          -DCMAKE_INSTALL_PREFIX=%INSTALL_FOLDER%
          -DCMAKE_C_COMPILER=clang-cl
          -DCMAKE_CXX_COMPILER=clang-cl
          -DENABLE_XHOST=OFF
          -DMAX_AM_ERI=5
          %SOURCE_FOLDER%

build_script:
  - cmake --build .
          --config %CONFIGURATION%
          -- -j %NUMBER_OF_PROCESSORS%

after_build:
  - cmake --build .
          --config %CONFIGURATION%
          --target install
          -- -j %NUMBER_OF_PROCESSORS%

before_test:
  - set PYTHONPATH=%INSTALL_FOLDER%\lib
  - python -c "import sys, psi4; print(sys.path); print(psi4)"
  - dir %BUILD_FOLDER%\stage\lib
  - dir %INSTALL_FOLDER%\lib
  # TODO create psi4.bat and set PATH
  - python %INSTALL_FOLDER%\bin\psi4 --version

test_script:
  # Check if OpenMP config hadn't failed silently
  - python -c "from psi4 import core; core.set_num_threads(42); assert core.get_num_threads() == 42"
  - python %INSTALL_FOLDER%\bin\psi4 %SOURCE_FOLDER%\tests\tu1-h2o-energy\input.dat
  #
  # Skipped long tests (not enough time to run all of them):
  #     cbs-delta-energy cbs-xtpl-gradien
  #     dfmp2-ecp fnocc2
  #     mp2-module
  #     scf5
  #     psimrcc-sp1
  #     pywrap-all pywrap-cbs1
  #
  # Failling tests:
  #     ci-property
  #
  # Tests requiring AM > 5:
  #     opt-full-hess-every
  #
  - ctest --build-config %CONFIGURATION%
          --exclude-regex "^(cbs-delta-energy|cbs-xtpl-gradient|dfmp2-ecp|fnocc2|mp2-module|scf5|psimrcc-sp1|pywrap-all|pywrap-cbs1|ci-property|opt-full-hess-every)$"
          --label-regex quick
          --output-on-failure
          --parallel %NUMBER_OF_PROCESSORS%
  - python %INSTALL_FOLDER%\bin\psi4 --test

after_test:
  # Run failling tests, but their results are ignored
  # TODO fix the tests
  - ctest --build-config %CONFIGURATION%
          --tests-regex "^(ci-property)$"
          --output-on-failure
          --parallel %NUMBER_OF_PROCESSORS% & exit 0

cache:
  - C:\Miniconda3-x64\pkgs

artifacts:
  - path: install
    name: psi4
  - path: build\tests
    name: tests

branches:
  only:
    - master
    # - 1.3.x
