Developer Guide

Developer Guide for Intel® oneAPI Math Kernel Library Windows*

ID 766692
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

CMake Config for oneMKL

If you want to integrate oneMKL into your CMake projects, starting with the Intel® oneAPI Math Kernel Library (oneMKL) 2021.3 release, MKLConfig.cmake is provided as part of the package and installation. MKLConfig.cmake supports all oneMKL configurations, compilers, and runtimes, as the oneMKL product itself. Help/usage is provided in the top section of MKLConfig.cmake.

Example

my_test/
  |_ build/                <-- Out-of-source build directory
  |_ CMakeLists.txt        <-- User side project's CMakeLists.txt
  |_ app.c                 <-- Source file that uses oneMKL API

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
enable_testing()
project(oneMKL_Example LANGUAGES C)
find_package(MKL CONFIG REQUIRED)
#message(STATUS "${MKL_IMPORTED_TARGETS}") #Provides available list of targets based on input
add_executable(myapp app.c)

target_compile_options(myapp PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS>)
target_include_directories(myapp PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(myapp PUBLIC $<LINK_ONLY:MKL::MKL>)

add_test(NAME mytest COMMAND myapp)
if(MKL_ENV)
  set_tests_properties(mytest PROPERTIES ENVIRONMENT "${MKL_ENV}")
endif()

Command line

# Source the compiler and runtime beforehand
build$ cmake .. -G Ninja -DCMAKE_C_COMPILER=icl
build$ cmake --build . && ctest
# If MKLConfig.cmake is not located by CMake automatically, its path can be manually specified by MKL_DIR:
build$ cmake .. -G Ninja -DCMAKE_C_COMPILER=icl -DMKL_DIR=<Full path to MKLConfig.cmake>
NOTE:

Ninja and NMake Makefiles are supported on Windows. Other CMake Generators may work but are not guaranteed.

When the Ninja build system is in use, Ninja 1.10.2 or later is required for Fortran support.