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