[CMake] cmake policy CMP0022 error

Stephen Kelly steveire at gmail.com
Fri Oct 25 02:40:41 EDT 2013


Clinton Stimpson wrote:

> 
> I have a target where I do this:
> SET_TARGET_PROPERTIES(mytarget PROPERTIES LINK_INTERFACE_LIBRARIES "")
> to hide 3rd party libraries from the link interface.
> 
> When I do
> if(APPLE)
>   CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
> endif()
> I get an error at generate time.
> 
> This is different than my previous experiences with cmake policies.  Based
> on past experiences, I expected to see a warning if I had
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
> but used CMake 2.8.12 which introduced CMP0022.

You might have wrong understanding of policies.

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6d50d0197a5

Your use of cmake_minimum_required(VERSION 2.8.12) requests the non-backward 
compatible behavior.

> 
> But in this case, I don't see a warning.
> The error I get with
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
> is:
> CMake Error in .../CMakeLists.txt:
>   Target "mytarget" has policy CMP0022 enabled, but also has old-style
>   LINK_INTERFACE_LIBRARIES properties populated, but it was exported
>   without the EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style
>   properties
> 
> 
> When I read the output from cmake --help-policy CMP0022, its not clear to
> me why I'm getting the error.

2.8.12 introduced a INTERFACE_LINK_LIBRARIES property, which should be used 
instead of LINK_INTERFACE_LIBRARIES. The policy makes the 
INTERFACE_LINK_LIBRARIES property ignored until it is set to NEW.

So when you do this:

 SET_TARGET_PROPERTIES(mytarget PROPERTIES LINK_INTERFACE_LIBRARIES "")

you could consider doing this instead:

 SET_TARGET_PROPERTIES(mytarget PROPERTIES INTERFACE_LINK_LIBRARIES "")

or just use 

 target_link_libraries(mytarget PRIVATE hiddenlib)

which has the same effect. PRIVATE means 'hide from the link interface'.

Thanks,

Steve.




More information about the CMake mailing list