Compare commits

...

3 commits

Author SHA1 Message Date
Christian Burger ae6130f095 cmake: some improvements
* not depending on "-dev" packages for the built Debian package
* some refactoring in if-clauses and with "quotes"
* libvterm dependency: if something is missing, made clear what
2022-04-23 22:24:08 +02:00
Christian Burger f994cb2261 moved library system headers to separate folder
Gave the library a version in case it is build statically.
2022-04-23 20:27:55 +02:00
Christian Burger 2d7dda88c5 cmake: determines version from latest Git tag
Some other changes to the CMake-files done as well:
* documentation looks more like Doxygen-style
* prevent mix-up with C++ GSL library ("Guidelines support library" not
"GNU scientific library")
2022-04-23 10:00:33 +02:00
12 changed files with 142 additions and 33 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
build/
sandbox/
VERSION

View file

@ -54,5 +54,6 @@
"stdexcept": "cpp",
"typeinfo": "cpp",
"pointers": "cpp"
}
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View file

@ -3,8 +3,8 @@
*/
#include "App.hpp"
#include "Window.hpp"
#include "Debug.hpp"
#include <NCursesPtyWindow/Window.hpp>
#include <unistd.h>
#include <utmp.h>

View file

@ -1,52 +1,62 @@
##
# @author Christian Burger <christian@krikkel.de>
cmake_minimum_required(VERSION 3.16.3)
include("cmake/version.cmake")
project(NCursesPtyWindow
VERSION 0.1.0
HOMEPAGE_URL "https://gitea.xndr.de/christian/shellipt")
### 3.16.3 does not pick up the project's homepage URL by itself
HOMEPAGE_URL "https://gitea.xndr.de/christian/NCursesPtyWindow"
VERSION ${SEMANTIC_VERSION})
set(CMAKE_CXX_STANDARD 17)
include(CTest)
enable_testing()
include(ExternalProject)
include("cmake/ncurses.cmake")
include("cmake/gsl.cmake")
add_library(NCursesPtyWindow Window.cpp SingleUserInput.cpp Debug.cpp)
### path to own system includes
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/include")
### libraries
include("cmake/ncurses.cmake")
target_link_libraries(NCursesPtyWindow ${CURSES_LIBRARIES})
include("cmake/gsl.cmake")
include("cmake/libvterm.cmake")
if(EXISTS libvtermProject)
add_dependencies(NCursesPtyWindow libvtermProject)
endif()
target_link_libraries(NCursesPtyWindow ${LIBVTERM_LIBRARY})
find_library(UTIL_LIBRARY util)
target_link_libraries(NCursesPtyWindow ${UTIL_LIBRARY})
target_link_libraries(NCursesPtyWindow ${CURSES_LIBRARIES} ${LIBVTERM_LIBRARY} ${UTIL_LIBRARY})
### threads
set(THREADS_PREFER_PTHREAD_FLAG true)
find_package(Threads REQUIRED)
target_link_libraries(NCursesPtyWindow Threads::Threads)
### demo application
add_executable(NCursesPtyApp main.cpp App.cpp)
target_link_libraries(NCursesPtyApp ${CURSES_LIBRARIES} NCursesPtyWindow)
target_link_libraries(NCursesPtyApp NCursesPtyWindow)
### installation and packaging
set_target_properties(NCursesPtyWindow PROPERTIES PUBLIC_HEADER "Window.hpp;SingleUserInput.hpp")
install(TARGETS NCursesPtyWindow ARCHIVE PUBLIC_HEADER)
set(NCURSES_PTY_WINDOW_SYSTEM_INCLUDE "include/NCursesPtyWindow")
set_target_properties(NCursesPtyWindow PROPERTIES PUBLIC_HEADER "${NCURSES_PTY_WINDOW_SYSTEM_INCLUDE}/Window.hpp;${NCURSES_PTY_WINDOW_SYSTEM_INCLUDE}/SingleUserInput.hpp"
VERSION "${CMAKE_PROJECT_VERSION}")
include(GNUInstallDirs)
install(TARGETS NCursesPtyWindow ARCHIVE
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/NCursesPtyWindow/")
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_CONTACT "Christian Burger <christian@krikkel.de>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library for a pseudo terminal where the host end is a ncurses window")
# 3.16.3 does not pick up the project's homepage URL by itself
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CMAKE_PROJECT_HOMEPAGE_URL})
set(CPACK_GENERATOR "DEB" "TGZ")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libncursesw6 (>=6.2), libvterm-dev (>= 0.1.2)")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libncursesw6 (>=6.2), libvterm0 (>= 0.1.2)")
include(CPack)

