xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/examples/stringop/CMakeLists.txt (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# sandboxed_api/examples/stringop/lib:stringop_params_proto
16sapi_protobuf_generate_cpp(
17  _sapi_stringop_params_pb_cc _sapi_stringop_params_pb_h
18  stringop_params.proto
19)
20# Object library to avoid having to use -Wl,--whole-archive. This simulates
21# Bazel's alwayslink=1.
22add_library(sapi_stringop_params_proto OBJECT
23  ${_sapi_stringop_params_pb_cc}
24  ${_sapi_stringop_params_pb_h}
25)
26add_library(sapi::stringop_params_proto ALIAS sapi_stringop_params_proto)
27target_include_directories(sapi_stringop_params_proto PUBLIC
28  ${Protobuf_INCLUDE_DIRS}
29)
30
31# sandboxed_api/examples/stringop/lib:stringop
32add_library(sapi_stringop STATIC
33  stringop.cc
34)
35add_library(sapi::stringop ALIAS sapi_stringop)
36add_dependencies(sapi_stringop
37  sapi::stringop_params_proto
38)
39target_link_libraries(sapi_stringop
40  PRIVATE $<TARGET_OBJECTS:sapi_stringop_params_proto>
41          sapi::base
42          absl::core_headers
43          sapi::lenval_core
44  PUBLIC protobuf::libprotobuf
45)
46
47# sandboxed_api/examples/stringop/lib:stringop-sapi
48add_sapi_library(stringop-sapi
49  FUNCTIONS duplicate_string
50            reverse_string
51            pb_duplicate_string
52            pb_reverse_string
53            nop
54            violate
55            get_raw_c_string
56  INPUTS stringop.cc
57  LIBRARY sapi_stringop
58  LIBRARY_NAME Stringop
59  NAMESPACE ""
60)
61add_library(sapi::stringop_sapi ALIAS stringop-sapi)
62target_link_libraries(stringop-sapi PRIVATE
63  $<TARGET_OBJECTS:sapi_stringop_params_proto>
64  sapi::base
65)
66
67if(SAPI_BUILD_TESTING)
68  # sandboxed_api/examples/stringop:main_stringop
69  add_executable(sapi_main_stringop
70    main_stringop.cc
71  )
72  set_target_properties(sapi_main_stringop PROPERTIES OUTPUT_NAME main_stringop)
73  target_link_libraries(sapi_main_stringop PRIVATE
74    absl::memory
75    absl::log
76    absl::statusor
77    absl::strings
78    sapi::sapi
79    sapi::status
80    sapi::stringop_sapi
81    sapi::test_main
82    sapi::vars
83  )
84  gtest_discover_tests_xcompile(sapi_main_stringop)
85endif()
86