clang-plugin.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. dnl This Source Code Form is subject to the terms of the Mozilla Public
  2. dnl License, v. 2.0. If a copy of the MPL was not distributed with this
  3. dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. AC_DEFUN([MOZ_CONFIG_CLANG_PLUGIN], [
  5. MOZ_ARG_ENABLE_BOOL(clang-plugin,
  6. [ --enable-clang-plugin Enable building with the mozilla clang plugin ],
  7. ENABLE_CLANG_PLUGIN=1,
  8. ENABLE_CLANG_PLUGIN= )
  9. if test -n "$ENABLE_CLANG_PLUGIN"; then
  10. if test -z "${CLANG_CC}${CLANG_CL}"; then
  11. AC_MSG_ERROR([Can't use clang plugin without clang.])
  12. fi
  13. AC_MSG_CHECKING([for llvm-config])
  14. if test -z "$LLVMCONFIG"; then
  15. if test -n "$CLANG_CL"; then
  16. CXX_COMPILER="$(dirname "$CXX")/clang"
  17. else
  18. CXX_COMPILER="${CXX}"
  19. fi
  20. LLVMCONFIG=`$CXX_COMPILER -print-prog-name=llvm-config`
  21. fi
  22. if test -z "$LLVMCONFIG"; then
  23. LLVMCONFIG=`which llvm-config`
  24. fi
  25. if test ! -x "$LLVMCONFIG"; then
  26. AC_MSG_RESULT([not found])
  27. AC_MSG_ERROR([Cannot find an llvm-config binary for building a clang plugin])
  28. fi
  29. AC_MSG_RESULT([$LLVMCONFIG])
  30. if test -z "$LLVMCONFIG"; then
  31. AC_MSG_ERROR([Cannot find an llvm-config binary for building a clang plugin])
  32. fi
  33. dnl For some reason the llvm-config downloaded from clang.llvm.org for clang3_8
  34. dnl produces a -isysroot flag for a sysroot which might not ship when passed
  35. dnl --cxxflags. We use sed to remove this argument so that builds work on OSX
  36. LLVM_CXXFLAGS=`$LLVMCONFIG --cxxflags | sed -e 's/-isysroot [[^ ]]*//'`
  37. dnl We are loaded into clang, so we don't need to link to very many things,
  38. dnl we just need to link to clangASTMatchers because it is not used by clang
  39. LLVM_LDFLAGS=`$LLVMCONFIG --ldflags | tr '\n' ' '`
  40. if test "${HOST_OS_ARCH}" = "Darwin"; then
  41. dnl We need to make sure that we use the symbols coming from the clang
  42. dnl binary. In order to do this, we need to pass -flat_namespace and
  43. dnl -undefined suppress to the linker. This makes sure that we link the
  44. dnl symbols into the flat namespace provided by clang, and thus get
  45. dnl access to all of the symbols which are undefined in our dylib as we
  46. dnl are building it right now, and also that we don't fail the build
  47. dnl due to undefined symbols (which will be provided by clang).
  48. CLANG_LDFLAGS="-Wl,-flat_namespace -Wl,-undefined,suppress -lclangASTMatchers"
  49. elif test "${HOST_OS_ARCH}" = "WINNT"; then
  50. CLANG_LDFLAGS="clangASTMatchers.lib"
  51. else
  52. CLANG_LDFLAGS="-lclangASTMatchers"
  53. fi
  54. if test -n "$CLANG_CL"; then
  55. dnl The llvm-config coming with clang-cl may give us arguments in the
  56. dnl /ARG form, which in msys will be interpreted as a path name. So we
  57. dnl need to split the args and convert the leading slashes that we find
  58. dnl into a dash.
  59. LLVM_REPLACE_CXXFLAGS=''
  60. for arg in $LLVM_CXXFLAGS; do
  61. dnl The following expression replaces a leading slash with a dash.
  62. dnl Also replace any backslashes with forward slash.
  63. arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
  64. LLVM_REPLACE_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS $arg"
  65. done
  66. LLVM_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS"
  67. LLVM_REPLACE_LDFLAGS=''
  68. for arg in $LLVM_LDFLAGS; do
  69. dnl The following expression replaces a leading slash with a dash.
  70. dnl Also replace any backslashes with forward slash.
  71. arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
  72. LLVM_REPLACE_LDFLAGS="$LLVM_REPLACE_LDFLAGS $arg"
  73. done
  74. LLVM_LDFLAGS="$LLVM_REPLACE_LDFLAGS"
  75. CLANG_REPLACE_LDFLAGS=''
  76. for arg in $CLANG_LDFLAGS; do
  77. dnl The following expression replaces a leading slash with a dash.
  78. dnl Also replace any backslashes with forward slash.
  79. arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
  80. CLANG_REPLACE_LDFLAGS="$CLANG_REPLACE_LDFLAGS $arg"
  81. done
  82. CLANG_LDFLAGS="$CLANG_REPLACE_LDFLAGS"
  83. fi
  84. dnl Check for the new ASTMatcher API names. Since this happened in the
  85. dnl middle of the 3.8 cycle, our CLANG_VERSION_FULL is impossible to use
  86. dnl correctly, so we have to detect this at configure time.
  87. AC_CACHE_CHECK(for new ASTMatcher API,
  88. ac_cv_have_new_ASTMatcher_api,
  89. [
  90. AC_LANG_SAVE
  91. AC_LANG_CPLUSPLUS
  92. _SAVE_CXXFLAGS="$CXXFLAGS"
  93. _SAVE_CXX="$CXX"
  94. _SAVE_MACOSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET"
  95. unset MACOSX_DEPLOYMENT_TARGET
  96. CXXFLAGS="${LLVM_CXXFLAGS}"
  97. CXX="${HOST_CXX}"
  98. AC_TRY_COMPILE([#include "clang/ASTMatchers/ASTMatchers.h"],
  99. [clang::ast_matchers::cxxConstructExpr();],
  100. ac_cv_have_new_ASTMatcher_names="yes",
  101. ac_cv_have_new_ASTMatcher_names="no")
  102. CXX="$_SAVE_CXX"
  103. CXXFLAGS="$_SAVE_CXXFLAGS"
  104. export MACOSX_DEPLOYMENT_TARGET="$_SAVE_MACOSX_DEPLOYMENT_TARGET"
  105. AC_LANG_RESTORE
  106. ])
  107. if test "$ac_cv_have_new_ASTMatcher_names" = "yes"; then
  108. LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DHAVE_NEW_ASTMATCHER_NAMES"
  109. fi
  110. dnl Check if we can compile has(ignoringParenImpCasts()) because
  111. dnl before 3.9 that ignoringParenImpCasts was done internally by "has".
  112. dnl See https://www.mail-archive.com/cfe-commits@lists.llvm.org/msg25234.html
  113. AC_CACHE_CHECK(for has with ignoringParenImpCasts,
  114. ac_cv_has_accepts_ignoringParenImpCasts,
  115. [
  116. AC_LANG_SAVE
  117. AC_LANG_CPLUSPLUS
  118. _SAVE_CXXFLAGS="$CXXFLAGS"
  119. _SAVE_CXX="$CXX"
  120. _SAVE_MACOSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET"
  121. unset MACOSX_DEPLOYMENT_TARGET
  122. CXXFLAGS="${LLVM_CXXFLAGS}"
  123. CXX="${HOST_CXX}"
  124. AC_TRY_COMPILE([#include "clang/ASTMatchers/ASTMatchers.h"],
  125. [using namespace clang::ast_matchers;
  126. expr(has(ignoringParenImpCasts(declRefExpr())));
  127. ],
  128. ac_cv_has_accepts_ignoringParenImpCasts="yes",
  129. ac_cv_has_accepts_ignoringParenImpCasts="no")
  130. CXX="$_SAVE_CXX"
  131. CXXFLAGS="$_SAVE_CXXFLAGS"
  132. export MACOSX_DEPLOYMENT_TARGET="$_SAVE_MACOSX_DEPLOYMENT_TARGET"
  133. AC_LANG_RESTORE
  134. ])
  135. if test "$ac_cv_has_accepts_ignoringParenImpCasts" = "yes"; then
  136. LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DHAS_ACCEPTS_IGNORINGPARENIMPCASTS"
  137. fi
  138. AC_DEFINE(MOZ_CLANG_PLUGIN)
  139. fi
  140. AC_SUBST(LLVM_CXXFLAGS)
  141. AC_SUBST(LLVM_LDFLAGS)
  142. AC_SUBST(CLANG_LDFLAGS)
  143. AC_SUBST(ENABLE_CLANG_PLUGIN)
  144. ])