Skip to content

Commit 3426961

Browse files
weslleyspereiraWeslley da Silva Pereira
authored andcommitted
More changes to improve flags BLAS++ and LAPACK++
1 parent 147558f commit 3426961

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
@@ -438,21 +438,55 @@ if (BLAS++ OR LAPACK++)
438438
endif()
439439

440440
# Adds target blaspp
441-
add_custom_target( blaspp ALL
441+
add_custom_target( blaspp ALL DEPENDS blaspp-cmd )
442+
add_custom_command( OUTPUT blaspp-cmd
443+
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
444+
COMMENT "Building BLAS++" )
445+
446+
# Set up information about the BLAS and LAPACK libraries
447+
if(NOT BLAS_FOUND)
448+
if(NOT LATESTLAPACK_FOUND)
449+
add_custom_command( OUTPUT blaspp-cmd APPEND
450+
COMMAND ${CMAKE_COMMAND}
451+
-B "${blaspp_BINARY_DIR}"
452+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
453+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>" )
454+
else()
455+
add_custom_command( OUTPUT blaspp-cmd APPEND
456+
COMMAND ${CMAKE_COMMAND}
457+
-B "${blaspp_BINARY_DIR}"
458+
-D BLAS_LIBRARIES="$<TARGET_FILE:${BLASLIB}>${BLAS_Fortran_LIB}"
459+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
460+
endif()
461+
else()
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="${BLAS_LIBRARIES}"
467+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
468+
else()
469+
add_custom_command( OUTPUT blaspp-cmd APPEND
470+
COMMAND ${CMAKE_COMMAND}
471+
-B "${blaspp_BINARY_DIR}"
472+
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
473+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
474+
endif()
475+
endif()
476+
477+
# Setup remaining configuration options and installation
478+
add_custom_command( OUTPUT blaspp-cmd APPEND
442479
COMMAND ${CMAKE_COMMAND}
443-
-B "${blaspp_BINARY_DIR}"
444-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
445-
-D blas_libraries_cached=""
446-
"-DBLAS_LIBRARIES=\"$<IF:$<BOOL:${BLAS_FOUND}>,${BLAS_LIBRARIES},$<TARGET_FILE:${BLASLIB}>>${BLAS_Fortran_LIB}\""
447-
-D lapack_libraries_cached=""
448-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
449-
-D build_tests=OFF
450-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
480+
-B "${blaspp_BINARY_DIR}"
481+
-D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}"
482+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
483+
-D blas_libraries_cached=""
484+
-D lapack_libraries_cached=""
485+
-D build_tests=OFF
486+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
451487
COMMAND ${CMAKE_COMMAND}
452488
--build "${blaspp_BINARY_DIR}"
453489
--target install
454-
WORKING_DIRECTORY "${blaspp_SOURCE_DIR}"
455-
COMMENT "Building BLAS++"
456490
)
457491

458492
# Set up dependencies
@@ -475,19 +509,36 @@ if (LAPACK++)
475509
endif()
476510

477511
# Adds target lapackpp
478-
add_custom_target( lapackpp ALL
479-
COMMAND ${CMAKE_COMMAND}
512+
add_custom_target( lapackpp ALL DEPENDS lapackpp-cmd )
513+
add_custom_command( OUTPUT lapackpp-cmd
514+
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
515+
COMMENT "Building LAPACK++" )
516+
517+
# Set up information about the LAPACK library
518+
if(NOT LATESTLAPACK_FOUND)
519+
add_custom_command( OUTPUT lapackpp-cmd APPEND
520+
COMMAND ${CMAKE_COMMAND}
480521
-B "${lapackpp_BINARY_DIR}"
481-
-D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}"
482-
-D lapack_libraries_cached=""
483-
"-DLAPACK_LIBRARIES=\"$<IF:$<BOOL:${LATESTLAPACK_FOUND}>,${LAPACK_LIBRARIES},$<TARGET_FILE:${LAPACKLIB}>>\""
484-
-D build_tests=OFF
485-
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
522+
-D LAPACK_LIBRARIES="$<TARGET_FILE:${LAPACKLIB}>${BLAS_Fortran_LIB}" )
523+
else()
524+
add_custom_command( OUTPUT lapackpp-cmd APPEND
525+
COMMAND ${CMAKE_COMMAND}
526+
-B "${lapackpp_BINARY_DIR}"
527+
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
528+
endif()
529+
530+
# Setup remaining configuration options and installation
531+
add_custom_command( OUTPUT lapackpp-cmd APPEND
532+
COMMAND ${CMAKE_COMMAND}
533+
-B "${lapackpp_BINARY_DIR}"
534+
-D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}"
535+
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
536+
-D lapack_libraries_cached=""
537+
-D build_tests=OFF
538+
-D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
486539
COMMAND ${CMAKE_COMMAND}
487540
--build "${lapackpp_BINARY_DIR}"
488541
--target install
489-
WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}"
490-
COMMENT "Building LAPACK++"
491542
)
492543

493544
# Set up dependencies
@@ -601,14 +652,14 @@ install(FILES
601652
)
602653
if (LAPACK++)
603654
install(
604-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
605-
DESTINATION "${CMAKE_INSTALL_LIBDIR}${LAPACK_BINARY_PATH_SUFFIX}"
606-
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
655+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
656+
DESTINATION "${CMAKE_INSTALL_LIBDIR}${LAPACK_BINARY_PATH_SUFFIX}"
657+
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
607658
)
608-
write_basic_package_version_file(
609-
"lapackppConfigVersion.cmake"
610-
VERSION 2023.08.25
611-
COMPATIBILITY AnyNewerVersion
659+
install(
660+
DIRECTORY "${lapackpp_BINARY_DIR}/include/"
661+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
662+
FILES_MATCHING REGEX "\\.(h|hh)$"
612663
)
613664
install(
614665
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
@@ -618,23 +669,18 @@ if (LAPACK++)
618669

619670
endif()
620671
if (BLAS++)
621-
install(
622-
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
623-
DESTINATION "${CMAKE_INSTALL_LIBDIR}${LAPACK_BINARY_PATH_SUFFIX}"
624-
FILES_MATCHING REGEX "libblaspp.(a|so)$"
625-
)
626-
write_basic_package_version_file(
627-
"blasppConfigVersion.cmake"
628-
VERSION 2023.08.25
629-
COMPATIBILITY AnyNewerVersion
630-
)
631672
install(
632673
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfig.cmake"
633674
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfigVersion.cmake"
634675
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
635676
)
636677
install(
637-
DIRECTORY "${PROJECT_BINARY_DIR}/include/"
678+
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
679+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
680+
FILES_MATCHING REGEX "libblaspp.(a|so)$"
681+
)
682+
install(
683+
DIRECTORY "${blaspp_BINARY_DIR}/include/"
638684
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
639685
FILES_MATCHING REGEX "\\.(h|hh)$"
640686
)

0 commit comments

Comments
 (0)