-
Notifications
You must be signed in to change notification settings - Fork 6
/
Setup.py
156 lines (138 loc) · 6.08 KB
/
Setup.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
import shlex, subprocess
import sys
import configparser
import pkg_resources
import shutil
required = {'gitpython'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if missing:
python = sys.executable
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
from pathlib import Path
import os, fnmatch
from git import Repo
def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(name)
return result
#read a .properties file without section headers.
def add_section_header(properties_file, header_name):
# configparser.ConfigParser requires at least one section header in a properties file.
# Our properties file doesn't have one, so add a header to it on the fly.
yield '[{}]\n'.format(header_name)
for line in properties_file:
yield line
def read_config_file(filename):
config = configparser.RawConfigParser()
if not os.path.isfile(filename):
file = open(filename, "w+", encoding="utf_8")
else:
file = open(filename, encoding="utf_8")
config.read_file(add_section_header(file, 'asection'), source=filename)
return config['asection']
def cmake(src,build_path,cmake_generator,flags):
wd=os.getcwd()
Path(build_path).mkdir(True,exist_ok=True)
os.chdir(build_path)
vs_versions=[cmake_generator,'Visual Studio 17 2022','Visual Studio 16 2019','Visual Studio 15 2017']
for vs_version in vs_versions:
cmakeCmd = ["cmake.exe", '-G',vs_version, os.path.relpath(src, build_path)]
#print(' '.join(cmakeCmd+flags))
retCode = subprocess.check_call(cmakeCmd+flags, stderr=subprocess.STDOUT, shell=True)
if retCode!=0:
continue
sln=find('*.sln','.')[0]
print(MSBUILD+'/p:Configuration=Release'+'/p:Platform=x64'+sln)
pid=subprocess.Popen([MSBUILD,'/p:Configuration=Release','/p:Platform=x64',sln])
pid.poll()
break
print(MSBUILD+'/p:Configuration=Debug'+'/p:Platform=x64'+sln)
pid=subprocess.Popen([MSBUILD,'/p:Configuration=Debug','/p:Platform=x64',sln])
pid.poll()
#copy outputs if executable e.g. dll's:
if os.path.exists("bin"):
main_build=wd+"/build"
if not os.path.exists(main_build):
os.makedirs(main_build)
#distutils.dir_util.copy_tree("bin", main_build+"/bin", update=1)
shutil.copytree("bin", main_build+"/bin", dirs_exist_ok=True)
os.chdir(wd)
def get_cmake_generator(build_path,default_gen):
wd=os.getcwd()
print(wd)
print(os.path.relpath(wd, build_path))
result=default_gen
cmakeCmd = ["cmake.exe", '-LA','-N', build_path]
try:
process = subprocess.Popen(cmakeCmd, stdout=subprocess.PIPE)
out = process.stdout.readlines()
for ln in out:
x = re.search(r"PLATFORM_USED_CMAKE_GENERATOR\:STRING\=([a-zA-Z0-9 ]*)", str(ln))
if x:
result=x.group(1)
process.poll()
except:
pass
return result
def GetMSBuild():
VSW=os.environ['ProgramFiles(x86)']+'/Microsoft Visual Studio/Installer/vswhere.exe'
print('VSW '+VSW)
process = subprocess.Popen([VSW,'-latest','-find','MSBuild\\**\\Bin\\MSBuild.exe'], stdout=subprocess.PIPE)
#'-requires','Microsoft.Component.MSBuild', not useful.
MSB = process.stdout.readline().strip().decode('UTF-8')
process.poll()
if MSB!="":
return MSB
print("vswhere did not find MSBuild, falling back to path search:")
for root, dirs, files in os.walk(os.environ['ProgramFiles(x86)']):
if "MSBuild.exe" in files:
MSB=os.path.join(root, "MSBuild.exe")
if MSB!="":
return MSB
for root, dirs, files in os.walk(os.environ['ProgramFiles']):
if "MSBuild.exe" in files:
MSB=os.path.join(root, "MSBuild.exe")
print('MSB '+MSB)
return MSB
def execute():
cmake_gen=get_cmake_generator('build','Visual Studio 17 2022')
print(cmake_gen)
repo = Repo(os.getcwd())
#We update only the submodules in "External" - others are private and must be handled manually.
sms = repo.submodules
for sm in sms:
if('External' in sm.name):
if sm.url[0:3] == '../':
repo.git.execute(command=['git', 'submodule', 'update', '--init', '--recursive', sm.name]) ##Alternate method for relative path
else:
sm.update(init=True,force=True,recursive=True)
print("Successfully Updated " + sm.name)
#else:
#print("Skipping " +sm.name)
fmt_md_flags=["-DCMAKE_CONFIGURATION_TYPES=Debug;Release","-DFMT_DOC=false","-DFMT_TEST=false","-DFMT_INSTALL=false",
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=lib","-DCMAKE_STATIC_LIBRARY_PREFIX_CXX=md_","-DCMAKE_CXX_FLAGS_DEBUG=/MDd /Zi /Ob0 /Od /RTC1",
"-DCMAKE_CXX_FLAGS_RELEASE=/MD /Ob2 /DNDEBUG"]
#"--trace-source=CMakeLists.txt"]
cmake('External/fmt','External/fmt/build_md',cmake_gen,fmt_md_flags)
fmt_mt_flags=["-DCMAKE_BUILD_TYPE=None","-DCMAKE_CONFIGURATION_TYPES=Debug;Release","-DFMT_DOC=false","-DFMT_TEST=false",
"-DFMT_INSTALL=false","-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=lib","-DCMAKE_STATIC_LIBRARY_PREFIX_CXX=mt_",
"-DCMAKE_CXX_FLAGS_DEBUG=/MTd /Zi /Ob0 /Od /RTC1","-DCMAKE_CXX_FLAGS_RELEASE=/MT /Ob2 /DNDEBUG"]
#,"--trace-source=CMakeLists.txt"]
cmake('External/fmt','External/fmt/build_mt',cmake_gen,fmt_mt_flags)
glfwflags=["-DGLFW_BUILD_DOCS=false","-DGLFW_BUILD_EXAMPLES=false","-DGLFW_BUILD_TESTS=false","-DGLFW_INSTALL=false","-DCMAKE_C_FLAGS_DEBUG=/MTd /Zi /Ob0 /Od /RTC1","-DCMAKE_C_FLAGS_RELEASE=/MT /Ob2 /DNDEBUG","-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=../lib"]
cmake('External/glfw','External/glfw/build_md',cmake_gen,glfwflags)
cmake('External/glfw','External/glfw/build_mt',cmake_gen,glfwflags+["-DUSE_MSVC_RUNTIME_LIBRARY_DLL=false"])
assimpflags=["-DASSIMP_BUILD_DOCS=false","-DASSIMP_BUILD_EXAMPLES=false","-DASSIMP_BUILD_TESTS=false","-DASSIMP_INSTALL=false","-DCMAKE_C_FLAGS_DEBUG=/MTd /Zi /Ob0 /Od /RTC1","-DCMAKE_C_FLAGS_RELEASE=/MT /Ob2 /DNDEBUG","-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=../lib"]
cmake('External/assimp','External/assimp/build_md',cmake_gen,glfwflags)
cmake('External/assimp','External/assimp/build_mt',cmake_gen,glfwflags+["-DUSE_MSVC_RUNTIME_LIBRARY_DLL=false"])
platform_flags=[]
cmake('.','build',cmake_gen,platform_flags)
version=read_config_file('version.properties')
user=read_config_file('user.properties')
MSBUILD=user.get('MSBUILD',GetMSBuild())
execute()