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 55if(NOT OT_PLATFORM_CONFIG) 56 set(OT_PLATFORM_CONFIG "openthread-core-simulation-config.h" PARENT_SCOPE) 57endif() 58 59list(APPEND OT_PLATFORM_DEFINES 60 "_BSD_SOURCE=1" 61 "_DEFAULT_SOURCE=1" 62 "OPENTHREAD_EXAMPLES_SIMULATION=1" 63 "OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1" 64) 65set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) 66 67add_library(openthread-simulation 68 alarm.c 69 ble.c 70 crypto.c 71 diag.c 72 dns.c 73 dnssd.c 74 dso_transport.c 75 entropy.c 76 flash.c 77 infra_if.c 78 logging.c 79 mdns_socket.c 80 misc.c 81 multipan.c 82 radio.c 83 simul_utils.c 84 spi-stubs.c 85 system.c 86 trel.c 87 uart.c 88 virtual_time/alarm-sim.c 89 virtual_time/platform-sim.c 90 $<TARGET_OBJECTS:openthread-platform-utils> 91) 92 93find_library(LIBRT rt) 94if(LIBRT) 95 target_link_libraries(openthread-simulation PRIVATE ${LIBRT}) 96endif() 97 98target_link_libraries(openthread-simulation PRIVATE 99 openthread-platform 100 ot-simulation-config 101 ot-config 102) 103 104target_compile_options(openthread-simulation PRIVATE 105 ${OT_CFLAGS} 106) 107 108target_include_directories(openthread-simulation PRIVATE 109 ${OT_PUBLIC_INCLUDES} 110 ${PROJECT_SOURCE_DIR}/examples/platforms 111 ${PROJECT_SOURCE_DIR}/src 112 ${PROJECT_SOURCE_DIR}/src/core 113) 114 115if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 116 set(CPACK_PACKAGE_NAME "openthread-simulation") 117 set(CPACK_GENERATOR "DEB") 118 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenThread Authors (https://github.com/openthread/openthread)") 119 set(CPACK_PACKAGE_CONTACT "OpenThread Authors (https://github.com/openthread/openthread)") 120 include(CPack) 121endif() 122