Skip to content

Commit 7b3f9fe

Browse files
committed
add cmake
1 parent 2fa0f10 commit 7b3f9fe

8 files changed

Lines changed: 143 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.14...3.24)
2+
3+
project(PDCurses
4+
LANGUAGES C
5+
VERSION 3.9
6+
DESCRIPTION "PDCurses - a curses library for environments that don't fit the termcap/terminfo model."
7+
HOMEPAGE_URL "https://github.com/wmcbrine/PDCurses")
8+
9+
# --- auto-ignore build directory
10+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
11+
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
12+
endif()
13+
14+
15+
add_library(pdcurses)
16+
set_target_properties(pdcurses PROPERTIES EXPORT_NAME CURSES)
17+
target_include_directories(pdcurses
18+
PUBLIC
19+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
20+
$<INSTALL_INTERFACE:include>
21+
)
22+
23+
add_subdirectory(pdcurses)
24+
25+
# for FetchContent
26+
add_library(CURSES::CURSES IMPORTED INTERFACE)
27+
target_link_libraries(CURSES::CURSES INTERFACE pdcurses)
28+
target_include_directories(CURSES::CURSES INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
29+
30+
if(WIN32)
31+
add_subdirectory(wincon)
32+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
33+
include(cmake/x11.cmake)
34+
35+
target_include_directories(pdcurses PRIVATE ${X11_INCLUDE_DIR})
36+
target_link_libraries(pdcurses PRIVATE ${X11_LIBRARIES} X11::Xt X11::Xpm X11::Xmu)
37+
38+
add_subdirectory(x11)
39+
else()
40+
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is not yet supported by CMake for PDCurses.")
41+
endif()
42+
43+
install(TARGETS pdcurses EXPORT ${PROJECT_NAME}-targets)
44+
install(FILES curses.h panel.h TYPE INCLUDE)
45+
46+
include(cmake/install.cmake)

cmake/config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
4+
5+
check_required_components(@PROJECT_NAME@)

cmake/install.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# --- BOILERPLATE: install / packaging
2+
3+
include(CMakePackageConfigHelpers)
4+
5+
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/config.cmake.in
6+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
7+
INSTALL_DESTINATION cmake
8+
)
9+
10+
write_basic_package_version_file(
11+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
12+
COMPATIBILITY SameMinorVersion
13+
)
14+
15+
install(EXPORT ${PROJECT_NAME}-targets
16+
NAMESPACE CURSES::
17+
DESTINATION cmake
18+
)
19+
20+
install(FILES
21+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
22+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
23+
DESTINATION cmake
24+
)
25+
26+
# --- CPack
27+
28+
set(CPACK_GENERATOR "TZST")
29+
set(CPACK_SOURCE_GENERATOR "TZST")
30+
set(CPACK_PACKAGE_VENDOR "William McBrine")
31+
set(CPACK_PACKAGE_CONTACT "William McBrine")
32+
# set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
33+
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
34+
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/package")
35+
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
36+
37+
install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE}
38+
DESTINATION share/docs/${PROJECT_NAME}
39+
)
40+
41+
include(CPack)

cmake/x11.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# extra parts of X11 needed
2+
find_package(X11 REQUIRED)
3+
4+
find_package(PkgConfig REQUIRED)
5+
6+
# xt.pc is broken on Ubuntu
7+
pkg_check_modules(_xt xt)
8+
9+
find_path(_xt_inc
10+
NAMES Intrinsic.h
11+
HINTS ${_xt_INCLUDE_DIRS}
12+
PATHS /usr/include
13+
PATH_SUFFIXES X11
14+
REQUIRED
15+
)
16+
17+
pkg_check_modules(_xaw REQUIRED xaw7)
18+
19+
list(APPEND X11_INCLUDE_DIR ${_xt_inc})
20+
list(APPEND X11_LIBRARIES ${_xaw_LIBRARIES})

demos/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.14...3.24)
2+
3+
project(PDcursesDemos LANGUAGES C)
4+
5+
# --- auto-ignore build directory
6+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
7+
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
8+
endif()
9+
10+
include(${PROJECT_SOURCE_DIR}/../cmake/x11.cmake)
11+
12+
find_package(PDCurses CONFIG REQUIRED)
13+
14+
foreach(f testcurs ozdemo xmas firework ptest rain worm)
15+
add_executable(${f} ${f}.c)
16+
target_link_libraries(${f} PRIVATE CURSES::CURSES)
17+
endforeach()
18+
19+
add_executable(tuidemo tui.c tuidemo.c)
20+
target_link_libraries(tuidemo PRIVATE CURSES::CURSES)

pdcurses/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target_sources(pdcurses PRIVATE
2+
addch.c addchstr.c addstr.c attr.c beep.c bkgd.c border.c clear.c color.c delch.c deleteln.c getch.c getstr.c getyx.c inch.c inchstr.c initscr.c inopts.c insch.c insstr.c instr.c kernel.c keyname.c mouse.c move.c outopts.c overlay.c pad.c panel.c printw.c refresh.c scanw.c scr_dump.c scroll.c slk.c termattr.c touch.c util.c window.c debug.c
3+
)

wincon/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target_sources(pdcurses PRIVATE
2+
pdcclip.c pdcdisp.c pdcgetsc.c pdckbd.c pdcscrn.c pdcsetsc.c pdcutil.c
3+
pdcwin.h
4+
)

x11/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target_sources(pdcurses PRIVATE
2+
pdcclip.c pdcdisp.c pdcgetsc.c pdckbd.c pdcscrn.c pdcsetsc.c pdcutil.c sb.c scrlbox.c
3+
pdcx11.h scrlbox.h
4+
)

0 commit comments

Comments
 (0)