The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
647 lines
33 KiB
647 lines
33 KiB
9 years ago
|
# Copyright 2014-2016 The Meson development team
|
||
11 years ago
|
|
||
|
# 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.
|
||
|
|
||
11 years ago
|
import os, sys
|
||
9 years ago
|
import pickle
|
||
9 years ago
|
from . import backends
|
||
|
from .. import build
|
||
|
from .. import dependencies
|
||
|
from .. import mlog
|
||
11 years ago
|
import xml.etree.ElementTree as ET
|
||
|
import xml.dom.minidom
|
||
9 years ago
|
from ..coredata import MesonException
|
||
11 years ago
|
|
||
9 years ago
|
class RegenInfo():
|
||
|
def __init__(self, source_dir, build_dir, depfiles, solutionfile):
|
||
|
self.source_dir = source_dir
|
||
|
self.build_dir = build_dir
|
||
|
self.depfiles = depfiles
|
||
|
self.solutionfile = solutionfile
|
||
|
|
||
11 years ago
|
class Vs2010Backend(backends.Backend):
|
||
9 years ago
|
def __init__(self, build):
|
||
|
super().__init__(build)
|
||
11 years ago
|
self.project_file_version = '10.0.30319.1'
|
||
|
# foo.c compiles to foo.obj, not foo.c.obj
|
||
|
self.source_suffix_in_obj = False
|
||
|
|
||
|
def generate_custom_generator_commands(self, target, parent_node):
|
||
|
idgroup = ET.SubElement(parent_node, 'ItemDefinitionGroup')
|
||
|
all_output_files = []
|
||
|
for genlist in target.get_generated_sources():
|
||
9 years ago
|
if isinstance(genlist, build.CustomTarget):
|
||
|
all_output_files += [os.path.join(self.get_target_dir(genlist), i) for i in genlist.output]
|
||
11 years ago
|
else:
|
||
9 years ago
|
generator = genlist.get_generator()
|
||
|
exe = generator.get_exe()
|
||
|
infilelist = genlist.get_infilelist()
|
||
|
outfilelist = genlist.get_outfilelist()
|
||
|
if isinstance(exe, build.BuildTarget):
|
||
|
exe_file = os.path.join(self.environment.get_build_dir(), self.get_target_filename(exe))
|
||
11 years ago
|
else:
|
||
9 years ago
|
exe_file = exe.get_command()
|
||
|
base_args = generator.get_arglist()
|
||
|
for i in range(len(infilelist)):
|
||
|
if len(infilelist) == len(outfilelist):
|
||
9 years ago
|
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i])
|
||
9 years ago
|
else:
|
||
|
sole_output = ''
|
||
|
curfile = infilelist[i]
|
||
|
infilename = os.path.join(self.environment.get_source_dir(), curfile)
|
||
|
outfiles = genlist.get_outputs_for(curfile)
|
||
9 years ago
|
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]
|
||
9 years ago
|
all_output_files += outfiles
|
||
|
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\
|
||
|
for x in base_args]
|
||
9 years ago
|
args = [x.replace("@SOURCE_DIR@", self.environment.get_source_dir()).replace("@BUILD_DIR@", self.get_target_private_dir(target))
|
||
9 years ago
|
for x in args]
|
||
|
fullcmd = [exe_file] + args
|
||
|
cbs = ET.SubElement(idgroup, 'CustomBuildStep')
|
||
|
ET.SubElement(cbs, 'Command').text = ' '.join(self.special_quote(fullcmd))
|
||
|
ET.SubElement(cbs, 'Inputs').text = infilename
|
||
|
ET.SubElement(cbs, 'Outputs').text = ';'.join(outfiles)
|
||
|
ET.SubElement(cbs, 'Message').text = 'Generating sources from %s.' % infilename
|
||
11 years ago
|
pg = ET.SubElement(parent_node, 'PropertyGroup')
|
||
|
ET.SubElement(pg, 'CustomBuildBeforeTargets').text = 'ClCompile'
|
||
|
return all_output_files
|
||
|
|
||
9 years ago
|
def generate(self, interp):
|
||
|
self.interpreter = interp
|
||
9 years ago
|
self.platform = 'Win32'
|
||
|
self.buildtype = self.environment.coredata.get_builtin_option('buildtype')
|
||
11 years ago
|
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
|
||
|
projlist = self.generate_projects()
|
||
|
self.gen_testproj('RUN_TESTS', os.path.join(self.environment.get_build_dir(), 'RUN_TESTS.vcxproj'))
|
||
9 years ago
|
self.gen_regenproj('REGEN', os.path.join(self.environment.get_build_dir(), 'REGEN.vcxproj'))
|
||
11 years ago
|
self.generate_solution(sln_filename, projlist)
|
||
9 years ago
|
self.generate_regen_info(sln_filename)
|
||
9 years ago
|
open(os.path.join(self.environment.get_scratch_dir(), 'regen.stamp'), 'wb')
|
||
|
rulefile = os.path.join(self.environment.get_scratch_dir(), 'regen.rule')
|
||
|
if not os.path.exists(rulefile):
|
||
|
open(rulefile, 'w').write("# For some reason this needs to be here.")
|
||
9 years ago
|
|
||
|
def generate_regen_info(self, sln_filename):
|
||
|
deps = self.get_regen_filelist()
|
||
|
regeninfo = RegenInfo(self.environment.get_source_dir(),
|
||
|
self.environment.get_build_dir(),
|
||
|
deps,
|
||
|
sln_filename)
|
||
|
pickle.dump(regeninfo, open(os.path.join(self.environment.get_scratch_dir(), 'regeninfo.dump'), 'wb'))
|
||
11 years ago
|
|
||
|
def get_obj_target_deps(self, obj_list):
|
||
|
result = {}
|
||
|
for o in obj_list:
|
||
|
if isinstance(o, build.ExtractedObjects):
|
||
|
result[o.target.get_basename()] = True
|
||
|
return result.keys()
|
||
|
|
||
9 years ago
|
def determine_deps(self, p):
|
||
|
all_deps = {}
|
||
|
target = self.build.targets[p[0]]
|
||
|
if isinstance(target, build.CustomTarget):
|
||
|
for d in target.dependencies:
|
||
|
all_deps[d.get_id()] = True
|
||
|
return all_deps
|
||
9 years ago
|
if isinstance(target, build.RunTarget):
|
||
|
for d in [target.command] + target.args:
|
||
|
if isinstance(d, build.BuildTarget):
|
||
|
all_deps[d.get_id()] = True
|
||
|
return all_deps
|
||
9 years ago
|
for ldep in target.link_targets:
|
||
|
all_deps[ldep.get_id()] = True
|
||
|
for objdep in self.get_obj_target_deps(target.objects):
|
||
|
all_deps[objdep] = True
|
||
|
for gendep in target.generated:
|
||
|
if isinstance(gendep, build.CustomTarget):
|
||
|
all_deps[gendep.get_id()] = True
|
||
|
else:
|
||
|
gen_exe = gendep.generator.get_exe()
|
||
|
if isinstance(gen_exe, build.Executable):
|
||
|
all_deps[gen_exe.get_id()] = True
|
||
|
return all_deps
|
||
|
|
||
11 years ago
|
def generate_solution(self, sln_filename, projlist):
|
||
|
ofile = open(sln_filename, 'w')
|
||
|
ofile.write('Microsoft Visual Studio Solution File, Format Version 11.00\n')
|
||
|
ofile.write('# Visual Studio 2010\n')
|
||
|
prj_templ = prj_line = 'Project("{%s}") = "%s", "%s", "{%s}"\n'
|
||
|
for p in projlist:
|
||
|
prj_line = prj_templ % (self.environment.coredata.guid, p[0], p[1], p[2])
|
||
|
ofile.write(prj_line)
|
||
9 years ago
|
all_deps = self.determine_deps(p)
|
||
9 years ago
|
ofile.write('\tProjectSection(ProjectDependencies) = postProject\n')
|
||
|
regen_guid = self.environment.coredata.regen_guid
|
||
|
ofile.write('\t\t{%s} = {%s}\n' % (regen_guid, regen_guid))
|
||
|
for dep in all_deps.keys():
|
||
|
guid = self.environment.coredata.target_guids[dep]
|
||
|
ofile.write('\t\t{%s} = {%s}\n' % (guid, guid))
|
||
|
ofile.write('EndProjectSection\n')
|
||
11 years ago
|
ofile.write('EndProject\n')
|
||
|
test_line = prj_templ % (self.environment.coredata.guid,
|
||
|
'RUN_TESTS', 'RUN_TESTS.vcxproj', self.environment.coredata.test_guid)
|
||
|
ofile.write(test_line)
|
||
9 years ago
|
ofile.write('EndProject\n')
|
||
9 years ago
|
regen_line = prj_templ % (self.environment.coredata.guid,
|
||
|
'REGEN', 'REGEN.vcxproj', self.environment.coredata.regen_guid)
|
||
|
ofile.write(regen_line)
|
||
11 years ago
|
ofile.write('EndProject\n')
|
||
|
ofile.write('Global\n')
|
||
|
ofile.write('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n')
|
||
9 years ago
|
ofile.write('\t\t%s|%s = %s|%s\n' % (self.buildtype, self.platform, self.buildtype, self.platform))
|
||
11 years ago
|
ofile.write('\tEndGlobalSection\n')
|
||
|
ofile.write('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n')
|
||
9 years ago
|
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
|
||
|
(self.environment.coredata.regen_guid, self.buildtype, self.platform,
|
||
|
self.buildtype, self.platform))
|
||
|
ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' %
|
||
|
(self.environment.coredata.regen_guid, self.buildtype, self.platform,
|
||
|
self.buildtype, self.platform))
|
||
11 years ago
|
for p in projlist:
|
||
9 years ago
|
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
|
||
|
(p[2], self.buildtype, self.platform,
|
||
|
self.buildtype, self.platform))
|
||
9 years ago
|
if not isinstance(self.build.targets[p[0]], build.RunTarget):
|
||
9 years ago
|
ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' %
|
||
|
(p[2], self.buildtype, self.platform,
|
||
|
self.buildtype, self.platform))
|
||
|
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
|
||
|
(self.environment.coredata.test_guid, self.buildtype, self.platform,
|
||
|
self.buildtype, self.platform))
|
||
11 years ago
|
ofile.write('\tEndGlobalSection\n')
|
||
|
ofile.write('\tGlobalSection(SolutionProperties) = preSolution\n')
|
||
|
ofile.write('\t\tHideSolutionNode = FALSE\n')
|
||
|
ofile.write('\tEndGlobalSection\n')
|
||
|
ofile.write('EndGlobal\n')
|
||
|
|
||
|
def generate_projects(self):
|
||
|
projlist = []
|
||
9 years ago
|
comp = None
|
||
|
for l, c in self.environment.coredata.compilers.items():
|
||
|
if l == 'c' or l == 'cpp':
|
||
|
comp = c
|
||
|
break
|
||
|
if comp is None:
|
||
|
raise RuntimeError('C and C++ compilers missing.')
|
||
11 years ago
|
for name, target in self.build.targets.items():
|
||
9 years ago
|
outdir = os.path.join(self.environment.get_build_dir(), self.get_target_dir(target))
|
||
11 years ago
|
fname = name + '.vcxproj'
|
||
|
relname = os.path.join(target.subdir, fname)
|
||
|
projfile = os.path.join(outdir, fname)
|
||
|
uuid = self.environment.coredata.target_guids[name]
|
||
9 years ago
|
self.gen_vcxproj(target, projfile, uuid, comp)
|
||
11 years ago
|
projlist.append((name, relname, uuid))
|
||
|
return projlist
|
||
|
|
||
|
def split_sources(self, srclist):
|
||
|
sources = []
|
||
|
headers = []
|
||
|
for i in srclist:
|
||
|
if self.environment.is_header(i):
|
||
|
headers.append(i)
|
||
|
else:
|
||
|
sources.append(i)
|
||
|
return (sources, headers)
|
||
|
|
||
|
def target_to_build_root(self, target):
|
||
|
if target.subdir == '':
|
||
|
return ''
|
||
10 years ago
|
|
||
|
directories = os.path.split(target.subdir)
|
||
|
directories = list(filter(bool,directories)) #Filter out empty strings
|
||
|
|
||
|
return '/'.join(['..']*len(directories))
|
||
11 years ago
|
|
||
|
def special_quote(self, arr):
|
||
|
return ['"%s"' % i for i in arr]
|
||
|
|
||
9 years ago
|
def create_basic_crap(self, target):
|
||
9 years ago
|
project_name = target.name
|
||
|
root = ET.Element('Project', {'DefaultTargets' : "Build",
|
||
|
'ToolsVersion' : '4.0',
|
||
|
'xmlns' : 'http://schemas.microsoft.com/developer/msbuild/2003'})
|
||
|
confitems = ET.SubElement(root, 'ItemGroup', {'Label' : 'ProjectConfigurations'})
|
||
9 years ago
|
prjconf = ET.SubElement(confitems, 'ProjectConfiguration',
|
||
|
{'Include' : self.buildtype + '|' + self.platform})
|
||
9 years ago
|
p = ET.SubElement(prjconf, 'Configuration')
|
||
9 years ago
|
p.text= self.buildtype
|
||
9 years ago
|
pl = ET.SubElement(prjconf, 'Platform')
|
||
9 years ago
|
pl.text = self.platform
|
||
9 years ago
|
globalgroup = ET.SubElement(root, 'PropertyGroup', Label='Globals')
|
||
|
guidelem = ET.SubElement(globalgroup, 'ProjectGuid')
|
||
|
guidelem.text = self.environment.coredata.test_guid
|
||
|
kw = ET.SubElement(globalgroup, 'Keyword')
|
||
9 years ago
|
kw.text = self.platform + 'Proj'
|
||
9 years ago
|
p = ET.SubElement(globalgroup, 'Platform')
|
||
9 years ago
|
p.text= self.platform
|
||
9 years ago
|
pname= ET.SubElement(globalgroup, 'ProjectName')
|
||
|
pname.text = project_name
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props')
|
||
|
type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration')
|
||
|
ET.SubElement(type_config, 'ConfigurationType')
|
||
|
ET.SubElement(type_config, 'CharacterSet').text = 'MultiByte'
|
||
|
ET.SubElement(type_config, 'UseOfMfc').text = 'false'
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props')
|
||
|
direlem = ET.SubElement(root, 'PropertyGroup')
|
||
|
fver = ET.SubElement(direlem, '_ProjectFileVersion')
|
||
|
fver.text = self.project_file_version
|
||
|
outdir = ET.SubElement(direlem, 'OutDir')
|
||
|
outdir.text = '.\\'
|
||
|
intdir = ET.SubElement(direlem, 'IntDir')
|
||
|
intdir.text = 'test-temp\\'
|
||
|
tname = ET.SubElement(direlem, 'TargetName')
|
||
|
tname.text = target.name
|
||
9 years ago
|
return root
|
||
|
|
||
|
def gen_run_target_vcxproj(self, target, ofname, guid):
|
||
|
root = self.create_basic_crap(target)
|
||
|
action = ET.SubElement(root, 'ItemDefinitionGroup')
|
||
|
customstep = ET.SubElement(action, 'PostBuildEvent')
|
||
|
cmd_raw = [target.command] + target.args
|
||
|
cmd = [sys.executable, os.path.join(self.environment.get_script_dir(), 'commandrunner.py'),
|
||
|
self.environment.get_build_dir(), self.environment.get_source_dir(),
|
||
|
self.get_target_dir(target)]
|
||
|
for i in cmd_raw:
|
||
|
if isinstance(i, build.BuildTarget):
|
||
|
cmd.append(os.path.join(self.environment.get_build_dir(), self.get_target_filename(i)))
|
||
|
elif isinstance(i, dependencies.ExternalProgram):
|
||
|
cmd += i.fullpath
|
||
|
else:
|
||
|
cmd.append(i)
|
||
|
cmd_templ = '''"%s" '''*len(cmd)
|
||
|
ET.SubElement(customstep, 'Command').text = cmd_templ % tuple(cmd)
|
||
|
ET.SubElement(customstep, 'Message').text = 'Running custom command.'
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets')
|
||
|
tree = ET.ElementTree(root)
|
||
|
tree.write(ofname, encoding='utf-8', xml_declaration=True)
|
||
|
|
||
|
def gen_custom_target_vcxproj(self, target, ofname, guid):
|
||
|
root = self.create_basic_crap(target)
|
||
9 years ago
|
action = ET.SubElement(root, 'ItemDefinitionGroup')
|
||
|
customstep = ET.SubElement(action, 'CustomBuildStep')
|
||
9 years ago
|
(srcs, ofilenames, cmd) = self.eval_custom_target_command(target, True)
|
||
9 years ago
|
cmd_templ = '''"%s" '''*len(cmd)
|
||
|
ET.SubElement(customstep, 'Command').text = cmd_templ % tuple(cmd)
|
||
|
ET.SubElement(customstep, 'Outputs').text = ';'.join([os.path.join(self.environment.get_build_dir(), i)\
|
||
|
for i in ofilenames])
|
||
|
ET.SubElement(customstep, 'Inputs').text = ';'.join([os.path.join(self.environment.get_build_dir(), i) \
|
||
|
for i in srcs])
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets')
|
||
|
tree = ET.ElementTree(root)
|
||
|
tree.write(ofname, encoding='utf-8', xml_declaration=True)
|
||
9 years ago
|
|
||
|
def gen_vcxproj(self, target, ofname, guid, compiler):
|
||
9 years ago
|
mlog.debug('Generating vcxproj %s.' % target.name)
|
||
11 years ago
|
entrypoint = 'WinMainCRTStartup'
|
||
|
subsystem = 'Windows'
|
||
|
if isinstance(target, build.Executable):
|
||
|
conftype = 'Application'
|
||
|
if not target.gui_app:
|
||
|
subsystem = 'Console'
|
||
|
entrypoint = 'mainCRTStartup'
|
||
|
elif isinstance(target, build.StaticLibrary):
|
||
|
conftype = 'StaticLibrary'
|
||
|
elif isinstance(target, build.SharedLibrary):
|
||
|
conftype = 'DynamicLibrary'
|
||
|
entrypoint = '_DllMainCrtStartup'
|
||
9 years ago
|
elif isinstance(target, build.CustomTarget):
|
||
9 years ago
|
return self.gen_custom_target_vcxproj(target, ofname, guid)
|
||
9 years ago
|
elif isinstance(target, build.RunTarget):
|
||
|
return self.gen_run_target_vcxproj(target, ofname, guid)
|
||
11 years ago
|
else:
|
||
9 years ago
|
raise MesonException('Unknown target type for %s' % target.get_basename())
|
||
|
down = self.target_to_build_root(target)
|
||
|
proj_to_src_root = os.path.join(down, self.build_to_src)
|
||
|
proj_to_src_dir = os.path.join(proj_to_src_root, target.subdir)
|
||
|
(sources, headers) = self.split_sources(target.sources)
|
||
9 years ago
|
buildtype = self.buildtype
|
||
9 years ago
|
project_name = target.name
|
||
|
target_name = target.name
|
||
11 years ago
|
root = ET.Element('Project', {'DefaultTargets' : "Build",
|
||
10 years ago
|
'ToolsVersion' : '4.0',
|
||
|
'xmlns' : 'http://schemas.microsoft.com/developer/msbuild/2003'})
|
||
11 years ago
|
confitems = ET.SubElement(root, 'ItemGroup', {'Label' : 'ProjectConfigurations'})
|
||
9 years ago
|
prjconf = ET.SubElement(confitems, 'ProjectConfiguration',
|
||
|
{'Include' : self.buildtype + '|' + self.platform})
|
||
11 years ago
|
p = ET.SubElement(prjconf, 'Configuration')
|
||
|
p.text= buildtype
|
||
|
pl = ET.SubElement(prjconf, 'Platform')
|
||
9 years ago
|
pl.text = self.platform
|
||
11 years ago
|
globalgroup = ET.SubElement(root, 'PropertyGroup', Label='Globals')
|
||
|
guidelem = ET.SubElement(globalgroup, 'ProjectGuid')
|
||
|
guidelem.text = guid
|
||
|
kw = ET.SubElement(globalgroup, 'Keyword')
|
||
9 years ago
|
kw.text = self.platform + 'Proj'
|
||
11 years ago
|
ns = ET.SubElement(globalgroup, 'RootNamespace')
|
||
|
ns.text = target_name
|
||
|
p = ET.SubElement(globalgroup, 'Platform')
|
||
9 years ago
|
p.text= self.platform
|
||
11 years ago
|
pname= ET.SubElement(globalgroup, 'ProjectName')
|
||
|
pname.text = project_name
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props')
|
||
|
type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration')
|
||
|
ET.SubElement(type_config, 'ConfigurationType').text = conftype
|
||
|
ET.SubElement(type_config, 'CharacterSet').text = 'MultiByte'
|
||
|
ET.SubElement(type_config, 'WholeProgramOptimization').text = 'false'
|
||
|
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props')
|
||
|
generated_files = self.generate_custom_generator_commands(target, root)
|
||
|
(gen_src, gen_hdrs) = self.split_sources(generated_files)
|
||
|
direlem = ET.SubElement(root, 'PropertyGroup')
|
||
|
fver = ET.SubElement(direlem, '_ProjectFileVersion')
|
||
|
fver.text = self.project_file_version
|
||
|
outdir = ET.SubElement(direlem, 'OutDir')
|
||
|
outdir.text = '.\\'
|
||
|
intdir = ET.SubElement(direlem, 'IntDir')
|
||
|
intdir.text = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir') + '\\'
|
||
|
tname = ET.SubElement(direlem, 'TargetName')
|
||
|
tname.text = target_name
|
||
|
inclinc = ET.SubElement(direlem, 'LinkIncremental')
|
||
|
inclinc.text = 'true'
|
||
|
|
||
|
compiles = ET.SubElement(root, 'ItemDefinitionGroup')
|
||
|
clconf = ET.SubElement(compiles, 'ClCompile')
|
||
|
opt = ET.SubElement(clconf, 'Optimization')
|
||
|
opt.text = 'disabled'
|
||
9 years ago
|
inc_dirs = [proj_to_src_dir, self.get_target_private_dir(target)]
|
||
10 years ago
|
cur_dir = target.subdir
|
||
|
if cur_dir == '':
|
||
|
cur_dir= '.'
|
||
|
inc_dirs.append(cur_dir)
|
||
11 years ago
|
extra_args = []
|
||
|
# SUCKS, VS can not handle per-language type flags, so just use
|
||
|
# them all.
|
||
9 years ago
|
extra_args += compiler.get_buildtype_args(self.buildtype)
|
||
9 years ago
|
for l in self.environment.coredata.external_args.values():
|
||
|
for a in l:
|
||
|
extra_args.append(a)
|
||
11 years ago
|
for l in self.build.global_args.values():
|
||
|
for a in l:
|
||
|
extra_args.append(a)
|
||
|
for l in target.extra_args.values():
|
||
|
for a in l:
|
||
|
extra_args.append(a)
|
||
9 years ago
|
# FIXME all the internal flags of VS (optimization etc) are represented
|
||
|
# by their own XML elements. In theory we should split all flags to those
|
||
|
# that have an XML element and those that don't and serialise them
|
||
|
# properly. This is a crapton of work for no real gain, so just dump them
|
||
|
# here.
|
||
|
extra_args = compiler.get_option_compile_args(self.environment.coredata.compiler_options)
|
||
11 years ago
|
if len(extra_args) > 0:
|
||
|
extra_args.append('%(AdditionalOptions)')
|
||
|
ET.SubElement(clconf, "AdditionalOptions").text = ' '.join(extra_args)
|
||
|
for d in target.include_dirs:
|
||
|
for i in d.incdirs:
|
||
|
curdir = os.path.join(d.curdir, i)
|
||
|
inc_dirs.append(self.relpath(curdir, target.subdir)) # build dir
|
||
|
inc_dirs.append(os.path.join(proj_to_src_root, curdir)) # src dir
|
||
|
inc_dirs.append('%(AdditionalIncludeDirectories)')
|
||
|
ET.SubElement(clconf, 'AdditionalIncludeDirectories').text = ';'.join(inc_dirs)
|
||
|
preproc = ET.SubElement(clconf, 'PreprocessorDefinitions')
|
||
|
rebuild = ET.SubElement(clconf, 'MinimalRebuild')
|
||
|
rebuild.text = 'true'
|
||
|
rtlib = ET.SubElement(clconf, 'RuntimeLibrary')
|
||
|
rtlib.text = 'MultiThreadedDebugDLL'
|
||
|
funclink = ET.SubElement(clconf, 'FunctionLevelLinking')
|
||
|
funclink.text = 'true'
|
||
|
pch = ET.SubElement(clconf, 'PrecompiledHeader')
|
||
|
warnings = ET.SubElement(clconf, 'WarningLevel')
|
||
|
warnings.text = 'Level3'
|
||
|
debinfo = ET.SubElement(clconf, 'DebugInformationFormat')
|
||
|
debinfo.text = 'EditAndContinue'
|
||
|
resourcecompile = ET.SubElement(compiles, 'ResourceCompile')
|
||
|
ET.SubElement(resourcecompile, 'PreprocessorDefinitions')
|
||
|
link = ET.SubElement(compiles, 'Link')
|
||
9 years ago
|
# Put all language args here, too.
|
||
|
extra_link_args = compiler.get_option_link_args(self.environment.coredata.compiler_options)
|
||
|
extra_link_args += compiler.get_buildtype_linker_args(self.buildtype)
|
||
|
for l in self.environment.coredata.external_link_args.values():
|
||
|
for a in l:
|
||
|
extra_link_args.append(a)
|
||
|
for l in target.link_args:
|
||
|
for a in l:
|
||
|
extra_link_args.append(a)
|
||
|
if len(extra_args) > 0:
|
||
|
extra_args.append('%(AdditionalOptions)')
|
||
|
ET.SubElement(link, "AdditionalOptions").text = ' '.join(extra_args)
|
||
|
|
||
11 years ago
|
additional_links = []
|
||
|
for t in target.link_targets:
|
||
9 years ago
|
lobj = self.build.targets[t.get_id()]
|
||
11 years ago
|
rel_path = self.relpath(lobj.subdir, target.subdir)
|
||
|
linkname = os.path.join(rel_path, lobj.get_import_filename())
|
||
|
additional_links.append(linkname)
|
||
|
for o in self.flatten_object_list(target, down):
|
||
|
assert(isinstance(o, str))
|
||
|
additional_links.append(o)
|
||
|
if len(additional_links) > 0:
|
||
|
additional_links.append('%(AdditionalDependencies)')
|
||
|
ET.SubElement(link, 'AdditionalDependencies').text = ';'.join(additional_links)
|
||
|
ofile = ET.SubElement(link, 'OutputFile')
|
||
|
ofile.text = '$(OutDir)%s' % target.get_filename()
|
||
|
addlibdir = ET.SubElement(link, 'AdditionalLibraryDirectories')
|
||
|
addlibdir.text = '%(AdditionalLibraryDirectories)'
|
||
|
subsys = ET.SubElement(link, 'SubSystem')
|
||
|
subsys.text = subsystem
|
||
|
gendeb = ET.SubElement(link, 'GenerateDebugInformation')
|
||
|
gendeb.text = 'true'
|
||
|
if isinstance(target, build.SharedLibrary):
|
||
|
ET.SubElement(link, 'ImportLibrary').text = target.get_import_filename()
|
||
|
pdb = ET.SubElement(link, 'ProgramDataBaseFileName')
|
||
|
pdb.text = '$(OutDir}%s.pdb' % target_name
|
||
|
if isinstance(target, build.Executable):
|
||
|
ET.SubElement(link, 'EntryPointSymbol').text = entrypoint
|
||
|
targetmachine = ET.SubElement(link, 'TargetMachine')
|
||
|
targetmachine.text = 'MachineX86'
|
||
|
|
||
|
if len(headers) + len(gen_hdrs) > 0:
|
||
|
inc_hdrs = ET.SubElement(root, 'ItemGroup')
|
||
|
for h in headers:
|
||
10 years ago
|
relpath = h.rel_to_builddir(proj_to_src_root)
|
||
11 years ago
|
ET.SubElement(inc_hdrs, 'CLInclude', Include=relpath)
|
||
|
for h in gen_hdrs:
|
||
9 years ago
|
if isinstance(h, str):
|
||
|
relpath = h
|
||
|
else:
|
||
|
relpath = h.rel_to_builddir(proj_to_src_root)
|
||
11 years ago
|
ET.SubElement(inc_hdrs, 'CLInclude', Include = relpath)
|
||
|
if len(sources) + len(gen_src) > 0:
|
||
|
inc_src = ET.SubElement(root, 'ItemGroup')
|
||
|
for s in sources:
|
||
10 years ago
|
relpath = s.rel_to_builddir(proj_to_src_root)
|
||
11 years ago
|
ET.SubElement(inc_src, 'CLCompile', Include=relpath)
|
||
|
for s in gen_src:
|
||
|
relpath = self.relpath(s, target.subdir)
|
||
|
ET.SubElement(inc_src, 'CLCompile', Include=relpath)
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets')
|
||
9 years ago
|
# Reference the regen target.
|
||
|
ig = ET.SubElement(root, 'ItemGroup')
|
||
|
pref = ET.SubElement(ig, 'ProjectReference', Include=os.path.join(self.environment.get_build_dir(), 'REGEN.vcxproj'))
|
||
|
ET.SubElement(pref, 'Project').text = self.environment.coredata.regen_guid
|
||
11 years ago
|
tree = ET.ElementTree(root)
|
||
|
tree.write(ofname, encoding='utf-8', xml_declaration=True)
|
||
|
# ElementTree can not do prettyprinting so do it manually
|
||
|
doc = xml.dom.minidom.parse(ofname)
|
||
|
open(ofname, 'w').write(doc.toprettyxml())
|
||
|
# World of horror! Python insists on not quoting quotes and
|
||
|
# fixing the escaped " into " whereas MSVS
|
||
|
# requires quoted but not fixed elements. Enter horrible hack.
|
||
|
txt = open(ofname, 'r').read()
|
||
|
open(ofname, 'w').write(txt.replace('"', '"'))
|
||
|
|
||
9 years ago
|
def gen_regenproj(self, project_name, ofname):
|
||
|
root = ET.Element('Project', {'DefaultTargets': 'Build',
|
||
|
'ToolsVersion' : '4.0',
|
||
|
'xmlns' : 'http://schemas.microsoft.com/developer/msbuild/2003'})
|
||
|
confitems = ET.SubElement(root, 'ItemGroup', {'Label' : 'ProjectConfigurations'})
|
||
9 years ago
|
prjconf = ET.SubElement(confitems, 'ProjectConfiguration',
|
||
|
{'Include' : self.buildtype + '|' + self.platform})
|
||
9 years ago
|
p = ET.SubElement(prjconf, 'Configuration')
|
||
9 years ago
|
p.text= self.buildtype
|
||
9 years ago
|
pl = ET.SubElement(prjconf, 'Platform')
|
||
9 years ago
|
pl.text = self.platform
|
||
9 years ago
|
globalgroup = ET.SubElement(root, 'PropertyGroup', Label='Globals')
|
||
|
guidelem = ET.SubElement(globalgroup, 'ProjectGuid')
|
||
|
guidelem.text = self.environment.coredata.test_guid
|
||
|
kw = ET.SubElement(globalgroup, 'Keyword')
|
||
9 years ago
|
kw.text = self.platform + 'Proj'
|
||
9 years ago
|
p = ET.SubElement(globalgroup, 'Platform')
|
||
9 years ago
|
p.text = self.platform
|
||
9 years ago
|
pname= ET.SubElement(globalgroup, 'ProjectName')
|
||
|
pname.text = project_name
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props')
|
||
|
type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration')
|
||
9 years ago
|
ET.SubElement(type_config, 'ConfigurationType').text = "Utility"
|
||
9 years ago
|
ET.SubElement(type_config, 'CharacterSet').text = 'MultiByte'
|
||
|
ET.SubElement(type_config, 'UseOfMfc').text = 'false'
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props')
|
||
|
direlem = ET.SubElement(root, 'PropertyGroup')
|
||
|
fver = ET.SubElement(direlem, '_ProjectFileVersion')
|
||
|
fver.text = self.project_file_version
|
||
|
outdir = ET.SubElement(direlem, 'OutDir')
|
||
|
outdir.text = '.\\'
|
||
|
intdir = ET.SubElement(direlem, 'IntDir')
|
||
|
intdir.text = 'test-temp\\'
|
||
|
tname = ET.SubElement(direlem, 'TargetName')
|
||
|
tname.text = project_name
|
||
|
|
||
|
action = ET.SubElement(root, 'ItemDefinitionGroup')
|
||
|
midl = ET.SubElement(action, 'Midl')
|
||
|
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
|
||
|
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
|
||
|
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
|
||
|
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
|
||
|
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
|
||
|
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
|
||
9 years ago
|
regen_command = [sys.executable,
|
||
|
self.environment.get_build_command(),
|
||
|
'--internal',
|
||
|
'regencheck']
|
||
9 years ago
|
private_dir = self.environment.get_scratch_dir()
|
||
|
cmd_templ = '''setlocal
|
||
9 years ago
|
"%s" "%s"
|
||
9 years ago
|
if %%errorlevel%% neq 0 goto :cmEnd
|
||
|
:cmEnd
|
||
|
endlocal & call :cmErrorLevel %%errorlevel%% & goto :cmDone
|
||
|
:cmErrorLevel
|
||
|
exit /b %%1
|
||
|
:cmDone
|
||
|
if %%errorlevel%% neq 0 goto :VCEnd'''
|
||
9 years ago
|
igroup = ET.SubElement(root, 'ItemGroup')
|
||
|
custombuild = ET.SubElement(igroup, 'CustomBuild', Include='meson-private/regen.rule')
|
||
|
message = ET.SubElement(custombuild, 'Message')
|
||
|
message.text = 'Checking whether solution needs to be regenerated.'
|
||
|
ET.SubElement(custombuild, 'Command').text = cmd_templ % \
|
||
9 years ago
|
('" "'.join(regen_command), private_dir)
|
||
9 years ago
|
ET.SubElement(custombuild, 'Outputs').text = os.path.join(self.environment.get_scratch_dir(), 'regen.stamp')
|
||
|
deps = self.get_regen_filelist()
|
||
|
depstr = ';'.join([os.path.join(self.environment.get_source_dir(), d) for d in deps])
|
||
|
ET.SubElement(custombuild, 'AdditionalInputs').text = depstr
|
||
9 years ago
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets')
|
||
9 years ago
|
ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets')
|
||
9 years ago
|
tree = ET.ElementTree(root)
|
||
|
tree.write(ofname, encoding='utf-8', xml_declaration=True)
|
||
|
|
||
11 years ago
|
def gen_testproj(self, target_name, ofname):
|
||
|
project_name = target_name
|
||
|
root = ET.Element('Project', {'DefaultTargets' : "Build",
|
||
10 years ago
|
'ToolsVersion' : '4.0',
|
||
|
'xmlns' : 'http://schemas.microsoft.com/developer/msbuild/2003'})
|
||
11 years ago
|
confitems = ET.SubElement(root, 'ItemGroup', {'Label' : 'ProjectConfigurations'})
|
||
9 years ago
|
prjconf = ET.SubElement(confitems, 'ProjectConfiguration',
|
||
|
{'Include' : self.buildtype + '|' + self.platform})
|
||
11 years ago
|
p = ET.SubElement(prjconf, 'Configuration')
|
||
9 years ago
|
p.text= self.buildtype
|
||
11 years ago
|
pl = ET.SubElement(prjconf, 'Platform')
|
||
9 years ago
|
pl.text = self.platform
|
||
11 years ago
|
globalgroup = ET.SubElement(root, 'PropertyGroup', Label='Globals')
|
||
|
guidelem = ET.SubElement(globalgroup, 'ProjectGuid')
|
||
|
guidelem.text = self.environment.coredata.test_guid
|
||
|
kw = ET.SubElement(globalgroup, 'Keyword')
|
||
9 years ago
|
kw.text = self.platform + 'Proj'
|
||
11 years ago
|
p = ET.SubElement(globalgroup, 'Platform')
|
||
9 years ago
|
p.text= self.platform
|
||
11 years ago
|
pname= ET.SubElement(globalgroup, 'ProjectName')
|
||
|
pname.text = project_name
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props')
|
||
|
type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration')
|
||
|
ET.SubElement(type_config, 'ConfigurationType')
|
||
|
ET.SubElement(type_config, 'CharacterSet').text = 'MultiByte'
|
||
|
ET.SubElement(type_config, 'UseOfMfc').text = 'false'
|
||
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.props')
|
||
|
direlem = ET.SubElement(root, 'PropertyGroup')
|
||
|
fver = ET.SubElement(direlem, '_ProjectFileVersion')
|
||
|
fver.text = self.project_file_version
|
||
|
outdir = ET.SubElement(direlem, 'OutDir')
|
||
|
outdir.text = '.\\'
|
||
|
intdir = ET.SubElement(direlem, 'IntDir')
|
||
|
intdir.text = 'test-temp\\'
|
||
|
tname = ET.SubElement(direlem, 'TargetName')
|
||
|
tname.text = target_name
|
||
|
|
||
|
action = ET.SubElement(root, 'ItemDefinitionGroup')
|
||
|
midl = ET.SubElement(action, 'Midl')
|
||
|
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
|
||
|
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
|
||
|
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
|
||
|
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
|
||
|
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
|
||
|
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
|
||
|
postbuild = ET.SubElement(action, 'PostBuildEvent')
|
||
|
ET.SubElement(postbuild, 'Message')
|
||
|
test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat')
|
||
9 years ago
|
test_command = [sys.executable,
|
||
|
self.environment.get_build_command(),
|
||
|
'--internal',
|
||
|
'test']
|
||
11 years ago
|
cmd_templ = '''setlocal
|
||
9 years ago
|
"%s" "%s"
|
||
11 years ago
|
if %%errorlevel%% neq 0 goto :cmEnd
|
||
|
:cmEnd
|
||
|
endlocal & call :cmErrorLevel %%errorlevel%% & goto :cmDone
|
||
|
:cmErrorLevel
|
||
|
exit /b %%1
|
||
|
:cmDone
|
||
|
if %%errorlevel%% neq 0 goto :VCEnd'''
|
||
9 years ago
|
ET.SubElement(postbuild, 'Command').text =\
|
||
|
cmd_templ % ('" "'.join(test_command), test_data)
|
||
11 years ago
|
ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets')
|
||
|
tree = ET.ElementTree(root)
|
||
|
tree.write(ofname, encoding='utf-8', xml_declaration=True)
|
||
|
datafile = open(test_data, 'wb')
|
||
9 years ago
|
self.serialise_tests()
|
||
11 years ago
|
datafile.close()
|
||
|
# ElementTree can not do prettyprinting so do it manually
|
||
|
#doc = xml.dom.minidom.parse(ofname)
|
||
|
#open(ofname, 'w').write(doc.toprettyxml())
|