1#
2#  Copyright (c) 2020, 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_library(openthread-radio-spinel)
30add_library(openthread-spinel-ncp)
31add_library(openthread-spinel-rcp)
32
33target_compile_definitions(openthread-radio-spinel PRIVATE
34    OPENTHREAD_FTD=0
35    OPENTHREAD_MTD=0
36    OPENTHREAD_RADIO=0
37)
38
39target_compile_definitions(openthread-spinel-ncp PRIVATE
40    OPENTHREAD_FTD=0
41    OPENTHREAD_MTD=0
42    OPENTHREAD_RADIO=0
43    PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1
44)
45
46target_compile_definitions(openthread-spinel-rcp PRIVATE
47    OPENTHREAD_FTD=0
48    OPENTHREAD_MTD=0
49    OPENTHREAD_RADIO=0
50    PUBLIC OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=0
51)
52
53target_compile_options(openthread-radio-spinel PRIVATE
54    ${OT_CFLAGS}
55)
56
57target_compile_options(openthread-spinel-ncp PRIVATE
58    ${OT_CFLAGS}
59)
60
61target_compile_options(openthread-spinel-rcp PRIVATE
62    ${OT_CFLAGS}
63)
64
65set(COMMON_INCLUDES
66    ${PROJECT_SOURCE_DIR}/src
67    ${PROJECT_SOURCE_DIR}/src/core
68)
69
70set(COMMON_SOURCES
71    spinel.c
72    spinel_buffer.cpp
73    spinel_decoder.cpp
74    spinel_encoder.cpp
75    spinel_helper.cpp
76)
77
78set(OT_SPINEL_VENDOR_HOOK_SOURCE "" CACHE STRING "set vendor hook source file for Spinel")
79set(OT_SPINEL_VENDOR_HOOK_HEADER "" CACHE STRING "set vendor hook header file for Spinel")
80if(OT_SPINEL_VENDOR_HOOK_SOURCE)
81    target_compile_definitions(openthread-spinel-rcp PUBLIC "OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE=1")
82    target_compile_definitions(openthread-spinel-ncp PUBLIC "OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE=1")
83    target_compile_definitions(openthread-spinel-rcp PUBLIC "OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_HEADER=\"${OT_SPINEL_VENDOR_HOOK_HEADER}\"")
84    target_compile_definitions(openthread-spinel-ncp PUBLIC "OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_HEADER=\"${OT_SPINEL_VENDOR_HOOK_HEADER}\"")
85    list(APPEND COMMON_SOURCES ${OT_SPINEL_VENDOR_HOOK_SOURCE_DIR}${OT_SPINEL_VENDOR_HOOK_SOURCE})
86    list(APPEND COMMON_INCLUDES ${OT_SPINEL_VENDOR_HOOK_SOURCE_DIR})
87endif()
88
89target_include_directories(openthread-radio-spinel PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
90target_include_directories(openthread-spinel-ncp PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
91target_include_directories(openthread-spinel-rcp PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES})
92
93target_sources(openthread-radio-spinel
94    PRIVATE
95        logger.cpp
96        radio_spinel.cpp
97        spinel_driver.cpp
98        spinel_helper.cpp
99)
100target_sources(openthread-spinel-ncp PRIVATE ${COMMON_SOURCES})
101target_sources(openthread-spinel-rcp PRIVATE ${COMMON_SOURCES})
102
103target_link_libraries(openthread-radio-spinel
104    INTERFACE
105        ot-lib-config
106    PRIVATE
107        ot-config
108)
109
110target_link_libraries(openthread-spinel-ncp
111    INTERFACE
112        ot-lib-config
113    PRIVATE
114        ot-config-ftd
115        ot-config
116)
117
118target_link_libraries(openthread-spinel-rcp
119    INTERFACE
120        ot-lib-config
121    PRIVATE
122        ot-config-radio
123        ot-config
124)
125
126if(BUILD_TESTING)
127    add_executable(ot-test-spinel
128        spinel.c
129    )
130    target_compile_definitions(ot-test-spinel
131        PRIVATE -DSPINEL_SELF_TEST=1 -D_GNU_SOURCE
132    )
133    add_test(NAME ot-test-spinel COMMAND ot-test-spinel)
134endif()
135