find_path(
  GTEST_INCLUDE_DIRS
  NAMES
  gtest
  PATHS
  include)

find_library(
  GTEST_LIBRARIES
  NAMES
  gtest
  libgtest
  PATHS
  lib)

find_library(
  GTEST_MAIN_LIBRARIES
  NAMES
  gtest_main
  libgtest_main
  PATHS
  lib)

SET(GTEST_BOTH_LIBRARIES ${GTEST_MAIN_LIBRARIES} ${GTEST_LIBRARIES})

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(GTEST REQUIRED_VARS GTEST_LIBRARIES GTEST_MAIN_LIBRARIES GTEST_BOTH_LIBRARIES GTEST_INCLUDE_DIRS)

if(NOT TARGET GTest::GTest)
    find_package(Threads)
    add_library(GTest::GTest INTERFACE IMPORTED)
    set_property(TARGET GTest::GTest PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIRS})
    set_property(TARGET GTest::GTest PROPERTY INTERFACE_LINK_LIBRARIES ${GTEST_LIBRARIES} Threads::Threads)
    set_property(TARGET GTest::GTest PROPERTY INTERFACE_COMPILE_DEFINITIONS ${CONAN_COMPILE_DEFINITIONS_GTEST})
endif()

if(NOT TARGET GTest::Main)
    add_library(GTest::Main INTERFACE IMPORTED)
    set_property(TARGET GTest::Main PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIRS})
    set_property(TARGET GTest::Main PROPERTY INTERFACE_LINK_LIBRARIES ${GTEST_MAIN_LIBRARIES} GTest::GTest)
    set_property(TARGET GTest::Main PROPERTY INTERFACE_COMPILE_DEFINITIONS ${CONAN_COMPILE_DEFINITIONS_GTEST})
endif()
