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) |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 8 | |
| 9 | set(FlatBuffers_Compiler_SRCS |
| 10 | include/flatbuffers/flatbuffers.h |
| 11 | include/flatbuffers/idl.h |
| 12 | include/flatbuffers/util.h |
| 13 | src/idl_parser.cpp |
| 14 | src/idl_gen_cpp.cpp |
Wouter van Oortmerssen | 557c88c | 2014-09-16 17:37:17 -0700 | [diff] [blame^] | 15 | src/idl_gen_general.cpp |
rw | 74d5f37 | 2014-07-11 16:12:35 -0700 | [diff] [blame] | 16 | src/idl_gen_go.cpp |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 17 | src/idl_gen_text.cpp |
| 18 | src/flatc.cpp |
| 19 | ) |
| 20 | |
| 21 | set(FlatBuffers_Tests_SRCS |
| 22 | include/flatbuffers/flatbuffers.h |
| 23 | include/flatbuffers/idl.h |
| 24 | include/flatbuffers/util.h |
| 25 | src/idl_parser.cpp |
| 26 | src/idl_gen_text.cpp |
| 27 | tests/test.cpp |
| 28 | # file generate by running compiler on tests/monster_test.fbs |
| 29 | tests/monster_test_generated.h |
| 30 | ) |
| 31 | |
| 32 | set(FlatBuffers_Sample_Binary_SRCS |
| 33 | include/flatbuffers/flatbuffers.h |
| 34 | samples/sample_binary.cpp |
| 35 | # file generate by running compiler on samples/monster.fbs |
| 36 | samples/monster_generated.h |
| 37 | ) |
| 38 | |
| 39 | set(FlatBuffers_Sample_Text_SRCS |
| 40 | include/flatbuffers/flatbuffers.h |
| 41 | include/flatbuffers/idl.h |
| 42 | include/flatbuffers/util.h |
| 43 | src/idl_parser.cpp |
| 44 | src/idl_gen_text.cpp |
| 45 | samples/sample_text.cpp |
| 46 | # file generate by running compiler on samples/monster.fbs |
| 47 | samples/monster_generated.h |
| 48 | ) |
| 49 | |
| 50 | set(CMAKE_BUILD_TYPE Debug) |
| 51 | |
| 52 | # source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS}) |
| 53 | # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) |
| 54 | |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 55 | if(APPLE) |
Wouter van Oortmerssen | bc5fa9d | 2014-08-25 10:42:38 -0700 | [diff] [blame] | 56 | set(CMAKE_CXX_FLAGS |
| 57 | "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra") |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 58 | 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] | 59 | set(CMAKE_CXX_FLAGS |
| 60 | "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 61 | endif() |
| 62 | |
| 63 | if(FLATBUFFERS_CODE_COVERAGE) |
Stefan Eilemann | 52f4f45 | 2014-07-26 13:12:56 +0200 | [diff] [blame] | 64 | 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] | 65 | set(CMAKE_EXE_LINKER_FLAGS |
| 66 | "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 67 | endif() |
| 68 | |
| 69 | include_directories(include) |
| 70 | |
| 71 | add_executable(flatc ${FlatBuffers_Compiler_SRCS}) |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 72 | if(FLATBUFFERS_BUILD_TESTS) |
| 73 | add_executable(flattests ${FlatBuffers_Tests_SRCS}) |
| 74 | add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) |
| 75 | add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) |
| 76 | endif() |
Wouter van Oortmerssen | 26a3073 | 2014-01-27 16:52:49 -0800 | [diff] [blame] | 77 | |
Daniel Nachbaur | 7a99b3c | 2014-07-15 15:09:36 +0200 | [diff] [blame] | 78 | install(DIRECTORY include/flatbuffers DESTINATION include) |
| 79 | install(TARGETS flatc DESTINATION bin) |
| 80 | |
Stewart Miles | 3f85183 | 2014-09-10 16:01:13 -0700 | [diff] [blame] | 81 | if(FLATBUFFERS_BUILD_TESTS) |
| 82 | add_test(NAME flattest |
| 83 | CONFIGURATIONS Debug |
| 84 | WORKING_DIRECTORY tests |
| 85 | COMMAND flattests) |
| 86 | endif() |