1# 2# Copyright 2021 The TensorFlow Authors. 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# https://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# Builds the flatc compiler separately (e.g. for the purposes of TF Lite kernel tests cross-compilation 17# during which a natively compiled 'flatc' binary is required. 18 19cmake_minimum_required(VERSION 3.16) 20project(flatc C CXX) 21 22# Incorporate the tflite CMake modules into the CMAKE_MODULE_PATH 23get_filename_component(TFLITE_NATIVE_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) 24get_filename_component(TFLITE_CMAKE_DIR ${TFLITE_NATIVE_TOOLS_DIR} DIRECTORY) 25set(TFLITE_CMAKE_MODULE_PATH ${TFLITE_CMAKE_DIR}/modules) 26 27list(APPEND CMAKE_MODULE_PATH ${TFLITE_CMAKE_MODULE_PATH}) 28list(APPEND CMAKE_PREFIX_PATH ${TFLITE_CMAKE_MODULE_PATH}) 29 30include(OverridableFetchContent) 31 32set(FLATC_EXCLUDE_FROM_ALL FALSE) 33 34# Install location of a (native) flatc compiler might be determined using the CMAKE_INSTALL_PREFIX variable. 35# If the user provides such location, the path gets cached during the first CMake run and used later 36# (for details see flatbuffers.cmake configuration). 37if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 38 set(FLATC_INSTALL_PREFIX <INSTALL_DIR> CACHE PATH "Flatc installation directory") 39else() 40 set(FLATC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Flatc installation directory") 41endif() 42 43find_package(flatbuffers) 44