Skip to content

Commit ca6673b

Browse files
More changes to improve flags BLAS++ and LAPACK++
1 parent 0c31c63 commit ca6673b

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
@@ -249,8 +249,13 @@ jobs:
249249
strategy:
250250
fail-fast: false
251251
matrix:
252-
sharedlib: [ ON, OFF ]
252+
sharedlib: [ OFF, ON ]
253253
lapackpp: [ OFF ]
254+
optblas: [ OFF, ON ]
255+
optlapack: [ OFF, ON ]
256+
exclude:
257+
- optblas: ON
258+
optlapack: ON
254259

255260
steps:
256261

@@ -261,12 +266,9 @@ jobs:
261266
uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
262267

263268
- name: Install the Basics
264-
# Adding some noise to the system: libopenblas-dev liblapack-dev should not
265-
# be linked to BLAS++ or LAPACK++.
266269
run: |
267270
sudo apt update
268-
sudo apt install -y cmake gfortran
269-
sudo apt purge libopenblas-dev liblapack-dev
271+
sudo apt install -y cmake gfortran libopenblas-dev
270272
271273
- name: Configure CMake
272274
run: >
@@ -279,26 +281,39 @@ jobs:
279281
-D BUILD_SHARED_LIBS:BOOL=${{ matrix.sharedlib }}
280282
-D BLAS++:BOOL=ON
281283
-D LAPACK++:BOOL=${{ matrix.lapackpp }}
284+
-D USE_OPTIMIZED_BLAS:BOOL=${{ matrix.optblas }}
285+
-D USE_OPTIMIZED_LAPACK:BOOL=${{ matrix.optlapack }}
282286
283287
- name: Build
284288
run: cmake --build build --config ${{env.BUILD_TYPE}}
285289

286-
- name: Check dependencies of BLAS++
290+
- name: Check dependencies of BLAS++ on BLAS and LAPACK
287291
working-directory: ${{github.workspace}}/build
288292
run: |
289-
blaspp_blas=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/libblas" | { grep -v grep || true; })
290-
echo "blaspp_blas: $blaspp_blas"
291-
if [[ -z $blaspp_blas ]]; then
292-
echo "BLAS++ dependency to BLAS is not correct!"
293-
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in lib/cmake/blaspp/blasppConfig.cmake"
294-
exit 1
295-
fi
296-
blaspp_lapack=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/liblapack" | { grep -v grep || true; })
297-
echo "blaspp_lapack: $blaspp_lapack"
298-
if [[ -z $blaspp_lapack ]]; then
299-
echo "BLAS++ dependency to LAPACK is not correct!"
300-
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in lib/cmake/blaspp/blasppConfig.cmake"
301-
exit 1
293+
configFile="lib/cmake/blaspp/blasppConfig.cmake"
294+
if [[ ${{ matrix.optblas }} == 'ON' || ${{ matrix.optlapack }} == 'ON' ]]; then
295+
if grep -q "openblas" $configFile; then
296+
echo "BLAS++ dependency to openblas is correct."
297+
else
298+
echo "CMake could not find openblas in $configFile:"
299+
cat $configFile
300+
exit 1
301+
fi
302+
else
303+
if grep -q "${{github.workspace}}/build/lib/libblas" $configFile; then
304+
echo "BLAS++ dependency to BLAS is correct."
305+
else
306+
echo "CMake could not find ${{github.workspace}}/build/lib/libblas in $configFile:"
307+
cat $configFile
308+
exit 1
309+
fi
310+
if grep -q "${{github.workspace}}/build/lib/liblapack" $configFile; then
311+
echo "BLAS++ dependency to LAPACK is correct."
312+
else
313+
echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in $configFile:"
314+
cat $configFile
315+
exit 1
316+
fi
302317
fi
303318
304319
- name: Install

CMakeLists.txt

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

