From c5c9432ac039fb98ef0b6888f6654f80b9973b95 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Sat, 28 Nov 2020 21:00:00 +0100 Subject: [PATCH] [Misc] A hodgepodge of tiny changes CMake: Simplify cmake target+version config generation and make it actually work. With the changes it is now possible to detect and use `Notcurses` in the following way: find_package(Notcurses REQUIRED) ... target_link_libraries(myapp PRIVATE notcurses::notcurses) Also, added the same CMake configuration for `Notcurses++`, to be used in the following way: find_package(Notcurses REQUIRED find_package(Notcurses++ REQUIRED) ... target_link_libraries(myapp PRIVATE notcurses++::notcurses++) Docs: `notcurses_cell(3)`: `cell_styles_{on,off} -> cell_{on,off}_styles` and `cell_load_simple` -> `cell_load_char` C++ API: * Plane: added constructors taking `ncplane_options const&` instead of the multitude of individual parameters * Plane: drop `struct` when `ncplane_options` is used. * Plane: added `strdup` (`cell_strdup`) * Plane: added `extract` (`cell_extract`) --- CMakeLists.txt | 36 +++++++++++++++---- doc/man/man3/notcurses_cell.3.md | 6 ++-- include/ncpp/Plane.hh | 61 +++++++++++++++++++++++--------- tools/NotcursesConfig.cmake.in | 9 ----- 4 files changed, 78 insertions(+), 34 deletions(-) delete mode 100644 tools/NotcursesConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a1b9af4145..1b495ecb99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -601,23 +601,47 @@ include(CMakePackageConfigHelpers) configure_file(tools/version.h.in include/version.h) configure_file(tools/builddef.h.in include/builddef.h) -configure_package_config_file(tools/NotcursesConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/notcurses/cmake -) - write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake COMPATIBILITY SameMajorVersion ) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake + COMPATIBILITY SameMajorVersion + ) + # Installation install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/NotcursesConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses" ) +install(TARGETS notcurses + EXPORT "NotcursesTargets" + ) + +install(EXPORT "NotcursesTargets" + NAMESPACE "notcurses::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses" + FILE "NotcursesConfig.cmake" +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/Notcurses++ConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++" + ) + +install(TARGETS notcurses++ + EXPORT "Notcurses++Targets" + ) + +install(EXPORT "Notcurses++Targets" + NAMESPACE "notcurses++::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Notcurses++" + FILE "Notcurses++Config.cmake" + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/notcurses.pc DESTINATION ${PKGCONFIG_DIR} diff --git a/doc/man/man3/notcurses_cell.3.md b/doc/man/man3/notcurses_cell.3.md index c9fa486a64..d0868d6e94 100644 --- a/doc/man/man3/notcurses_cell.3.md +++ b/doc/man/man3/notcurses_cell.3.md @@ -56,9 +56,9 @@ typedef struct cell { **unsigned cell_styles(const cell* ***c***);** -**void cell_styles_on(cell* ***c***, unsigned ***stylebits***);** +**void cell_on_styles(cell* ***c***, unsigned ***stylebits***);** -**void cell_styles_off(cell* ***c***, unsigned ***stylebits***);** +**void cell_off_styles(cell* ***c***, unsigned ***stylebits***);** **void cell_set_fg_default(cell* ***c***);** @@ -74,7 +74,7 @@ typedef struct cell { **char* cell_strdup(const struct ncplane* ***n***, const cell* ***c***);** -**int cell_load_simple(struct ncplane* ***n***, cell* ***c***, char ***ch***);** +**int cell_load_char(struct ncplane* ***n***, cell* ***c***, char ***ch***);** **char* cell_extract(const struct ncplane* ***n***, const cell* ***c***, uint16_t* ***stylemask***, uint64_t* ***channels***);** diff --git a/include/ncpp/Plane.hh b/include/ncpp/Plane.hh index e5fe13e567..5d034bbb09 100644 --- a/include/ncpp/Plane.hh +++ b/include/ncpp/Plane.hh @@ -60,6 +60,20 @@ namespace ncpp plane = create_plane (*n, rows, cols, yoff, xoff, opaque); } + explicit Plane (Plane *n, ncplane_options const& nopts, NotCurses *ncinst = nullptr) + : Plane (static_cast(n), nopts, ncinst) + {} + + explicit Plane (const Plane *n, ncplane_options const& nopts, NotCurses *ncinst = nullptr) + : Root (ncinst) + { + if (n == nullptr) { + throw invalid_argument ("'n' must be a valid pointer"); + } + + plane = create_plane (*n, nopts); + } + explicit Plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque = nullptr) : Root (nullptr) { @@ -69,7 +83,7 @@ namespace ncpp explicit Plane (int rows, int cols, int yoff, int xoff, void *opaque = nullptr, NotCurses *ncinst = nullptr) : Root (ncinst) { - struct ncplane_options nopts = { + ncplane_options nopts = { .y = yoff, .x = xoff, .rows = rows, @@ -102,6 +116,16 @@ namespace ncpp plane = create_plane (const_cast(n), rows, cols, yoff, align, opaque); } + explicit Plane (Plane &n, ncplane_options const& nopts, NotCurses *ncinst = nullptr) + : Plane (static_cast(n), nopts, ncinst) + {} + + explicit Plane (Plane const& n, ncplane_options const& nopts, NotCurses *ncinst = nullptr) + : Root (ncinst) + { + plane = create_plane (n, nopts); + } + explicit Plane (Plane *n, int rows, int cols, int yoff, NCAlign align, void *opaque = nullptr) : Root (nullptr) { @@ -1130,6 +1154,16 @@ namespace ncpp return error_guard (ncplane_rotate_ccw (plane), -1); } + char* strdup (Cell const& cell) const noexcept + { + return cell_strdup (plane, cell); + } + + char* extract (Cell const& cell, uint16_t *stylemask = nullptr, uint64_t *channels = nullptr) + { + return cell_extract (plane, cell, stylemask, channels); + } + const char* get_extended_gcluster (Cell &cell) const noexcept { return cell_extended_gcluster (plane, cell); @@ -1227,9 +1261,9 @@ namespace ncpp private: ncplane* create_plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque) { - struct ncplane_options nopts = { + ncplane_options nopts = { .y = yoff, - .x = xoff, + .x = xoff, .rows = rows, .cols = cols, .userptr = opaque, @@ -1237,17 +1271,7 @@ namespace ncpp .resizecb = nullptr, .flags = 0, }; - ncplane *ret = ncplane_create ( - n.plane, - &nopts - ); - - if (ret == nullptr) - throw init_error ("Notcurses failed to create a new plane"); - - map_plane (plane, this); - - return ret; + return create_plane (n, nopts); } ncplane* create_plane (Plane &n, int rows, int cols, int yoff, NCAlign align, void *opaque) @@ -1262,16 +1286,21 @@ namespace ncpp nullptr, 0, }; + return create_plane (n, nopts); + } + + ncplane* create_plane (const Plane &n, ncplane_options const& nopts) + { ncplane *ret = ncplane_create ( n.plane, &nopts ); - if (ret == nullptr) + if (ret == nullptr) { throw init_error ("Notcurses failed to create an aligned plane"); + } map_plane (plane, this); - return ret; } diff --git a/tools/NotcursesConfig.cmake.in b/tools/NotcursesConfig.cmake.in deleted file mode 100644 index 1b093f97e1..0000000000 --- a/tools/NotcursesConfig.cmake.in +++ /dev/null @@ -1,9 +0,0 @@ -@PACKAGE_INIT@ -set(Notcurses_DIR "@PACKAGE_SOME_INSTALL_DIR@") - -# Compute paths -get_filename_component(Notcurses_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(Notcurses_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") -set(Notcurses_LIBRARY_DIRS "@CONF_LIBRARY_DIRS@") - -set(Notcurses_LIBRARIES -lnotcurses)