Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 2 | # generate compile_commands.json |
| 3 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Vladimir Glavnyy | 5f32f94 | 2018-11-17 00:24:06 +0700 | [diff] [blame] | 4 | include(CheckCXXSymbolExists) |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 5 | |
| 6 | project(FlatBuffers) |
| 7 | |
| 8 | # NOTE: Code coverage only works on Linux & OSX. |
| 9 | option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 10 | option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 11 | option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON) |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 12 | option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library" |
| 13 | ON) |
| 14 | option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" |
| 15 | ON) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 16 | option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag" |
| 17 | OFF) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 18 | option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 19 | option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF) |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 20 | option(FLATBUFFERS_BUILD_SHAREDLIB |
| 21 | "Enable the build of the flatbuffers shared library" |
| 22 | OFF) |
Kamil Rojewski | 6bfa107 | 2018-07-19 18:40:28 +0200 | [diff] [blame] | 23 | option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON) |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 24 | # NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm). |
Kamil Rojewski | 30c4948 | 2018-12-06 20:12:06 +0100 | [diff] [blame] | 25 | option(FLATBUFFERS_CODE_SANITIZE |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 26 | "Add '-fsanitize' flags to 'flattests' and 'flatc' targets." |
| 27 | OFF) |
Marc Butler | 4567b13 | 2019-02-22 06:06:04 +1100 | [diff] [blame] | 28 | option(FLATBUFFERS_PACKAGE_REDHAT |
| 29 | "Build an rpm using the 'package' target." |
| 30 | OFF) |
| 31 | option(FLATBUFFERS_PACKAGE_DEBIAN |
| 32 | "Build an deb using the 'package' target." |
| 33 | OFF) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 34 | option(FLATBUFFERS_BUILD_CPP17 |
| 35 | "Enable the build of c++17 test target. \" |
| 36 | Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher." |
| 37 | OFF) |
| 38 | option(FLATBUFFERS_BUILD_LEGACY |
| 39 | "Run C++ code generator with '--cpp-std c++0x' switch." |
| 40 | OFF) |
Wouter van Oortmerssen | 9bf9b18 | 2019-02-25 11:42:37 -0800 | [diff] [blame] | 41 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 42 | if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS) |
| 43 | message(WARNING |
| 44 | "Cannot build tests without building the compiler. Tests will be disabled.") |
| 45 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 46 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 47 | |
Vladimir Glavnyy | 925c1d7 | 2018-10-04 23:27:37 +0700 | [diff] [blame] | 48 | if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH) |
| 49 | # Override the default recursion depth limit. |
| 50 | add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH}) |
| 51 | message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}") |
| 52 | endif() |
| 53 | |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 54 | # Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions. |
Vladimir Glavnyy | 5f32f94 | 2018-11-17 00:24:06 +0700 | [diff] [blame] | 55 | if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 56 | set(FLATBUFFERS_LOCALE_INDEPENDENT 0) |
Vladimir Glavnyy | 5f32f94 | 2018-11-17 00:24:06 +0700 | [diff] [blame] | 57 | if(MSVC) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 58 | check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 59 | check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
Vladimir Glavnyy | 5f32f94 | 2018-11-17 00:24:06 +0700 | [diff] [blame] | 60 | else() |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 61 | check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 62 | check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
| 63 | endif() |
| 64 | if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L) |
| 65 | set(FLATBUFFERS_LOCALE_INDEPENDENT 1) |
Vladimir Glavnyy | 5f32f94 | 2018-11-17 00:24:06 +0700 | [diff] [blame] | 66 | endif() |
| 67 | endif() |
| 68 | add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>) |
| 69 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 70 | set(FlatBuffers_Library_SRCS |
Wouter van Oortmerssen | 88a85ff | 2017-06-15 20:54:04 -0700 | [diff] [blame] | 71 | include/flatbuffers/base.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 72 | include/flatbuffers/flatbuffers.h |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 73 | include/flatbuffers/hash.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 74 | include/flatbuffers/idl.h |
| 75 | include/flatbuffers/util.h |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 76 | include/flatbuffers/reflection.h |
| 77 | include/flatbuffers/reflection_generated.h |
Stewart Miles | a892322 | 2017-07-13 06:27:39 -0700 | [diff] [blame] | 78 | include/flatbuffers/stl_emulation.h |
Wouter van Oortmerssen | aac6be1 | 2016-02-01 18:00:30 -0800 | [diff] [blame] | 79 | include/flatbuffers/flexbuffers.h |
Wouter van Oortmerssen | 88a85ff | 2017-06-15 20:54:04 -0700 | [diff] [blame] | 80 | include/flatbuffers/registry.h |
Wouter van Oortmerssen | 72a99ab | 2017-08-24 17:44:03 -0700 | [diff] [blame] | 81 | include/flatbuffers/minireflect.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 82 | src/idl_parser.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 83 | src/idl_gen_text.cpp |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 84 | src/reflection.cpp |
Wouter van Oortmerssen | e98b191 | 2016-03-30 17:34:52 -0700 | [diff] [blame] | 85 | src/util.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 86 | ) |
| 87 | |
| 88 | set(FlatBuffers_Compiler_SRCS |
| 89 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 90 | src/idl_gen_cpp.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 91 | src/idl_gen_csharp.cpp |
Dan Field | 8891264 | 2018-05-18 14:06:15 -0400 | [diff] [blame] | 92 | src/idl_gen_dart.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 93 | src/idl_gen_kotlin.cpp |
rw | 74d5f37 | 2014-07-11 16:12:35 -0700 | [diff] [blame] | 94 | src/idl_gen_go.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 95 | src/idl_gen_java.cpp |
Kamil Rojewski | 30c4948 | 2018-12-06 20:12:06 +0100 | [diff] [blame] | 96 | src/idl_gen_js_ts.cpp |
Shuhei Taunma | 5ce8682 | 2015-11-05 16:19:28 +0900 | [diff] [blame] | 97 | src/idl_gen_php.cpp |
rw | 48dfc69 | 2014-12-16 00:32:11 -0800 | [diff] [blame] | 98 | src/idl_gen_python.cpp |
aardappel | 4898809 | 2018-07-23 19:03:11 -0700 | [diff] [blame] | 99 | src/idl_gen_lobster.cpp |
Derek Bailey | ba5eb3b | 2018-07-05 15:55:57 -0700 | [diff] [blame] | 100 | src/idl_gen_lua.cpp |
Robert | 3c54fd9 | 2018-09-02 17:05:50 -0700 | [diff] [blame] | 101 | src/idl_gen_rust.cpp |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 102 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 103 | src/idl_gen_grpc.cpp |
schoetbi | f202041 | 2017-07-10 17:05:59 +0200 | [diff] [blame] | 104 | src/idl_gen_json_schema.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 105 | src/idl_gen_swift.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 106 | src/flatc.cpp |
Wouter van Oortmerssen | b395359 | 2017-01-25 13:41:34 -0800 | [diff] [blame] | 107 | src/flatc_main.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 108 | include/flatbuffers/code_generators.h |
| 109 | src/code_generators.cpp |
Harsh Vardhan | 2e7806e | 2016-08-19 10:41:11 +0530 | [diff] [blame] | 110 | grpc/src/compiler/schema_interface.h |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 111 | grpc/src/compiler/cpp_generator.h |
| 112 | grpc/src/compiler/cpp_generator.cc |
Ronak Jain | a31ddd2 | 2016-12-06 02:50:38 +0530 | [diff] [blame] | 113 | grpc/src/compiler/go_generator.h |
| 114 | grpc/src/compiler/go_generator.cc |
Yuri Finkelstein | 8518b3f | 2017-12-21 07:55:57 -1000 | [diff] [blame] | 115 | grpc/src/compiler/java_generator.h |
| 116 | grpc/src/compiler/java_generator.cc |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 117 | grpc/src/compiler/python_generator.h |
| 118 | grpc/src/compiler/python_private_generator.h |
| 119 | grpc/src/compiler/python_generator.cc |
| 120 | grpc/src/compiler/swift_generator.h |
| 121 | grpc/src/compiler/swift_generator.cc |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 122 | ) |
| 123 | |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 124 | set(FlatHash_SRCS |
| 125 | include/flatbuffers/hash.h |
| 126 | src/flathash.cpp |
| 127 | ) |
| 128 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 129 | set(FlatBuffers_Tests_SRCS |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 130 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 131 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 132 | tests/test.cpp |
Sumant Tambe | 49fed8c | 2018-09-24 12:03:31 -0700 | [diff] [blame] | 133 | tests/test_assert.h |
| 134 | tests/test_assert.cpp |
| 135 | tests/test_builder.h |
| 136 | tests/test_builder.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 137 | tests/native_type_test_impl.h |
| 138 | tests/native_type_test_impl.cpp |
| 139 | include/flatbuffers/code_generators.h |
| 140 | src/code_generators.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 141 | # file generate by running compiler on tests/monster_test.fbs |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 142 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 143 | # file generate by running compiler on namespace_test/namespace_test1.fbs |
| 144 | ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h |
| 145 | ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h |
| 146 | # file generate by running compiler on union_vector/union_vector.fbs |
| 147 | ${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h |
| 148 | # file generate by running compiler on tests/arrays_test.fbs |
| 149 | ${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h |
| 150 | # file generate by running compiler on tests/native_type_test.fbs |
| 151 | ${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h |
| 152 | # file generate by running compiler on tests/monster_extra.fbs |
| 153 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h |
| 154 | # file generate by running compiler on tests/monster_test.fbs |
| 155 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h |
| 156 | ) |
| 157 | |
| 158 | set(FlatBuffers_Tests_CPP17_SRCS |
| 159 | ${FlatBuffers_Library_SRCS} |
| 160 | tests/test_assert.h |
| 161 | tests/test_assert.cpp |
| 162 | tests/cpp17/test_cpp17.cpp |
| 163 | # file generate by running compiler on tests/monster_test.fbs |
| 164 | ${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h |
| 165 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Vladimir Glavnyy | 44bf719 | 2019-12-24 03:13:48 +0700 | [diff] [blame] | 166 | ) |
| 167 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 168 | set(FlatBuffers_Sample_Binary_SRCS |
| 169 | include/flatbuffers/flatbuffers.h |
| 170 | samples/sample_binary.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 171 | # file generated by running compiler on samples/monster.fbs |
| 172 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 173 | ) |
| 174 | |
| 175 | set(FlatBuffers_Sample_Text_SRCS |
Wouter van Oortmerssen | 7b94eab | 2017-01-13 17:44:42 -0800 | [diff] [blame] | 176 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 177 | samples/sample_text.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 178 | # file generated by running compiler on samples/monster.fbs |
| 179 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 180 | ) |
| 181 | |
tira-misu | dba962e | 2018-12-13 20:59:27 +0100 | [diff] [blame] | 182 | set(FlatBuffers_Sample_BFBS_SRCS |
| 183 | ${FlatBuffers_Library_SRCS} |
tira-misu | dba962e | 2018-12-13 20:59:27 +0100 | [diff] [blame] | 184 | samples/sample_bfbs.cpp |
| 185 | # file generated by running compiler on samples/monster.fbs |
| 186 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 187 | ) |
| 188 | |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 189 | set(FlatBuffers_GRPCTest_SRCS |
| 190 | include/flatbuffers/flatbuffers.h |
| 191 | include/flatbuffers/grpc.h |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 192 | include/flatbuffers/util.h |
| 193 | src/util.cpp |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 194 | tests/monster_test.grpc.fb.h |
Sumant Tambe | 49fed8c | 2018-09-24 12:03:31 -0700 | [diff] [blame] | 195 | tests/test_assert.h |
| 196 | tests/test_builder.h |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 197 | tests/monster_test.grpc.fb.cc |
Sumant Tambe | 49fed8c | 2018-09-24 12:03:31 -0700 | [diff] [blame] | 198 | tests/test_assert.cpp |
| 199 | tests/test_builder.cpp |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 200 | grpc/tests/grpctest.cpp |
Sumant Tambe | e757854 | 2018-08-30 16:43:22 -0700 | [diff] [blame] | 201 | grpc/tests/message_builder_test.cpp |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 202 | # file generate by running compiler on tests/monster_test.fbs |
| 203 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 204 | ) |
| 205 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 206 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 207 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 208 | |
Andrew Hundt | 520d684 | 2016-10-05 16:20:30 -0400 | [diff] [blame] | 209 | if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") |
Wouter van Oortmerssen | 606098c | 2016-10-17 13:06:11 -0700 | [diff] [blame] | 210 | # do not apply any global settings if the toolchain |
Andrew Hundt | 520d684 | 2016-10-05 16:20:30 -0400 | [diff] [blame] | 211 | # is being configured externally |
Vladimir Glavnyy | 7d3930a | 2019-01-29 01:16:12 +0700 | [diff] [blame] | 212 | message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") |
Andrew Hundt | 520d684 | 2016-10-05 16:20:30 -0400 | [diff] [blame] | 213 | elseif(APPLE) |
Jason Sanmiya | 30c07f4 | 2016-07-22 19:04:23 -0700 | [diff] [blame] | 214 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
Per Grön | 9aeeddf | 2017-05-12 18:48:17 +0200 | [diff] [blame] | 215 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
Frank Benkstein | 20396a1 | 2018-10-16 00:11:31 +0200 | [diff] [blame] | 216 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 217 | elseif(CMAKE_COMPILER_IS_GNUCXX) |
Tony Kelman | 4c16038 | 2016-04-01 21:42:23 -0700 | [diff] [blame] | 218 | if(CYGWIN) |
| 219 | set(CMAKE_CXX_FLAGS |
| 220 | "${CMAKE_CXX_FLAGS} -std=gnu++11") |
| 221 | else(CYGWIN) |
| 222 | set(CMAKE_CXX_FLAGS |
| 223 | "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 224 | endif(CYGWIN) |
Wouter van Oortmerssen | bc5fa9d | 2014-08-25 10:42:38 -0700 | [diff] [blame] | 225 | set(CMAKE_CXX_FLAGS |
Tony Kelman | 4c16038 | 2016-04-01 21:42:23 -0700 | [diff] [blame] | 226 | "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow") |
Frank Benkstein | 20396a1 | 2018-10-16 00:11:31 +0200 | [diff] [blame] | 227 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
Kamil Rojewski | 474ba68 | 2018-02-12 17:37:51 +0100 | [diff] [blame] | 228 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4) |
| 229 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
| 230 | set(CMAKE_CXX_FLAGS |
Wouter van Oortmerssen | a821b15 | 2018-12-26 16:02:14 -0800 | [diff] [blame] | 231 | "${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2") |
Kamil Rojewski | 474ba68 | 2018-02-12 17:37:51 +0100 | [diff] [blame] | 232 | endif() |
maurice barnum | 697cad7 | 2016-02-11 00:03:53 +0000 | [diff] [blame] | 233 | set(CMAKE_CXX_FLAGS |
Juyeon Yoon | 0998861 | 2018-04-06 01:17:33 +0900 | [diff] [blame] | 234 | "${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter") |
maurice barnum | 697cad7 | 2016-02-11 00:03:53 +0000 | [diff] [blame] | 235 | endif() |
Will Gardner | ce4d331 | 2016-02-29 17:28:40 +0000 | [diff] [blame] | 236 | |
| 237 | # Certain platforms such as ARM do not use signed chars by default |
| 238 | # which causes issues with certain bounds checks. |
| 239 | set(CMAKE_CXX_FLAGS |
| 240 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 241 | |
Jason Sanmiya | 985de21 | 2016-09-08 10:47:50 -0700 | [diff] [blame] | 242 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 243 | set(CMAKE_CXX_FLAGS |
Alex Ames | f2627e1 | 2017-10-20 16:29:51 -0700 | [diff] [blame] | 244 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
Frank Benkstein | 20396a1 | 2018-10-16 00:11:31 +0200 | [diff] [blame] | 245 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
Vladimir Glavnyy | 7d3930a | 2019-01-29 01:16:12 +0700 | [diff] [blame] | 246 | if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8) |
Wouter van Oortmerssen | e237f53 | 2019-03-07 15:14:40 -0800 | [diff] [blame] | 247 | list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning |
Vladimir Glavnyy | 7d3930a | 2019-01-29 01:16:12 +0700 | [diff] [blame] | 248 | endif() |
Kamil Rojewski | 6bfa107 | 2018-07-19 18:40:28 +0200 | [diff] [blame] | 249 | if(FLATBUFFERS_LIBCXX_WITH_CLANG) |
| 250 | if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") |
| 251 | set(CMAKE_CXX_FLAGS |
| 252 | "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 253 | endif() |
| 254 | if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR |
| 255 | "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")) |
| 256 | set(CMAKE_EXE_LINKER_FLAGS |
| 257 | "${CMAKE_EXE_LINKER_FLAGS} -lc++abi") |
| 258 | endif() |
Yuri | 26f15bc | 2016-03-02 17:15:42 -0800 | [diff] [blame] | 259 | endif() |
Will Gardner | ce4d331 | 2016-02-29 17:28:40 +0000 | [diff] [blame] | 260 | |
| 261 | # Certain platforms such as ARM do not use signed chars by default |
| 262 | # which causes issues with certain bounds checks. |
| 263 | set(CMAKE_CXX_FLAGS |
| 264 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 265 | |
Wouter van Oortmerssen | 6561c7a | 2017-02-15 17:44:55 -0800 | [diff] [blame] | 266 | elseif(MSVC) |
chronoxor | f538738 | 2017-03-10 21:27:30 +0300 | [diff] [blame] | 267 | # Visual Studio pedantic build settings |
Wouter van Oortmerssen | 238a8eb | 2017-03-29 12:01:11 -0700 | [diff] [blame] | 268 | # warning C4512: assignment operator could not be generated |
Wouter van Oortmerssen | e93a565 | 2017-04-24 10:29:25 -0700 | [diff] [blame] | 269 | # warning C4316: object allocated on the heap may not be aligned |
| 270 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 271 | endif() |
| 272 | |
| 273 | if(FLATBUFFERS_CODE_COVERAGE) |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 274 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 8f80fec | 2014-07-29 10:29:38 -0700 | [diff] [blame] | 275 | set(CMAKE_EXE_LINKER_FLAGS |
| 276 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 277 | endif() |
| 278 | |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 279 | function(add_fsanitize_to_target _target _sanitizer) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 280 | if(WIN32) |
| 281 | target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING) |
| 282 | message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}") |
| 283 | else() |
| 284 | # FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer. |
| 285 | # List of sanitizer is string starts with '=': "=address,undefined,thread,memory". |
| 286 | if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR |
| 287 | ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")) |
| 288 | ) |
| 289 | set(_sanitizer_flags "=address,undefined") |
| 290 | if(_sanitizer MATCHES "=.*") |
| 291 | # override default by user-defined sanitizer list |
| 292 | set(_sanitizer_flags ${_sanitizer}) |
| 293 | endif() |
| 294 | target_compile_options(${_target} PRIVATE |
| 295 | -g -fsigned-char -fno-omit-frame-pointer |
| 296 | "-fsanitize${_sanitizer_flags}") |
| 297 | target_link_libraries(${_target} PRIVATE |
| 298 | "-fsanitize${_sanitizer_flags}") |
| 299 | set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON) |
| 300 | message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}") |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 301 | endif() |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 302 | endif() |
| 303 | endfunction() |
| 304 | |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 305 | if(BIICODE) |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 306 | include(biicode/cmake/biicode.cmake) |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 307 | return() |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 308 | endif() |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 309 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 310 | include_directories(include) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 311 | include_directories(grpc) |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 312 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 313 | if(FLATBUFFERS_BUILD_FLATLIB) |
Vladimir Glavnyy | 27e4f43 | 2018-08-07 04:59:29 +0700 | [diff] [blame] | 314 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 315 | # Attach header directory for when build via add_subdirectory(). |
Vladimir Glavnyy | 27e4f43 | 2018-08-07 04:59:29 +0700 | [diff] [blame] | 316 | target_include_directories(flatbuffers INTERFACE |
| 317 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) |
Frank Benkstein | 20396a1 | 2018-10-16 00:11:31 +0200 | [diff] [blame] | 318 | target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 319 | endif() |
| 320 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 321 | if(FLATBUFFERS_BUILD_FLATC) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 322 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
Frank Benkstein | 20396a1 | 2018-10-16 00:11:31 +0200 | [diff] [blame] | 323 | target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
Vladimir Glavnyy | 3f388ec | 2019-01-25 04:30:11 +0700 | [diff] [blame] | 324 | if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32) |
Vladimir Glavnyy | 0fb1d44 | 2018-10-30 01:29:05 +0700 | [diff] [blame] | 325 | add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE}) |
| 326 | endif() |
Xiaolei Yu | 3a8bc30 | 2016-05-01 11:15:53 +0800 | [diff] [blame] | 327 | if(NOT FLATBUFFERS_FLATC_EXECUTABLE) |
| 328 | set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>) |
| 329 | endif() |
Wouter van Oortmerssen | cb2481e | 2017-05-10 15:42:23 -0700 | [diff] [blame] | 330 | if(MSVC) |
| 331 | # Make flatc.exe not depend on runtime dlls for easy distribution. |
| 332 | target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>) |
| 333 | endif() |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 334 | if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC) |
| 335 | target_link_libraries(flatc PRIVATE -static) |
| 336 | endif() |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 337 | endif() |
| 338 | |
Jason Sanmiya | f47660f | 2015-04-28 15:44:10 -0700 | [diff] [blame] | 339 | if(FLATBUFFERS_BUILD_FLATHASH) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 340 | add_executable(flathash ${FlatHash_SRCS}) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 341 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 342 | |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 343 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 344 | add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS}) |
Sergey Avseyev | ca52bfe | 2017-11-10 01:39:32 +0300 | [diff] [blame] | 345 | |
| 346 | # Shared object version: "major.minor.micro" |
| 347 | # - micro updated every release when there is no API/ABI changes |
| 348 | # - minor updated when there are additions in API/ABI |
| 349 | # - major (ABI number) updated when there are changes in ABI (or removals) |
| 350 | set(FlatBuffers_Library_SONAME_MAJOR "1") |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 351 | set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.12.0") |
Sergey Avseyev | ca52bfe | 2017-11-10 01:39:32 +0300 | [diff] [blame] | 352 | set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers |
| 353 | SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}" |
| 354 | VERSION "${FlatBuffers_Library_SONAME_FULL}") |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 355 | endif() |
| 356 | |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 357 | # Global list of generated files. |
| 358 | # Use the global property to be independent of PARENT_SCOPE. |
| 359 | set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 360 | |
| 361 | function(get_generated_output generated_files) |
| 362 | get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 363 | set(${generated_files} ${tmp} PARENT_SCOPE) |
| 364 | endfunction(get_generated_output) |
| 365 | |
| 366 | function(register_generated_output file_name) |
| 367 | get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 368 | list(APPEND tmp ${file_name}) |
| 369 | set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp}) |
| 370 | endfunction(register_generated_output) |
| 371 | |
| 372 | function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT) |
| 373 | if(FLATBUFFERS_BUILD_LEGACY) |
| 374 | set(OPT ${OPT};--cpp-std c++0x) |
| 375 | else() |
| 376 | # --cpp-std is defined by flatc default settings. |
| 377 | endif() |
| 378 | message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'") |
Wouter van Oortmerssen | 4cdf3eb | 2014-10-24 14:26:29 -0700 | [diff] [blame] | 379 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
Wouter van Oortmerssen | 7b80535 | 2014-09-23 11:55:42 -0700 | [diff] [blame] | 380 | string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS}) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 381 | add_custom_command( |
| 382 | OUTPUT ${GEN_HEADER} |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 383 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 384 | --cpp --gen-mutable --gen-object-api --reflect-names |
Stewart Miles | a892322 | 2017-07-13 06:27:39 -0700 | [diff] [blame] | 385 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 386 | ${OPT} |
Wouter van Oortmerssen | 22743ca | 2017-05-24 15:21:26 -0700 | [diff] [blame] | 387 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 388 | -o "${SRC_FBS_DIR}" |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 389 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 390 | DEPENDS flatc |
| 391 | COMMENT "Run generation: '${GEN_HEADER}'") |
| 392 | register_generated_output(${GEN_HEADER}) |
| 393 | endfunction() |
| 394 | |
| 395 | function(compile_flatbuffers_schema_to_cpp SRC_FBS) |
| 396 | compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare") |
svenk177 | e635141 | 2019-06-18 00:15:13 +0200 | [diff] [blame] | 397 | endfunction() |
| 398 | |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 399 | function(compile_flatbuffers_schema_to_binary SRC_FBS) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 400 | message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema") |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 401 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 402 | string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 403 | # For details about flags see generate_code.bat(sh) |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 404 | add_custom_command( |
| 405 | OUTPUT ${GEN_BINARY_SCHEMA} |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 406 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 407 | -b --schema --bfbs-comments --bfbs-builtins |
| 408 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
| 409 | -o "${SRC_FBS_DIR}" |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 410 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 411 | DEPENDS flatc |
| 412 | COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'") |
| 413 | register_generated_output(${GEN_BINARY_SCHEMA}) |
| 414 | endfunction() |
| 415 | |
| 416 | function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT) |
| 417 | if(FLATBUFFERS_BUILD_LEGACY) |
| 418 | set(OPT ${OPT};--cpp-std c++0x) |
| 419 | else() |
| 420 | # --cpp-std is defined by flatc default settings. |
| 421 | endif() |
| 422 | message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'") |
| 423 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 424 | string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS}) |
| 425 | # For details about flags see generate_code.bat(sh) |
| 426 | add_custom_command( |
| 427 | OUTPUT ${GEN_BFBS_HEADER} |
| 428 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 429 | --cpp --gen-mutable --gen-object-api --reflect-names |
| 430 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
| 431 | ${OPT} |
| 432 | --bfbs-comments --bfbs-builtins --bfbs-gen-embed |
| 433 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
| 434 | -o "${SRC_FBS_DIR}" |
| 435 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
| 436 | DEPENDS flatc |
| 437 | COMMENT "Run generation: '${GEN_BFBS_HEADER}'") |
| 438 | register_generated_output(${GEN_BFBS_HEADER}) |
sjoblom65 | 47026ea | 2020-01-24 17:55:34 -0500 | [diff] [blame] | 439 | endfunction() |
| 440 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 441 | if(FLATBUFFERS_BUILD_TESTS) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 442 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") |
| 443 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") |
| 444 | |
| 445 | # TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 446 | compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 447 | compile_flatbuffers_schema_to_binary(tests/monster_test.fbs) |
| 448 | compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test1.fbs) |
| 449 | compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test2.fbs) |
| 450 | compile_flatbuffers_schema_to_cpp(tests/union_vector/union_vector.fbs) |
| 451 | compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "") |
| 452 | compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare") |
| 453 | compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs) |
| 454 | compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare") |
| 455 | if(NOT (MSVC AND (MSVC_VERSION LESS 1900))) |
| 456 | compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF. |
| 457 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 458 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 459 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 460 | add_dependencies(flattests generated_code) |
Zarian Waheed | 6d6271d | 2016-12-16 08:46:30 -0800 | [diff] [blame] | 461 | set_property(TARGET flattests |
| 462 | PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 463 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1) |
Vladimir Glavnyy | 3f388ec | 2019-01-25 04:30:11 +0700 | [diff] [blame] | 464 | if(FLATBUFFERS_CODE_SANITIZE) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 465 | add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE}) |
Vladimir Glavnyy | 3f388ec | 2019-01-25 04:30:11 +0700 | [diff] [blame] | 466 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 467 | |
| 468 | compile_flatbuffers_schema_to_cpp(samples/monster.fbs) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 469 | compile_flatbuffers_schema_to_binary(samples/monster.fbs) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 470 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 471 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 472 | add_dependencies(flatsamplebinary generated_code) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 473 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 474 | add_dependencies(flatsampletext generated_code) |
tira-misu | dba962e | 2018-12-13 20:59:27 +0100 | [diff] [blame] | 475 | add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 476 | add_dependencies(flatsamplebfbs generated_code) |
| 477 | |
| 478 | if(FLATBUFFERS_BUILD_CPP17) |
| 479 | # Don't generate header for flattests_cpp17 target. |
| 480 | # This target uses "generated_cpp17/monster_test_generated.h" |
| 481 | # produced by direct call of generate_code.bat(sh) script. |
| 482 | add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS}) |
| 483 | add_dependencies(flattests_cpp17 generated_code) |
| 484 | target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) |
| 485 | target_compile_definitions(flattests_cpp17 PRIVATE |
| 486 | FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 487 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1 |
| 488 | ) |
| 489 | if(FLATBUFFERS_CODE_SANITIZE) |
| 490 | add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE}) |
| 491 | endif() |
| 492 | endif(FLATBUFFERS_BUILD_CPP17) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 493 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 494 | |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 495 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 496 | if(CMAKE_COMPILER_IS_GNUCXX) |
Lawrence Chan | da67c0a | 2017-06-07 15:56:49 -0500 | [diff] [blame] | 497 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow") |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 498 | endif() |
Sumant Tambe | e757854 | 2018-08-30 16:43:22 -0700 | [diff] [blame] | 499 | if(NOT GRPC_INSTALL_PATH) |
| 500 | message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md") |
| 501 | endif() |
| 502 | if(NOT PROTOBUF_DOWNLOAD_PATH) |
| 503 | message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md") |
| 504 | endif() |
| 505 | INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include) |
| 506 | INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src) |
| 507 | LINK_DIRECTORIES(${GRPC_INSTALL_PATH}/lib) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 508 | add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS}) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 509 | add_dependencies(grpctest generated_code) |
| 510 | target_link_libraries(grpctest PRIVATE grpc++_unsecure grpc_unsecure gpr pthread dl) |
| 511 | if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32) |
| 512 | # GRPC test has problems with alignment and will fail under ASAN/UBSAN. |
| 513 | # add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE}) |
| 514 | endif() |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 515 | endif() |
| 516 | |
Dmitry Volosnykh | daf0a42 | 2018-02-16 00:39:15 +0300 | [diff] [blame] | 517 | include(CMake/Version.cmake) |
| 518 | |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 519 | if(FLATBUFFERS_INSTALL) |
Sergey Avseyev | 2edb1dc | 2017-11-06 21:38:53 +0300 | [diff] [blame] | 520 | include(GNUInstallDirs) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 521 | |
Sergey Avseyev | 2edb1dc | 2017-11-06 21:38:53 +0300 | [diff] [blame] | 522 | install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 523 | |
| 524 | set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers") |
| 525 | |
Dmitry Volosnykh | daf0a42 | 2018-02-16 00:39:15 +0300 | [diff] [blame] | 526 | configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 527 | install( |
Dmitry Volosnykh | daf0a42 | 2018-02-16 00:39:15 +0300 | [diff] [blame] | 528 | FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake" |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 529 | DESTINATION ${FB_CMAKE_DIR} |
| 530 | ) |
| 531 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 532 | if(FLATBUFFERS_BUILD_FLATLIB) |
Bastien Brunnenstein | ba08b0e | 2017-11-30 17:45:58 +0100 | [diff] [blame] | 533 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 534 | install( |
| 535 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 536 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 537 | ) |
| 538 | else() |
| 539 | install( |
| 540 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 541 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 542 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 543 | ) |
| 544 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 545 | |
| 546 | install(EXPORT FlatbuffersTargets |
| 547 | FILE FlatbuffersTargets.cmake |
| 548 | NAMESPACE flatbuffers:: |
| 549 | DESTINATION ${FB_CMAKE_DIR} |
| 550 | ) |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 551 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 552 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 553 | if(FLATBUFFERS_BUILD_FLATC) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 554 | install( |
| 555 | TARGETS flatc EXPORT FlatcTargets |
| 556 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 557 | ) |
| 558 | |
| 559 | install( |
| 560 | EXPORT FlatcTargets |
| 561 | FILE FlatcTargets.cmake |
| 562 | NAMESPACE flatbuffers:: |
| 563 | DESTINATION ${FB_CMAKE_DIR} |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 564 | ) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 565 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 566 | |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 567 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
Bastien Brunnenstein | ba08b0e | 2017-11-30 17:45:58 +0100 | [diff] [blame] | 568 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 569 | install( |
| 570 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 571 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 572 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 573 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 574 | ) |
| 575 | else() |
| 576 | install( |
| 577 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 578 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 579 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 580 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 581 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 582 | ) |
| 583 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 584 | |
| 585 | install( |
| 586 | EXPORT FlatbuffersSharedTargets |
| 587 | FILE FlatbuffersSharedTargets.cmake |
| 588 | NAMESPACE flatbuffers:: |
| 589 | DESTINATION ${FB_CMAKE_DIR} |
| 590 | ) |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 591 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 592 | endif() |
Daniel Nachbaur | 7a99b3c | 2014-07-15 15:09:36 +0200 | [diff] [blame] | 593 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 594 | if(FLATBUFFERS_BUILD_TESTS) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 595 | enable_testing() |
| 596 | |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 597 | add_test(NAME flattests COMMAND flattests) |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 598 | if(FLATBUFFERS_BUILD_CPP17) |
| 599 | add_test(NAME flattests_cpp17 COMMAND flattests_cpp17) |
| 600 | endif() |
Sumant Tambe | e757854 | 2018-08-30 16:43:22 -0700 | [diff] [blame] | 601 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 602 | add_test(NAME grpctest COMMAND grpctest) |
| 603 | endif() |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 604 | endif() |
Johan Euphrosine | 331d2d8 | 2015-11-17 13:39:37 -0800 | [diff] [blame] | 605 | |
Haibo Huang | b9f6b1a | 2020-03-16 15:41:29 -0700 | [diff] [blame] | 606 | # This target is sync-barrier. |
| 607 | # Other generate-dependent targets can depend on 'generated_code' only. |
| 608 | get_generated_output(fbs_generated) |
| 609 | if(fbs_generated) |
| 610 | # message(STATUS "Add generated_code target with files:${fbs_generated}") |
| 611 | add_custom_target(generated_code |
| 612 | DEPENDS ${fbs_generated} |
| 613 | COMMENT "All generated files were updated.") |
| 614 | endif() |
| 615 | |
Johan Euphrosine | 331d2d8 | 2015-11-17 13:39:37 -0800 | [diff] [blame] | 616 | include(CMake/BuildFlatBuffers.cmake) |
Vitaly Isaev | 928effd | 2015-05-13 15:15:59 +0300 | [diff] [blame] | 617 | |
Marc Butler | 4567b13 | 2019-02-22 06:06:04 +1100 | [diff] [blame] | 618 | if(UNIX) |
| 619 | # Use of CPack only supported on Linux systems. |
| 620 | if(FLATBUFFERS_PACKAGE_DEBIAN) |
| 621 | include(CMake/PackageDebian.cmake) |
| 622 | endif() |
| 623 | if (FLATBUFFERS_PACKAGE_REDHAT) |
| 624 | include(CMake/PackageRedhat.cmake) |
| 625 | endif() |
| 626 | include(CPack) |
Vitaly Isaev | 928effd | 2015-05-13 15:15:59 +0300 | [diff] [blame] | 627 | endif() |