Skip to content

cmake FEATURE LibYANG CMake config package - #2651

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

Roytak wants to merge 10 commits into
develfrom
cmake-config

Conversation

@Roytak

@Roytak Roytak commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Installs a LibYANG CMake package so that dependent projects can use find_package(LibYANG CONFIG) and link the imported target LibYANG::yang instead of a copied Find module or pkg-config. The package version is the SO version with SameMajorVersion compatibility.

It contains these related changes:

  • FindLibYANG.cmake is removed and the README describes the package instead (copies kept in other projects still work),
  • the minimum CMake version is now 3.12 (the declared 2.8.12 no longer worked),
  • private dependencies of yang no longer leak to linking targets, and the DLL is installed into bin on Windows,
  • the internal lcbor.h is no longer installed, so <cbor.h> is not part of the public interface,
  • pkg-config --cflags libyang works without the PCRE2 and xxHash development packages, because private dependencies are listed only in Libs.private, which now also includes the ones that were missing,
  • the build refreshes its copies of the public headers whenever a header changes, without a manual CMake rerun,
  • the deb and rpm -dev packages ship the CMake package, the unused apkg tests are removed, and the CI package jobs build the PR's own sources instead of cloning the target branch.

libyang-dev no longer depends on libpcre2-dev, but libyang.pc kept
libpcre2-8 and libxxhash in Requires.private. pkg-config resolves
Requires.private even for --cflags, so pkg-config --cflags libyang
failed on a system without those -dev packages.

The private dependencies are now listed only in Libs.private, which
needs no .pc files and is used only for static linking. The file also
lists libcbor, libm, libdl and threads, which were missing, works with
absolute CMAKE_INSTALL_INCLUDEDIR/LIBDIR and is generated always, the
pkg-config binary is not needed for that. The warning about
PKG_CONFIG_PATH needed the binary and is dropped.
The apkg tests were never run, CI only builds and installs the
packages, and they still expected version 2 of libyang. They only
checked that pkg-config and yanglint print a version, so they are
removed instead of fixed.
The declared minimum 2.8.12 no longer worked. The new minimum is the
one of the dependent projects: sysrepo and netopeer2 link OBJECT
libraries through target_link_libraries() and netopeer2 uses
CURL::libcurl, both new in CMake 3.12. libyang itself builds with
CMake 3.5, but the whole family keeps one minimum.

Two places did not work with older CMake. use_compat() removed an
empty CMAKE_THREAD_LIBS_INIT from a list, which fails up to CMake 3.19.
yang_update linked yangobj objects as a library, which CMake before
3.21 does without a dependency on yangobj, and it failed in a static
build, where there is no yangobj.

The 32-bit CI job ran in i386/ubuntu, which is Ubuntu 18.04 with CMake
3.10. It runs in the i386 Debian 13 image now.
Without keywords every dependency of the yang target was transitive and
an exported target would carry absolute paths of all the private
libraries. All the dependencies are private now except ws2_32 on
Windows, because ly_config.h includes winsock2.h.

The target also carries its include directory so that a linked target
finds <libyang/libyang.h> both in the build tree and after
installation, and the DLL is installed into bin on Windows.
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.
lcbor.h is a private header of the CBOR parser and printer. Its
functions are not exported and no public header includes it, but as an
installed header it made <cbor.h> part of the public interface. It is
now documented with the other internal headers.
Comment thread CMakeLists.txt Resolved
Comment thread CMakeModules/LibYANGConfigPackage.cmake Resolved
A shared build installs the LibYANG CMake package into
lib/cmake/LibYANG and exports it from the build tree, so that
find_package(LibYANG CONFIG) works without a Find module, pkg-config
or hand-set include and library paths. It provides the imported target
LibYANG::yang and the variables LibYANG_PROJECT_VERSION and
LibYANG_HAVE_CBOR.

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, it would need imported
targets for all the private dependencies.
The Find module was never installed, projects copied it into their own
trees, and the LibYANG CMake package replaces it. The copies keep
working, releases without the package are found by pkg-config. README
describes the package instead.
The CMake package belongs to libyang-dev and libyang-devel.
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 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.
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.

2 participants