• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 Stefan.Eilemann@epfl.ch
2# Copyright 2014 Google Inc. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Find the flatbuffers schema compiler
17#
18# Output Variables:
19# * FLATBUFFERS_FLATC_EXECUTABLE the flatc compiler executable
20# * FLATBUFFERS_FOUND
21#
22# Provides:
23# * FLATBUFFERS_GENERATE_C_HEADERS(Name <files>) creates the C++ headers
24#   for the given flatbuffer schema files.
25#   Returns the header files in ${Name}_OUTPUTS
26
27set(FLATBUFFERS_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
28
29find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc)
30find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h)
31
32include(FindPackageHandleStandardArgs)
33find_package_handle_standard_args(flatbuffers
34  DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR)
35
36if(FLATBUFFERS_FOUND)
37  function(FLATBUFFERS_GENERATE_C_HEADERS Name)
38    set(FLATC_OUTPUTS)
39    foreach(FILE ${ARGN})
40      get_filename_component(FLATC_OUTPUT ${FILE} NAME_WE)
41      set(FLATC_OUTPUT
42        "${CMAKE_CURRENT_BINARY_DIR}/${FLATC_OUTPUT}_generated.h")
43      list(APPEND FLATC_OUTPUTS ${FLATC_OUTPUT})
44
45      add_custom_command(OUTPUT ${FLATC_OUTPUT}
46        COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE}
47        ARGS -c -o "${CMAKE_CURRENT_BINARY_DIR}/" ${FILE}
48        COMMENT "Building C++ header for ${FILE}"
49        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
50    endforeach()
51    set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE)
52  endfunction()
53
54  set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR})
55  include_directories(${CMAKE_BINARY_DIR})
56else()
57  set(FLATBUFFERS_INCLUDE_DIR)
58endif()
59
60include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")