configure.ac 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.6.1],[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. AC_ARG_WITH([zlib],
  42. [AS_HELP_STRING([--with-zlib],
  43. [include classes for streaming compressed data in and out @<:@default=check@:>@])],
  44. [],[with_zlib=check])
  45. AC_ARG_WITH([zlib-include],
  46. [AS_HELP_STRING([--with-zlib-include=PATH],
  47. [zlib include directory])],
  48. [CPPFLAGS="-I$withval $CPPFLAGS"])
  49. AC_ARG_WITH([zlib-lib],
  50. [AS_HELP_STRING([--with-zlib-lib=PATH],
  51. [zlib lib directory])],
  52. [LDFLAGS="-L$withval $LDFLAGS"])
  53. AC_ARG_WITH([protoc],
  54. [AS_HELP_STRING([--with-protoc=COMMAND],
  55. [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
  56. [],[with_protoc=no])
  57. # Checks for programs.
  58. AC_PROG_CC
  59. AC_PROG_CXX
  60. AC_PROG_CXX_FOR_BUILD
  61. AC_LANG([C++])
  62. ACX_USE_SYSTEM_EXTENSIONS
  63. m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
  64. AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
  65. AC_PROG_OBJC
  66. # test_util.cc takes forever to compile with GCC and optimization turned on.
  67. AC_MSG_CHECKING([C++ compiler flags...])
  68. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
  69. AS_IF([test "$GCC" = "yes"],[
  70. PROTOBUF_OPT_FLAG="-O2"
  71. CXXFLAGS="${CXXFLAGS} -g"
  72. ])
  73. # Protocol Buffers contains several checks that are intended to be used only
  74. # for debugging and which might hurt performance. Most users are probably
  75. # end users who don't want these checks, so add -DNDEBUG by default.
  76. CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG"
  77. AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
  78. ],[
  79. AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
  80. ])
  81. AC_SUBST(PROTOBUF_OPT_FLAG)
  82. ACX_CHECK_SUNCC
  83. # Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
  84. # to the link
  85. AC_PROG_LIBTOOL
  86. # Check whether the linker supports version scripts
  87. AC_MSG_CHECKING([whether the linker supports version scripts])
  88. save_LDFLAGS=$LDFLAGS
  89. LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
  90. cat > conftest.map <<EOF
  91. {
  92. global:
  93. main;
  94. local:
  95. *;
  96. };
  97. EOF
  98. AC_LINK_IFELSE(
  99. [AC_LANG_SOURCE([int main() { return 0; }])],
  100. [have_ld_version_script=yes; AC_MSG_RESULT(yes)],
  101. [have_ld_version_script=no; AC_MSG_RESULT(no)])
  102. LDFLAGS=$save_LDFLAGS
  103. AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], [test "$have_ld_version_script" == "yes"])
  104. # Checks for header files.
  105. AC_HEADER_STDC
  106. AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
  107. # Checks for library functions.
  108. AC_FUNC_MEMCMP
  109. AC_FUNC_STRTOD
  110. AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
  111. # Check for zlib.
  112. HAVE_ZLIB=0
  113. AS_IF([test "$with_zlib" != no], [
  114. AC_MSG_CHECKING([zlib version])
  115. # First check the zlib header version.
  116. AC_COMPILE_IFELSE(
  117. [AC_LANG_PROGRAM([[
  118. #include <zlib.h>
  119. #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
  120. # error zlib version too old
  121. #endif
  122. ]], [])], [
  123. AC_MSG_RESULT([ok (1.2.0.4 or later)])
  124. # Also need to add -lz to the linker flags and make sure this succeeds.
  125. AC_SEARCH_LIBS([zlibVersion], [z], [
  126. AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
  127. HAVE_ZLIB=1
  128. ], [
  129. AS_IF([test "$with_zlib" != check], [
  130. AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
  131. ])
  132. ])
  133. ], [
  134. AS_IF([test "$with_zlib" = check], [
  135. AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
  136. ], [
  137. AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
  138. ])
  139. ])
  140. ])
  141. AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
  142. dnl On some platforms, std::atomic needs a helper library
  143. AC_MSG_CHECKING(whether -latomic is needed)
  144. AC_LINK_IFELSE([AC_LANG_SOURCE([[
  145. #include <atomic>
  146. #include <cstdint>
  147. std::atomic<std::int64_t> v;
  148. int main() {
  149. return v;
  150. }
  151. ]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes)
  152. AC_MSG_RESULT($STD_ATOMIC_NEED_LIBATOMIC)
  153. if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
  154. LIBATOMIC_LIBS="-latomic"
  155. fi
  156. AC_SUBST([LIBATOMIC_LIBS])
  157. AS_IF([test "$with_protoc" != "no"], [
  158. PROTOC=$with_protoc
  159. AS_IF([test "$with_protoc" = "yes"], [
  160. # No argument given. Use system protoc.
  161. PROTOC=protoc
  162. ])
  163. AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
  164. # Does not start with a slash, but contains a slash. So, it's a relative
  165. # path (as opposed to an absolute path or an executable in $PATH).
  166. # Since it will actually be executed from the src directory, prefix with
  167. # the current directory. We also insert $ac_top_build_prefix in case this
  168. # is a nested package and --with-protoc was actually given on the outer
  169. # package's configure script.
  170. PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
  171. ])
  172. AC_SUBST([PROTOC])
  173. ])
  174. AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
  175. AX_PTHREAD
  176. AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"])
  177. # We still keep this for improving pbconfig.h for unsupported platforms.
  178. AC_CXX_STL_HASH
  179. # Enable ObjC support for conformance directory on OS X.
  180. OBJC_CONFORMANCE_TEST=0
  181. case "$target_os" in
  182. darwin*)
  183. OBJC_CONFORMANCE_TEST=1
  184. ;;
  185. esac
  186. AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
  187. AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory])
  188. # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
  189. # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
  190. # too.
  191. export CFLAGS
  192. export CXXFLAGS
  193. AC_CONFIG_SUBDIRS([third_party/googletest])
  194. AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
  195. AC_OUTPUT