Skip to content

Commit

Permalink
[Windows] Simplify iniparser import
Browse files Browse the repository at this point in the history
Use most standrard meson way to import cmake iniparser library
This way of importing wil work regardless of operating system

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Grzegorz Kisala <[email protected]>
  • Loading branch information
gkisalapl committed Jan 17, 2025
1 parent c603787 commit bf77046
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
46 changes: 11 additions & 35 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('nntrainer', 'c', 'cpp',
version: '0.5.0',
license: ['apache-2.0'],
meson_version: '>=0.50.0',
meson_version: '>=0.55.0',
default_options: [
'werror=true',
'warning_level=1',
Expand All @@ -11,6 +11,16 @@ project('nntrainer', 'c', 'cpp',
]
)

# CMake module
cmake = import('cmake')

# iniparser
iniparser_options = cmake.subproject_options()
iniparser_options.add_cmake_defines({'BUILD_DOCS': false})
iniparser_options.add_cmake_defines({'BUILD_SHARED_LIBS': false})
iniparser_subproject = cmake.subproject('iniparser', options: iniparser_options, required: true)
iniparser_dep = iniparser_subproject.dependency('iniparser-static')

# Set version info
nntrainer_version = meson.project_version()
nntrainer_version_split = nntrainer_version.split('.')
Expand Down Expand Up @@ -346,40 +356,6 @@ libm_dep = cxx.find_library('m') # cmath library
libdl_dep = cxx.find_library('dl') # DL library
thread_dep = dependency('threads') # pthread for tensorflow-lite

iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
if get_option('platform') == 'android'
message('preparing iniparser')
run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
iniparser_root = meson.build_root() / 'iniparser'
iniparser_dep = declare_dependency(include_directories: [ 'iniparser/src' ])
endif

if not iniparser_dep.found()
message('falling back to find libiniparser library and header files')
libiniparser_dep = cxx.find_library('iniparser')
sysroot = run_command(
cxx.cmd_array() + ['-print-sysroot']
).stdout().split('\n')[0]

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

if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
args : sysroot_inc_cflags_iniparser)
iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
compile_args : sysroot_inc_cflags_iniparser)
else
error('Failed to resolve dependency on iniparser')
endif
endif

if get_option('platform') == 'android'
message('preparing ml api')
run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
Expand Down
4 changes: 4 additions & 0 deletions subprojects/iniparser.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
url = https://github.com/ndevilla/iniparser.git
directory=iniparser
revision = v4.2.4

0 comments on commit bf77046

Please sign in to comment.