FindGTest/GoogleTest issues with CMP0057
GoogleTest.cmake
attempts to use the IN_LIST
operator, but does not control CMP0057, resulting in an error if the user doesn't enable it explicitly. You can reproduce the error with the following snippet:
cmake_minimum_required(VERSION 3.1)
find_package(GTest REQUIRED)
add_executable(foo_test foo_test.cpp)
target_link_libraries(foo_test ${GTEST_MAIN_LIBRARIES} ${GTEST_LIBRARIES})
gtest_add_tests(foo_test "" AUTO)
With CMake 3.10, that snippet yields the error
CMake Warning (dev) at /opt/clion/bin/cmake/share/cmake-3.10/Modules/GoogleTest.cmake:265 (if):
Policy CMP0057 is not set: Support new IN_LIST if() operator. Run "cmake
--help-policy CMP0057" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
This is especially problematic because in older versions of CMake, FindGTest
didn't call into GoogleTest
, so this error didn't manifest. I tried with CMake 3.5, and the above code worked fine. So, this issue is badly breaking forwards-compatibility!
I think the fix would be to just stick a
cmake_policy(SET CMP0057 NEW)
at the top of GoogleTest
.
Edited by Jamie Smith