View file

@ -2,7 +2,7 @@
* @author Christian Burger (christian@krikkel.de)
*/
#include "SingleUserInput.hpp"
#include <NCursesPtyWindow/SingleUserInput.hpp>
#include "Debug.hpp"
#include <vterm.h>

View file

@ -2,7 +2,7 @@
* @author Christian Burger (christian@krikkel.de)
*/
#include "Window.hpp"
#include <NCursesPtyWindow/Window.hpp>
#include "Debug.hpp"
#include <cstdio>

View file

@ -1,9 +1,11 @@
##
# @brief Includes Microsoft's "C++ Guidelines Standard Library"
# @author Christian Burger <christian@krikkel.de>
find_path(GSL_INCLUDE_DIR "gsl")
if(GSL_INCLUDE_DIR STREQUAL "GSL_INCLUDE_DIR-NOTFOUND")
find_path(GSL_INCLUDE_DIR "gsl/gsl" REQUIRED)
if(NOT GSL_INCLUDE_DIR)
message(SEND_ERROR "Microsoft GSL not found.")
else()
message(STATUS "Microsoft GSL found.")
message(STATUS "Found Microsoft C++ GSL.")
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
endif()

View file

@ -1,17 +1,31 @@
# @author Christian Burger <christian@krikkel.de>
# @brief searches for libvterm and builds it if not found
##
# @brief Includes `libvterm` (builds it if not found on the system).
#
# provides LIBVTERM_LIBRARY and include path
# dependency must be added like this:
# if(EXISTS libvtermProject)
# Provides ${LIBVTERM_LIBRARY} and implicitly adds path for correct
# `#include<>`.
#
# @warning dependency must be added like this:
# if(TARGET libvtermProject)
# add_dependencies(<targetDependingOn> libvtermProject)
# endif()
#
# @author Christian Burger <christian@krikkel.de>
find_library(LIBVTERM_LIBRARY NAMES libvterm.so.0.0.2 vterm)
find_library(LIBVTERM_LIBRARY NAMES "libvterm.so.0.0.2" "vterm")
find_path(LIBVTERM_INCLUDE "vterm.h")
if(LIBVTERM_LIBRARY STREQUAL "LIBVTERM_LIBRARY-NOTFOUND")
message(STATUS "libvterm not found — building it")
if(NOT LIBVTERM_LIBRARY)
message(STATUS "Did not find `libvterm.so`.")
set(LIBVTERM_BUILD_IT TRUE)
endif()
if(NOT LIBVTERM_INCLUDE)
message(STATUS "Did not find `vterm.h`.")
set(LIBVTERM_BUILD_IT TRUE)
endif()
if(LIBVTERM_BUILD_IT)
include(ExternalProject)
message(STATUS "Did not find libvterm (see previous error) — 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"
@ -22,4 +36,6 @@ if(LIBVTERM_LIBRARY STREQUAL "LIBVTERM_LIBRARY-NOTFOUND")
ExternalProject_Get_property(libvtermProject SOURCE_DIR)
set(LIBVTERM_LIBRARY "${SOURCE_DIR}/.libs/libvterm.a")
include_directories(SYSTEM "${SOURCE_DIR}/include")
else()
message(STATUS "Found vterm library.")
endif()

View file

@ -1,3 +1,5 @@
##
# @brief Includes the UTF-8 C++ version of the `ncurses` library.
# @author Christian Burger <christian@krikkel.de>
set(CURSES_NEED_NCURSES TRUE)
@ -6,8 +8,8 @@ find_package(Curses 6.2 REQUIRED)
include_directories(SYSTEM ${CURSES_INCLUDE_DIRS})
# find C++ interface for ncurses with unicode support
find_library(CURSES_CPP_WIDE_LIBRARY NAMES ncurses++w REQUIRED)
find_library(CURSES_CPP_WIDE_LIBRARY NAMES ncurses++w)
if(NOT CURSES_CPP_WIDE_LIBRARY)
message(FATAL_ERROR "C++ interface for ncurses (wide/unicode) not found.")
message(SEND_ERROR "C++ interface for ncurses (wide/unicode) not found.")
endif()
list(APPEND CURSES_LIBRARIES ${CURSES_CPP_WIDE_LIBRARY})

77
cmake/version.cmake Normal file
View file

@ -0,0 +1,77 @@
##
# @brief a ${SEMANTIC_VERSION} based on Git tags (or a `VERSION` file) à la
# `v<major>.<minor>.<patch>` is provided
#
# Versions have the format "v<major>.<minor>.<patch>" in accordance with
# Semantic Versioning. If a version is provided by a file named `VERSION`, the
# full version must be given. If a version is provided by Git tags, only part of
# the version must be given, the format is then: "v<major>.<minor>". The <patch>
# version is automatically deduced from the distance in commits to the latest
# Git tag. The version set in the file overrides the tags in the Git repository.
#
# based upon Semantic Versioning: https://semver.org/
#
# @attention The <patch> version-part is a bit flaky; it gives the distance in
# commits to the <major>.<minor> version. Due to the non-linear
# nature of the commit history (because of branches), it is ambigous
# (i. e. multiple commits can be found at the same distance). On top
# of that, it is your job to make sure, that patches only fix bugs
# and do not change the API (no new functionalty; or old removed).
#
# One option to address both issues is: Stay in one branch for
# releases for example named 'release' and cherry-pick new
# versions into the branch (alphas, betas, candidates and releases).
# Optional: squash cherry-picked commits, so that the <patch> part of
# the version is only incremented by one.
# @warning To update the version you have to run CMake again.
#
# @todo escape/quote paths
# @todo test cases for CMake file components?
# @todo make variables local (see: unset()) and put them in a "namespace"
# @author Christian Burger <christian@krikkel.de>
find_package(Git)
function(get_semantic_version)
if(EXISTS "${CMAKE_SOURCE_DIR}/VERSION")
message(STATUS "using file `VERSION` to determine version")
file(READ "VERSION" REPOSITORY_VERSION)
elseif(GIT_FOUND)
message(STATUS "using Git to determine project version")
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_SOURCE_DIR} describe --always --match v[0-9]*.[0-9]*
OUTPUT_VARIABLE REPOSITORY_VERSION)
else()
message(WARNING "We need Git or a file \"VERSION\" to determine a version (e. g. \"v1.0\").")
endif()
# test cases
#set(REPOSITORY_VERSION "v0.1") # = 0.1.0
#set(REPOSITORY_VERSION "v0.1-1-g12345678") # = 0.1.1
#set(REPOSITORY_VERSION "v0.1") # = 0.0.0
#set(REPOSITORY_VERSION "1234abcd") # = 0.0.0
#set(REPOSITORY_VERSION "") # = 0.1.0
string(REGEX MATCH "^v([0-9]+)\.([0-9]+)([-\\.]([0-9]+))?" SEMANTIC_VERSION_PREPROCESSED "${REPOSITORY_VERSION}")
if("${SEMANTIC_VERSION_PREPROCESSED}" STREQUAL "")
message(STATUS "Found no version tag (e. g. \"v1.0\").")
endif()
set(SEMANTIC_VERSION_MAJOR ${CMAKE_MATCH_1})
set(SEMANTIC_VERSION_MINOR ${CMAKE_MATCH_2})
set(SEMANTIC_VERSION_PATCH ${CMAKE_MATCH_4})
if("${SEMANTIC_VERSION_MAJOR}" STREQUAL "")
set(SEMANTIC_VERSION "0.0.0")
else()
if("${SEMANTIC_VERSION_PATCH}" STREQUAL "")
set(SEMANTIC_VERSION_PATCH "0")
endif()
set(SEMANTIC_VERSION "${SEMANTIC_VERSION_MAJOR}.${SEMANTIC_VERSION_MINOR}.${SEMANTIC_VERSION_PATCH}")
endif()
message(STATUS "Project version is: ${SEMANTIC_VERSION}")
set(SEMANTIC_VERSION "${SEMANTIC_VERSION}" PARENT_SCOPE)
endfunction()
get_semantic_version()