• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14include_guard(GLOBAL)
15
16include("$ENV{PW_ROOT}/pw_build/pigweed.cmake")
17include("$ENV{PW_ROOT}/pw_unit_test/test.cmake")
18
19# Used by pw_add_test to instantiate unit test executables for the host.
20#
21# Required Args:
22#
23#   NAME: name for the desired executable
24#   TEST_DEP: the target which provides the tests for this executable
25#   TEST_MAIN: The test main to use, can be "" to use defaults.
26#
27function(pw_add_test_executable_with_main NAME TEST_DEP TEST_MAIN)
28  pw_parse_arguments(
29    NUM_POSITIONAL_ARGS
30      3
31  )
32
33  # CMake requires a source file to determine the LINKER_LANGUAGE.
34  add_executable("${NAME}" EXCLUDE_FROM_ALL
35                 $<TARGET_PROPERTY:pw_build.empty,SOURCES>)
36
37  set(test_backend "${pw_unit_test_BACKEND}")
38  if ("${TEST_MAIN}" STREQUAL "")
39    if("${test_backend}" STREQUAL "pw_unit_test.light")
40      set(main pw_unit_test.logging_main)
41    elseif("${test_backend}" STREQUAL "pw_unit_test.googletest")
42      set(main pw_third_party.googletest.gmock_main)
43    elseif("${test_backend}" STREQUAL "pw_unit_test.fuzztest")
44      set(main pw_third_party.fuzztest_gtest_main)
45    else()
46      message(FATAL_ERROR
47              "Unsupported test backend selected for host test executables")
48    endif()
49  else()
50    set(main ${TEST_MAIN})
51  endif()
52
53  pw_target_link_targets("${NAME}"
54    PRIVATE
55      "${main}"
56      "${TEST_DEP}"
57  )
58endfunction(pw_add_test_executable_with_main)
59
60# Used by pw_add_test to instantiate unit test executables for the host.
61#
62# Required Args:
63#
64#   NAME: name for the desired executable
65#   TEST_DEP: the target which provides the tests for this executable
66#
67function(pw_add_test_executable NAME TEST_DEP)
68  pw_add_test_executable_with_main(${NAME} ${TEST_DEP} "")
69endfunction(pw_add_test_executable)
70