configure.ac 6.09 KB
Newer Older
temporal's avatar
temporal committed
1 2 3 4 5 6
## Process this file with autoconf to produce configure.
## In general, the safest way to proceed is to run ./autogen.sh

AC_PREREQ(2.59)

# Note:  If you change the version, you must also update it in:
7 8 9 10 11 12 13
# * Protobuf.podspec
# * csharp/Google.Protobuf.Tools.nuspec
# * csharp/src/*/AssemblyInfo.cs
# * csharp/src/Google.Protobuf/Google.Protobuf.nuspec
# * java/*/pom.xml
# * python/google/protobuf/__init__.py
# * protoc-artifacts/pom.xml
temporal's avatar
temporal committed
14
# * src/google/protobuf/stubs/common.h
15
# * src/Makefile.am (Update -version-info for LDFLAGS if needed)
16 17 18 19
#
# In the SVN trunk, the version should always be the next anticipated release
# version with the "-pre" suffix.  (We used to use "-SNAPSHOT" but this pushed
# the size of one file name in the dist tarfile over the 99-char limit.)
Jisi Liu's avatar
Jisi Liu committed
20
AC_INIT([Protocol Buffers],[3.0.0],[protobuf@googlegroups.com],[protobuf])
temporal's avatar
temporal committed
21

22
AM_MAINTAINER_MODE([enable])
23

temporal's avatar
temporal committed
24
AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
25 26 27
# The config file is generated but not used by the source code, since we only
# need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are
# passed down in CXXFLAGS manually in src/Makefile.am
28
AC_CONFIG_HEADERS([config.h])
29
AC_CONFIG_MACRO_DIR([m4])
30

31 32
AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)])
case "$DIST_LANG" in
33
  "") DIST_LANG=all ;;
34
  all | cpp | csharp | java | python | javanano | objectivec | ruby | js) ;;
35 36 37 38
  *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;;
esac
AC_SUBST(DIST_LANG)

39 40 41 42 43 44
# autoconf's default CXXFLAGS are usually "-g -O2".  These aren't necessarily
# the best choice for libprotobuf.
AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
      [CFLAGS=""])
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
      [CXXFLAGS=""])
45

46 47
AC_CANONICAL_TARGET

48
AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects])
temporal's avatar
temporal committed
49

50 51 52 53 54
AC_ARG_WITH([zlib],
  [AS_HELP_STRING([--with-zlib],
    [include classes for streaming compressed data in and out @<:@default=check@:>@])],
  [],[with_zlib=check])

55 56 57 58 59
AC_ARG_WITH([protoc],
  [AS_HELP_STRING([--with-protoc=COMMAND],
    [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
  [],[with_protoc=no])

temporal's avatar
temporal committed
60 61 62
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
63
AC_LANG([C++])
64
ACX_USE_SYSTEM_EXTENSIONS
65
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
temporal's avatar
temporal committed
66
AM_CONDITIONAL(GCC, test "$GCC" = yes)   # let the Makefile know if we're gcc
67
AC_PROG_OBJC
68

69
# test_util.cc takes forever to compile with GCC and optimization turned on.
70
AC_MSG_CHECKING([C++ compiler flags...])
71 72 73 74 75
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
  AS_IF([test "$GCC" = "yes"],[
    PROTOBUF_OPT_FLAG="-O2"
    CXXFLAGS="${CXXFLAGS} -g"
  ])
76 77 78 79 80 81 82 83 84 85 86 87 88

  # Protocol Buffers contains several checks that are intended to be used only
  # for debugging and which might hurt performance.  Most users are probably
  # end users who don't want these checks, so add -DNDEBUG by default.
  CXXFLAGS="$CXXFLAGS -DNDEBUG"

  AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
],[
  AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
])

AC_SUBST(PROTOBUF_OPT_FLAG)

89
ACX_CHECK_SUNCC
temporal's avatar
temporal committed
90

91
# Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
92 93 94
# to the link
AC_PROG_LIBTOOL

temporal's avatar
temporal committed
95 96 97 98 99 100 101 102 103
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])

# Checks for library functions.
AC_FUNC_MEMCMP
AC_FUNC_STRTOD
AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])

104
# Check for zlib.
105
HAVE_ZLIB=0
106 107 108 109 110
AS_IF([test "$with_zlib" != no], [
  AC_MSG_CHECKING([zlib version])

  # First check the zlib header version.
  AC_COMPILE_IFELSE(
111
    [AC_LANG_PROGRAM([[
112 113 114 115
        #include <zlib.h>
        #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
        # error zlib version too old
        #endif
116
        ]], [])], [
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    AC_MSG_RESULT([ok (1.2.0.4 or later)])

    # Also need to add -lz to the linker flags and make sure this succeeds.
    AC_SEARCH_LIBS([zlibVersion], [z], [
      AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
      HAVE_ZLIB=1
    ], [
      AS_IF([test "$with_zlib" != check], [
        AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
      ])
    ])
  ], [
    AS_IF([test "$with_zlib" = check], [
      AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
    ], [
      AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
    ])
  ])
])
136 137
AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])

138 139
AS_IF([test "$with_protoc" != "no"], [
  PROTOC=$with_protoc
140
  AS_IF([test "$with_protoc" = "yes"], [
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    # No argument given.  Use system protoc.
    PROTOC=protoc
  ])
  AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
    # Does not start with a slash, but contains a slash.  So, it's a relative
    # path (as opposed to an absolute path or an executable in $PATH).
    # Since it will actually be executed from the src directory, prefix with
    # the current directory.  We also insert $ac_top_build_prefix in case this
    # is a nested package and --with-protoc was actually given on the outer
    # package's configure script.
    PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
  ])
  AC_SUBST([PROTOC])
])
AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])

temporal's avatar
temporal committed
157
ACX_PTHREAD
158 159 160
AM_CONDITIONAL([HAVE_PTHREAD], [test "x$acx_pthread_ok" = "xyes"])

# We still keep this for improving pbconfig.h for unsupported platforms.
temporal's avatar
temporal committed
161 162
AC_CXX_STL_HASH

163 164 165 166 167 168 169 170
case "$target_os" in
  mingw* | cygwin* | win*)
    ;;
  *)
    # Need to link against rt on Solaris
    AC_SEARCH_LIBS([sched_yield], [rt], [], [AC_MSG_FAILURE([sched_yield was not found on your system])])
    ;;
esac
171

172 173 174 175 176 177 178 179 180
# Enable ObjC support for conformance directory on OS X.
OBJC_CONFORMANCE_TEST=0
case "$target_os" in
  darwin*)
    OBJC_CONFORMANCE_TEST=1
    ;;
esac
AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])

181 182
# HACK:  Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
#   since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
183 184
#   too.
export CFLAGS
185
export CXXFLAGS
186
AC_CONFIG_SUBDIRS([gmock])
187

188
AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
189
AC_OUTPUT