blob: 09f16d9870c38501cd3d2b5e7a424bb1cf17ff4a [file] [log] [blame]
Mark Youngc65d3252016-01-06 15:58:55 -07001#!/usr/bin/env python3
2#
3# Copyright (C) 2016 Valve Corporation
4# Copyright (C) 2016 Google Inc.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a
7# copy of this software and associated documentation files (the "Software"),
8# to deal in the Software without restriction, including without limitation
9# the rights to use, copy, modify, merge, publish, distribute, sublicense,
10# and/or sell copies of the Software, and to permit persons to whom the
11# Software is furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included
14# in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22# DEALINGS IN THE SOFTWARE.
23#
24# Author: Mark Young <marky@lunarg.com>
25
26import sys
27import os
28
29# Following function code snippet was found on StackOverflow (with a change to lower
30# camel-case on the variable names):
31# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
32def find_executable(program):
33 def is_exe(fPath):
34 return os.path.isfile(fPath) and os.access(fPath, os.X_OK)
35
36 fPath, fName = os.path.split(program)
37 if fPath:
38 if is_exe(program):
39 return program
40 else:
41 for path in os.environ["PATH"].split(os.pathsep):
42 path = path.strip('"')
43 exe_file = os.path.join(path, program)
44 if is_exe(exe_file):
45 return exe_file
46
47 return None
48
49def determine_year(version):
50 if version == 8:
51 return 2005
52 elif version == 9:
53 return 2008
54 elif version == 10:
55 return 2010
56 elif version == 11:
57 return 2012
58 elif version == 12:
59 return 2013
60 elif version == 14:
61 return 2015
62 else:
63 return 0000
64
65# Determine if msbuild is in the path, then call it to determine the version and parse
66# it into a format we can use, which is "<version_num> <version_year>".
67if __name__ == '__main__':
68 exeName = 'msbuild.exe'
69 versionCall = exeName + ' /ver'
70
71 # Determine if the executable exists in the path, this is critical.
72 #
73 foundExeName = find_executable(exeName)
74
75 # If not found, return an invalid number but in the appropriate format so it will
76 # fail if the program above tries to use it.
77 if foundExeName == None:
78 print('00 0000 Win32')
79 print('Executable ' + exeName + ' not found in PATH!')
80 else:
81 sysCallOut = os.popen(versionCall).read()
82
83 version = None
84
85 # Split around any spaces first
86 spaceList = sysCallOut.split(' ')
87 for spaceString in spaceList:
88
89 # If we've already found it, bail.
90 if version != None:
91 break
92
93 # Now split around line feeds
94 lineList = spaceString.split('\n')
95 for curLine in lineList:
96
97 # If we've already found it, bail.
98 if version != None:
99 break
100
101 # We only want to continue if there's a period in the list
102 if '.' not in curLine:
103 continue
104
105 # Get the first element and determine if it is a number, if so, we've
106 # got our number.
107 splitAroundPeriod = curLine.split('.')
108 if splitAroundPeriod[0].isdigit():
109 version = int (splitAroundPeriod[0])
110 break
111
112 # Failsafe to return a number in the proper format, but one that will fail.
113 if version == None:
114 version = 00
115
116 # Determine the year associated with that version
117 year = determine_year(version)
118
Mark Younge7da8372016-01-07 12:43:07 -0700119 # TODO: Add detect to deteremine the OS target of current system.
120 # Hard-code to Win64 for now since it's all we officially support.
121 #osTarget = 'Win32'
122 #if os.environ.get('PROCESSOR_ARCHITECTURE', '') == 'AMD64':
123 # osTarget = 'Win64'
124 osTarget = 'Win64'
125
Mark Youngc65d3252016-01-06 15:58:55 -0700126 # Output the string we need for Cmake to properly build for this version
127 print(str(version) + ' ' + str(year) + ' ' + osTarget)