diff options
author | Zbigniew Mandziejewicz <shaxbee@gmail.com> | 2014-09-16 00:50:23 +0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2014-09-22 15:53:19 -0700 |
commit | 3f8700b29669855ae440ad67180742ede82b3fb2 (patch) | |
tree | d365fd9b5d961d8e3300bf46cb87fb6c8f2c8430 /CMakeLists.txt | |
parent | 048638a971204e111ce855319c575be7b4637e9e (diff) | |
download | flatbuffers-3f8700b29669855ae440ad67180742ede82b3fb2.tar.gz flatbuffers-3f8700b29669855ae440ad67180742ede82b3fb2.tar.bz2 flatbuffers-3f8700b29669855ae440ad67180742ede82b3fb2.zip |
Generate headers from spec, add option for installing targets
Change-Id: I16ddb06e887e618fa871e842054115909fbf235c
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 68bfb601..96de9a09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(FlatBuffers) # 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 @@ -26,14 +27,14 @@ set(FlatBuffers_Tests_SRCS 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 @@ -43,12 +44,10 @@ 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}) @@ -69,18 +68,35 @@ endif() 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() |