Usage of INTERFACE_LINK_LIBRARIES with namespaced targets

I try to use the Intel MKL, which has some pkg-config configuration files, with CMake. When I try to link the MKL statically in my project some linker options will be stored in the INTERFACE_LINK_LIBRARIES property. When I use this namespaced target in the target_link_libraries command the linker option will be set, which causes the compilation to fail.

Is there a way to tell CMake that the linker options should be used in my project when using the namespaced target?

The CMakeLists.txt currently looks like this:

cmake_minimum_required(VERSION 3.16)
project(intel-fft
    LANGUAGES C CXX
    )

set(source_files
    "main.c"
    )
set(executable_name test_fft)
 
# the `pkg_check_modules` function is created with this call
find_package(PkgConfig REQUIRED)

# these calls create special `PkgConfig::<MODULE>` variables
pkg_check_modules(INTEL_MKL
    REQUIRED
    IMPORTED_TARGET
    mkl-static-ilp64-iomp
    )
    
add_executable(${executable_name}
    ${source_files}
    )

set_target_properties(${executable_name}
    PROPERTIES
        C_STANDARD 11
        CXX_STANDARD 14
        CXX_STANDARD_REQUIRED ON
        CXX_EXTENSIONS OFF
    )

get_property(INTERFACE_LINK_OPTIONS
    TARGET PkgConfig::INTEL_MKL
    PROPERTY INTERFACE_LINK_OPTIONS
    )

target_link_libraries(${executable_name}
    PUBLIC
        PkgConfig::INTEL_MKL
        ${INTERFACE_LINK_OPTIONS}  # This option is needed because it sets some linker options
        # ${INTEL_MKL_LDFLAGS_OTHER} <- This would also work
    )

These are the options which are stored in INTERFACE_LINK_OPTIONS:

-Wl,--start-group;/opt/intel/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/libmkl_intel_ilp64.a;/opt/intel/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/libmkl_intel_thread.a;/opt/intel/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/libmkl_core.a;-Wl,--end-group

I don’t understand your problem.

Why do you extract the INTERFACE_LINK_OPTIONS property from target PkgConfig::INTEL_MKL to re-inject them in the command target_link_directories?

The command target_link_libraries(${executable_name} PUBLIC PkgConfig::INTEL_MKL) is enough to propagate interface link options from target PkgConfig::INTEL_MKL to your target.

Unfortunately it’s not enough to just add PkgConfig::INTEL_MKL when I use the static library. I have to explicitly add ${INTEL_MKL_LDFLAGS_OTHER} (which is equal to the INTERFACE_LINK_OPTIONS property) to the target_link_libraries command, otherwise the required linker flags would not be set.

The question is if this behavior is expected or if this is perhaps a CMake bug?

I cannot reproduce your problem. Using exactly same CMakeLists.txt I get the expected result: no need to manually specify the link options.

What is the exact version of the cmake tool ?

As stated by @marc.chevrier it should be enough to:
target_link_libraries(${executable_name} PUBLIC PkgConfig::INTEL_MKL)
to drag in the necesserary INTERFACE_LINK_OPTIONS from PkgConfig::INTEL_MKL.
but you said:
…when I use the static library. I have to explicitly add…
does this mean that when you use shared lib it works?

The INTERFACE_LINK_OPTIONS you have shown only refer to static lib.

Yes it works for the shared library version because the linker flags will be set in the INTERFACE_LINK_LIBRARIES property only. The property INTERFACE_LINK_OPTIONS is empty when I use the shared library.

@marc.chevrier did reproduce your use case (see Usage of INTERFACE_LINK_LIBRARIES with namespaced targets) may be you could share a non-working stripped down example with us.