Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / CMakeLists.txt
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
29 cmake_minimum_required(VERSION 3.10.2)
30 project(openthread-br VERSION 0.2.0)
31
32
33 add_library(otbr-config INTERFACE)
34
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)
43
44
45 if(NOT CMAKE_C_STANDARD)
46     set(CMAKE_C_STANDARD 99)
47     set(CMAKE_C_STANDARD_REQUIRED ON)
48 endif()
49
50 if(NOT CMAKE_CXX_STANDARD)
51     set(CMAKE_CXX_STANDARD 11)
52     set(CMAKE_CXX_STANDARD_REQUIRED ON)
53 endif()
54
55 set(CMAKE_CXX_EXTENSIONS OFF)
56
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)
61 endif()
62
63 add_compile_options(-Wall -Wextra -Werror -Wfatal-errors -Wno-missing-braces)
64
65
66 execute_process(
67     COMMAND git describe --dirty --always
68     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
69     OUTPUT_VARIABLE OTBR_GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
70 )
71
72 if(OTBR_GIT_VERSION)
73     set(OTBR_VERSION "${PROJECT_VERSION}-${OTBR_GIT_VERSION}")
74 else()
75     set(OTBR_VERSION "${PROJECT_VERSION}")
76 endif()
77
78 message(STATUS "Version: ${OTBR_VERSION}")
79
80
81 target_include_directories(otbr-config INTERFACE
82     ${PROJECT_SOURCE_DIR}/include
83     ${PROJECT_SOURCE_DIR}/src
84 )
85 target_compile_definitions(otbr-config INTERFACE
86     "OTBR_PACKAGE_NAME=\"OPENTHREAD_BR\""
87     "OTBR_PACKAGE_VERSION=\"${OTBR_VERSION}\""
88 )
89
90 if(BUILD_SHARED_LIBS)
91     target_link_libraries(otbr-config INTERFACE -Wl,--unresolved-symbols=ignore-in-shared-libs)
92 endif()
93
94 find_package(PkgConfig)
95 include(GNUInstallDirs)
96
97 if (OTBR_SRP_ADVERTISING_PROXY)
98     target_compile_definitions(otbr-config INTERFACE
99             OTBR_ENABLE_SRP_ADVERTISING_PROXY=1
100     )
101 endif()
102
103 if (OTBR_BACKBONE_ROUTER)
104     target_compile_definitions(otbr-config INTERFACE
105             OTBR_ENABLE_BACKBONE_ROUTER=1
106     )
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)
111 endif()
112
113 if(OTBR_DBUS)
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
118     )
119 endif()
120
121 if(OTBR_REST)
122     target_compile_definitions(otbr-config INTERFACE
123         OTBR_ENABLE_REST_SERVER=1
124     )
125 endif()
126
127 if(OTBR_WEB)
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)
135 endif()
136
137 if(OTBR_OPENWRT)
138     target_compile_definitions(otbr-config INTERFACE
139         OTBR_ENABLE_OPENWRT=1
140     )
141 endif()
142
143 if(OTBR_UNSECURE_JOIN)
144     target_compile_definitions(otbr-config INTERFACE
145         OTBR_ENABLE_UNSECURE_JOIN=1
146     )
147 endif()
148
149 set(OTBR_MDNS "avahi" CACHE STRING "MDNS service provider")
150 set_property(CACHE OTBR_MDNS PROPERTY STRINGS "avahi" "mDNSResponder")
151
152 pkg_check_modules(SYSTEMD systemd)
153
154 if(SYSTEMD_FOUND)
155     pkg_get_variable(OTBR_SYSTEMD_UNIT_DIR systemd systemdsystemunitdir)
156 endif()
157
158
159 add_subdirectory(third_party EXCLUDE_FROM_ALL)
160 add_subdirectory(src)
161 add_subdirectory(tools)
162
163
164 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
165     include(CTest)
166
167     if(BUILD_TESTING)
168         pkg_check_modules(CPPUTEST cpputest REQUIRED)
169         add_subdirectory(tests)
170     endif()
171
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")
175     include(CPack)
176 endif()
177
178 if (OTBR_DOC)
179     add_subdirectory(doc)
180 endif()