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

image:
  - Visual Studio 2015
  - Visual Studio 2017

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

# clone directory
clone_folder: C:\projects\stp

platform:
  - x64
#  - x86

environment:
  global:
    BOOST_ROOT: C:\projects\stp\boost_1_59_0_install
    MINISAT_ROOT: C:\projects\stp\minisat\myinstall
    ZLIB_ROOT: C:\projects\stp\zlib\myinstall
    PYTHON: "C:\\Python27"
    PYTHON_ARCH: "x86"
    PYTHON_VERSION: "2.7.13"
    BUILD_TYPE: Release
    APPVEYOR_SAVE_CACHE_ON_ERROR: false
    BOOST_OPTIONS: link=static runtime-link=static

    # 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

install:
    "%PYTHON%\\python.exe -m pip install lit"

configuration:
  - Release

#cache:
  #- C:\projects\stp\llvm -> appveyor.yml
  #- C:\projects\stp\llvm.build -> appveyor.yml

before_build:
  - IF "%PLATFORM%" == "x86" ( SET CMAKE_GENERATOR="Visual Studio 14 2015")
  - IF "%PLATFORM%" == "x64" ( SET CMAKE_GENERATOR="Visual Studio 14 2015 Win64")

  - echo %PLATFORM%
  - echo %CMAKE_GENERATOR%
  - echo %configuration%
  - echo %APPVEYOR_BUILD_FOLDER%
  - echo %cd%

  # The STP query-file-tests require the "not" tool. For now, we use the one
  # provided by LLVM. This should eventually be replaced by the not tool of
  # OutputCheck.
  #
  # Note: the tests are currently disabled on AppVeyor (see below)
  #
  # - cd C:\projects\stp
  # - if not exist llvm git clone --depth=1 --branch release_40 https://github.com/llvm-mirror/llvm
  # - if not exist llvm.build mkdir llvm.build
  # - cd llvm.build
  # - if not exist Release\bin\not.exe cmake -G %CMAKE_GENERATOR% -DPYTHON_EXECUTABLE=%PYTHON%\python.exe ..\llvm
  # - if not exist Release\bin\not.exe cmake --build . --config Release --target not
  # - set PATH=%PATH%;%cd%\Release\bin

  # boost
  - cd C:\projects\stp
  - 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
  - cd C:\projects\stp
  - 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% ..
  - cmake --build . --config %CONFIGURATION%
  - cmake --build . --config %CONFIGURATION% --target install
  - dir ..\myinstall\

  # minisat
  - cd C:\projects\stp
  - git clone https://github.com/msoos/minisat
  - cd minisat
  - echo %cd%
  - mkdir build
  - mkdir myinstall
  - cd build
  - cmake -DSTATICCOMPILE=ON -G %CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX=%MINISAT_ROOT% -DZLIB_ROOT=%ZLIB_ROOT% ..
  - cmake --build . --config %CONFIGURATION%
  - cmake --build . --config %CONFIGURATION% --target install
  - dir ..\myinstall\
  - dir ..\myinstall\lib\
  - dir ..\myinstall\bin\
  - dir ..\myinstall\include\


  # cryptominisat
  - cd C:\projects\stp
  - git clone https://github.com/msoos/cryptominisat
  - cd cryptominisat
  - git submodule update --init --recursive
  - mkdir build
  - cd build
  - cmake --version
  - cmake -G %CMAKE_GENERATOR% -DSTATICCOMPILE=ON -DNOZLIB=ON -DENABLE_PYTHON_INTERFACE=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DONLY_SIMPLE=ON -DENABLE_TESTING=OFF ..
  - cmake --build . --config Release
  - cmake --build . --config Release --target install
  - cd ../..

  # get flex, bison, perl
  - cd C:\projects\stp
  - C:\cygwin64\setup-x86_64.exe  -qnNd -R C:/cygwin64 -s http://cygwin.mirror.constant.com -l C:/cygwin64/var/cache/setup --packages "flex,bison,perl"
  # prepend cygwin to %PATH% so that Cygwin's cat.exe is used instead of Git's
  # one. This had caused Cygwin version conflicts (probably due to the wrong
  # Cygwin DLL being loaded for cat.exe)
  - SET PATH=C:/cygwin64/bin;%PATH%

  # finally STP
  - cd c:\projects\stp
  - git submodule update --init --recursive
  # Building in c:\projects\stp\build fails with cmake --build since ASTKind.h
  # cannot be found, so build it in ..\stp.build
  - mkdir ..\stp.build
  - cd ..\stp.build
  - cmake --version
  - cmake -G %CMAKE_GENERATOR% -DENABLE_TESTING=NO -DENABLE_PYTHON_INTERFACE=OFF -DMINISAT_LIBDIR=%MINISAT_ROOT% -DMINISAT_INCLUDE_DIRS=%MINISAT_ROOT%\include -DSTATICCOMPILE=ON -DZLIB_ROOT=%ZLIB_ROOT% -DCMAKE_PREFIX_PATH=C:\cygwin64 -DBOOST_LIBRARYDIR=%BOOST_ROOT%/lib -DBoost_DEBUG=1 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DBOOST_ROOT=%BOOST_ROOT% ../stp
  - ls


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

after_build:
  - echo "%APPVEYOR_BUILD_FOLDER%"
  - echo %APPVEYOR_BUILD_FOLDER%
  #- dir /s /b

  - 7z a c:\projects\stp\stp.zip C:\projects\stp.build\bin\stp.exe -tzip
  - cd c:\projects\stp

artifacts:
  - path: stp.zip
    name: stp.zip

test: off
