CMake 3.19 Policy CMP0111 always warns for an INTERFACE IMPORTED targets
With the introduction of the new policy CMP0111 in CMake 3.19, cmake is supposed to warn when the IMPORTED_LOCATION property isn't set on a IMPORTED library or executable target according to the documentation at https://cmake.org/cmake/help/git-stage/policy/CMP0111.html
Now when the IMPORTED target is also an INTERFACE target, the IMPORTED_LOCATION property cannot be set(because there is no artifact on disk.
Now looking at the code in cmTarget.cxx linked here the logic checks if the target type is not an INTERFACE and skips setting the result
variable containing the IMPORTED_LOCATION.
The logic then checks if the result
variable is empty and if so warns when policy CMP0111 is enabled without checking against the target type not being INTERFACE at that point
Adding a INTERFACE IMPORTED target that is attached to a MODULE library is enough to trigger the warning.
cmake_minimum_required(VERSION 3.19)
project(InterfaceImportedCMP0111Warn)
add_library(Foo INTERFACE IMPORTED GLOBAL)
target_include_directories(Foo INTERFACE .)
add_library(ModuleLib MODULE source.cpp)
target_link_libraries(ModuleLib PUBLIC Foo)
A dummy source.cpp
file is also needed to attach to the module library in order to allow it to be a valid target. It can be empty file.
Other Notes: In order to reproduce this issue the cmVisualStudio10TargetGenerator::AddLibraries
function needs to have the generator target return Unknown for the GetManagedType call which occurs when the Library Type > cmStateEnums::SHARED_LIBRARY
This is the reason why the add_library target in the repro is using a MODULE library.