configure.ac 6.1 KB

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