xref: /aosp_15_r20/external/libprotobuf-mutator/src/CMakeLists.txt (revision fd525a9c096e28cf6f8d8719388df0568a611e7b)
1*fd525a9cSAndroid Build Coastguard Worker# Copyright 2017 Google Inc. All rights reserved.
2*fd525a9cSAndroid Build Coastguard Worker#
3*fd525a9cSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*fd525a9cSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*fd525a9cSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*fd525a9cSAndroid Build Coastguard Worker#
7*fd525a9cSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*fd525a9cSAndroid Build Coastguard Worker#
9*fd525a9cSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*fd525a9cSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*fd525a9cSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*fd525a9cSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*fd525a9cSAndroid Build Coastguard Worker# limitations under the License.
14*fd525a9cSAndroid Build Coastguard Worker
15*fd525a9cSAndroid Build Coastguard Workeradd_subdirectory(libfuzzer)
16*fd525a9cSAndroid Build Coastguard Worker
17*fd525a9cSAndroid Build Coastguard Workeradd_library(protobuf-mutator
18*fd525a9cSAndroid Build Coastguard Worker            binary_format.cc
19*fd525a9cSAndroid Build Coastguard Worker            mutator.cc
20*fd525a9cSAndroid Build Coastguard Worker            text_format.cc
21*fd525a9cSAndroid Build Coastguard Worker            utf8_fix.cc)
22*fd525a9cSAndroid Build Coastguard Workertarget_link_libraries(protobuf-mutator
23*fd525a9cSAndroid Build Coastguard Worker                      ${PROTOBUF_LIBRARIES})
24*fd525a9cSAndroid Build Coastguard Workerset_target_properties(protobuf-mutator PROPERTIES
25*fd525a9cSAndroid Build Coastguard Worker                      COMPILE_FLAGS "${NO_FUZZING_FLAGS}"
26*fd525a9cSAndroid Build Coastguard Worker                      SOVERSION 0)
27*fd525a9cSAndroid Build Coastguard Worker
28*fd525a9cSAndroid Build Coastguard Workerif (LIB_PROTO_MUTATOR_TESTING)
29*fd525a9cSAndroid Build Coastguard Worker  protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
30*fd525a9cSAndroid Build Coastguard Worker                        mutator_test_proto2.proto
31*fd525a9cSAndroid Build Coastguard Worker                        mutator_test_proto3.proto)
32*fd525a9cSAndroid Build Coastguard Worker
33*fd525a9cSAndroid Build Coastguard Worker  add_library(mutator-test-proto
34*fd525a9cSAndroid Build Coastguard Worker              ${PROTO_SRCS})
35*fd525a9cSAndroid Build Coastguard Worker
36*fd525a9cSAndroid Build Coastguard Worker  add_executable(mutator_test
37*fd525a9cSAndroid Build Coastguard Worker                 mutator_test.cc
38*fd525a9cSAndroid Build Coastguard Worker                 utf8_fix_test.cc
39*fd525a9cSAndroid Build Coastguard Worker                 weighted_reservoir_sampler_test.cc)
40*fd525a9cSAndroid Build Coastguard Worker  target_link_libraries(mutator_test
41*fd525a9cSAndroid Build Coastguard Worker                        protobuf-mutator
42*fd525a9cSAndroid Build Coastguard Worker                        mutator-test-proto
43*fd525a9cSAndroid Build Coastguard Worker                        ${ZLIB_LIBRARIES}
44*fd525a9cSAndroid Build Coastguard Worker                        ${GTEST_BOTH_LIBRARIES}
45*fd525a9cSAndroid Build Coastguard Worker                        ${CMAKE_THREAD_LIBS_INIT})
46*fd525a9cSAndroid Build Coastguard Worker
47*fd525a9cSAndroid Build Coastguard Worker  ProcessorCount(CPU_COUNT)
48*fd525a9cSAndroid Build Coastguard Worker  math(EXPR TEST_SHARDS_COUNT 2*${CPU_COUNT})
49*fd525a9cSAndroid Build Coastguard Worker  math(EXPR TEST_SHARDS_MAX ${TEST_SHARDS_COUNT}-1)
50*fd525a9cSAndroid Build Coastguard Worker  foreach(SHARD RANGE ${TEST_SHARDS_MAX})
51*fd525a9cSAndroid Build Coastguard Worker    add_test(test.protobuf_mutator_test_${SHARD} mutator_test --gtest_color=yes AUTO)
52*fd525a9cSAndroid Build Coastguard Worker    set_property(
53*fd525a9cSAndroid Build Coastguard Worker        TEST test.protobuf_mutator_test_${SHARD}
54*fd525a9cSAndroid Build Coastguard Worker        APPEND PROPERTY ENVIRONMENT
55*fd525a9cSAndroid Build Coastguard Worker        GTEST_SHARD_INDEX=${SHARD}
56*fd525a9cSAndroid Build Coastguard Worker        GTEST_TOTAL_SHARDS=${TEST_SHARDS_COUNT})
57*fd525a9cSAndroid Build Coastguard Worker  endforeach(SHARD)
58*fd525a9cSAndroid Build Coastguard Worker
59*fd525a9cSAndroid Build Coastguard Worker  add_dependencies(check mutator_test)
60*fd525a9cSAndroid Build Coastguard Workerendif()
61*fd525a9cSAndroid Build Coastguard Worker
62*fd525a9cSAndroid Build Coastguard Workerinstall(TARGETS protobuf-mutator
63*fd525a9cSAndroid Build Coastguard Worker        EXPORT libprotobuf-mutatorTargets
64*fd525a9cSAndroid Build Coastguard Worker        ARCHIVE DESTINATION ${LIB_DIR}
65*fd525a9cSAndroid Build Coastguard Worker        LIBRARY DESTINATION ${LIB_DIR}
66*fd525a9cSAndroid Build Coastguard Worker        INCLUDES DESTINATION include/libprotobuf-mutator include/libprotobuf-mutator/src)
67