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