diff --git a/cmake/LAMMPSConfig.cmake.in b/cmake/LAMMPSConfig.cmake.in index 969bd6e929..7cd782b3b8 100644 --- a/cmake/LAMMPSConfig.cmake.in +++ b/cmake/LAMMPSConfig.cmake.in @@ -20,8 +20,8 @@ if(NOT @BUILD_SHARED_LIBS@) find_dependency(ZLIB REQUIRED) endif() if(@PKG_KIM@) - find_package(KIM-API @KIM-API_MIN_VERSION@ CONFIG REQUIRED) - add_kim_api_imported_library() + find_dependency(PkgConfig REQUIRED) + pkg_check_modules(KIM-API REQUIRED IMPORTED_TARGET libkim-api>=@KIM-API_MIN_VERSION@) if(@CURL_FOUND@) find_dependency(CURL REQUIRED) endif() diff --git a/cmake/Modules/Packages/KIM.cmake b/cmake/Modules/Packages/KIM.cmake index 06e513bc0a..278a6b5afc 100644 --- a/cmake/Modules/Packages/KIM.cmake +++ b/cmake/Modules/Packages/KIM.cmake @@ -1,8 +1,12 @@ -# CMake configuration for KIM package set(KIM-API_MIN_VERSION 2.1.3) find_package(CURL) if(CURL_FOUND) - target_link_libraries(lammps PRIVATE CURL::libcurl) + if(CMAKE_VERSION VERSION_LESS 3.12) + target_include_directories(lammps PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(lammps PRIVATE ${CURL_LIBRARIES}) + else() + target_link_libraries(lammps PRIVATE CURL::libcurl) + endif() target_compile_definitions(lammps PRIVATE -DLMP_KIM_CURL) set(LMP_DEBUG_CURL OFF CACHE STRING "Set libcurl verbose mode on/off. If on, it displays a lot of verbose information about its operations.") mark_as_advanced(LMP_DEBUG_CURL) @@ -15,11 +19,13 @@ if(CURL_FOUND) target_compile_definitions(lammps PRIVATE -DLMP_NO_SSL_CHECK) endif() endif() -find_package(KIM-API ${KIM-API_MIN_VERSION} CONFIG) -if(KIM-API_FOUND) - set(DOWNLOAD_KIM_DEFAULT OFF) -else() - set(DOWNLOAD_KIM_DEFAULT ON) +find_package(PkgConfig QUIET) +set(DOWNLOAD_KIM_DEFAULT ON) +if(PKG_CONFIG_FOUND) + pkg_check_modules(KIM-API QUIET libkim-api>=${KIM-API_MIN_VERSION}) + if(KIM-API_FOUND) + set(DOWNLOAD_KIM_DEFAULT OFF) + endif() endif() option(DOWNLOAD_KIM "Download KIM-API from OpenKIM instead of using an already installed one" ${DOWNLOAD_KIM_DEFAULT}) if(DOWNLOAD_KIM) @@ -54,7 +60,7 @@ if(DOWNLOAD_KIM) install(CODE "MESSAGE(FATAL_ERROR \"Installing liblammps with downloaded libraries is currently not supported.\")") endif() else() - find_package(KIM-API ${KIM-API_MIN_VERSION} CONFIG REQUIRED) - add_kim_api_imported_library() - target_link_libraries(lammps PRIVATE kim-api) + find_package(PkgConfig REQUIRED) + pkg_check_modules(KIM-API REQUIRED IMPORTED_TARGET libkim-api>=${KIM-API_MIN_VERSION}) + target_link_libraries(lammps PRIVATE PkgConfig::KIM-API) endif()