2 # Copyright (c) 2020, The OpenThread Authors.
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.
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.
29 cmake_minimum_required(VERSION 3.10.2)
30 project(openthread-br VERSION 0.2.0)
33 add_library(otbr-config INTERFACE)
35 option(OTBR_SRP_ADVERTISING_PROXY "Enable Advertising Proxy" OFF)
36 option(OTBR_BACKBONE_ROUTER "Enable Backbone Router" OFF)
37 option(OTBR_DBUS "Enable DBus support" OFF)
38 option(OTBR_OPENWRT "Enable OpenWrt support" OFF)
39 option(OTBR_UNSECURE_JOIN "Enable unsecure joining" OFF)
40 option(OTBR_WEB "Enable Web GUI" OFF)
41 option(OTBR_REST "Enable Rest Server" OFF)
42 option(OTBR_DOC "Build documentation" OFF)
45 if(NOT CMAKE_C_STANDARD)
46 set(CMAKE_C_STANDARD 99)
47 set(CMAKE_C_STANDARD_REQUIRED ON)
50 if(NOT CMAKE_CXX_STANDARD)
51 set(CMAKE_CXX_STANDARD 11)
52 set(CMAKE_CXX_STANDARD_REQUIRED ON)
55 set(CMAKE_CXX_EXTENSIONS OFF)
57 if (OTBR_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
58 message(STATUS "Coverage: ON")
59 target_compile_options(otbr-config INTERFACE -g -O0 --coverage)
60 target_link_libraries(otbr-config INTERFACE --coverage)
63 add_compile_options(-Wall -Wextra -Werror -Wfatal-errors -Wno-missing-braces)
67 COMMAND git describe --dirty --always
68 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
69 OUTPUT_VARIABLE OTBR_GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
73 set(OTBR_VERSION "${PROJECT_VERSION}-${OTBR_GIT_VERSION}")
75 set(OTBR_VERSION "${PROJECT_VERSION}")
78 message(STATUS "Version: ${OTBR_VERSION}")
81 target_include_directories(otbr-config INTERFACE
82 ${PROJECT_SOURCE_DIR}/include
83 ${PROJECT_SOURCE_DIR}/src
85 target_compile_definitions(otbr-config INTERFACE
86 "OTBR_PACKAGE_NAME=\"OPENTHREAD_BR\""
87 "OTBR_PACKAGE_VERSION=\"${OTBR_VERSION}\""
91 target_link_libraries(otbr-config INTERFACE -Wl,--unresolved-symbols=ignore-in-shared-libs)
94 find_package(PkgConfig)
95 include(GNUInstallDirs)
97 if (OTBR_SRP_ADVERTISING_PROXY)
98 target_compile_definitions(otbr-config INTERFACE
99 OTBR_ENABLE_SRP_ADVERTISING_PROXY=1
103 if (OTBR_BACKBONE_ROUTER)
104 target_compile_definitions(otbr-config INTERFACE
105 OTBR_ENABLE_BACKBONE_ROUTER=1
107 set(OT_BACKBONE_ROUTER_DUA_NDPROXYING ON CACHE BOOL "Enable Backbone Router DUA ND Proxying in OpenThread" FORCE)
108 set(OT_THREAD_VERSION 1.2 CACHE STRING "Backbone Router requires Thread 1.2 or higher" FORCE)
109 set(OT_BACKBONE_ROUTER ON CACHE BOOL "Enable Backbone Router feature in OpenThread" FORCE)
110 set(OT_SERVICE ON CACHE BOOL "Backbone Router requires Thread network service" FORCE)
114 pkg_check_modules(DBUS REQUIRED dbus-1)
115 pkg_get_variable(OTBR_DBUS_SYSTEM_BUS_SERVICES_DIR dbus-1 system_bus_services_dir)
116 target_compile_definitions(otbr-config INTERFACE
117 OTBR_ENABLE_DBUS_SERVER=1
122 target_compile_definitions(otbr-config INTERFACE
123 OTBR_ENABLE_REST_SERVER=1
128 pkg_check_modules(JSONCPP jsoncpp REQUIRED)
129 set(Boost_USE_STATIC_LIBS ON)
130 set(Boost_USE_MULTITHREADED ON)
131 set(Boost_USE_STATIC_RUNTIME OFF)
132 find_package(Boost REQUIRED
133 COMPONENTS filesystem system)
134 set(OTBR_WEB_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/otbr-web)
138 target_compile_definitions(otbr-config INTERFACE
139 OTBR_ENABLE_OPENWRT=1
143 if(OTBR_UNSECURE_JOIN)
144 target_compile_definitions(otbr-config INTERFACE
145 OTBR_ENABLE_UNSECURE_JOIN=1
149 set(OTBR_MDNS "avahi" CACHE STRING "MDNS service provider")
150 set_property(CACHE OTBR_MDNS PROPERTY STRINGS "avahi" "mDNSResponder")
152 pkg_check_modules(SYSTEMD systemd)
155 pkg_get_variable(OTBR_SYSTEMD_UNIT_DIR systemd systemdsystemunitdir)
159 add_subdirectory(third_party EXCLUDE_FROM_ALL)
160 add_subdirectory(src)
161 add_subdirectory(tools)
164 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
168 pkg_check_modules(CPPUTEST cpputest REQUIRED)
169 add_subdirectory(tests)
172 set(CPACK_GENERATOR "DEB")
173 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenThread Authors <openthread-users@googlegroups.com")
174 set(CPACK_PACKAGE_CONTACT "OpenThread Authors <openthread-users@googlegroups.com")
179 add_subdirectory(doc)