Skip to content

Commit

Permalink
More changes to improve flags BLAS++ and LAPACK++
Browse files Browse the repository at this point in the history
  • Loading branch information
weslleyspereira committed Sep 8, 2023
1 parent 35c78b7 commit 66905e9
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 56 deletions.
66 changes: 48 additions & 18 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ jobs:
strategy:
fail-fast: false
matrix:
sharedlib: [ ON, OFF ]
sharedlib: [ OFF, ON ]
lapackpp: [ OFF ]
optblas: [ OFF, ON ]
optlapack: [ OFF, ON ]
exclude:
- optblas: ON
optlapack: ON

steps:

Expand All @@ -174,12 +179,9 @@ jobs:
uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3

- name: Install the Basics
# Adding some noise to the system: libopenblas-dev liblapack-dev should not
# be linked to BLAS++ or LAPACK++.
run: |
sudo apt update
sudo apt install -y cmake gfortran
sudo apt purge libopenblas-dev liblapack-dev
sudo apt install -y cmake gfortran libopenblas-dev
- name: Configure CMake
run: >
Expand All @@ -192,26 +194,54 @@ jobs:
-D BUILD_SHARED_LIBS:BOOL=${{ matrix.sharedlib }}
-D BLAS++:BOOL=ON
-D LAPACK++:BOOL=${{ matrix.lapackpp }}
-D USE_OPTIMIZED_BLAS:BOOL=${{ matrix.optblas }}
-D USE_OPTIMIZED_LAPACK:BOOL=${{ matrix.optlapack }}
- name: Build
run: cmake --build build --config ${{env.BUILD_TYPE}}

- name: Check dependencies of BLAS++
- name: Check dependencies of BLAS++ on BLAS
working-directory: ${{github.workspace}}/build
run: |
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
configFile="lib/cmake/blaspp/blasppConfig.cmake"
if [[ ${{ matrix.optblas }} == 'ON' ]]; then
if grep -q "openblas" $configFile; then
echo "BLAS++ dependency to BLAS is correct."
else
echo "CMake could not find openblas in $configFile:"
cat $configFile
exit 1
fi
else
if grep -q "${{github.workspace}}/build/lib/libblas" $configFile; then
echo "BLAS++ dependency to BLAS is correct."
else
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in $configFile:"
cat $configFile
exit 1
fi
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
- name: Check dependencies of BLAS++ on LAPACK
working-directory: ${{github.workspace}}/build
run: |
configFile="lib/cmake/blaspp/blasppConfig.cmake"
if [[ ${{ matrix.optblas }} == 'ON' ]]; then
if grep -q "openblas" $configFile; then
echo "BLAS++ dependency to LAPACK is correct."
else
echo "CMake could not find openblas in $configFile:"
cat $configFile
exit 1
fi
else
if grep -q "${{github.workspace}}/build/lib/liblapack" $configFile; then
echo "BLAS++ dependency to LAPACK is correct."
else
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in $configFile:"
cat $configFile
exit 1
fi
fi
- name: Install
Expand Down
122 changes: 84 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,21 +512,55 @@ if (BLAS++ OR LAPACK++)
endif()

# Adds target blaspp
add_custom_target( blaspp ALL
add_custom_target( blaspp ALL DEPENDS blaspp-cmd )
add_custom_command( OUTPUT blaspp-cmd
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
COMMENT "Building BLAS++" )

# Set up information about the BLAS and LAPACK libraries
if(NOT BLAS_FOUND)
if(NOT LATESTLAPACK_FOUND)
add_custom_command( OUTPUT blaspp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${blaspp_BINARY_DIR}"
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>" )
else()
add_custom_command( OUTPUT blaspp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${blaspp_BINARY_DIR}"
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
endif()
else()
if(NOT LATESTLAPACK_FOUND)
add_custom_command( OUTPUT blaspp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${blaspp_BINARY_DIR}"
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
else()
add_custom_command( OUTPUT blaspp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${blaspp_BINARY_DIR}"
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
endif()
endif()

# Setup remaining configuration options and installation
add_custom_command( OUTPUT blaspp-cmd APPEND
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}
-B "${blaspp_BINARY_DIR}"
-D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}"
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
-D blas_libraries_cached=""
-D lapack_libraries_cached=""
-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
Expand All @@ -549,19 +583,36 @@ if (LAPACK++)
endif()

# Adds target lapackpp
add_custom_target( lapackpp ALL
COMMAND ${CMAKE_COMMAND}
add_custom_target( lapackpp ALL DEPENDS lapackpp-cmd )
add_custom_command( OUTPUT lapackpp-cmd
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
COMMENT "Building LAPACK++" )

# Set up information about the LAPACK library
if(NOT LATESTLAPACK_FOUND)
add_custom_command( OUTPUT lapackpp-cmd APPEND
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}
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
else()
add_custom_command( OUTPUT lapackpp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${lapackpp_BINARY_DIR}"
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
endif()

# Setup remaining configuration options and installation
add_custom_command( OUTPUT lapackpp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${lapackpp_BINARY_DIR}"
-D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}"
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
-D lapack_libraries_cached=""
-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
Expand Down Expand Up @@ -675,14 +726,14 @@ install(FILES
)
if (LAPACK++)
install(
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
)
write_basic_package_version_file(
"lapackppConfigVersion.cmake"
VERSION 2023.08.25
COMPATIBILITY AnyNewerVersion
install(
DIRECTORY "${lapackpp_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING REGEX "\\.(h|hh)$"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
Expand All @@ -692,23 +743,18 @@ if (LAPACK++)

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 2023.08.25
COMPATIBILITY AnyNewerVersion
)
install(
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 "${PROJECT_BINARY_DIR}/include/"
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "libblaspp.(a|so)$"
)
install(
DIRECTORY "${blaspp_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING REGEX "\\.(h|hh)$"
)
Expand Down

0 comments on commit 66905e9

Please sign in to comment.