CMake with "RelWithDebInfo" build type links to debug libraries
Summary
The MKLConfig.cmake file included with MKL causes debug libraries to be linked when the "RelWithDebInfo" build type is used. This results in linker errors. This happens due to lines like this: https://github.com/oneapi-src/oneMKL/blob/57c5f2b064b444d782ca6ea7be97929c07fe4e43/cmake/mkl/MKLConfig.cmake#L513
Version
I have experienced this on version 2023.0 but looking at the current "Develop" branch it looks like the same behavior should still be present.
Environment
- TBB 2021.8.0 (installed with vcpkg)
- Windows 10
- MSVC 17.6.3
Steps to reproduce
The "Broken-RelWithDebInfo" configuration of this example project reproduces the issue. If you have vcpkg installed and a "VCPKG_ROOT" environment variable set then the project should automatically install TBB. Since MKL has MKL_THREADING set to "tbb_thread" it will link to "mkl_tbb_threadd.lib" which will cause linker errors like this:
...\MSVC-Release\mkl_tbb_threadd.lib(_mdd_tbb_driver.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MD_DynamicRelease' in myProject.cpp.obj
...\MSVC-Release\LINK : fatal error LNK1104: cannot open file 'tbb12_debug.lib'
Observed behavior
When "CMAKE_BUILD_TYPE" is "RelWithDebInfo" the MKL CMake config file will cause the "MKL::MKL" target to link with debug libraries. This causes a number of linker errors to appear since the rest of the project will be using release builds.
Expected behavior
When using a build type of "RelWithDebInfo" MKL should behave the same as when the build type is "Release
I have updated to MKL 2024.0 and while the MKLConfig.cmake file has been moved to oneAPI\mkl\2024.0\lib\cmake\mkl and its contents have been changed this problem is still there. I am able to fix the file for my purposes by replacing all instances of "Debug|DebInfo" with "Debug"
Hi @nickanthony-dgl thanks for reporting this issue! We've just merged the, it will be available in oneMKL 2024.2 release. Let me know if you need it sooner, we can update the copy of MKLConfig.cmake in this opensource project as well.