xref: /aosp_15_r20/external/pigweed/third_party/googletest/CMakeLists.txt (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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.
14
15include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
16
17set(dir_pw_third_party_googletest "" CACHE PATH
18    "Path to the googletest installation. When set, pw_third_party.googletest \
19     is provided")
20
21# If googletest is not configured, a script that displays an error message is
22# used instead. If the build rule is used in the build it fails with this
23# error.
24if(NOT dir_pw_third_party_googletest)
25  pw_add_error_target(pw_third_party.googletest
26    MESSAGE
27      "Attempted to build the pw_third_party.googletest without "
28      "configuring it via dir_pw_third_party_googletest. "
29      "See https://pigweed.dev/third_party/googletest."
30  )
31
32  pw_add_library(pw_third_party.googletest.gtest_main INTERFACE
33    PUBLIC_DEPS
34      pw_third_party.googletest
35  )
36
37  pw_add_library(pw_third_party.googletest.gmock_main INTERFACE
38    PUBLIC_DEPS
39      pw_third_party.googletest
40  )
41
42else()  # dir_pw_thid_parrty_googletest is set
43  pw_add_library(pw_third_party.googletest STATIC
44    SOURCES
45      # Only add the "*-all.cc" files (and no headers) to improve maintainability
46      # from upstream refactoring. The "*-all.cc" files include the respective
47      # source files.
48      ${dir_pw_third_party_googletest}/googlemock/src/gmock-all.cc
49      ${dir_pw_third_party_googletest}/googletest/src/gtest-all.cc
50    HEADERS
51      ${dir_pw_third_party_googletest}/googlemock/include/gmock/gmock.h
52      ${dir_pw_third_party_googletest}/googletest/include/gtest/gtest-spi.h
53      ${dir_pw_third_party_googletest}/googletest/include/gtest/gtest.h
54    PUBLIC_INCLUDES
55      ${dir_pw_third_party_googletest}/googletest
56      ${dir_pw_third_party_googletest}/googletest/include
57      ${dir_pw_third_party_googletest}/googlemock
58      ${dir_pw_third_party_googletest}/googlemock/include
59    PUBLIC_COMPILE_OPTIONS
60      -Wno-undef
61  )
62
63  pw_add_library(pw_third_party.googletest.gtest_main STATIC
64    SOURCES
65      ${dir_pw_third_party_googletest}/googletest/src/gtest_main.cc
66    PUBLIC_DEPS
67      pw_third_party.googletest
68  )
69
70  pw_add_library(pw_third_party.googletest.gmock_main STATIC
71    SOURCES
72      ${dir_pw_third_party_googletest}/googlemock/src/gmock_main.cc
73    PUBLIC_DEPS
74      pw_third_party.googletest
75  )
76endif()
77