aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--README31
-rw-r--r--configure.ac14
-rwxr-xr-xscripts/gmock-config.in303
4 files changed, 330 insertions, 22 deletions
diff --git a/Makefile.am b/Makefile.am
index e58f7fee..4a5a3fd6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,6 +7,10 @@ SUBDIRS = $(subdirs)
# Scripts and utilities to be installed by 'make install'.
dist_bin_SCRIPTS = scripts/gmock_doctor.py
+bin_SCRIPTS = scripts/gmock-config
+
+# This is generated by the configure script, so clean it for distribution.
+DISTCLEANFILES = scripts/gmock-config
# We define the global AM_CPPFLAGS as everything we compile includes from these
# directories.
diff --git a/README b/README
index 77610e28..47d10edb 100644
--- a/README
+++ b/README
@@ -40,10 +40,8 @@ testing framework for writing tests. Currently Google Mock only works
with Google Test (http://code.google.com/p/googletest/), although
eventually we plan to support other C++ testing frameworks. You can
use either the copy of Google Test that comes with Google Mock, or a
-compatible version you already have.
-
-TODO(wan@google.com): describe which Google Test versions are
-compatible with the latest Google Mock release.
+compatible version you already have. This version of Google Mock
+requires Google Test 1.2.1.
Google Mock depends on advanced C++ features and thus requires a more
modern compiler. The following are needed to use Google Mock:
@@ -101,20 +99,23 @@ or for a release version X.Y.*'s branch:
Next you will need to prepare the GNU Autotools build system, if you
are using Linux or Mac OS X. Enter the target directory of the
checkout command you used ('gmock-svn' or 'gmock-X.Y-svn' above) and
-proceed with the following commands:
+proceed with the following command:
+
+ $ autoreconf -fvi
+
+Once you have completed this step, you are ready to build the library.
+Note that you should need to complete this step only once. The sub-
+sequent `make' invocations will automatically re-generate the bits of
+the build system that need to be changed.
- $ aclocal-1.9 # Where "1.9" must match the following automake command.
- $ libtoolize -c # Use "glibtoolize -c" instead on Mac OS X.
- $ autoheader
- $ automake-1.9 -ac # See Automake version requirements above.
- $ autoconf
+If your system uses older versions of the autotools, the above command will
+fail. You may need to explicitly specify a version to use. For instance, if
+you have both GNU Automake 1.4 and 1.9 installed and `automake' would invoke
+the 1.4, use instead:
-While this is a bit complicated, it will most often be automatically re-run by
-your "make" invocations, so in practice you shouldn't need to worry too much.
-Once you have completed these steps, you are ready to build the library.
+ $ AUTOMAKE=automake-1.9 ACLOCAL=aclocal-1.9 autoreconf -fvi
-TODO(chandlerc@google.com): Update the above with instructions on
-preparing the build system for Google Test.
+Make sure you're using the same version of automake and aclocal.
### Source Package: ###
Google Mock is also released in source packages which can be downloaded from
diff --git a/configure.ac b/configure.ac
index 60742504..65a48b4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,7 @@ AC_CONFIG_SRCDIR([./COPYING])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([build-aux/config.h])
AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([scripts/gmock-config], [chmod +x scripts/gmock-config])
# Initialize Automake with various options. We require at least v1.9, prevent
# pedantic complaints about package files, and enable various distribution
@@ -79,10 +80,7 @@ AC_ARG_VAR([GTEST_VERSION],
[The version of Google Test available.])
HAVE_BUILT_GTEST="no"
-# TODO(chandlerc@google.com): This is arbitrary, but we will need to introduce
-# some features to the GoogleTest build system to help support GoogleMock, and
-# at that point it will become more meaningful.
-GTEST_MIN_VERSION="1.0.0"
+GTEST_MIN_VERSION="1.2.1"
AS_IF([test "x${enable_external_gtest}" = "xyes"],
[# Begin filling in variables as we are able.
@@ -111,11 +109,13 @@ AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"],
GTEST_LIBS=`${GTEST_CONFIG} --libs`
GTEST_VERSION=`${GTEST_CONFIG} --version`],
[AC_CONFIG_SUBDIRS([gtest])
- GTEST_CONFIG='$(builddir)/gtest/scripts/gtest-config'
- GTEST_CPPFLAGS='-I$(srcdir)/gtest/include -I$(srcdir)/gtest'
+ # GTEST_CONFIG needs to be executable both in a Makefile environmont and
+ # in a shell script environment, so resolve an absolute path for it here.
+ GTEST_CONFIG="`pwd -P`/gtest/scripts/gtest-config"
+ GTEST_CPPFLAGS='-I$(top_srcdir)/gtest/include'
GTEST_CXXFLAGS='-g'
GTEST_LDFLAGS=''
- GTEST_LIBS='$(builddir)/gtest/lib/libgtest.la'
+ GTEST_LIBS='$(top_builddir)/gtest/lib/libgtest.la'
GTEST_VERSION="${GTEST_MIN_VERSION}"])
# TODO(chandlerc@google.com) Check the types, structures, and other compiler
diff --git a/scripts/gmock-config.in b/scripts/gmock-config.in
new file mode 100755
index 00000000..540faff7
--- /dev/null
+++ b/scripts/gmock-config.in
@@ -0,0 +1,303 @@
+#!/bin/sh
+
+# These variables are automatically filled in by the configure script.
+name="@PACKAGE_TARNAME@"
+version="@PACKAGE_VERSION@"
+
+show_usage()
+{
+ echo "Usage: gmock-config [OPTIONS...]"
+}
+
+show_help()
+{
+ show_usage
+ cat <<\EOF
+
+The `gmock-config' script provides access to the necessary compile and linking
+flags to connect with Google C++ Mocking Framework, both in a build prior to
+installation, and on the system proper after installation. The installation
+overrides may be issued in combination with any other queries, but will only
+affect installation queries if called on a built but not installed gmock. The
+installation queries may not be issued with any other types of queries, and
+only one installation query may be made at a time. The version queries and
+compiler flag queries may be combined as desired but not mixed. Different
+version queries are always combined with logical "and" semantics, and only the
+last of any particular query is used while all previous ones ignored. All
+versions must be specified as a sequence of numbers separated by periods.
+Compiler flag queries output the union of the sets of flags when combined.
+
+ Examples:
+ gmock-config --min-version=1.0 || echo "Insufficient Google Mock version."
+
+ g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp
+ g++ $(gmock-config --ldflags --libs) -o foo foo.o
+
+ # When using a built but not installed Google Mock:
+ g++ $(../../my_gmock_build/scripts/gtest-config ...) ...
+
+ # When using an installed Google Mock, but with installation overrides:
+ export GMOCK_PREFIX="/opt"
+ g++ $(gmock-config --libdir="/opt/lib64" ...) ...
+
+ Help:
+ --usage brief usage information
+ --help display this help message
+
+ Installation Overrides:
+ --prefix=<dir> overrides the installation prefix
+ --exec-prefix=<dir> overrides the executable installation prefix
+ --libdir=<dir> overrides the library installation prefix
+ --includedir=<dir> overrides the header file installation prefix
+
+ Installation Queries:
+ --prefix installation prefix
+ --exec-prefix executable installation prefix
+ --libdir library installation directory
+ --includedir header file installation directory
+ --version the version of the Google Mock installation
+
+ Version Queries:
+ --min-version=VERSION return 0 if the version is at least VERSION
+ --exact-version=VERSION return 0 if the version is exactly VERSION
+ --max-version=VERSION return 0 if the version is at most VERSION
+
+ Compilation Flag Queries:
+ --cppflags compile flags specific to the C-like preprocessors
+ --cxxflags compile flags appropriate for C++ programs
+ --ldflags linker flags
+ --libs libraries for linking
+
+EOF
+}
+
+# This function bounds our version with a min and a max. It uses some clever
+# POSIX-compliant variable expansion to portably do all the work in the shell
+# and avoid any dependency on a particular "sed" or "awk" implementation.
+# Notable is that it will only ever compare the first 3 components of versions.
+# Further components will be cleanly stripped off. All versions must be
+# unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
+# the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
+# investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
+# continuing to maintain our own shell version.
+check_versions()
+{
+ major_version=${version%%.*}
+ minor_version="0"
+ point_version="0"
+ if test "${version#*.}" != "${version}"; then
+ minor_version=${version#*.}
+ minor_version=${minor_version%%.*}
+ fi
+ if test "${version#*.*.}" != "${version}"; then
+ point_version=${version#*.*.}
+ point_version=${point_version%%.*}
+ fi
+
+ min_version="$1"
+ min_major_version=${min_version%%.*}
+ min_minor_version="0"
+ min_point_version="0"
+ if test "${min_version#*.}" != "${min_version}"; then
+ min_minor_version=${min_version#*.}
+ min_minor_version=${min_minor_version%%.*}
+ fi
+ if test "${min_version#*.*.}" != "${min_version}"; then
+ min_point_version=${min_version#*.*.}
+ min_point_version=${min_point_version%%.*}
+ fi
+
+ max_version="$2"
+ max_major_version=${max_version%%.*}
+ max_minor_version="0"
+ max_point_version="0"
+ if test "${max_version#*.}" != "${max_version}"; then
+ max_minor_version=${max_version#*.}
+ max_minor_version=${max_minor_version%%.*}
+ fi
+ if test "${max_version#*.*.}" != "${max_version}"; then
+ max_point_version=${max_version#*.*.}
+ max_point_version=${max_point_version%%.*}
+ fi
+
+ test $(($major_version)) -lt $(($min_major_version)) && exit 1
+ if test $(($major_version)) -eq $(($min_major_version)); then
+ test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
+ if test $(($minor_version)) -eq $(($min_minor_version)); then
+ test $(($point_version)) -lt $(($min_point_version)) && exit 1
+ fi
+ fi
+
+ test $(($major_version)) -gt $(($max_major_version)) && exit 1
+ if test $(($major_version)) -eq $(($max_major_version)); then
+ test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
+ if test $(($minor_version)) -eq $(($max_minor_version)); then
+ test $(($point_version)) -gt $(($max_point_version)) && exit 1
+ fi
+ fi
+
+ exit 0
+}
+
+# Show the usage line when no arguments are specified.
+if test $# -eq 0; then
+ show_usage
+ exit 1
+fi
+
+while test $# -gt 0; do
+ case $1 in
+ --usage) show_usage; exit 0;;
+ --help) show_help; exit 0;;
+
+ # Installation overrides
+ --prefix=*) GMOCK_PREFIX=${1#--prefix=};;
+ --exec-prefix=*) GMOCK_EXEC_PREFIX=${1#--exec-prefix=};;
+ --libdir=*) GMOCK_LIBDIR=${1#--libdir=};;
+ --includedir=*) GMOCK_INCLUDEDIR=${1#--includedir=};;
+
+ # Installation queries
+ --prefix|--exec-prefix|--libdir|--includedir|--version)
+ if test -n "${do_query}"; then
+ show_usage
+ exit 1
+ fi
+ do_query=${1#--}
+ ;;
+
+ # Version checking
+ --min-version=*)
+ do_check_versions=yes
+ min_version=${1#--min-version=}
+ ;;
+ --max-version=*)
+ do_check_versions=yes
+ max_version=${1#--max-version=}
+ ;;
+ --exact-version=*)
+ do_check_versions=yes
+ exact_version=${1#--exact-version=}
+ ;;
+
+ # Compiler flag output
+ --cppflags) echo_cppflags=yes;;
+ --cxxflags) echo_cxxflags=yes;;
+ --ldflags) echo_ldflags=yes;;
+ --libs) echo_libs=yes;;
+
+ # Everything else is an error
+ *) show_usage; exit 1;;
+ esac
+ shift
+done
+
+# These have defaults filled in by the configure script but can also be
+# overridden by environment variables or command line parameters.
+prefix="${GMOCK_PREFIX:-@prefix@}"
+exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}"
+libdir="${GMOCK_LIBDIR:-@libdir@}"
+includedir="${GMOCK_INCLUDEDIR:-@includedir@}"
+
+# We try and detect if our binary is not located at its installed location. If
+# it's not, we provide variables pointing to the source and build tree rather
+# than to the install tree. We also locate Google Test using the configured
+# gtest-config script rather than searching the PATH and our bindir for one.
+# This allows building against a just-built gmock rather than an installed
+# gmock.
+bindir="@bindir@"
+this_relative_bindir=`dirname $0`
+this_bindir=`cd ${this_relative_bindir}; pwd -P`
+if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
+ # The path to the script doesn't end in the bindir sequence from Autoconf,
+ # assume that we are in a build tree.
+ build_dir=`dirname ${this_bindir}`
+ src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P`
+
+ # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
+ # should work to remove it, and/or remove libtool altogether, replacing it
+ # with direct references to the library and a link path.
+ gmock_libs="${build_dir}/lib/libgtest.la"
+ gmock_ldflags=""
+
+ # We provide hooks to include from either the source or build dir, where the
+ # build dir is always preferred. This will potentially allow us to write
+ # build rules for generated headers and have them automatically be preferred
+ # over provided versions.
+ gmock_cppflags="-I${build_dir}/include -I${src_dir}/include"
+ gmock_cxxflags=""
+
+ # Directly invoke the gtest-config script used during the build process.
+ gtest_config="@GTEST_CONFIG@"
+else
+ # We're using an installed gmock, although it may be staged under some
+ # prefix. Assume (as our own libraries do) that we can resolve the prefix,
+ # and are present in the dynamic link paths.
+ gmock_ldflags="-L${libdir}"
+ gmock_libs="-l${name}"
+ gmock_cppflags="-I${includedir}"
+ gmock_cxxflags=""
+
+ # We also prefer any gtest-config script installed in our prefix. Lacking
+ # one, we look in the PATH for one.
+ gtest_config="${bindir}/gtest-config"
+ if test ! -x "${gtest_config}"; then
+ gtest_config=`which gtest-config`
+ fi
+fi
+
+# Ensure that we have located a Google Test to link against.
+if ! test -x "${gtest_config}"; then
+ echo "Unable to locate Google Test, check your Google Mock configuration" \
+ "and installation" >&2
+ exit 1
+elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then
+ echo "The Google Test found is not the same version as Google Mock was " \
+ "built against" >&2
+ exit 1
+fi
+
+# Add the necessary Google Test bits into the various flag variables
+gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`"
+gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`"
+gmock_ldflags="${gmock_ldflags}`${gtest_config} --ldflags`"
+gmock_libs="${gmock_libs} `${gtest_config} --libs`"
+
+# Do an installation query if requested.
+if test -n "$do_query"; then
+ case $do_query in
+ prefix) echo $prefix; exit 0;;
+ exec-prefix) echo $exec_prefix; exit 0;;
+ libdir) echo $libdir; exit 0;;
+ includedir) echo $includedir; exit 0;;
+ version) echo $version; exit 0;;
+ *) show_usage; exit 1;;
+ esac
+fi
+
+# Do a version check if requested.
+if test "$do_check_versions" = "yes"; then
+ # Make sure we didn't receive a bad combination of parameters.
+ test "$echo_cppflags" = "yes" && show_usage && exit 1
+ test "$echo_cxxflags" = "yes" && show_usage && exit 1
+ test "$echo_ldflags" = "yes" && show_usage && exit 1
+ test "$echo_libs" = "yes" && show_usage && exit 1
+
+ if test "$exact_version" != ""; then
+ check_versions $exact_version $exact_version
+ # unreachable
+ else
+ check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
+ # unreachable
+ fi
+fi
+
+# Do the output in the correct order so that these can be used in-line of
+# a compiler invocation.
+output=""
+test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags"
+test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags"
+test "$echo_ldflags" = "yes" && output="$output $gmock_ldflags"
+test "$echo_libs" = "yes" && output="$output $gmock_libs"
+echo $output
+
+exit 0