$NetBSD: patch-CMakeLists.txt,v 1.7 2025/01/14 11:41:00 wiz Exp $

A changeset that I pushed upstream in a PR, to enable separate libblas build,
un-break standalone CBLAS build with included BLAS, not unconditionally
require unnecessary C++ compiler.

See: https://github.com/Reference-LAPACK/lapack/pull/972

--- CMakeLists.txt.orig	2023-11-24 20:41:15.000000000 +0000
+++ CMakeLists.txt
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.6)
 
-project(LAPACK)
+project(LAPACK Fortran C)
 
 set(LAPACK_MAJOR_VERSION 3)
 set(LAPACK_MINOR_VERSION 12)
@@ -244,8 +244,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}"
@@ -277,6 +281,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)")
+
+if(LAPACK)
+
 # --------------------------------------------------
 # LAPACK
 # User did not provide a LAPACK Library but specified to search for one
@@ -348,6 +356,8 @@ else()
     CACHE STRING "Linker flags for shared libs" FORCE)
 endif()
 
+endif()
+
 if(BUILD_TESTING)
   add_subdirectory(TESTING)
 endif()
@@ -413,6 +423,7 @@ function(_display_cpp_implementation_msg
   message(STATUS "----------------")
 endfunction()
 if (BLAS++)
+  enable_language(CXX)
   _display_cpp_implementation_msg("BLAS")
   include(ExternalProject)
   ExternalProject_Add(blaspp
@@ -424,6 +435,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)
@@ -482,10 +494,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 "")
@@ -499,6 +515,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)
@@ -514,6 +531,8 @@ if(NOT LAPACK_WITH_TMGLIB_FOUND AND LAPA
   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)
@@ -551,6 +570,9 @@ install(FILES
   DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LAPACKLIB}-${LAPACK_VERSION}
   COMPONENT Development
   )
+
+endif() # BUILD_LAPACK
+
 if (LAPACK++)
   install(
   DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
@@ -562,6 +584,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
@@ -575,6 +598,7 @@ if (LAPACK++)
 
 endif()
 if (BLAS++)
+  include(CMakePackageConfigHelpers)
   write_basic_package_version_file(
     "blasppConfigVersion.cmake"
     VERSION 2020.10.02
