How do you handle recursive dependencies in CMake
<p>Say I have packages A, B, and C. Package B uses package A and package C uses package B. I create shared libraries.</p>

<p>So in package B I do something like</p>

<pre><code>    find_package(A)
    ...
    if(${A_FOUND})
    target_link_libraries(B ${A_LIBRARIES})
    endif()
</code></pre>

<p>and in package C I do</p>

<pre><code>    find_package(B)
    ...
    if(${B_FOUND})
    target_link_libraries(C ${B_LIBRARIES})
    endif()

    add_executable(main main.cpp)
    target_link_libraries(main C)
</code></pre>

<p>where ${B_LIBRARIES} contains only B. The compiler will now complain</p>

<pre><code>    /usr/bin/ld: cannot find -lA
    collect2: error: ld returned 1 exit status
</code></pre>

<p>as long as A is installed in a place that is not in the link_directories of C. I was wondering what is the correct way of handling this. For me using <code>find_package(A)</code> in C (which would work) doesn't seem to be the nice. For me especially, because I don't know in advance if B depends on A or not. It might also depend on a different package.</p>