From 8e71512f123bed8a99b0890a8a3f1541174fb59a Mon Sep 17 00:00:00 2001 From: Christian Burger Date: Wed, 13 Apr 2022 13:10:55 +0200 Subject: [PATCH] cmake: locate or build `libvterm` dependency There is no version detection. If there is any vterm library, it is used. If it is the wrong version, there will be an build error. `libvterm.so.0.0.2` is preferred, which hopefully is compatible to revision 740 or Ubuntu `libvterm0` version 0.1.2-2. If no library is found, the correct one is downloaded and build. --- CMakeLists.txt | 8 ++++++-- cmake/gsl.cmake | 2 ++ cmake/libvterm.cmake | 21 +++++++++++++++++++++ cmake/ncurses.cmake | 2 ++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 cmake/libvterm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e8be85d..37de1f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +# @author Christian Burger + cmake_minimum_required(VERSION 3.16.3) project(NCursesPtyWindow VERSION 0.1.0) @@ -6,15 +8,17 @@ set(CMAKE_CXX_STANDARD 17) include(CTest) enable_testing() +include(ExternalProject) include("cmake/ncurses.cmake") include("cmake/gsl.cmake") +add_library(NCursesPtyWindow NCursesPtyWindow.cpp SingleUserInput.cpp Debug.cpp) ### libraries -find_library(LIBVTERM_LIBRARY vterm) + +include("cmake/libvterm.cmake") find_library(UTIL_LIBRARY util) -add_library(NCursesPtyWindow NCursesPtyWindow.cpp SingleUserInput.cpp Debug.cpp) target_link_libraries(NCursesPtyWindow ${CURSES_LIBRARIES} ${LIBVTERM_LIBRARY} ${UTIL_LIBRARY}) ### threads diff --git a/cmake/gsl.cmake b/cmake/gsl.cmake index f55f87b..dd4cd95 100644 --- a/cmake/gsl.cmake +++ b/cmake/gsl.cmake @@ -1,3 +1,5 @@ +# @author Christian Burger + find_path(GSL_INCLUDE_DIR "gsl") if(GSL_INCLUDE_DIR STREQUAL "GSL_INCLUDE_DIR-NOTFOUND") message(SEND_ERROR "Microsoft GSL not found.") diff --git a/cmake/libvterm.cmake b/cmake/libvterm.cmake new file mode 100644 index 0000000..95e6eb3 --- /dev/null +++ b/cmake/libvterm.cmake @@ -0,0 +1,21 @@ +# @author Christian Burger +# @brief searches for libvterm and builds it if not found +# +# requires NCursesPtyWindow target; provides LIBVTERM_LIBRARY + +find_library(LIBVTERM_LIBRARY NAMES libvterm.so.0.0.2 vterm) + +if(LIBVTERM_LIBRARY STREQUAL "LIBVTERM_LIBRARY-NOTFOUND") + message(STATUS "libvterm not found — building it") + ExternalProject_Add( + libvtermProject + DOWNLOAD_COMMAND URL "https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/libvterm/0.1.2-2/libvterm_0.1.2.orig.tar.gz" + CONFIGURE_COMMAND "" + BUILD_IN_SOURCE true + INSTALL_COMMAND "" + ) + ExternalProject_Get_property(libvtermProject SOURCE_DIR) + set(LIBVTERM_LIBRARY "${SOURCE_DIR}/.libs/libvterm.a") + include_directories(SYSTEM "${SOURCE_DIR}/include") + add_dependencies(NCursesPtyWindow libvtermProject) +endif() diff --git a/cmake/ncurses.cmake b/cmake/ncurses.cmake index 1069824..6643fa1 100644 --- a/cmake/ncurses.cmake +++ b/cmake/ncurses.cmake @@ -1,3 +1,5 @@ +# @author Christian Burger + ### ncurses set(CURSES_NEED_NCURSES TRUE) set(CURSES_NEED_WIDE TRUE)