### CMake Build Configuration for Examples Source: https://github.com/project/libubox/blob/master/examples/CMakeLists.txt This snippet configures the build process for libubox examples. It sets compiler flags, includes directories, finds libraries, and defines executables for example programs. ```cmake IF (BUILD_EXAMPLES) PROJECT(ubox-examples C) ADD_DEFINITIONS(-O1 -Wall -Werror --std=gnu99 -g3) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) FIND_LIBRARY(json NAMES json-c json) ADD_EXECUTABLE(ustream-example ustream-example.c) TARGET_LINK_LIBRARIES(ustream-example ubox) ADD_EXECUTABLE(json_script-example json_script-example.c) TARGET_LINK_LIBRARIES(json_script-example ubox blobmsg_json json_script ${json}) ENDIF() ``` -------------------------------- ### Project and Installation Prefix Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Initializes the CMake project for C and sets the installation prefix to the root directory. ```cmake PROJECT(uloop C) SET(CMAKE_INSTALL_PREFIX /) ``` -------------------------------- ### Build and Install Lua uloop Module Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Compiles the uloop.c file into a shared library (MODULE) named 'uloop_lua', links it with 'ubox', and installs it to the detected Lua module path. ```cmake IF(BUILD_LUA) ADD_LIBRARY(uloop_lua MODULE uloop.c) SET_TARGET_PROPERTIES(uloop_lua PROPERTIES OUTPUT_NAME uloop PREFIX "" ) TARGET_LINK_LIBRARIES(uloop_lua ubox) INSTALL(TARGETS uloop_lua LIBRARY DESTINATION ${LUAPATH} ) ENDIF() ``` -------------------------------- ### Python Virtual Environment Setup Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Defines variables for the Python virtual environment directory and executables (pip, cram). ```cmake SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv") SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip") SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram") ``` -------------------------------- ### Create Python Virtual Environment and Install Cram Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt An add custom command to create a Python virtual environment and install the 'cram' package using pip. This command is executed when the output file ${PYTHON_VENV_CRAM} is needed. ```cmake ADD_CUSTOM_COMMAND( OUTPUT ${PYTHON_VENV_CRAM} COMMAND ${PYTHON_EXECUTABLE} -m venv ${PYTHON_VENV_DIR} COMMAND ${PYTHON_VENV_PIP} install cram ) ``` -------------------------------- ### Glob for Test Cases Source: https://github.com/project/libubox/blob/master/tests/fuzz/CMakeLists.txt Finds all C source files in the current directory that start with 'test-'. ```cmake FILE(GLOB test_cases "test-*.c") ``` -------------------------------- ### Lua Path Detection Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Executes a Lua command to find the package.cpath for installing Lua modules. This is used to determine the correct installation directory for the uloop Lua module. ```cmake IF(NOT LUAPATH) EXECUTE_PROCESS( COMMAND lua -e "for k in string.gmatch(package.cpath .. \";", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end" OUTPUT_VARIABLE LUAPATH RESULT_VARIABLE LUA_CHECK_RES OUTPUT_STRIP_TRAILING_WHITESPACE ) IF(BUILD_LUA) IF(NOT ${LUA_CHECK_RES} EQUAL 0 OR "${LUAPATH}" EQUAL "") MESSAGE(SEND_ERROR "Lua was not found on your system") ENDIF() ENDIF() ENDIF() ``` -------------------------------- ### Glob and Add Unit Tests Source: https://github.com/project/libubox/blob/master/tests/CMakeLists.txt Finds all C files starting with 'test-' and adds them as unit tests using the previously defined macro. It also calls an 'ADD_UNIT_TEST_SAN' macro, which is not defined in this snippet. ```cmake FILE(GLOB test_cases "test-*.c") FOREACH(test_case ${test_cases}) GET_FILENAME_COMPONENT(test_case ${test_case} NAME_WE) ADD_UNIT_TEST(${test_case}) ADD_UNIT_TEST_SAN(${test_case}) ENDFOREACH(test_case) ``` -------------------------------- ### Build Definitions and Link Directories Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Adds compiler definitions for optimization, warnings, C standard, debugging, and includes the parent directory for linking. ```cmake ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I.. ${LUA_CFLAGS}) LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) ``` -------------------------------- ### Add Subdirectories Source: https://github.com/project/libubox/blob/master/tests/CMakeLists.txt Includes subdirectories 'cram' and 'shunit2' into the build. These likely contain their own build configurations. ```cmake ADD_SUBDIRECTORY(cram) ADD_SUBDIRECTORY(shunit2) ``` -------------------------------- ### Prepare Cram Virtual Environment Target Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Creates a custom target 'prepare-cram-venv' that depends on the creation of the Python virtual environment and 'cram' executable. This ensures the venv is ready before tests that depend on it. ```cmake ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM}) ``` -------------------------------- ### Glob Test Cases Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Finds all files matching the pattern 'test_*.t' in the current directory to be used as test cases. ```cmake FILE(GLOB test_cases "test_*.t") ``` -------------------------------- ### Lua Dependency Search Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Searches for the Lua 5.1 development files using pkg-config if LUA_CFLAGS is not already defined. ```cmake IF(NOT LUA_CFLAGS) pkg_search_module(LUA lua5.1 lua-5.1) ENDIF() ``` -------------------------------- ### Define Unit Test Macro Source: https://github.com/project/libubox/blob/master/tests/CMakeLists.txt Defines a reusable macro 'ADD_UNIT_TEST' to simplify the creation of C executables for unit tests. It links against several libraries and sets include directories. ```cmake MACRO(ADD_UNIT_TEST name) ADD_EXECUTABLE(${name} ${name}.c) TARGET_LINK_LIBRARIES(${name} ubox blobmsg_json json_script ${json}) TARGET_INCLUDE_DIRECTORIES(${name} PRIVATE ${PROJECT_SOURCE_DIR}) ENDMACRO(ADD_UNIT_TEST) ``` -------------------------------- ### Loop Through Test Cases and Add Fuzzers Source: https://github.com/project/libubox/blob/master/tests/fuzz/CMakeLists.txt Iterates over the discovered test cases and applies the ADD_FUZZER_TEST macro to each one. ```cmake FOREACH(test_case ${test_cases}) GET_FILENAME_COMPONENT(test_case ${test_case} NAME_WE) ADD_FUZZER_TEST(${test_case}) ENDFOREACH(test_case) ``` -------------------------------- ### Add Shunit2 Test Source: https://github.com/project/libubox/blob/master/tests/shunit2/CMakeLists.txt Adds a Shunit2 test case to the CMake build. The test is named 'shunit2' and executes the 'tests.sh' script from the current source directory. ```cmake ADD_TEST( NAME shunit2 COMMAND tests.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Add Cram Test Case Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Defines a test named 'cram' that executes the 'cram' tool with the discovered test cases. The test runs in the source directory. ```cmake ADD_TEST( NAME cram COMMAND ${PYTHON_VENV_CRAM} ${test_cases} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Set Shunit2 Test Environment Variable Source: https://github.com/project/libubox/blob/master/tests/shunit2/CMakeLists.txt Appends an environment variable 'TEST_JSON_SCRIPT' to the 'shunit2' test. This is used to specify the path to a JSON script for testing purposes. ```cmake SET_PROPERTY(TEST shunit2 APPEND PROPERTY ENVIRONMENT "TEST_JSON_SCRIPT=$") ``` -------------------------------- ### Set Environment Properties for Cram Test Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Sets environment variables for the 'cram' test. This includes paths to the 'jshn' target and the directory containing 'test-avl' executables, which might be used by the tests. ```cmake SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "JSHN=$") SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "TEST_BIN_DIR=$") ``` -------------------------------- ### macOS Shared Module Flag Source: https://github.com/project/libubox/blob/master/lua/CMakeLists.txt Sets a specific C flag for macOS to handle dynamic lookups in shared modules. ```cmake IF(APPLE) SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup") ENDIF(APPLE) ``` -------------------------------- ### Find Python Interpreter Source: https://github.com/project/libubox/blob/master/tests/cram/CMakeLists.txt Locates the Python interpreter required for the project. Ensures Python 3 is available. ```cmake FIND_PACKAGE(PythonInterp 3 REQUIRED) ``` -------------------------------- ### Add Fuzzer Test Macro Source: https://github.com/project/libubox/blob/master/tests/fuzz/CMakeLists.txt Defines a CMake macro to add a fuzzer executable. It configures compiler and linker options for various sanitizers (fuzzer, address, leak, undefined) and links necessary libraries. ```cmake MACRO(ADD_FUZZER_TEST name) ADD_EXECUTABLE(${name} ${name}.c) TARGET_COMPILE_OPTIONS(${name} PRIVATE -g -O1 -fno-omit-frame-pointer -fsanitize=fuzzer,address,leak,undefined) TARGET_INCLUDE_DIRECTORIES(${name} PRIVATE ${PROJECT_SOURCE_DIR}) TARGET_LINK_OPTIONS(${name} PRIVATE -stdlib=libc++ -fsanitize=fuzzer,address,leak,undefined) TARGET_LINK_LIBRARIES(${name} ubox blobmsg_json json_script ${json}) ADD_TEST( NAME ${name} COMMAND ${name} -max_len=256 -timeout=10 -max_total_time=300 ${CMAKE_CURRENT_SOURCE_DIR}/corpus ) ENDMACRO(ADD_FUZZER_TEST) ``` -------------------------------- ### Conditional Fuzzing Subdirectory Source: https://github.com/project/libubox/blob/master/tests/CMakeLists.txt Adds the 'fuzz' subdirectory to the build only if the C compiler is Clang. This suggests fuzzing targets are specific to Clang. ```cmake IF(CMAKE_C_COMPILER_ID STREQUAL "Clang") ADD_SUBDIRECTORY(fuzz) ENDIF() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.