summaryrefslogtreecommitdiff
path: root/build/appveyor/win_setcompiler.bat
blob: a3eb90cd052a68443fd2702766c5683e89c0636d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
::
:: Licensed under the Apache License, Version 2.0 (the "License");
:: you may not use this file except in compliance with the License.
:: You may obtain a copy of the License at
::
::     http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing, software
:: distributed under the License is distributed on an "AS IS" BASIS,
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
:: See the License for the specific language governing permissions and
:: limitations under the License.
::

::
:: Detect the compiler edition we're building in.
:: Set the COMPILER environment variable to one of:
::   gcc   = MinGW / MSYS2 and gcc toolchain
::   vc100 = Visual Studio 2010
::   vc110 = Visual Studio 2012
::   vc120 = Visual Studio 2013
::   vc140 = Visual Studio 2015
::   vc141 = Visual Studio 2017
::
:: Honors any existing COMPILER environment variable
::   setting instead of overwriting it, to allow it
::   to be forced if needed.
::
:: Sets ERRORLEVEL to 0 if COMPILER can be determined,
::                 to 1 if it cannot.
::

IF DEFINED COMPILER (
  ECHO [warn ] using existing environment variable COMPILER
  EXIT /B 0
)

IF NOT "%PROFILE:~0,4%" == "MSVC" (
  SET COMPILER=gcc
) ELSE (
  CALL :CHECK 16
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc100)
  CALL :CHECK 17
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc110)
  CALL :CHECK 18
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc120)
  CALL :CHECK 19.0
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc140)
  CALL :CHECK 19.1
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc141)
  CALL :CHECK 19.2
  IF !ERRORLEVEL! == 0 (SET COMPILER=vc142)
)

IF NOT DEFINED COMPILER (
  ECHO [error] unable to determine the compiler edition
  EXIT /B 1
)

ECHO [info ] detected compiler edition    %COMPILER%
EXIT /B 0

:CHECK
cl /? 2>&1 | findstr /C:"Version %1%" > nul
EXIT /B