Repository navigation
Conversation
michalvasko
requested changes
Nov 23, 2026
michalvasko
approved these changes
Nov 23, 2026
Merged
Roytak
force-pushed
the
cmake-config
branch
3 times, most recently
from
December 1, 2026 15:34
81ab2ed to
bc2e38f
Compare
michalvasko
reviewed
Dec 2, 2026
| # yang update library | ||
| add_library(${LIB_NAME} STATIC ${lib_src}) | ||
| # yang update library, uses also internal libyang functions | ||
| add_library(${LIB_NAME} STATIC ${lib_src} $<TARGET_OBJECTS:yang>) |
Member
There was a problem hiding this comment.
You are duplicating the yang functions in ${lib_src} and then $<TARGET_OBJECTS:yang>. Only the latter should be needed.
Contributor
Author
There was a problem hiding this comment.
lib_src was actually the sources of yang update, not yang, so I just renamed the variable to avoid future confusion.
| set(CMAKE_THREAD_PREFER_PTHREAD TRUE) | ||
| find_package(Threads REQUIRED) | ||
| target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT}) | ||
| # link pthreads, found by use_compat() |
Member
There was a problem hiding this comment.
Do not rely on use_compat(), it may be changed or reordered but mainly is in a separate subordinate List. But you can first check it (if(TARGET Threads::Threads)...) and search for the threads yourself in case the check fails.
| message(STATUS "Static build, CMake config package is not installed") | ||
| endif() | ||
|
|
||
| # pkg-config file paths, the install directories may be absolute |
Member
There was a problem hiding this comment.
They are not by default and even if set that way manually, it should not really be an issue (and is a user mistake).
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, 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.
Roytak
marked this pull request as ready for review
December 2, 2026 09:07
The declared minimum 2.8.12 no longer worked. CMake 3.12 is the oldest version that links OBJECT libraries through target_link_libraries(), which the following commits need. It is also the minimum of sysrepo and netopeer2, 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 the libyang objects as a library, which CMake before 3.21 does without a dependency on libyang. The objects of a non-object library are also available only since CMake 3.15, so yangupdate and its tests are disabled with older CMake. The CMP0075 policy guard is always true now. 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.
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, LibYANG_HAVE_CBOR, LibYANG_YANG_MODULE_DIR, LibYANG_PLUGINS_DIR_EXTENSIONS and LibYANG_PLUGINS_DIR_TYPES. 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. GenConfigPackage.cmake, shared with the other projects, generates the whole config from its arguments, with the documentation in LibYANGConfig.doc as its header.
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.
FindCMocka and FindPCRE2 marked their result variables as advanced, which are not cached, instead of the cache variables of find_path() and find_library(). FindCBOR and FindXXHash marked none. The cache variables were thus shown in the basic view of cmake-gui and ccmake.
The compat sources were compiled into libyang and again into each tool and unit test. The compat functions are now an object library, compiled once and hidden in the shared libyang. The tools and unit tests link it next to libyang, the objects of an object library reach only the targets linking it directly. It also carries the compat.h include directory and the thread library its functions call. libyang links Threads::Threads instead of the raw thread library flag, which is kept only for libyang.pc.
The Windows dirname() implementation using shlwapi was removed from compat, but its declaration in posix-shims/libgen.h and the shlwapi link remained. Nothing includes libgen.h any more.
The <dirent.h> and posix-shims include directories and the pthreads library on Windows are dependencies of the compat functions, but were set up for libyang after use_compat(), partly three times over. use_compat() now sets them up on the compat object library, which passes them on to libyang and to the tools and unit tests linking it, those use the POSIX headers too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Installs a LibYANG CMake package so that dependent projects can use
find_package(LibYANG CONFIG)and link the imported targetLibYANG::yanginstead of a copied Find module or pkg-config. The package version is the SO version withSameMajorVersioncompatibility.It contains these related changes:
FindLibYANG.cmakeis removed and the README describes the package instead (copies kept in other projects still work),yangno longer leak to linking targets, and the DLL is installed intobinon Windows,lcbor.his no longer installed, so<cbor.h>is not part of the public interface,pkg-config --cflags libyangworks without the PCRE2 and xxHash development packages, because private dependencies are listed only inLibs.private, which now also includes the ones that were missing,-devpackages 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.