configure.ac 5.7 KB

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