try_compile to use include directory from imported target

I am trying to figure out during configure time if the BLAS I find (ubuntu-20.04) is from Intel MKL, or some other vendor.

  find_package(BLAS REQUIRED)

  try_compile(
    test_use_mkl ${CMAKE_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/test_include_mkl.cpp
    LINK_LIBRARIES BLAS::BLAS OUTPUT_VARIABLE test_out)
  message(STATUS "Using Intel MKL: ${test_use_mkl } ${test_out}")

During configuration I get:

– Found BLAS: /usr/lib/x86_64-linux-gnu/libmkl_intel_lp64.so;/usr/lib/x86_64-linux-gnu/libmkl_intel_thread.so;/usr/lib/x86_64-linux-gnu/libmkl_core.so;/usr/lib/x86_64-linux-gnu/libiomp5.so;-lpthread;-lm;-ldl
– Using Intel MKL: FALSE Change Dir: /home/lloyd/src/VegaFEM/CIBuild/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_fdefb/fast && /usr/bin/make -f CMakeFiles/cmTC_fdefb.dir/build.make CMakeFiles/cmTC_fdefb.dir/build
make[1]: Entering directory ‘/home/lloyd/src/VegaFEM/CIBuild/CMakeFiles/CMakeTmp’
Building CXX object CMakeFiles/cmTC_fdefb.dir/test_include_mkl.cpp.o
/usr/bin/c++ -std=c++14 -o CMakeFiles/cmTC_fdefb.dir/test_include_mkl.cpp.o -c /home/lloyd/src/VegaFEM/cmake/test_include_mkl.cpp
/home/lloyd/src/VegaFEM/cmake/test_include_mkl.cpp:1:10: fatal error: mkl_blas.h: No such file or directory

How can I use try_compile with an imported target? Can I get the include directories from the target BLAS::BLAS?

I think the issue is that FindBlas does not actually set the include dirs, so the imported target BLAS::BLAS is not enough. I added the lines:

  foreach(lib ${BLAS_LIBRARIES})
    if (${lib} MATCHES "mkl")
      set(USE_INTEL_MKL ON)
    endif()
  endforeach()
  if(USE_INTEL_MKL )
    find_path(BLAS_INCLUDE_DIRS mkl_cblas.h PATHS /usr/include /usr/local/include /usr/include/mkl REQUIRED)
  endif()

to find the header locations, and skip the try_compile.

try_compile does not support imported targets AFAIK.

There is the INTERFACE_INCLUDE_DIRECTORIES property, but this will not get any transitive requirements from other dependencies.