Merge pull request #1634 from junghans/kim-api-version

cmake: add version check for kim-api
This commit is contained in:
Axel Kohlmeyer 2019-09-05 13:59:46 -04:00 committed by GitHub
commit 92c77a2b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 5 deletions

View File

@ -37,6 +37,26 @@
# KIM-API-CMAKE_Fortran_COMPILER
#
function(_KIMAPI_GET_VERSION _OUT_ver _version_hdr)
if(NOT EXISTS ${_version_hdr})
message(FATAL_ERROR "Header file ${_version_hdr} not found (check value of KIM-API_INCLUDE_DIR)")
endif()
foreach(_var KIM_VERSION_MAJOR KIM_VERSION_MINOR KIM_VERSION_PATCH)
file(STRINGS ${_version_hdr} _contents REGEX "#define ${_var}[ \t]+")
if(_contents)
string(REGEX REPLACE ".*#define ${_var}[ \t]+([0-9]+).*" "\\1" _${_var} "${_contents}")
if(${_${_var}} STREQUAL "")
message(FATAL_ERROR "Version parsing failed for ${_var} in ${_version_hdr}, got empty return!")
elseif(NOT ${_${_var}} MATCHES "^[0-9]+$")
message(FATAL_ERROR "Version parsing failed for ${_var} in ${_version_hdr}, excepted a number but got ${_${_var}}!")
endif()
else()
message(FATAL_ERROR "No ${_var} line found in include file ${_version_hdr}")
endif()
endforeach()
set(${_OUT_ver} ${_KIM_VERSION_MAJOR}.${_KIM_VERSION_MINOR}.${_KIM_VERSION_PATCH} PARENT_SCOPE)
endfunction()
if(KIM-API_FIND_QUIETLY)
set(REQ_OR_QUI "QUIET")
else()
@ -54,6 +74,12 @@ if(KIM-API_FOUND)
pkg_get_variable(KIM-API_CMAKE_Fortran_COMPILER libkim-api CMAKE_Fortran_COMPILER)
endif()
if(KIM-API_INCLUDEDIR)
_KIMAPI_GET_VERSION(KIM-API_VERSION ${KIM-API_INCLUDEDIR}/KIM_Version.h)
else()
set(KIM-API_VERSION 0)
endif()
# handle the QUIETLY and REQUIRED arguments and set KIM-API_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(KIM-API REQUIRED_VARS KIM-API_LIBRARIES)
find_package_handle_standard_args(KIM-API REQUIRED_VARS KIM-API_LIBRARIES VERSION_VAR KIM-API_VERSION)

View File

@ -1,4 +1,5 @@
if(PKG_KIM)
set(KIM-API_MIN_VERSION 2.1)
find_package(CURL)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
@ -7,10 +8,17 @@ if(PKG_KIM)
endif()
find_package(KIM-API QUIET)
if(KIM-API_FOUND)
set(DOWNLOAD_KIM_DEFAULT OFF)
if (KIM-API_VERSION VERSION_LESS ${KIM-API_MIN_VERSION})
if ("${DOWNLOAD_KIM}" STREQUAL "")
message(WARNING "Unsuitable KIM-API version \"${KIM-API_VERSION}\" found, but required is at least \"${KIM-API_MIN_VERSION}\". Default behavior set to download and build our own.")
endif()
set(DOWNLOAD_KIM_DEFAULT ON)
else()
set(DOWNLOAD_KIM_DEFAULT OFF)
endif()
else()
if (NOT DOWNLOAD_KIM)
message(WARNING "KIM-API package not found. We will download and build our own")
if ("${DOWNLOAD_KIM}" STREQUAL "")
message(WARNING "KIM-API package not found. Default behavior set to download and build our own")
endif()
set(DOWNLOAD_KIM_DEFAULT ON)
endif()
@ -42,7 +50,7 @@ if(PKG_KIM)
set(KIM-API_LDFLAGS ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/libkim-api${CMAKE_SHARED_LIBRARY_SUFFIX})
list(APPEND LAMMPS_DEPS kim_build)
else()
find_package(KIM-API REQUIRED)
find_package(KIM-API ${KIM-API_MIN_VERSION} REQUIRED)
endif()
list(APPEND LAMMPS_LINK_LIBS "${KIM-API_LDFLAGS}")
include_directories(${KIM-API_INCLUDE_DIRS})