diff options
Diffstat (limited to 'cmake/modules/FindFlatBuffers.cmake')
| -rw-r--r-- | cmake/modules/FindFlatBuffers.cmake | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/cmake/modules/FindFlatBuffers.cmake b/cmake/modules/FindFlatBuffers.cmake new file mode 100644 index 0000000..6f7e6a2 --- /dev/null +++ b/cmake/modules/FindFlatBuffers.cmake | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | # FindFlatBuffers | ||
| 2 | # -------- | ||
| 3 | # Find the FlatBuffers schema compiler and headers | ||
| 4 | # | ||
| 5 | # This will define the following variables: | ||
| 6 | # | ||
| 7 | # FLATBUFFERS_FOUND - system has FlatBuffers compiler and headers | ||
| 8 | # FLATBUFFERS_FLATC_EXECUTABLE - the flatc compiler executable | ||
| 9 | # FLATBUFFERS_INCLUDE_DIRS - the FlatFuffers include directory | ||
| 10 | # FLATBUFFERS_MESSAGES_INCLUDE_DIR - the directory for generated headers | ||
| 11 | |||
| 12 | if(ENABLE_INTERNAL_FLATBUFFERS) | ||
| 13 | include(ExternalProject) | ||
| 14 | file(STRINGS ${CMAKE_SOURCE_DIR}/tools/depends/native/flatbuffers-native/Makefile VER REGEX "^[ ]*VERSION[ ]*=.+$") | ||
| 15 | string(REGEX REPLACE "^[ ]*VERSION[ ]*=[ ]*" "" FLATBUFFERS_VER "${VER}") | ||
| 16 | |||
| 17 | # Allow user to override the download URL with a local tarball | ||
| 18 | # Needed for offline build envs | ||
| 19 | if(FLATBUFFERS_URL) | ||
| 20 | get_filename_component(FLATBUFFERS_URL "${FLATBUFFERS_URL}" ABSOLUTE) | ||
| 21 | else() | ||
| 22 | set(FLATBUFFERS_URL http://mirrors.kodi.tv/build-deps/sources/flatbuffers-${FLATBUFFERS_VER}.tar.gz) | ||
| 23 | endif() | ||
| 24 | if(VERBOSE) | ||
| 25 | message(STATUS "FLATBUFFERS_URL: ${FLATBUFFERS_URL}") | ||
| 26 | endif() | ||
| 27 | |||
| 28 | set(FLATBUFFERS_FLATC_EXECUTABLE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/bin/flatc CACHE INTERNAL "FlatBuffer compiler") | ||
| 29 | set(FLATBUFFERS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/include CACHE INTERNAL "FlatBuffer include dir") | ||
| 30 | |||
| 31 | externalproject_add(flatbuffers | ||
| 32 | URL ${FLATBUFFERS_URL} | ||
| 33 | DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/download | ||
| 34 | PREFIX ${CORE_BUILD_DIR}/flatbuffers | ||
| 35 | CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} | ||
| 36 | -DCMAKE_BUILD_TYPE=Release | ||
| 37 | -DFLATBUFFERS_CODE_COVERAGE=OFF | ||
| 38 | -DFLATBUFFERS_BUILD_TESTS=OFF | ||
| 39 | -DFLATBUFFERS_INSTALL=ON | ||
| 40 | -DFLATBUFFERS_BUILD_FLATLIB=OFF | ||
| 41 | -DFLATBUFFERS_BUILD_FLATC=ON | ||
| 42 | -DFLATBUFFERS_BUILD_FLATHASH=OFF | ||
| 43 | -DFLATBUFFERS_BUILD_GRPCTEST=OFF | ||
| 44 | -DFLATBUFFERS_BUILD_SHAREDLIB=OFF | ||
| 45 | "${EXTRA_ARGS}" | ||
| 46 | PATCH_COMMAND patch -p1 < ${CORE_SOURCE_DIR}/tools/depends/native/flatbuffers-native/0001-Fix-compiler-warning.patch | ||
| 47 | BUILD_BYPRODUCTS ${FLATBUFFERS_FLATC_EXECUTABLE}) | ||
| 48 | set_target_properties(flatbuffers PROPERTIES FOLDER "External Projects" | ||
| 49 | INTERFACE_INCLUDE_DIRECTORIES ${FLATBUFFERS_INCLUDE_DIR}) | ||
| 50 | else() | ||
| 51 | find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc) | ||
| 52 | find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) | ||
| 53 | endif() | ||
| 54 | |||
| 55 | include(FindPackageHandleStandardArgs) | ||
| 56 | find_package_handle_standard_args(FlatBuffers | ||
| 57 | REQUIRED_VARS FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR | ||
| 58 | VERSION_VAR FLATBUFFERS_VER) | ||
| 59 | |||
| 60 | if(FLATBUFFERS_FOUND) | ||
| 61 | set(FLATBUFFERS_MESSAGES_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/RetroPlayer/messages CACHE INTERNAL "Generated FlatBuffer headers") | ||
| 62 | set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR} ${FLATBUFFERS_MESSAGES_INCLUDE_DIR}) | ||
| 63 | |||
| 64 | if(NOT TARGET flatbuffers) | ||
| 65 | add_library(flatbuffers UNKNOWN IMPORTED) | ||
| 66 | set_target_properties(flatbuffers PROPERTIES | ||
| 67 | FOLDER "External Projects" | ||
| 68 | INTERFACE_INCLUDE_DIRECTORIES ${FLATBUFFERS_INCLUDE_DIR}) | ||
| 69 | endif() | ||
| 70 | endif() | ||
| 71 | |||
| 72 | mark_as_advanced(FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR) | ||
