blob: d687237f5548b75b481049b67568aa7cf14b13c7 [file] [log] [blame]
set(AVIF_LOCAL_GTEST_GIT_TAG v1.14.0)
set(GTest_FOUND ON CACHE BOOL "")
set(GTEST_INCLUDE_DIRS ${AVIF_SOURCE_DIR}/ext/googletest/googletest/include)
set(GTEST_LIB_FILENAME
${AVIF_SOURCE_DIR}/ext/googletest/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
)
set(GTEST_MAIN_LIB_FILENAME
${AVIF_SOURCE_DIR}/ext/googletest/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}
)
if(EXISTS ${GTEST_INCLUDE_DIRS}/gtest/gtest.h AND EXISTS ${GTEST_LIB_FILENAME} AND EXISTS ${GTEST_MAIN_LIB_FILENAME})
message(STATUS "libavif(AVIF_GTEST=LOCAL): compiled library found in ext/googletest")
add_library(GTest::gtest STATIC IMPORTED)
set_target_properties(GTest::gtest PROPERTIES IMPORTED_LOCATION "${GTEST_LIB_FILENAME}" AVIF_LOCAL ON)
if(TARGET Threads::Threads)
target_link_libraries(GTest::gtest INTERFACE Threads::Threads)
endif()
target_include_directories(GTest::gtest INTERFACE "${GTEST_INCLUDE_DIRS}")
add_library(GTest::gtest_main STATIC IMPORTED)
target_link_libraries(GTest::gtest_main INTERFACE GTest::gtest)
set_target_properties(GTest::gtest_main PROPERTIES IMPORTED_LOCATION "${GTEST_MAIN_LIB_FILENAME}" AVIF_LOCAL ON)
else()
message(STATUS "libavif(AVIF_GTEST=LOCAL): compiled library not found in ext/googletest; using FetchContent")
if(EXISTS "${AVIF_SOURCE_DIR}/ext/googletest")
message(STATUS "libavif(AVIF_GTEST=LOCAL): ext/googletest found; using as FetchContent SOURCE_DIR")
set(FETCHCONTENT_SOURCE_DIR_GOOGLETEST "${AVIF_SOURCE_DIR}/ext/googletest")
message(CHECK_START "libavif(AVIF_LOCAL_GTEST): configuring googletest")
else()
message(CHECK_START "libavif(AVIF_LOCAL_GTEST): fetching and configuring googletest")
endif()
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG ${AVIF_LOCAL_GTEST_GIT_TAG}
GIT_SHALLOW ON
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK ON CACHE BOOL "" FORCE)
avif_fetchcontent_populate_cmake(googletest)
set_target_properties(gtest gtest_main PROPERTIES AVIF_LOCAL ON)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
message(CHECK_PASS "complete")
endif()