version: '{branch}.{build}'
clone_depth: 1

environment:
    # Tell msys2 to add mingw64 to the path
    MSYSTEM: MINGW64
    # Tell msys2 to inherit the current directory when starting the shell
    CHERE_INVOKING: 1

install:
    # Download libiio
    - cd c:\
    - appveyor DownloadFile https://ci.appveyor.com/api/projects/analogdevicesinc/libiio/artifacts/libiio.zip?branch=master
    - 7z x libiio*.zip > nul
    - mkdir libiio-win64
    - mkdir libiio-win32
    - mkdir libiio-mingw-win64
    - mkdir libiio-mingw-win32
    - mv libiio-*/MS64/* libiio-win64/
    - cp libiio-*/include/* libiio-win64/
    - mv libiio-*/MS32/* libiio-win32/
    - cp libiio-*/include/* libiio-win32/
    - mv libiio-*/MinGW32/* libiio-mingw-win32/
    - cp libiio-*/include/* libiio-mingw-win32/
    - mv libiio-*/MinGW64/* libiio-mingw-win64/
    - cp libiio-*/include/* libiio-mingw-win64/

    #Install Inno Setup
    - choco install InnoSetup
    - set PATH=%PATH%;"C:\Program Files (x86)\Inno Setup 5"



build_script:
    # 32-bit build - MinGW
    - set OLD_PATH=%PATH%
    - set OPT_PATH=C:\msys64\mingw32\bin;C:\msys64\mingw64\bin;
    - set PATH=%OPT_PATH%%PATH%

    - mkdir c:\projects\libad9361-iio\build-mingw-win32
    - cd c:\projects\libad9361-iio\build-mingw-win32
#    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy  mingw-w64-i686-gcc "
    - cmake -G "Unix Makefiles" \
        -DLIBIIO_LIBRARIES:FILEPATH=c:/libiio-mingw-win32/libiio.dll.a \
        -DLIBIIO_INCLUDEDIR:PATH=c:/libiio-mingw-win32 \
        -DCMAKE_CONFIGURATION_TYPES=Release \
        -DCMAKE_C_COMPILER:FILEPATH=c:/msys64/mingw32/bin/i686-w64-mingw32-gcc.exe \
        -DCMAKE_MAKE_PROGRAM=c:/msys64/mingw32/bin/mingw32-make.exe \
        ..
    - cmake --build . --config Release
    - copy c:\libiio-mingw-win32\*.dll c:\projects\libad9361-iio\build-mingw-win32\test\
    - copy c:\projects\libad9361-iio\build-mingw-win32\*.dll c:\projects\libad9361-iio\build-mingw-win32\test\
    - ctest -V -R

    # 64-bit build - MinGW
    - mkdir c:\projects\libad9361-iio\build-mingw-win64
    - cd c:\projects\libad9361-iio\build-mingw-win64
#    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy  mingw-w64-x86_64-gcc"
    - cmake -G "Unix Makefiles" \
        -DLIBIIO_LIBRARIES:FILEPATH=c:/libiio-mingw-win64/libiio.dll.a \
        -DLIBIIO_INCLUDEDIR:PATH=c:/libiio-mingw-win64 \
        -DCMAKE_CONFIGURATION_TYPES=Release \
        -DCMAKE_C_COMPILER:FILEPATH=c:/msys64/mingw64/bin/x86_64-w64-mingw32-gcc.exe \
        -DCMAKE_MAKE_PROGRAM=c:/msys64/mingw64/bin/mingw32-make.exe \
        ..
    - cmake --build . --config Release
    - copy c:\libiio-mingw-win64\*.dll c:\projects\libad9361-iio\build-mingw-win64\test\
    - copy c:\projects\libad9361-iio\build-mingw-win64\*.dll c:\projects\libad9361-iio\build-mingw-win64\test\
    - ctest -V -R

    # 32-bit build - VS
    - mkdir c:\projects\libad9361-iio\build-win32
    - cd c:\projects\libad9361-iio\build-win32
    - cmake -G "Visual Studio 12" \
        -DLIBIIO_LIBRARIES:FILEPATH=c:/libiio-win32/libiio.lib \
        -DLIBIIO_INCLUDEDIR:PATH=c:/libiio-win32 \
        -DCMAKE_CONFIGURATION_TYPES=Release \
        ..
    - cmake --build . --config Release
    - copy c:\libiio-win32\*.dll c:\projects\libad9361-iio\build-win32\test\Release
    - copy c:\projects\libad9361-iio\build-win32\Release\*.dll c:\projects\libad9361-iio\build-win32\test\Release
    - ctest -V -C Release

    # 64-bit build - VS
    - mkdir c:\projects\libad9361-iio\build-win64
    - cd c:\projects\libad9361-iio\build-win64
    - cmake -G "Visual Studio 12 Win64" \
        -DLIBIIO_LIBRARIES:FILEPATH=c:/libiio-win64/libiio.lib \
        -DLIBIIO_INCLUDEDIR:PATH=c:/libiio-win64 \
        -DCMAKE_CONFIGURATION_TYPES=Release \
        ..
    - cmake --build . --config Release
    - copy c:\libiio-win64\*.dll c:\projects\libad9361-iio\build-win64\test\Release
    - copy c:\projects\libad9361-iio\build-win64\Release\*.dll c:\projects\libad9361-iio\build-win64\test\Release
    - ctest -V -C Release
    
    #Create the installer
    - ISCC c:\projects\libad9361-iio\build-win64\libad9361-iio.iss
    - appveyor PushArtifact C:\libad9361-setup.exe

    # Create ZIPs
    - cd c:\projects\libad9361-iio

    - mkdir c:\libad9361-win32
    - copy ad9361.h c:\libad9361-win32\
    - copy bindings\matlab\ad9361-wrapper.h c:\libad9361-win32\
    - copy build-win32\Release\libad9361.* c:\libad9361-win32\
    - copy c:\libiio-win32\*.dll c:\libad9361-win32\
    - 7z a "c:\libad9361-win32.zip" c:\libad9361-win32
    - appveyor PushArtifact c:\libad9361-win32.zip

    - mkdir c:\libad9361-win64
    - copy ad9361.h c:\libad9361-win64\
    - copy bindings\matlab\ad9361-wrapper.h c:\libad9361-win64\
    - copy build-win64\Release\libad9361.* c:\libad9361-win64\
    - copy c:\libiio-win64\*.dll c:\libad9361-win64\
    - 7z a "c:\libad9361-win64.zip" c:\libad9361-win64
    - appveyor PushArtifact c:\libad9361-win64.zip

    - mkdir c:\libad9361-mingw-win32
    - copy ad9361.h c:\libad9361-mingw-win32\
    - copy bindings\matlab\ad9361-wrapper.h c:\libad9361-mingw-win32\
    - copy build-mingw-win32\libad9361.* c:\libad9361-mingw-win32\
    - copy c:\libiio-mingw-win32\*.dll c:\libad9361-mingw-win32\
    - 7z a "c:\libad9361-mingw-win32.zip" c:\libad9361-mingw-win32
    - appveyor PushArtifact c:\libad9361-mingw-win32.zip

    - mkdir c:\libad9361-mingw-win64
    - copy ad9361.h c:\libad9361-mingw-win64\
    - copy bindings\matlab\ad9361-wrapper.h c:\libad9361-mingw-win64\
    - copy build-mingw-win64\libad9361.* c:\libad9361-mingw-win64\
    - copy c:\libiio-mingw-win64\*.dll c:\libad9361-mingw-win64\
    - 7z a "c:\libad9361-mingw-win64.zip" c:\libad9361-mingw-win64
    - appveyor PushArtifact c:\libad9361-mingw-win64.zip
