Skip to content

Commit 680cfd8

Browse files
More changes to improve flags BLAS++ and LAPACK++
1 parent 35c78b7 commit 680cfd8

File tree

2 files changed

+118
-57
lines changed

2 files changed

+118
-57
lines changed

.github/workflows/cmake.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ jobs:
162162
strategy:
163163
fail-fast: false
164164
matrix:
165-
sharedlib: [ ON, OFF ]
165+
sharedlib: [ OFF, ON ]
166166
lapackpp: [ OFF ]
167+
optblas: [ OFF, ON ]
168+
optlapack: [ OFF, ON ]
169+
exclude:
170+
- optblas: ON
171+
optlapack: ON
167172

168173
steps:
169174

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

176181
- name: Install the Basics
177-
# Adding some noise to the system: libopenblas-dev liblapack-dev should not
178-
# be linked to BLAS++ or LAPACK++.
179182
run: |
180183
sudo apt update
181-
sudo apt install -y cmake gfortran
182-
sudo apt purge libopenblas-dev liblapack-dev
184+
sudo apt install -y cmake gfortran libopenblas-dev
183185
184186
- name: Configure CMake
185187
run: >
@@ -192,26 +194,39 @@ jobs:
192194
-D BUILD_SHARED_LIBS:BOOL=${{ matrix.sharedlib }}
193195
-D BLAS++:BOOL=ON
194196
-D LAPACK++:BOOL=${{ matrix.lapackpp }}
197+
-D USE_OPTIMIZED_BLAS:BOOL=${{ matrix.optblas }}
198+
-D USE_OPTIMIZED_LAPACK:BOOL=${{ matrix.optlapack }}
195199
196200
- name: Build
197201
run: cmake --build build --config ${{env.BUILD_TYPE}}
198202

199-
- name: Check dependencies of BLAS++
203+
- name: Check dependencies of BLAS++ on BLAS and LAPACK
200204
working-directory: ${{github.workspace}}/build
201205
run: |
202-
blaspp_blas=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/libblas" | { grep -v grep || true; })
203-
echo "blaspp_blas: $blaspp_blas"
204-
if [[ -z $blaspp_blas ]]; then
205-
echo "BLAS++ dependency to BLAS is not correct!"
206-
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in lib/cmake/blaspp/blasppConfig.cmake"
207-
exit 1
208-
fi
209-
blaspp_lapack=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/liblapack" | { grep -v grep || true; })
210-
echo "blaspp_lapack: $blaspp_lapack"
211-
if [[ -z $blaspp_lapack ]]; then
212-
echo "BLAS++ dependency to LAPACK is not correct!"
213-
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in lib/cmake/blaspp/blasppConfig.cmake"
214-
exit 1
206+
configFile="lib/cmake/blaspp/blasppConfig.cmake"
207+
if [[ ${{ matrix.optblas }} == 'ON' || ${{ matrix.optlapack }} == 'ON' ]]; then
208+
if grep -q "openblas" $configFile; then
209+
echo "BLAS++ dependency to openblas is correct."
210+
else
211+
echo "CMake could not find openblas in $configFile:"
212+
cat $configFile
213+
exit 1
214+
fi
215+
else
216+
if grep -q "${{github.workspace}}/build/lib/libblas" $configFile; then
217+
echo "BLAS++ dependency to BLAS is correct."
218+
else
219+
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in $configFile:"
220+
cat $configFile
221+
exit 1
222+
fi
223+
if grep -q "${{github.workspace}}/build/lib/liblapack" $configFile; then
224+
echo "BLAS++ dependency to LAPACK is correct."
225+
else
226+
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in $configFile:"
227+
cat $configFile
228+
exit 1
229+
fi
215230
fi
216231
217232
- name: Install

CMakeLists.txt

Lines changed: 84 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,55 @@ if (BLAS++ OR LAPACK++)
512512
endif()
513513

