2014-01-28 00:52:49 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
project(FlatBuffers)
|
|
|
|
|
|
|
|
# NOTE: Code coverage only works on Linux & OSX.
|
|
|
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
2014-09-10 23:01:13 +00:00
|
|
|
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
2014-09-15 16:50:23 +00:00
|
|
|
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
2015-01-02 12:51:31 +00:00
|
|
|
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" ON)
|
|
|
|
|
|
|
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
|
|
|
message(WARNING
|
|
|
|
"Cannot build tests without building the compiler. Tests will be disabled.")
|
|
|
|
set(FLATBUFFERS_BUILD_TESTS OFF)
|
|
|
|
endif()
|
2014-01-28 00:52:49 +00:00
|
|
|
|
|
|
|
set(FlatBuffers_Compiler_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
include/flatbuffers/idl.h
|
|
|
|
include/flatbuffers/util.h
|
|
|
|
src/idl_parser.cpp
|
|
|
|
src/idl_gen_cpp.cpp
|
2014-09-17 00:37:17 +00:00
|
|
|
src/idl_gen_general.cpp
|
2014-07-11 23:12:35 +00:00
|
|
|
src/idl_gen_go.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
src/idl_gen_text.cpp
|
2014-09-26 23:46:30 +00:00
|
|
|
src/idl_gen_fbs.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
src/flatc.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
set(FlatBuffers_Tests_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
include/flatbuffers/idl.h
|
|
|
|
include/flatbuffers/util.h
|
|
|
|
src/idl_parser.cpp
|
|
|
|
src/idl_gen_text.cpp
|
2014-09-26 23:46:30 +00:00
|
|
|
src/idl_gen_fbs.cpp
|
2014-01-28 00:52:49 +00:00
|
|
|
tests/test.cpp
|
|
|
|
# file generate by running compiler on tests/monster_test.fbs
|
2014-09-15 16:50:23 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
set(FlatBuffers_Sample_Binary_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
samples/sample_binary.cpp
|
2014-09-15 16:50:23 +00:00
|
|
|
# file generated by running compiler on samples/monster.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
set(FlatBuffers_Sample_Text_SRCS
|
|
|
|
include/flatbuffers/flatbuffers.h
|
|
|
|
include/flatbuffers/idl.h
|
|
|
|
include/flatbuffers/util.h
|
|
|
|
src/idl_parser.cpp
|
|
|
|
src/idl_gen_text.cpp
|
|
|
|
samples/sample_text.cpp
|
2014-09-15 16:50:23 +00:00
|
|
|
# file generated by running compiler on samples/monster.fbs
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
2014-01-28 00:52:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
|
|
|
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
|
|
|
|
2014-07-26 11:12:56 +00:00
|
|
|
if(APPLE)
|
2014-08-25 17:42:38 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra")
|
2014-07-26 11:12:56 +00:00
|
|
|
elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2014-08-25 17:42:38 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra")
|
2014-01-28 00:52:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FLATBUFFERS_CODE_COVERAGE)
|
2014-07-26 11:12:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
2014-07-29 17:29:38 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
2014-01-28 00:52:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
include_directories(include)
|
|
|
|
|
2015-01-02 12:51:31 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATC)
|
2014-01-28 00:52:49 +00:00
|
|
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
2015-01-02 12:51:31 +00:00
|
|
|
endif()
|
2014-09-15 16:50:23 +00:00
|
|
|
|
|
|
|
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
2014-10-24 21:26:29 +00:00
|
|
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
2014-09-23 18:55:42 +00:00
|
|
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
2014-09-15 16:50:23 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_HEADER}
|
|
|
|
COMMAND flatc -c -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
|
|
|
DEPENDS flatc)
|
|
|
|
endfunction()
|
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
if(FLATBUFFERS_BUILD_TESTS)
|
2014-09-15 16:50:23 +00:00
|
|
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
2014-09-15 16:50:23 +00:00
|
|
|
|
|
|
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
2014-09-10 23:01:13 +00:00
|
|
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
|
|
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
|
|
|
endif()
|
2014-01-28 00:52:49 +00:00
|
|
|
|
2014-09-15 16:50:23 +00:00
|
|
|
if(FLATBUFFERS_INSTALL)
|
|
|
|
install(DIRECTORY include/flatbuffers DESTINATION include)
|
2015-01-02 12:51:31 +00:00
|
|
|
if(FLATBUFFERS_BUILD_FLATC)
|
|
|
|
install(TARGETS flatc DESTINATION bin)
|
|
|
|
endif()
|
2014-09-15 16:50:23 +00:00
|
|
|
endif()
|
2014-07-15 13:09:36 +00:00
|
|
|
|
2014-09-10 23:01:13 +00:00
|
|
|
if(FLATBUFFERS_BUILD_TESTS)
|
2014-09-15 16:50:23 +00:00
|
|
|
enable_testing()
|
|
|
|
|
2014-09-23 18:55:42 +00:00
|
|
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2014-09-15 16:50:23 +00:00
|
|
|
add_test(NAME flattests COMMAND flattests)
|
2014-09-10 23:01:13 +00:00
|
|
|
endif()
|