[cmake-developers] Generator Expression self-references now allowed?

Brad King brad.king at kitware.com
Fri Feb 22 09:47:47 EST 2013


Steve,

Can you explain the need for 953def1e17f3bbba0aa42037ae15ced011d8fd2a:

    Fix DAG checker finding cycling dependencies.

    Before this patch, the following is reported falsely as a self-reference:

     target_link_libraries(empty2 LINK_PUBLIC empty3)
     target_link_libraries(empty3 LINK_PUBLIC empty2)

     add_custom_target(...
        -DINCLUDES=$<TARGET_PROPERTY:empty2,INTERFACE_INCLUDE_DIRECTORIES>
     )

    The reason is that the existing code assumed that all reading of
    include directories would be done through cmTarget::GetIncludeDirectories()
    and would therefore be initialized with a DagChecker. That is not the case
    if reading the property with an 'external' generator expression.

    As an unfortunate side-effect of backward compatibility for the
    LINK_INTERFACE_LIBRARIES property, self references can no longer be errors.

+      // It would be better to consider it an error for the foo target
+      // to have a INTERFACE_INCLUDE_DIRECTORIES which depends directly on its
+      // own INTERFACE_INCLUDE_DIRECTORIES property, but as the error of a
+      // target having itself in its own LINK_INTERFACE_LIBRARIES is 'allowed'
+      // and tested, and as the interface includes and defines are now based
+      // on the link interface, it breaks the CMakeOnly.LinkInterfaceLoop test.

?  The LinkInterfaceLoop test was added here:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8e756d2b

to cover a case that was accidentally allowed but that should not be used.
I'd rather not drop this great safety check for backward-compatibility
with bad code.

Can't you instead simply have the usage requirements skip appending
a target's own requirements to itself?  That way the resulting
generator expression would still not have a self reference.

-Brad



More information about the cmake-developers mailing list