From 1f307ebbe6604539493e165a7a2b00b366711fd8 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 28 Sep 2023 13:29:57 -0400 Subject: [PATCH] [cmake] if LAPACK_LIBRARIES includes IMPORTED targets make sure they are available --- cmake/madness-config.cmake.in | 7 +++++++ external/lapack.cmake | 8 ++++++++ src/madness/CMakeLists.txt | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmake/madness-config.cmake.in b/cmake/madness-config.cmake.in index 6683525d379..700b6c54d93 100644 --- a/cmake/madness-config.cmake.in +++ b/cmake/madness-config.cmake.in @@ -226,3 +226,10 @@ if (@LIBXC_FOUND@) set(LIBXC_FOUND 1) endif() +### LAPACK_LIBRARIES might include IMPORTED targets that are not globally available +if (LAPACK_LIBRARIES MATCHES OpenMP::OpenMP_C AND NOT TARGET OpenMP::OpenMP_C) + find_package(OpenMP REQUIRED COMPONENTS C) +endif() +if (LAPACK_LIBRARIES MATCHES Threads::Threads AND NOT TARGET Threads::Threads) + find_package(Threads REQUIRED) +endif() diff --git a/external/lapack.cmake b/external/lapack.cmake index 30306fbbea7..cf554b8137a 100644 --- a/external/lapack.cmake +++ b/external/lapack.cmake @@ -117,6 +117,14 @@ if (USER_LAPACK_LIBRARIES) endif(USER_LAPACK_LIBRARIES_IS_ACML) endif(USER_LAPACK_LIBRARIES_IS_MKL) + # LAPACK_LIBRARIES might include IMPORTED targets that are not globally available + if (LAPACK_LIBRARIES MATCHES OpenMP::OpenMP_C AND NOT TARGET OpenMP::OpenMP_C) + find_package(OpenMP REQUIRED COMPONENTS C) + endif() + if (LAPACK_LIBRARIES MATCHES Threads::Threads AND NOT TARGET Threads::Threads) + find_package(Threads REQUIRED) + endif() + endif(USER_LAPACK_LIBRARIES) cmake_pop_check_state() diff --git a/src/madness/CMakeLists.txt b/src/madness/CMakeLists.txt index c7142efc970..0e60e5ce8dc 100644 --- a/src/madness/CMakeLists.txt +++ b/src/madness/CMakeLists.txt @@ -94,7 +94,13 @@ if(HAVE_IBMBGQ OR HAVE_IBMBGP) target_link_libraries(madness PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/new_mtxmq/bests/libMADMTXM.a) endif() if (LAPACK_FOUND) - target_link_libraries(madness PUBLIC ${LAPACK_LIBRARIES}) + + # if LAPACK_LIBRARIES includes IMPORTED targets make sure they are available + if (LAPACK_LIBRARIES MATCHES OpenMP::OpenMP_C AND NOT TARGET OpenMP::OpenMP_C) + find_package(OpenMP REQUIRED COMPONENTS C) + endif() + + target_link_libraries(madness PUBLIC ${LAPACK_LIBRARIES}) if (LAPACK_INCLUDE_DIRS) target_include_directories(madness PUBLIC ${LAPACK_INCLUDE_DIRS}) endif(LAPACK_INCLUDE_DIRS)