llnl / llnl/blt

add a blt_find_package() macro?

Open
#284 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
296
Forks
66
Avg merge
1h 3m
Merged PRs (30d)
1

Description

I recently had some good clean fun getting blas and lapack packages properly linked into our code project. As part of this, I eventually just make `FindBlas.cmake` and `FindLAPACK.cmake` files that are essentially identical aside from the name. It seems that cmake has a somewhat inconsistent interface with its `find_package()` macro as the various implementation of the FindXYZ (i.e. `FindMPI`, `FindBLAS`, `FindLAPACK`) do not have a similar interface. By this I mean they use different input variables to find what you are looking for, and they set different output variables. Anyways, the files that I made seem like they might be useful for making a `blt_find_package()` macro. Here is the BLAS one:

```
if( NOT BLAS_DIR )

find_package(BLAS REQUIRED)

list( GET BLAS_LIBRARIES 0 BLAS_LIB0 )
get_filename_component( BLAS_LIBRARY_DIR ${BLAS_LIB0} DIRECTORY CACHE )
get_filename_component( BLAS_DIR ${BLAS_LIBRARY_DIR} DIRECTORY CACHE )
set( BLAS_INCLUDE_DIR ${BLAS_DIR}/include CACHE PATH "" )

else()
find_path( BLAS_INCLUDE_DIR
NAMES blas.h cblas.h mkl_blas.h mkl_cblas.h
PATHS ${BLAS_DIR}/include
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)

if( NOT DEFINED BLAS_LIBRARY_NAMES )
set( BLAS_LIBRARY_NAMES "blas;cblas;libmkl_rt.so" CACHE STRING "")
endif()

find_library( BLAS_LIBRARIES
NAMES ${BLAS_LIBRARY_NAMES}
PATHS ${BLAS_DIR}/lib ${BLAS_DIR}/lib64
NO_DEFAULT_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH)

list( GET BLAS_LIBRARIES 0 BLAS_LIB0 )
get_filename_component( BLAS_LIBRARY_DIR ${BLAS_LIB0} DIRECTORY CACHE )

endif()

find_package_handle_standard_args( BLAS
DEFAULT_MSG
BLAS_DIR
BLAS_INCLUDE_DIR
BLAS_LIBRARY_DIR
BLAS_LIBRARIES
)

set(BLAS_LIBRARY_NAMES "" CACHE STRING "" FORCE)
foreach( lib ${BLAS_LIBRARIES} )
get_filename_component( libname ${lib} NAME )
list( APPEND BLAS_LIBRARY_NAMES ${libname} )
endforeach()

message( " BLAS_FOUND = ${BLAS_FOUND}" )
message( " BLAS_DIR = ${BLAS_DIR}" )
message( " BLAS_INCLUDE_DIR = ${BLAS_INCLUDE_DIR}" )
message( " BLAS_LIBRARY_DIR = ${BLAS_LIBRARY_DIR}" )
message( " BLAS_LIBRARIES = ${BLAS_LIBRARIES}" )
message( " BLAS_LIBRARY_NAMES = ${BLAS_LIBRARY_NAMES}" )
message( " BLAS_LINKER_FLAGS = ${BLAS_LINKER_FLAGS}" )
```

possible inputs are:
```
PACKAGE_NAME
PACKAGE_DIR
INCLUDE_PATHS
INCLUDE_NAMES
LIBRARY_PATHS
LIBRARY_NAMES
```
outputs are all listed in the message at the end.

So let me know if you think this is useful and within scope of blt.
@cyrush @white238 @kennyweiss

Contributor guide

Open the contributing guide

Research direction

Review the proposed FindBlas.cmake and FindLAPACK.cmake patterns, then compare them with BLT's existing CMake package-finding entry points. Resolve the macro's supported inputs and outputs, and define completion as an agreed, generalized blt_find_package() design with coverage for the described package-discovery cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.