Avoid duplicate linking to avoid Xcode 15 warnings

Ultimately, I have the “same” scenario that is described above with some small differences (information listed below). Things are not de-duplicated for me. I am on macOS 14.6.1 utilizing CMake v3.29.5, Clang 17.0.6, and OpenMPI 4.1.6 from MacPorts.

  1. libB and libC depend on libA.
  2. appZ depends on libA and libB.
    1. libA is on the link line twice.
  3. appY depends on libA, libB, and libC.
    1. libA is on the link line twice (so the transitive libraries appear to be de-duplicated by CMake).

I haven’t found any link specification order that results in de-duplication. This differs from the example in the aforementioned issue.

  • I tried libA before libB and libC.
  • I tried libA after libB and libC.

What do I need to do? The MR points to the following, although the poster seems to indicate it doesn’t work. Is this syntax correct?

cmake_policy(SET CMP0156 NEW)
set(CMAKE_C_LINK_LIBRARIES_PROCESSING ORDER=REVERSE UNICITY=ALL)
set(CMAKE_CXX_LINK_LIBRARIES_PROCESSING ORDER=REVERSE UNICITY=ALL)