CMake-ify, rename to termkey2 for the time being

This commit is contained in:
Přemysl Eric Janouch 2014-10-09 23:47:24 +02:00
parent 3465d5553f
commit 5692f32bcf
33 changed files with 258 additions and 206 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Qt Creator
/CMakeLists.txt.user*

151
CMakeLists.txt Normal file
View File

@ -0,0 +1,151 @@
project (termkey2 C)
cmake_minimum_required (VERSION 2.8.5)
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
set (CMAKE_C_FLAGS "-std=c99")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
# Version
set (project_VERSION_MAJOR 0)
set (project_VERSION_MINOR 1)
set (project_VERSION_PATCH 0)
set (project_VERSION ${project_VERSION_MAJOR})
set (project_VERSION ${project_VERSION}.${project_VERSION_MINOR})
set (project_VERSION ${project_VERSION}.${project_VERSION_PATCH})
set (project_API_VERSION ${project_VERSION_MAJOR})
# Names
set (project_LIB_NAME "termkey2-${project_API_VERSION}")
set (project_INCLUDE_NAME "termkey2-${project_API_VERSION}")
set (project_CMAKE_NAME "TermKey2")
# Dependecies
find_package (Curses)
find_package (PkgConfig REQUIRED)
pkg_check_modules (glib glib-2.0 gio-2.0)
pkg_check_modules (unibilium unibilium>=0.1.0)
# Header files with configuration
configure_file (${PROJECT_SOURCE_DIR}/termkey2-config.h.in
${PROJECT_BINARY_DIR}/termkey2-config.h)
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
# Project source files
set (lib_sources
termkey2.c
driver-csi.c
driver-ti.c)
set (lib_headers
termkey2.h
termkey2-internal.h
${PROJECT_BINARY_DIR}/termkey2-config.h)
# Project libraries
if (unibilium_FOUND)
include_directories (${unibilium_INCLUDE_DIRS})
set (lib_libraries ${unibilium_LIBRARIES})
add_definitions (-DHAVE_UNIBILIUM)
elseif (CURSES_FOUND)
include_directories (${CURSES_INCLUDE_DIR})
set (lib_libraries ${CURSES_LIBRARY})
else (CURSES_FOUND)
message (SEND_ERROR "Unibilium not found, Curses not found")
endif (unibilium_FOUND)
# Create the library targets
add_library (termkey2 SHARED ${lib_sources} ${lib_headers})
target_link_libraries (termkey2 ${lib_libraries})
set_target_properties (termkey2 PROPERTIES
OUTPUT_NAME ${project_LIB_NAME}
VERSION ${project_VERSION}
SOVERSION ${project_API_VERSION})
add_library (termkey2-static STATIC ${lib_sources} ${lib_headers})
target_link_libraries (termkey2-static ${lib_libraries})
set_target_properties (termkey2-static PROPERTIES
OUTPUT_NAME ${project_LIB_NAME}
VERSION ${project_VERSION}
SOVERSION ${project_API_VERSION})
# Demos
add_executable (demo-async EXCLUDE_FROM_ALL demo-async.c)
target_link_libraries (demo-async termkey2-static ${lib_libraries})
add_executable (demo EXCLUDE_FROM_ALL demo.c)
target_link_libraries (demo termkey2-static ${lib_libraries})
set (demos demo demo-async)
if (glib_FOUND)
include_directories (${glib_INCLUDE_DIRS})
add_executable (demo-glib EXCLUDE_FROM_ALL demo-glib.c)
target_link_libraries (demo
termkey2-static ${lib_libraries} ${glib_LIBRARIES})
list (APPEND demos demo-glib)
endif (glib_FOUND)
add_custom_target (demos DEPENDS ${demos})
# The files to be installed
include (GNUInstallDirs)
install (TARGETS termkey2 termkey2-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
install (FILES termkey2.h ${PROJECT_BINARY_DIR}/termkey2-config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${project_INCLUDE_NAME})
# Configuration for other CMake projects
configure_file (config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake @ONLY)
configure_file (config-version.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake @ONLY)
install (FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${project_VERSION})
# Do some unit tests
option (BUILD_TESTING "Build tests" OFF)
# TODO: glob, port the tests to CTest
set (project_tests)
if (BUILD_TESTING)
enable_testing ()
set (test_common_sources t/taplib.c t/taplib.h)
foreach (name ${project_tests})
add_executable (test-${name} t/${name}.c ${test_common_sources})
target_link_libraries (test-${name} ${lib_libraries})
add_test (test-${name} test-${name})
endforeach (name)
endif (BUILD_TESTING)
# pkg-config
file (WRITE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc"
"Name: ${PROJECT_NAME}\n"
"Description: Terminal key input library\n"
"Version: ${project_VERSION}\n"
"Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${project_LIB_NAME}\n"
"Libs.private: ${lib_libraries}\n"
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${project_INCLUDE_NAME}\n")
install (FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Terminal key input library")
set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p.janouch@gmail.com>")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
set (CPACK_GENERATOR "TGZ;ZIP")
set (CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME}-${project_VERSION}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${project_VERSION}")
include (CPack)

178
Makefile
View File

@ -1,178 +0,0 @@
ifeq ($(shell uname),Darwin)
LIBTOOL ?= glibtool
else
LIBTOOL ?= libtool
endif
ifneq ($(VERBOSE),1)
LIBTOOL +=--quiet
endif
CFLAGS +=-Wall -Wextra -std=c99
ifeq ($(DEBUG),1)
CFLAGS +=-ggdb -DDEBUG
endif
ifeq ($(PROFILE),1)
CFLAGS +=-pg
LDFLAGS+=-pg
endif
ifeq ($(shell pkg-config --atleast-version=0.1.0 unibilium && echo 1),1)
CFLAGS +=$(shell pkg-config --cflags unibilium) -DHAVE_UNIBILIUM
LDFLAGS+=$(shell pkg-config --libs unibilium)
else ifeq ($(shell pkg-config tinfo && echo 1),1)
CFLAGS +=$(shell pkg-config --cflags tinfo)
LDFLAGS+=$(shell pkg-config --libs tinfo)
else ifeq ($(shell pkg-config ncursesw && echo 1),1)
CFLAGS +=$(shell pkg-config --cflags ncursesw)
LDFLAGS+=$(shell pkg-config --libs ncursesw)
else
LDFLAGS+=-lncurses
endif
OBJECTS=termkey.lo driver-csi.lo driver-ti.lo
LIBRARY=libtermkey.la
DEMOS=demo demo-async
ifeq ($(shell pkg-config glib-2.0 && echo 1),1)
DEMOS+=demo-glib
endif
DEMO_OBJECTS=$(DEMOS:=.lo)
TESTSOURCES=$(wildcard t/[0-9]*.c)
TESTFILES=$(TESTSOURCES:.c=.t)
VERSION_MAJOR=0
VERSION_MINOR=17
VERSION_CURRENT=12
VERSION_REVISION=0
VERSION_AGE=11
PREFIX=/usr/local
LIBDIR=$(PREFIX)/lib
INCDIR=$(PREFIX)/include
MANDIR=$(PREFIX)/share/man
MAN3DIR=$(MANDIR)/man3
MAN7DIR=$(MANDIR)/man7
all: $(LIBRARY) $(DEMOS)
%.lo: %.c termkey.h termkey-internal.h
$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $<
$(LIBRARY): $(OBJECTS)
$(LIBTOOL) --mode=link --tag=CC $(CC) -rpath $(LIBDIR) -version-info $(VERSION_CURRENT):$(VERSION_REVISION):$(VERSION_AGE) $(LDFLAGS) -o $@ $^
demo: $(LIBRARY) demo.lo
$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^
demo-async: $(LIBRARY) demo-async.lo
$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^
demo-glib.lo: demo-glib.c termkey.h
$(LIBTOOL) --mode=compile --tag=CC $(CC) -o $@ -c $< $(shell pkg-config glib-2.0 --cflags)
demo-glib: $(LIBRARY) demo-glib.lo
$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^ $(shell pkg-config glib-2.0 --libs)
t/%.t: t/%.c $(LIBRARY) t/taplib.lo
$(LIBTOOL) --mode=link --tag=CC $(CC) -o $@ $^
t/taplib.lo: t/taplib.c
$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -o $@ -c $^
.PHONY: test
test: $(TESTFILES)
prove -e ""
.PHONY: clean-test
clean-test:
$(LIBTOOL) --mode=clean rm -f $(TESTFILES) t/taplib.lo
.PHONY: clean
clean: clean-test
$(LIBTOOL) --mode=clean rm -f $(OBJECTS) $(DEMO_OBJECTS)
$(LIBTOOL) --mode=clean rm -f $(LIBRARY)
$(LIBTOOL) --mode=clean rm -rf $(DEMOS)
.PHONY: install
install: install-inc install-lib install-man
$(LIBTOOL) --mode=finish $(DESTDIR)$(LIBDIR)
install-inc: termkey.h
install -d $(DESTDIR)$(INCDIR)
install -m644 termkey.h $(DESTDIR)$(INCDIR)
install -d $(DESTDIR)$(LIBDIR)/pkgconfig
sed "s,@LIBDIR@,$(LIBDIR),;s,@INCDIR@,$(INCDIR)," <termkey.pc.in >$(DESTDIR)$(LIBDIR)/pkgconfig/termkey.pc
install-lib: $(LIBRARY)
install -d $(DESTDIR)$(LIBDIR)
$(LIBTOOL) --mode=install install libtermkey.la $(DESTDIR)$(LIBDIR)/libtermkey.la
install-man:
install -d $(DESTDIR)$(MAN3DIR)
install -d $(DESTDIR)$(MAN7DIR)
for F in man/*.3; do \
gzip <$$F >$(DESTDIR)$(MAN3DIR)/$${F#man/}.gz; \
done
for F in man/*.7; do \
gzip <$$F >$(DESTDIR)$(MAN7DIR)/$${F#man/}.gz; \
done
while read FROM EQ TO; do \
echo ln -sf $$TO.gz $(DESTDIR)$(MAN3DIR)/$$FROM.gz; \
done < man/also
# DIST CUT
MANSOURCE=$(wildcard man/*.3.sh)
BUILTMAN=$(MANSOURCE:.3.sh=.3)
VERSION=$(VERSION_MAJOR).$(VERSION_MINOR)
all: doc
doc: $(BUILTMAN)
%.3: %.3.sh
sh $< >$@
clean: clean-built
clean-built:
rm -f $(BUILTMAN) termkey.h
termkey.h: termkey.h.in Makefile
rm -f $@
sed -e 's/@@VERSION_MAJOR@@/$(VERSION_MAJOR)/g' \
-e 's/@@VERSION_MINOR@@/$(VERSION_MINOR)/g' \
$< >$@
chmod a-w $@
DISTDIR=libtermkey-$(VERSION)
distdir: all
mkdir __distdir
cp *.c *.h LICENSE __distdir
mkdir __distdir/t
cp t/*.c t/*.h __distdir/t
mkdir __distdir/man
cp man/*.[37] man/also __distdir/man
sed "s,@VERSION@,$(VERSION)," <termkey.pc.in >__distdir/termkey.pc.in
sed "/^# DIST CUT/Q" <Makefile >__distdir/Makefile
mv __distdir $(DISTDIR)
TARBALL=$(DISTDIR).tar.gz
dist: distdir
tar -czf $(TARBALL) $(DISTDIR)
rm -rf $(DISTDIR)
HTMLDIR=html
htmldocs: $(BUILTMAN)
perl $(HOME)/src/perl/Parse-Man/examples/man-to-html.pl -O $(HTMLDIR) --file-extension tmpl --link-extension html --template home_lou.tt2 --also man/also man/*.3 man/*.7 --index index.tmpl

60
README Normal file
View File

@ -0,0 +1,60 @@
termkey2
========
`termkey2' is a library providing an alternative to ncurses' handling of
terminal input. ncurses does a really terrible job at that, mainly wrt. mouse
support which seems to be utterly broken. If you can drag things in a terminal
application, such as in VIM, I can assure you it's not using ncurses for that.
Since terminal I/O is really complicated and full of special cases, this project
doesn't aspire to also replace the output part of ncurses, but is rather
complementary to it. In the end it makes use of its terminfo library.
The API isn't stable yet. Tell me what needs to be done so I can fix it first.
Building and Installing
-----------------------
Build dependencies: GCC/Clang, pkg-config, cmake >= 2.8.5
Optional dependencies: Unibilium (alternative for curses), GLib (for the demos)
$ git clone https://github.com/pjanouch/termkey2.git
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
To install the library, you can do either the usual:
$ make install
Or you can try telling CMake to make a package for you. For Debian it is:
$ cpack -G DEB
# dpkg -i termkey2-*.deb
To see the library in action, you can try running the demos, which are
statically linked against the library, and hence they can be run as they are:
$ make demos
What's Different From the Original termkey?
-------------------------------------------
The main change is throwing away any UTF-8 dependent code, making the library
capable of handling all unibyte and multibyte encodings supported by iconv on
your system. The characters are still presented as Unicode at the end, however,
as the other sensible option is wchar_t and that doesn't really work well, see
http://gnu.org/software/libunistring/manual/libunistring.html#The-wchar_005ft-mess
Another change worth mentioning is the usage of CMake instead of the problematic
libtool-based Makefile. Now you can include this project in your other CMake-
-based projects and simply import the target. No package maintainer action is
needed for you to enjoy the benefits of proper terminal input.
The rest is just me going silly over formatting and various unimportant stuff.
Oh, and I've deleted the manpages. It needs more Doxygen. :) TBD
License
-------
`termkey2' is based on the `termkey' library originally written by Paul Evans
<leonerd@leonerd.org.uk>, with additional changes made by Přemysl Janouch
<p.janouch@gmail.com>.
You may use the software under the terms of the MIT license, the text of which
is included within the package, see the file LICENSE.

10
config-version.cmake.in Normal file
View File

@ -0,0 +1,10 @@
set (PACKAGE_VERSION "@project_VERSION@")
if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set (PACKAGE_VERSION_COMPATIBLE FALSE)
else ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set (PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set (PACKAGE_VERSION_EXACT TRUE)
endif ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
endif ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")

8
config.cmake.in Normal file
View File

@ -0,0 +1,8 @@
# - Config file for @project_CMAKE_NAME@
# It defines the following variables:
# @project_CMAKE_NAME@_INCLUDE_DIRS
# @project_CMAKE_NAME@_LIBRARIES
set (@project_CMAKE_NAME@_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@project_INCLUDE_NAME@)
set (@project_CMAKE_NAME@_LIBRARIES termkey2)

View File

@ -6,7 +6,7 @@
#include <unistd.h>
#include <locale.h>
#include "termkey.h"
#include "termkey2.h"
static void
on_key (termkey_t *tk, termkey_key_t *key)

View File

@ -3,7 +3,7 @@
#include <unistd.h>
#include <locale.h>
#include "termkey.h"
#include "termkey2.h"
static termkey_t *tk;
static int timeout_id;

2
demo.c
View File

@ -6,7 +6,7 @@
#include <errno.h>
#include <locale.h>
#include "termkey.h"
#include "termkey2.h"
int
main(int argc, char *argv[])

View File

@ -1,5 +1,5 @@
#include "termkey.h"
#include "termkey-internal.h"
#include "termkey2.h"
#include "termkey2-internal.h"
#include <stdio.h>
#include <string.h>

View File

@ -1,8 +1,8 @@
// we want strdup()
#define _XOPEN_SOURCE 600
#include "termkey.h"
#include "termkey-internal.h"
#include "termkey2.h"
#include "termkey2-internal.h"
#ifdef HAVE_UNIBILIUM
# include <unibilium.h>
@ -240,7 +240,7 @@ load_terminfo (termkey_ti_t *ti, const char *term)
if (node && !insert_seq (ti, value, node))
{
free(node);
free (node);
return 0;
}
}

View File

@ -1,8 +0,0 @@
libdir=@LIBDIR@
includedir=@INCDIR@
Name: termkey
Description: Abstract terminal key input library
Version: @VERSION@
Libs: -L${libdir} -ltermkey
Cflags: -I${includedir}

8
termkey2-config.h.in Normal file
View File

@ -0,0 +1,8 @@
#ifndef TERMKEY2_CONFIG_H
#define TERMKEY2_CONFIG_H
#define TERMKEY_VERSION_MAJOR @project_VERSION_MAJOR@
#define TERMKEY_VERSION_MINOR @project_VERSION_MINOR@
#endif // ! TERMKEY2_CONFIG_H

View File

@ -1,7 +1,7 @@
#ifndef TERMKEY_INTERNAL_H
#define TERMKEY_INTERNAL_H
#ifndef TERMKEY2_INTERNAL_H
#define TERMKEY2_INTERNAL_H
#include "termkey.h"
#include "termkey2.h"
#include <stdint.h>
#include <termios.h>
@ -111,5 +111,5 @@ termkey_key_set_linecol (termkey_key_t *key, int line, int col)
extern termkey_driver_t termkey_driver_csi;
extern termkey_driver_t termkey_driver_ti;
#endif // ! TERMKEY_INTERNAL_H
#endif // ! TERMKEY2_INTERNAL_H

View File

@ -1,5 +1,5 @@
#include "termkey.h"
#include "termkey-internal.h"
#include "termkey2.h"
#include "termkey2-internal.h"
#include <ctype.h>
#include <errno.h>
@ -739,7 +739,7 @@ emit_codepoint (termkey_t *tk, uint32_t codepoint, termkey_key_t *key)
* lowercase
*/
if (codepoint + 0x40 >= 'A' && codepoint + 0x40 <= 'Z')
// It's a letter - use lowecase instead
// It's a letter - use lowercase instead
key->code.codepoint = codepoint + 0x60;
else
key->code.codepoint = codepoint + 0x40;

View File

@ -1,12 +1,11 @@
#ifndef TERMKEY_H
#define TERMKEY_H
#ifndef TERMKEY2_H
#define TERMKEY2_H
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#define TERMKEY_VERSION_MAJOR @@VERSION_MAJOR@@
#define TERMKEY_VERSION_MINOR @@VERSION_MINOR@@
#include "termkey2-config.h"
#define TERMKEY_CHECK_VERSION \
termkey_check_version (TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR)
@ -268,5 +267,5 @@ const char *termkey_strpkey (termkey_t *tk, const char *str,
int termkey_keycmp (termkey_t *tk,
const termkey_key_t *key1, const termkey_key_t *key2);
#endif // ! TERMKEY_H
#endif // ! TERMKEY2_H