@@ -353,9 +353,27 @@ option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF)
353353if (LAPACKE_WITH_TMG)
354354 set (LAPACKE ON )
355355endif ()
356- if (BUILD_TESTING OR LAPACKE_WITH_TMG) #already included, avoid double inclusion
356+
357+ # TMGLIB
358+ # Cache export target
359+ set (LAPACK_INSTALL_EXPORT_NAME_CACHE ${LAPACK_INSTALL_EXPORT_NAME} )
360+ if (BUILD_TESTING OR LAPACKE_WITH_TMG)
361+ if (LATESTLAPACK_FOUND AND LAPACKE_WITH_TMG)
362+ set (CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES} )
363+ # Check if dlatms (part of tmg) is found
364+ CHECK_FORTRAN_FUNCTION_EXISTS ("dlatms" LAPACK_WITH_TMGLIB_FOUND )
365+ unset (CMAKE_REQUIRED_LIBRARIES)
366+ if (NOT LAPACK_WITH_TMGLIB_FOUND)
367+ # Build and install TMG as part of LAPACKE targets (as opposed to LAPACK
368+ # targets)
369+ set (LAPACK_INSTALL_EXPORT_NAME ${LAPACKELIB} -targets)
370+ endif ()
371+ endif ()
357372 add_subdirectory (TESTING/MATGEN )
358373endif ()
374+ # Reset export target
375+ set (LAPACK_INSTALL_EXPORT_NAME ${LAPACK_INSTALL_EXPORT_NAME_CACHE} )
376+ unset (LAPACK_INSTALL_EXPORT_NAME_CACHE)
359377
360378if (LAPACKE)
361379 add_subdirectory (LAPACKE )
@@ -451,7 +469,7 @@ if(NOT LATESTLAPACK_FOUND)
451469 set (ALL_TARGETS ${ALL_TARGETS} ${LAPACKLIB} )
452470endif ()
453471
454- if (BUILD_TESTING OR LAPACKE_WITH_TMG )
472+ if (BUILD_TESTING)
455473 set (ALL_TARGETS ${ALL_TARGETS} ${TMGLIB} )
456474endif ()
457475
@@ -479,6 +497,10 @@ if(LAPACKE)
479497 set (ALL_TARGETS ${ALL_TARGETS} ${LAPACKELIB} )
480498endif ()
481499
500+ if (NOT LAPACK_WITH_TMGLIB_FOUND AND LAPACKE_WITH_TMG)
501+ set (ALL_TARGETS ${ALL_TARGETS} ${TMGLIB} )
502+ endif ()
503+
482504# Export lapack and lapacke targets from the build tree, if any.
483505set (_lapack_config_build_guard_target "" )
484506if (ALL_TARGETS)
0 commit comments