2022-01-30 20:56:16 +00:00
|
|
|
# This is the legacy minimum version flatbuffers supported for a while.
|
2023-01-30 07:00:57 +00:00
|
|
|
cmake_minimum_required(VERSION 3.8...3.25.2)
|
2022-01-30 20:56:16 +00:00
|
|
|
|
2022-02-23 00:40:42 +00:00
|
|
|
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
|
|
|
include(CMake/Version.cmake)
|
|
|
|
|
2023-01-30 07:00:57 +00:00
|
|
|
project(FlatBuffers
|
2022-02-23 00:40:42 +00:00
|
|
|
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
2021-11-18 04:22:23 +00:00
|
|
|
LANGUAGES CXX)
|
|
|
|
|
2018-10-29 18:29:05 +00:00
|
|
|
# generate compile_commands.json
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2014-01-28 00:52:49 +00:00
|
|
|
|
|
|
|
# NOTE: Code coverage only works on Linux & OSX.
|
|
|
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
2014-09-10 23:01:13 +00:00
|
|
|
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
2014-09-15 16:50:23 +00:00
|
|
|
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
2016-07-02 01:08:51 +00:00
|
|
|
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
|
|
|
ON)
|
|
|
|
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
|
|
|
ON)
|
2019-11-18 20:16:41 +00:00
|
|
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
|
|
|
OFF)
|
2023-05-05 19:08:09 +00:00
|
|
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" OFF)
|
2022-02-22 23:12:11 +00:00
|
|
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
|
2021-11-15 21:41:22 +00:00
|
|
|
OFF)
|
2016-04-14 01:16:05 +00:00
|
|
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
2016-09-06 17:12:04 +00:00
|
|
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
|
|
|
"Enable the build of the flatbuffers shared library"
|
|
|
|
OFF)
|
2018-07-19 16:40:28 +00:00
|
|
|
option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
|
2018-10-29 18:29:05 +00:00
|
|
|
# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
|
2018-12-06 19:12:06 +00:00
|
|
|
option(FLATBUFFERS_CODE_SANITIZE
|
2018-10-29 18:29:05 +00:00
|
|
|
"Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
|
|
|
|
OFF)
|
2019-02-21 19:06:04 +00:00
|
|
|
option(FLATBUFFERS_PACKAGE_REDHAT
|
|
|
|
"Build an rpm using the 'package' target."
|
|
|
|
OFF)
|
|
|
|
option(FLATBUFFERS_PACKAGE_DEBIAN
|
|
|
|
"Build an deb using the 'package' target."
|
|
|
|
OFF)
|
2019-12-23 20:13:48 +00:00
|
|
|
option(FLATBUFFERS_BUILD_CPP17
|
|
|
|
"Enable the build of c++17 test target. \"
|
|
|
|
Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
|
|
|
|
OFF)
|
|
|
|
option(FLATBUFFERS_BUILD_LEGACY
|
|
|
|
"Run C++ code generator with '--cpp-std c++0x' switch."
|
|
|
|
OFF)
|
2020-03-27 15:35:44 +00:00
|
|
|
option(FLATBUFFERS_ENABLE_PCH
|
|
|
|
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
|
|
|
Only work if CMake supports 'target_precompile_headers'. \"
|
|
|
|
This can speed up compilation time."
|
|
|
|
OFF)
|
2022-11-18 19:04:46 +00:00
|
|
|
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
2021-12-01 07:13:24 +00:00
|
|
|
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
|
|
|
types." OFF)
|
2022-11-18 19:04:46 +00:00
|
|
|
option(FLATBUFFERS_STRICT_MODE
|
2022-08-07 04:06:14 +00:00
|
|
|
"Build flatbuffers with all warnings as errors (-Werror or /WX)."
|
|
|
|
OFF)
|
2019-02-25 19:42:37 +00:00
|
|
|
|
2022-08-26 07:22:27 +00:00
|
|
|
if(NOT DEFINED FLATBUFFERS_CPP_STD)
|
|
|
|
set(FLATBUFFERS_CPP_STD 11)
|
|
|
|
endif()
|
|
|
|
|
2022-08-06 05:08:36 +00:00
|
|
|
set(MSVC_LIKE OFF)
|
|
|
|
if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
|
|
|
set(MSVC_LIKE ON)
|
|
|
|
endif()
|
|
|
|
|
2023-01-30 07:00:57 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(IS_CLANG ON)
|
|
|
|
else()
|
|
|
|
set(IS_CLANG OFF)
|
|
|
|
endif()
|
|
|
|
|
2022-08-28 23:54:58 +00:00
|
|
|
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
|
|
|
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
|
|
|
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
|
|
|
endif()
|
|
|
|
|
2015-01-02 12:51:31 +00:00
|
|
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
|
|
|
message(WARNING
|
|
|
|
"Cannot build tests without building the compiler. Tests will be disabled.")
|
|
|
|
set(FLATBUFFERS_BUILD_TESTS OFF)
|
|
|
|
endif()
|
2014-01-28 00:52:49 +00:00
|
|
|
|
2018-10-04 16:27:37 +00:00
|
|
|
if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
|
|
|
# Override the default recursion depth limit.
|
|
|
|
add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
|
|
|
|
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
|
|
|
endif()
|
|
|
|
|
2019-05-09 17:15:29 +00:00
|
|
|
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
2018-11-16 17:24:06 +00:00
|
|
|
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
2021-11-18 04:22:23 +00:00
|
|
|
include(CheckCXXSymbolExists)
|
|
|
|
|
2019-05-09 17:15:29 +00:00
|
|
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
2022-08-06 05:08:36 +00:00
|
|
|
if(MSVC_LIKE)
|
2019-05-09 17:15:29 +00:00
|
|
|
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
|
|
|
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
2018-11-16 17:24:06 +00:00
|
|
|
else()
|
2019-05-09 17:15:29 +00:00
|
|
|
check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
|
|
|
check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
|
|
|
endif()
|
|
|
|
if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
|
|
|
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
|
2018-11-16 17:24:06 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
|
|
|
|
2022-10-29 00:23:36 +00:00
|
|
|
if(NOT WIN32)
|
|
|
|
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
|
|
|
|
if(NOT HAVE_REALPATH)
|
|
|
|
add_definitions(-DFLATBUFFERS_NO_ABSOLUTE_PATH_RESOLUTION)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-07-22 12:18:59 +00:00
|
|
|
set(FlatBuffers_Library_SRCS
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/allocator.h
|
|
|
|
include/flatbuffers/array.h
|
2017-06-16 03:54:04 +00:00
|
|
|
include/flatbuffers/base.h
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/buffer.h
|
|
|
|
include/flatbuffers/buffer_ref.h
|
|
|
|
include/flatbuffers/default_allocator.h
|
|
|
|
include/flatbuffers/detached_buffer.h
|
2023-01-08 23:01:33 +00:00
|
|
|
include/flatbuffers/code_generator.h
|
2023-04-06 01:49:29 +00:00
|
|
|
include/flatbuffers/file_manager.h
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/flatbuffer_builder.h
|
2014-01-28 00:52:49 +00:00
|
|
|
include/flatbuffers/flatbuffers.h
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/flexbuffers.h
|
2022-04-05 23:29:42 +00:00
|
|
|
include/flatbuffers/flex_flat_util.h
|
2015-02-13 23:58:29 +00:00
|
|
|
include/flatbuffers/hash.h
|
2014-01-28 00:52:49 +00:00
|
|
|
include/flatbuffers/idl.h
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/minireflect.h
|
2015-05-21 23:33:29 +00:00
|
|
|
include/flatbuffers/reflection.h
|
|
|
|
include/flatbuffers/reflection_generated.h
|
2017-06-16 03:54:04 +00:00
|
|
|
include/flatbuffers/registry.h
|
2021-11-11 06:26:09 +00:00
|
|
|
include/flatbuffers/stl_emulation.h
|
|
|
|
include/flatbuffers/string.h
|
|
|
|
include/flatbuffers/struct.h
|
|
|
|
include/flatbuffers/table.h
|
|
|
|
include/flatbuffers/util.h
|
|
|
|
include/flatbuffers/vector.h
|
|
|
|
include/flatbuffers/vector_downward.h
|
|
|
|
include/flatbuffers/verifier.h
|
2014-01-28 00:52:49 +00:00
|
|
|
src/idl_parser.cpp
|
2015-07-22 12:18:59 +00:00
|
|
|
src/idl_gen_text.cpp
|
2015-07-31 20:55:53 +00:00
|
|
|
src/reflection.cpp
|
2016-03-31 00:34:52 +00:00
|
|
|
src/util.cpp
|
2015-07-22 12:18:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
set(FlatBuffers_Compiler_SRCS
|
|
|
|
${FlatBuffers_Library_SRCS}
|
2023-01-25 17:05:48 +00:00
|
|
|
src/idl_gen_binary.cpp
|
|
|
|
src/idl_gen_text.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
src/idl_gen_cpp.cpp
|
2019-11-11 19:37:55 +00:00
|
|
|
src/idl_gen_csharp.cpp
|
Add [Dart] support (#4676)
* Add [Dart] support
* fix enum vectors
* Allow for opt out of string interning
* fix comment style, make interning opt in
* remove Offset<T>, prefer int
* avoid creating unnecessary vtable objects
* start work on tests - do not generate builder if struct has 0 fields - add int64
* support reading structs properly
* correctly handle reading vectors of structs, dartfmt
* support structs, fix unnecessary prepares
* fix bool customizations
* undo unintentional removal of file
* docs updates, complete tutorial, bug fix for codegen
* more documentation
* Update docs, add to doxygen file
* update package structure, add samples script/code
* rearrange sample
* Tests
* Add readme for pub
* cleanup package for pub
* update docs for renamed file
* remove custom matcher, use `closeTo` instead
* remove unintentional file
* remove unintended file checkin
* use auto, move method, cleanup
* refactor to ObjectBuilders, add Builders
* Update tests, examples
* Add files missing from previous commit
* documentation and example updates
* Update LICENSE, make dartanalyzer happy, fix minor bugs, get rid of duplicate files, publish script
* fix sample for slightly different schema
* Update pubspec.yaml
2018-05-18 18:06:15 +00:00
|
|
|
src/idl_gen_dart.cpp
|
2019-07-22 23:05:15 +00:00
|
|
|
src/idl_gen_kotlin.cpp
|
Add Kotlin multiplatform support (#7969)
* [Kotlin] Introduction to Kotlin Multiplaform
The first implementation of the Kotlin code generation was made years
ago at the time Kotlin Multiplaform was not stable and Kotlin is mostly
used on JVM-based targets. For this reason the generated code uses java
based runtime.
That design decision comes with many drawbacks, leaving the code
generated more java-like and making it impossible to use more advanced
features of the Kotlin language.
In this change we are adding two parts: A pure, multi-plaform, Kotlin
runtime and a new code generator to accompany it.
* [Kotlin] Remove scalar sign cast from code generation
Now that we have a new runtime the accepts unsigned types, we don't
need to code generate casting back and from signed scalars. This
MR removes this from both code generations and adds the necessary
API to the runtime.
* [Kotlin] Use offset on public API to represent buffer position
Currently, kotlin was following Java's approach of representing objects,
vectors, tables as "Int" (the position of it in the buffer). This change
replaces naked Int with Offset<T>, offering a type-safe API. So,
instead of
fun Table.createTable(b: FlatBufferBuilder, subTable: Int)
We will have
fun Table.createTable(b: FlatBufferBuilder, subTable: Offset<SubTable>)
Making impossible to accidentally switch parameters.
The performance should be similar to use Int as we are using value
class for Offset and ArrayOffset, which most of the time translate to
Int in the bytecode.
* [Kotlin] Add builder for tables
Add builder constructor to make create of table more ergonomic.
For example the movie sample for the test set could be written as:
Movie.createMovie(fbb,
mainCharacterType = Character_.MuLan,
mainCharacter = att) {
charactersType = charsType
this.characters = characters
}
instead of:
Movie.startMovie(fbb)
Movie.addMainCharacterType(fbb, Character_.MuLan)
Movie.addMainCharacter(fbb, att as Offset<Any>)
Movie.addCharactersType(fbb, charsType)
Movie.addCharacters(fbb, charsVec)
Movie.endMovie(fbb)
* [Kotlin] Move enum types to value class
Moving to flatbuffer enums to value class adds type safety for parameters
with minimum to no performance impact.
* [Kotlin] Simplify Union parameters to avoid naked casting
Just a small change on the APIs that receive union as parameters,
creating a typealias UnionOffset to avoid using Offset<Any>. To "convert"
an table offset to an union, one just call Offset.toUnion().
* [Kotlin] Apply clang-format on kotlin code generators
* [Kotlin] Update kotlin generator to follow official naming conventions
Updating directory, package and enum naming to follow Kotlin official
convention.
https://kotlinlang.org/docs/coding-conventions.html#naming-rules
* [Kotlin] Add fixes to improve performance
1 - Add benchmark comparing serialization between Java & Kotlin
2 - ReadWriteBuffer does not auto-grow (thus avoid check size in every op)
3 - Add specialized add functions on FlatBufferBuilder to avoid boxing
offsets.
4 - Remove a few Kotlin syntax sugar that generated performance penalties.
* [Kotlin] Remove builder from Kotlin KMP and add some optimizations
to avoid boxing of Offset classes
---------
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-05-26 18:00:33 +00:00
|
|
|
src/idl_gen_kotlin_kmp.cpp
|
2014-07-11 23:12:35 +00:00
|
|
|
src/idl_gen_go.cpp
|
2019-11-11 19:37:55 +00:00
|
|
|
src/idl_gen_java.cpp
|
2021-01-14 19:34:44 +00:00
|
|
|
src/idl_gen_ts.cpp
|
(PHP) add experimental support for PHP language.
* codegen for all basic features: WIP (probably implemented all basic feature)
* JSON parsing: NO
* Simple mutation: NO
* Reflection: NO
* Buffer verifier: NO (will be add later)
* Testing: basic: Yes
* Testing: fuzz: Yes
* Performance: Not bad
* Platform: Supported Linux, OS X, Windows (has 32bit integer limitation)
* Engine Unity: No
flatc --php monster_test.fbs
<?php
//include neccessary files.
$fbb = new Google\FlatBuffers\FlatBufferBuilder(1);
$str = $fbb->createString("monster");
\MyGame\Example\Monster::startMonster($fbb);
\MyGame\Example\Monster::addHp($fbb, 80);
\MyGame\Example\Monster::addName($fbb, $str);
$mon = \MyGame\Example\Monster::endMonster($fbb);
$fbb->finish($mon);
echo $fbb->sizedByteArray();
PHP 5.4 higher
Currently, we do not register this library to packagist as still experimental and versioning problem.
If you intended to use flatbuffers with composer. add repostiories section to composer.json like below.
"repositories": [{
"type": "vcs",
"url": "https://github.com/google/flatbuffers"
}],
and just put google/flatbuffers.
"require": {
"google/flatbuffers": "*"
}
* PHP's integer is platform dependant. we strongly recommend use 64bit machine
and don't use uint, ulong types as prevent overflow issue.
ref: http://php.net/manual/en/language.types.integer.php
* php don't support float type. floating point numbers are always parsed as double precision internally.
ref: http://php.net/manual/en/language.types.float.php
* ByteBuffer is little bit slow implemnentation due to many chr/ord function calls. Especially encoding objects.
This is expected performance as PHP5 has parsing arguments overhead. probably we'll add C-extension.
Basically, PHP implementation respects Java and C# implementation.
Note: ByteBuffer and FlatBuffersBuilder class are not intended to use other purposes.
we may change internal API foreseeable future.
PSR-2, PSR-4 standards.
Implemented simple assertion class (respect JavaScript testcase implementation) as we prefer small code base.
this also keeps CI iteration speed.
we'll choose phpunit or something when the test cases grown.
2015-11-05 07:19:28 +00:00
|
|
|
src/idl_gen_php.cpp
|
2014-12-16 08:32:11 +00:00
|
|
|
src/idl_gen_python.cpp
|
2018-07-24 02:03:11 +00:00
|
|
|
src/idl_gen_lobster.cpp
|
2018-09-03 00:05:50 +00:00
|
|
|
src/idl_gen_rust.cpp
|
2014-09-26 23:46:30 +00:00
|
|
|
src/idl_gen_fbs.cpp
|
2016-04-14 01:16:05 +00:00
|
|
|
src/idl_gen_grpc.cpp
|
2017-07-10 15:05:59 +00:00
|
|
|
src/idl_gen_json_schema.cpp
|
[Swift] Swift implementation 🎉🎉 (#5603)
* Implemented the swift version of Flatbuffers
Implemented serailzing, reading, and mutating data from object monster
Fixes mis-aligned pointer issue
Fixes issue when shared strings are removed from table
Adds swift enum, structs code gen
Fixed namespace issues + started implementing the table gen
Added Mutate function to the code generator
Generated linux test cases
Fixed an issue with bools, and structs readers in table writer
Swift docker image added
Updated the test cases, and removed a method parameters in swift
Fixed createVector api when called with scalars
Fixed issues with scalar arrays, and fixed the code gen namespaces, added sample_binary.swift
Cleaned up project
Added enum vectors, and their readers
Refactored code
Added swift into the support document
Added documentation in docs, and fixed a small issue with Data() not being returned correctly
Fixes Lowercase issue, and prevents generating lookups for deprecated keys
* Made all the required funcs to have const + removed unneeded code + fix lowercase func
* Removed transform from lowercased and moved it to function
* Fixes an issue with iOS allocation from read
* Refactored cpp code to be more readable
* casts position into int for position
* Fix enums issue, moves scalar writer code to use memcpy
* Removed c_str from struct function
* Fixed script to generate new objects when ran on travis ci: fix
* Handles deallocating space allocated for structs
* Updated the test cases to adhere to the fileprivate lookup, no mutation for unions, and updated the names of the vector functions
2020-01-09 20:12:10 +00:00
|
|
|
src/idl_gen_swift.cpp
|
2023-04-06 01:49:29 +00:00
|
|
|
src/file_name_saving_file_manager.cpp
|
|
|
|
src/file_binary_writer.cpp
|
|
|
|
src/file_writer.cpp
|
2022-03-16 04:48:42 +00:00
|
|
|
src/idl_namer.h
|
|
|
|
src/namer.h
|
2014-01-28 00:52:49 +00:00
|
|
|
src/flatc.cpp
|
2017-01-25 21:41:34 +00:00
|
|
|
src/flatc_main.cpp
|
2021-12-03 05:29:19 +00:00
|
|
|
src/bfbs_gen.h
|
|
|
|
src/bfbs_gen_lua.h
|
2022-10-21 18:30:04 +00:00
|
|
|
src/bfbs_gen_nim.h
|
2022-03-16 04:48:42 +00:00
|
|
|
src/bfbs_namer.h
|
2024-06-18 23:02:57 +00:00
|
|
|
include/codegen/idl_namer.h
|
|
|
|
include/codegen/namer.h
|
2024-05-29 19:47:29 +00:00
|
|
|
include/codegen/python.h
|
|
|
|
include/codegen/python.cc
|
2020-01-02 16:49:57 +00:00
|
|
|
include/flatbuffers/code_generators.h
|
2022-03-18 21:08:05 +00:00
|
|
|
src/binary_annotator.h
|
|
|
|
src/binary_annotator.cpp
|
|
|
|
src/annotated_binary_text_gen.h
|
|
|
|
src/annotated_binary_text_gen.cpp
|
2021-12-03 05:29:19 +00:00
|
|
|
src/bfbs_gen_lua.cpp
|
2022-10-21 18:30:04 +00:00
|
|
|
src/bfbs_gen_nim.cpp
|
2020-01-02 16:49:57 +00:00
|
|
|
src/code_generators.cpp
|
2016-08-19 05:11:11 +00:00
|
|
|
grpc/src/compiler/schema_interface.h
|
2016-04-14 01:16:05 +00:00
|
|
|
grpc/src/compiler/cpp_generator.h
|
|
|
|
grpc/src/compiler/cpp_generator.cc
|
2016-12-05 21:20:38 +00:00
|
|
|
grpc/src/compiler/go_generator.h
|
|
|
|
grpc/src/compiler/go_generator.cc
|
2017-12-21 17:55:57 +00:00
|
|
|
grpc/src/compiler/java_generator.h
|
|
|
|
grpc/src/compiler/java_generator.cc
|
2019-11-15 00:58:35 +00:00
|
|
|
grpc/src/compiler/python_generator.h
|
|
|
|
grpc/src/compiler/python_generator.cc
|
2020-02-24 17:27:41 +00:00
|
|
|
grpc/src/compiler/swift_generator.h
|
|
|
|
grpc/src/compiler/swift_generator.cc
|
2020-10-07 16:56:30 +00:00
|
|
|
grpc/src/compiler/ts_generator.h
|
|
|
|
grpc/src/compiler/ts_generator.cc
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
2015-02-13 23:58:29 +00:00
|
|
|
set(FlatHash_SRCS
|
|
|
|
include/flatbuffers/hash.h
|
|
|
|
src/flathash.cpp
|
|
|
|
)
|
|
|
|
|
2014-01-28 00:52:49 +00:00
|
|
|
set(FlatBuffers_Tests_SRCS
|
2015-07-31 20:55:53 +00:00
|
|
|
${FlatBuffers_Library_SRCS}
|
2014-09-26 23:46:30 +00:00
|
|
|
src/idl_gen_fbs.cpp
|
2022-08-28 23:54:58 +00:00
|
|
|
tests/evolution_test.cpp
|
|
|
|
tests/flexbuffers_test.cpp
|
|
|
|
tests/fuzz_test.cpp
|
|
|
|
tests/json_test.cpp
|
2022-11-18 19:04:46 +00:00
|
|
|
tests/key_field_test.cpp
|
2022-08-28 23:54:58 +00:00
|
|
|
tests/monster_test.cpp
|
|
|
|
tests/optional_scalars_test.cpp
|
|
|
|
tests/parser_test.cpp
|
|
|
|
tests/proto_test.cpp
|
|
|
|
tests/reflection_test.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
tests/test.cpp
|
2018-09-24 19:03:31 +00:00
|
|
|
tests/test_assert.h
|
|
|
|
tests/test_assert.cpp
|
|
|
|
tests/test_builder.h
|
|
|
|
tests/test_builder.cpp
|
2022-08-28 23:54:58 +00:00
|
|
|
tests/util_test.cpp
|
2019-08-01 21:31:48 +00:00
|
|
|
tests/native_type_test_impl.h
|
|
|
|
tests/native_type_test_impl.cpp
|
2022-09-21 18:05:05 +00:00
|
|
|
tests/alignment_test.h
|
|
|
|
tests/alignment_test.cpp
|
2023-05-09 16:16:30 +00:00
|
|
|
tests/64bit/offset64_test.h
|
|
|
|
tests/64bit/offset64_test.cpp
|
2020-01-02 16:49:57 +00:00
|
|
|
include/flatbuffers/code_generators.h
|
|
|
|
src/code_generators.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
2019-12-23 20:13:48 +00:00
|
|
|
set(FlatBuffers_Tests_CPP17_SRCS
|
|
|
|
${FlatBuffers_Library_SRCS}
|
|
|
|
tests/test_assert.h
|
|
|
|
tests/test_assert.cpp
|
|
|
|
tests/cpp17/test_cpp17.cpp
|
|
|
|
)
|
|
|
|
|
2014-01-28 00:52:49 +00:00
|
|
|
set(FlatBuffers_Sample_Binary_SRCS
|
|
|
|
samples/sample_binary.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
set(FlatBuffers_Sample_Text_SRCS
|
Add CodeWriter utility class.
Helps simplify code generation code. Instead of this:
code += "inline const " + cpp_qualified_name + " *Get";
code += name;
code += "(const void *buf) {\n return flatbuffers::GetRoot<";
code += cpp_qualified_name + ">(buf);\n}\n\n";
You do this:
code.SetValue("NAME", struct_def.name);
code.SetValue("CPP_NAME", cpp_qualified_name);
code += "inline const {{CPP_NAME}} *Get{{NAME}}(const void *buf) {";
code += " return flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
code += "}";
code += "";
Updated the CPP code generator to use the CodeWriter class. Most of the
changes in the generated code are white-space changes, esp. around new
lines (since the code generator class automatically appends new lines
when appending a string). Actual code changes include:
* Renamed "rehasher" to "_rehasher" for consistency with other args in
Pack function.
* Renamed "union_obj" to "obj: in UnPack function.
* Always do "(void)_o;" to prevent unused variable warning in Create
function (instead of only doing it if there are no fields) in order
to avoid two-passes.
* Renamed padding variables from __paddingX to paddingX__.
"Each name that contains a double underscore (_ _) [...] is reserved
to the implementation for any use." C++ standards 17.4.3.1.2.
* Add braces around switch cases.
* Calculate index as a separate statement in EnumName function, eg.
const size_t index = ...;
return EnumNamesX()[index];
vs.
return EnumNamesX()[...];
* Stored end table offset in variable in Finish() functions, eg.
const auto end = fbb_.EndTable(start_, ...);
auto o = flatbuffers::Offset<T>(end);
vs.
auto o = flatbuffers::Offset<T>(fbb_.EndTable(start, ...));
* Separate reinterpret_cast calls from function calls in Union
functions, eg.
auto ptr = reinterpret_cast<const T *>(obj);
return ptr->UnPack(resolver);
vs.
return reinterpret_cast<const T *>(obj)->UnPack(resolver);
* Removed unecessary (void)(padding__X) no-ops from constructors, eg.
Test(int16_t a, int8_t b) : ... {
(void)__padding0; // <-- Removed this line.
}
In the idl_gen_cpp.cpp file itself, I refactored some code generation into
new functions: GenParam, GenNativeTable, GenVerifyCall, GenBuilders,
GenUnpackFieldStatement, and GenCreateParam.
Change-Id: I727b1bd8719d05b7ce33cbce00eb58fda817b25d
2017-01-14 01:44:42 +00:00
|
|
|
${FlatBuffers_Library_SRCS}
|
2014-01-28 00:52:49 +00:00
|
|
|
samples/sample_text.cpp
|
|
|
|
)
|
|
|
|
|
2018-12-13 19:59:27 +00:00
|
|
|
set(FlatBuffers_Sample_BFBS_SRCS
|
|
|
|
${FlatBuffers_Library_SRCS}
|
|
|
|
samples/sample_bfbs.cpp
|
|
|
|
)
|
|
|
|
|
2016-04-14 01:16:05 +00:00
|
|
|
set(FlatBuffers_GRPCTest_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
include/flatbuffers/grpc.h
|
2019-05-09 17:10:10 +00:00
|
|
|
include/flatbuffers/util.h
|
|
|
|
src/util.cpp
|
2016-04-14 01:16:05 +00:00
|
|
|
tests/monster_test.grpc.fb.h
|
2018-09-24 19:03:31 +00:00
|
|
|
tests/test_assert.h
|
|
|
|
tests/test_builder.h
|
2016-04-14 01:16:05 +00:00
|
|
|
tests/monster_test.grpc.fb.cc
|
2018-09-24 19:03:31 +00:00
|
|
|
tests/test_assert.cpp
|
|
|
|
tests/test_builder.cpp
|
2016-04-14 01:16:05 +00:00
|
|
|
grpc/tests/grpctest.cpp
|
2018-08-30 23:43:22 +00:00
|
|
|
grpc/tests/message_builder_test.cpp
|
2016-04-14 01:16:05 +00:00
|
|
|
)
|
|
|
|
|
2022-04-06 20:25:43 +00:00
|
|
|
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
|
|
|
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
2021-02-10 19:49:34 +00:00
|
|
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
2023-01-30 07:00:57 +00:00
|
|
|
if(DEFINED FLATBUFFERS_CXX_FLAGS)
|
2021-02-10 19:49:34 +00:00
|
|
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
|
|
|
endif()
|
|
|
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
|
|
|
|
2018-10-29 18:29:05 +00:00
|
|
|
function(add_fsanitize_to_target _target _sanitizer)
|
2019-12-23 20:13:48 +00:00
|
|
|
if(WIN32)
|
|
|
|
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
|
|
|
message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
|
|
|
|
else()
|
|
|
|
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
|
|
|
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
2023-01-30 07:00:57 +00:00
|
|
|
if(IS_CLANG OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9))
|
2019-12-23 20:13:48 +00:00
|
|
|
set(_sanitizer_flags "=address,undefined")
|
|
|
|
if(_sanitizer MATCHES "=.*")
|
|
|
|
# override default by user-defined sanitizer list
|
|
|
|
set(_sanitizer_flags ${_sanitizer})
|
|
|
|
endif()
|
|
|
|
target_compile_options(${_target} PRIVATE
|
|
|
|
-g -fsigned-char -fno-omit-frame-pointer
|
|
|
|
"-fsanitize${_sanitizer_flags}")
|
|
|
|
target_link_libraries(${_target} PRIVATE
|
|
|
|
"-fsanitize${_sanitizer_flags}")
|
2023-01-30 07:00:57 +00:00
|
|
|
set_target_properties(${_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
2019-12-23 20:13:48 +00:00
|
|
|
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
2018-10-29 18:29:05 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-03-27 15:35:44 +00:00
|
|
|
function(add_pch_to_target _target _pch_header)
|
2023-01-30 07:00:57 +00:00
|
|
|
# the command is available since cmake 3.16
|
2020-03-27 15:35:44 +00:00
|
|
|
if(COMMAND target_precompile_headers)
|
|
|
|
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
|
|
|
if(NOT MSVC)
|
|
|
|
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2014-01-28 00:52:49 +00:00
|
|
|
include_directories(include)
|
2016-04-14 01:16:05 +00:00
|
|
|
include_directories(grpc)
|
2014-01-28 00:52:49 +00:00
|
|
|
|
2022-04-06 20:25:43 +00:00
|
|
|
# Creates an interface library that stores the configuration settings that each
|
|
|
|
# target links too. This is a compromise between setting configuration globally
|
2022-11-18 19:04:46 +00:00
|
|
|
# with add_compile_options() and the more targetted target_compile_options().
|
|
|
|
# This way each target in this file can share settings and override them if
|
2022-04-06 20:25:43 +00:00
|
|
|
# needed.
|
|
|
|
add_library(ProjectConfig INTERFACE)
|
|
|
|
target_compile_features(ProjectConfig
|
|
|
|
INTERFACE
|
2022-08-26 07:22:27 +00:00
|
|
|
cxx_std_${FLATBUFFERS_CPP_STD}
|
2022-04-06 20:25:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Force the standard to be met.
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
|
|
|
# We shouldn't rely on any compiler-extensions to make things work.
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2022-08-06 05:08:36 +00:00
|
|
|
if(MSVC_LIKE)
|
2022-04-06 20:25:43 +00:00
|
|
|
target_compile_options(ProjectConfig
|
2022-11-18 19:04:46 +00:00
|
|
|
INTERFACE
|
2022-04-06 20:25:43 +00:00
|
|
|
/W4
|
2022-08-07 04:06:14 +00:00
|
|
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
|
|
|
/WX # Treat all compiler warnings as errors
|
|
|
|
>
|
2022-04-06 20:25:43 +00:00
|
|
|
/wd4512 # C4512: assignment operator could not be generated
|
|
|
|
/wd4316 # C4316: object allocated on the heap may not be aligned
|
2022-04-18 17:20:06 +00:00
|
|
|
/wd4456 # C4456: hides previous local declaration
|
2022-08-06 05:08:36 +00:00
|
|
|
$<$<CXX_COMPILER_ID:Clang>:
|
2022-04-06 20:25:43 +00:00
|
|
|
/D_CRT_SECURE_NO_WARNINGS
|
|
|
|
>
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
target_compile_options(ProjectConfig
|
|
|
|
INTERFACE
|
|
|
|
-Wall
|
2022-08-07 04:06:14 +00:00
|
|
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
|
|
|
-Werror # Treat all compiler warnings as errors
|
2022-08-09 02:08:32 +00:00
|
|
|
|
2022-08-24 17:36:11 +00:00
|
|
|
-fno-rtti # Disable runtime type information
|
|
|
|
|
2022-08-24 06:23:24 +00:00
|
|
|
$<$<CXX_COMPILER_ID:GNU>:
|
|
|
|
# False positive string overflow
|
|
|
|
# https://github.com/google/flatbuffers/issues/7366
|
|
|
|
-Wno-error=stringop-overflow
|
|
|
|
>
|
2022-08-07 04:06:14 +00:00
|
|
|
>
|
2022-11-18 19:04:46 +00:00
|
|
|
-pedantic
|
|
|
|
-Wextra
|
2022-04-06 20:25:43 +00:00
|
|
|
-Wno-unused-parameter
|
|
|
|
-Wold-style-cast
|
|
|
|
-fsigned-char
|
2022-04-12 23:22:39 +00:00
|
|
|
-Wnon-virtual-dtor
|
2022-04-06 20:25:43 +00:00
|
|
|
|
2022-08-24 06:23:24 +00:00
|
|
|
# This isn't working for some reason: $<$<CXX_COMPILER_ID:CLANG>:
|
|
|
|
$<$<BOOL:${IS_CLANG}>:
|
2022-12-15 05:35:54 +00:00
|
|
|
-Wnewline-eof
|
2022-08-24 06:23:24 +00:00
|
|
|
-Wno-unknown-warning-option
|
2022-08-16 17:48:41 +00:00
|
|
|
-Wmissing-declarations
|
|
|
|
-Wzero-as-null-pointer-constant
|
2022-04-06 20:25:43 +00:00
|
|
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,3.8>:
|
|
|
|
-Wimplicit-fallthrough
|
|
|
|
-Wextra-semi
|
2022-11-18 19:04:46 +00:00
|
|
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
2022-08-07 04:06:14 +00:00
|
|
|
-Werror=unused-private-field
|
|
|
|
>
|
2022-04-06 20:25:43 +00:00
|
|
|
>
|
|
|
|
>
|
|
|
|
|
|
|
|
$<$<CXX_COMPILER_ID:GNU>:
|
|
|
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.4>:
|
2022-08-07 04:06:14 +00:00
|
|
|
-Wunused-result
|
2022-11-18 19:04:46 +00:00
|
|
|
-Wunused-parameter
|
2022-08-16 17:48:41 +00:00
|
|
|
-Werror=unused-parameter
|
|
|
|
-Wmissing-declarations
|
|
|
|
>
|
|
|
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.7>:
|
|
|
|
-Wzero-as-null-pointer-constant
|
2022-04-06 20:25:43 +00:00
|
|
|
>
|
|
|
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,7.0>:
|
2022-11-18 19:04:46 +00:00
|
|
|
-faligned-new
|
2022-08-07 04:06:14 +00:00
|
|
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
|
|
|
-Werror=implicit-fallthrough=2
|
|
|
|
>
|
2022-04-06 20:25:43 +00:00
|
|
|
>
|
2022-06-14 23:32:10 +00:00
|
|
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,8.0>:
|
|
|
|
-Wextra-semi
|
|
|
|
>
|
2022-04-06 20:25:43 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
$<$<BOOL:${FLATBUFFERS_CODE_COVERAGE}>:
|
|
|
|
-g
|
|
|
|
-fprofile-arcs
|
|
|
|
-ftest-coverage
|
|
|
|
>
|
|
|
|
)
|
|
|
|
|
|
|
|
if(FLATBUFFERS_CODE_COVERAGE)
|
|
|
|
target_link_options(ProjectConfig
|
|
|
|
INTERFACE
|
|
|
|
-fprofile-arcs
|
|
|
|
-ftest-coverage
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-07-22 12:18:59 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
2018-08-06 21:59:29 +00:00
|
|
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
2022-04-06 20:25:43 +00:00
|
|
|
|
2019-12-23 20:13:48 +00:00
|
|
|
# Attach header directory for when build via add_subdirectory().
|
2022-11-18 19:04:46 +00:00
|
|
|
target_include_directories(flatbuffers
|
2022-04-06 20:25:43 +00:00
|
|
|
INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
)
|
|
|
|
target_link_libraries(flatbuffers PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
|
|
|
|
2020-03-27 15:35:44 +00:00
|
|
|
if(FLATBUFFERS_ENABLE_PCH)
|
|
|
|
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
|
|
|
endif()
|
2015-07-22 12:18:59 +00:00
|
|
|
endif()
|
|
|
|
|
2015-01-02 12:51:31 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATC)
|
2015-02-13 23:58:29 +00:00
|
|
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
2020-03-27 15:35:44 +00:00
|
|
|
if(FLATBUFFERS_ENABLE_PCH)
|
|
|
|
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
|
|
|
endif()
|
2022-04-06 20:25:43 +00:00
|
|
|
|
|
|
|
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
2022-11-18 19:04:46 +00:00
|
|
|
target_compile_options(flatc
|
2023-01-30 07:00:57 +00:00
|
|
|
PRIVATE
|
2022-08-06 05:08:36 +00:00
|
|
|
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
2022-04-06 20:25:43 +00:00
|
|
|
/MT
|
|
|
|
>
|
|
|
|
)
|
|
|
|
|
2019-01-24 21:30:11 +00:00
|
|
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
2018-10-29 18:29:05 +00:00
|
|
|
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
|
|
|
endif()
|
2016-05-01 03:15:53 +00:00
|
|
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
|
|
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
|
|
|
endif()
|
2019-11-18 20:16:41 +00:00
|
|
|
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
|
|
|
target_link_libraries(flatc PRIVATE -static)
|
|
|
|
endif()
|
2015-02-13 23:58:29 +00:00
|
|
|
endif()
|
|
|
|
|
2015-04-28 22:44:10 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
2015-02-13 23:58:29 +00:00
|
|
|
add_executable(flathash ${FlatHash_SRCS})
|
2022-04-06 20:25:43 +00:00
|
|
|
target_link_libraries(flathash PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
2015-01-02 12:51:31 +00:00
|
|
|
endif()
|
2014-09-15 16:50:23 +00:00
|
|
|
|
2016-09-06 17:12:04 +00:00
|
|
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
|
|
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
2022-04-06 20:25:43 +00:00
|
|
|
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
2023-01-10 17:31:49 +00:00
|
|
|
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
|
|
|
# stability guarantees. Therefore, always use the full version as SOVERSION
|
|
|
|
# in order to avoid breaking reverse dependencies on upgrades.
|
|
|
|
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
2023-01-30 07:00:57 +00:00
|
|
|
set_target_properties(flatbuffers_shared PROPERTIES
|
|
|
|
OUTPUT_NAME flatbuffers
|
2023-01-10 17:31:49 +00:00
|
|
|
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
2017-11-09 22:39:32 +00:00
|
|
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
2020-03-27 15:35:44 +00:00
|
|
|
if(FLATBUFFERS_ENABLE_PCH)
|
|
|
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
|
|
|
endif()
|
2016-09-06 17:12:04 +00:00
|
|
|
endif()
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
2014-10-24 21:26:29 +00:00
|
|
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
2014-09-23 18:55:42 +00:00
|
|
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
2023-05-12 23:26:21 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_HEADER}
|
|
|
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
2023-05-05 19:08:09 +00:00
|
|
|
${OPT}
|
|
|
|
-o "${SRC_FBS_DIR}"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
2023-05-26 18:49:06 +00:00
|
|
|
DEPENDS flatc ${SRC_FBS}
|
2023-05-05 19:08:09 +00:00
|
|
|
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
|
|
|
|
)
|
|
|
|
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
|
2019-06-17 22:15:13 +00:00
|
|
|
endfunction()
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
function(compile_schema_for_test SRC_FBS OPT)
|
|
|
|
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
|
|
|
target_sources(flattests PRIVATE ${GEN_FILE})
|
2015-05-21 23:33:29 +00:00
|
|
|
endfunction()
|
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
function(compile_schema_for_samples SRC_FBS OPT)
|
|
|
|
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
2023-05-13 04:23:51 +00:00
|
|
|
target_sources(flatsample PRIVATE ${GEN_FILE})
|
2020-01-24 22:55:34 +00:00
|
|
|
endfunction()
|
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
if(FLATBUFFERS_BUILD_TESTS)
|
|
|
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
2022-04-06 20:25:43 +00:00
|
|
|
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
2023-05-12 23:44:28 +00:00
|
|
|
target_include_directories(flattests PUBLIC
|
|
|
|
# Ideally everything is fully qualified from the root directories
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
# TODO(derekbailey): update includes to fully qualify src/ and tests/
|
|
|
|
src
|
|
|
|
tests
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests
|
|
|
|
)
|
2023-05-10 03:33:54 +00:00
|
|
|
|
|
|
|
# Have tests load data from the source directory, not the build directory.
|
|
|
|
add_definitions(-DFLATBUFFERS_TEST_PATH_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/)
|
2023-05-05 19:08:09 +00:00
|
|
|
|
|
|
|
# The flattest target needs some generated files
|
|
|
|
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
|
|
|
|
SET(FLATC_OPT_COMP ${FLATC_OPT};--gen-compare)
|
2023-05-31 18:52:05 +00:00
|
|
|
SET(FLATC_OPT_SCOPED_ENUMS ${FLATC_OPT_COMP};--scoped-enums)
|
2023-05-05 19:08:09 +00:00
|
|
|
|
|
|
|
compile_schema_for_test(tests/alignment_test.fbs "${FLATC_OPT_COMP}")
|
2023-05-31 18:52:05 +00:00
|
|
|
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
2023-05-05 19:08:09 +00:00
|
|
|
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
|
|
|
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
|
2023-05-08 20:54:24 +00:00
|
|
|
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
2023-05-09 16:16:30 +00:00
|
|
|
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
|
|
|
|
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
|
|
|
|
compile_schema_for_test(tests/64bit/evolution/v2.fbs "${FLATC_OPT_COMP}")
|
2023-05-31 18:52:05 +00:00
|
|
|
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
2022-06-15 03:53:28 +00:00
|
|
|
|
2019-01-24 21:30:11 +00:00
|
|
|
if(FLATBUFFERS_CODE_SANITIZE)
|
2020-01-06 23:26:41 +00:00
|
|
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
2019-01-24 21:30:11 +00:00
|
|
|
endif()
|
2023-05-05 19:08:09 +00:00
|
|
|
|
2014-09-15 16:50:23 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
2022-04-06 20:25:43 +00:00
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
|
|
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
2018-12-13 19:59:27 +00:00
|
|
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
2023-05-05 19:08:09 +00:00
|
|
|
|
2023-05-13 00:11:18 +00:00
|
|
|
# Add a library so there is a single target that the generated samples can
|
|
|
|
# link too.
|
2023-11-23 00:32:02 +00:00
|
|
|
if(MSVC OR ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20.0")
|
2023-11-18 08:19:03 +00:00
|
|
|
add_library(flatsample INTERFACE)
|
|
|
|
else()
|
|
|
|
add_library(flatsample STATIC)
|
|
|
|
endif()
|
2023-05-13 00:11:18 +00:00
|
|
|
|
2023-05-13 04:23:51 +00:00
|
|
|
# Since flatsample has no sources, we have to explicitly set the linker lang.
|
|
|
|
set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX)
|
2023-05-13 00:11:18 +00:00
|
|
|
|
2023-05-05 19:08:09 +00:00
|
|
|
compile_schema_for_samples(samples/monster.fbs "${FLATC_OPT_COMP}")
|
2019-12-23 20:13:48 +00:00
|
|
|
|
2023-05-13 04:23:51 +00:00
|
|
|
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
|
|
|
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
|
|
|
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
2023-05-13 00:11:18 +00:00
|
|
|
|
2019-12-23 20:13:48 +00:00
|
|
|
if(FLATBUFFERS_BUILD_CPP17)
|
|
|
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
2022-04-06 20:25:43 +00:00
|
|
|
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
2023-05-10 03:33:54 +00:00
|
|
|
target_include_directories(flattests_cpp17 PUBLIC src tests)
|
2023-01-30 07:00:57 +00:00
|
|
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
|
2022-06-15 03:53:28 +00:00
|
|
|
|
2019-12-23 20:13:48 +00:00
|
|
|
if(FLATBUFFERS_CODE_SANITIZE)
|
|
|
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
|
|
|
endif()
|
|
|
|
endif(FLATBUFFERS_BUILD_CPP17)
|
2014-09-10 23:01:13 +00:00
|
|
|
endif()
|
2014-01-28 00:52:49 +00:00
|
|
|
|
2016-04-14 01:16:05 +00:00
|
|
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
2018-08-30 23:43:22 +00:00
|
|
|
if(NOT GRPC_INSTALL_PATH)
|
|
|
|
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
|
|
|
endif()
|
|
|
|
if(NOT PROTOBUF_DOWNLOAD_PATH)
|
|
|
|
message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
|
|
|
|
endif()
|
|
|
|
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
|
|
|
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
2021-03-25 19:12:35 +00:00
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
2021-07-29 17:41:51 +00:00
|
|
|
find_package(absl CONFIG REQUIRED)
|
2021-03-25 19:12:35 +00:00
|
|
|
find_package(protobuf CONFIG REQUIRED)
|
|
|
|
find_package(gRPC CONFIG REQUIRED)
|
2016-04-14 01:16:05 +00:00
|
|
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
2023-11-20 18:35:56 +00:00
|
|
|
target_link_libraries(grpctest
|
2022-11-18 19:04:46 +00:00
|
|
|
PRIVATE
|
2022-04-06 20:25:43 +00:00
|
|
|
$<BUILD_INTERFACE:ProjectConfig>
|
2022-11-18 19:04:46 +00:00
|
|
|
gRPC::grpc++_unsecure
|
|
|
|
gRPC::gpr
|
2022-04-06 20:25:43 +00:00
|
|
|
pthread
|
2022-11-18 19:04:46 +00:00
|
|
|
dl
|
2022-04-06 20:25:43 +00:00
|
|
|
)
|
2016-04-14 01:16:05 +00:00
|
|
|
endif()
|
|
|
|
|
2014-09-15 16:50:23 +00:00
|
|
|
if(FLATBUFFERS_INSTALL)
|
2017-11-06 18:38:53 +00:00
|
|
|
include(GNUInstallDirs)
|
2017-11-16 20:51:25 +00:00
|
|
|
|
2017-11-06 18:38:53 +00:00
|
|
|
install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2017-11-16 20:51:25 +00:00
|
|
|
|
|
|
|
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
|
|
|
|
2022-09-01 17:28:59 +00:00
|
|
|
configure_file(CMake/flatbuffers-config-version.cmake.in flatbuffers-config-version.cmake @ONLY)
|
2017-11-16 20:51:25 +00:00
|
|
|
install(
|
2022-11-18 19:04:46 +00:00
|
|
|
FILES
|
|
|
|
"CMake/flatbuffers-config.cmake"
|
2022-09-10 07:30:47 +00:00
|
|
|
"CMake/BuildFlatBuffers.cmake"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-config-version.cmake"
|
2017-11-16 20:51:25 +00:00
|
|
|
DESTINATION ${FB_CMAKE_DIR}
|
|
|
|
)
|
|
|
|
|
2015-07-22 12:18:59 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
2022-01-30 20:56:16 +00:00
|
|
|
install(
|
2022-08-06 05:19:17 +00:00
|
|
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
2022-01-30 20:56:16 +00:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
2017-11-16 20:51:25 +00:00
|
|
|
|
2022-08-06 05:19:17 +00:00
|
|
|
install(EXPORT FlatBuffersTargets
|
|
|
|
FILE FlatBuffersTargets.cmake
|
2017-11-16 20:51:25 +00:00
|
|
|
NAMESPACE flatbuffers::
|
|
|
|
DESTINATION ${FB_CMAKE_DIR}
|
|
|
|
)
|
2015-07-22 12:18:59 +00:00
|
|
|
endif()
|
2017-11-16 20:51:25 +00:00
|
|
|
|
2015-01-02 12:51:31 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATC)
|
2017-11-16 20:51:25 +00:00
|
|
|
install(
|
|
|
|
TARGETS flatc EXPORT FlatcTargets
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT FlatcTargets
|
|
|
|
FILE FlatcTargets.cmake
|
|
|
|
NAMESPACE flatbuffers::
|
|
|
|
DESTINATION ${FB_CMAKE_DIR}
|
|
|
|
)
|
2015-01-02 12:51:31 +00:00
|
|
|
endif()
|
2017-11-16 20:51:25 +00:00
|
|
|
|
2016-09-06 17:12:04 +00:00
|
|
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
2022-01-30 20:56:16 +00:00
|
|
|
install(
|
2022-08-06 05:19:17 +00:00
|
|
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
2022-01-30 20:56:16 +00:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
2017-11-16 20:51:25 +00:00
|
|
|
|
2022-01-30 20:56:16 +00:00
|
|
|
install(
|
2022-08-06 05:19:17 +00:00
|
|
|
EXPORT FlatBuffersSharedTargets
|
|
|
|
FILE FlatBuffersSharedTargets.cmake
|
2017-11-16 20:51:25 +00:00
|
|
|
NAMESPACE flatbuffers::
|
|
|
|
DESTINATION ${FB_CMAKE_DIR}
|
|
|
|
)
|
2016-09-06 17:12:04 +00:00
|
|
|
endif()
|
2021-02-22 18:23:38 +00:00
|
|
|
|
|
|
|
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
|
|
|
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
|
|
|
install(
|
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
|
|
|
)
|
|
|
|
endif()
|
2014-09-15 16:50:23 +00:00
|
|
|
endif()
|
2014-07-15 13:09:36 +00:00
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
if(FLATBUFFERS_BUILD_TESTS)
|
2014-09-15 16:50:23 +00:00
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
add_test(NAME flattests COMMAND flattests)
|
2020-01-02 18:12:14 +00:00
|
|
|
if(FLATBUFFERS_BUILD_CPP17)
|
|
|
|
add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
|
|
|
|
endif()
|
2018-08-30 23:43:22 +00:00
|
|
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
|
|
|
add_test(NAME grpctest COMMAND grpctest)
|
|
|
|
endif()
|
2014-09-10 23:01:13 +00:00
|
|
|
endif()
|
2015-11-17 21:39:37 +00:00
|
|
|
|
|
|
|
include(CMake/BuildFlatBuffers.cmake)
|
2015-05-13 12:15:59 +00:00
|
|
|
|
2019-02-21 19:06:04 +00:00
|
|
|
if(UNIX)
|
|
|
|
# Use of CPack only supported on Linux systems.
|
|
|
|
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
|
|
|
include(CMake/PackageDebian.cmake)
|
2020-03-17 20:38:29 +00:00
|
|
|
include(CPack)
|
2019-02-21 19:06:04 +00:00
|
|
|
endif()
|
|
|
|
if (FLATBUFFERS_PACKAGE_REDHAT)
|
|
|
|
include(CMake/PackageRedhat.cmake)
|
2020-03-17 20:38:29 +00:00
|
|
|
include(CPack)
|
2019-02-21 19:06:04 +00:00
|
|
|
endif()
|
2015-05-13 12:15:59 +00:00
|
|
|
endif()
|
2021-11-15 21:41:22 +00:00
|
|
|
|
|
|
|
# Include for running Google Benchmarks.
|
2022-01-30 20:56:16 +00:00
|
|
|
if(FLATBUFFERS_BUILD_BENCHMARKS)
|
2021-11-15 21:41:22 +00:00
|
|
|
add_subdirectory(benchmarks)
|
2021-12-10 19:28:24 +00:00
|
|
|
endif()
|
2022-01-26 04:51:00 +00:00
|
|
|
|
|
|
|
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
|
|
|
add_library(FlatBuffers INTERFACE)
|
|
|
|
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
|
|
|
target_include_directories(
|
|
|
|
FlatBuffers
|
|
|
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
2022-08-06 05:19:17 +00:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|