This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler_version.py
65 lines (55 loc) · 2.37 KB
/
compiler_version.py
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
import sys, os, subprocess
from subprocess import PIPE, run
def main():
if sys.platform == "linux" or sys.platform == "linux2":
if len(sys.argv) > 1:
cxx=sys.argv[1]
else:
cxx="gcc"
return get_linux_compiler(cxx)
elif sys.platform == "win32":
if len(sys.argv) > 1:
msvc=sys.argv[1]
else:
msvc="15"
return get_windows_compiler(msvc)
def get_windows_compiler(msvc_version_number):
compiler="msvc"
version=""
if msvc_version_number == "15" or msvc_version_number == "2017":
version="15.0"
os.environ["VCROOT"] = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Auxiliary\\Build\\"
os.environ["VSINSTALLDIR"] = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\"
os.environ["VisualStudioVersion"] = "15.0"
os.environ["Platform"] = "x64"
msbuild="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\MSBuild.exe"
output=subprocess.run([f"doskey", f"msbuild={msbuild}"], shell=True)
elif msvc_version_number == "16" or msvc_version_number == "2019":
version="16.0"
os.environ["VCROOT"] = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Auxiliary\\Build\\"
os.environ["VSINSTALLDIR"] = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\"
os.environ["VisualStudioVersion"] = "16.0"
os.environ["Platform"] = "x64"
msbuild="C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe"
output=subprocess.run([f"doskey", f"msbuild={msbuild}"], shell=True)
else:
return ""
print(f"Found compiler {compiler}-{version}")
return f"{compiler}-{version}"
def get_linux_compiler(compiler_name):
compiler=""
version=""
if "clang" in compiler_name:
command=['clang','--version']
elif "gcc" in compiler_name or "g++" in compiler_name:
command=['gcc','--version']
else:
return ""
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
output_list=result.stdout.split('\n')
output=output_list[0]
output=output.split()
compiler=output[0]
version=output[-1]
print(f"Found compiler {compiler}-{version}")
return f"{compiler}-{version}"