xref: /aosp_15_r20/external/ot-br-posix/tests/gtest/CMakeLists.txt (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
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
29cmake_minimum_required(VERSION 3.14)
30project(openthread-br-gtest)
31
32# GoogleTest requires at least C++14
33set(CMAKE_CXX_STANDARD 14)
34set(CMAKE_CXX_STANDARD_REQUIRED ON)
35
36include(FetchContent)
37FetchContent_Declare(
38    googletest
39    URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
40)
41# For Windows: Prevent overriding the parent project's compiler/linker settings
42set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
43FetchContent_MakeAvailable(googletest)
44
45include(GoogleTest)
46
47add_executable(otbr-gtest-unit
48    test_async_task.cpp
49    test_common_types.cpp
50    test_dns_utils.cpp
51    test_logging.cpp
52    test_once_callback.cpp
53    test_pskc.cpp
54    test_task_runner.cpp
55)
56target_link_libraries(otbr-gtest-unit
57    mbedtls
58    otbr-common
59    otbr-ncp
60    otbr-utils
61    GTest::gmock_main
62)
63gtest_discover_tests(otbr-gtest-unit)
64
65if(OTBR_MDNS)
66    add_executable(otbr-gtest-mdns-subscribe
67        test_mdns_subscribe.cpp
68    )
69    target_link_libraries(otbr-gtest-mdns-subscribe
70        otbr-common
71        otbr-mdns
72        GTest::gmock_main
73    )
74    gtest_discover_tests(otbr-gtest-mdns-subscribe)
75endif()
76
77add_executable(otbr-posix-gtest-unit
78    test_netif.cpp
79)
80target_link_libraries(otbr-posix-gtest-unit
81    otbr-posix
82    GTest::gmock_main
83)
84gtest_discover_tests(otbr-posix-gtest-unit PROPERTIES LABELS "sudo")
85
86add_executable(otbr-gtest-host-api
87    ${OTBR_PROJECT_DIRECTORY}/src/ncp/rcp_host.cpp
88    ${OPENTHREAD_PROJECT_DIRECTORY}/tests/gtest/fake_platform.cpp
89    fake_posix_platform.cpp
90    test_rcp_host_api.cpp
91)
92target_include_directories(otbr-gtest-host-api
93    PRIVATE
94        ${OTBR_PROJECT_DIRECTORY}/src
95        ${OPENTHREAD_PROJECT_DIRECTORY}/src/core
96        ${OPENTHREAD_PROJECT_DIRECTORY}/tests/gtest
97)
98target_link_libraries(otbr-gtest-host-api
99    mbedtls
100    otbr-common
101    otbr-utils
102    GTest::gmock_main
103)
104gtest_discover_tests(otbr-gtest-host-api)
105