HPCW 3.0
Loading...
Searching...
No Matches
openblas.cmake
Go to the documentation of this file.
1# Copyright (c) 2020 - 2024 David Guibert
2# Copyright (c) 2024 Antoine Morvan
3# Copyright (c) 2024 Niclas Schroeter
4# All rights reserved.
5#
6# SPDX-License-Identifier: Apache-2.0
7
8set(OPENBLAS_BUILD_PARALLEL_LEVEL
9 "1"
10 CACHE STRING "Enable OpenBLAS parallel compilation")
11set_property(GLOBAL PROPERTY openblas_can_use_system TRUE)
12set_property(GLOBAL PROPERTY openblas_depends)
13
14set(openblas_cmake_args "" CACHE STRING "Custom CMake arguments for OpenBLAS")
15set(openblas_build_args "" CACHE STRING "Custom Make arguments for OpenBLAS")
16
17if(openblas_enabled)
18 if(USE_SYSTEM_blas OR USE_SYSTEM_openblas)
19 message(STATUS "blas/lapack: enabled (system installed)")
20 # set(BLA_VENDOR Intel10_64lp) set(BLA_F95 ON) #if ON tries to find the
21 # BLAS95/LAPACK95 interfaces
22
23 find_package(BLAS REQUIRED)
24 # BLAS_FOUND library implementing the BLAS interface is found
25 # BLAS_LINKER_FLAGS uncached list of required linker flags (excluding -l and
26 # -L). BLAS_LIBRARIES uncached list of libraries (using full path name) to
27 # link against to use BLAS (may be empty if compiler implicitly links BLAS)
28 # BLAS95_LIBRARIES uncached list of libraries (using full path name) to link
29 # against to use BLAS95 interface BLAS95_FOUND library implementing the
30 # BLAS95 interface is found
31
32 # https://cmake.org/cmake/help/latest/module/FindLAPACK.html
33 find_package(LAPACK REQUIRED)
34 # LAPACK_FOUND library implementing the LAPACK interface is found
35 # LAPACK_LINKER_FLAGS uncached list of required linker flags (excluding -l
36 # and -L). LAPACK_LIBRARIES uncached list of libraries (using full path
37 # name) to link against to use LAPACK LAPACK95_LIBRARIES uncached list of
38 # libraries (using full path name) to link against to use LAPACK95
39 # LAPACK95_FOUND library implementing the LAPACK95 interface is found
40 message(STATUS "BLAS: ${BLAS_FOUND}")
41 message(STATUS "LAPACK: ${LAPACK_FOUND}")
42
43 add_library(openblas UNKNOWN IMPORTED)
44 else()
45 if(NOT TARGET openblas)
46 message(STATUS "OpenBLAS: enabled (internally built)")
47
48 ExternalProject_Data_Add(
49 openblas
50 ${openblas_revision}
51
52 CMAKE_ARGS ${cmake_params}
53 -DCMAKE_INSTALL_LIBDIR:FILEPATH=lib
54 -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
55 -DCMAKE_INSTALL_PREFIX:FILEPATH=<INSTALL_DIR>
56 -DCMAKE_BUILD_TYPE:STRING=Release
57 -DBUILD_SHARED_LIBS:BOOL=ON
58 -DBUILD_STATIC_LIBS:BOOL=ON
59 -DUSE_THREAD:BOOL=ON
60 -DUSE_OPENMP:BOOL=ON
61 ${default_cmake_args}
62 ${openblas_cmake_args}
63 BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j${BUILD_PARALLEL_LEVEL} ${default_build_args} ${openblas_build_args}
64 INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} -j${BUILD_PARALLEL_LEVEL} PREFIX=<INSTALL_DIR> install
65 )
66
67 ExternalProject_Get_Property(openblas INSTALL_DIR)
68 set(OPENBLAS_DIR ${INSTALL_DIR})
69
70 set_if_not_present(ENV{CPATH} "$ENV{CPATH}" "${OPENBLAS_DIR}/include")
71 set_if_not_present(ENV{LIBRARY_PATH} "$ENV{LIBRARY_PATH}"
72 "${OPENBLAS_DIR}/lib")
73 set_if_not_present(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}"
74 "${OPENBLAS_DIR}/lib")
75
76 set(BLAS_FOUND ON)
77 set(BLAS_LIBRARIES "${OPENBLAS_DIR}/lib/libopenblas.so")
78 set(LAPACK_FOUND ON)
79 set(LAPACK_LIBRARIES "${OPENBLAS_DIR}/lib/libopenblas.so")
80
81 endif(NOT TARGET openblas)
82 endif()
83
84 message(STATUS "BLAS_LIBRARIES: ${BLAS_LIBRARIES}")
85 message(STATUS "BLAS95_LIBRARIES: ${BLAS95_LIBRARIES}")
86 message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
87 message(STATUS "LAPACK95_LIBRARIES: ${LAPACK95_LIBRARIES}")
88
89 string(REPLACE ";" " " BLAS_LIBRARIES_LIBS "${BLAS_LIBRARIES}")
90 string(REPLACE ";" " " BLAS95_LIBRARIES_LIBS "${BLAS95_LIBRARIES}")
91 string(REPLACE ";" " " LAPACK_LIBRARIES_LIBS "${LAPACK_LIBRARIES}")
92 string(REPLACE ";" " " LAPACK95_LIBRARIES_LIBS "${LAPACK95_LIBRARIES}")
93 message(STATUS "BLAS_LIBRARIES_LIBS: ${BLAS_LIBRARIES_LIBS}")
94endif(openblas_enabled)