gmock-config.in 11 KB

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