[UnitTest] Add new unittest for libnpuhost
[platform/adaptation/npu/trix-engine.git] / meson.build
1 project('npu-engine', ['c', 'cpp'],
2   version: '2.0.5',
3   license: ['Proprietary'],
4   meson_version: '>=0.47.0',
5   default_options: [
6     'werror=true',
7     'warning_level=1',
8     'c_std=gnu89',
9     'cpp_std=gnu++11',
10   ]
11 )
12
13 cc = meson.get_compiler('c')
14 cpp = meson.get_compiler('cpp')
15 sysroot = run_command(
16     cpp.cmd_array() + ['-print-sysroot']
17     ).stdout().split('\n')[0]
18
19 warning_c_flags = [
20   '-Wmissing-prototypes',
21   '-Wmissing-declarations',
22   '-Wnested-externs',
23   '-Waggregate-return',
24   '-Wold-style-definition',
25   '-Wdeclaration-after-statement'
26 ]
27
28 warning_flags = [
29   '-Wredundant-decls',
30   '-Wwrite-strings',
31   '-Wformat',
32   '-Wformat-nonliteral',
33   '-Wformat-security',
34   '-Winit-self',
35   '-Waddress',
36   '-Wno-multichar',
37   '-Wvla',
38   '-Wpointer-arith',
39   '-Wno-sign-compare',
40 ]
41
42 foreach extra_arg : warning_c_flags
43   if cc.has_argument (extra_arg)
44     add_project_arguments([extra_arg], language : 'c')
45   endif
46 endforeach
47
48 foreach extra_arg : warning_flags
49   if cc.has_argument (extra_arg)
50     add_project_arguments([extra_arg], language : 'c')
51   endif
52   if cpp.has_argument (extra_arg)
53     add_project_arguments([extra_arg], language : 'cpp')
54   endif
55 endforeach
56
57 # Add version arguments
58 version = meson.project_version().split('.')
59 add_project_arguments('-DVER_NE_MAJOR=' + version[0], language: ['c', 'cpp'])
60 add_project_arguments('-DVER_NE_MINOR=' + version[1], language: ['c', 'cpp'])
61 add_project_arguments('-DVER_NE_EXTRA=' + version[2], language: ['c', 'cpp'])
62
63 # Install Paths
64 ne_prefix = get_option('prefix')
65 ne_libdir = join_paths(ne_prefix, get_option('libdir'))
66 ne_bindir = join_paths(ne_prefix, get_option('bindir'))
67 ne_includedir = join_paths(ne_prefix, get_option('includedir'))
68 ne_inidir = get_option('sysconfdir')
69 ne_datadir = join_paths(ne_prefix, join_paths(get_option('datadir'), 'npu-engine'))
70
71 add_project_arguments('-DNE_INIDIR="' + ne_inidir + '"', language: ['c', 'cpp'])
72 add_project_arguments('-DNE_DATADIR="' + ne_datadir + '"', language: ['c', 'cpp'])
73
74 ne_common_inc = include_directories('include/common')
75 ne_host_inc = include_directories('include/host')
76
77 if not get_option('enable_npu_emul')
78   ne_kernel_hdr = get_option('kernel_hdr_dir')
79   ne_hernel_hdr_cflags = '-I' + ne_kernel_hdr
80   if cpp.has_header('misc/trinity.h', args: ne_hernel_hdr_cflags)
81     add_project_arguments(ne_hernel_hdr_cflags, language: ['c', 'cpp'])
82   else
83     if not cpp.has_header('misc/trinity.h')
84       error('Failed to find \'misc/trintiy.h\'. Try to use the -Dkernel_hdr_dir option.')
85     endif
86   endif
87 endif
88
89 if sysroot.startswith('/')
90   sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
91   sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
92   add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
93   sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
94       '/iniparser')
95 else
96   sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
97 endif
98
99
100 libdl_dep = cc.find_library('dl') # DL library
101 libm_dep = cc.find_library('m') # math library
102 thread_dep = dependency('threads') # pthread library
103 iniparser_dep = dependency('iniparser', required: false) # iniparser library
104 if not iniparser_dep.found()
105   libiniparser = cpp.find_library('iniparser')
106   if libiniparser.found() and cpp.has_header('iniparser.h',\
107       args : sysroot_inc_cflags_iniparser)
108     iniparser_dep = declare_dependency(
109       compile_args : sysroot_inc_cflags_iniparser,
110       dependencies: libiniparser,
111     )
112   else
113     error('Failed to resovle dependency on libiniparser')
114   endif
115 endif
116 libdrm_dep = dependency('libdrm')
117
118 if get_option('enable_npu_emul')
119   add_project_arguments('-I/opt/trinity/include', language: ['c', 'cpp'])
120   add_project_arguments('-DENABLE_EMUL', language: ['c', 'cpp'])
121 endif
122 if get_option('enable_data_manip')
123   add_project_arguments('-DENABLE_MANIP', language: ['c', 'cpp'])
124 endif
125 if get_option('enable_buffering')
126   add_project_arguments('-DENABLE_BUFFERING', language: ['c', 'cpp'])
127 endif
128
129 subdir('src')
130 subdir('tests')
131
132 # Set configuration to install .ini
133 ne_install_conf = configuration_data()
134
135 ne_install_conf.set('VERSION', meson.project_version())
136 ne_install_conf.set('PREFIX', ne_prefix)
137 ne_install_conf.set('EXEC_PREFIX', ne_bindir)
138 ne_install_conf.set('LIB_INSTALL_DIR', ne_libdir)
139 ne_install_conf.set('INCLUDE_INSTALL_DIR', ne_includedir)
140
141 ne_install_conf.set('RESV_MEM_SIZE', get_option('resv_mem_size'))
142 ne_install_conf.set('NUM_THREADS', get_option('num_threads'))
143 ne_install_conf.set('LOG_DIR', get_option('log_dir'))
144 ne_install_conf.set('LOG_VERBOSE', get_option('log_verbose'))
145
146 # Install .ini
147 configure_file(input: 'npu-engine.ini.in', output: 'npu-engine.ini',
148   install_dir: ne_inidir,
149   configuration: ne_install_conf)
150
151 # Install .pc
152 configure_file(input: 'npu-engine.pc.in', output: 'npu-engine.pc',
153   install_dir: join_paths(ne_libdir, 'pkgconfig'),
154   configuration: ne_install_conf)
155
156 # Install headers
157 ne_install_headers = [
158   'include/common/npubinfmt.h',
159   'include/common/typedef.h',
160   'include/host/libnpuhost.h',
161 ]
162
163 install_headers(ne_install_headers, subdir: 'npu-engine')