blob: 9bf07fe17dc6c9712569d7fc434716cd5204db88 [file] [log] [blame]
James Kuszmaul8e62b022022-03-22 09:33:25 -07001# This is the legacy minimum version flatbuffers supported for a while.
2cmake_minimum_required(VERSION 2.8.12...3.22.1)
3
4# CMake version 3.16 is the 'de-facto' minimum version for flatbuffers. If the
5# current cmake is older than this, warn the user and include the legacy file to
6# provide some level of support.
7if(CMAKE_VERSION VERSION_LESS 3.16)
8 message(WARNING "Using cmake version ${CMAKE_VERSION} which is older than "
9 "our target version of 3.16. This will use the legacy CMakeLists.txt that "
10 "supports version 2.8.12 and higher, but not actively maintained. Consider "
11 "upgrading cmake to a newer version, as this may become a fatal error in the "
12 "future.")
13 # Use the legacy version of CMakeLists.txt
14 include(CMake/CMakeLists_legacy.cmake.in)
15 return()
16endif()
17
18# Attempt to read the current version of flatbuffers by looking at the latest tag.
19include(CMake/Version.cmake)
20
21if (POLICY CMP0048)
22 cmake_policy(SET CMP0048 NEW)
23 project(FlatBuffers
24 DESCRIPTION "Flatbuffers serialization library"
25 VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
26 LANGUAGES CXX)
27else()
28 project(FlatBuffers)
29endif (POLICY CMP0048)
30
Austin Schuhe89fa2d2019-08-14 20:24:23 -070031# generate compile_commands.json
32set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Austin Schuhe89fa2d2019-08-14 20:24:23 -070033
34# NOTE: Code coverage only works on Linux & OSX.
35option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
36option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
37option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
38option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
39 ON)
40option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
41 ON)
Austin Schuh272c6132020-11-14 16:37:52 -080042option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
43 OFF)
Austin Schuhe89fa2d2019-08-14 20:24:23 -070044option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
James Kuszmaul8e62b022022-03-22 09:33:25 -070045option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
46 OFF)
Austin Schuhe89fa2d2019-08-14 20:24:23 -070047option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
48option(FLATBUFFERS_BUILD_SHAREDLIB
49 "Enable the build of the flatbuffers shared library"
50 OFF)
51option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
52# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
53option(FLATBUFFERS_CODE_SANITIZE
54 "Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
55 OFF)
56option(FLATBUFFERS_PACKAGE_REDHAT
57 "Build an rpm using the 'package' target."
58 OFF)
59option(FLATBUFFERS_PACKAGE_DEBIAN
60 "Build an deb using the 'package' target."
61 OFF)
Austin Schuh272c6132020-11-14 16:37:52 -080062option(FLATBUFFERS_BUILD_CPP17
63 "Enable the build of c++17 test target. \"
64 Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
65 OFF)
66option(FLATBUFFERS_BUILD_LEGACY
67 "Run C++ code generator with '--cpp-std c++0x' switch."
68 OFF)
69option(FLATBUFFERS_ENABLE_PCH
70 "Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
71 Only work if CMake supports 'target_precompile_headers'. \"
72 This can speed up compilation time."
73 OFF)
James Kuszmaul8e62b022022-03-22 09:33:25 -070074option(FLATBUFFERS_SKIP_MONSTER_EXTRA
75 "Skip generating monster_extra.fbs that contains non-supported numerical\"
76 types." OFF)
77option(FLATBUFFERS_OSX_BUILD_UNIVERSAL
78 "Enable the build for multiple architectures on OS X (arm64, x86_64)."
79 ON)
Austin Schuhe89fa2d2019-08-14 20:24:23 -070080
81if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
82 message(WARNING
83 "Cannot build tests without building the compiler. Tests will be disabled.")
84 set(FLATBUFFERS_BUILD_TESTS OFF)
85endif()
86
87if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
88 # Override the default recursion depth limit.
89 add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
90 message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
91endif()
92
93# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
94if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
James Kuszmaul8e62b022022-03-22 09:33:25 -070095 include(CheckCXXSymbolExists)
96
Austin Schuhe89fa2d2019-08-14 20:24:23 -070097 set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
98 if(MSVC)
99 check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
100 check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
101 else()
102 check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
103 check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
104 endif()
105 if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
106 set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
107 endif()
108endif()
109add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
110
111set(FlatBuffers_Library_SRCS
James Kuszmaul8e62b022022-03-22 09:33:25 -0700112 include/flatbuffers/allocator.h
113 include/flatbuffers/array.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700114 include/flatbuffers/base.h
James Kuszmaul8e62b022022-03-22 09:33:25 -0700115 include/flatbuffers/bfbs_generator.h
116 include/flatbuffers/buffer.h
117 include/flatbuffers/buffer_ref.h
118 include/flatbuffers/default_allocator.h
119 include/flatbuffers/detached_buffer.h
120 include/flatbuffers/flatbuffer_builder.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700121 include/flatbuffers/flatbuffers.h
James Kuszmaul8e62b022022-03-22 09:33:25 -0700122 include/flatbuffers/flexbuffers.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700123 include/flatbuffers/hash.h
124 include/flatbuffers/idl.h
James Kuszmaul8e62b022022-03-22 09:33:25 -0700125 include/flatbuffers/minireflect.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700126 include/flatbuffers/reflection.h
127 include/flatbuffers/reflection_generated.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700128 include/flatbuffers/registry.h
James Kuszmaul8e62b022022-03-22 09:33:25 -0700129 include/flatbuffers/stl_emulation.h
130 include/flatbuffers/string.h
131 include/flatbuffers/struct.h
132 include/flatbuffers/table.h
133 include/flatbuffers/util.h
134 include/flatbuffers/vector.h
135 include/flatbuffers/vector_downward.h
136 include/flatbuffers/verifier.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700137 src/idl_parser.cpp
138 src/idl_gen_text.cpp
139 src/reflection.cpp
140 src/util.cpp
141)
142
143set(FlatBuffers_Compiler_SRCS
144 ${FlatBuffers_Library_SRCS}
145 src/idl_gen_cpp.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800146 src/idl_gen_csharp.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700147 src/idl_gen_dart.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700148 src/idl_gen_kotlin.cpp
149 src/idl_gen_go.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800150 src/idl_gen_java.cpp
James Kuszmaul8e62b022022-03-22 09:33:25 -0700151 src/idl_gen_ts.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700152 src/idl_gen_php.cpp
153 src/idl_gen_python.cpp
154 src/idl_gen_lobster.cpp
155 src/idl_gen_lua.cpp
156 src/idl_gen_rust.cpp
157 src/idl_gen_fbs.cpp
158 src/idl_gen_grpc.cpp
159 src/idl_gen_json_schema.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800160 src/idl_gen_swift.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700161 src/flatc.cpp
162 src/flatc_main.cpp
James Kuszmaul8e62b022022-03-22 09:33:25 -0700163 src/bfbs_gen.h
164 src/bfbs_gen_lua.h
Austin Schuh272c6132020-11-14 16:37:52 -0800165 include/flatbuffers/code_generators.h
James Kuszmaul8e62b022022-03-22 09:33:25 -0700166 src/bfbs_gen_lua.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800167 src/code_generators.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700168 grpc/src/compiler/schema_interface.h
169 grpc/src/compiler/cpp_generator.h
170 grpc/src/compiler/cpp_generator.cc
171 grpc/src/compiler/go_generator.h
172 grpc/src/compiler/go_generator.cc
173 grpc/src/compiler/java_generator.h
174 grpc/src/compiler/java_generator.cc
Austin Schuh272c6132020-11-14 16:37:52 -0800175 grpc/src/compiler/python_generator.h
Austin Schuh272c6132020-11-14 16:37:52 -0800176 grpc/src/compiler/python_generator.cc
177 grpc/src/compiler/swift_generator.h
178 grpc/src/compiler/swift_generator.cc
179 grpc/src/compiler/ts_generator.h
180 grpc/src/compiler/ts_generator.cc
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700181)
182
183set(FlatHash_SRCS
184 include/flatbuffers/hash.h
185 src/flathash.cpp
186)
187
188set(FlatBuffers_Tests_SRCS
189 ${FlatBuffers_Library_SRCS}
190 src/idl_gen_fbs.cpp
191 tests/test.cpp
192 tests/test_assert.h
193 tests/test_assert.cpp
194 tests/test_builder.h
195 tests/test_builder.cpp
196 tests/native_type_test_impl.h
197 tests/native_type_test_impl.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800198 include/flatbuffers/code_generators.h
199 src/code_generators.cpp
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700200 # file generate by running compiler on tests/monster_test.fbs
201 ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
Austin Schuh272c6132020-11-14 16:37:52 -0800202 # file generate by running compiler on namespace_test/namespace_test1.fbs
203 ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
204 ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
205 # file generate by running compiler on union_vector/union_vector.fbs
206 ${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700207 # file generate by running compiler on tests/arrays_test.fbs
208 ${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
209 # file generate by running compiler on tests/native_type_test.fbs
210 ${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
Austin Schuh272c6132020-11-14 16:37:52 -0800211 # file generate by running compiler on tests/monster_extra.fbs
212 ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
213 # file generate by running compiler on tests/monster_test.fbs
214 ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
215 # file generate by running compiler on tests/optional_scalars.fbs
216 ${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
217)
218
219set(FlatBuffers_Tests_CPP17_SRCS
220 ${FlatBuffers_Library_SRCS}
221 tests/test_assert.h
222 tests/test_assert.cpp
223 tests/cpp17/test_cpp17.cpp
224 # file generate by running compiler on tests/monster_test.fbs
225 ${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
226 ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
227 ${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
228 ${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700229)
230
231set(FlatBuffers_Sample_Binary_SRCS
232 include/flatbuffers/flatbuffers.h
233 samples/sample_binary.cpp
234 # file generated by running compiler on samples/monster.fbs
235 ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
236)
237
238set(FlatBuffers_Sample_Text_SRCS
239 ${FlatBuffers_Library_SRCS}
240 samples/sample_text.cpp
241 # file generated by running compiler on samples/monster.fbs
242 ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
243)
244
245set(FlatBuffers_Sample_BFBS_SRCS
246 ${FlatBuffers_Library_SRCS}
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700247 samples/sample_bfbs.cpp
248 # file generated by running compiler on samples/monster.fbs
249 ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
250)
251
252set(FlatBuffers_GRPCTest_SRCS
253 include/flatbuffers/flatbuffers.h
254 include/flatbuffers/grpc.h
255 include/flatbuffers/util.h
256 src/util.cpp
257 tests/monster_test.grpc.fb.h
258 tests/test_assert.h
259 tests/test_builder.h
260 tests/monster_test.grpc.fb.cc
261 tests/test_assert.cpp
262 tests/test_builder.cpp
263 grpc/tests/grpctest.cpp
264 grpc/tests/message_builder_test.cpp
Austin Schuh272c6132020-11-14 16:37:52 -0800265 # file generate by running compiler on tests/monster_test.fbs
266 ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700267)
268
269# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
270# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
271
272if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
273 # do not apply any global settings if the toolchain
274 # is being configured externally
275 message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700276elseif(CMAKE_COMPILER_IS_GNUCXX)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700277 set(CMAKE_CXX_FLAGS
278 "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
279 set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
280 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
281 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
282 set(CMAKE_CXX_FLAGS
283 "${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
284 endif()
285 set(CMAKE_CXX_FLAGS
286 "${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
287 endif()
288
289 # Certain platforms such as ARM do not use signed chars by default
290 # which causes issues with certain bounds checks.
291 set(CMAKE_CXX_FLAGS
292 "${CMAKE_CXX_FLAGS} -fsigned-char")
293
James Kuszmaul8e62b022022-03-22 09:33:25 -0700294# MSVC **MUST** come before the Clang check, as clang-cl is flagged by CMake as "MSVC", but it still textually
295# matches as Clang in its Compiler Id :)
296# Note: in CMake >= 3.14 we can check CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" or "MSVC" to differentiate...
297elseif(MSVC)
298 # Visual Studio pedantic build settings
299 # warning C4512: assignment operator could not be generated
300 # warning C4316: object allocated on the heap may not be aligned
301 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
302
303 if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
304 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
305 endif()
306
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700307elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
James Kuszmaul8e62b022022-03-22 09:33:25 -0700308 if(APPLE)
309 if(FLATBUFFERS_OSX_BUILD_UNIVERSAL)
310 set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
311 endif()
312 endif()
313
314 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700315 set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
316 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
317 list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
318 endif()
319 if(FLATBUFFERS_LIBCXX_WITH_CLANG)
320 if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
321 set(CMAKE_CXX_FLAGS
322 "${CMAKE_CXX_FLAGS} -stdlib=libc++")
323 endif()
324 if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
325 "${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
326 set(CMAKE_EXE_LINKER_FLAGS
327 "${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
328 endif()
329 endif()
330
331 # Certain platforms such as ARM do not use signed chars by default
332 # which causes issues with certain bounds checks.
333 set(CMAKE_CXX_FLAGS
334 "${CMAKE_CXX_FLAGS} -fsigned-char")
335
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700336endif()
337
James Kuszmaul8e62b022022-03-22 09:33:25 -0700338# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
339if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
340 message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
341 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
342endif()
343message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
344
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700345if(FLATBUFFERS_CODE_COVERAGE)
346 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
347 set(CMAKE_EXE_LINKER_FLAGS
348 "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
349endif()
350
351function(add_fsanitize_to_target _target _sanitizer)
Austin Schuh272c6132020-11-14 16:37:52 -0800352 if(WIN32)
353 target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
354 message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
355 else()
356 # FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
357 # List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
358 if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
359 ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
360 )
361 set(_sanitizer_flags "=address,undefined")
362 if(_sanitizer MATCHES "=.*")
363 # override default by user-defined sanitizer list
364 set(_sanitizer_flags ${_sanitizer})
365 endif()
366 target_compile_options(${_target} PRIVATE
367 -g -fsigned-char -fno-omit-frame-pointer
368 "-fsanitize${_sanitizer_flags}")
369 target_link_libraries(${_target} PRIVATE
370 "-fsanitize${_sanitizer_flags}")
371 set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
372 message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700373 endif()
Austin Schuh272c6132020-11-14 16:37:52 -0800374 endif()
375endfunction()
376
377function(add_pch_to_target _target _pch_header)
378 if(COMMAND target_precompile_headers)
379 target_precompile_headers(${_target} PRIVATE ${_pch_header})
380 if(NOT MSVC)
381 set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
382 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700383 endif()
384endfunction()
385
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700386include_directories(include)
387include_directories(grpc)
388
389if(FLATBUFFERS_BUILD_FLATLIB)
390 add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
Austin Schuh272c6132020-11-14 16:37:52 -0800391 # Attach header directory for when build via add_subdirectory().
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700392 target_include_directories(flatbuffers INTERFACE
393 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
394 target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
James Kuszmaul8e62b022022-03-22 09:33:25 -0700395 target_compile_features(flatbuffers PUBLIC cxx_std_11)
Austin Schuh272c6132020-11-14 16:37:52 -0800396 if(FLATBUFFERS_ENABLE_PCH)
397 add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
398 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700399endif()
400
401if(FLATBUFFERS_BUILD_FLATC)
402 add_executable(flatc ${FlatBuffers_Compiler_SRCS})
Austin Schuh272c6132020-11-14 16:37:52 -0800403 if(FLATBUFFERS_ENABLE_PCH)
404 add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
405 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700406 target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
James Kuszmaul8e62b022022-03-22 09:33:25 -0700407 target_compile_features(flatc PUBLIC cxx_std_11)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700408 if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
409 add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
410 endif()
411 if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
412 set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
413 endif()
414 if(MSVC)
415 # Make flatc.exe not depend on runtime dlls for easy distribution.
416 target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
417 endif()
Austin Schuh272c6132020-11-14 16:37:52 -0800418 if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
419 target_link_libraries(flatc PRIVATE -static)
420 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700421endif()
422
423if(FLATBUFFERS_BUILD_FLATHASH)
424 add_executable(flathash ${FlatHash_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700425 target_compile_features(flathash PUBLIC cxx_std_11)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700426endif()
427
428if(FLATBUFFERS_BUILD_SHAREDLIB)
429 add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700430 target_compile_features(flatbuffers_shared PUBLIC cxx_std_11)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700431 # Shared object version: "major.minor.micro"
432 # - micro updated every release when there is no API/ABI changes
433 # - minor updated when there are additions in API/ABI
434 # - major (ABI number) updated when there are changes in ABI (or removals)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700435 set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
436 set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700437 set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
438 SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
439 VERSION "${FlatBuffers_Library_SONAME_FULL}")
Austin Schuh272c6132020-11-14 16:37:52 -0800440 if(FLATBUFFERS_ENABLE_PCH)
441 add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
442 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700443endif()
444
Austin Schuh272c6132020-11-14 16:37:52 -0800445# Global list of generated files.
446# Use the global property to be independent of PARENT_SCOPE.
447set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
448
449function(get_generated_output generated_files)
450 get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
451 set(${generated_files} ${tmp} PARENT_SCOPE)
452endfunction(get_generated_output)
453
454function(register_generated_output file_name)
455 get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
456 list(APPEND tmp ${file_name})
457 set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
458endfunction(register_generated_output)
459
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700460function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
Austin Schuh272c6132020-11-14 16:37:52 -0800461 if(FLATBUFFERS_BUILD_LEGACY)
462 set(OPT ${OPT};--cpp-std c++0x)
463 else()
464 # --cpp-std is defined by flatc default settings.
465 endif()
466 message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700467 get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
468 string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
469 add_custom_command(
470 OUTPUT ${GEN_HEADER}
Austin Schuh272c6132020-11-14 16:37:52 -0800471 COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
472 --cpp --gen-mutable --gen-object-api --reflect-names
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700473 --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
Austin Schuh272c6132020-11-14 16:37:52 -0800474 ${OPT}
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700475 -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
Austin Schuh272c6132020-11-14 16:37:52 -0800476 -o "${SRC_FBS_DIR}"
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700477 "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
Austin Schuh272c6132020-11-14 16:37:52 -0800478 DEPENDS flatc
479 COMMENT "Run generation: '${GEN_HEADER}'")
480 register_generated_output(${GEN_HEADER})
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700481endfunction()
482
483function(compile_flatbuffers_schema_to_cpp SRC_FBS)
Austin Schuh272c6132020-11-14 16:37:52 -0800484 compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700485endfunction()
486
487function(compile_flatbuffers_schema_to_binary SRC_FBS)
Austin Schuh272c6132020-11-14 16:37:52 -0800488 message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700489 get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
490 string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700491 # For details about flags see generate_code.py
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700492 add_custom_command(
493 OUTPUT ${GEN_BINARY_SCHEMA}
Austin Schuh272c6132020-11-14 16:37:52 -0800494 COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
495 -b --schema --bfbs-comments --bfbs-builtins
James Kuszmaul8e62b022022-03-22 09:33:25 -0700496 --bfbs-filenames ${SRC_FBS_DIR}
Austin Schuh272c6132020-11-14 16:37:52 -0800497 -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
498 -o "${SRC_FBS_DIR}"
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700499 "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
Austin Schuh272c6132020-11-14 16:37:52 -0800500 DEPENDS flatc
501 COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
502 register_generated_output(${GEN_BINARY_SCHEMA})
503endfunction()
504
505function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
506 if(FLATBUFFERS_BUILD_LEGACY)
507 set(OPT ${OPT};--cpp-std c++0x)
508 else()
509 # --cpp-std is defined by flatc default settings.
510 endif()
511 message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
512 get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
513 string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700514 # For details about flags see generate_code.py
Austin Schuh272c6132020-11-14 16:37:52 -0800515 add_custom_command(
516 OUTPUT ${GEN_BFBS_HEADER}
517 COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
518 --cpp --gen-mutable --gen-object-api --reflect-names
519 --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
520 ${OPT}
521 --bfbs-comments --bfbs-builtins --bfbs-gen-embed
James Kuszmaul8e62b022022-03-22 09:33:25 -0700522 --bfbs-filenames ${SRC_FBS_DIR}
Austin Schuh272c6132020-11-14 16:37:52 -0800523 -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
524 -o "${SRC_FBS_DIR}"
525 "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
526 DEPENDS flatc
527 COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
528 register_generated_output(${GEN_BFBS_HEADER})
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700529endfunction()
530
531if(FLATBUFFERS_BUILD_TESTS)
Austin Schuh272c6132020-11-14 16:37:52 -0800532 file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
533 file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
534
535 # TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700536 compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
Austin Schuh272c6132020-11-14 16:37:52 -0800537 compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700538 compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
539 compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
540 compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
Austin Schuh272c6132020-11-14 16:37:52 -0800541 compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700542 compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
Austin Schuh272c6132020-11-14 16:37:52 -0800543 compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
544 compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
545 compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
546 if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
547 compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
548 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700549 include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
550 add_executable(flattests ${FlatBuffers_Tests_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700551 target_compile_features(flattests PUBLIC cxx_std_11)
Austin Schuh272c6132020-11-14 16:37:52 -0800552 add_dependencies(flattests generated_code)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700553 set_property(TARGET flattests
554 PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
555 FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
556 if(FLATBUFFERS_CODE_SANITIZE)
Austin Schuh272c6132020-11-14 16:37:52 -0800557 add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700558 endif()
559
560 compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
Austin Schuh272c6132020-11-14 16:37:52 -0800561 compile_flatbuffers_schema_to_binary(samples/monster.fbs)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700562 include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
563 add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700564 target_compile_features(flatsamplebinary PUBLIC cxx_std_11)
Austin Schuh272c6132020-11-14 16:37:52 -0800565 add_dependencies(flatsamplebinary generated_code)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700566 add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700567 target_compile_features(flatsampletext PUBLIC cxx_std_11)
Austin Schuh272c6132020-11-14 16:37:52 -0800568 add_dependencies(flatsampletext generated_code)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700569 add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
James Kuszmaul8e62b022022-03-22 09:33:25 -0700570 target_compile_features(flatsamplebfbs PUBLIC cxx_std_11)
Austin Schuh272c6132020-11-14 16:37:52 -0800571 add_dependencies(flatsamplebfbs generated_code)
572
573 if(FLATBUFFERS_BUILD_CPP17)
574 # Don't generate header for flattests_cpp17 target.
575 # This target uses "generated_cpp17/monster_test_generated.h"
James Kuszmaul8e62b022022-03-22 09:33:25 -0700576 # produced by direct call of generate_code.py script.
Austin Schuh272c6132020-11-14 16:37:52 -0800577 add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
578 add_dependencies(flattests_cpp17 generated_code)
579 target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
580 target_compile_definitions(flattests_cpp17 PRIVATE
581 FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
582 FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
583 )
584 if(FLATBUFFERS_CODE_SANITIZE)
585 add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
586 endif()
587 endif(FLATBUFFERS_BUILD_CPP17)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700588endif()
589
590if(FLATBUFFERS_BUILD_GRPCTEST)
591 if(CMAKE_COMPILER_IS_GNUCXX)
592 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
593 endif()
594 if(NOT GRPC_INSTALL_PATH)
595 message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
596 endif()
597 if(NOT PROTOBUF_DOWNLOAD_PATH)
598 message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
599 endif()
600 INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
601 INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700602 find_package(Threads REQUIRED)
603 list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
604 find_package(absl CONFIG REQUIRED)
605 find_package(protobuf CONFIG REQUIRED)
606 find_package(gRPC CONFIG REQUIRED)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700607 add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
Austin Schuh272c6132020-11-14 16:37:52 -0800608 add_dependencies(grpctest generated_code)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700609 target_compile_features(grpctest PRIVATE cxx_std_11)
610 target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
Austin Schuh272c6132020-11-14 16:37:52 -0800611 if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
612 # GRPC test has problems with alignment and will fail under ASAN/UBSAN.
613 # add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
614 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700615endif()
616
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700617
618if(FLATBUFFERS_INSTALL)
619 include(GNUInstallDirs)
620
621 install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
622
623 set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
624
625 configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY)
626 install(
627 FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake"
628 DESTINATION ${FB_CMAKE_DIR}
629 )
630
631 if(FLATBUFFERS_BUILD_FLATLIB)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700632 install(
633 TARGETS flatbuffers EXPORT FlatbuffersTargets
634 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
635 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
636 )
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700637
638 install(EXPORT FlatbuffersTargets
639 FILE FlatbuffersTargets.cmake
640 NAMESPACE flatbuffers::
641 DESTINATION ${FB_CMAKE_DIR}
642 )
643 endif()
644
645 if(FLATBUFFERS_BUILD_FLATC)
646 install(
647 TARGETS flatc EXPORT FlatcTargets
648 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
649 )
650
651 install(
652 EXPORT FlatcTargets
653 FILE FlatcTargets.cmake
654 NAMESPACE flatbuffers::
655 DESTINATION ${FB_CMAKE_DIR}
656 )
657 endif()
658
659 if(FLATBUFFERS_BUILD_SHAREDLIB)
James Kuszmaul8e62b022022-03-22 09:33:25 -0700660 install(
661 TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
662 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
663 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
664 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
665 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
666 )
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700667
James Kuszmaul8e62b022022-03-22 09:33:25 -0700668 install(
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700669 EXPORT FlatbuffersSharedTargets
670 FILE FlatbuffersSharedTargets.cmake
671 NAMESPACE flatbuffers::
672 DESTINATION ${FB_CMAKE_DIR}
673 )
674 endif()
James Kuszmaul8e62b022022-03-22 09:33:25 -0700675
676 if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
677 configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
678 install(
679 FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
680 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
681 )
682 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700683endif()
684
685if(FLATBUFFERS_BUILD_TESTS)
686 enable_testing()
687
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700688 add_test(NAME flattests COMMAND flattests)
Austin Schuh272c6132020-11-14 16:37:52 -0800689 if(FLATBUFFERS_BUILD_CPP17)
690 add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
691 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700692 if(FLATBUFFERS_BUILD_GRPCTEST)
693 add_test(NAME grpctest COMMAND grpctest)
694 endif()
695endif()
696
Austin Schuh272c6132020-11-14 16:37:52 -0800697# This target is sync-barrier.
698# Other generate-dependent targets can depend on 'generated_code' only.
699get_generated_output(fbs_generated)
700if(fbs_generated)
701 # message(STATUS "Add generated_code target with files:${fbs_generated}")
702 add_custom_target(generated_code
703 DEPENDS ${fbs_generated}
704 COMMENT "All generated files were updated.")
705endif()
706
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700707include(CMake/BuildFlatBuffers.cmake)
708
709if(UNIX)
710 # Use of CPack only supported on Linux systems.
711 if(FLATBUFFERS_PACKAGE_DEBIAN)
712 include(CMake/PackageDebian.cmake)
Austin Schuh272c6132020-11-14 16:37:52 -0800713 include(CPack)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700714 endif()
715 if (FLATBUFFERS_PACKAGE_REDHAT)
716 include(CMake/PackageRedhat.cmake)
Austin Schuh272c6132020-11-14 16:37:52 -0800717 include(CPack)
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700718 endif()
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700719endif()
James Kuszmaul8e62b022022-03-22 09:33:25 -0700720
721# Include for running Google Benchmarks.
722if(FLATBUFFERS_BUILD_BENCHMARKS)
723 add_subdirectory(benchmarks)
724endif()
725
726# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
727add_library(FlatBuffers INTERFACE)
728add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
729target_include_directories(
730 FlatBuffers
731 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
732 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)