xref: /aosp_15_r20/external/ot-br-posix/src/agent/CMakeLists.txt (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1#
2#  Copyright (c) 2020-2021, The OpenThread Authors.
3#  All rights reserved.
4#
5#  Redistribution and use in source and binary forms, with or without
6#  modification, are permitted provided that the following conditions are met:
7#  1. Redistributions of source code must retain the above copyright
8#     notice, this list of conditions and the following disclaimer.
9#  2. Redistributions in binary form must reproduce the above copyright
10#     notice, this list of conditions and the following disclaimer in the
11#     documentation and/or other materials provided with the distribution.
12#  3. Neither the name of the copyright holder nor the
13#     names of its contributors may be used to endorse or promote products
14#     derived from this software without specific prior written permission.
15#
16#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26#  POSSIBILITY OF SUCH DAMAGE.
27#
28
29add_executable(otbr-agent
30    application.cpp
31    main.cpp
32    uris.hpp
33    vendor.hpp
34)
35
36target_link_libraries(otbr-agent PRIVATE
37    $<$<BOOL:${OTBR_BORDER_AGENT}>:otbr-border-agent>
38    $<$<BOOL:${OTBR_BACKBONE_ROUTER}>:otbr-backbone-router>
39    $<$<BOOL:${OTBR_DBUS}>:otbr-dbus-server>
40    $<$<BOOL:${OTBR_MDNS}>:otbr-mdns>
41    $<$<BOOL:${OTBR_OPENWRT}>:otbr-ubus>
42    $<$<BOOL:${OTBR_REST}>:otbr-rest>
43    openthread-cli-ftd
44    openthread-ftd
45    openthread-spinel-rcp
46    openthread-radio-spinel
47    openthread-hdlc
48    openthread-posix
49    otbr-sdp-proxy
50    otbr-ncp
51    otbr-common
52    otbr-utils
53)
54
55add_dependencies(otbr-agent ot-ctl print-ot-config otbr-sdp-proxy otbr-utils otbr-ncp)
56if (OTBR_BORDER_AGENT)
57    add_dependencies(otbr-agent otbr-border-agent)
58endif()
59
60install(TARGETS otbr-agent DESTINATION sbin)
61
62if(CMAKE_VERSION VERSION_LESS 3.13)
63    install(PROGRAMS $<TARGET_FILE:ot-ctl> DESTINATION sbin)
64else()
65    install(TARGETS ot-ctl DESTINATION sbin)
66endif()
67
68set(OTBR_AGENT_USER "root" CACHE STRING "set the username running otbr-agent service")
69set(OTBR_AGENT_GROUP "root" CACHE STRING "set the group using otbr-agent client")
70
71if(OTBR_MDNS STREQUAL "mDNSResponder")
72    set(EXEC_START_PRE "ExecStartPre=/usr/sbin/service mdns start\n")
73elseif(OTBR_MDNS STREQUAL "avahi")
74    set(EXEC_START_PRE "ExecStartPre=/usr/sbin/service avahi-daemon start\n")
75else()
76    message(WARNING "OTBR_MDNS=\"${OTBR_MDNS}\" is not supported")
77endif()
78
79configure_file(openthread-otbr-posix-config.h.in openthread-otbr-posix-config.h)
80
81if(OTBR_DBUS)
82    configure_file(otbr-agent.conf.in otbr-agent.conf)
83    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.conf
84        DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/dbus-1/system.d)
85endif()
86
87if(OTBR_SYSTEMD_UNIT_DIR)
88    configure_file(otbr-agent.service.in otbr-agent.service)
89    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.service
90        DESTINATION ${OTBR_SYSTEMD_UNIT_DIR}
91    )
92elseif(NOT OTBR_OPENWRT)
93    configure_file(otbr-agent.init.in otbr-agent.init)
94    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.init
95        DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/init.d
96        RENAME otbr-agent)
97endif()
98
99set(OTBR_NO_AUTO_ATTACH "0" CACHE STRING "Set to 1 to disable auto Thread attach")
100
101configure_file(otbr-agent.default.in otbr-agent.default)
102install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.default
103    DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/default
104    RENAME otbr-agent
105)
106
107pkg_check_modules(LIBSYSTEMD libsystemd)
108if(LIBSYSTEMD_FOUND)
109    target_compile_definitions(otbr-config INTERFACE "HAVE_LIBSYSTEMD=1")
110    target_link_libraries(otbr-agent PUBLIC ${LIBSYSTEMD_LIBRARIES})
111endif()
112