@@ -238,6 +238,7 @@ set(format_sources
238238 src/*.h
239239 src/plugins_exts/*
240240 src/plugins_types/*)
241+
241242#
242243# options
243244#
@@ -256,6 +257,7 @@ option(ENABLE_YANGLINT_INTERACTIVE "Enable interactive CLI yanglint" ON)
256257option (ENABLE_TOOLS "Build binary tools 'yanglint' and 'yangre'" ON )
257258option (ENABLE_COMMON_TARGETS "Define common custom target names such as 'doc' or 'uninstall', may cause conflicts when using add_subdirectory() to build this project" ON )
258259option (BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON )
260+ option (ENABLE_CBOR_SUPPORT "Enable CBOR support with libcbor" ON )
259261set (YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_DATADIR} /yang/modules/libyang" CACHE STRING "Directory where to copy the YANG modules to" )
260262
261263if (ENABLE_INTERNAL_DOCS)
@@ -323,6 +325,42 @@ if(ENABLE_COVERAGE)
323325 gen_coverage_enable (${ENABLE_TESTS} )
324326endif ()
325327
328+ if (ENABLE_CBOR_SUPPORT)
329+ find_package (PkgConfig )
330+ if (PKG_CONFIG_FOUND)
331+ pkg_check_modules (LIBCBOR REQUIRED libcbor )
332+ if (LIBCBOR_FOUND)
333+ message (STATUS "libcbor found, enabling CBOR support" )
334+ add_definitions (-DENABLE_CBOR_SUPPORT )
335+ include_directories (${LIBCBOR_INCLUDE_DIRS} )
336+ # Add CBOR parser files to the library sources
337+ list (APPEND libsrc src/parser_cbor.c)
338+ list (APPEND headers src/parser_cbor.h)
339+ # Add CBOR files to format sources
340+ list (APPEND format_sources src/parser_cbor.c src/parser_cbor.h)
341+ else ()
342+ message (FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF" )
343+ endif ()
344+ else ()
345+ # Fallback to find_path and find_library if pkg-config is not available
346+ find_path (LIBCBOR_INCLUDE_DIR cbor.h )
347+ find_library (LIBCBOR_LIBRARY cbor )
348+ if (LIBCBOR_INCLUDE_DIR AND LIBCBOR_LIBRARY)
349+ message (STATUS "libcbor found via find_path/find_library, enabling CBOR support" )
350+ add_definitions (-DENABLE_CBOR_SUPPORT )
351+ include_directories (${LIBCBOR_INCLUDE_DIR} )
352+ set (LIBCBOR_LIBRARIES ${LIBCBOR_LIBRARY} )
353+ # Add CBOR parser files to the library sources
354+ list (APPEND libsrc src/parser_cbor.c)
355+ list (APPEND headers src/parser_cbor.h)
356+ # Add CBOR files to format sources
357+ list (APPEND format_sources src/parser_cbor.c src/parser_cbor.h)
358+ else ()
359+ message (FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF" )
360+ endif ()
361+ endif ()
362+ endif ()
363+
326364if ("${BUILD_TYPE_UPPER} " STREQUAL "DEBUG" )
327365 # enable before adding tests to let them detect that format checking is available - one of the tests is format checking
328366 source_format_enable (0.77 )
@@ -427,6 +465,11 @@ find_package(PCRE2 10.21 REQUIRED)
427465include_directories (${PCRE2_INCLUDE_DIRS} )
428466target_link_libraries (yang ${PCRE2_LIBRARIES} )
429467
468+ # link libcbor if CBOR support is enabled
469+ if (ENABLE_CBOR_SUPPORT)
470+ target_link_libraries (yang ${LIBCBOR_LIBRARIES} )
471+ endif ()
472+
430473# XXHash include and library
431474find_package (XXHash )
432475if (XXHASH_FOUND)
@@ -521,4 +564,4 @@ add_custom_target(cclean
521564 COMMAND make clean
522565 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
523566 COMMAND rm -rf Makefile Doxyfile
524- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
567+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
0 commit comments