LATTE.cmake: create and use imported target

This commit is contained in:
Christoph Junghans
2020-03-25 11:26:19 -06:00
parent 58c9c4c64b
commit 2571b6058e
2 changed files with 16 additions and 7 deletions

View File

@ -7,12 +7,21 @@
find_library(LATTE_LIBRARY NAMES latte)
set(LATTE_LIBRARIES ${LATTE_LIBRARY})
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LATTE_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(LATTE DEFAULT_MSG LATTE_LIBRARY)
# Copy the results to the output variables and target.
if(LATTE_FOUND)
set(LATTE_LIBRARIES ${LATTE_LIBRARY})
if(NOT TARGET LATTE::latte)
add_library(LATTE::latte UNKNOWN IMPORTED)
set_target_properties(LATTE::latte PROPERTIES
IMPORTED_LOCATION "${LATTE_LIBRARY}")
endif()
endif()
mark_as_advanced(LATTE_LIBRARY)

View File

@ -26,15 +26,15 @@ if(PKG_LATTE)
)
add_dependencies(lammps latte_build)
ExternalProject_get_property(latte_build INSTALL_DIR)
set(LATTE_LIBRARIES ${INSTALL_DIR}/${_LATTE_LIBDIR}/liblatte.a)
target_link_libraries(lammps PRIVATE ${INSTALL_DIR}/${_LATTE_LIBDIR}/liblatte.a ${LAPACK_LIBRARIES})
if(NOT LAPACK_FOUND)
add_dependencies(latte_build linalg)
endif()
else()
find_package(LATTE)
if(NOT LATTE_FOUND)
message(FATAL_ERROR "LATTE library not found, help CMake to find it by setting LATTE_LIBRARY, or set DOWNLOAD_LATTE=ON to download it")
endif()
target_link_libraries(lammps PRIVATE LATTE::latte)
endif()
if(NOT LAPACK_FOUND)
add_dependencies(latte_build linalg)
endif()
target_link_libraries(lammps PRIVATE ${LATTE_LIBRARIES} ${LAPACK_LIBRARIES})
endif()