configure.ac 6.7 KB

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