Skip to content

Commit

Permalink
Try to fix BLAS++ and LAPACK++ installation so that the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
weslleyspereira committed Sep 7, 2023
1 parent 9ff5e49 commit 35c78b7
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 83 deletions.
51 changes: 14 additions & 37 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
fail-fast: false
matrix:
sharedlib: [ ON, OFF ]
lapackpp: [ ON, OFF ]
lapackpp: [ OFF ]

steps:

Expand All @@ -179,7 +179,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y cmake gfortran
# sudo apt purge libopenblas-dev liblapack-dev
sudo apt purge libopenblas-dev liblapack-dev
- name: Configure CMake
run: >
Expand All @@ -199,42 +199,19 @@ jobs:
- name: Check dependencies of BLAS++
working-directory: ${{github.workspace}}/build
run: |
if [[ ${{ matrix.sharedlib }} == 'ON' ]]; then
blaspp_blas=$(ldd lib/libblaspp.so | grep libblas.so | { grep -v grep || true; })
if [[ -z $blaspp_blas || "$blaspp_blas" != *"${{github.workspace}}/build"* ]]; then
echo "BLAS++ dependency to BLAS is not correct!"
echo "ldd lib/libblaspp.so:"
ldd lib/libblaspp.so
exit 1
fi
else
blaspp_blas=$(cat lib/blaspp/blasppConfig.cmake | grep -lblas | { grep -v grep || true; })
if [[ -z $blaspp_blas ]]; then
echo "BLAS++ dependency to BLAS is not correct!"
echo "We could not find -lblas in lib/blaspp/blasppConfig.cmake"
exit 1
fi
blaspp_blas=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/libblas" | { grep -v grep || true; })
echo "blaspp_blas: $blaspp_blas"
if [[ -z $blaspp_blas ]]; then
echo "BLAS++ dependency to BLAS is not correct!"
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in lib/cmake/blaspp/blasppConfig.cmake"
exit 1
fi
- name: Check dependencies when LAPACK++ is ON
if: ${{ matrix.lapackpp == 'ON' }}
working-directory: ${{github.workspace}}/build
run: |
if [[ ${{ matrix.sharedlib }} == 'ON' ]]; then
lapackpp_lapack=$(ldd lib/liblapackpp.so | grep liblapack.so | { grep -v grep || true; })
if [[ -z $lapackpp_lapack || $lapackpp_lapack != *"${{github.workspace}}/build"* ]]; then
echo "LAPACK++ dependency to LAPACK is not correct!"
echo "ldd lib/liblapackpp.so:"
ldd lib/liblapackpp.so
exit 1
fi
else
lapackpp_lapack=$(cat lib/lapackpp/lapackppConfig.cmake | grep -llapack | { grep -v grep || true; })
if [[ -z $lapackpp_lapack ]]; then
echo "LAPACK++ dependency to LAPACK is not correct!"
echo "We could not find -llapack in lib/lapackpp/lapackppConfig.cmake"
exit 1
fi
blaspp_lapack=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/liblapack" | { grep -v grep || true; })
echo "blaspp_lapack: $blaspp_lapack"
if [[ -z $blaspp_lapack ]]; then
echo "BLAS++ dependency to LAPACK is not correct!"
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in lib/cmake/blaspp/blasppConfig.cmake"
exit 1
fi
- name: Install
Expand Down
149 changes: 103 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.11)
# VERSION 3.11: FetchContent

project(LAPACK Fortran C)

Expand All @@ -10,6 +11,19 @@ set(
${LAPACK_MAJOR_VERSION}.${LAPACK_MINOR_VERSION}.${LAPACK_PATCH_VERSION}
)

# Dependencies on other projects
include(FetchContent)
FetchContent_Declare(
blaspp
GIT_REPOSITORY https://github.com/icl-utk-edu/blaspp
GIT_TAG f8f983d5b45a8f366aae41fbe9888b14cbae20f8 # v2023.08.25
)
FetchContent_Declare(
lapackpp
GIT_REPOSITORY https://github.com/icl-utk-edu/lapackpp
GIT_TAG 62680a16a9aba2a426e3d089dd13e18bfd140c74 # v2023.08.25
)

# Allow setting a prefix for the library names
set(CMAKE_STATIC_LIBRARY_PREFIX "lib${LIBRARY_PREFIX}")
set(CMAKE_SHARED_LIBRARY_PREFIX "lib${LIBRARY_PREFIX}")
Expand Down Expand Up @@ -472,38 +486,86 @@ function(_display_cpp_implementation_msg name)
message(STATUS "For support ${name}++ related question, please email: [email protected]")
message(STATUS "----------------")
endfunction()
if (BLAS++)
_display_cpp_implementation_msg("BLAS")
include(ExternalProject)
ExternalProject_Add(blaspp
URL https://bitbucket.org/icl/blaspp/downloads/blaspp-2020.10.02.tar.gz
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -Dbuild_tests=OFF -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/blaspp-prefix/src/blaspp
BUILD_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" ${CMAKE_COMMAND} --build .
INSTALL_COMMAND ${CMAKE_COMMAND} -E env PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" ${CMAKE_COMMAND} --install .
)
ExternalProject_Add_StepDependencies(blaspp build ${BLAS_LIBRARIES})

