diff options
author | Chase Douglas <chase.douglas@canonical.com> | 2012-03-08 14:18:39 -0800 |
---|---|---|
committer | Chase Douglas <chase.douglas@canonical.com> | 2012-03-16 15:23:42 -0700 |
commit | 71f006cadac2bc7f249965896d898143d7592f12 (patch) | |
tree | 271b6a7491d58e3bce07be1d225d47b0697ee59e /m4/gtest.m4 | |
parent | d02b5095dbe69b695034242a978c489aaef61109 (diff) |
Build gtest as part of the project
Google Test does not recommend using precompiled gtest libraries. See:
http://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog
This change modifies the build system so the examples build the gtest
and xorg-gtest libraries and link against the locally built libraries
instead of any other precompiled libraries on the system. It uses the
same compiler flags to compile everything so the C++ One-Definition Rule
is not broken.
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
Reviewed-By: Christopher Halse Rogers <christopher.halse.rogers@canonical.com>
Diffstat (limited to 'm4/gtest.m4')
-rw-r--r-- | m4/gtest.m4 | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/m4/gtest.m4 b/m4/gtest.m4 index cd41b21..2de334c 100644 --- a/m4/gtest.m4 +++ b/m4/gtest.m4 @@ -1,24 +1,63 @@ -# Checks whether the gtest library is available on the system -# Allows for adjusting the include and library path. -# Sets have_gtest=yes if the library is present and -# reports the compiler and linker flags in -# GTEST_CXXFLAGS AND GTEST_LDFLAGS, respectively. -AC_DEFUN([AC_CHECK_GTEST], +# Copyright (C) 2012 Canonical, Ltd. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Checks whether the gtest source is available on the system. Allows for +# adjusting the include and source path. Sets have_gtest=yes if the source is +# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and +# source location respectively. +AC_DEFUN([CHECK_GTEST], [ AC_ARG_WITH([gtest-include-path], - [AS_HELP_STRING([--with-gtest-include-path], - [location of the Google test headers, defaults to /usr/include])], - [GTEST_CPPFLAGS="-I$withval"]) + [AS_HELP_STRING([--with-gtest-include-path], + [location of the Google test headers])], + [GTEST_CPPFLAGS="-I$withval"]) + + AC_ARG_WITH([gtest-source-path], + [AS_HELP_STRING([--with-gtest-source-path], + [location of the Google test sources, defaults to /usr/src/gtest])], + [GTEST_SOURCE="$withval"], + [GTEST_SOURCE="/usr/src/gtest"]) + + GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE" - AC_ARG_WITH([gtest-lib-path], - [AS_HELP_STRING([--with-gtest-lib-path], [location of the Google test libraries])], - [GTEST_LDFLAGS="-L$withval -lpthread"], - [GTEST_LDFLAGS='-lpthread']) + AC_LANG_PUSH([C++]) - AC_LANG_PUSH(C++) + tmp_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $GTEST_CPPFLAGS" - AC_CHECK_LIB([gtest], [main], [:], [:], [$GTEST_LDFLAGS]) + AC_CHECK_HEADER([gtest/gtest.h]) + + CPPFLAGS="$tmp_CPPFLAGS" AC_LANG_POP -]) # AC_CHECK_GTEST + AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc] + [$GTEST_SOURCE/src/gtest_main.cc], + [have_gtest_source=yes], + [have_gtest_source=no]) + + AS_IF([test "x$ac_cv_header_gtest_gtest_h" = xyes -a \ + "x$have_gtest_source" = xyes], + [have_gtest=yes] + [AC_SUBST(GTEST_CPPFLAGS)] + [AC_SUBST(GTEST_SOURCE)], + [have_gtest=no]) +]) # CHECK_GTEST |