configure.ac 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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],[2.3.0-pre],[protobuf@googlegroups.com],[protobuf])
  14. AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
  15. AC_CONFIG_HEADERS([config.h])
  16. AC_CONFIG_MACRO_DIR([m4])
  17. # autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
  18. # the best choice for libprotobuf.
  19. AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
  20. [CFLAGS=""])
  21. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
  22. [CXXFLAGS=""])
  23. AC_CANONICAL_TARGET
  24. AM_INIT_AUTOMAKE
  25. AC_ARG_WITH([zlib],
  26. [AS_HELP_STRING([--with-zlib],
  27. [include classes for streaming compressed data in and out @<:@default=check@:>@])],
  28. [],[with_zlib=check])
  29. AC_ARG_WITH([protoc],
  30. [AS_HELP_STRING([--with-protoc=COMMAND],
  31. [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
  32. [],[with_protoc=no])
  33. # Checks for programs.
  34. AC_PROG_CC
  35. AC_PROG_CXX
  36. AC_LANG([C++])
  37. ACX_USE_SYSTEM_EXTENSIONS
  38. AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
  39. # test_util.cc takes forever to compile with GCC and optimization turned on.
  40. AC_MSG_CHECKING([C++ compiler flags...])
  41. AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
  42. AS_IF([test "$GCC" = "yes"],[
  43. PROTOBUF_OPT_FLAG="-O2"
  44. CXXFLAGS="${CXXFLAGS} -g"
  45. ])
  46. # Protocol Buffers contains several checks that are intended to be used only
  47. # for debugging and which might hurt performance. Most users are probably
  48. # end users who don't want these checks, so add -DNDEBUG by default.
  49. CXXFLAGS="$CXXFLAGS -DNDEBUG"
  50. AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
  51. ],[
  52. AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
  53. ])
  54. AC_SUBST(PROTOBUF_OPT_FLAG)
  55. ACX_CHECK_SUNCC
  56. # Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
  57. # to the link
  58. AC_PROG_LIBTOOL
  59. # Checks for header files.
  60. AC_HEADER_STDC
  61. AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
  62. # Checks for library functions.
  63. AC_FUNC_MEMCMP
  64. AC_FUNC_STRTOD
  65. AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
  66. # Check for zlib.
  67. HAVE_ZLIB=0
  68. AS_IF([test "$with_zlib" != no], [
  69. AC_MSG_CHECKING([zlib version])
  70. # First check the zlib header version.
  71. AC_COMPILE_IFELSE(
  72. AC_LANG_PROGRAM([[
  73. #include <zlib.h>
  74. #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
  75. # error zlib version too old
  76. #endif
  77. ]], []), [
  78. AC_MSG_RESULT([ok (1.2.0.4 or later)])
  79. # Also need to add -lz to the linker flags and make sure this succeeds.
  80. AC_SEARCH_LIBS([zlibVersion], [z], [
  81. AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
  82. HAVE_ZLIB=1
  83. ], [
  84. AS_IF([test "$with_zlib" != check], [
  85. AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
  86. ])
  87. ])
  88. ], [
  89. AS_IF([test "$with_zlib" = check], [
  90. AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
  91. ], [
  92. AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
  93. ])
  94. ])
  95. ])
  96. AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
  97. AS_IF([test "$with_protoc" != "no"], [
  98. PROTOC=$with_protoc
  99. AS_IF([test "$with_protoc" == "yes"], [
  100. # No argument given. Use system protoc.
  101. PROTOC=protoc
  102. ])
  103. AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
  104. # Does not start with a slash, but contains a slash. So, it's a relative
  105. # path (as opposed to an absolute path or an executable in $PATH).
  106. # Since it will actually be executed from the src directory, prefix with
  107. # the current directory. We also insert $ac_top_build_prefix in case this
  108. # is a nested package and --with-protoc was actually given on the outer
  109. # package's configure script.
  110. PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
  111. ])
  112. AC_SUBST([PROTOC])
  113. ])
  114. AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
  115. ACX_PTHREAD
  116. AC_CXX_STL_HASH
  117. # HACK: Make gtest's configure script pick up our copy of CXXFLAGS, since the
  118. # flags added by ACX_CHECK_SUNCC must be used when compiling gtest too.
  119. export CXXFLAGS
  120. AC_CONFIG_SUBDIRS([gtest])
  121. AC_CONFIG_FILES([Makefile src/Makefile protobuf.pc protobuf-lite.pc])
  122. AC_OUTPUT