if (BLAS++ OR LAPACK++)

if (BLAS++)
_display_cpp_implementation_msg("BLAS")
endif()

# Check if population has already been performed
FetchContent_GetProperties(blaspp)
if(NOT blaspp_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(blaspp)
endif()

# For static builds, we may need to link against a Fortran library
set(BLAS_Fortran_LIB "")
if (NOT BLAS_FOUND AND NOT BUILD_SHARED_LIBS)
if (CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(BLAS_Fortran_LIB ";-lgfortran")
else()
# TODO: This is incomplete. Fill in the other cases.
set(BLAS_Fortran_LIB "")
endif()
endif()

# Adds target blaspp
add_custom_target( blaspp ALL
COMMAND ${CMAKE_COMMAND}
-B "${blaspp_BINARY_DIR}"
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
-D blas_libraries_cached=""
"-DBLAS_LIBRARIES=\"$<IF:$<BOOL:${BLAS_FOUND}>,${BLAS_LIBRARIES},$<TARGET_FILE:${BLASLIB}>>${BLAS_Fortran_LIB}\""
-D lapack_libraries_cached=""
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
-D build_tests=OFF
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
COMMAND ${CMAKE_COMMAND}
--build "${blaspp_BINARY_DIR}"
--target install
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
COMMENT "Building BLAS++"
)

# Set up dependencies
if(NOT BLAS_FOUND)
add_dependencies(blaspp ${BLASLIB})
endif()
if(NOT LATESTLAPACK_FOUND)
add_dependencies(blaspp ${LAPACKLIB})
endif()
endif()

if (LAPACK++)
message (STATUS "linking lapack++ against ${LAPACK_LIBRARIES}")
_display_cpp_implementation_msg("LAPACK")
include(ExternalProject)
if (BUILD_SHARED_LIBS)
ExternalProject_Add(lapackpp
URL https://bitbucket.org/icl/lapackpp/downloads/lapackpp-2020.10.02.tar.gz
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DLAPACK_LIBRARIES=${LAPACK_LIBRARIES} -Dbuild_tests=OFF -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp
BUILD_COMMAND ${CMAKE_COMMAND} -E env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" ${CMAKE_COMMAND} --build .
INSTALL_COMMAND ${CMAKE_COMMAND} -E env PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" ${CMAKE_COMMAND} --install .
)
else ()
# FIXME this does not really work as the libraries list gets converted to a semicolon-separated list somewhere in the lapack++ build files
ExternalProject_Add(lapackpp
URL https://bitbucket.org/icl/lapackpp/downloads/lapackpp-2020.10.02.tar.gz
CONFIGURE_COMMAND env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${CMAKE_BINARY_DIR}/lib LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DLAPACK_LIBRARIES="${PROJECT_BINARY_DIR}/lib/liblapack.a -lgfortran" -Dbuild_tests=OFF -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp
BUILD_COMMAND env LIBRARY_PATH=$ENV{LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib LIB_SUFFIX="" ${CMAKE_COMMAND} --build .
INSTALL_COMMAND ${CMAKE_COMMAND} -E env PREFIX=${PROJECT_BINARY_DIR} LIB_SUFFIX="" ${CMAKE_COMMAND} --install .
)

# Check if population has already been performed
FetchContent_GetProperties(lapackpp)
if(NOT lapackpp_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(lapackpp)
endif()
ExternalProject_Add_StepDependencies(lapackpp build blaspp ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})

# Adds target lapackpp
add_custom_target( lapackpp ALL
COMMAND ${CMAKE_COMMAND}
-B "${lapackpp_BINARY_DIR}"
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
-D lapack_libraries_cached=""
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
-D build_tests=OFF
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
COMMAND ${CMAKE_COMMAND}
--build "${lapackpp_BINARY_DIR}"
--target install
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
COMMENT "Building LAPACK++"
)

# Set up dependencies
add_dependencies(lapackpp blaspp)
endif()

# --------------------------------------------------
Expand Down Expand Up @@ -617,41 +679,36 @@ if (LAPACK++)
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
)
install(
DIRECTORY "${PROJECT_BINARY_DIR}/lapackpp-prefix/src/lapackpp/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING REGEX "\\.(h|hh)$"
)
write_basic_package_version_file(
"lapackppConfigVersion.cmake"
VERSION 2020.10.02
VERSION 2023.08.25
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfigVersion.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
)

endif()
if (BLAS++)
install(
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "libblaspp.(a|so)$"
)
write_basic_package_version_file(
"blasppConfigVersion.cmake"
VERSION 2020.10.02
VERSION 2023.08.25
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/blaspp/blasppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/blaspp/blasppConfigVersion.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
)
install(
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "libblaspp.(a|so)$"
)
install(
DIRECTORY "${PROJECT_BINARY_DIR}/blaspp-prefix/src/blaspp/include/"
DIRECTORY "${PROJECT_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING REGEX "\\.(h|hh)$"
)
Expand Down

0 comments on commit 35c78b7

Please sign in to comment.