configure.ac 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. # * java/pom.xml
  6. # * python/setup.py
  7. # * src/google/protobuf/stubs/common.h
  8. # * src/Makefile.am (Update -version-info for LDFLAGS if needed)
  9. #
  10. # In the SVN trunk, the version should always be the next anticipated release
  11. # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
  12. # the size of one file name in the dist tarfile over the 99-char limit.)
  13. AC_INIT([Protocol Buffers],[3.0.0-beta-3],[protobuf@googlegroups.com],[protobuf])
  14. AM_MAINTAINER_MODE([enable])
  15. AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
  16. # The config file is generated but not used by the source code, since we only
  17. # need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are
  18. # passed down in CXXFLAGS manually in src/Makefile.am
  19. AC_CONFIG_HEADERS([config.h])
  20. AC_CONFIG_MACRO_DIR([m4])
  21. AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)])
  22. case "$DIST_LANG" in
  23. "") DIST_LANG=all ;;
  24. all | cpp | csharp | java | python | javanano | objectivec | ruby | js) ;;
  25. *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;;
  26. esac
  27. AC_SUBST(DIST_LANG)
  28. # autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
  29. # the best choice for libprotobuf.
  30. AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
  31. [CFLAGS=""])
  32. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
  33. [CXXFLAGS=""])
  34. AC_CANONICAL_TARGET
  35. AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects])
  36. AC_ARG_WITH([zlib],
  37. [AS_HELP_STRING([--with-zlib],
  38. [include classes for streaming compressed data in and out @<:@default=check@:>@])],
  39. [],[with_zlib=check])
  40. AC_ARG_WITH([protoc],
  41. [AS_HELP_STRING([--with-protoc=COMMAND],
  42. [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
  43. [],[with_protoc=no])
  44. # Checks for programs.
  45. AC_PROG_CC
  46. AC_PROG_CXX
  47. AC_LANG([C++])
  48. ACX_USE_SYSTEM_EXTENSIONS
  49. m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
  50. AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
  51. AC_PROG_OBJC
  52. # test_util.cc takes forever to compile with GCC and optimization turned on.
  53. AC_MSG_CHECKING([C++ compiler flags...])
  54. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
  55. AS_IF([test "$GCC" = "yes"],[
  56. PROTOBUF_OPT_FLAG="-O2"
  57. CXXFLAGS="${CXXFLAGS} -g"
  58. ])
  59. # Protocol Buffers contains several checks that are intended to be used only
  60. # for debugging and which might hurt performance. Most users are probably
  61. # end users who don't want these checks, so add -DNDEBUG by default.
  62. CXXFLAGS="$CXXFLAGS -DNDEBUG"
  63. AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
  64. ],[
  65. AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
  66. ])
  67. AC_SUBST(PROTOBUF_OPT_FLAG)
  68. ACX_CHECK_SUNCC
  69. # Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
  70. # to the link
  71. AC_PROG_LIBTOOL
  72. # Checks for header files.
  73. AC_HEADER_STDC
  74. AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
  75. # Checks for library functions.
  76. AC_FUNC_MEMCMP
  77. AC_FUNC_STRTOD
  78. AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
  79. # Check for zlib.
  80. HAVE_ZLIB=0
  81. AS_IF([test "$with_zlib" != no], [
  82. AC_MSG_CHECKING([zlib version])
  83. # First check the zlib header version.
  84. AC_COMPILE_IFELSE(
  85. [AC_LANG_PROGRAM([[
  86. #include <zlib.h>
  87. #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
  88. # error zlib version too old
  89. #endif
  90. ]], [])], [
  91. AC_MSG_RESULT([ok (1.2.0.4 or later)])
  92. # Also need to add -lz to the linker flags and make sure this succeeds.
  93. AC_SEARCH_LIBS([zlibVersion], [z], [
  94. AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
  95. HAVE_ZLIB=1
  96. ], [
  97. AS_IF([test "$with_zlib" != check], [
  98. AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
  99. ])
  100. ])
  101. ], [
  102. AS_IF([test "$with_zlib" = check], [
  103. AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
  104. ], [
  105. AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
  106. ])
  107. ])
  108. ])
  109. AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
  110. AS_IF([test "$with_protoc" != "no"], [
  111. PROTOC=$with_protoc
  112. AS_IF([test "$with_protoc" = "yes"], [
  113. # No argument given. Use system protoc.
  114. PROTOC=protoc
  115. ])
  116. AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
  117. # Does not start with a slash, but contains a slash. So, it's a relative
  118. # path (as opposed to an absolute path or an executable in $PATH).
  119. # Since it will actually be executed from the src directory, prefix with
  120. # the current directory. We also insert $ac_top_build_prefix in case this
  121. # is a nested package and --with-protoc was actually given on the outer
  122. # package's configure script.
  123. PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
  124. ])
  125. AC_SUBST([PROTOC])
  126. ])
  127. AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
  128. ACX_PTHREAD
  129. AM_CONDITIONAL([HAVE_PTHREAD], [test "x$acx_pthread_ok" = "xyes"])
  130. # We still keep this for improving pbconfig.h for unsupported platforms.
  131. AC_CXX_STL_HASH
  132. case "$target_os" in
  133. mingw* | cygwin* | win*)
  134. ;;
  135. *)
  136. # Need to link against rt on Solaris
  137. AC_SEARCH_LIBS([sched_yield], [rt], [], [AC_MSG_FAILURE([sched_yield was not found on your system])])
  138. ;;
  139. esac
  140. # Enable ObjC support for conformance directory on OS X.
  141. OBJC_CONFORMANCE_TEST=0
  142. case "$target_os" in
  143. darwin*)
  144. OBJC_CONFORMANCE_TEST=1
  145. ;;
  146. esac
  147. AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
  148. # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
  149. # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
  150. # too.
  151. export CFLAGS
  152. export CXXFLAGS
  153. AC_CONFIG_SUBDIRS([gmock])
  154. AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
  155. AC_OUTPUT