Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8) |
| 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) |
| 16 | option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) |
| 17 | option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF) |
| 18 | option(FLATBUFFERS_BUILD_SHAREDLIB |
| 19 | "Enable the build of the flatbuffers shared library" |
| 20 | OFF) |
| 21 | option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON) |
| 22 | # NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm). |
| 23 | option(FLATBUFFERS_CODE_SANITIZE |
| 24 | "Add '-fsanitize' flags to 'flattests' and 'flatc' targets." |
| 25 | OFF) |
| 26 | option(FLATBUFFERS_PACKAGE_REDHAT |
| 27 | "Build an rpm using the 'package' target." |
| 28 | OFF) |
| 29 | option(FLATBUFFERS_PACKAGE_DEBIAN |
| 30 | "Build an deb using the 'package' target." |
| 31 | OFF) |
| 32 | |
| 33 | if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS) |
| 34 | message(WARNING |
| 35 | "Cannot build tests without building the compiler. Tests will be disabled.") |
| 36 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 37 | endif() |
| 38 | |
| 39 | if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH) |
| 40 | # Override the default recursion depth limit. |
| 41 | add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH}) |
| 42 | message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}") |
| 43 | endif() |
| 44 | |
| 45 | # Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions. |
| 46 | if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT) |
| 47 | set(FLATBUFFERS_LOCALE_INDEPENDENT 0) |
| 48 | if(MSVC) |
| 49 | check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 50 | check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
| 51 | else() |
| 52 | check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L) |
| 53 | check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L) |
| 54 | endif() |
| 55 | if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L) |
| 56 | set(FLATBUFFERS_LOCALE_INDEPENDENT 1) |
| 57 | endif() |
| 58 | endif() |
| 59 | add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>) |
| 60 | |
| 61 | set(FlatBuffers_Library_SRCS |
| 62 | include/flatbuffers/code_generators.h |
| 63 | include/flatbuffers/base.h |
| 64 | include/flatbuffers/flatbuffers.h |
| 65 | include/flatbuffers/hash.h |
| 66 | include/flatbuffers/idl.h |
| 67 | include/flatbuffers/util.h |
| 68 | include/flatbuffers/reflection.h |
| 69 | include/flatbuffers/reflection_generated.h |
| 70 | include/flatbuffers/stl_emulation.h |
| 71 | include/flatbuffers/flexbuffers.h |
| 72 | include/flatbuffers/registry.h |
| 73 | include/flatbuffers/minireflect.h |
| 74 | src/code_generators.cpp |
| 75 | src/idl_parser.cpp |
| 76 | src/idl_gen_text.cpp |
| 77 | src/reflection.cpp |
| 78 | src/util.cpp |
| 79 | ) |
| 80 | |
| 81 | set(FlatBuffers_Compiler_SRCS |
| 82 | ${FlatBuffers_Library_SRCS} |
| 83 | src/idl_gen_cpp.cpp |
| 84 | src/idl_gen_dart.cpp |
| 85 | src/idl_gen_general.cpp |
| 86 | src/idl_gen_kotlin.cpp |
| 87 | src/idl_gen_go.cpp |
| 88 | src/idl_gen_js_ts.cpp |
| 89 | src/idl_gen_php.cpp |
| 90 | src/idl_gen_python.cpp |
| 91 | src/idl_gen_lobster.cpp |
| 92 | src/idl_gen_lua.cpp |
| 93 | src/idl_gen_rust.cpp |
| 94 | src/idl_gen_fbs.cpp |
| 95 | src/idl_gen_grpc.cpp |
| 96 | src/idl_gen_json_schema.cpp |
| 97 | src/flatc.cpp |
| 98 | src/flatc_main.cpp |
| 99 | grpc/src/compiler/schema_interface.h |
| 100 | grpc/src/compiler/cpp_generator.h |
| 101 | grpc/src/compiler/cpp_generator.cc |
| 102 | grpc/src/compiler/go_generator.h |
| 103 | grpc/src/compiler/go_generator.cc |
| 104 | grpc/src/compiler/java_generator.h |
| 105 | grpc/src/compiler/java_generator.cc |
| 106 | ) |
| 107 | |
| 108 | set(FlatHash_SRCS |
| 109 | include/flatbuffers/hash.h |
| 110 | src/flathash.cpp |
| 111 | ) |
| 112 | |
| 113 | set(FlatBuffers_Tests_SRCS |
| 114 | ${FlatBuffers_Library_SRCS} |
| 115 | src/idl_gen_fbs.cpp |
| 116 | tests/test.cpp |
| 117 | tests/test_assert.h |
| 118 | tests/test_assert.cpp |
| 119 | tests/test_builder.h |
| 120 | tests/test_builder.cpp |
| 121 | tests/native_type_test_impl.h |
| 122 | tests/native_type_test_impl.cpp |
| 123 | # file generate by running compiler on tests/monster_test.fbs |
| 124 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
| 125 | # file generate by running compiler on tests/arrays_test.fbs |
| 126 | ${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h |
| 127 | # file generate by running compiler on tests/native_type_test.fbs |
| 128 | ${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h |
| 129 | ) |
| 130 | |
| 131 | set(FlatBuffers_Sample_Binary_SRCS |
| 132 | include/flatbuffers/flatbuffers.h |
| 133 | samples/sample_binary.cpp |
| 134 | # file generated by running compiler on samples/monster.fbs |
| 135 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 136 | ) |
| 137 | |
| 138 | set(FlatBuffers_Sample_Text_SRCS |
| 139 | ${FlatBuffers_Library_SRCS} |
| 140 | samples/sample_text.cpp |
| 141 | # file generated by running compiler on samples/monster.fbs |
| 142 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 143 | ) |
| 144 | |
| 145 | set(FlatBuffers_Sample_BFBS_SRCS |
| 146 | ${FlatBuffers_Library_SRCS} |
| 147 | src/idl_gen_general.cpp |
| 148 | samples/sample_bfbs.cpp |
| 149 | # file generated by running compiler on samples/monster.fbs |
| 150 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 151 | ) |
| 152 | |
| 153 | set(FlatBuffers_GRPCTest_SRCS |
| 154 | include/flatbuffers/flatbuffers.h |
| 155 | include/flatbuffers/grpc.h |
| 156 | include/flatbuffers/util.h |
| 157 | src/util.cpp |
| 158 | tests/monster_test.grpc.fb.h |
| 159 | tests/test_assert.h |
| 160 | tests/test_builder.h |
| 161 | tests/monster_test.grpc.fb.cc |
| 162 | tests/test_assert.cpp |
| 163 | tests/test_builder.cpp |
| 164 | grpc/tests/grpctest.cpp |
| 165 | grpc/tests/message_builder_test.cpp |
| 166 | # file generated by running compiler on samples/monster.fbs |
| 167 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 168 | ) |
| 169 | |
| 170 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 171 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 172 | |
| 173 | if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") |
| 174 | # do not apply any global settings if the toolchain |
| 175 | # is being configured externally |
| 176 | message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") |
| 177 | elseif(APPLE) |
| 178 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
| 179 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
| 180 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 181 | elseif(CMAKE_COMPILER_IS_GNUCXX) |
| 182 | if(CYGWIN) |
| 183 | set(CMAKE_CXX_FLAGS |
| 184 | "${CMAKE_CXX_FLAGS} -std=gnu++11") |
| 185 | else(CYGWIN) |
| 186 | set(CMAKE_CXX_FLAGS |
| 187 | "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 188 | endif(CYGWIN) |
| 189 | set(CMAKE_CXX_FLAGS |
| 190 | "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow") |
| 191 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 192 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4) |
| 193 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
| 194 | set(CMAKE_CXX_FLAGS |
| 195 | "${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2") |
| 196 | endif() |
| 197 | set(CMAKE_CXX_FLAGS |
| 198 | "${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter") |
| 199 | endif() |
| 200 | |
| 201 | # Certain platforms such as ARM do not use signed chars by default |
| 202 | # which causes issues with certain bounds checks. |
| 203 | set(CMAKE_CXX_FLAGS |
| 204 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 205 | |
| 206 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
| 207 | set(CMAKE_CXX_FLAGS |
| 208 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
| 209 | set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast") |
| 210 | if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8) |
| 211 | list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning |
| 212 | endif() |
| 213 | if(FLATBUFFERS_LIBCXX_WITH_CLANG) |
| 214 | if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") |
| 215 | set(CMAKE_CXX_FLAGS |
| 216 | "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 217 | endif() |
| 218 | if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR |
| 219 | "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")) |
| 220 | set(CMAKE_EXE_LINKER_FLAGS |
| 221 | "${CMAKE_EXE_LINKER_FLAGS} -lc++abi") |
| 222 | endif() |
| 223 | endif() |
| 224 | |
| 225 | # Certain platforms such as ARM do not use signed chars by default |
| 226 | # which causes issues with certain bounds checks. |
| 227 | set(CMAKE_CXX_FLAGS |
| 228 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 229 | |
| 230 | elseif(MSVC) |
| 231 | # Visual Studio pedantic build settings |
| 232 | # warning C4512: assignment operator could not be generated |
| 233 | # warning C4316: object allocated on the heap may not be aligned |
| 234 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316") |
| 235 | endif() |
| 236 | |
| 237 | if(FLATBUFFERS_CODE_COVERAGE) |
| 238 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") |
| 239 | set(CMAKE_EXE_LINKER_FLAGS |
| 240 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
| 241 | endif() |
| 242 | |
| 243 | function(add_fsanitize_to_target _target _sanitizer) |
| 244 | # FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer. |
| 245 | # List of sanitizer is string starts with '=': "=address,undefined,thread,memory". |
| 246 | if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR |
| 247 | ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")) |
| 248 | ) |
| 249 | set(_sanitizer_flags "=address,undefined") |
| 250 | if(_sanitizer MATCHES "=.*") |
| 251 | # override default by user-defined sanitizer list |
| 252 | set(_sanitizer_flags ${_sanitizer}) |
| 253 | endif() |
| 254 | target_compile_options(${_target} PRIVATE |
| 255 | -g -fsigned-char -fno-omit-frame-pointer |
| 256 | "-fsanitize${_sanitizer_flags}") |
| 257 | target_link_libraries(${_target} PRIVATE |
| 258 | "-fsanitize${_sanitizer_flags}") |
| 259 | set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON) |
| 260 | message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}") |
| 261 | endif() |
| 262 | endfunction() |
| 263 | |
| 264 | if(BIICODE) |
| 265 | include(biicode/cmake/biicode.cmake) |
| 266 | return() |
| 267 | endif() |
| 268 | |
| 269 | include_directories(include) |
| 270 | include_directories(grpc) |
| 271 | |
| 272 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 273 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
| 274 | # CMake > 2.8.11: Attach header directory for when build via add_subdirectory(). |
| 275 | target_include_directories(flatbuffers INTERFACE |
| 276 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) |
| 277 | target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
| 278 | endif() |
| 279 | |
| 280 | if(FLATBUFFERS_BUILD_FLATC) |
| 281 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
| 282 | target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}") |
| 283 | if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32) |
| 284 | add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE}) |
| 285 | endif() |
| 286 | if(NOT FLATBUFFERS_FLATC_EXECUTABLE) |
| 287 | set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>) |
| 288 | endif() |
| 289 | if(MSVC) |
| 290 | # Make flatc.exe not depend on runtime dlls for easy distribution. |
| 291 | target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>) |
| 292 | endif() |
| 293 | endif() |
| 294 | |
| 295 | if(FLATBUFFERS_BUILD_FLATHASH) |
| 296 | add_executable(flathash ${FlatHash_SRCS}) |
| 297 | endif() |
| 298 | |
| 299 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 300 | add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS}) |
| 301 | |
| 302 | # Shared object version: "major.minor.micro" |
| 303 | # - micro updated every release when there is no API/ABI changes |
| 304 | # - minor updated when there are additions in API/ABI |
| 305 | # - major (ABI number) updated when there are changes in ABI (or removals) |
| 306 | set(FlatBuffers_Library_SONAME_MAJOR "1") |
| 307 | set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.11.0") |
| 308 | set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers |
| 309 | SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}" |
| 310 | VERSION "${FlatBuffers_Library_SONAME_FULL}") |
| 311 | endif() |
| 312 | |
| 313 | function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT) |
| 314 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 315 | string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS}) |
| 316 | add_custom_command( |
| 317 | OUTPUT ${GEN_HEADER} |
| 318 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c --gen-mutable |
| 319 | --gen-object-api -o "${SRC_FBS_DIR}" |
| 320 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
| 321 | --reflect-names ${OPT} |
| 322 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
| 323 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
| 324 | DEPENDS flatc) |
| 325 | endfunction() |
| 326 | |
| 327 | function(compile_flatbuffers_schema_to_cpp SRC_FBS) |
| 328 | compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare") |
| 329 | endfunction() |
| 330 | |
| 331 | function(compile_flatbuffers_schema_to_binary SRC_FBS) |
| 332 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 333 | string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) |
| 334 | add_custom_command( |
| 335 | OUTPUT ${GEN_BINARY_SCHEMA} |
| 336 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -b --schema -o "${SRC_FBS_DIR}" |
| 337 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
| 338 | DEPENDS flatc) |
| 339 | endfunction() |
| 340 | |
| 341 | if(FLATBUFFERS_BUILD_TESTS) |
| 342 | compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) |
| 343 | compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "") |
| 344 | compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs --scoped-enums) |
| 345 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) |
| 346 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
| 347 | set_property(TARGET flattests |
| 348 | PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 349 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1) |
| 350 | if(FLATBUFFERS_CODE_SANITIZE) |
| 351 | if(WIN32) |
| 352 | target_compile_definitions(flattests PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING) |
| 353 | message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to flattests") |
| 354 | else() |
| 355 | add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE}) |
| 356 | endif() |
| 357 | endif() |
| 358 | |
| 359 | compile_flatbuffers_schema_to_cpp(samples/monster.fbs) |
| 360 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples) |
| 361 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
| 362 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
| 363 | add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS}) |
| 364 | endif() |
| 365 | |
| 366 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 367 | if(CMAKE_COMPILER_IS_GNUCXX) |
| 368 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow") |
| 369 | endif() |
| 370 | if(NOT GRPC_INSTALL_PATH) |
| 371 | message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md") |
| 372 | endif() |
| 373 | if(NOT PROTOBUF_DOWNLOAD_PATH) |
| 374 | message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md") |
| 375 | endif() |
| 376 | INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include) |
| 377 | INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src) |
| 378 | LINK_DIRECTORIES(${GRPC_INSTALL_PATH}/lib) |
| 379 | add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS}) |
| 380 | target_link_libraries(grpctest grpc++_unsecure grpc_unsecure gpr pthread dl) |
| 381 | endif() |
| 382 | |
| 383 | include(CMake/Version.cmake) |
| 384 | |
| 385 | if(FLATBUFFERS_INSTALL) |
| 386 | include(GNUInstallDirs) |
| 387 | |
| 388 | install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 389 | |
| 390 | set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers") |
| 391 | |
| 392 | configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY) |
| 393 | install( |
| 394 | FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake" |
| 395 | DESTINATION ${FB_CMAKE_DIR} |
| 396 | ) |
| 397 | |
| 398 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 399 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 400 | install( |
| 401 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 402 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 403 | ) |
| 404 | else() |
| 405 | install( |
| 406 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 407 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 408 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 409 | ) |
| 410 | endif() |
| 411 | |
| 412 | install(EXPORT FlatbuffersTargets |
| 413 | FILE FlatbuffersTargets.cmake |
| 414 | NAMESPACE flatbuffers:: |
| 415 | DESTINATION ${FB_CMAKE_DIR} |
| 416 | ) |
| 417 | endif() |
| 418 | |
| 419 | if(FLATBUFFERS_BUILD_FLATC) |
| 420 | install( |
| 421 | TARGETS flatc EXPORT FlatcTargets |
| 422 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 423 | ) |
| 424 | |
| 425 | install( |
| 426 | EXPORT FlatcTargets |
| 427 | FILE FlatcTargets.cmake |
| 428 | NAMESPACE flatbuffers:: |
| 429 | DESTINATION ${FB_CMAKE_DIR} |
| 430 | ) |
| 431 | endif() |
| 432 | |
| 433 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 434 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 435 | install( |
| 436 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 437 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 438 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 439 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 440 | ) |
| 441 | else() |
| 442 | install( |
| 443 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 444 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 445 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 446 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 447 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 448 | ) |
| 449 | endif() |
| 450 | |
| 451 | install( |
| 452 | EXPORT FlatbuffersSharedTargets |
| 453 | FILE FlatbuffersSharedTargets.cmake |
| 454 | NAMESPACE flatbuffers:: |
| 455 | DESTINATION ${FB_CMAKE_DIR} |
| 456 | ) |
| 457 | endif() |
| 458 | endif() |
| 459 | |
| 460 | if(FLATBUFFERS_BUILD_TESTS) |
| 461 | enable_testing() |
| 462 | |
| 463 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION |
| 464 | "${CMAKE_CURRENT_BINARY_DIR}") |
| 465 | add_test(NAME flattests COMMAND flattests) |
| 466 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 467 | add_test(NAME grpctest COMMAND grpctest) |
| 468 | endif() |
| 469 | endif() |
| 470 | |
| 471 | include(CMake/BuildFlatBuffers.cmake) |
| 472 | |
| 473 | if(UNIX) |
| 474 | # Use of CPack only supported on Linux systems. |
| 475 | if(FLATBUFFERS_PACKAGE_DEBIAN) |
| 476 | include(CMake/PackageDebian.cmake) |
| 477 | endif() |
| 478 | if (FLATBUFFERS_PACKAGE_REDHAT) |
| 479 | include(CMake/PackageRedhat.cmake) |
| 480 | endif() |
| 481 | include(CPack) |
| 482 | endif() |