Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 1 | cmake_minimum_required(VERSION 2.8.12) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 2 | # generate compile_commands.json |
| 3 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 4 | include(CheckCXXSymbolExists) |
| 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) |
| 10 | option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON) |
| 11 | option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON) |
| 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) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 16 | option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag" |
| 17 | OFF) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 18 | option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) |
| 19 | option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF) |
| 20 | option(FLATBUFFERS_BUILD_SHAREDLIB |
| 21 | "Enable the build of the flatbuffers shared library" |
| 22 | OFF) |
| 23 | option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON) |
| 24 | # NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm). |
| 25 | option(FLATBUFFERS_CODE_SANITIZE |
| 26 | "Add '-fsanitize' flags to 'flattests' and 'flatc' targets." |
| 27 | OFF) |
| 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) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [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) |
| 41 | option(FLATBUFFERS_ENABLE_PCH |
| 42 | "Enable precompile headers support for 'flatbuffers' and 'flatc'. \" |
| 43 | Only work if CMake supports 'target_precompile_headers'. \" |
| 44 | This can speed up compilation time." |
| 45 | OFF) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 46 | |
| 47 | if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS) |
| 48 | message(WARNING |
| 49 | "Cannot build tests without building the compiler. Tests will be disabled.") |
| 50 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 51 | endif() |
| 52 | |
| 53 | if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH) |
| 54 | # Override the default recursion depth limit. |
| 55 | add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH}) |
| 56 | message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}") |
| 57 | endif() |
| 58 | |
| 59 | # Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions. |
| 60 | if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT) |
| 61 | set(FLATBUFFERS_LOCALE_INDEPENDENT 0) |
| 62 | if(MSVC) |
| 63 | check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 64 | check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
| 65 | else() |
| 66 | check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 67 | check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
| 68 | endif() |
| 69 | if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L) |
| 70 | set(FLATBUFFERS_LOCALE_INDEPENDENT 1) |
| 71 | endif() |
| 72 | endif() |
| 73 | add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>) |
| 74 | |
| 75 | set(FlatBuffers_Library_SRCS |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 76 | include/flatbuffers/base.h |
| 77 | include/flatbuffers/flatbuffers.h |
| 78 | include/flatbuffers/hash.h |
| 79 | include/flatbuffers/idl.h |
| 80 | include/flatbuffers/util.h |
| 81 | include/flatbuffers/reflection.h |
| 82 | include/flatbuffers/reflection_generated.h |
| 83 | include/flatbuffers/stl_emulation.h |
| 84 | include/flatbuffers/flexbuffers.h |
| 85 | include/flatbuffers/registry.h |
| 86 | include/flatbuffers/minireflect.h |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 87 | src/idl_parser.cpp |
| 88 | src/idl_gen_text.cpp |
| 89 | src/reflection.cpp |
| 90 | src/util.cpp |
| 91 | ) |
| 92 | |
| 93 | set(FlatBuffers_Compiler_SRCS |
| 94 | ${FlatBuffers_Library_SRCS} |
| 95 | src/idl_gen_cpp.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 96 | src/idl_gen_csharp.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 97 | src/idl_gen_dart.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 98 | src/idl_gen_kotlin.cpp |
| 99 | src/idl_gen_go.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 100 | src/idl_gen_java.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 101 | src/idl_gen_js_ts.cpp |
| 102 | src/idl_gen_php.cpp |
| 103 | src/idl_gen_python.cpp |
| 104 | src/idl_gen_lobster.cpp |
| 105 | src/idl_gen_lua.cpp |
| 106 | src/idl_gen_rust.cpp |
| 107 | src/idl_gen_fbs.cpp |
| 108 | src/idl_gen_grpc.cpp |
| 109 | src/idl_gen_json_schema.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 110 | src/idl_gen_swift.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 111 | src/flatc.cpp |
| 112 | src/flatc_main.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 113 | include/flatbuffers/code_generators.h |
| 114 | src/code_generators.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 115 | grpc/src/compiler/schema_interface.h |
| 116 | grpc/src/compiler/cpp_generator.h |
| 117 | grpc/src/compiler/cpp_generator.cc |
| 118 | grpc/src/compiler/go_generator.h |
| 119 | grpc/src/compiler/go_generator.cc |
| 120 | grpc/src/compiler/java_generator.h |
| 121 | grpc/src/compiler/java_generator.cc |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 122 | grpc/src/compiler/python_generator.h |
| 123 | grpc/src/compiler/python_private_generator.h |
| 124 | grpc/src/compiler/python_generator.cc |
| 125 | grpc/src/compiler/swift_generator.h |
| 126 | grpc/src/compiler/swift_generator.cc |
| 127 | grpc/src/compiler/ts_generator.h |
| 128 | grpc/src/compiler/ts_generator.cc |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 129 | ) |
| 130 | |
| 131 | set(FlatHash_SRCS |
| 132 | include/flatbuffers/hash.h |
| 133 | src/flathash.cpp |
| 134 | ) |
| 135 | |
| 136 | set(FlatBuffers_Tests_SRCS |
| 137 | ${FlatBuffers_Library_SRCS} |
| 138 | src/idl_gen_fbs.cpp |
| 139 | tests/test.cpp |
| 140 | tests/test_assert.h |
| 141 | tests/test_assert.cpp |
| 142 | tests/test_builder.h |
| 143 | tests/test_builder.cpp |
| 144 | tests/native_type_test_impl.h |
| 145 | tests/native_type_test_impl.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 146 | include/flatbuffers/code_generators.h |
| 147 | src/code_generators.cpp |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 148 | # file generate by running compiler on tests/monster_test.fbs |
| 149 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 150 | # file generate by running compiler on namespace_test/namespace_test1.fbs |
| 151 | ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h |
| 152 | ${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h |
| 153 | # file generate by running compiler on union_vector/union_vector.fbs |
| 154 | ${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 155 | # file generate by running compiler on tests/arrays_test.fbs |
| 156 | ${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h |
| 157 | # file generate by running compiler on tests/native_type_test.fbs |
| 158 | ${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 159 | # file generate by running compiler on tests/monster_extra.fbs |
| 160 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h |
| 161 | # file generate by running compiler on tests/monster_test.fbs |
| 162 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h |
| 163 | # file generate by running compiler on tests/optional_scalars.fbs |
| 164 | ${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h |
| 165 | ) |
| 166 | |
| 167 | set(FlatBuffers_Tests_CPP17_SRCS |
| 168 | ${FlatBuffers_Library_SRCS} |
| 169 | tests/test_assert.h |
| 170 | tests/test_assert.cpp |
| 171 | tests/cpp17/test_cpp17.cpp |
| 172 | # file generate by running compiler on tests/monster_test.fbs |
| 173 | ${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h |
| 174 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
| 175 | ${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h |
| 176 | ${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 177 | ) |
| 178 | |
| 179 | set(FlatBuffers_Sample_Binary_SRCS |
| 180 | include/flatbuffers/flatbuffers.h |
| 181 | samples/sample_binary.cpp |
| 182 | # file generated by running compiler on samples/monster.fbs |
| 183 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 184 | ) |
| 185 | |
| 186 | set(FlatBuffers_Sample_Text_SRCS |
| 187 | ${FlatBuffers_Library_SRCS} |
| 188 | samples/sample_text.cpp |
| 189 | # file generated by running compiler on samples/monster.fbs |
| 190 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 191 | ) |
| 192 | |
| 193 | set(FlatBuffers_Sample_BFBS_SRCS |
| 194 | ${FlatBuffers_Library_SRCS} |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 195 | samples/sample_bfbs.cpp |
| 196 | # file generated by running compiler on samples/monster.fbs |
| 197 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 198 | ) |
| 199 | |
| 200 | set(FlatBuffers_GRPCTest_SRCS |
| 201 | include/flatbuffers/flatbuffers.h |
| 202 | include/flatbuffers/grpc.h |
| 203 | include/flatbuffers/util.h |
| 204 | src/util.cpp |
| 205 | tests/monster_test.grpc.fb.h |
| 206 | tests/test_assert.h |
| 207 | tests/test_builder.h |
| 208 | tests/monster_test.grpc.fb.cc |
| 209 | tests/test_assert.cpp |
| 210 | tests/test_builder.cpp |
| 211 | grpc/tests/grpctest.cpp |
| 212 | grpc/tests/message_builder_test.cpp |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 213 | # file generate by running compiler on tests/monster_test.fbs |
| 214 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 215 | ) |
| 216 | |
| 217 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 218 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 219 | |
| 220 | if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") |
| 221 | # do not apply any global settings if the toolchain |
| 222 | # is being configured externally |
| 223 | message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") |
| 224 | elseif(APPLE) |
| 225 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
| 226 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
| 227 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 228 | elseif(CMAKE_COMPILER_IS_GNUCXX) |
| 229 | if(CYGWIN) |
| 230 | set(CMAKE_CXX_FLAGS |
| 231 | "${CMAKE_CXX_FLAGS} -std=gnu++11") |
| 232 | else(CYGWIN) |
| 233 | set(CMAKE_CXX_FLAGS |
| 234 | "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 235 | endif(CYGWIN) |
| 236 | set(CMAKE_CXX_FLAGS |
| 237 | "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow") |
| 238 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 239 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4) |
| 240 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
| 241 | set(CMAKE_CXX_FLAGS |
| 242 | "${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2") |
| 243 | endif() |
| 244 | set(CMAKE_CXX_FLAGS |
| 245 | "${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter") |
| 246 | endif() |
| 247 | |
| 248 | # Certain platforms such as ARM do not use signed chars by default |
| 249 | # which causes issues with certain bounds checks. |
| 250 | set(CMAKE_CXX_FLAGS |
| 251 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 252 | |
| 253 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
| 254 | set(CMAKE_CXX_FLAGS |
| 255 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
| 256 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 257 | if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8) |
| 258 | list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning |
| 259 | endif() |
| 260 | if(FLATBUFFERS_LIBCXX_WITH_CLANG) |
| 261 | if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") |
| 262 | set(CMAKE_CXX_FLAGS |
| 263 | "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 264 | endif() |
| 265 | if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR |
| 266 | "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")) |
| 267 | set(CMAKE_EXE_LINKER_FLAGS |
| 268 | "${CMAKE_EXE_LINKER_FLAGS} -lc++abi") |
| 269 | endif() |
| 270 | endif() |
| 271 | |
| 272 | # Certain platforms such as ARM do not use signed chars by default |
| 273 | # which causes issues with certain bounds checks. |
| 274 | set(CMAKE_CXX_FLAGS |
| 275 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 276 | |
| 277 | elseif(MSVC) |
| 278 | # Visual Studio pedantic build settings |
| 279 | # warning C4512: assignment operator could not be generated |
| 280 | # warning C4316: object allocated on the heap may not be aligned |
| 281 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 282 | |
| 283 | # multi-core build. |
| 284 | add_definitions("/MP") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 285 | endif() |
| 286 | |
| 287 | if(FLATBUFFERS_CODE_COVERAGE) |
| 288 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") |
| 289 | set(CMAKE_EXE_LINKER_FLAGS |
| 290 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
| 291 | endif() |
| 292 | |
| 293 | function(add_fsanitize_to_target _target _sanitizer) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 294 | if(WIN32) |
| 295 | target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING) |
| 296 | message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}") |
| 297 | else() |
| 298 | # FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer. |
| 299 | # List of sanitizer is string starts with '=': "=address,undefined,thread,memory". |
| 300 | if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR |
| 301 | ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")) |
| 302 | ) |
| 303 | set(_sanitizer_flags "=address,undefined") |
| 304 | if(_sanitizer MATCHES "=.*") |
| 305 | # override default by user-defined sanitizer list |
| 306 | set(_sanitizer_flags ${_sanitizer}) |
| 307 | endif() |
| 308 | target_compile_options(${_target} PRIVATE |
| 309 | -g -fsigned-char -fno-omit-frame-pointer |
| 310 | "-fsanitize${_sanitizer_flags}") |
| 311 | target_link_libraries(${_target} PRIVATE |
| 312 | "-fsanitize${_sanitizer_flags}") |
| 313 | set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON) |
| 314 | message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 315 | endif() |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 316 | endif() |
| 317 | endfunction() |
| 318 | |
| 319 | function(add_pch_to_target _target _pch_header) |
| 320 | if(COMMAND target_precompile_headers) |
| 321 | target_precompile_headers(${_target} PRIVATE ${_pch_header}) |
| 322 | if(NOT MSVC) |
| 323 | set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON) |
| 324 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 325 | endif() |
| 326 | endfunction() |
| 327 | |
| 328 | if(BIICODE) |
| 329 | include(biicode/cmake/biicode.cmake) |
| 330 | return() |
| 331 | endif() |
| 332 | |
| 333 | include_directories(include) |
| 334 | include_directories(grpc) |
| 335 | |
| 336 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 337 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 338 | # Attach header directory for when build via add_subdirectory(). |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 339 | target_include_directories(flatbuffers INTERFACE |
| 340 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) |
| 341 | target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 342 | if(FLATBUFFERS_ENABLE_PCH) |
| 343 | add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h) |
| 344 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 345 | endif() |
| 346 | |
| 347 | if(FLATBUFFERS_BUILD_FLATC) |
| 348 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 349 | if(FLATBUFFERS_ENABLE_PCH) |
| 350 | add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h) |
| 351 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 352 | target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
| 353 | if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32) |
| 354 | add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE}) |
| 355 | endif() |
| 356 | if(NOT FLATBUFFERS_FLATC_EXECUTABLE) |
| 357 | set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>) |
| 358 | endif() |
| 359 | if(MSVC) |
| 360 | # Make flatc.exe not depend on runtime dlls for easy distribution. |
| 361 | target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>) |
| 362 | endif() |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 363 | if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC) |
| 364 | target_link_libraries(flatc PRIVATE -static) |
| 365 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 366 | endif() |
| 367 | |
| 368 | if(FLATBUFFERS_BUILD_FLATHASH) |
| 369 | add_executable(flathash ${FlatHash_SRCS}) |
| 370 | endif() |
| 371 | |
| 372 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 373 | add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS}) |
| 374 | |
| 375 | # Shared object version: "major.minor.micro" |
| 376 | # - micro updated every release when there is no API/ABI changes |
| 377 | # - minor updated when there are additions in API/ABI |
| 378 | # - major (ABI number) updated when there are changes in ABI (or removals) |
| 379 | set(FlatBuffers_Library_SONAME_MAJOR "1") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 380 | set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.12.0") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 381 | set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers |
| 382 | SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}" |
| 383 | VERSION "${FlatBuffers_Library_SONAME_FULL}") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 384 | if(FLATBUFFERS_ENABLE_PCH) |
| 385 | add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h) |
| 386 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 387 | endif() |
| 388 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 389 | # Global list of generated files. |
| 390 | # Use the global property to be independent of PARENT_SCOPE. |
| 391 | set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 392 | |
| 393 | function(get_generated_output generated_files) |
| 394 | get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 395 | set(${generated_files} ${tmp} PARENT_SCOPE) |
| 396 | endfunction(get_generated_output) |
| 397 | |
| 398 | function(register_generated_output file_name) |
| 399 | get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS) |
| 400 | list(APPEND tmp ${file_name}) |
| 401 | set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp}) |
| 402 | endfunction(register_generated_output) |
| 403 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 404 | function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 405 | if(FLATBUFFERS_BUILD_LEGACY) |
| 406 | set(OPT ${OPT};--cpp-std c++0x) |
| 407 | else() |
| 408 | # --cpp-std is defined by flatc default settings. |
| 409 | endif() |
| 410 | message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 411 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 412 | string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS}) |
| 413 | add_custom_command( |
| 414 | OUTPUT ${GEN_HEADER} |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 415 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 416 | --cpp --gen-mutable --gen-object-api --reflect-names |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 417 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 418 | ${OPT} |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 419 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 420 | -o "${SRC_FBS_DIR}" |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 421 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 422 | DEPENDS flatc |
| 423 | COMMENT "Run generation: '${GEN_HEADER}'") |
| 424 | register_generated_output(${GEN_HEADER}) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 425 | endfunction() |
| 426 | |
| 427 | function(compile_flatbuffers_schema_to_cpp SRC_FBS) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 428 | compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 429 | endfunction() |
| 430 | |
| 431 | function(compile_flatbuffers_schema_to_binary SRC_FBS) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 432 | message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema") |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 433 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 434 | string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 435 | # For details about flags see generate_code.bat(sh) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 436 | add_custom_command( |
| 437 | OUTPUT ${GEN_BINARY_SCHEMA} |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 438 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 439 | -b --schema --bfbs-comments --bfbs-builtins |
| 440 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
| 441 | -o "${SRC_FBS_DIR}" |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 442 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 443 | DEPENDS flatc |
| 444 | COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'") |
| 445 | register_generated_output(${GEN_BINARY_SCHEMA}) |
| 446 | endfunction() |
| 447 | |
| 448 | function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT) |
| 449 | if(FLATBUFFERS_BUILD_LEGACY) |
| 450 | set(OPT ${OPT};--cpp-std c++0x) |
| 451 | else() |
| 452 | # --cpp-std is defined by flatc default settings. |
| 453 | endif() |
| 454 | message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'") |
| 455 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 456 | string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS}) |
| 457 | # For details about flags see generate_code.bat(sh) |
| 458 | add_custom_command( |
| 459 | OUTPUT ${GEN_BFBS_HEADER} |
| 460 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" |
| 461 | --cpp --gen-mutable --gen-object-api --reflect-names |
| 462 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
| 463 | ${OPT} |
| 464 | --bfbs-comments --bfbs-builtins --bfbs-gen-embed |
| 465 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
| 466 | -o "${SRC_FBS_DIR}" |
| 467 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
| 468 | DEPENDS flatc |
| 469 | COMMENT "Run generation: '${GEN_BFBS_HEADER}'") |
| 470 | register_generated_output(${GEN_BFBS_HEADER}) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 471 | endfunction() |
| 472 | |
| 473 | if(FLATBUFFERS_BUILD_TESTS) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 474 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") |
| 475 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") |
| 476 | |
| 477 | # TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 478 | compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 479 | compile_flatbuffers_schema_to_binary(tests/monster_test.fbs) |
| 480 | compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test1.fbs) |
| 481 | compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test2.fbs) |
| 482 | compile_flatbuffers_schema_to_cpp(tests/union_vector/union_vector.fbs) |
| 483 | compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 484 | compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 485 | compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare") |
| 486 | compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs) |
| 487 | compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare") |
| 488 | if(NOT (MSVC AND (MSVC_VERSION LESS 1900))) |
| 489 | compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF. |
| 490 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 491 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) |
| 492 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 493 | add_dependencies(flattests generated_code) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 494 | set_property(TARGET flattests |
| 495 | PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 496 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1) |
| 497 | if(FLATBUFFERS_CODE_SANITIZE) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 498 | add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE}) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 499 | endif() |
| 500 | |
| 501 | compile_flatbuffers_schema_to_cpp(samples/monster.fbs) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 502 | compile_flatbuffers_schema_to_binary(samples/monster.fbs) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 503 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples) |
| 504 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 505 | add_dependencies(flatsamplebinary generated_code) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 506 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 507 | add_dependencies(flatsampletext generated_code) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 508 | add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 509 | add_dependencies(flatsamplebfbs generated_code) |
| 510 | |
| 511 | if(FLATBUFFERS_BUILD_CPP17) |
| 512 | # Don't generate header for flattests_cpp17 target. |
| 513 | # This target uses "generated_cpp17/monster_test_generated.h" |
| 514 | # produced by direct call of generate_code.bat(sh) script. |
| 515 | add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS}) |
| 516 | add_dependencies(flattests_cpp17 generated_code) |
| 517 | target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) |
| 518 | target_compile_definitions(flattests_cpp17 PRIVATE |
| 519 | FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 520 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1 |
| 521 | ) |
| 522 | if(FLATBUFFERS_CODE_SANITIZE) |
| 523 | add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE}) |
| 524 | endif() |
| 525 | endif(FLATBUFFERS_BUILD_CPP17) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 526 | endif() |
| 527 | |
| 528 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 529 | if(CMAKE_COMPILER_IS_GNUCXX) |
| 530 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow") |
| 531 | endif() |
| 532 | if(NOT GRPC_INSTALL_PATH) |
| 533 | message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md") |
| 534 | endif() |
| 535 | if(NOT PROTOBUF_DOWNLOAD_PATH) |
| 536 | message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md") |
| 537 | endif() |
| 538 | INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include) |
| 539 | INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src) |
| 540 | LINK_DIRECTORIES(${GRPC_INSTALL_PATH}/lib) |
| 541 | add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS}) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 542 | add_dependencies(grpctest generated_code) |
| 543 | target_link_libraries(grpctest PRIVATE grpc++_unsecure grpc_unsecure gpr pthread dl) |
| 544 | if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32) |
| 545 | # GRPC test has problems with alignment and will fail under ASAN/UBSAN. |
| 546 | # add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE}) |
| 547 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 548 | endif() |
| 549 | |
| 550 | include(CMake/Version.cmake) |
| 551 | |
| 552 | if(FLATBUFFERS_INSTALL) |
| 553 | include(GNUInstallDirs) |
| 554 | |
| 555 | install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 556 | |
| 557 | set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers") |
| 558 | |
| 559 | configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY) |
| 560 | install( |
| 561 | FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake" |
| 562 | DESTINATION ${FB_CMAKE_DIR} |
| 563 | ) |
| 564 | |
| 565 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 566 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 567 | install( |
| 568 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 569 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 570 | ) |
| 571 | else() |
| 572 | install( |
| 573 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 574 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 575 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 576 | ) |
| 577 | endif() |
| 578 | |
| 579 | install(EXPORT FlatbuffersTargets |
| 580 | FILE FlatbuffersTargets.cmake |
| 581 | NAMESPACE flatbuffers:: |
| 582 | DESTINATION ${FB_CMAKE_DIR} |
| 583 | ) |
| 584 | endif() |
| 585 | |
| 586 | if(FLATBUFFERS_BUILD_FLATC) |
| 587 | install( |
| 588 | TARGETS flatc EXPORT FlatcTargets |
| 589 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 590 | ) |
| 591 | |
| 592 | install( |
| 593 | EXPORT FlatcTargets |
| 594 | FILE FlatcTargets.cmake |
| 595 | NAMESPACE flatbuffers:: |
| 596 | DESTINATION ${FB_CMAKE_DIR} |
| 597 | ) |
| 598 | endif() |
| 599 | |
| 600 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 601 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 602 | install( |
| 603 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 604 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 605 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 606 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 607 | ) |
| 608 | else() |
| 609 | install( |
| 610 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 611 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 612 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 613 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 614 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 615 | ) |
| 616 | endif() |
| 617 | |
| 618 | install( |
| 619 | EXPORT FlatbuffersSharedTargets |
| 620 | FILE FlatbuffersSharedTargets.cmake |
| 621 | NAMESPACE flatbuffers:: |
| 622 | DESTINATION ${FB_CMAKE_DIR} |
| 623 | ) |
| 624 | endif() |
| 625 | endif() |
| 626 | |
| 627 | if(FLATBUFFERS_BUILD_TESTS) |
| 628 | enable_testing() |
| 629 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 630 | add_test(NAME flattests COMMAND flattests) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 631 | if(FLATBUFFERS_BUILD_CPP17) |
| 632 | add_test(NAME flattests_cpp17 COMMAND flattests_cpp17) |
| 633 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 634 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 635 | add_test(NAME grpctest COMMAND grpctest) |
| 636 | endif() |
| 637 | endif() |
| 638 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 639 | # This target is sync-barrier. |
| 640 | # Other generate-dependent targets can depend on 'generated_code' only. |
| 641 | get_generated_output(fbs_generated) |
| 642 | if(fbs_generated) |
| 643 | # message(STATUS "Add generated_code target with files:${fbs_generated}") |
| 644 | add_custom_target(generated_code |
| 645 | DEPENDS ${fbs_generated} |
| 646 | COMMENT "All generated files were updated.") |
| 647 | endif() |
| 648 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 649 | include(CMake/BuildFlatBuffers.cmake) |
| 650 | |
| 651 | if(UNIX) |
| 652 | # Use of CPack only supported on Linux systems. |
| 653 | if(FLATBUFFERS_PACKAGE_DEBIAN) |
| 654 | include(CMake/PackageDebian.cmake) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 655 | include(CPack) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 656 | endif() |
| 657 | if (FLATBUFFERS_PACKAGE_REDHAT) |
| 658 | include(CMake/PackageRedhat.cmake) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 659 | include(CPack) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 660 | endif() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 661 | endif() |