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) |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 9 | option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library" ON) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 10 | option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" ON) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 11 | option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 12 | |
| 13 | if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS) |
| 14 | message(WARNING |
| 15 | "Cannot build tests without building the compiler. Tests will be disabled.") |
| 16 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 17 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 18 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 19 | set(FlatBuffers_Library_SRCS |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 20 | include/flatbuffers/flatbuffers.h |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 21 | include/flatbuffers/hash.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 22 | include/flatbuffers/idl.h |
| 23 | include/flatbuffers/util.h |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 24 | include/flatbuffers/reflection.h |
| 25 | include/flatbuffers/reflection_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 26 | src/idl_parser.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 27 | src/idl_gen_text.cpp |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 28 | src/reflection.cpp |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | set(FlatBuffers_Compiler_SRCS |
| 32 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 33 | src/idl_gen_cpp.cpp |
Wouter van Oortmerssen | 557c88c | 2014-09-16 17:37:17 -0700 | [diff] [blame] | 34 | src/idl_gen_general.cpp |
rw | 74d5f37 | 2014-07-11 16:12:35 -0700 | [diff] [blame] | 35 | src/idl_gen_go.cpp |
Evan Wallace | 224e33e | 2015-08-17 00:56:54 -0700 | [diff] [blame^] | 36 | src/idl_gen_js.cpp |
rw | 48dfc69 | 2014-12-16 00:32:11 -0800 | [diff] [blame] | 37 | src/idl_gen_python.cpp |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 38 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 39 | src/flatc.cpp |
| 40 | ) |
| 41 | |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 42 | set(FlatHash_SRCS |
| 43 | include/flatbuffers/hash.h |
| 44 | src/flathash.cpp |
| 45 | ) |
| 46 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 47 | set(FlatBuffers_Tests_SRCS |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 48 | ${FlatBuffers_Library_SRCS} |
Wouter van Oortmerssen | d38b9af | 2014-09-26 16:46:30 -0700 | [diff] [blame] | 49 | src/idl_gen_fbs.cpp |
Wouter van Oortmerssen | 7101224 | 2015-07-31 13:55:53 -0700 | [diff] [blame] | 50 | src/idl_gen_general.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 51 | tests/test.cpp |
| 52 | # file generate by running compiler on tests/monster_test.fbs |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 53 | ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 54 | ) |
| 55 | |
| 56 | set(FlatBuffers_Sample_Binary_SRCS |
| 57 | include/flatbuffers/flatbuffers.h |
| 58 | samples/sample_binary.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 59 | # file generated by running compiler on samples/monster.fbs |
| 60 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 61 | ) |
| 62 | |
| 63 | set(FlatBuffers_Sample_Text_SRCS |
| 64 | include/flatbuffers/flatbuffers.h |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 65 | include/flatbuffers/hash.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 66 | include/flatbuffers/idl.h |
| 67 | include/flatbuffers/util.h |
| 68 | src/idl_parser.cpp |
| 69 | src/idl_gen_text.cpp |
| 70 | samples/sample_text.cpp |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 71 | # file generated by running compiler on samples/monster.fbs |
| 72 | ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 73 | ) |
| 74 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 75 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 76 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 77 | |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 78 | if(APPLE) |
Wouter van Oortmerssen | bc5fa9d | 2014-08-25 10:42:38 -0700 | [diff] [blame] | 79 | set(CMAKE_CXX_FLAGS |
| 80 | "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 81 | elseif(CMAKE_COMPILER_IS_GNUCXX) |
Wouter van Oortmerssen | bc5fa9d | 2014-08-25 10:42:38 -0700 | [diff] [blame] | 82 | set(CMAKE_CXX_FLAGS |
| 83 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra") |
Wouter van Oortmerssen | 932b22f | 2015-05-27 16:57:21 -0700 | [diff] [blame] | 84 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 85 | set(CMAKE_CXX_FLAGS |
| 86 | "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++ -Wall -pedantic -Werror -Wextra") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 87 | endif() |
| 88 | |
| 89 | if(FLATBUFFERS_CODE_COVERAGE) |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 90 | 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] | 91 | set(CMAKE_EXE_LINKER_FLAGS |
| 92 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 93 | endif() |
| 94 | |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 95 | if(BIICODE) |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 96 | include(biicode/cmake/biicode.cmake) |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 97 | return() |
franchuti688 | 23f75f5 | 2015-04-01 12:35:37 +0200 | [diff] [blame] | 98 | endif() |
franramirez688 | da0f096 | 2015-01-31 11:14:59 -0500 | [diff] [blame] | 99 | |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 100 | include_directories(include) |
| 101 | |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 102 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 103 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
| 104 | endif() |
| 105 | |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 106 | if(FLATBUFFERS_BUILD_FLATC) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 107 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
| 108 | endif() |
| 109 | |
Jason Sanmiya | f47660f | 2015-04-28 15:44:10 -0700 | [diff] [blame] | 110 | if(FLATBUFFERS_BUILD_FLATHASH) |
Alex Ames | d575321 | 2015-02-13 15:58:29 -0800 | [diff] [blame] | 111 | add_executable(flathash ${FlatHash_SRCS}) |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 112 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 113 | |
| 114 | function(compile_flatbuffers_schema_to_cpp SRC_FBS) |
Wouter van Oortmerssen | 4cdf3eb | 2014-10-24 14:26:29 -0700 | [diff] [blame] | 115 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
Wouter van Oortmerssen | 7b80535 | 2014-09-23 11:55:42 -0700 | [diff] [blame] | 116 | string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS}) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 117 | add_custom_command( |
| 118 | OUTPUT ${GEN_HEADER} |
Wouter van Oortmerssen | 1808337 | 2015-06-15 12:29:06 -0700 | [diff] [blame] | 119 | COMMAND flatc -c --no-includes --gen-mutable -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 120 | DEPENDS flatc) |
| 121 | endfunction() |
| 122 | |
Wouter van Oortmerssen | 81312c2 | 2015-05-21 16:33:29 -0700 | [diff] [blame] | 123 | function(compile_flatbuffers_schema_to_binary SRC_FBS) |
| 124 | get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) |
| 125 | string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) |
| 126 | add_custom_command( |
| 127 | OUTPUT ${GEN_BINARY_SCHEMA} |
| 128 | COMMAND flatc -b --schema -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" |
| 129 | DEPENDS flatc) |
| 130 | endfunction() |
| 131 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 132 | if(FLATBUFFERS_BUILD_TESTS) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 133 | compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) |
| 134 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 135 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 136 | |
| 137 | compile_flatbuffers_schema_to_cpp(samples/monster.fbs) |
| 138 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 139 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
| 140 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
| 141 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 142 | |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 143 | if(FLATBUFFERS_INSTALL) |
| 144 | install(DIRECTORY include/flatbuffers DESTINATION include) |
Martell Malone | 79d3cb6 | 2015-07-22 13:18:59 +0100 | [diff] [blame] | 145 | if(FLATBUFFERS_BUILD_FLATLIB) |
| 146 | install(TARGETS flatbuffers DESTINATION lib) |
| 147 | endif() |
Leander Bessa Beernaert | 3ec8d7f | 2015-01-02 13:51:31 +0100 | [diff] [blame] | 148 | if(FLATBUFFERS_BUILD_FLATC) |
| 149 | install(TARGETS flatc DESTINATION bin) |
| 150 | endif() |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 151 | endif() |
Daniel Nachbaur | 7a99b3c | 2014-07-15 15:09:36 +0200 | [diff] [blame] | 152 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 153 | if(FLATBUFFERS_BUILD_TESTS) |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 154 | enable_testing() |
| 155 | |
Wouter van Oortmerssen | 7b80535 | 2014-09-23 11:55:42 -0700 | [diff] [blame] | 156 | file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION |
| 157 | "${CMAKE_CURRENT_BINARY_DIR}") |
Zbigniew Mandziejewicz | 3f8700b | 2014-09-16 00:50:23 +0800 | [diff] [blame] | 158 | add_test(NAME flattests COMMAND flattests) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 159 | endif() |