1# 2# Copyright (c) 2019, 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 29set(OT_PLATFORM_LIB "openthread-posix" PARENT_SCOPE) 30 31add_library(ot-posix-config INTERFACE) 32 33option(OT_DAEMON "Enable daemon mode" OFF) 34if(OT_DAEMON) 35 target_compile_definitions(ot-posix-config 36 INTERFACE "OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE=1" 37 ) 38 39 # We have to add this definition to `ot-config` because openthread core 40 # libraries will set config file to "openthrad-core-posix-config.h" which 41 # depends on `OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE` to correctly enable 42 # PLATFORM_NETIF and PLATFORM_UDP features. Otherwise, openthread core and 43 # posix libraries will use different feature definitions. 44 list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE=1") 45 set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) 46endif() 47 48option(OT_POSIX_INSTALL_EXTERNAL_ROUTES "Install External Routes as IPv6 routes" ON) 49if(OT_POSIX_INSTALL_EXTERNAL_ROUTES) 50 target_compile_definitions(ot-posix-config 51 INTERFACE "OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE=1" 52 ) 53else() 54 target_compile_definitions(ot-posix-config 55 INTERFACE "OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE=0" 56 ) 57endif() 58 59option(OT_POSIX_VIRTUAL_TIME "enable virtual time" OFF) 60if(OT_POSIX_VIRTUAL_TIME) 61 target_compile_definitions(ot-posix-config 62 INTERFACE "OPENTHREAD_POSIX_VIRTUAL_TIME=1" 63 ) 64endif() 65 66option(OT_POSIX_MAX_POWER_TABLE "enable max power table" OFF) 67if(OT_POSIX_MAX_POWER_TABLE) 68 target_compile_definitions(ot-posix-config 69 INTERFACE "OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE=1" 70 ) 71endif() 72 73option(OT_POSIX_SECURE_SETTINGS "enable secure settings" OFF) 74if (OT_POSIX_SECURE_SETTINGS) 75 target_compile_definitions(ot-posix-config 76 INTERFACE "OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE=1" 77 ) 78endif() 79 80set(OT_POSIX_CONFIG_RCP_BUS "" CACHE STRING "RCP bus type") 81if(OT_POSIX_CONFIG_RCP_BUS) 82 target_compile_definitions(ot-posix-config 83 INTERFACE "OPENTHREAD_POSIX_CONFIG_RCP_BUS=OT_POSIX_RCP_BUS_${OT_POSIX_CONFIG_RCP_BUS}" 84 ) 85endif() 86 87set(OT_POSIX_NAT64_CIDR "192.168.255.0/24" CACHE STRING "NAT64 CIDR for OpenThread NAT64") 88if(OT_POSIX_NAT64_CIDR) 89 target_compile_definitions(ot-posix-config 90 INTERFACE "OPENTHREAD_POSIX_CONFIG_NAT64_CIDR=\"${OT_POSIX_NAT64_CIDR}\"" 91 ) 92endif() 93 94if(NOT OT_PLATFORM_CONFIG) 95 set(OT_PLATFORM_CONFIG "openthread-core-posix-config.h" PARENT_SCOPE) 96endif() 97 98set(CMAKE_EXE_LINKER_FLAGS "-rdynamic ${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE) 99 100if(OT_ANDROID_NDK) 101 target_compile_options(ot-posix-config INTERFACE -Wno-sign-compare) 102endif() 103 104add_library(openthread-posix 105 alarm.cpp 106 backbone.cpp 107 backtrace.cpp 108 config_file.cpp 109 daemon.cpp 110 entropy.cpp 111 firewall.cpp 112 hdlc_interface.cpp 113 infra_if.cpp 114 logging.cpp 115 mainloop.cpp 116 memory.cpp 117 misc.cpp 118 multicast_routing.cpp 119 netif.cpp 120 power.cpp 121 power_updater.cpp 122 radio.cpp 123 radio_url.cpp 124 resolver.cpp 125 settings.cpp 126 spi_interface.cpp 127 system.cpp 128 trel.cpp 129 udp.cpp 130 utils.cpp 131 virtual_time.cpp 132) 133 134include(vendor.cmake) 135 136target_link_libraries(openthread-posix 137 PUBLIC 138 openthread-platform 139 PRIVATE 140 openthread-cli-ftd 141 openthread-ftd 142 openthread-hdlc 143 openthread-spinel-rcp 144 openthread-url 145 ot-config-ftd 146 ot-config 147 ot-posix-config 148 $<$<NOT:$<BOOL:${OT_ANDROID_NDK}>>:util> 149 $<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:rt> 150) 151 152option(OT_TARGET_OPENWRT "enable openthread posix for OpenWRT" OFF) 153if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT OT_TARGET_OPENWRT) 154 target_compile_definitions(ot-posix-config 155 INTERFACE "OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE=1" 156 ) 157 target_link_libraries(openthread-posix PRIVATE anl) 158endif() 159 160target_compile_definitions(openthread-posix 161 PUBLIC 162 ${OT_PUBLIC_DEFINES} 163 PRIVATE 164 OPENTHREAD_FTD=1 165 OPENTHREAD_MTD=0 166) 167 168target_compile_options(openthread-posix PRIVATE 169 ${OT_CFLAGS} 170) 171 172target_include_directories(openthread-posix PRIVATE 173 ${OT_PUBLIC_INCLUDES} 174 ${PROJECT_SOURCE_DIR}/src 175 ${PROJECT_SOURCE_DIR}/src/core 176 ${PROJECT_SOURCE_DIR}/third_party/mbedtls/repo/include 177 PUBLIC 178 ${PROJECT_SOURCE_DIR}/src/posix/platform/include 179) 180 181add_executable(ot-posix-test-settings 182 settings.cpp 183) 184target_compile_definitions(ot-posix-test-settings 185 PRIVATE -DSELF_TEST=1 -DOPENTHREAD_CONFIG_LOG_PLATFORM=0 186) 187target_include_directories(ot-posix-test-settings 188 PRIVATE 189 ${PROJECT_SOURCE_DIR}/include 190 ${PROJECT_SOURCE_DIR}/src 191 ${PROJECT_SOURCE_DIR}/src/core 192 ${PROJECT_SOURCE_DIR}/src/posix/platform/include 193) 194add_test(NAME ot-posix-test-settings COMMAND ot-posix-test-settings) 195