<commit_before>cmake_minimum_required(VERSION 2.8)

project(FlatBuffers)
set(FlatBuffers_VERSION 1.0.0)

# NOTE: Code coverage only works on Linux & OSX.
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
option(FLATBUFFERS_USE_CXX03_STDLIB
  "Use boost classes to enable C++03 stdlib compatibility" OFF)

if(FLATBUFFERS_USE_CXX03_STDLIB)
  find_package(Boost 1.41.0 REQUIRED)
  include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
endif()

configure_file(include/flatbuffers/options.in.h
  "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h")
include_directories("${PROJECT_BINARY_DIR}/include")

set(FlatBuffers_Library_SRCS
  "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h"
  include/flatbuffers/flatbuffers.h
  include/flatbuffers/idl.h
  include/flatbuffers/util.h
  src/base64.cpp
  src/idl_parser.cpp
  src/idl_gen_cpp.cpp
  src/idl_gen_general.cpp
  src/idl_gen_go.cpp
  src/idl_gen_text.cpp
  src/idl_gen_fbs.cpp
  src/flatc.cpp
)

set(FlatBuffers_Compiler_SRCS
  src/flatc.cpp
)

set(FlatBuffers_Tests_SRCS
  tests/test.cpp
  # file generate by running compiler on tests/monster_test.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
)

set(FlatBuffers_Sample_Binary_SRCS
  samples/sample_binary.cpp
  # file generated by running compiler on samples/monster.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)

set(FlatBuffers_Sample_Text_SRCS
  samples/sample_text.cpp
  # file generated by running compiler on samples/monster.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)

# source_group(Compiler FILES ${FlatBuffers_Library_SRCS})
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})

if(APPLE)
  set(CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -Werror -Wextra")
  if(NOT FLATBUFFERS_USE_CXX03_STDLIB)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  endif()
elseif(CMAKE_COMPILER_IS_GNUCXX OR
       CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
       CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  set(CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -fno-strict-aliasing")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  add_definitions(-fPIC)
endif()

if(FLATBUFFERS_CODE_COVERAGE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
  set(CMAKE_EXE_LINKER_FLAGS
      "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include_directories(include)

function(compile_flatbuffers_schema_to_cpp SRC_FBS)
  get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
  string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
  add_custom_command(
    OUTPUT ${GEN_HEADER}
    COMMAND flatc -c -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
    DEPENDS flatc)
endfunction()

add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
target_link_libraries(flatc flatbuffers)

if(FLATBUFFERS_BUILD_TESTS)
  compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
  add_executable(flattests ${FlatBuffers_Tests_SRCS})
  target_link_libraries(flattests flatbuffers)

  compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
  add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
  target_link_libraries(flatsamplebinary flatbuffers)
  add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
  target_link_libraries(flatsampletext flatbuffers)

  enable_testing()
  file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION
       "${CMAKE_CURRENT_BINARY_DIR}")
  add_test(NAME flattests COMMAND flattests)
endif()


if(NOT FLATBUFFERS_INSTALL)
  return()
endif()

#--------------------------------------------------
# INSTALL : setup files for projects that find_package(FlatBuffers)<commit_msg>Don't have main() in shared library<commit_after>cmake_minimum_required(VERSION 2.8)

project(FlatBuffers)
set(FlatBuffers_VERSION 1.0.0)

# NOTE: Code coverage only works on Linux & OSX.
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
option(FLATBUFFERS_USE_CXX03_STDLIB
  "Use boost classes to enable C++03 stdlib compatibility" OFF)

if(FLATBUFFERS_USE_CXX03_STDLIB)
  find_package(Boost 1.41.0 REQUIRED)
  include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
endif()

configure_file(include/flatbuffers/options.in.h
  "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h")
include_directories("${PROJECT_BINARY_DIR}/include")

set(FlatBuffers_Library_SRCS
  "${PROJECT_BINARY_DIR}/include/flatbuffers/options.h"
  include/flatbuffers/flatbuffers.h
  include/flatbuffers/idl.h
  include/flatbuffers/util.h
  src/base64.cpp
  src/idl_parser.cpp
  src/idl_gen_cpp.cpp
  src/idl_gen_general.cpp
  src/idl_gen_go.cpp
  src/idl_gen_text.cpp
  src/idl_gen_fbs.cpp
)

set(FlatBuffers_Compiler_SRCS
  src/flatc.cpp
)

set(FlatBuffers_Tests_SRCS
  tests/test.cpp
  # file generate by running compiler on tests/monster_test.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
)

set(FlatBuffers_Sample_Binary_SRCS
  samples/sample_binary.cpp
  # file generated by running compiler on samples/monster.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)

set(FlatBuffers_Sample_Text_SRCS
  samples/sample_text.cpp
  # file generated by running compiler on samples/monster.fbs
  ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)

# source_group(Compiler FILES ${FlatBuffers_Library_SRCS})
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})

if(APPLE)
  set(CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -Werror -Wextra")
  if(NOT FLATBUFFERS_USE_CXX03_STDLIB)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  endif()
elseif(CMAKE_COMPILER_IS_GNUCXX OR
       CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
       CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  set(CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -fno-strict-aliasing")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  add_definitions(-fPIC)
endif()

if(FLATBUFFERS_CODE_COVERAGE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
  set(CMAKE_EXE_LINKER_FLAGS
      "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include_directories(include)

function(compile_flatbuffers_schema_to_cpp SRC_FBS)
  get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
  string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
  add_custom_command(
    OUTPUT ${GEN_HEADER}
    COMMAND flatc -c -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
    DEPENDS flatc)
endfunction()

add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
add_executable(flatc src/flatc.cpp ${FlatBuffers_Compiler_SRCS})
target_link_libraries(flatc flatbuffers)

if(FLATBUFFERS_BUILD_TESTS)
  compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
  add_executable(flattests ${FlatBuffers_Tests_SRCS})
  target_link_libraries(flattests flatbuffers)

  compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
  include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
  add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
  target_link_libraries(flatsamplebinary flatbuffers)
  add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
  target_link_libraries(flatsampletext flatbuffers)

  enable_testing()
  file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION
       "${CMAKE_CURRENT_BINARY_DIR}")
  add_test(NAME flattests COMMAND flattests)
endif()


if(NOT FLATBUFFERS_INSTALL)
  return()
endif()

#--------------------------------------------------
# INSTALL : setup files for projects that find_package(FlatBuffers)
{'fraction_non_alphanumeric': 0.10907586858898606, 'fraction_numerical': 0.005199716379106594, 'mean_word_length': 6.2086882453151615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3895166', 'n_tokens_mistral': 3343, 'n_tokens_neox': 3202, 'n_words': 474}