From 39203334d41cccc2627c731ae213ac904dfb9b6e Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Sun, 22 Oct 2017 20:54:36 +0200 Subject: [PATCH] meson: add a option where to find the clang library and header with having them people can just specify where the clang stuff is installed, if its not possible to find it in the default location. This fixes a bug where clang was not found, dirs: is meant as exclusive parameter, so if you specify there a custom directory, then only THIS specific directory will be used for the search. This fixes also that bug and only specifies that argument if a custom location is given. --- meson.build | 30 +++++++++++++++++++++++++----- meson_options.txt | 2 ++ scripts/clang_build_include_dir.sh | 6 ------ src/bin/meson.build | 9 ++------- src/tests/meson.build | 3 ++- 5 files changed, 31 insertions(+), 19 deletions(-) delete mode 100755 scripts/clang_build_include_dir.sh diff --git a/meson.build b/meson.build index 8abb7be..5e3da9e 100644 --- a/meson.build +++ b/meson.build @@ -40,17 +40,37 @@ else config_h.set_quoted('BEAR_COMMAND', '') endif -if get_option('libclang') == true and cc.has_header('clang-c/Index.h') - has_clang_header = true - clang = cc.find_library('clang', dirs : ['/usr/local/opt/llvm/lib']) +opt_clang_header_dir = get_option('libclang-libdir') +opt_clang_link_dir = get_option('libclang-headerdir') + +if get_option('libclang') == true + + #check for the header + found = false + if opt_clang_header_dir != '' + found = cc.has_header('clang-c/Index.h', args : '-I'+opt_clang_header_dir) + else + found = cc.has_header('clang-c/Index.h') + endif + + if found == false + error('Clang header not found!') + endif + + clang_inc = include_directories(opt_clang_header_dir) + + #check for the library to link + if opt_clang_link_dir != '' + clang = cc.find_library('clang', dirs : [opt_clang_link_dir]) + else + clang = cc.find_library('clang') + endif clang_include_dir_command = run_command(find_program('scripts/clang_include_dir.sh')) clang_include_dir = clang_include_dir_command.stdout().strip() config_h.set_quoted('CLANG_INCLUDES', clang_include_dir) config_h.set('HAVE_LIBCLANG', '1') -else - has_clang_header = false endif subdir('po') diff --git a/meson_options.txt b/meson_options.txt index 10ae169..61f4286 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,4 @@ option('libclang', type : 'boolean', value : true, description : 'Weather to have libclang support') option('bear', type : 'boolean', value : true, description : 'Weather to have bear support') +option('libclang-libdir', type : 'string', value : '', description : 'Specify a none default location for your clang installation') +option('libclang-headerdir', type : 'string', value : '', description : 'Specify a none default location for your clang installation') diff --git a/scripts/clang_build_include_dir.sh b/scripts/clang_build_include_dir.sh deleted file mode 100755 index a5b320e..0000000 --- a/scripts/clang_build_include_dir.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -if [[ -d /usr/local/opt/llvm ]]; then - echo "/usr/local/opt/llvm/include" -fi - diff --git a/src/bin/meson.build b/src/bin/meson.build index ee0ad99..809c4c2 100644 --- a/src/bin/meson.build +++ b/src/bin/meson.build @@ -28,14 +28,9 @@ endforeach deps = [elm, edi_lib, intl] incls = [] -if get_option('libclang') == true and has_clang_header == true +if get_option('libclang') == true deps += [clang] - - clang_build_include_dir_command = run_command(find_program('../../scripts/clang_build_include_dir.sh')) - clang_build_include_dir = clang_build_include_dir_command.stdout().strip() - if clang_build_include_dir != '' - incls += include_directories(clang_build_include_dir) - endif + incls += [clang_inc] endif executable('edi', src, diff --git a/src/tests/meson.build b/src/tests/meson.build index 0c08504..8959bf7 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -13,8 +13,9 @@ check = dependency('check') deps = [elm, check, edi_lib] -if get_option('libclang') == true and has_clang_header == true +if get_option('libclang') == true deps += [clang] + incls += [clang_inc] endif exe = executable('edi_suite', src,