build: check if libvterm version meets requirement (#22010)

The vterm.h file only specifies major and minor version, but not patch,
meaning that requiring a specific patch number isn't currently possible.
This commit is contained in:
dundargoc 2023-01-26 21:35:06 +01:00 committed by GitHub
parent 3c2bb1b2be
commit 843c9025ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 13 deletions

View File

@ -1,10 +0,0 @@
# - Try to find libvterm
# Once done this will define
# LIBVTERM_FOUND - System has libvterm
# LIBVTERM_INCLUDE_DIRS - The libvterm include directories
# LIBVTERM_LIBRARIES - The libraries needed to use libvterm
include(LibFindMacros)
libfind_pkg_detect(LIBVTERM vterm FIND_PATH vterm.h FIND_LIBRARY vterm)
libfind_process(LIBVTERM REQUIRED)

20
cmake/Findlibvterm.cmake Normal file
View File

@ -0,0 +1,20 @@
find_path(LIBVTERM_INCLUDE_DIR vterm.h)
find_library(LIBVTERM_LIBRARY vterm)
if(LIBVTERM_INCLUDE_DIR AND EXISTS "${LIBVTERM_INCLUDE_DIR}/vterm.h")
file(STRINGS ${LIBVTERM_INCLUDE_DIR}/vterm.h VTERM_VERSION_MAJOR REGEX "#define VTERM_VERSION_MAJOR")
string(REGEX MATCH "[0-9]+" VTERM_VERSION_MAJOR ${VTERM_VERSION_MAJOR})
file(STRINGS ${LIBVTERM_INCLUDE_DIR}/vterm.h VTERM_VERSION_MINOR REGEX "#define VTERM_VERSION_MINOR")
string(REGEX MATCH "[0-9]+" VTERM_VERSION_MINOR ${VTERM_VERSION_MINOR})
set(VTERM_VERSION ${VTERM_VERSION_MAJOR}.${VTERM_VERSION_MINOR})
endif()
find_package_handle_standard_args(libvterm
REQUIRED_VARS LIBVTERM_INCLUDE_DIR LIBVTERM_LIBRARY
VERSION_VAR VTERM_VERSION)
add_library(libvterm INTERFACE)
target_include_directories(libvterm SYSTEM BEFORE INTERFACE INTERFACE ${LIBVTERM_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LIBVTERM_LIBRARY})

View File

@ -30,9 +30,8 @@ find_package(LibTermkey 0.22 REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LIBTERMKEY_INCLUDE_DIRS}) target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LIBTERMKEY_INCLUDE_DIRS})
target_link_libraries(main_lib INTERFACE ${LIBTERMKEY_LIBRARIES}) target_link_libraries(main_lib INTERFACE ${LIBTERMKEY_LIBRARIES})
find_package(LIBVTERM 0.3 REQUIRED) find_package(libvterm 0.3 REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LIBVTERM_INCLUDE_DIRS}) target_link_libraries(main_lib INTERFACE libvterm)
target_link_libraries(main_lib INTERFACE ${LIBVTERM_LIBRARIES})
find_package(Iconv REQUIRED) find_package(Iconv REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${Iconv_INCLUDE_DIRS}) target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${Iconv_INCLUDE_DIRS})