icl-utk-edu / blaspp

BLAS++ is a C++ wrapper around CPU and GPU BLAS (basic linear algebra subroutines), developed as part of the SLATE project.
https://icl.utk.edu/slate/
BSD 3-Clause "New" or "Revised" License
66 stars 23 forks source link

CMake defines after find_package not documented #24

Open NAThompson opened 1 year ago

NAThompson commented 1 year ago

I can easily find instructions on how to build blaspp, and succeeded in doing so. However, how to reference it in another CMake-managed project does not appear to be documented.

I have resorted to the following technique to see what CMake variables are defined after a successful find_package(blaspp REQUIRED):

cmake_minimum_required (VERSION 3.25.0)
project(try_blaspp)
get_directory_property(_vars_before VARIABLES)
find_package(blaspp REQUIRED)
get_directory_property(_vars VARIABLES)

list(REMOVE_ITEM _vars _vars_before ${_vars_before})
foreach(_var IN LISTS _vars)
    message(STATUS "${_var} = ${${_var}}")
endforeach()
add_executable(run main.cpp)
# This line will fail:
#target_include_directories(run PRIVATE ${blaspp_INCLUDE_DIRS})

This prints:

-- CONFIG_FILES = /opt/slate/lib/blaspp/blasppTargets-noconfig.cmake
-- _DIR = /opt/slate/lib/blaspp
-- blaspp_CONFIG = /opt/slate/lib/blaspp/blasppConfig.cmake
-- blaspp_CONSIDERED_CONFIGS = /opt/slate/lib/blaspp/blasppConfig.cmake
-- blaspp_CONSIDERED_VERSIONS = 2022.07.00
-- blaspp_FOUND = 1
-- blaspp_VERSION = 2022.07.00
-- blaspp_VERSION_COUNT = 3
-- blaspp_VERSION_MAJOR = 2022
-- blaspp_VERSION_MINOR = 7
-- blaspp_VERSION_PATCH = 0
-- blaspp_VERSION_TWEAK = 0
-- blaspp_cblas_found = true
-- blaspp_cblas_include = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers
-- blaspp_cblas_libraries =
-- blaspp_defines = -DBLAS_FORTRAN_ADD_;-DBLAS_HAVE_ACCELERATE;-DBLAS_COMPLEX_RETURN_ARGUMENT;-DBLAS_HAVE_F2C;-DBLAS_HAVE_ACCELERATE_CBLAS_H;-DBLAS_HAVE_CBLAS
-- blaspp_libraries = -framework Accelerate;OpenMP::OpenMP_CXX
-- blaspp_use_cuda = false
-- blaspp_use_hip = false
-- blaspp_use_openmp = true

I expected that one of these CMake variables should be set to /opt/slate/include, so that I can write (say)

target_include_directories(run PRIVATE ${blaspp_INCLUDE_DIRS})

yet blaspp_INCLUDE_DIRS does not appear to be defined, and hence the compile step fails:

main.cpp:3:10: fatal error: 'blas.hh' file not found
#include <blas.hh>
         ^~~~~~~~~
1 error generated.

If I hardcode the path to the blas include dir, I fail to link, necessitating hard coded path to the blas library, which again I cannot see in the defined CMake variables:

...
target_include_directories(run PRIVATE /opt/slate/include)
target_link_libraries(run PRIVATE /opt/slate/lib/libblaspp.dylib)
mgates3 commented 1 year ago

Thanks for the feedback. We will add documentation on how to integrate BLAS++ into an application. However, I don't understand the issue that you are having. It seems to be too complicated. Simply doing this works in the example directory:

#-------------------------------------------------------------------------------
find_package( blaspp REQUIRED )

#--------------------
add_executable(
    example_gemm
    example_gemm.cc
)
target_link_libraries(
    example_gemm
    blaspp
)

I don't find it necessary with CMake packages to explicitly get the path to their include directory — CMake should use it automatically.