[Release] NPU Engine v2.2.9 Release
[platform/adaptation/npu/trix-engine.git] / meson.build
1 project('npu-engine', ['c', 'cpp'],
2   version: '2.2.9',
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 get_option('enable_fpga_workaround')
90   add_project_arguments('-DENABLE_FPGA_WORKAROUND', language: ['c', 'cpp'])
91 endif
92
93 if sysroot.startswith('/')
94   sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
95   sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
96   add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
97   sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
98       '/iniparser')
99 else
100   sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
101 endif
102
103
104 libdl_dep = cc.find_library('dl') # DL library
105 libm_dep = cc.find_library('m') # math library
106 thread_dep = dependency('threads') # pthread library
107 iniparser_dep = dependency('iniparser', required: false) # iniparser library
108 if not iniparser_dep.found()
109   libiniparser = cpp.find_library('iniparser')
110   if libiniparser.found() and cpp.has_header('iniparser.h',\
111       args : sysroot_inc_cflags_iniparser)
112     iniparser_dep = declare_dependency(
113       compile_args : sysroot_inc_cflags_iniparser,
114       dependencies: libiniparser,
115     )
116   else
117     error('Failed to resovle dependency on libiniparser')
118   endif
119 endif
120 libdrm_dep = dependency('libdrm')
121
122 if get_option('enable_npu_emul')
123   add_project_arguments('-I/opt/trinity/include', language: ['c', 'cpp'])
124   add_project_arguments('-DENABLE_EMUL', language: ['c', 'cpp'])
125 endif
126 if get_option('enable_data_manip')
127   add_project_arguments('-DENABLE_MANIP', language: ['c', 'cpp'])
128 endif
129 if get_option('enable_buffering')
130   add_project_arguments('-DENABLE_BUFFERING', language: ['c', 'cpp'])
131 endif
132
133 subdir('src')
134 subdir('tests')
135 subdir('utils')
136
137 # Set configuration to install .ini
138 ne_install_conf = configuration_data()
139
140 ne_install_conf.set('VERSION', meson.project_version())
141 ne_install_conf.set('PREFIX', ne_prefix)
142 ne_install_conf.set('EXEC_PREFIX', ne_bindir)
143 ne_install_conf.set('LIB_INSTALL_DIR', ne_libdir)
144 ne_install_conf.set('INCLUDE_INSTALL_DIR', ne_includedir)
145
146 ne_install_conf.set('RESV_MEM_SIZE', get_option('resv_mem_size'))
147 ne_install_conf.set('NUM_THREADS', get_option('num_threads'))
148 ne_install_conf.set('LOG_DIR', get_option('log_dir'))
149 ne_install_conf.set('LOG_VERBOSE', get_option('log_verbose'))
150
151 # Install .ini
152 configure_file(input: 'npu-engine.ini.in', output: 'npu-engine.ini',
153   install_dir: ne_inidir,
154   configuration: ne_install_conf)
155
156 # Install .pc
157 configure_file(input: 'npu-engine.pc.in', output: 'npu-engine.pc',
158   install_dir: join_paths(ne_libdir, 'pkgconfig'),
159   configuration: ne_install_conf)
160
161 # Install headers
162 ne_install_headers = [
163   'include/common/npubinfmt.h',
164   'include/common/typedef.h',
165   'include/host/libnpuhost.h',
166 ]
167
168 install_headers(ne_install_headers, subdir: 'npu-engine')