<commit_before># Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.5)
project(LibProtobufMutator CXX)

# External dependencies
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/external)

# External dependencies
include(ProcessorCount)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

find_package(Threads REQUIRED)

find_package(LibLZMA REQUIRED)
include_directories(${LIBLZMA_INCLUDE_DIRS})

find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})

set(CMAKE_CXX_STANDARD 11)

option(LIB_PROTO_MUTATOR_WITH_ASAN "Enable address sanitizer" ON)

include_directories(${PROJECT_SOURCE_DIR})

set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
check_cxx_compiler_flag(-fsanitize=address LIB_PROTO_MUTATOR_HAS_SANITIZE_ADDRESS)
check_cxx_compiler_flag("-fsanitize=address -fsanitize-address-use-after-scope"
                        LIB_PROTO_MUTATOR_HAS_SANITIZE_SCOPE)
unset(CMAKE_REQUIRED_FLAGS)
check_cxx_compiler_flag(-fsanitize=leak LIB_PROTO_MUTATOR_HAS_SANITIZE_LEAK)

set(CMAKE_REQUIRED_FLAGS "-fsanitize-coverage=trace-pc-guard")
check_cxx_compiler_flag(-fsanitize-coverage=trace-pc-guard LIB_PROTO_MUTATOR_HAS_TRACE_PC)
unset(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_FLAGS "-fsanitize-coverage=trace-cmp")
check_cxx_compiler_flag(-fsanitize-coverage=trace-cmp LIB_PROTO_MUTATOR_HAS_TRACE_CMP)
unset(CMAKE_REQUIRED_FLAGS)

if (LIB_PROTO_MUTATOR_HAS_TRACE_PC)
  list(APPEND SANITIZE_COVERAGE_OPTIONS trace-pc-guard)
endif()
if (LIB_PROTO_MUTATOR_HAS_TRACE_CMP)
  list(APPEND SANITIZE_COVERAGE_OPTIONS trace-cmp)
endif()

if (SANITIZE_COVERAGE_OPTIONS)
  foreach(OPT ${SANITIZE_COVERAGE_OPTIONS})
    set(FUZZING_FLAGS "${FUZZING_FLAGS},${OPT}")
  endforeach()
  string(SUBSTRING ${FUZZING_FLAGS} 1 -1 FUZZING_FLAGS)
  set(FUZZING_FLAGS "-fsanitize-coverage=${FUZZING_FLAGS}")
endif()

set(EXTRA_FLAGS "-fno-exceptions -Werror -Wall")
if (LIB_PROTO_MUTATOR_WITH_ASAN)
  if (LIB_PROTO_MUTATOR_HAS_SANITIZE_ADDRESS)
    set(EXTRA_FLAGS "${EXTRA_FLAGS} -fsanitize=address")
    if (LIB_PROTO_MUTATOR_HAS_SANITIZE_SCOPE)
      set(EXTRA_FLAGS "${EXTRA_FLAGS} -fsanitize-address-use-after-scope")
    endif()
  endif()
  if (LIB_PROTO_MUTATOR_HAS_SANITIZE_LEAK)
    set(EXTRA_FLAGS "${EXTRA_FLAGS} -fsanitize=leak")
  endif()
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS}")

include(googletest)
include(protobuf)

# Libraries
add_library(protobuf-mutator
            src/libfuzzer_protobuf_mutator.cc
            src/protobuf_mutator.cc)
target_link_libraries(protobuf-mutator
                      ${PROTOBUF_LIBRARY})

# Tests
enable_testing()
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS src/protobuf_mutator.proto)<commit_msg>Remove -fsanitize=leak, address sanitizer detects leaks<commit_after># Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.5)
project(LibProtobufMutator CXX)

# External dependencies
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/external)

# External dependencies
include(ProcessorCount)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

find_package(Threads REQUIRED)

find_package(LibLZMA REQUIRED)
include_directories(${LIBLZMA_INCLUDE_DIRS})

find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})

set(CMAKE_CXX_STANDARD 11)

option(LIB_PROTO_MUTATOR_WITH_ASAN "Enable address sanitizer" ON)

include_directories(${PROJECT_SOURCE_DIR})

set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
check_cxx_compiler_flag(-fsanitize=address LIB_PROTO_MUTATOR_HAS_SANITIZE_ADDRESS)
check_cxx_compiler_flag("-fsanitize=address -fsanitize-address-use-after-scope"
                        LIB_PROTO_MUTATOR_HAS_SANITIZE_SCOPE)
unset(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_FLAGS "-fsanitize-coverage=trace-pc-guard")
check_cxx_compiler_flag(-fsanitize-coverage=trace-pc-guard LIB_PROTO_MUTATOR_HAS_TRACE_PC)
unset(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_FLAGS "-fsanitize-coverage=trace-cmp")
check_cxx_compiler_flag(-fsanitize-coverage=trace-cmp LIB_PROTO_MUTATOR_HAS_TRACE_CMP)
unset(CMAKE_REQUIRED_FLAGS)

if (LIB_PROTO_MUTATOR_HAS_TRACE_PC)
  list(APPEND SANITIZE_COVERAGE_OPTIONS trace-pc-guard)
endif()
if (LIB_PROTO_MUTATOR_HAS_TRACE_CMP)
  list(APPEND SANITIZE_COVERAGE_OPTIONS trace-cmp)
endif()

if (SANITIZE_COVERAGE_OPTIONS)
  foreach(OPT ${SANITIZE_COVERAGE_OPTIONS})
    set(FUZZING_FLAGS "${FUZZING_FLAGS},${OPT}")
  endforeach()
  string(SUBSTRING ${FUZZING_FLAGS} 1 -1 FUZZING_FLAGS)
  set(FUZZING_FLAGS "-fsanitize-coverage=${FUZZING_FLAGS}")
endif()

set(EXTRA_FLAGS "-fno-exceptions -Werror -Wall")
if (LIB_PROTO_MUTATOR_WITH_ASAN)
  if (LIB_PROTO_MUTATOR_HAS_SANITIZE_ADDRESS)
    set(EXTRA_FLAGS "${EXTRA_FLAGS} -fsanitize=address")
    if (LIB_PROTO_MUTATOR_HAS_SANITIZE_SCOPE)
      set(EXTRA_FLAGS "${EXTRA_FLAGS} -fsanitize-address-use-after-scope")
    endif()
  endif()
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS}")

include(googletest)
include(protobuf)

# Libraries
add_library(protobuf-mutator
            src/libfuzzer_protobuf_mutator.cc
            src/protobuf_mutator.cc)
target_link_libraries(protobuf-mutator
                      ${PROTOBUF_LIBRARY})

# Tests
enable_testing()
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS src/protobuf_mutator.proto)
{'fraction_non_alphanumeric': 0.09144451332920024, 'fraction_numerical': 0.0043397396156230625, 'mean_word_length': 6.691299165673421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1593454', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2317, 'n_words': 408}