• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2012 The Libphonenumber Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Author: Fredrik Roubert
16
17# It used to be common to provide pre-compiled Google Test libraries, but this
18# practice is not recommended and is increasingly rare today:
19#
20# http://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog
21#
22# This helper function will either find a pre-compiled library or else find the
23# source code and add a library target to build the library from source.
24
25function (find_or_build_gtest)
26  # Find header files.
27  find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
28  if (${GTEST_INCLUDE_DIR} STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
29    message (FATAL_ERROR
30      "Can't find Google C++ Testing Framework: can't locate gtest/gtest.h. "
31      "Please read the README and also take a look at tools/cpp/gtest.cmake.")
32  endif ()
33  include_directories (${GTEST_INCLUDE_DIR})
34
35  # Check for a pre-compiled library.
36  find_library (GTEST_LIB gtest)
37  if (${GTEST_LIB} STREQUAL "GTEST_LIB-NOTFOUND")
38    # No pre-compiled library found, attempt building it from source.
39    find_path (GTEST_SOURCE_DIR src/gtest-all.cc
40               HINTS /usr/src/gtest /usr/local/src/gtest)
41    add_library (gtest STATIC ${GTEST_SOURCE_DIR}/src/gtest-all.cc)
42    include_directories (${GTEST_SOURCE_DIR})
43
44    set (GTEST_LIB gtest PARENT_SCOPE)
45  endif ()
46
47endfunction ()
48