[Meson] Revise the build script to check sysroot and kernel header file
authorWook Song <wook16.song@samsung.com>
Thu, 4 Jun 2020 06:39:01 +0000 (15:39 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Thu, 4 Jun 2020 10:42:57 +0000 (19:42 +0900)
This patch revises the build script to check sysroot and the kernel
header file, 'misc/trinity.h'.

Signed-off-by: Wook Song <wook16.song@samsung.com>
meson.build
meson_options.txt

index 9154404..e75b464 100644 (file)
@@ -1,7 +1,7 @@
 project('npu-engine', ['c', 'cpp'],
   version: '2.0.1',
   license: ['Proprietary'],
-  meson_version: '>=0.50.0',
+  meson_version: '>=0.47.0',
   default_options: [
     'werror=true',
     'warning_level=1',
@@ -12,6 +12,9 @@ project('npu-engine', ['c', 'cpp'],
 
 cc = meson.get_compiler('c')
 cpp = meson.get_compiler('cpp')
+sysroot = run_command(
+    cpp.cmd_array() + ['-print-sysroot']
+    ).stdout().split('\n')[0]
 
 warning_c_flags = [
   '-Wmissing-prototypes',
@@ -69,6 +72,29 @@ ne_datadir = join_paths(ne_prefix, join_paths(get_option('datadir'), 'npu-engine
 ne_common_inc = include_directories('include/common')
 ne_host_inc = include_directories('include/host')
 
+if not get_option('enable_npu_emul')
+  ne_kernel_hdr = get_option('kernel_hdr_dir')
+  ne_hernel_hdr_cflags = '-I' + ne_kernel_hdr
+  if cpp.has_header('misc/trinity.h', args: ne_hernel_hdr_cflags)
+    add_project_arguments(ne_hernel_hdr_cflags, language: ['c', 'cpp'])
+  else
+    if not cpp.has_header('misc/trinity.h')
+      error('Failed to find \'misc/trintiy.h\'. Try to use the -Dkernel_hdr_dir option.')
+    endif
+  endif
+endif
+
+if sysroot.startswith('/')
+  sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
+  sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
+  add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
+  sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
+      '/iniparser')
+else
+  sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
+endif
+
+
 libdl_dep = cc.find_library('dl') # DL library
 libm_dep = cc.find_library('m') # math library
 thread_dep = dependency('threads') # pthread library
@@ -76,9 +102,9 @@ iniparser_dep = dependency('iniparser', required: false) # iniparser library
 if not iniparser_dep.found()
   libiniparser = cpp.find_library('iniparser')
   if libiniparser.found() and cpp.has_header('iniparser.h',\
-      args : '-I/usr/include/iniparser')
+      args : sysroot_inc_cflags_iniparser)
     iniparser_dep = declare_dependency(
-      compile_args : '-I/usr/include/iniparser',
+      compile_args : sysroot_inc_cflags_iniparser,
       dependencies: libiniparser,
     )
   else
index 290ec3c..77cdeaa 100644 (file)
@@ -5,3 +5,4 @@ option('log_dir', type : 'string', value : '/tmp/')
 option('enable_npu_emul', type : 'boolean', value : false)
 option('enable_data_manip', type : 'boolean', value : false)
 option('enable_buffering', type : 'boolean', value : false)
+option('kernel_hdr_dir', type : 'string', value : '')