514514
# Adds target blaspp
515-
add_custom_target( blaspp ALL
515+
add_custom_target( blaspp ALL DEPENDS blaspp-cmd )
516+
add_custom_command( OUTPUT blaspp-cmd
517+
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
518+
COMMENT "Building BLAS++" )
519+
520+
# Set up information about the BLAS and LAPACK libraries
521+
if(NOT BLAS_FOUND)
522+
if(NOT LATESTLAPACK_FOUND)
523+
add_custom_command( OUTPUT blaspp-cmd APPEND
524+
COMMAND ${CMAKE_COMMAND}
525+
-B "${blaspp_BINARY_DIR}"
526+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
527+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>" )
528+
else()
529+
add_custom_command( OUTPUT blaspp-cmd APPEND
530+
COMMAND ${CMAKE_COMMAND}
531+
-B "${blaspp_BINARY_DIR}"
532+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
533+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
534+
endif()
535+
else()
536+
if(NOT LATESTLAPACK_FOUND)
537+
add_custom_command( OUTPUT blaspp-cmd APPEND
538+
COMMAND ${CMAKE_COMMAND}
539+
-B "${blaspp_BINARY_DIR}"
540+
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
541+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
542+
else()
543+
add_custom_command( OUTPUT blaspp-cmd APPEND
544+
COMMAND ${CMAKE_COMMAND}
545+
-B "${blaspp_BINARY_DIR}"
546+
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
547+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
548+
endif()
549+
endif()
550+
551+
# Setup remaining configuration options and installation
552+
add_custom_command( OUTPUT blaspp-cmd APPEND
516553
COMMAND ${CMAKE_COMMAND}
517-
-B "${blaspp_BINARY_DIR}"
518-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
519-
-D blas_libraries_cached=""
520-
"-DBLAS_LIBRARIES=\"$<IF:$<BOOL:${BLAS_FOUND}>,${BLAS_LIBRARIES},$<TARGET_FILE:${BLASLIB}>>${BLAS_Fortran_LIB}\""
521-
-D lapack_libraries_cached=""
522-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
523-
-D build_tests=OFF
524-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
554+
-B "${blaspp_BINARY_DIR}"
555+
-D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}"
556+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
557+
-D blas_libraries_cached=""
558+
-D lapack_libraries_cached=""
559+
-D build_tests=OFF
560+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
525561
COMMAND ${CMAKE_COMMAND}
526562
--build "${blaspp_BINARY_DIR}"
527563
--target install
528-
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
529-
COMMENT "Building BLAS++"
530564
)
531565

532566
# Set up dependencies
@@ -549,19 +583,36 @@ if (LAPACK++)
549583
endif()
550584

551585
# Adds target lapackpp
552-
add_custom_target( lapackpp ALL
553-
COMMAND ${CMAKE_COMMAND}
586+
add_custom_target( lapackpp ALL DEPENDS lapackpp-cmd )
587+
add_custom_command( OUTPUT lapackpp-cmd
588+
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
589+
COMMENT "Building LAPACK++" )
590+
591+
# Set up information about the LAPACK library
592+
if(NOT LATESTLAPACK_FOUND)
593+
add_custom_command( OUTPUT lapackpp-cmd APPEND
594+
COMMAND ${CMAKE_COMMAND}
554595
-B "${lapackpp_BINARY_DIR}"
555-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
556-
-D lapack_libraries_cached=""
557-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
558-
-D build_tests=OFF
559-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
596+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
597+
else()
598+
add_custom_command( OUTPUT lapackpp-cmd APPEND
599+
COMMAND ${CMAKE_COMMAND}
600+
-B "${lapackpp_BINARY_DIR}"
601+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
602+
endif()
603+
604+
# Setup remaining configuration options and installation
605+
add_custom_command( OUTPUT lapackpp-cmd APPEND
606+
COMMAND ${CMAKE_COMMAND}
607+
-B "${lapackpp_BINARY_DIR}"
608+
-D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}"
609+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
610+
-D lapack_libraries_cached=""
611+
-D build_tests=OFF
612+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
560613
COMMAND ${CMAKE_COMMAND}
561614
--build "${lapackpp_BINARY_DIR}"
562615
--target install
563-
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
564-
COMMENT "Building LAPACK++"
565616
)
566617

567618
# Set up dependencies
@@ -675,14 +726,14 @@ install(FILES
675726
)
676727
if (LAPACK++)
677728
install(
678-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
679-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
680-
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
729+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
730+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
731+
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
681732
)
682-
write_basic_package_version_file(
683-
"lapackppConfigVersion.cmake"
684-
VERSION 2023.08.25
685-
COMPATIBILITY AnyNewerVersion
733+
install(
734+
DIRECTORY "${lapackpp_BINARY_DIR}/include/"
735+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
736+
FILES_MATCHING REGEX "\\.(h|hh)$"
686737
)
687738
install(
688739
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
@@ -692,23 +743,18 @@ if (LAPACK++)
692743

693744
endif()
694745
if (BLAS++)
695-
install(
696-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
697-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
698-
FILES_MATCHING REGEX "libblaspp.(a|so)$"
699-
)
700-
write_basic_package_version_file(
701-
"blasppConfigVersion.cmake"
702-
VERSION 2023.08.25
703-
COMPATIBILITY AnyNewerVersion
704-
)
705746
install(
706747
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfig.cmake"
707748
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfigVersion.cmake"
708749
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
709750
)
710751
install(
711-
DIRECTORY "${PROJECT_BINARY_DIR}/include/"
752+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
753+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
754+
FILES_MATCHING REGEX "libblaspp.(a|so)$"
755+
)
756+
install(
757+
DIRECTORY "${blaspp_BINARY_DIR}/include/"
712758
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
713759
FILES_MATCHING REGEX "\\.(h|hh)$"
714760
)

0 commit comments

Comments
 (0)