# NOTE: Code coverage only works on Linux & OSX.
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
+option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
set(FlatBuffers_Compiler_SRCS
include/flatbuffers/flatbuffers.h
src/idl_gen_text.cpp
tests/test.cpp
# file generate by running compiler on tests/monster_test.fbs
- tests/monster_test_generated.h
+ ${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
)
set(FlatBuffers_Sample_Binary_SRCS
include/flatbuffers/flatbuffers.h
samples/sample_binary.cpp
- # file generate by running compiler on samples/monster.fbs
- samples/monster_generated.h
+ # file generated by running compiler on samples/monster.fbs
+ ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)
set(FlatBuffers_Sample_Text_SRCS
src/idl_parser.cpp
src/idl_gen_text.cpp
samples/sample_text.cpp
- # file generate by running compiler on samples/monster.fbs
- samples/monster_generated.h
+ # file generated by running compiler on samples/monster.fbs
+ ${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
)
-set(CMAKE_BUILD_TYPE Debug)
-
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
include_directories(include)
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
+
+function(compile_flatbuffers_schema_to_cpp SRC_FBS)
+ get_filename_component(SRC_FBS_DIR ${SRC_FBS} DIRECTORY)
+ string(REGEX REPLACE ".fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
+ add_custom_command(
+ OUTPUT ${GEN_HEADER}
+ COMMAND flatc -c -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
+ DEPENDS flatc)
+endfunction()
+
if(FLATBUFFERS_BUILD_TESTS)
+ compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
add_executable(flattests ${FlatBuffers_Tests_SRCS})
+
+ compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
endif()
-install(DIRECTORY include/flatbuffers DESTINATION include)
-install(TARGETS flatc DESTINATION bin)
+if(FLATBUFFERS_INSTALL)
+ install(DIRECTORY include/flatbuffers DESTINATION include)
+ install(TARGETS flatc DESTINATION bin)
+endif()
if(FLATBUFFERS_BUILD_TESTS)
- add_test(NAME flattest
- CONFIGURATIONS Debug
- WORKING_DIRECTORY tests
- COMMAND flattests)
+ enable_testing()
+
+ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+ add_test(NAME flattests COMMAND flattests)
endif()
inline const char *EnumNameAny(int e) { return EnumNamesAny()[e]; }
-bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);
+inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);
MANUALLY_ALIGNED_STRUCT(4) Vec3 {
private:
return builder_.Finish();
}
-bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
+inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
switch (type) {
case Any_NONE: return true;
case Any_Monster: return verifier.VerifyTable(reinterpret_cast<const Monster *>(union_obj));