waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

cuda.py (1677B)


      1 #!/usr/bin/env python
      2 # encoding: utf-8
      3 # Thomas Nagy, 2010
      4 
      5 "cuda"
      6 
      7 from waflib import Task
      8 from waflib.TaskGen import extension
      9 from waflib.Tools import ccroot, c_preproc
     10 from waflib.Configure import conf
     11 
     12 class cuda(Task.Task):
     13 	run_str = '${NVCC} ${CUDAFLAGS} ${NVCCFLAGS_ST:CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F} ${TGT}'
     14 	color   = 'GREEN'
     15 	ext_in  = ['.h']
     16 	vars    = ['CCDEPS']
     17 	scan    = c_preproc.scan
     18 	shell   = False
     19 
     20 @extension('.cu', '.cuda')
     21 def c_hook(self, node):
     22 	return self.create_compiled_task('cuda', node)
     23 
     24 @extension('.cpp')
     25 def cxx_hook(self, node):
     26 	# override processing for one particular type of file
     27 	if getattr(self, 'cuda', False):
     28 		return self.create_compiled_task('cuda', node)
     29 	else:
     30 		return self.create_compiled_task('cxx', node)
     31 
     32 def configure(conf):
     33 	conf.find_program('nvcc', var='NVCC')
     34 	conf.find_cuda_libs()
     35 	conf.env.NVCCFLAGS_ST = "--compiler-options=%s"
     36 
     37 @conf
     38 def find_cuda_libs(self):
     39 	"""
     40 	find the cuda include and library folders
     41 
     42 	use ctx.program(source='main.c', target='app', use='CUDA CUDART')
     43 	"""
     44 
     45 	if not self.env.NVCC:
     46 		self.fatal('check for nvcc first')
     47 
     48 	d = self.root.find_node(self.env.NVCC[0]).parent.parent
     49 
     50 	node = d.find_node('include')
     51 	_includes = node and node.abspath() or ''
     52 
     53 	_libpath = []
     54 	for x in ('lib64', 'lib64/stubs', 'lib', 'lib/stubs'):
     55 		try:
     56 			_libpath.append(d.find_node(x).abspath())
     57 		except:
     58 			pass
     59 
     60 	# this should not raise any error
     61 	self.check_cxx(header='cuda.h', lib='cuda', libpath=_libpath, includes=_includes)
     62 	self.check_cxx(header='cuda.h', lib='cudart', libpath=_libpath, includes=_includes)
     63