3 # These variables are automatically filled in by the configure script.
4 name="@PACKAGE_TARNAME@"
5 version="@PACKAGE_VERSION@"
9 echo "Usage: gmock-config [OPTIONS...]"
17 The `gmock-config' script provides access to the necessary compile and linking
18 flags to connect with Google C++ Mocking Framework, both in a build prior to
19 installation, and on the system proper after installation. The installation
20 overrides may be issued in combination with any other queries, but will only
21 affect installation queries if called on a built but not installed gmock. The
22 installation queries may not be issued with any other types of queries, and
23 only one installation query may be made at a time. The version queries and
24 compiler flag queries may be combined as desired but not mixed. Different
25 version queries are always combined with logical "and" semantics, and only the
26 last of any particular query is used while all previous ones ignored. All
27 versions must be specified as a sequence of numbers separated by periods.
28 Compiler flag queries output the union of the sets of flags when combined.
31 gmock-config --min-version=1.0 || echo "Insufficient Google Mock version."
33 g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp
34 g++ $(gmock-config --ldflags --libs) -o foo foo.o
36 # When using a built but not installed Google Mock:
37 g++ $(../../my_gmock_build/scripts/gmock-config ...) ...
39 # When using an installed Google Mock, but with installation overrides:
40 export GMOCK_PREFIX="/opt"
41 g++ $(gmock-config --libdir="/opt/lib64" ...) ...
44 --usage brief usage information
45 --help display this help message
47 Installation Overrides:
48 --prefix=<dir> overrides the installation prefix
49 --exec-prefix=<dir> overrides the executable installation prefix
50 --libdir=<dir> overrides the library installation prefix
51 --includedir=<dir> overrides the header file installation prefix
54 --prefix installation prefix
55 --exec-prefix executable installation prefix
56 --libdir library installation directory
57 --includedir header file installation directory
58 --version the version of the Google Mock installation
61 --min-version=VERSION return 0 if the version is at least VERSION
62 --exact-version=VERSION return 0 if the version is exactly VERSION
63 --max-version=VERSION return 0 if the version is at most VERSION
65 Compilation Flag Queries:
66 --cppflags compile flags specific to the C-like preprocessors
67 --cxxflags compile flags appropriate for C++ programs
68 --ldflags linker flags
69 --libs libraries for linking
74 # This function bounds our version with a min and a max. It uses some clever
75 # POSIX-compliant variable expansion to portably do all the work in the shell
76 # and avoid any dependency on a particular "sed" or "awk" implementation.
77 # Notable is that it will only ever compare the first 3 components of versions.
78 # Further components will be cleanly stripped off. All versions must be
79 # unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
80 # the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
81 # investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
82 # continuing to maintain our own shell version.
85 major_version=${version%%.*}
88 if test "${version#*.}" != "${version}"; then
89 minor_version=${version#*.}
90 minor_version=${minor_version%%.*}
92 if test "${version#*.*.}" != "${version}"; then
93 point_version=${version#*.*.}
94 point_version=${point_version%%.*}
98 min_major_version=${min_version%%.*}
100 min_point_version="0"
101 if test "${min_version#*.}" != "${min_version}"; then
102 min_minor_version=${min_version#*.}
103 min_minor_version=${min_minor_version%%.*}
105 if test "${min_version#*.*.}" != "${min_version}"; then
106 min_point_version=${min_version#*.*.}
107 min_point_version=${min_point_version%%.*}
111 max_major_version=${max_version%%.*}
112 max_minor_version="0"
113 max_point_version="0"
114 if test "${max_version#*.}" != "${max_version}"; then
115 max_minor_version=${max_version#*.}
116 max_minor_version=${max_minor_version%%.*}
118 if test "${max_version#*.*.}" != "${max_version}"; then
119 max_point_version=${max_version#*.*.}
120 max_point_version=${max_point_version%%.*}
123 test $(($major_version)) -lt $(($min_major_version)) && exit 1
124 if test $(($major_version)) -eq $(($min_major_version)); then
125 test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
126 if test $(($minor_version)) -eq $(($min_minor_version)); then
127 test $(($point_version)) -lt $(($min_point_version)) && exit 1
131 test $(($major_version)) -gt $(($max_major_version)) && exit 1
132 if test $(($major_version)) -eq $(($max_major_version)); then
133 test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
134 if test $(($minor_version)) -eq $(($max_minor_version)); then
135 test $(($point_version)) -gt $(($max_point_version)) && exit 1
142 # Show the usage line when no arguments are specified.
143 if test $# -eq 0; then
148 while test $# -gt 0; do
150 --usage) show_usage; exit 0;;
151 --help) show_help; exit 0;;
153 # Installation overrides
154 --prefix=*) GMOCK_PREFIX=${1#--prefix=};;
155 --exec-prefix=*) GMOCK_EXEC_PREFIX=${1#--exec-prefix=};;
156 --libdir=*) GMOCK_LIBDIR=${1#--libdir=};;
157 --includedir=*) GMOCK_INCLUDEDIR=${1#--includedir=};;
159 # Installation queries
160 --prefix|--exec-prefix|--libdir|--includedir|--version)
161 if test -n "${do_query}"; then
170 do_check_versions=yes
171 min_version=${1#--min-version=}
174 do_check_versions=yes
175 max_version=${1#--max-version=}
178 do_check_versions=yes
179 exact_version=${1#--exact-version=}
182 # Compiler flag output
183 --cppflags) echo_cppflags=yes;;
184 --cxxflags) echo_cxxflags=yes;;
185 --ldflags) echo_ldflags=yes;;
186 --libs) echo_libs=yes;;
188 # Everything else is an error
189 *) show_usage; exit 1;;
194 # These have defaults filled in by the configure script but can also be
195 # overridden by environment variables or command line parameters.
196 prefix="${GMOCK_PREFIX:-@prefix@}"
197 exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}"
198 libdir="${GMOCK_LIBDIR:-@libdir@}"
199 includedir="${GMOCK_INCLUDEDIR:-@includedir@}"
201 # We try and detect if our binary is not located at its installed location. If
202 # it's not, we provide variables pointing to the source and build tree rather
203 # than to the install tree. We also locate Google Test using the configured
204 # gtest-config script rather than searching the PATH and our bindir for one.
205 # This allows building against a just-built gmock rather than an installed
208 this_relative_bindir=`dirname $0`
209 this_bindir=`cd ${this_relative_bindir}; pwd -P`
210 if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
211 # The path to the script doesn't end in the bindir sequence from Autoconf,
212 # assume that we are in a build tree.
213 build_dir=`dirname ${this_bindir}`
214 src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P`
216 # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
217 # should work to remove it, and/or remove libtool altogether, replacing it
218 # with direct references to the library and a link path.
219 gmock_libs="${build_dir}/lib/libgmock.la"
222 # We provide hooks to include from either the source or build dir, where the
223 # build dir is always preferred. This will potentially allow us to write
224 # build rules for generated headers and have them automatically be preferred
225 # over provided versions.
226 gmock_cppflags="-I${build_dir}/include -I${src_dir}/include"
229 # Directly invoke the gtest-config script used during the build process.
230 gtest_config="@GTEST_CONFIG@"
232 # We're using an installed gmock, although it may be staged under some
233 # prefix. Assume (as our own libraries do) that we can resolve the prefix,
234 # and are present in the dynamic link paths.
235 gmock_ldflags="-L${libdir}"
236 gmock_libs="-l${name}"
237 gmock_cppflags="-I${includedir}"
240 # We also prefer any gtest-config script installed in our prefix. Lacking
241 # one, we look in the PATH for one.
242 gtest_config="${bindir}/gtest-config"
243 if test ! -x "${gtest_config}"; then
244 gtest_config=`which gtest-config`
248 # Ensure that we have located a Google Test to link against.
249 if ! test -x "${gtest_config}"; then
250 echo "Unable to locate Google Test, check your Google Mock configuration" \
251 "and installation" >&2
253 elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then
254 echo "The Google Test found is not the same version as Google Mock was " \
259 # Add the necessary Google Test bits into the various flag variables
260 gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`"
261 gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`"
262 gmock_ldflags="${gmock_ldflags} `${gtest_config} --ldflags`"
263 gmock_libs="${gmock_libs} `${gtest_config} --libs`"
265 # Do an installation query if requested.
266 if test -n "$do_query"; then
268 prefix) echo $prefix; exit 0;;
269 exec-prefix) echo $exec_prefix; exit 0;;
270 libdir) echo $libdir; exit 0;;
271 includedir) echo $includedir; exit 0;;
272 version) echo $version; exit 0;;
273 *) show_usage; exit 1;;
277 # Do a version check if requested.
278 if test "$do_check_versions" = "yes"; then
279 # Make sure we didn't receive a bad combination of parameters.
280 test "$echo_cppflags" = "yes" && show_usage && exit 1
281 test "$echo_cxxflags" = "yes" && show_usage && exit 1
282 test "$echo_ldflags" = "yes" && show_usage && exit 1
283 test "$echo_libs" = "yes" && show_usage && exit 1
285 if test "$exact_version" != ""; then
286 check_versions $exact_version $exact_version
289 check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
294 # Do the output in the correct order so that these can be used in-line of
295 # a compiler invocation.
297 test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags"
298 test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags"
299 test "$echo_ldflags" = "yes" && output="$output $gmock_ldflags"
300 test "$echo_libs" = "yes" && output="$output $gmock_libs"