aboutsummaryrefslogtreecommitdiff
path: root/meson.build
blob: 313483761297d2f713b1fba3e616f1649ed857b9 (plain)
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
project('libmg2d', 'c',
         default_options : ['c_std=c11'])

add_project_arguments('-D_XOPEN_SOURCE=700', language : 'c')

lib_src = [
    'bicgstab.c',
    'boundary.c',
    'components.c',
    'cpu.c',
    'ell_grid_solve.c',
    'log.c',
    'mg2d.c',
    'residual_calc.c',
    'timer.c',
    'transfer.c',
]
lib_obj = []

verscript = 'libmg2d.v'
ver_flag  = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), verscript)

cc = meson.get_compiler('c')
libm = cc.find_library('m', required : false)
libcblas   = cc.find_library('blas')
liblapacke = cc.find_library('lapacke')
libndarray = cc.find_library('ndarray')

dep_tp  = declare_dependency(link_args : '-lthreadpool')

dep_mpi = dependency('mpi', language: 'c')

deps = [dep_tp, libm, libcblas, liblapacke, libndarray, dep_mpi]

cdata = configuration_data()
cdata.set10('ARCH_X86',          false)
cdata.set10('ARCH_X86_64',       false)
cdata.set10('HAVE_EXTERNAL_ASM', false)

arch = host_machine.cpu_family()
if arch.startswith('x86')
    cdata.set10('ARCH_X86', true)

    if arch == 'x86_64'
        cdata.set10('ARCH_X86_64', true)
        nasm = find_program('nasm', required : get_option('nasm'))
        if nasm.found()
            cdata.set10('HAVE_EXTERNAL_ASM', true)
        else
            warning('nasm not found, no SIMD will be built')
        endif
    endif
endif

configure_file(output : 'config.h', output_format : 'c', configuration : cdata)

if nasm.found()
    cdata_asm = configuration_data()
    cdata_asm.set10('ARCH_X86', true)
    cdata_asm.set10('ARCH_X86_64', true)
    cdata_asm.set10('ARCH_X86_32', false)
    configure_file(output : 'config.asm', output_format : 'nasm', configuration : cdata_asm)

    if host_machine.system() == 'windows'
        nasm_format = 'win'
    elif host_machine.system() == 'darwin'
        nasm_format = 'macho'
    else
        nasm_format = 'elf'
    endif
    nasm_format += '64'

    nasm_gen = generator(nasm,
        output: '@BASENAME@.obj',
        depfile: '@BASENAME@.obj.ndep',
        arguments: [
            '-f', nasm_format,
            '-I', '@SOURCE_DIR@/',
            '-I', '@0@/'.format(meson.current_build_dir()),
            '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@',
            '@EXTRA_ARGS@',
            '@INPUT@',
            '-o', '@OUTPUT@'
        ]
    )

    nasm_sources = files(
        'cpuid.asm',
        'ndarray.asm',
        'residual_calc.asm',
        'transfer_interp.asm',
    )

    lib_obj += nasm_gen.process(nasm_sources)
endif

library('mg2d', lib_src, lib_obj, link_args : ver_flag, dependencies : deps, link_depends : verscript)

# test programs
test_progs = ['relax', 'relax_mpi', 'mg2d', 'mg2d_mpi']
foreach t : test_progs
    target = t + '_test'
    executable(target, [target + '.c'] + lib_src, lib_obj, dependencies : deps + [libm])
endforeach