configure.ac 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. ## Process this file with autoconf to produce configure.
  2. ## In general, the safest way to proceed is to run ./autogen.sh
  3. AC_PREREQ(2.59)
  4. # Note: If you change the version, you must also update it in:
  5. # * Protobuf.podspec
  6. # * csharp/Google.Protobuf.Tools.nuspec
  7. # * csharp/src/*/AssemblyInfo.cs
  8. # * csharp/src/Google.Protobuf/Google.Protobuf.nuspec
  9. # * java/*/pom.xml
  10. # * python/google/protobuf/__init__.py
  11. # * protoc-artifacts/pom.xml
  12. # * src/google/protobuf/stubs/common.h
  13. # * src/Makefile.am (Update -version-info for LDFLAGS if needed)
  14. #
  15. # In the SVN trunk, the version should always be the next anticipated release
  16. # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
  17. # the size of one file name in the dist tarfile over the 99-char limit.)
  18. AC_INIT([Protocol Buffers],[3.20.0-rc-2],[protobuf@googlegroups.com],[protobuf])
  19. AM_MAINTAINER_MODE([enable])
  20. AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
  21. # The config file is generated but not used by the source code, since we only
  22. # need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are
  23. # passed down in CXXFLAGS manually in src/Makefile.am
  24. AC_CONFIG_HEADERS([config.h])
  25. AC_CONFIG_MACRO_DIR([m4])
  26. AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)])
  27. case "$DIST_LANG" in
  28. "") DIST_LANG=all ;;
  29. all | cpp | csharp | java | python | javanano | objectivec | ruby | js | php) ;;
  30. *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;;
  31. esac
  32. AC_SUBST(DIST_LANG)
  33. # autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
  34. # the best choice for libprotobuf.
  35. AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
  36. [CFLAGS=""])
  37. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
  38. [CXXFLAGS=""])
  39. AC_CANONICAL_TARGET
  40. AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects])
  41. # Silent rules enabled: the output is minimal but informative.
  42. # In particular, the warnings from the compiler stick out very clearly.
  43. # To see all logs, use the --disable-silent-rules on configure or via make V=1
  44. AM_SILENT_RULES([yes])
  45. AC_ARG_WITH([zlib],
  46. [AS_HELP_STRING([--with-zlib],
  47. [include classes for streaming compressed data in and out @<:@default=check@:>@])],
  48. [],[with_zlib=check])
  49. AC_ARG_WITH([zlib-include],
  50. [AS_HELP_STRING([--with-zlib-include=PATH],
  51. [zlib include directory])],
  52. [CPPFLAGS="-I$withval $CPPFLAGS"])
  53. AC_ARG_WITH([zlib-lib],
  54. [AS_HELP_STRING([--with-zlib-lib=PATH],
  55. [zlib lib directory])],
  56. [LDFLAGS="-L$withval $LDFLAGS"])
  57. AC_ARG_WITH([protoc],
  58. [AS_HELP_STRING([--with-protoc=COMMAND],
  59. [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
  60. [],[with_protoc=no])
  61. # Checks for programs.
  62. AC_PROG_CC
  63. AC_PROG_CXX
  64. AC_PROG_CXX_FOR_BUILD
  65. AC_LANG([C++])
  66. ACX_USE_SYSTEM_EXTENSIONS
  67. m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
  68. AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
  69. AS_CASE([$target_os], [darwin*], [AC_PROG_OBJC], [AM_CONDITIONAL([am__fastdepOBJC], [false])])
  70. # test_util.cc takes forever to compile with GCC and optimization turned on.
  71. AC_MSG_CHECKING([C++ compiler flags...])
  72. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
  73. AS_IF([test "$GCC" = "yes"],[
  74. PROTOBUF_OPT_FLAG="-O2"
  75. CXXFLAGS="${CXXFLAGS} -g"
  76. ])
  77. # Protocol Buffers contains several checks that are intended to be used only
  78. # for debugging and which might hurt performance. Most users are probably
  79. # end users who don't want these checks, so add -DNDEBUG by default.
  80. CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG"
  81. AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
  82. ],[
  83. AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
  84. ])
  85. AC_SUBST(PROTOBUF_OPT_FLAG)
  86. ACX_CHECK_SUNCC
  87. # Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
  88. # to the link
  89. AC_PROG_LIBTOOL
  90. # Check whether the linker supports version scripts
  91. AC_MSG_CHECKING([whether the linker supports version scripts])
  92. save_LDFLAGS=$LDFLAGS
  93. LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
  94. cat > conftest.map <<EOF
  95. {
  96. global:
  97. main;
  98. local:
  99. *;
  100. };
  101. EOF
  102. AC_LINK_IFELSE(
  103. [AC_LANG_SOURCE([int main() { return 0; }])],
  104. [have_ld_version_script=yes; AC_MSG_RESULT(yes)],
  105. [have_ld_version_script=no; AC_MSG_RESULT(no)])
  106. LDFLAGS=$save_LDFLAGS
  107. AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], [test "$have_ld_version_script" = "yes"])
  108. # Checks for header files.
  109. AC_HEADER_STDC
  110. AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
  111. # Checks for library functions.
  112. AC_FUNC_MEMCMP
  113. AC_FUNC_STRTOD
  114. AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
  115. # Check for zlib.
  116. HAVE_ZLIB=0
  117. AS_IF([test "$with_zlib" != no], [
  118. AC_MSG_CHECKING([zlib version])
  119. # First check the zlib header version.
  120. AC_COMPILE_IFELSE(
  121. [AC_LANG_PROGRAM([[
  122. #include <zlib.h>
  123. #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
  124. # error zlib version too old
  125. #endif
  126. ]], [])], [
  127. AC_MSG_RESULT([ok (1.2.0.4 or later)])
  128. # Also need to add -lz to the linker flags and make sure this succeeds.
  129. AC_SEARCH_LIBS([zlibVersion], [z], [
  130. AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
  131. HAVE_ZLIB=1
  132. ], [
  133. AS_IF([test "$with_zlib" != check], [
  134. AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
  135. ])
  136. ])
  137. ], [
  138. AS_IF([test "$with_zlib" = check], [
  139. AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
  140. ], [
  141. AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
  142. ])
  143. ])
  144. ])
  145. AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
  146. # Add -std=c++11 if necesssary. It is important for us to do this before the
  147. # libatomic check below, since that also depends on C++11.
  148. AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory])
  149. dnl On some platforms, std::atomic needs a helper library
  150. AC_MSG_CHECKING(whether -latomic is needed)
  151. AC_LINK_IFELSE([AC_LANG_SOURCE([[
  152. #include <atomic>
  153. #include <cstdint>
  154. std::atomic<std::int64_t> v;
  155. int main() {
  156. return v;
  157. }
  158. ]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes)
  159. AC_MSG_RESULT($STD_ATOMIC_NEED_LIBATOMIC)
  160. if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
  161. LIBATOMIC_LIBS="-latomic"
  162. fi
  163. AC_SUBST([LIBATOMIC_LIBS])
  164. AS_IF([test "$with_protoc" != "no"], [
  165. PROTOC=$with_protoc
  166. AS_IF([test "$with_protoc" = "yes"], [
  167. # No argument given. Use system protoc.
  168. PROTOC=protoc
  169. ])
  170. AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
  171. # Does not start with a slash, but contains a slash. So, it's a relative
  172. # path (as opposed to an absolute path or an executable in $PATH).
  173. # Since it will actually be executed from the src directory, prefix with
  174. # the current directory. We also insert $ac_top_build_prefix in case this
  175. # is a nested package and --with-protoc was actually given on the outer
  176. # package's configure script.
  177. PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
  178. ])
  179. AC_SUBST([PROTOC])
  180. ])
  181. AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
  182. AX_PTHREAD
  183. AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"])
  184. # We still keep this for improving pbconfig.h for unsupported platforms.
  185. AC_CXX_STL_HASH
  186. # Enable ObjC support for conformance directory on OS X.
  187. OBJC_CONFORMANCE_TEST=0
  188. case "$target_os" in
  189. darwin*)
  190. OBJC_CONFORMANCE_TEST=1
  191. ;;
  192. esac
  193. AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
  194. AC_MSG_CHECKING(whether -llog is needed)
  195. ANDROID_TEST=no
  196. case "$target_os" in
  197. *android*)
  198. ANDROID_TEST=yes
  199. ;;
  200. esac
  201. AC_MSG_RESULT($ANDROID_TEST)
  202. if test "x$ANDROID_TEST" = xyes; then
  203. LIBLOG_LIBS="-llog"
  204. fi
  205. AC_SUBST([LIBLOG_LIBS])
  206. # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
  207. # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
  208. # too.
  209. export CFLAGS
  210. export CXXFLAGS
  211. AC_CONFIG_SUBDIRS([third_party/googletest])
  212. AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
  213. AC_OUTPUT