install(EXPORT): Generated fooTargets.cmake file sets old policy version
Using CMake 3.17.0 on FreeBSD (it's not in the ports tree yet, testing locally), when I build Catch2 it produces a Catch2Targets.cmake
file as part of the build. That targets file starts with:
# Generated by CMake
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
(This comes from ./Source/cmExportFileGenerator.cxx
) So policies are reset to quite ancient. The file goes on with (like 28)
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
When used (e.g. through find_package(Catch2)
) with CMake 3.17, this yields the following warning (dev):
CMake Warning (dev) at /usr/local/lib/cmake/Catch2/Catch2Targets.cmake:28 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Quoted variables like "" will no longer be dereferenced when the policy is
set to NEW. Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
/usr/local/lib/cmake/Catch2/Catch2Config.cmake:33 (include)
Setting the policy in the calling CMakeLists isn't effective, because policies get reset. I realise it's just a warning, for developers, but it's annoying and impossible to squash and turns previously innocuous find_package()
calls into something scary.