FindBLAS failing with Intel Parallel Studio
The changes introduced in commit 6bd9cee6 (merge request !4246 (merged)) seem to break compatibility of FindBLAS with Intel MKL provided by the Intel compiler suites in Linux. Tested with Intel Parallel Studio XE 2020 with the following script
cmake_minimum_required(VERSION 3.16)
project(TestBlas)
find_package(BLAS)
and invocation
cmake -D BLA_VENDOR=Intel10_64lp .
The library that is not being found is libiomp5.
Background
While Intel Parallel Studio does set the environment variable MKLROOT
to the subfolder containing MKL, this folder does not contain the compiler run-time libraries, of which at least libiomp5 is needed with threaded MKL. Before the above-mentioned commit, the search directory with the needed thread library was added by means of CMAKE_C_IMPLICIT_LINK_DIRECTORIES
, which is populated from the environment variable LIBRARY_PATH
defined by the package. However, this seems now unintentionally broken.
Actually, there are two issues with FindBLAS, the first one new, the other existed even before. Both of them are related to specifics of the CMake language.
Issue 1: Attempt to append to a macro argument
In the macro CHECK_BLAS_LIBRARIES
, an attempt is made to append strings to the variable _addlibdir
, which is a parameter of the macro. Whether this is documented somewhere in CMake or a bug, the APPEND action does not have any effect whatsoever. Only when I introduce a replacement local variable, say
set(_addlibdirs ${_addlibdir})
and operate on that one, the following APPEND works. This is well reproducible with minimal script like this
cmake_minimum_required(VERSION 3.16)
project(TestListAppend)
macro(my_macro param)
set(var ${param})
message("var before = ${var}")
message("param before = ${param}")
list(APPEND param "world")
list(APPEND var "world")
message("param after = ${param}")
message("var after = ${var}")
endmacro()
my_macro("Hello")
which prints
var before = Hello
param before = Hello
param after = Hello
var after = Hello;world
illustrating that while APPEND to a normal variable works well, it does not do anything when applied to macro parameter. If this is normal in CMake, then the macro CHECK_BLAS_LIBRARIES
should be fixed accordingly.
Issue 2: Environment variable fails to dereference [NO LONGER RELEVANT]
The script also tries to add the contents of LD_LIBRARY_PATH
to the list of directories to be searched. However, even if the above point is solved, the result of the statement
list(APPEND _addlibdir ENV LD_LIBRARY_PATH)
seems to be just addition of the literal string "ENV" and "LD_LIBRARY_PATH" to _addlibdir
. Obviously, this is not the desired outcome. A minimal reproducible example would be
cmake_minimum_required(VERSION 3.16)
project(TestENV)
set(mylist)
list(APPEND mylist ENV PATH)
message("${mylist}")
which simply prints
ENV;PATH
rather than the content of the environment variable PATH
. If this is expected, I think that the non-functional code should not be there at all.