summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroubert@google.com <roubert@google.com@ee073f10-1060-11df-b6a4-87a95322a99c>2012-10-05 09:04:05 +0000
committerroubert@google.com <roubert@google.com@ee073f10-1060-11df-b6a4-87a95322a99c>2012-10-05 09:04:05 +0000
commit84fec3c723f8c005ff34cecefcaeba38ee383778 (patch)
treee9121234cab82a5d92ace75c32b03582f0bfe61e
parent66c7f0ebf7b31f041067099e2bbef62fb6ab6f0b (diff)
downloadandroid_external_libphonenumbergoogle-84fec3c723f8c005ff34cecefcaeba38ee383778.tar.gz
android_external_libphonenumbergoogle-84fec3c723f8c005ff34cecefcaeba38ee383778.tar.bz2
android_external_libphonenumbergoogle-84fec3c723f8c005ff34cecefcaeba38ee383778.zip
CPP: Update CMake rules for Google Test to not require a pre-compiled static
library but be able to build the library from source as current practice is. Review URL: https://codereview.appspot.com/6602047 git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@531 ee073f10-1060-11df-b6a4-87a95322a99c
-rw-r--r--cpp/CMakeLists.txt4
-rw-r--r--tools/cpp/CMakeLists.txt27
-rw-r--r--tools/cpp/gtest.cmake47
3 files changed, 52 insertions, 26 deletions
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 7150659..80157c6 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -23,6 +23,8 @@ set (libphonenumber_VERSION_MINOR 1)
# Helper functions dealing with finding libraries and programs this library
# depends on.
+include (../tools/cpp/gtest.cmake)
+
function (print_error DESCRIPTION FILE)
message (FATAL_ERROR
"Can't find ${DESCRIPTION}: can't locate ${FILE}. Please read the README.")
@@ -82,7 +84,7 @@ if (NOT Boost_FOUND)
endif ()
include_directories (${Boost_INCLUDE_DIRS})
-find_required_library (GTEST gtest/gtest.h gtest "Google Test framework")
+find_or_build_gtest ()
if (${USE_RE2} STREQUAL "ON")
find_required_library (RE2 re2/re2.h re2 "Google RE2")
diff --git a/tools/cpp/CMakeLists.txt b/tools/cpp/CMakeLists.txt
index 3875a79..fafa846 100644
--- a/tools/cpp/CMakeLists.txt
+++ b/tools/cpp/CMakeLists.txt
@@ -21,32 +21,9 @@ project (generate_geocoding_data)
# Helper functions dealing with finding libraries and programs this library
# depends on.
-function (print_error DESCRIPTION FILE)
- message (FATAL_ERROR
- "Can't find ${DESCRIPTION}: can't locate ${FILE}. Please read the README.")
-endfunction ()
+include (gtest.cmake)
-# Find a library. If it has not been found, stop CMake with a fatal error
-# message.
-function (find_required_library NAME HEADER LIBRARY DESCRIPTION)
- # Check the header.
- find_path (${NAME}_INCLUDE_DIR ${HEADER})
- set (INCLUDE_DIR ${${NAME}_INCLUDE_DIR})
-
- if (${INCLUDE_DIR} STREQUAL "${INCLUDE_DIR}-NOTFOUND")
- print_error (${DESCRIPTION} ${HEADER})
- endif ()
- include_directories (${INCLUDE_DIR})
- # Check the binary.
- find_library (${NAME}_LIB ${LIBRARY})
- set (LIB ${NAME}_LIB)
-
- if (${LIB} STREQUAL "${LIB}-NOTFOUND")
- print_error (${DESCRIPTION} ${LIBRARY})
- endif ()
-endfunction (find_required_library)
-
-find_required_library (GTEST gtest/gtest.h gtest "Google Test framework")
+find_or_build_gtest ()
set (
SOURCES
diff --git a/tools/cpp/gtest.cmake b/tools/cpp/gtest.cmake
new file mode 100644
index 0000000..268329f
--- /dev/null
+++ b/tools/cpp/gtest.cmake
@@ -0,0 +1,47 @@
+# Copyright (C) 2012 The Libphonenumber Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Author: Fredrik Roubert
+
+# It used to be common to provide pre-compiled Google Test libraries, but this
+# practice is not recommended and is increasingly rare today:
+#
+# http://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog
+#
+# This helper function will either find a pre-compiled library or else find the
+# source code and add a library target to build the library from source.
+
+function (find_or_build_gtest)
+ # Find header files.
+ find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
+ if (${GTEST_INCLUDE_DIR} STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
+ message (FATAL_ERROR
+ "Can't find Google C++ Testing Framework: can't locate gtest/gtest.h. "
+ "Please read the README and also take a look at tools/cpp/gtest.cmake.")
+ endif ()
+ include_directories (${GTEST_INCLUDE_DIR})
+
+ # Check for a pre-compiled library.
+ find_library (GTEST_LIB gtest)
+ if (${GTEST_LIB} STREQUAL "GTEST_LIB-NOTFOUND")
+ # No pre-compiled library found, attempt building it from source.
+ find_path (GTEST_SOURCE_DIR src/gtest-all.cc
+ HINTS /usr/src/gtest /usr/local/src/gtest)
+ add_library (gtest STATIC ${GTEST_SOURCE_DIR}/src/gtest-all.cc)
+ include_directories (${GTEST_SOURCE_DIR})
+
+ set (GTEST_LIB gtest PARENT_SCOPE)
+ endif ()
+
+endfunction ()