Skip to content

cmake FEATURE LibNETCONF2 config package - #658

Draft
Roytak wants to merge 17 commits into
develfrom
cmake-config
Draft

Roytak wants to merge 17 commits into
develfrom
cmake-config

Conversation

@Roytak

@Roytak Roytak commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Installs the LibNETCONF2 CMake package (shared builds only), so dependent projects can use find_package(LibNETCONF2) and link the imported target LibNETCONF2::netconf2. The package also provides LibNETCONF2_PROJECT_VERSION, LibNETCONF2_YANG_MODULE_DIR, LibNETCONF2_SSH, LibNETCONF2_TLS and LibNETCONF2_TLS_BACKEND. Its version is the SO version, and it can also be used from a build tree.

It contains these changes:

  • FindLibNETCONF2.cmake is removed. Copies of it in other projects keep working.
  • libyang and libssh are found by their own CMake packages. A libyang build tree can be used with -DLibYANG_DIR=<libyang build dir>.
  • CMake 3.12 is now the minimum.
  • libnetconf2.pc lists libyang and libssh in Requires and the private dependencies of a static build in Libs.private. Its Cflags carry NC_SSH/NC_TLS.
  • NC_SSH/NC_TLS are also set on the target, so a libnetconf2 header included directly declares the SSH and TLS functions.
  • Edited public headers are copied into the build tree again without a manual reconfigure.
  • The CMake package is shipped in libnetconf2-dev/libnetconf2-devel. libnetconf2-dev depends on libssh-dev, and the build depends on libcrypt-dev.
  • The CI package jobs build the PR's own sources instead of the target branch.
  • The tests use only the public API of the shared library.
  • Fixes the socket library link on QNX, find module cache variables that stayed visible in cmake-gui/ccmake, and a busy loop in test_two_channels.

The public headers include libyang and libssh headers, but
libnetconf2.pc did not require them, so pkg-config --cflags and --libs
gave only the flags of libnetconf2. They are in Requires now, the
private dependencies of a static build are listed in Libs.private,
which needs no .pc files.

The file also works with absolute CMAKE_INSTALL_INCLUDEDIR/LIBDIR and
is generated always, the pkg-config binary is not needed for that.
The apkg tests were never run, CI only builds and installs the
packages, and they still expected version 2 of libnetconf2. They only
checked that pkg-config prints a version, so they are removed instead
of fixed.
The declared minimum 3.5 no longer worked, VERSION_GREATER_EQUAL needs
CMake 3.7. CMake 3.12 is the oldest version that links OBJECT
libraries through target_link_libraries(), which the following commits
need, and its FindCURL always provides CURL::libcurl.

use_compat() removed an empty CMAKE_THREAD_LIBS_INIT from a list, which
fails up to CMake 3.19.
use_compat() links the socket library to netconf2 on QNX, but it was
called before the target was created, which CMake refuses. The check
of the crypt library called check_library_exists() without including
its module and worked only because FindThreads includes it.
libyang installs the LibYANG CMake package with the LibYANG::yang
imported target and libssh its libssh package with the ssh target, so
the copies of FindLibYANG.cmake and FindLibSSH.cmake are no longer
needed. The test objects get the include directories of both by
linking netconf2.

A libyang build tree can be used by -DLibYANG_DIR=<libyang build dir>
instead of setting the include directory and library manually.
Without keywords every dependency of the netconf2 target was transitive
and an exported target would carry absolute paths of all the private
libraries. libyang and libssh are public, the public headers include
them, all the other dependencies are private. They are collected in
NC_PRIVATE_LIBS and linked to netconf2 and to the test objects, which
contain the library code. The tests link the test objects directly and
get their dependencies with them.

