Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake build: Add -DLAPACK option, un-break CBLAS+BLAS build, do not require C++ if unnecessary #972

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BLAS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ install(FILES
DESTINATION ${PKG_CONFIG_DIR}
COMPONENT Development
)

install(EXPORT ${BLASLIB}-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${BLASLIB}-${LAPACK_VERSION}
COMPONENT Development
)
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.6)

project(LAPACK)
project(LAPACK Fortran C)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the project language specified here, statements enable_language(Fortran) at lines 226 and 301 are not needed anymore.


set(LAPACK_MAJOR_VERSION 3)
set(LAPACK_MINOR_VERSION 12)
Expand Down Expand Up @@ -245,8 +245,12 @@ endif()
# Neither user specified or optimized BLAS libraries can be used
if(NOT BLAS_FOUND)
message(STATUS "Using supplied NETLIB BLAS implementation")
set(LAPACK_INSTALL_EXPORT_NAME_CACHE ${LAPACK_INSTALL_EXPORT_NAME})
set(LAPACK_INSTALL_EXPORT_NAME ${BLASLIB}-targets)
add_subdirectory(BLAS)
set(BLAS_LIBRARIES ${BLASLIB})
set(LAPACK_INSTALL_EXPORT_NAME ${LAPACK_INSTALL_EXPORT_NAME_CACHE})
unset(LAPACK_INSTALL_EXPORT_NAME_CACHE)
else()
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}"
Expand Down Expand Up @@ -278,6 +282,10 @@ endif()

option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF)

option(LAPACK "Whether to build or use LAPACK (to enable a BLAS-only build)")
Copy link

@quant quant Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be explicit, do not omit OFF, even though it is the default.
And consider building LAPACK enabled by default, in the project named LAPACK.


if(LAPACK)

# --------------------------------------------------
# LAPACK
# User did not provide a LAPACK Library but specified to search for one
Expand Down Expand Up @@ -349,6 +357,8 @@ else()
CACHE STRING "Linker flags for shared libs" FORCE)
endif()

endif()

if(BUILD_TESTING)
add_subdirectory(TESTING)
endif()
Expand Down Expand Up @@ -414,6 +424,7 @@ function(_display_cpp_implementation_msg name)
message(STATUS "----------------")
endfunction()
if (BLAS++)
enable_language(CXX)
_display_cpp_implementation_msg("BLAS")
include(ExternalProject)
ExternalProject_Add(blaspp
Expand All @@ -425,6 +436,7 @@ if (BLAS++)
ExternalProject_Add_StepDependencies(blaspp build ${BLAS_LIBRARIES})
endif()
if (LAPACK++)
enable_language(CXX)
message (STATUS "linking lapack++ against ${LAPACK_LIBRARIES}")
_display_cpp_implementation_msg("LAPACK")
include(ExternalProject)
Expand Down Expand Up @@ -483,10 +495,14 @@ if(NOT BLAS_FOUND)
set(ALL_TARGETS ${ALL_TARGETS} ${BLASLIB})
endif()

if(LAPACK)
if(NOT LATESTLAPACK_FOUND)
set(ALL_TARGETS ${ALL_TARGETS} ${LAPACKLIB})
set(BUILD_LAPACK ON)
endif()
endif()

if(LAPACK)
# Export lapack targets, not including lapacke, from the
# install tree, if any.
set(_lapack_config_install_guard_target "")
Expand All @@ -500,6 +516,7 @@ if(ALL_TARGETS)
# lapack-config.cmake to load targets from the install tree.
list(GET ALL_TARGETS 0 _lapack_config_install_guard_target)
endif()
endif()

# Include cblas in targets exported from the build tree.
if(CBLAS)
Expand All @@ -515,6 +532,8 @@ if(NOT LAPACK_WITH_TMGLIB_FOUND AND LAPACKE_WITH_TMG)
set(ALL_TARGETS ${ALL_TARGETS} ${TMGLIB})
endif()

if(BUILD_LAPACK)

# Export lapack and lapacke targets from the build tree, if any.
set(_lapack_config_build_guard_target "")
if(ALL_TARGETS)
Expand Down Expand Up @@ -552,6 +571,9 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LAPACKLIB}-${LAPACK_VERSION}
COMPONENT Development
)

endif() # BUILD_LAPACK

if (LAPACK++)
install(
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
Expand All @@ -563,6 +585,7 @@ if (LAPACK++)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING REGEX "\\.(h|hh)$"
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"lapackppConfigVersion.cmake"
VERSION 2020.10.02
Expand All @@ -576,6 +599,7 @@ if (LAPACK++)

endif()
if (BLAS++)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"blasppConfigVersion.cmake"
VERSION 2020.10.02
Expand Down