Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how OpenBLAS library is searched #39

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})