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
|
import os
import glob
from warnings import warn
cusp_abspath = os.path.abspath("../../cusp/")
# try to import an environment first
try:
Import('env')
except:
exec open("../../build/build-env.py")
env = Environment()
# this function builds a trivial source file from a Cusp header
def trivial_source_from_header(source, target, env):
src_abspath = str(source[0])
src_relpath = os.path.relpath(src_abspath, cusp_abspath)
include = os.path.join('cusp', src_relpath)
target_filename = str(target[0])
fid = open(target_filename, 'w')
fid.write('#include <' + include + '>\n')
fid.close()
# CUFile builds a trivial .cu file from a Cusp header
cu_from_header_builder = Builder(action = trivial_source_from_header,
suffix = '.cu',
src_suffix = '.h')
env.Append(BUILDERS = {'CUFile' : cu_from_header_builder})
# CPPFile builds a trivial .cpp file from a Cusp header
cpp_from_header_builder = Builder(action = trivial_source_from_header,
suffix = '.cpp',
src_suffix = '.h')
env.Append(BUILDERS = {'CPPFile' : cpp_from_header_builder})
# find all user-includable .h files in the cusp tree and generate trivial source files #including them
extensions = ['.h']
folders = ['', # main folder
'gallery/',
'graph/',
'io/',
'krylov/',
'precond/',
'relaxation/']
sources = []
for folder in folders:
for ext in extensions:
pattern = os.path.join(os.path.join(cusp_abspath, folder), "*" + ext)
for fullpath in glob.glob(pattern):
headerfilename = os.path.basename(fullpath)
cu = env.CUFile(headerfilename.replace('.h', '.cu'), fullpath)
cpp = env.CPPFile(headerfilename.replace('.h', '_cpp.cpp'), fullpath)
sources.append(cu)
#sources.append(cpp) # TODO: re-enable this
# insure that all files #include <cusp/detail/config.h>
fid = open(fullpath)
if '#include <cusp/detail/config.h>' not in fid.read():
warn('Header <cusp/' + folder + headerfilename + '> does not include <cusp/detail/config.h>')
# and the file with main()
sources.append('main.cu')
tester = env.Program('tester', sources)
|