Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
# Test the minimum supported cmake.
linux:
runs-on: ubuntu-latest
timeout-minutes: 15
Expand All @@ -32,3 +31,22 @@ jobs:

- name: Run tests
run: make test

linux-cmake:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7.0.0
with:
persist-credentials: false

- name: Install dependencies
run: sudo apt --update install build-essential libncurses-dev cmake

- name: Build
run: |
cmake -B build .
cmake --build build

- name: Run tests
run: ctest --test-dir build --output-on-failure
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ tools/*
/.maint
/tags

!CMakeLists.txt

# autoreconf
aclocal.m4
autom4te.cache/
Expand Down
47 changes: 43 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(unibilium LANGUAGES C VERSION 2.1.3)

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.c)
add_library(unibilium ${SRC_FILES})
set_target_properties(unibilium PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h
VERSION "${VERSION_MAJOR}.${VERSION_MINOR}")
add_library(unibilium
unibilium.c
uninames.c
uniutil.c
)
set_target_properties(unibilium PROPERTIES
PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h
# Keep in sync with Makefile.in
# "$LT_CURRENT - $LT_AGE.$LT_AGE.$LT_REVISION"
VERSION "4.0.1"
# "$LT_CURRENT - $LT_AGE"
SOVERSION "4")
target_compile_features(unibilium PRIVATE c_std_99)

if(NOT WIN32)
execute_process(COMMAND sh -c "ncursesw6-config --terminfo-dirs 2>/dev/null || \
Expand All @@ -15,13 +24,43 @@ if(NOT WIN32)
OUTPUT_VARIABLE TERMINFO_DIRS_DEFAULT)
# Remove trailing newline
string(STRIP "${TERMINFO_DIRS_DEFAULT}" TERMINFO_DIRS_DEFAULT)

execute_process(COMMAND sh -c "ncursesw6-config --terminfo 2>/dev/null || \
ncurses6-config --terminfo 2>/dev/null || \
ncursesw5-config --terminfo 2>/dev/null || \
ncurses5-config --terminfo 2>/dev/null || \
echo '/usr/share/terminfo'"
OUTPUT_VARIABLE TERMINFO_DEFAULT)
# Remove trailing newline
string(STRIP "${TERMINFO_DEFAULT}" TERMINFO_DEFAULT)
else()
set(TERMINFO_DIRS_DEFAULT "")
set(TERMINFO_DEFAULT "")
endif()
set(TERMINFO_DIRS "${TERMINFO_DIRS_DEFAULT}" CACHE STRING "Colon-separated list of directories where unibilium should look for compiled terminfo files at runtime")
target_compile_definitions(unibilium PUBLIC "TERMINFO_DIRS=\"${TERMINFO_DIRS}\"")
set(TERMINFO "${TERMINFO_DEFAULT}" CACHE STRING "Directory where unibilium should look for compiled terminfo files at runtime")
target_compile_definitions(unibilium PUBLIC "TERMINFO=\"${TERMINFO}\"")

include(GNUInstallDirs)

if(NOT WIN32)
add_subdirectory(doc)
set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
set(INCDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set(VERSION ${PROJECT_VERSION})
configure_file(unibilium.pc.in unibilium.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unibilium.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
unset(LIBDIR)
unset(INCDIR)
unset(VERSION)
endif()
add_subdirectory(tools)

enable_testing()
add_subdirectory(t)

install(TARGETS unibilium
PUBLIC_HEADER
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
5 changes: 3 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ STATIC_TEST_FILES:= \
t/static_screen-256color.c \
t/static_screen.c \
t/static_tmux.c \
t/static_xterm-256color.c
t/static_xterm-256color.c \
t/static_xterm.c
.PHONY: regenerate-tests
regenerate-tests:
$(RM) $(STATIC_TEST_FILES)
$(MAKE) $(STATIC_TEST_FILES)

t/static_%.c: | tools/gen-static-test
$< $(patsubst t/static_%.c,%,$@) > $@
$| $(patsubst t/static_%.c,%,$@) > $@
86 changes: 86 additions & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
if(NOT CMAKE_SKIP_INSTALL_RULES)
find_program(PROG_GZIP gzip)
if(NOT PROG_GZIP)
message(FATAL_ERROR "Missing gzip. Set CMAKE_SKIP_INSTALL_RULES to skip man pages.")
endif()

find_program(PROG_POD2MAN pod2man)
if(NOT PROG_POD2MAN)
message(FATAL_ERROR "Missing pod2man. Set CMAKE_SKIP_INSTALL_RULES to skip man pages.")
endif()

macro(unibi_pod2man basename)
set(OUT_MAN_FILE "${CMAKE_CURRENT_BINARY_DIR}/${basename}.3")
set(OUT_GZ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${basename}.3.gz")
add_custom_command(
OUTPUT "${OUT_MAN_FILE}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.pod"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND pod2man --center "${PROJECT_NAME}" --section 3 --release "${PROJECT_NAME}-${PROJECT_VERSION}" "${basename}.pod" "${OUT_MAN_FILE}")
add_custom_command(
OUTPUT "${OUT_GZ_FILE}"
DEPENDS "${OUT_MAN_FILE}"
COMMAND gzip --stdout "${OUT_MAN_FILE}" > "${OUT_GZ_FILE}")
add_custom_target(man_page_${basename}
DEPENDS "${OUT_GZ_FILE}")
add_dependencies(man_pages man_page_${basename})
install(FILES "${OUT_GZ_FILE}"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man3/")
endmacro()

add_custom_target(man_pages ALL)

unibi_pod2man(unibi_add_ext_bool)
unibi_pod2man(unibi_add_ext_num)
unibi_pod2man(unibi_add_ext_str)
unibi_pod2man(unibi_count_ext_bool)
unibi_pod2man(unibi_count_ext_num)
unibi_pod2man(unibi_count_ext_str)
unibi_pod2man(unibi_del_ext_bool)
unibi_pod2man(unibi_destroy)
unibi_pod2man(unibi_dummy)
unibi_pod2man(unibi_dump)
unibi_pod2man(unibi_format)
unibi_pod2man(unibi_from_env)
unibi_pod2man(unibi_from_fd)
unibi_pod2man(unibi_from_file)
unibi_pod2man(unibi_from_fp)
unibi_pod2man(unibi_from_mem)
unibi_pod2man(unibi_from_term)
unibi_pod2man(unibi_get_aliases)
unibi_pod2man(unibi_get_bool)
unibi_pod2man(unibi_get_ext_bool_name)
unibi_pod2man(unibi_get_ext_bool)
unibi_pod2man(unibi_get_ext_num_name)
unibi_pod2man(unibi_get_ext_num)
unibi_pod2man(unibi_get_ext_str_name)
unibi_pod2man(unibi_get_ext_str)
unibi_pod2man(unibi_get_name)
unibi_pod2man(unibi_get_num)
unibi_pod2man(unibi_get_str)
unibi_pod2man(unibi_int_from_var)
unibi_pod2man(unibilium.h)
unibi_pod2man(unibi_name_bool)
unibi_pod2man(unibi_name_num)
unibi_pod2man(unibi_name_str)
unibi_pod2man(unibi_num_from_var)
unibi_pod2man(unibi_run)
unibi_pod2man(unibi_set_aliases)
unibi_pod2man(unibi_set_bool)
unibi_pod2man(unibi_set_ext_bool_name)
unibi_pod2man(unibi_set_ext_bool)
unibi_pod2man(unibi_set_ext_num_name)
unibi_pod2man(unibi_set_ext_num)
unibi_pod2man(unibi_set_ext_str_name)
unibi_pod2man(unibi_set_ext_str)
unibi_pod2man(unibi_set_name)
unibi_pod2man(unibi_set_num)
unibi_pod2man(unibi_set_str)
unibi_pod2man(unibi_short_name_bool)
unibi_pod2man(unibi_short_name_num)
unibi_pod2man(unibi_short_name_str)
unibi_pod2man(unibi_str_from_var)
unibi_pod2man(unibi_terminfo_dirs)
unibi_pod2man(unibi_var_from_num)
unibi_pod2man(unibi_var_from_str)
endif()
36 changes: 36 additions & 0 deletions t/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
macro(unibi_test basename)
add_executable(${basename} "${basename}.c")
target_include_directories(${basename} PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${basename} unibilium)
add_test(
NAME ${basename}
COMMAND prove -f $<TARGET_FILE:${basename}>
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endmacro()

unibi_test(00_load)
unibi_test(if-then-else)
unibi_test(new-extended-format-static_screen)
unibi_test(static_screen-256color)
unibi_test(static_screen)
unibi_test(static_tmux)
unibi_test(static_xterm-256color)
unibi_test(static_xterm)
unibi_test(wide-format)

macro(regen termname)
set(OUT_STATIC_FILE "static_${termname}.c")
add_custom_target(regen-${termname}
COMMAND gen-static-test "${termname}" > "${CMAKE_CURRENT_BINARY_DIR}/${OUT_STATIC_FILE}")
add_custom_target(copy-${termname}
DEPENDS regen-${termname}
COMMAND cmake -E copy "${CMAKE_CURRENT_BINARY_DIR}/${OUT_STATIC_FILE}" ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(regenerate-tests regen-${termname})
endmacro()

add_custom_target(regenerate-tests)
regen(screen-256color)
regen(screen)
regen(tmux)
regen(xterm-256color)
regen(xterm)
10 changes: 10 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
macro(unibi_tool basename)
add_executable(${basename} "${basename}.c")
target_link_libraries(${basename} unibilium)
target_include_directories(${basename} PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_features(${basename} PRIVATE c_std_99)
endmacro()

unibi_tool(unibi-dump)
unibi_tool(unibi-put)
unibi_tool(gen-static-test)
13 changes: 10 additions & 3 deletions tools/gen-static-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static void print_str_esc(const char *s, int twice) {
}
}

enum {MAX_BUF = 32768};
int main(int argc, char **argv) {
unibi_term *ut;
if (argc < 2) {
Expand All @@ -68,10 +69,15 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}

char buf[4096];
size_t r = unibi_dump(ut, buf, sizeof buf);
if (r > sizeof buf) {
char *buf = malloc(MAX_BUF);
if (!buf) {
perror("malloc()");
return EXIT_FAILURE;
}
size_t r = unibi_dump(ut, buf, MAX_BUF);
if (r > MAX_BUF) {
perror("unibi_dump()");
free(buf);
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -324,6 +330,7 @@ int main(int argc, char **argv) {
say("}");

unibi_destroy(ut);
free(buf);

say("");
say("static void setup(void) {");
Expand Down