454454
# Adds target blaspp
455-
add_custom_target( blaspp ALL
455+
add_custom_target( blaspp ALL DEPENDS blaspp-cmd )
456+
add_custom_command( OUTPUT blaspp-cmd
457+
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
458+
COMMENT "Building BLAS++" )
459+
460+
# Set up information about the BLAS and LAPACK libraries
461+
if(NOT BLAS_FOUND)
462+
if(NOT LATESTLAPACK_FOUND)
463+
add_custom_command( OUTPUT blaspp-cmd APPEND
464+
COMMAND ${CMAKE_COMMAND}
465+
-B "${blaspp_BINARY_DIR}"
466+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
467+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>" )
468+
else()
469+
add_custom_command( OUTPUT blaspp-cmd APPEND
470+
COMMAND ${CMAKE_COMMAND}
471+
-B "${blaspp_BINARY_DIR}"
472+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
473+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
474+
endif()
475+
else()
476+
if(NOT LATESTLAPACK_FOUND)
477+
add_custom_command( OUTPUT blaspp-cmd APPEND
478+
COMMAND ${CMAKE_COMMAND}
479+
-B "${blaspp_BINARY_DIR}"
480+
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
481+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
482+
else()
483+
add_custom_command( OUTPUT blaspp-cmd APPEND
484+
COMMAND ${CMAKE_COMMAND}
485+
-B "${blaspp_BINARY_DIR}"
486+
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
487+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
488+
endif()
489+
endif()
490+
491+
# Setup remaining configuration options and installation
492+
add_custom_command( OUTPUT blaspp-cmd APPEND
456493
COMMAND ${CMAKE_COMMAND}
457-
-B "${blaspp_BINARY_DIR}"
458-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
459-
-D blas_libraries_cached=""
460-
"-DBLAS_LIBRARIES=\"$<IF:$<BOOL:${BLAS_FOUND}>,${BLAS_LIBRARIES},$<TARGET_FILE:${BLASLIB}>>${BLAS_Fortran_LIB}\""
461-
-D lapack_libraries_cached=""
462-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
463-
-D build_tests=OFF
464-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
494+
-B "${blaspp_BINARY_DIR}"
495+
-D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}"
496+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
497+
-D blas_libraries_cached=""
498+
-D lapack_libraries_cached=""
499+
-D build_tests=OFF
500+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
465501
COMMAND ${CMAKE_COMMAND}
466502
--build "${blaspp_BINARY_DIR}"
467503
--target install
468-
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
469-
COMMENT "Building BLAS++"
470504
)
471505

472506
# Set up dependencies
@@ -489,19 +523,36 @@ if (LAPACK++)
489523
endif()
490524

491525
# Adds target lapackpp
492-
add_custom_target( lapackpp ALL
493-
COMMAND ${CMAKE_COMMAND}
526+
add_custom_target( lapackpp ALL DEPENDS lapackpp-cmd )
527+
add_custom_command( OUTPUT lapackpp-cmd
528+
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
529+
COMMENT "Building LAPACK++" )
530+
531+
# Set up information about the LAPACK library
532+
if(NOT LATESTLAPACK_FOUND)
533+
add_custom_command( OUTPUT lapackpp-cmd APPEND
534+
COMMAND ${CMAKE_COMMAND}
494535
-B "${lapackpp_BINARY_DIR}"
495-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
496-
-D lapack_libraries_cached=""
497-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
498-
-D build_tests=OFF
499-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
536+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
537+
else()
538+
add_custom_command( OUTPUT lapackpp-cmd APPEND
539+
COMMAND ${CMAKE_COMMAND}
540+
-B "${lapackpp_BINARY_DIR}"
541+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
542+
endif()
543+
544+
# Setup remaining configuration options and installation
545+
add_custom_command( OUTPUT lapackpp-cmd APPEND
546+
COMMAND ${CMAKE_COMMAND}
547+
-B "${lapackpp_BINARY_DIR}"
548+
-D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}"
549+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
550+
-D lapack_libraries_cached=""
551+
-D build_tests=OFF
552+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
500553
COMMAND ${CMAKE_COMMAND}
501554
--build "${lapackpp_BINARY_DIR}"
502555
--target install
503-
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
504-
COMMENT "Building LAPACK++"
505556
)
506557

507558
# Set up dependencies
@@ -615,14 +666,14 @@ install(FILES
615666
)
616667
if (LAPACK++)
617668
install(
618-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
619-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
620-
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
669+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
670+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
671+
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
621672
)
622-
write_basic_package_version_file(
623-
"lapackppConfigVersion.cmake"
624-
VERSION 2023.08.25
625-
COMPATIBILITY AnyNewerVersion
673+
install(
674+
DIRECTORY "${lapackpp_BINARY_DIR}/include/"
675+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
676+
FILES_MATCHING REGEX "\\.(h|hh)$"
626677
)
627678
install(
628679
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
@@ -632,23 +683,18 @@ if (LAPACK++)
632683

633684
endif()
634685
if (BLAS++)
635-
install(
636-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
637-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
638-
FILES_MATCHING REGEX "libblaspp.(a|so)$"
639-
)
640-
write_basic_package_version_file(
641-
"blasppConfigVersion.cmake"
642-
VERSION 2023.08.25
643-
COMPATIBILITY AnyNewerVersion
644-
)
645686
install(
646687
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfig.cmake"
647688
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfigVersion.cmake"
648689
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
649690
)
650691
install(
651-
DIRECTORY "${PROJECT_BINARY_DIR}/include/"
692+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
693+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
694+
FILES_MATCHING REGEX "libblaspp.(a|so)$"
695+
)
696+
install(
697+
DIRECTORY "${blaspp_BINARY_DIR}/include/"
652698
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
653699
FILES_MATCHING REGEX "\\.(h|hh)$"
654700
)

0 commit comments

Comments
 (0)