Skip to content

Commit

Permalink
Improve how OpenBLAS library is searched (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardob90 authored Jan 10, 2024
1 parent e491c57 commit e41936e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ cython_debug/

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

Expand All @@ -211,3 +210,6 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

# CMake builds
cmake-build*/
3 changes: 3 additions & 0 deletions cleedpy/cleed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Where to find CMake modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Workaround for Apple Clang
# Disables the warning "implicit declaration of function '...' is invalid in C99"
if(APPLE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
Expand Down
65 changes: 65 additions & 0 deletions cleedpy/cleed/cmake/FindOpenBLAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# cmake/Modules/FindOpenBLAS.cmake
SET(Open_BLAS_INCLUDE_SEARCH_PATHS
/usr/include
/usr/include/openblas
/usr/include/openblas-base
/usr/local/include
/usr/local/include/openblas
/usr/local/include/openblas-base
/usr/local/opt/openblas/include
/opt/OpenBLAS/include
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/include
$ENV{OpenBLAS_HOME}/include/openblas
)

SET(Open_BLAS_LIB_SEARCH_PATHS
/lib/
/lib/openblas-base
/lib64/
/usr/lib
/usr/lib/openblas-base
/usr/lib64
/usr/local/lib
/usr/local/lib64
/usr/local/opt/openblas/lib
/opt/OpenBLAS/lib
$ENV{OpenBLAS}
$ENV{OpenBLAS}/lib
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/lib
)

FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})

SET(OpenBLAS_FOUND ON)

# Check include files
IF(NOT OpenBLAS_INCLUDE_DIR)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS include. Turning OpenBLAS_FOUND off")
ENDIF()

# Check libraries
IF(NOT OpenBLAS_LIB)
SET(OpenBLAS_FOUND OFF)
MESSAGE(STATUS "Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off")
ENDIF()

IF (OpenBLAS_FOUND)
IF (NOT OpenBLAS_FIND_QUIETLY)
MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIB}")
MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}")
ENDIF (NOT OpenBLAS_FIND_QUIETLY)
ELSE (OpenBLAS_FOUND)
IF (OpenBLAS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find OpenBLAS")
ENDIF (OpenBLAS_FIND_REQUIRED)
ENDIF (OpenBLAS_FOUND)

MARK_AS_ADVANCED(
OpenBLAS_INCLUDE_DIR
OpenBLAS_LIB
OpenBLAS
)
16 changes: 5 additions & 11 deletions cleedpy/cleed/src/libmat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ file(GLOB LIBMAT_SOURCES "mat*.c")
# Define the library from the collected source files
add_library(mat SHARED ${LIBMAT_SOURCES})

# Find BLAS/LAPACK
find_package(BLAS REQUIRED)
# Find BLAS
find_package(OpenBLAS REQUIRED)
include_directories(${OpenBLAS_INCLUDE_DIR})

# Include directories for BLAS/LAPACK
find_file(BLAS_HEADER "cblas.h" HINTS ${CMAKE_PREFIX_PATH})
if(BLAS_HEADER)
get_filename_component(BLAS_INCLUDE_DIR ${BLAS_HEADER} DIRECTORY)
include_directories(${BLAS_INCLUDE_DIR})
endif()

# Link libmat with BLAS/LAPACK
target_link_libraries(mat ${BLAS_LIBRARIES})
# Link libmat with BLAS
target_link_libraries(mat ${OpenBLAS_LIB})

0 comments on commit e41936e

Please sign in to comment.