CMake: Allow the user to set GTEST_SRC_DIR when cross compiling

Previously, we first set GTEST_SRC_DIR as a CACHE variable, which
allows the user to set it to a different value if they prefer.
Then later, if we're cross compiling, we'd override it to a
different value. But when overriding it, we'd lose the value that
the user set.

Instead set up the default value in a different CMake variable,
and set that as default value when setting up the CACHE variable.

This way, we have varying defaults, while still respecting the
user specified value, if any.

Change-Id: I7e571b6251a4d08da02c119a0aad2b1c14585e26
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/5444428
Reviewed-by: Frank Barchard <fbarchard@chromium.org>
This commit is contained in:
Martin Storsjö 2024-04-11 11:04:35 +03:00 committed by Frank Barchard
parent 38fa3ce2c9
commit 5fb6c8cbe3

View File

@ -146,10 +146,11 @@ endif()
if(UNIT_TEST)
find_library(GTEST_LIBRARY gtest)
if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND")
set(GTEST_SRC_DIR /usr/src/gtest CACHE STRING "Location of gtest sources")
set(GTEST_SRC_DIR_DEFAULT /usr/src/gtest)
if (CMAKE_CROSSCOMPILING)
set(GTEST_SRC_DIR third_party/googletest/src/googletest)
set(GTEST_SRC_DIR_DEFAULT third_party/googletest/src/googletest)
endif()
set(GTEST_SRC_DIR ${GTEST_SRC_DIR_DEFAULT} CACHE STRING "Location of gtest sources")
if(EXISTS ${GTEST_SRC_DIR}/src/gtest-all.cc)
message(STATUS "building gtest from sources in ${GTEST_SRC_DIR}")
set(gtest_sources ${GTEST_SRC_DIR}/src/gtest-all.cc)