FindGoogleTest.cmake 4.64 KB
Newer Older
Mike Kremer's avatar
Mike Kremer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# Locate and configure the Google Test libraries.
#
# Defines the following variable:
#
#   GTEST_FOUND - Found the Google Test libraries
#   GTEST_INCLUDE_DIRS - The directories needed on the include paths
#   GTEST_LIBRARIES - The libraries to link to test executables
#   GTEST_MAIN_LIBRARIES - The libraries to link for automatic main() provision
#
#   Copyright 2008 Chandler Carruth
#
#   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.

if(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
  set(GTEST_FOUND true)
else(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)
  set(GTEST_PREFIX "" CACHE PATH "Installation prefix for Google Test")
  if(GTEST_PREFIX)
    find_path(_GTEST_INCLUDE_DIR "gtest/gtest.h"
      PATHS "${GTEST_PREFIX}/include"
      NO_DEFAULT_PATH)
    find_library(_GTEST_LIBRARY gtest
      PATHS "${GTEST_PREFIX}/lib"
      NO_DEFAULT_PATH)
    find_library(_GTEST_MAIN_LIBRARY gtest_main
      PATHS "${GTEST_PREFIX}/lib"
      NO_DEFAULT_PATH)
38 39 40 41
	  
    if ( _GTEST_LIBRARY )
      get_filename_component(_GTEST_LIBRARY_DIR ${_GTEST_LIBRARY} PATH CACHE )
    endif()
Mike Kremer's avatar
Mike Kremer committed
42 43 44
  else(GTEST_PREFIX)
    find_path(_GTEST_INCLUDE_DIR "gtest/gtest.h"
      PATHS
Jan Möbius's avatar
Jan Möbius committed
45
      ~/sw/gtest-1.8.0/include
46 47
      ~/sw/gtest-1.7.0/include
      ~/sw/gtest/include     
Jan Möbius's avatar
Jan Möbius committed
48
      /ACG/acgdev/gcc-x86_64/gtest/include
Mike Kremer's avatar
Mike Kremer committed
49 50
      /opt/local/include
      /usr/local/include
51 52 53
      /usr/include
      "C:/libs/win32/gtest/include"
      NO_DEFAULT_PATH )
Mike Kremer's avatar
Mike Kremer committed
54 55
    find_library(_GTEST_LIBRARY gtest
      PATHS
Jan Möbius's avatar
Jan Möbius committed
56
      ~/sw/gtest-1.8.0/lib
57
      ~/sw/gtest-1.7.0/lib
Mike Kremer's avatar
Mike Kremer committed
58
      ~/sw/gtest/lib
Jan Möbius's avatar
Jan Möbius committed
59
      /ACG/acgdev/gcc-x86_64/gtest/lib
Mike Kremer's avatar
Mike Kremer committed
60 61
      /opt/local/lib
      /usr/local/lib
Jan Möbius's avatar
Jan Möbius committed
62
      /usr/include
63 64
      "C:/libs/win32/gtest/lib"
      NO_DEFAULT_PATH )
Mike Kremer's avatar
Mike Kremer committed
65 66
    find_library(_GTEST_MAIN_LIBRARY gtest_main
      PATHS
Jan Möbius's avatar
Jan Möbius committed
67
      ~/sw/gtest-1.8.0/lib
68
      ~/sw/gtest-1.7.0/lib
Mike Kremer's avatar
Mike Kremer committed
69
      ~/sw/gtest/lib
Jan Möbius's avatar
Jan Möbius committed
70
      /ACG/acgdev/gcc-x86_64/gtest/lib
Mike Kremer's avatar
Mike Kremer committed
71 72
      /opt/local/lib
      /usr/local/lib
Jan Möbius's avatar
Jan Möbius committed
73
      /usr/include
74 75
      "C:/libs/win32/gtest/lib"
      NO_DEFAULT_PATH )
Mike Kremer's avatar
Mike Kremer committed
76 77 78 79 80 81 82 83 84 85 86

     if ( _GTEST_LIBRARY )
        get_filename_component(_GTEST_LIBRARY_DIR ${_GTEST_LIBRARY} PATH CACHE )
     endif()

  endif(GTEST_PREFIX)
  if(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
    set(GTEST_FOUND true)
    set(GTEST_INCLUDE_DIRS ${_GTEST_INCLUDE_DIR} CACHE PATH
      "Include directories for Google Test framework")
	  
Jan Möbius's avatar
Jan Möbius committed
87
    if ( NOT WIN32 )
Mike Kremer's avatar
Mike Kremer committed
88 89 90 91
      set(GTEST_LIBRARIES ${_GTEST_LIBRARY} CACHE FILEPATH
        "Libraries to link for Google Test framework")
      set(GTEST_MAIN_LIBRARIES ${_GTEST_MAIN_LIBRARY} CACHE FILEPATH
        "Libraries to link for Google Test automatic main() definition")
Jan Möbius's avatar
Jan Möbius committed
92 93 94 95
      set(GTEST_MAIN_LIBRARY ${_GTEST_MAIN_LIBRARY} CACHE FILEPATH
        "Libraries to link for Google Test automatic main() definition")
    else()
      set(GTEST_LIBRARIES "optimized;gtest;debug;gtestd" CACHE FILEPATH
Mike Kremer's avatar
Mike Kremer committed
96 97 98
        "Libraries to link for Google Test framework")
      set(GTEST_MAIN_LIBRARIES "optimized;gtest_main;debug;gtest_maind" CACHE FILEPATH
        "Libraries to link for Google Test automatic main() definition")
Jan Möbius's avatar
Jan Möbius committed
99 100 101
      set(GTEST_MAIN_LIBRARY "optimized;gtest_main;debug;gtest_maind" CACHE FILEPATH
        "Libraries to link for Google Test automatic main() definition")
    endif()
Mike Kremer's avatar
Mike Kremer committed
102
	
Jan Möbius's avatar
Jan Möbius committed
103 104 105 106
    # Macro required to use google test with vs2012
    if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*"  )
       add_definitions(-D_VARIADIC_MAX=10)
    endif()
107

Jan Möbius's avatar
Jan Möbius committed
108 109
    set(GTEST_LIBRARY ${_GTEST_LIBRARY} CACHE FILEPATH
          "GTest Libraries")
Mike Kremer's avatar
Mike Kremer committed
110 111 112 113 114 115 116 117 118 119 120 121
    set(GTEST_LIBRARY_DIR ${_GTEST_LIBRARY_DIR} CACHE FILEPATH
      "Library dir containing Google Test libraries")
    mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES GTEST_MAIN_LIBRARIES GTEST_LIBRARY_DIR )
    if(NOT GoogleTest_FIND_QUIETLY)
      message(STATUS "Found Google Test: ${GTEST_LIBRARIES}")
    endif(NOT GoogleTest_FIND_QUIETLY)
  else(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
    if(GoogleTest_FIND_REQUIRED)
      message(FATAL_ERROR "Could not find the Google Test framework")
    endif(GoogleTest_FIND_REQUIRED)
  endif(_GTEST_INCLUDE_DIR AND _GTEST_LIBRARY AND _GTEST_MAIN_LIBRARY)
endif(GTEST_INCLUDE_DIRS AND GTEST_LIBRARIES AND GTEST_MAIN_LIBRARIES)