|
| 1 | +# Copyright 2023-2025 AVSystem <avsystem@avsystem.com> |
| 2 | +# AVSystem Anjay Lite LwM2M SDK |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under AVSystem Anjay Lite LwM2M Client SDK - Non-Commercial License. |
| 6 | +# See the attached LICENSE file for details. |
| 7 | + |
| 8 | +cmake_minimum_required(VERSION 3.6.0) |
| 9 | + |
| 10 | +# Core CMake code is located in cmake/anjay_lite-config.cmake and the library is |
| 11 | +# supposed to be imported using find_package() mechanism - this file only meant |
| 12 | +# to be a convenience wrapper for all example and test targets. |
| 13 | + |
| 14 | +project(anjay_lite C) |
| 15 | + |
| 16 | +set(CMAKE_C_STANDARD 99) |
| 17 | +set(CMAKE_C_EXTENSIONS OFF) |
| 18 | + |
| 19 | +# Below find_package() call is meant for IDE indexing purposes. |
| 20 | +set(anjay_lite_DIR "cmake") |
| 21 | +find_package(anjay_lite REQUIRED) |
| 22 | + |
| 23 | +find_program(VALGRIND_EXECUTABLE valgrind) |
| 24 | + |
| 25 | +add_custom_target(run_tests) |
| 26 | + |
| 27 | +function(add_standalone_target NAME PATH WITH_VALGRIND) |
| 28 | + set(workdir "${CMAKE_BINARY_DIR}/${NAME}") |
| 29 | + |
| 30 | + string(REPLACE " " ";" unescaped_c_flags "${CMAKE_C_FLAGS}") |
| 31 | + string(REPLACE " " ";" unescaped_exe_linker_flags "${CMAKE_EXE_LINKER_FLAGS}") |
| 32 | + |
| 33 | + add_custom_target(${NAME} ALL) |
| 34 | + add_custom_command(TARGET ${NAME} COMMAND ${CMAKE_COMMAND} -E make_directory |
| 35 | + "${workdir}") |
| 36 | + add_custom_command( |
| 37 | + TARGET ${NAME} |
| 38 | + COMMAND |
| 39 | + ${CMAKE_COMMAND} -S "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}" -B . |
| 40 | + -DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" |
| 41 | + -DCMAKE_C_FLAGS="${unescaped_c_flags}" |
| 42 | + -DCMAKE_EXE_LINKER_FLAGS="${unescaped_exe_linker_flags}" |
| 43 | + COMMAND ${CMAKE_COMMAND} --build . --target ${NAME} -- -j${NPROC} |
| 44 | + WORKING_DIRECTORY "${workdir}") |
| 45 | + |
| 46 | + if(WITH_VALGRIND AND VALGRIND_EXECUTABLE) |
| 47 | + add_custom_target( |
| 48 | + ${NAME}_with_valgrind |
| 49 | + DEPENDS ${NAME} |
| 50 | + COMMAND "${VALGRIND_EXECUTABLE}" --leak-check=full --track-origins=yes -q |
| 51 | + --error-exitcode=63 "${workdir}/${NAME}") |
| 52 | + endif() |
| 53 | + |
| 54 | + if(${NAME} MATCHES "_tests") |
| 55 | + add_dependencies(run_tests ${NAME}) |
| 56 | + add_custom_command(TARGET run_tests COMMAND "${workdir}/${NAME}") |
| 57 | + endif() |
| 58 | +endfunction() |
| 59 | + |
| 60 | +# tests |
| 61 | +add_standalone_target(dm_tests tests/anj/dm ON) |
| 62 | +add_standalone_target(dm_without_composite_tests tests/anj/dm_without_composite ON) |
| 63 | +add_standalone_target(observe_tests tests/anj/observe ON) |
| 64 | +add_standalone_target(observe_without_composite_tests tests/anj/observe_without_composite ON) |
| 65 | +add_standalone_target(exchange_tests tests/anj/exchange ON) |
| 66 | +add_standalone_target(io_tests tests/anj/io ON) |
| 67 | +add_standalone_target(io_tests_without_extended tests/anj/io_without_extended ON) |
| 68 | +add_standalone_target(coap_tests tests/anj/coap ON) |
| 69 | +add_standalone_target(net_tests tests/anj/net ON) |
| 70 | +add_standalone_target(core_tests tests/anj/core ON) |
| 71 | + |
| 72 | +# examples |
| 73 | +add_standalone_target(anjay_lite_firmware_update examples/tutorial/firmware-update OFF) |
| 74 | + |
| 75 | +add_standalone_target(anjay_lite_bc_initialization examples/tutorial/BC-Initialization OFF) |
| 76 | +add_standalone_target(anjay_lite_bc_mandatory_objects examples/tutorial/BC-MandatoryObjects OFF) |
| 77 | +add_standalone_target(anjay_lite_bc_object_impl examples/tutorial/BC-BasicObjectImplementation OFF) |
| 78 | +add_standalone_target(anjay_lite_bc_notifications examples/tutorial/BC-Notifications OFF) |
| 79 | +add_standalone_target(anjay_lite_bc_send examples/tutorial/BC-Send OFF) |
| 80 | + |
| 81 | +add_standalone_target(anjay_lite_at_bootstrap examples/tutorial/AT-Bootstrap OFF) |
| 82 | +add_standalone_target(anjay_lite_at_queue_mode examples/tutorial/AT-QueueMode OFF) |
| 83 | +add_standalone_target(anjay_lite_at_multi_instance_object examples/tutorial/AT-MultiInstanceObject OFF) |
| 84 | +add_standalone_target(anjay_lite_at_multi_instance_object_dynamic examples/tutorial/AT-MultiInstanceObjectDynamic OFF) |
| 85 | +add_standalone_target(anjay_lite_at_multi_instance_resource examples/tutorial/AT-MultiInstanceResource OFF) |
| 86 | +add_standalone_target(anjay_lite_at_multi_instance_resource_dynamic examples/tutorial/AT-MultiInstanceResourceDynamic OFF) |
| 87 | + |
| 88 | +add_standalone_target(anjay_lite_minimal_network_api examples/custom-network/minimal OFF) |
| 89 | +add_standalone_target(anjay_lite_reuse_port examples/custom-network/reuse-port OFF) |
| 90 | + |
| 91 | +# Sphinx and doxygen documentation |
| 92 | +add_subdirectory(doc) |
| 93 | + |
| 94 | +# C++ header compatibility check |
| 95 | +add_standalone_target(cxx_header_check tests/cxx_header_check OFF) |
0 commit comments