LINK_LIBRARY generator expression with WHOLE_ARCHIVE doesn't work with exported/imported targets

Context of the Problem

We are creating a DPDK package using CMake that exports targets with a namespace prefix (e.g., dpdk::libeal, dpdk::libmempool_ring). Some DPDK libraries (for example, mempool_ring and mempool_stack) require linking with the --whole-archive flag (or -Wl,--whole-archive), otherwise symbols from these libraries are not included in the final executable.

The Problem

We are trying to use the CMake generator expression $<LINK_LIBRARY:WHOLE_ARCHIVE,...>, but it doesn’t work properly for exported targets:

  1. When using local target names (before export):

    cmake

    target_link_libraries(some_target INTERFACE 
        "$<LINK_LIBRARY:WHOLE_ARCHIVE,libmempool_ring>"
    )
    

    After exporting the package, when targets receive the dpdk:: prefix, this expression starts interpreting libmempool_ring as a library name (not a target) and tries to link with -llibmempool_ring.

  2. When using $<TARGET_NAME:...>:

    cmake

    target_link_libraries(some_target INTERFACE 
        "$<LINK_LIBRARY:WHOLE_ARCHIVE,$<TARGET_NAME:libmempool_ring>>"
    )
    

    In this case, CMake correctly resolves the library path (the correct path to librte_mempool_ring.a), but the --whole-archive flags are not added. The $<TARGET_NAME:...> expression appears to return the path to the library file, not a reference to the target, which causes the loss of information about the need for WHOLE_ARCHIVE linking.

Expected Behavior

When linking, something like this should be generated:

text

-Wl,--whole-archive /path/to/librte_mempool_ring.a -Wl,--no-whole-archive

Actual Behavior

  1. In the first case, an incorrect linker flag is generated: -llibmempool_ring

  2. In the second case, only the library path is generated without the --whole-archive flags

Questions

  1. How to properly use $<LINK_LIBRARY:WHOLE_ARCHIVE,...> for targets that will be exported with a namespace prefix?

  2. Is there a workaround for this issue in current CMake versions (4.2.1)?

  3. Is this a known issue/limitation in CMake?

CMake Version and Environment

  • CMake 4.2.1 (minimum version 3.30 specified in the project)

  • Compiler: GCC/G++

  • Linker: GNU ld or gold

  • OS: Linux

Your explanations are not clear enough. Please, provide a snippet showing the problem.