Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8) |
| 2 | |
| 3 | project(FlatBuffers) |
| 4 | |
| 5 | # NOTE: Code coverage only works on Linux & OSX. |
| 6 | option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 7 | option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 8 | option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON) |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 9 | option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library" |
| 10 | ON) |
| 11 | option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" |
| 12 | ON) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 13 | option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 14 | option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF) |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 15 | option(FLATBUFFERS_BUILD_SHAREDLIB |
| 16 | "Enable the build of the flatbuffers shared library" |
| 17 | OFF) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 18 | |
| 19 | if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS) |
| 20 | message(WARNING |
| 21 | "Cannot build tests without building the compiler. Tests will be disabled.") |
| 22 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 23 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 24 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 25 | set(FlatBuffers_Library_SRCS |
Lakedaemon | 8a64afa | 2016-04-13 23:21:18 +0200 | [diff] [blame] | 26 | include/flatbuffers/code_generators.h |
Wouter van Oortmerssen | 88a85ff | 2017-06-15 20:54:04 -0700 | [diff] [blame] | 27 | include/flatbuffers/base.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 28 | include/flatbuffers/flatbuffers.h |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 29 | include/flatbuffers/hash.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 30 | include/flatbuffers/idl.h |
| 31 | include/flatbuffers/util.h |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 32 | include/flatbuffers/reflection.h |
| 33 | include/flatbuffers/reflection_generated.h |
Stewart Miles | a892322 | 2017-07-13 06:27:39 -0700 | [diff] [blame] | 34 | include/flatbuffers/stl_emulation.h |
Wouter van Oortmerssen | aac6be1 | 2016-02-01 18:00:30 -0800 | [diff] [blame] | 35 | include/flatbuffers/flexbuffers.h |
Wouter van Oortmerssen | 88a85ff | 2017-06-15 20:54:04 -0700 | [diff] [blame] | 36 | include/flatbuffers/registry.h |
Wouter van Oortmerssen | 72a99ab | 2017-08-24 17:44:03 -0700 | [diff] [blame] | 37 | include/flatbuffers/minireflect.h |
Wouter van Oortmerssen | 7b94eab | 2017-01-13 17:44:42 -0800 | [diff] [blame] | 38 | src/code_generators.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 39 | src/idl_parser.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 40 | src/idl_gen_text.cpp |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 41 | src/reflection.cpp |
Wouter van Oortmerssen | e98b191 | 2016-03-30 17:34:52 -0700 | [diff] [blame] | 42 | src/util.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 43 | ) |
| 44 | |
| 45 | set(FlatBuffers_Compiler_SRCS |
| 46 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 47 | src/idl_gen_cpp.cpp |
Wouter van Oortmerssen | 557c88c | 2014-09-16 17:37:17 -0700 | [diff] [blame] | 48 | src/idl_gen_general.cpp |
rw | 74d5f37 | 2014-07-11 16:12:35 -0700 | [diff] [blame] | 49 | src/idl_gen_go.cpp |
Evan Wallace | 224e33e | 2015-08-17 00:56:54 -0700 | [diff] [blame] | 50 | src/idl_gen_js.cpp |
Shuhei Taunma | 5ce8682 | 2015-11-05 16:19:28 +0900 | [diff] [blame] | 51 | src/idl_gen_php.cpp |
rw | 48dfc69 | 2014-12-16 00:32:11 -0800 | [diff] [blame] | 52 | src/idl_gen_python.cpp |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 53 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 54 | src/idl_gen_grpc.cpp |
schoetbi | f202041 | 2017-07-10 17:05:59 +0200 | [diff] [blame] | 55 | src/idl_gen_json_schema.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 56 | src/flatc.cpp |
Wouter van Oortmerssen | b395359 | 2017-01-25 13:41:34 -0800 | [diff] [blame] | 57 | src/flatc_main.cpp |
Harsh Vardhan | 2e7806e | 2016-08-19 10:41:11 +0530 | [diff] [blame] | 58 | grpc/src/compiler/schema_interface.h |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 59 | grpc/src/compiler/cpp_generator.h |
| 60 | grpc/src/compiler/cpp_generator.cc |
Ronak Jain | a31ddd2 | 2016-12-06 02:50:38 +0530 | [diff] [blame] | 61 | grpc/src/compiler/go_generator.h |
| 62 | grpc/src/compiler/go_generator.cc |
Yuri Finkelstein | 8518b3f | 2017-12-21 07:55:57 -1000 | [diff] [blame] | 63 | grpc/src/compiler/java_generator.h |
| 64 | grpc/src/compiler/java_generator.cc |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 65 | ) |
| 66 | |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 67 | set(FlatHash_SRCS |
| 68 | include/flatbuffers/hash.h |
| 69 | src/flathash.cpp |
| 70 | ) |
| 71 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 72 | set(FlatBuffers_Tests_SRCS |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 73 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 74 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 75 | tests/test.cpp |
| 76 | # file generate by running compiler on tests/monster_test.fbs |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 77 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 78 | ) |
| 79 | |
| 80 | set(FlatBuffers_Sample_Binary_SRCS |
| 81 | include/flatbuffers/flatbuffers.h |
| 82 | samples/sample_binary.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 83 | # file generated by running compiler on samples/monster.fbs |
| 84 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 85 | ) |
| 86 | |
| 87 | set(FlatBuffers_Sample_Text_SRCS |
Wouter van Oortmerssen | 7b94eab | 2017-01-13 17:44:42 -0800 | [diff] [blame] | 88 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 89 | samples/sample_text.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 90 | # file generated by running compiler on samples/monster.fbs |
| 91 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 92 | ) |
| 93 | |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 94 | set(FlatBuffers_GRPCTest_SRCS |
| 95 | include/flatbuffers/flatbuffers.h |
| 96 | include/flatbuffers/grpc.h |
| 97 | tests/monster_test.grpc.fb.h |
| 98 | tests/monster_test.grpc.fb.cc |
| 99 | grpc/tests/grpctest.cpp |
| 100 | # file generated by running compiler on samples/monster.fbs |
| 101 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
| 102 | ) |
| 103 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 104 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 105 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 106 | |
Andrew Hundt | 520d684 | 2016-10-05 16:20:30 -0400 | [diff] [blame] | 107 | if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") |
Wouter van Oortmerssen | 606098c | 2016-10-17 13:06:11 -0700 | [diff] [blame] | 108 | # do not apply any global settings if the toolchain |
Andrew Hundt | 520d684 | 2016-10-05 16:20:30 -0400 | [diff] [blame] | 109 | # is being configured externally |
| 110 | elseif(APPLE) |
Jason Sanmiya | 30c07f4 | 2016-07-22 19:04:23 -0700 | [diff] [blame] | 111 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
Per Grön | 9aeeddf | 2017-05-12 18:48:17 +0200 | [diff] [blame] | 112 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 113 | elseif(CMAKE_COMPILER_IS_GNUCXX) |
Tony Kelman | 4c16038 | 2016-04-01 21:42:23 -0700 | [diff] [blame] | 114 | if(CYGWIN) |
| 115 | set(CMAKE_CXX_FLAGS |
| 116 | "${CMAKE_CXX_FLAGS} -std=gnu++11") |
| 117 | else(CYGWIN) |
| 118 | set(CMAKE_CXX_FLAGS |
| 119 | "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 120 | endif(CYGWIN) |
Wouter van Oortmerssen | bc5fa9d | 2014-08-25 10:42:38 -0700 | [diff] [blame] | 121 | set(CMAKE_CXX_FLAGS |
Tony Kelman | 4c16038 | 2016-04-01 21:42:23 -0700 | [diff] [blame] | 122 | "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow") |
Kamil Rojewski | 474ba68 | 2018-02-12 17:37:51 +0100 | [diff] [blame^] | 123 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4) |
| 124 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
| 125 | set(CMAKE_CXX_FLAGS |
| 126 | "${CMAKE_CXX_FLAGS} -faligned-new") |
| 127 | endif() |
maurice barnum | 697cad7 | 2016-02-11 00:03:53 +0000 | [diff] [blame] | 128 | set(CMAKE_CXX_FLAGS |
Wouter van Oortmerssen | 606098c | 2016-10-17 13:06:11 -0700 | [diff] [blame] | 129 | "${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result \ |
| 130 | -Wunused-parameter -Werror=unused-parameter") |
maurice barnum | 697cad7 | 2016-02-11 00:03:53 +0000 | [diff] [blame] | 131 | endif() |
Will Gardner | ce4d331 | 2016-02-29 17:28:40 +0000 | [diff] [blame] | 132 | |
| 133 | # Certain platforms such as ARM do not use signed chars by default |
| 134 | # which causes issues with certain bounds checks. |
| 135 | set(CMAKE_CXX_FLAGS |
| 136 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 137 | |
Jason Sanmiya | 985de21 | 2016-09-08 10:47:50 -0700 | [diff] [blame] | 138 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 139 | set(CMAKE_CXX_FLAGS |
Alex Ames | f2627e1 | 2017-10-20 16:29:51 -0700 | [diff] [blame] | 140 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter") |
Andrei Lebedev | 695d261 | 2017-02-26 09:47:57 +0400 | [diff] [blame] | 141 | if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") |
| 142 | set(CMAKE_CXX_FLAGS |
| 143 | "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 144 | endif() |
| 145 | if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR |
| 146 | "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")) |
Yuri | 26f15bc | 2016-03-02 17:15:42 -0800 | [diff] [blame] | 147 | set(CMAKE_EXE_LINKER_FLAGS |
| 148 | "${CMAKE_EXE_LINKER_FLAGS} -lc++abi") |
| 149 | endif() |
Will Gardner | ce4d331 | 2016-02-29 17:28:40 +0000 | [diff] [blame] | 150 | |
| 151 | # Certain platforms such as ARM do not use signed chars by default |
| 152 | # which causes issues with certain bounds checks. |
| 153 | set(CMAKE_CXX_FLAGS |
| 154 | "${CMAKE_CXX_FLAGS} -fsigned-char") |
| 155 | |
Wouter van Oortmerssen | 6561c7a | 2017-02-15 17:44:55 -0800 | [diff] [blame] | 156 | elseif(MSVC) |
chronoxor | f538738 | 2017-03-10 21:27:30 +0300 | [diff] [blame] | 157 | # Visual Studio pedantic build settings |
Wouter van Oortmerssen | 238a8eb | 2017-03-29 12:01:11 -0700 | [diff] [blame] | 158 | # warning C4512: assignment operator could not be generated |
Wouter van Oortmerssen | e93a565 | 2017-04-24 10:29:25 -0700 | [diff] [blame] | 159 | # warning C4316: object allocated on the heap may not be aligned |
| 160 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 161 | endif() |
| 162 | |
| 163 | if(FLATBUFFERS_CODE_COVERAGE) |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 164 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 8f80fec | 2014-07-29 10:29:38 -0700 | [diff] [blame] | 165 | set(CMAKE_EXE_LINKER_FLAGS |
| 166 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 167 | endif() |
| 168 | |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 169 | if(BIICODE) |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 170 | include(biicode/cmake/biicode.cmake) |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 171 | return() |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 172 | endif() |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 173 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 174 | include_directories(include) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 175 | include_directories(grpc) |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 176 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 177 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 178 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
| 179 | endif() |
| 180 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 181 | if(FLATBUFFERS_BUILD_FLATC) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 182 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
Xiaolei Yu | 3a8bc30 | 2016-05-01 11:15:53 +0800 | [diff] [blame] | 183 | if(NOT FLATBUFFERS_FLATC_EXECUTABLE) |
| 184 | set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>) |
| 185 | endif() |
Wouter van Oortmerssen | cb2481e | 2017-05-10 15:42:23 -0700 | [diff] [blame] | 186 | if(MSVC) |
| 187 | # Make flatc.exe not depend on runtime dlls for easy distribution. |
| 188 | target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>) |
| 189 | endif() |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 190 | endif() |
| 191 | |
Jason Sanmiya | f47660f | 2015-04-28 15:44:10 -0700 | [diff] [blame] | 192 | if(FLATBUFFERS_BUILD_FLATHASH) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 193 | add_executable(flathash ${FlatHash_SRCS}) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 194 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 195 | |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 196 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
| 197 | add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS}) |
Sergey Avseyev | ca52bfe | 2017-11-10 01:39:32 +0300 | [diff] [blame] | 198 | |
| 199 | # Shared object version: "major.minor.micro" |
| 200 | # - micro updated every release when there is no API/ABI changes |
| 201 | # - minor updated when there are additions in API/ABI |
| 202 | # - major (ABI number) updated when there are changes in ABI (or removals) |
| 203 | set(FlatBuffers_Library_SONAME_MAJOR "1") |
Wouter van Oortmerssen | 34aea43 | 2017-11-20 09:46:03 -0800 | [diff] [blame] | 204 | set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.8.0") |
Sergey Avseyev | ca52bfe | 2017-11-10 01:39:32 +0300 | [diff] [blame] | 205 | set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers |
| 206 | SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}" |
| 207 | VERSION "${FlatBuffers_Library_SONAME_FULL}") |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 208 | endif() |
| 209 | |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 210 | function(compile_flatbuffers_schema_to_cpp SRC_FBS) |
Wouter van Oortmerssen | 4cdf3eb | 2014-10-24 14:26:29 -0700 | [diff] [blame] | 211 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
Wouter van Oortmerssen | 7b80535 | 2014-09-23 11:55:42 -0700 | [diff] [blame] | 212 | string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS}) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 213 | add_custom_command( |
| 214 | OUTPUT ${GEN_HEADER} |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 215 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c --no-includes --gen-mutable |
| 216 | --gen-object-api -o "${SRC_FBS_DIR}" |
Stewart Miles | a892322 | 2017-07-13 06:27:39 -0700 | [diff] [blame] | 217 | --cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs |
Wouter van Oortmerssen | 72a99ab | 2017-08-24 17:44:03 -0700 | [diff] [blame] | 218 | --reflect-names |
Wouter van Oortmerssen | 22743ca | 2017-05-24 15:21:26 -0700 | [diff] [blame] | 219 | -I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test" |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 220 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 221 | DEPENDS flatc) |
| 222 | endfunction() |
| 223 | |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 224 | function(compile_flatbuffers_schema_to_binary SRC_FBS) |
| 225 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 226 | string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) |
| 227 | add_custom_command( |
| 228 | OUTPUT ${GEN_BINARY_SCHEMA} |
Wouter van Oortmerssen | 3101e32 | 2016-07-01 18:08:51 -0700 | [diff] [blame] | 229 | COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -b --schema -o "${SRC_FBS_DIR}" |
| 230 | "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 231 | DEPENDS flatc) |
| 232 | endfunction() |
| 233 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 234 | if(FLATBUFFERS_BUILD_TESTS) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 235 | compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) |
| 236 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 237 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
Zarian Waheed | 6d6271d | 2016-12-16 08:46:30 -0800 | [diff] [blame] | 238 | set_property(TARGET flattests |
| 239 | PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE |
| 240 | FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 241 | |
| 242 | compile_flatbuffers_schema_to_cpp(samples/monster.fbs) |
| 243 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 244 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
| 245 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
| 246 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 247 | |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 248 | if(FLATBUFFERS_BUILD_GRPCTEST) |
| 249 | if(CMAKE_COMPILER_IS_GNUCXX) |
Lawrence Chan | da67c0a | 2017-06-07 15:56:49 -0500 | [diff] [blame] | 250 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow") |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 251 | endif() |
| 252 | add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS}) |
Yuri Finkelstein | 61f4a46 | 2017-12-21 06:49:00 -1000 | [diff] [blame] | 253 | target_link_libraries(grpctest grpc++_unsecure grpc_unsecure gpr pthread dl) |
Wouter van Oortmerssen | 48f37f9 | 2016-04-13 18:16:05 -0700 | [diff] [blame] | 254 | endif() |
| 255 | |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 256 | if(FLATBUFFERS_INSTALL) |
Sergey Avseyev | 2edb1dc | 2017-11-06 21:38:53 +0300 | [diff] [blame] | 257 | include(GNUInstallDirs) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 258 | |
Sergey Avseyev | 2edb1dc | 2017-11-06 21:38:53 +0300 | [diff] [blame] | 259 | install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 260 | |
| 261 | set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers") |
| 262 | |
| 263 | install( |
| 264 | FILES "CMake/FlatbuffersConfig.cmake" |
| 265 | DESTINATION ${FB_CMAKE_DIR} |
| 266 | ) |
| 267 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 268 | if(FLATBUFFERS_BUILD_FLATLIB) |
Bastien Brunnenstein | ba08b0e | 2017-11-30 17:45:58 +0100 | [diff] [blame] | 269 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 270 | install( |
| 271 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 272 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 273 | ) |
| 274 | else() |
| 275 | install( |
| 276 | TARGETS flatbuffers EXPORT FlatbuffersTargets |
| 277 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 278 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 279 | ) |
| 280 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 281 | |
| 282 | install(EXPORT FlatbuffersTargets |
| 283 | FILE FlatbuffersTargets.cmake |
| 284 | NAMESPACE flatbuffers:: |
| 285 | DESTINATION ${FB_CMAKE_DIR} |
| 286 | ) |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 287 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 288 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 289 | if(FLATBUFFERS_BUILD_FLATC) |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 290 | install( |
| 291 | TARGETS flatc EXPORT FlatcTargets |
| 292 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 293 | CONFIGURATIONS Release |
| 294 | ) |
| 295 | |
| 296 | install( |
| 297 | EXPORT FlatcTargets |
| 298 | FILE FlatcTargets.cmake |
| 299 | NAMESPACE flatbuffers:: |
| 300 | DESTINATION ${FB_CMAKE_DIR} |
| 301 | CONFIGURATIONS Release |
| 302 | ) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 303 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 304 | |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 305 | if(FLATBUFFERS_BUILD_SHAREDLIB) |
Bastien Brunnenstein | ba08b0e | 2017-11-30 17:45:58 +0100 | [diff] [blame] | 306 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| 307 | install( |
| 308 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 309 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 310 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 311 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 312 | ) |
| 313 | else() |
| 314 | install( |
| 315 | TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets |
| 316 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 317 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 318 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 319 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 320 | ) |
| 321 | endif() |
red1939 | 7e803c4 | 2017-11-16 21:51:25 +0100 | [diff] [blame] | 322 | |
| 323 | install( |
| 324 | EXPORT FlatbuffersSharedTargets |
| 325 | FILE FlatbuffersSharedTargets.cmake |
| 326 | NAMESPACE flatbuffers:: |
| 327 | DESTINATION ${FB_CMAKE_DIR} |
| 328 | ) |
changnet | a15659e | 2016-09-07 01:12:04 +0800 | [diff] [blame] | 329 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 330 | endif() |
Daniel Nachbaur | 7a99b3c | 2014-07-15 15:09:36 +0200 | [diff] [blame] | 331 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 332 | if(FLATBUFFERS_BUILD_TESTS) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 333 | enable_testing() |
| 334 | |
Wouter van Oortmerssen | 7b80535 | 2014-09-23 11:55:42 -0700 | [diff] [blame] | 335 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION |
| 336 | "${CMAKE_CURRENT_BINARY_DIR}") |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 337 | add_test(NAME flattests COMMAND flattests) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 338 | endif() |
Johan Euphrosine | 331d2d8 | 2015-11-17 13:39:37 -0800 | [diff] [blame] | 339 | |
| 340 | include(CMake/BuildFlatBuffers.cmake) |
Vitaly Isaev | 928effd | 2015-05-13 15:15:59 +0300 | [diff] [blame] | 341 | |
| 342 | if(FLATBUFFERS_PACKAGE_DEBIAN) |
| 343 | include(CMake/PackageDebian.cmake) |
| 344 | endif() |