2019-12-23 20:13:48 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2018-10-29 18:29:05 +00:00
|
|
|
# generate compile_commands.json
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2018-11-16 17:24:06 +00:00
|
|
|
include(CheckCXXSymbolExists)
|
2014-01-28 00:52:49 +00:00
|
|
|
|
|
|
|
project(FlatBuffers)
|
|
|
|
|
|
|
|
# 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)
|
2015-02-13 23:58:29 +00:00
|
|
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
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)
|
2019-02-25 19:42:37 +00:00
|
|
|
|
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)
|
2019-05-09 17:15:29 +00:00
|
|
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
2018-11-16 17:24:06 +00:00
|
|
|
if(MSVC)
|
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}>)
|
|
|
|
|
2015-07-22 12:18:59 +00:00
|
|
|
set(FlatBuffers_Library_SRCS
|
2017-06-16 03:54:04 +00:00
|
|
|
include/flatbuffers/base.h
|
2014-01-28 00:52:49 +00:00
|
|
|
include/flatbuffers/flatbuffers.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
|
|
|
|
include/flatbuffers/util.h
|
2015-05-21 23:33:29 +00:00
|
|
|
include/flatbuffers/reflection.h
|
|
|
|
include/flatbuffers/reflection_generated.h
|
2017-07-13 13:27:39 +00:00
|
|
|
include/flatbuffers/stl_emulation.h
|
2016-02-02 02:00:30 +00:00
|
|
|
include/flatbuffers/flexbuffers.h
|
2017-06-16 03:54:04 +00:00
|
|
|
include/flatbuffers/registry.h
|
2017-08-25 00:44:03 +00:00
|
|
|
include/flatbuffers/minireflect.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}
|
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
|
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
|
2018-12-06 19:12:06 +00:00
|
|
|
src/idl_gen_js_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-07-05 22:55:57 +00:00
|
|
|
src/idl_gen_lua.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
|
2014-01-28 00:52:49 +00:00
|
|
|
src/flatc.cpp
|
2017-01-25 21:41:34 +00:00
|
|
|
src/flatc_main.cpp
|
2020-01-02 16:49:57 +00:00
|
|
|
include/flatbuffers/code_generators.h
|
|
|
|
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_private_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
|
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
|
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
|
2019-08-01 21:31:48 +00:00
|
|
|
tests/native_type_test_impl.h
|
|
|
|
tests/native_type_test_impl.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
|
|
|
# file generate by running compiler on tests/monster_test.fbs
|
2014-09-15 16:50:23 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
2019-12-23 20:13:48 +00:00
|
|
|
# file generate by running compiler on namespace_test/namespace_test1.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
|
|
|
|
# file generate by running compiler on union_vector/union_vector.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
|
2019-06-17 22:15:13 +00:00
|
|
|
# file generate by running compiler on tests/arrays_test.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
|
2019-08-01 21:31:48 +00:00
|
|
|
# file generate by running compiler on tests/native_type_test.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
|
2019-10-21 17:11:32 +00:00
|
|
|
# file generate by running compiler on tests/monster_extra.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
2020-01-24 22:55:34 +00:00
|
|
|
# file generate by running compiler on tests/monster_test.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
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
|
|
|
|
# file generate by running compiler on tests/monster_test.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
|
|
|
)
|
|
|
|
|
2014-01-28 00:52:49 +00:00
|
|
|
set(FlatBuffers_Sample_Binary_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
samples/sample_binary.cpp
|
2014-09-15 16:50:23 +00:00
|
|
|
# file generated by running compiler on samples/monster.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2014-09-15 16:50:23 +00:00
|
|
|
# file generated by running compiler on samples/monster.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
2018-12-13 19:59:27 +00:00
|
|
|
set(FlatBuffers_Sample_BFBS_SRCS
|
|
|
|
${FlatBuffers_Library_SRCS}
|
|
|
|
samples/sample_bfbs.cpp
|
|
|
|
# file generated by running compiler on samples/monster.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
|
|
|
)
|
|
|
|
|
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
|
2019-12-23 20:13:48 +00:00
|
|
|
# file generate by running compiler on tests/monster_test.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
2016-04-14 01:16:05 +00:00
|
|
|
)
|
|
|
|
|
2014-01-28 00:52:49 +00:00
|
|
|
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
|
|
|
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
|
|
|
|
2016-10-05 20:20:30 +00:00
|
|
|
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
2016-10-17 20:06:11 +00:00
|
|
|
# do not apply any global settings if the toolchain
|
2016-10-05 20:20:30 +00:00
|
|
|
# is being configured externally
|
2019-01-28 18:16:12 +00:00
|
|
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
2016-10-05 20:20:30 +00:00
|
|
|
elseif(APPLE)
|
2016-07-23 02:04:23 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
2017-05-12 16:48:17 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
2018-10-15 22:11:31 +00:00
|
|
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
2015-05-27 23:57:21 +00:00
|
|
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
2016-04-02 04:42:23 +00:00
|
|
|
if(CYGWIN)
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
|
|
|
else(CYGWIN)
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
|
|
endif(CYGWIN)
|
2014-08-25 17:42:38 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
2016-04-02 04:42:23 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
2018-10-15 22:11:31 +00:00
|
|
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
2018-02-12 16:37:51 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
|
|
|
set(CMAKE_CXX_FLAGS
|
2018-12-27 00:02:14 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
2018-02-12 16:37:51 +00:00
|
|
|
endif()
|
2016-02-11 00:03:53 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
2018-04-05 16:17:33 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
2016-02-11 00:03:53 +00:00
|
|
|
endif()
|
2016-02-29 17:28:40 +00:00
|
|
|
|
|
|
|
# Certain platforms such as ARM do not use signed chars by default
|
|
|
|
# which causes issues with certain bounds checks.
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
|
|
|
2016-09-08 17:47:50 +00:00
|
|
|
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
2015-05-27 23:57:21 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
2017-10-20 23:29:51 +00:00
|
|
|
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
2018-10-15 22:11:31 +00:00
|
|
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
2019-01-28 18:16:12 +00:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
2019-03-07 23:14:40 +00:00
|
|
|
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
2019-01-28 18:16:12 +00:00
|
|
|
endif()
|
2018-07-19 16:40:28 +00:00
|
|
|
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
|
|
|
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
endif()
|
|
|
|
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
|
|
|
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
|
|
|
endif()
|
2016-03-03 01:15:42 +00:00
|
|
|
endif()
|
2016-02-29 17:28:40 +00:00
|
|
|
|
|
|
|
# Certain platforms such as ARM do not use signed chars by default
|
|
|
|
# which causes issues with certain bounds checks.
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
|
|
|
2017-02-16 01:44:55 +00:00
|
|
|
elseif(MSVC)
|
2017-03-10 18:27:30 +00:00
|
|
|
# Visual Studio pedantic build settings
|
2017-03-29 19:01:11 +00:00
|
|
|
# warning C4512: assignment operator could not be generated
|
2017-04-24 17:29:25 +00:00
|
|
|
# warning C4316: object allocated on the heap may not be aligned
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
2014-01-28 00:52:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FLATBUFFERS_CODE_COVERAGE)
|
2014-07-26 11:12:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
2014-07-29 17:29:38 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
2014-01-28 00:52:49 +00:00
|
|
|
endif()
|
|
|
|
|
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".
|
|
|
|
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
|
|
|
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
|
|
|
)
|
|
|
|
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}")
|
|
|
|
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
2018-10-29 18:29:05 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2015-01-31 16:14:59 +00:00
|
|
|
if(BIICODE)
|
2015-04-01 10:35:37 +00:00
|
|
|
include(biicode/cmake/biicode.cmake)
|
2015-01-31 16:14:59 +00:00
|
|
|
return()
|
2015-04-01 10:35:37 +00:00
|
|
|
endif()
|
2015-01-31 16:14:59 +00:00
|
|
|
|
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
|
|
|
|
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})
|
2019-12-23 20:13:48 +00:00
|
|
|
# Attach header directory for when build via add_subdirectory().
|
2018-08-06 21:59:29 +00:00
|
|
|
target_include_directories(flatbuffers INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
2018-10-15 22:11:31 +00:00
|
|
|
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
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})
|
2018-10-15 22:11:31 +00:00
|
|
|
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
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()
|
2017-05-10 22:42:23 +00:00
|
|
|
if(MSVC)
|
|
|
|
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
|
|
|
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
|
|
|
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})
|
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})
|
2017-11-09 22:39:32 +00:00
|
|
|
|
|
|
|
# Shared object version: "major.minor.micro"
|
|
|
|
# - micro updated every release when there is no API/ABI changes
|
|
|
|
# - minor updated when there are additions in API/ABI
|
|
|
|
# - major (ABI number) updated when there are changes in ABI (or removals)
|
|
|
|
set(FlatBuffers_Library_SONAME_MAJOR "1")
|
2020-03-12 21:41:06 +00:00
|
|
|
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.12.0")
|
2017-11-09 22:39:32 +00:00
|
|
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
|
|
|
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
|
|
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
2016-09-06 17:12:04 +00:00
|
|
|
endif()
|
|
|
|
|
2020-01-06 23:26:41 +00:00
|
|
|
# Global list of generated files.
|
|
|
|
# Use the global property to be independent of PARENT_SCOPE.
|
|
|
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
|
|
|
|
|
|
function(get_generated_output generated_files)
|
|
|
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
|
|
set(${generated_files} ${tmp} PARENT_SCOPE)
|
|
|
|
endfunction(get_generated_output)
|
|
|
|
|
|
|
|
function(register_generated_output file_name)
|
|
|
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
|
|
list(APPEND tmp ${file_name})
|
|
|
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
|
|
|
endfunction(register_generated_output)
|
|
|
|
|
2019-06-17 22:15:13 +00:00
|
|
|
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
2019-12-23 20:13:48 +00:00
|
|
|
if(FLATBUFFERS_BUILD_LEGACY)
|
|
|
|
set(OPT ${OPT};--cpp-std c++0x)
|
|
|
|
else()
|
|
|
|
# --cpp-std is defined by flatc default settings.
|
|
|
|
endif()
|
2020-01-06 23:26:41 +00:00
|
|
|
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
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})
|
2014-09-15 16:50:23 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_HEADER}
|
2020-01-06 23:26:41 +00:00
|
|
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
|
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
2017-07-13 13:27:39 +00:00
|
|
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
2020-01-06 23:26:41 +00:00
|
|
|
${OPT}
|
2017-05-24 22:21:26 +00:00
|
|
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
2020-01-06 23:26:41 +00:00
|
|
|
-o "${SRC_FBS_DIR}"
|
2016-07-02 01:08:51 +00:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
2020-01-06 23:26:41 +00:00
|
|
|
DEPENDS flatc
|
|
|
|
COMMENT "Run generation: '${GEN_HEADER}'")
|
|
|
|
register_generated_output(${GEN_HEADER})
|
2014-09-15 16:50:23 +00:00
|
|
|
endfunction()
|
|
|
|
|
2019-06-17 22:15:13 +00:00
|
|
|
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
2019-12-23 20:13:48 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
2019-06-17 22:15:13 +00:00
|
|
|
endfunction()
|
|
|
|
|
2015-05-21 23:33:29 +00:00
|
|
|
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
2020-01-06 23:26:41 +00:00
|
|
|
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
2015-05-21 23:33:29 +00:00
|
|
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
|
|
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
2020-01-06 23:26:41 +00:00
|
|
|
# For details about flags see generate_code.bat(sh)
|
2015-05-21 23:33:29 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
2020-01-06 23:26:41 +00:00
|
|
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
|
|
-b --schema --bfbs-comments --bfbs-builtins
|
|
|
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
|
|
|
-o "${SRC_FBS_DIR}"
|
2016-07-02 01:08:51 +00:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
2020-01-06 23:26:41 +00:00
|
|
|
DEPENDS flatc
|
|
|
|
COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
|
|
|
|
register_generated_output(${GEN_BINARY_SCHEMA})
|
2015-05-21 23:33:29 +00:00
|
|
|
endfunction()
|
|
|
|
|
2020-01-24 22:55:34 +00:00
|
|
|
function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|
|
|
if(FLATBUFFERS_BUILD_LEGACY)
|
|
|
|
set(OPT ${OPT};--cpp-std c++0x)
|
|
|
|
else()
|
|
|
|
# --cpp-std is defined by flatc default settings.
|
|
|
|
endif()
|
|
|
|
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
|
|
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
|
|
|
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
|
|
|
# For details about flags see generate_code.bat(sh)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_BFBS_HEADER}
|
|
|
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
|
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
|
|
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
|
|
|
${OPT}
|
|
|
|
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
|
|
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
|
|
|
-o "${SRC_FBS_DIR}"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
|
|
|
DEPENDS flatc
|
|
|
|
COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
|
|
|
|
register_generated_output(${GEN_BFBS_HEADER})
|
|
|
|
endfunction()
|
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
if(FLATBUFFERS_BUILD_TESTS)
|
2020-01-06 23:26:41 +00:00
|
|
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
|
|
|
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
2014-09-15 16:50:23 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
2020-01-06 23:26:41 +00:00
|
|
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
2019-12-23 20:13:48 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test1.fbs)
|
|
|
|
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test2.fbs)
|
|
|
|
compile_flatbuffers_schema_to_cpp(tests/union_vector/union_vector.fbs)
|
2019-08-01 21:31:48 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
2019-08-26 21:33:38 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
2020-01-06 23:26:41 +00:00
|
|
|
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
2020-01-24 22:55:34 +00:00
|
|
|
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
2019-12-23 20:13:48 +00:00
|
|
|
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
2019-10-21 17:11:32 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
|
|
|
endif()
|
2014-09-15 16:50:23 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(flattests generated_code)
|
2016-12-16 16:46:30 +00:00
|
|
|
set_property(TARGET flattests
|
|
|
|
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
|
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
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()
|
2014-09-15 16:50:23 +00:00
|
|
|
|
|
|
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
2020-01-06 23:26:41 +00:00
|
|
|
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
2014-09-15 16:50:23 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(flatsamplebinary generated_code)
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(flatsampletext generated_code)
|
2018-12-13 19:59:27 +00:00
|
|
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(flatsamplebfbs generated_code)
|
2019-12-23 20:13:48 +00:00
|
|
|
|
|
|
|
if(FLATBUFFERS_BUILD_CPP17)
|
|
|
|
# Don't generate header for flattests_cpp17 target.
|
|
|
|
# This target uses "generated_cpp17/monster_test_generated.h"
|
|
|
|
# produced by direct call of generate_code.bat(sh) script.
|
|
|
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(flattests_cpp17 generated_code)
|
2019-12-23 20:13:48 +00:00
|
|
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
|
|
|
target_compile_definitions(flattests_cpp17 PRIVATE
|
|
|
|
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
|
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
|
|
|
)
|
|
|
|
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)
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
2017-06-07 20:56:49 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
2016-04-14 01:16:05 +00:00
|
|
|
endif()
|
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)
|
|
|
|
LINK_DIRECTORIES(${GRPC_INSTALL_PATH}/lib)
|
2016-04-14 01:16:05 +00:00
|
|
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
2020-01-06 23:26:41 +00:00
|
|
|
add_dependencies(grpctest generated_code)
|
2019-12-23 20:13:48 +00:00
|
|
|
target_link_libraries(grpctest PRIVATE grpc++_unsecure grpc_unsecure gpr pthread dl)
|
2020-01-06 23:26:41 +00:00
|
|
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
2019-12-23 20:13:48 +00:00
|
|
|
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
|
|
|
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
|
|
|
endif()
|
2016-04-14 01:16:05 +00:00
|
|
|
endif()
|
|
|
|
|
2018-02-15 21:39:15 +00:00
|
|
|
include(CMake/Version.cmake)
|
|
|
|
|
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")
|
|
|
|
|
2018-02-15 21:39:15 +00:00
|
|
|
configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY)
|
2017-11-16 20:51:25 +00:00
|
|
|
install(
|
2018-02-15 21:39:15 +00:00
|
|
|
FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.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)
|
2017-11-30 16:45:58 +00:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
|
|
|
install(
|
|
|
|
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
install(
|
|
|
|
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-16 20:51:25 +00:00
|
|
|
|
|
|
|
install(EXPORT FlatbuffersTargets
|
|
|
|
FILE FlatbuffersTargets.cmake
|
|
|
|
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)
|
2017-11-30 16:45:58 +00:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
|
|
|
install(
|
|
|
|
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
install(
|
|
|
|
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-16 20:51:25 +00:00
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT FlatbuffersSharedTargets
|
|
|
|
FILE FlatbuffersSharedTargets.cmake
|
|
|
|
NAMESPACE flatbuffers::
|
|
|
|
DESTINATION ${FB_CMAKE_DIR}
|
|
|
|
)
|
2016-09-06 17:12:04 +00:00
|
|
|
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
|
|
|
|
2020-01-06 23:26:41 +00:00
|
|
|
# This target is sync-barrier.
|
|
|
|
# Other generate-dependent targets can depend on 'generated_code' only.
|
|
|
|
get_generated_output(fbs_generated)
|
|
|
|
if(fbs_generated)
|
|
|
|
# message(STATUS "Add generated_code target with files:${fbs_generated}")
|
|
|
|
add_custom_target(generated_code
|
|
|
|
DEPENDS ${fbs_generated}
|
|
|
|
COMMENT "All generated files were updated.")
|
|
|
|
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()
|