The target also carries its include directory, so that a linked target
finds <nc_client.h> both in the build tree and after installation, and
the NC_SSH and NC_TLS definitions, which only nc_client.h and
nc_server.h defined so far, so a directly included libnetconf2 header
did not declare the SSH and TLS functions. libnetconf2.pc carries the
definitions in Cflags as well.
The compat source was compiled into netconf2 and once more into the
test objects. use_compat() now creates the nccompat OBJECT library,
which netconf2 links privately. The tests link it themselves, the
compat functions in netconf2 are hidden.
The public headers were copied into the build tree by file(COPY) only
when CMake ran, so after editing a header the build used its stale copy
until the next manual reconfiguration. configure_file() makes the build
rerun CMake and refresh the copy whenever the header changes.
A shared build installs the LibNETCONF2 CMake package into
lib/cmake/LibNETCONF2 and exports it from the build tree. It provides
the imported target LibNETCONF2::netconf2 with libyang and libssh as its
public dependencies, found by their CMake packages, and the variables
LibNETCONF2_PROJECT_VERSION, LibNETCONF2_YANG_MODULE_DIR, which replaces
LN2_SCHEMAS_DIR of libnetconf2.pc, LibNETCONF2_SSH, LibNETCONF2_TLS and
LibNETCONF2_TLS_BACKEND. The YANG module directory moves with the
installed package if it is under the prefix, the build tree package
points to the modules in the source tree and looks for libyang and
libssh first where libnetconf2 found them.

The package version is the SO version with SameMajorVersion
compatibility, the version the Find modules of the dependent projects
compare. A static build installs no package. GenConfigPackage.cmake
generating it is the same module as in libyang and sysrepo.
The Find module was never installed, projects copied it into their own
trees, and the LibNETCONF2 CMake package replaces it. The copies keep
working, releases without the package are found by pkg-config. README
describes the package.
The CMake package belongs to libnetconf2-dev and libnetconf2-devel.
libnetconf2-dev now depends on libssh-dev, the public headers include
libssh headers and the package needs the libssh CMake package. The
devel rpm gets the dependency from libnetconf2.pc.

dh_missing now fails on installed files missing from all the packages,
with debhelper compat 10 it did not even list them, so a new installed
file silently fell out of the deb packages. pkg-config is no longer
needed for the build.
The package jobs cloned the target branch of libnetconf2 from GitHub,
so a pull request was built without its own changes. They now build
the checked out sources and no longer install pkg-config, which the
build does not need anymore.
libc6-dev in Debian sid does not depend on libcrypt-dev anymore, so the
build did not find crypt(3).
FindLibPAM, FindLibVAL and FindMbedTLS marked their _INCLUDE_DIRS and
_LIBRARIES as advanced, FindCMocka its CMOCKA_LIBRARIES, which are
normal variables. The cache variables of find_path() and find_library()
stayed visible in cmake-gui and ccmake.
The server thread of test_two_channels checked the nc_ps_poll() result
against NC_PS_POLL_TIMEOUT, the 2000 ms test timeout, instead of the
NC_PSPOLL_TIMEOUT flag. The mask did not contain the timeout bit, so
the thread polled in a busy loop without the intended back off.
The tests compiled the library sources once more (testobj) to reach
hidden functions and variables and to --wrap the functions libnetconf2
calls. They now link ncbin, the shared library with own compat objects,
meant also for any executables of this project. The private
dependencies are no longer shared with testobj, each is linked to
netconf2 where it is found.

- FD sessions are created by nc_connect_inout() and nc_accept_inout(),
  each with a fake peer that chooses the NETCONF version, and are then
  switched to the shared socketpair
- the idle timeout is configured through ietf-netconf-server and the
  idle sessions really wait for it
- the mocks replace the functions by symbol interposition and reach the
  real ones by dlsym(RTLD_NEXT)
- test_client_messages checked the private RPC structures, it now sends
  every RPC and compares what the server received
- test_client_monitoring closes the server end of an FD session instead
  of resetting an SSH connection found by its port, so it needs neither
  SSH nor TLS
The names of the test timeout macros did not say their unit. They get
the _MS suffix, as NC_MSG_TIMEOUT_MS has, and the shared ones in
ln2_test.h a short comment each.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant