3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
7 # Thomas Nagy, 2006-2016 (ita)
10 C# support. A simple example::
15 bld(features='cs', source='main.cs', gen='foo')
17 Note that the configuration may compile C# snippets::
21 public class Test { public static int Main(string[] args) { return 0; } }
24 conf.check(features='cs', fragment=FRAG, compile_filename='test.cs', gen='test.exe',
25 bintype='exe', csflags=['-pkg:gtk-sharp-2.0'], msg='Checking for Gtksharp support')
28 from waflib
import Utils
, Task
, Options
, Errors
29 from waflib
.TaskGen
import before_method
, after_method
, feature
30 from waflib
.Tools
import ccroot
31 from waflib
.Configure
import conf
33 ccroot
.USELIB_VARS
['cs'] = set(['CSFLAGS', 'ASSEMBLIES', 'RESOURCES'])
34 ccroot
.lib_patterns
['csshlib'] = ['%s']
37 @before_method('process_source')
40 Create a C# task bound to the attribute *cs_task*. There can be only one C# task by task generator.
44 for x
in self
.to_nodes(self
.source
):
45 if x
.name
.endswith('.cs'):
49 self
.source
= no_nodes
51 bintype
= getattr(self
, 'bintype', self
.gen
.endswith('.dll') and 'library' or 'exe')
52 self
.cs_task
= tsk
= self
.create_task('mcs', cs_nodes
, self
.path
.find_or_declare(self
.gen
))
53 tsk
.env
.CSTYPE
= '/target:%s' % bintype
54 tsk
.env
.OUT
= '/out:%s' % tsk
.outputs
[0].abspath()
55 self
.env
.append_value('CSFLAGS', '/platform:%s' % getattr(self
, 'platform', 'anycpu'))
57 inst_to
= getattr(self
, 'install_path', bintype
=='exe' and '${BINDIR}' or '${LIBDIR}')
59 # note: we are making a copy, so the files added to cs_task.outputs won't be installed automatically
60 mod
= getattr(self
, 'chmod', bintype
=='exe' and Utils
.O755
or Utils
.O644
)
61 self
.install_task
= self
.add_install_files(install_to
=inst_to
, install_from
=self
.cs_task
.outputs
[:], chmod
=mod
)
64 @after_method('apply_cs')
67 C# applications honor the **use** keyword::
70 bld(features='cs', source='My.cs', bintype='library', gen='my.dll', name='mylib')
71 bld(features='cs', source='Hi.cs', includes='.', bintype='exe', gen='hi.exe', use='mylib', name='hi')
73 names
= self
.to_list(getattr(self
, 'use', []))
74 get
= self
.bld
.get_tgen_by_name
78 except Errors
.WafError
:
79 self
.env
.append_value('CSFLAGS', '/reference:%s' % x
)
83 tsk
= getattr(y
, 'cs_task', None) or getattr(y
, 'link_task', None)
85 self
.bld
.fatal('cs task has no link task for use %r' % self
)
86 self
.cs_task
.dep_nodes
.extend(tsk
.outputs
) # dependency
87 self
.cs_task
.set_run_after(tsk
) # order (redundant, the order is inferred from the nodes inputs/outputs)
88 self
.env
.append_value('CSFLAGS', '/reference:%s' % tsk
.outputs
[0].abspath())
91 @after_method('apply_cs', 'use_cs')
94 The C# targets may create .mdb or .pdb files::
97 bld(features='cs', source='My.cs', bintype='library', gen='my.dll', csdebug='full')
98 # csdebug is a value in (True, 'full', 'pdbonly')
100 csdebug
= getattr(self
, 'csdebug', self
.env
.CSDEBUG
)
104 node
= self
.cs_task
.outputs
[0]
105 if self
.env
.CS_NAME
== 'mono':
106 out
= node
.parent
.find_or_declare(node
.name
+ '.mdb')
108 out
= node
.change_ext('.pdb')
109 self
.cs_task
.outputs
.append(out
)
111 self
.install_task
.source
.append(out
)
112 except AttributeError:
115 if csdebug
== 'pdbonly':
116 val
= ['/debug+', '/debug:pdbonly']
117 elif csdebug
== 'full':
118 val
= ['/debug+', '/debug:full']
121 self
.env
.append_value('CSFLAGS', val
)
124 class mcs(Task
.Task
):
129 run_str
= '${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}'
131 def exec_command(self
, cmd
, **kw
):
132 if '/noconfig' in cmd
:
133 raise ValueError('/noconfig is not allowed when using response files, check your flags!')
134 return super(self
.__class
__, self
).exec_command(cmd
, **kw
)
138 Find a C# compiler, set the variable MCS for the compiler and CS_NAME (mono or csc)
140 csc
= getattr(Options
.options
, 'cscbinary', None)
143 conf
.find_program(['csc', 'mcs', 'gmcs'], var
='MCS')
144 conf
.env
.ASS_ST
= '/r:%s'
145 conf
.env
.RES_ST
= '/resource:%s'
147 conf
.env
.CS_NAME
= 'csc'
148 if str(conf
.env
.MCS
).lower().find('mcs') > -1:
149 conf
.env
.CS_NAME
= 'mono'
153 Add a command-line option for the configuration::
155 $ waf configure --with-csc-binary=/foo/bar/mcs
157 opt
.add_option('--with-csc-binary', type='string', dest
='cscbinary')
159 class fake_csshlib(Task
.Task
):
161 Task used for reading a foreign .net assembly and adding the dependency on it
166 def runnable_status(self
):
170 def read_csshlib(self
, name
, paths
=[]):
172 Read a foreign .net assembly for the *use* system::
175 bld.read_csshlib('ManagedLibrary.dll', paths=[bld.env.mylibrarypath])
176 bld(features='cs', source='Hi.cs', bintype='exe', gen='hi.exe', use='ManagedLibrary.dll')
178 :param name: Name of the library
180 :param paths: Folders in which the library may be found
181 :type paths: list of string
182 :return: A task generator having the feature *fake_lib* which will call :py:func:`waflib.Tools.ccroot.process_lib`
183 :rtype: :py:class:`waflib.TaskGen.task_gen`
185 return self(name
=name
, features
='fake_lib', lib_paths
=paths
, lib_type
='csshlib')