Debian Codegraph @

m4/ax_clang.m4

raw
1 # -*- mode: m4 -*-
2 #
3 # Copyright (c) 2017 The University of Utah
4 #
5 # Copying and distribution of this file, with or without modification, are
6 # permitted in any medium without royalty provided the copyright notice
7 # and this notice are preserved. This file is offered as-is, without any
8 # warranty.
9
10 ###############################################################################
11
12 # SYNOPSIS
13 #
14 # AX_CLANG()
15 #
16 # DESCRIPTION
17 #
18 # Test for a Clang build or installation tree, and set the output variables
19 # `CLANG_CPPFLAGS' and `CLANG_LDFLAGS' as needed for compiling and linking
20 # programs against that tree.
21 #
22 # Clang is usually built and/or installed alongside LLVM. When that is the
23 # case, the information we get from macro AX_LLVM is enough for compiling and
24 # linking programs against Clang. This AX_CLANG macro is needed only when
25 # the LLVM and Clang trees are separate, for whatever reason.
26 #
27 # `CLANG_CPPFLAGS' is set to the command-line "-I" directives that are
28 # needed to compile programs against the specified Clang tree. This macro
29 # digs the include directories out of the file "ClangConfig.cmake".
30 #
31 # `CLANG_LDFLAGS' is set to the command-line "-L" directive that is needed.
32 # This is easy to determine: the libraries are in the tree's "lib" directory.
33
34 AC_DEFUN([AX_CLANG],
35 [
36 AC_ARG_WITH([clang],
37 AS_HELP_STRING([--with-clang@<:@=DIR@:>@],
38 [use separate Clang tree located in DIR
39 [advanced option;
40 default is to find Clang libraries and headers in LLVM tree]]),
41 [with_clang="$withval"],
42 [with_clang=no])
43
44 CLANG_CPPFLAGS=''
45 CLANG_LDFLAGS=''
46
47 if test "x$with_clang" = "xno"; then
48 true # Do nothing.
49 elif test "x$with_clang" = "xyes"; then
50 AC_MSG_ERROR(
51 [--with-clang requires an argument (a Clang build/install tree)])
52 else
53
54 clang_dir="$with_clang"
55 clang_cmake_file="$clang_dir/lib/cmake/clang/ClangConfig.cmake"
56 AC_CHECK_FILE([$clang_cmake_file],
57 [],
58 [
59 AC_MSG_ERROR(
60 [argument to --with-clang is not a Clang build/install tree])
61 ])
62
63 # Dig the list of include directories out of the $clang_cmake_file, which
64 # is a CMake file. The sed expressions below:
65 #
66 # + Find the line: set(CLANG_INCLUDE_DIRS "<dirlist>")
67 # and output: <dirlist>
68 # + From the list: <dir1>;<dir2>;...
69 # output: -I<dir1>;-I<dir2>;...
70 # + Erase semis: -I<dir1> -I<dir2> ...
71 #
72 changequote(<<, >>)dnl
73 CLANG_CPPFLAGS=`dnl
74 sed -n -E dnl
75 -e 's/^set\(CLANG_INCLUDE_DIRS [^"]*"([^"]+)"\)$/\1/p' dnl
76 "$clang_cmake_file" | dnl
77 sed -E dnl
78 -e 's/([^;]+)/-I\1/g' dnl
79 -e 's/;/ /g'`
80 changequote([, ])dnl
81 #
82 # Find the list of library directories. This is easy: everything is in
83 # the "lib" subdirectory.
84 #
85 CLANG_LDFLAGS="-L$clang_dir/lib"
86 fi
87 AC_SUBST(CLANG_CPPFLAGS)
88 AC_SUBST(CLANG_LDFLAGS)
89 ])