# branches to build
branches:
  # whitelist
  only:
    - master
    - appveyor_debug

image:
  - Visual Studio 2015
  # if 2015 works, this should work too
  - Visual Studio 2017
  # may or may not work, let's not try
  #- Visual Studio 2013

# scripts that are called at very beginning, before repo cloning
init:
  - git config --global core.autocrlf input


# clone directory
clone_folder: c:\projects\cryptominisat

platform:
  - x64

environment:
  global:
    BOOST_ROOT: C:\projects\cryptominisat\boost_1_59_0_install
    ZLIB_ROOT: C:\projects\cryptominisat\zlib\myinstall
    PYTHON: "C:\\Python36-x64"
    BUILD_TYPE: Release
    APPVEYOR_SAVE_CACHE_ON_ERROR: false

    # WarningLevel of 1 is ONLY SEVERE warnings, nothing else. See
    # https://stackoverflow.com/questions/1023858/how-to-suppress-specific-msbuild-warning
    MSBUILD_FLAGS: /maxcpucount /nologo /property:WarningLevel=1
  matrix:
  # Normal
  - DYNAMIC_COMPILE_SETTING: OFF
    STATICCOMPILE_SETTING: ON
    EXTRA_FLAGS:
    BOOST_OPTIONS: link=static runtime-link=static

  # Largemem
  - DYNAMIC_COMPILE_SETTING: OFF
    STATICCOMPILE_SETTING: ON
    BOOST_OPTIONS: link=static runtime-link=static
    EXTRA_FLAGS: -DLARGEMEM=ON

  # Gauss
  - DYNAMIC_COMPILE_SETTING: OFF
    STATICCOMPILE_SETTING: ON
    BOOST_OPTIONS: link=static runtime-link=static
    EXTRA_FLAGS: -DUSE_GAUSS=ON

  #- DYNAMIC_COMPILE_SETTING: ON
    #STATICCOMPILE_SETTING: OFF
    #EXTRA_FLAGS:
    #BOOST_OPTIONS: link=shared runtime-link=shared

configuration:
  - Release

before_build:
  - IF "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" ( SET CMAKE_GENERATOR="Visual Studio 15 2017 Win64")
  - IF "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" ( SET CMAKE_GENERATOR="Visual Studio 14 2015 Win64")
  - echo "APPVEYOR_BUILD_WORKER_IMAGE:"
  - echo %APPVEYOR_BUILD_WORKER_IMAGE%
  - echo "cmake generator:"
  - echo %CMAKE_GENERATOR%
  - echo "platform:"
  - echo %PLATFORM%
  - echo %configuration%

  # get "lit" from python pip
  - echo "Python is:"
  - echo %PYTHON%
  - "%PYTHON%/python -m pip install lit"
  - echo "Querying lit version..."
  - "%PYTHON%/python -m lit.main --version"
  - cd %PYTHON%/
  - ls

  # boost
  - cd c:\projects\cryptominisat
  - mkdir boost_1_59_0_install
  - ps: . .\scripts\appveyor.ps1
  - cd boost_1_59_0
  - echo "Building boost.."
  - bootstrap.bat --with-libraries=program_options
  - cat project-config.jam
  - b2 --with-program_options address-model=64 toolset=msvc-14.0 variant=release %BOOST_OPTIONS% threading=multi  install --prefix=%BOOST_ROOT% > boost_install.out

  # zlib
  # TODO check out http://stackoverflow.com/questions/10507893/libzip-with-visual-studio-2010
  # below is C:\projects\cryptominisat
  - cd C:\projects\cryptominisat
  - git clone https://github.com/madler/zlib
  - cd zlib
  - git checkout v1.2.8
  - echo %cd%
  - mkdir build
  - mkdir myinstall
  - cd build
  - cmake -G %CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX=%ZLIB_ROOT% ..
  - if %PLATFORM%==x64 call msbuild %MSBUILD_FLAGS% /t:Build /p:Configuration=%CONFIGURATION% /p:Platform="x64" zlib.sln
  - msbuild %MSBUILD_FLAGS% INSTALL.vcxproj

  # build CMS
  - echo Running cmake...
  - cd c:\projects\cryptominisat
  - git submodule update --init --recursive
  - mkdir build
  - cd build
  - cmake --version

  # :(((
  # cannot enable testing becasue of visibility issues: -DENABLE_TESTING=%DYNAMIC_COMPILE_SETTING%
  # :(((

  - cmake -G %CMAKE_GENERATOR% %EXTRA_FLAGS%  -DENABLE_PYTHON_INTERFACE=%DYNAMIC_COMPILE_SETTING% -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DSTATICCOMPILE=%STATICCOMPILE_SETTING% -DZLIB_ROOT=%ZLIB_ROOT% -DPYTHON_LIBRARY=%PYTHON%/libs -DPYTHON_INCLUDE_DIR=%PYTHON%/include -DPYTHON_EXECUTABLE:FILEPATH=%PYTHON%/python.exe -DBoost_DEBUG=1 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DBOOST_ROOT=%BOOST_ROOT% ..
  - ls

build_script:
  - cmake --build . --config Release

after_build:
  #- call ctest -V -C %CONFIGURATION%
  # - call DUMPBIN C:\Program Files\cryptominisat5\bin\cryptominisat5_simple.exe /ALL
  # - call "C:\Program Files\cryptominisat5\bin\cryptominisat5_simple.exe" --help
  # - call "C:\Program Files\cryptominisat5\bin\cryptominisat5.exe" --help
  - echo %APPVEYOR_BUILD_FOLDER%
  - 7z a c:\projects\cryptominisat\cryptominisat5.zip %APPVEYOR_BUILD_FOLDER%\build\Release\cryptominisat5.exe -tzip
  - cd c:\projects\cryptominisat

artifacts:
  - path: cryptominisat5.zip
    name: cryptominisat5.zip

deploy_script:
  #- cd c:\projects\cryptominisat
  #- curl -T cryptominisat.zip --user %ACCOUNT% https://someplace/

test: off
