ceph/cmake/modules/FindGMock.cmake
Kefu Chai 6f231ee864 cmake: link against gtest in a better way
* add FindGMock.cmake which allows user to use the libgtest-dev
  shipped by distro
* add GMock::{GMock,Main}, GTest::{GTest,Main} targets to be
  compatible with FindGTest.cmake and FindGMock.cmake, which
  expose the built libraries with properties adhered to
  them. so the consumer of them can import them in a better way.
* update tests to drop the commands like
  set_target_properties(foo PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}),
  as they are already linked against gmock and gtest.

Signed-off-by: Kefu Chai <kchai@redhat.com>
2018-08-17 15:21:27 +08:00

22 lines
638 B
CMake

find_path(GMock_INCLUDE_DIR NAMES gmock/gmock.h)
find_library(GMock_GMock_LIBRARY NAMES gmock)
find_library(GMock_Main_LIBRARY NAMES gmock_main)
find_package_handle_standard_args(GMock
REQUIRED_VARS
GMock_GMock_LIBRARY
GMock_Main_LIBRARY
GMock_INCLUDE_DIR)
if(GMock_FOUND)
foreach(c GMock Main)
if(NOT TARGET GMock::${c})
add_library(GMock::${c} UNKNOWN IMPORTED)
set_target_properties(GMock::${c} PROPERTIES
IMPORTED_LOCATION "${GMock_${c}_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GMock_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
endif()
endforeach()
endif()