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-simulation" PARENT_SCOPE) 30 31add_library(ot-simulation-config INTERFACE) 32 33option(OT_SIMULATION_VIRTUAL_TIME "enable virtual time") 34if(OT_SIMULATION_VIRTUAL_TIME) 35 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_VIRTUAL_TIME=1") 36endif() 37 38option(OT_SIMULATION_VIRTUAL_TIME_UART "enable virtual time for UART") 39if(OT_SIMULATION_VIRTUAL_TIME_UART) 40 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_VIRTUAL_TIME_UART=1") 41endif() 42 43option(OT_SIMULATION_MAX_NETWORK_SIZE "set maximum network size (default: 33)") 44if(OT_SIMULATION_MAX_NETWORK_SIZE) 45 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_MAX_NETWORK_SIZE=${OT_SIMULATION_MAX_NETWORK_SIZE}") 46endif() 47 48option(OT_SIMULATION_INFRA_IF "enable simulation infra if" ON) 49if (OT_SIMULATION_INFRA_IF) 50 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF=1") 51else() 52 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF=0") 53endif() 54 55option(OT_SIMULATION_DNSSD "enable simulation dnssd" ON) 56if (OT_SIMULATION_DNSSD) 57 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD=1") 58else() 59 target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD=0") 60endif() 61 62if(NOT OT_PLATFORM_CONFIG) 63 set(OT_PLATFORM_CONFIG "openthread-core-simulation-config.h" PARENT_SCOPE) 64endif() 65 66list(APPEND OT_PLATFORM_DEFINES 67 "_BSD_SOURCE=1" 68 "_DEFAULT_SOURCE=1" 69 "OPENTHREAD_EXAMPLES_SIMULATION=1" 70 "OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1" 71) 72set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) 73 74add_library(openthread-simulation 75 alarm.c 76 ble.c 77 crypto.c 78 diag.c 79 dns.c 80 dnssd.c 81 dso_transport.c 82 entropy.c 83 flash.c 84 infra_if.c 85 logging.c 86 mdns_socket.c 87 misc.c 88 multipan.c 89 radio.c 90 simul_utils.c 91 spi-stubs.c 92 system.c 93 trel.c 94 uart.c 95 virtual_time/alarm-sim.c 96 virtual_time/platform-sim.c 97 $<TARGET_OBJECTS:openthread-platform-utils> 98) 99 100find_library(LIBRT rt) 101if(LIBRT) 102 target_link_libraries(openthread-simulation PRIVATE ${LIBRT}) 103endif() 104 105target_link_libraries(openthread-simulation PRIVATE 106 openthread-platform 107 ot-simulation-config 108 ot-config 109) 110 111target_compile_options(openthread-simulation PRIVATE 112 ${OT_CFLAGS} 113) 114 115target_include_directories(openthread-simulation PRIVATE 116 ${OT_PUBLIC_INCLUDES} 117 ${PROJECT_SOURCE_DIR}/examples/platforms 118 ${PROJECT_SOURCE_DIR}/src 119 ${PROJECT_SOURCE_DIR}/src/core 120) 121 122if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 123 set(CPACK_PACKAGE_NAME "openthread-simulation") 124 set(CPACK_GENERATOR "DEB") 125 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenThread Authors (https://github.com/openthread/openthread)") 126 set(CPACK_PACKAGE_CONTACT "OpenThread Authors (https://github.com/openthread/openthread)") 127 include(CPack) 128endif() 129