Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 1 | #TOSA serialization library |
| 2 | |
Eric Kunze | 9d0c233 | 2023-01-04 21:31:56 +0000 | [diff] [blame] | 3 | # Copyright (c) 2020-2023, ARM Limited. |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Contains TOSA flatbuffer serialization library content. |
| 18 | |
| 19 | cmake_minimum_required(VERSION 3.13.4) |
| 20 | project(TosaSerialization) |
| 21 | |
| 22 | set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to") |
| 23 | set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 24 | |
| 25 | set(CMAKE_VERBOSE_MAKEFILE ON) |
| 26 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 27 | option(BUILD_TESTS "Build test applications" ON) |
| 28 | option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off) |
| 29 | |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 30 | include_directories(${PROJECT_SOURCE_DIR}/third_party/half/include) |
| 31 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 32 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 33 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 34 | add_library(tosa_serialization_lib |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 35 | src/tosa_serialization_handler.cpp |
| 36 | src/numpy_utils.cpp |
Kevin Cheng | 87de41f | 2021-11-03 22:09:42 -0700 | [diff] [blame] | 37 | ) |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 38 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 39 | # Verify we have a valid flatbuffers include path. |
| 40 | # We will explicitly exclude the system include directories and only |
| 41 | # accept either a user supplied value or the local third_party/flatbuffers. |
| 42 | find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h |
| 43 | NO_DEFAULT_PATH |
| 44 | HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers |
| 45 | PATH_SUFFIXES include) |
| 46 | message(STATUS "Flatbuffers include located at: ${FLATBUFFERS_INCLUDE_PATH}") |
| 47 | include_directories(${FLATBUFFERS_INCLUDE_PATH}) |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 48 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 49 | # Next is the library. |
| 50 | # We will explicitly exclude the system lib directories and only accept |
| 51 | # either a user supplied value or the local third_party/flatbuffers. |
| 52 | find_library(FLATBUFFERS_LIBRARY |
| 53 | NAMES libflatbuffers.a flatbuffers |
| 54 | NO_DEFAULT_PATH |
| 55 | HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers |
| 56 | PATH_SUFFIXES lib) |
| 57 | |
| 58 | if(FLATBUFFERS_LIBRARY) |
| 59 | message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}") |
| 60 | target_link_libraries(tosa_serialization_lib PRIVATE ${FLATBUFFERS_LIBRARY}) |
| 61 | else() |
| 62 | # It's not there we treat third_party/flatbuffers as a sub project. |
| 63 | # In this case we'll need to build the downloaded source. |
| 64 | # Turn off unnecessary flatbuffers targets |
| 65 | set(FLATBUFFERS_BUILD_TESTS OFF) |
| 66 | add_subdirectory(third_party/flatbuffers) |
| 67 | target_link_libraries(tosa_serialization_lib PRIVATE flatbuffers) |
| 68 | endif() |
| 69 | |
| 70 | set(public_headers) |
| 71 | list(APPEND public_headers |
| 72 | include/attribute.h |
| 73 | include/attribute.def |
| 74 | include/numpy_utils.h |
| 75 | include/tosa_generated.h |
| 76 | include/tosa_serialization_handler.h |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 77 | ) |
| 78 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 79 | set_target_properties(tosa_serialization_lib PROPERTIES PUBLIC_HEADER "${public_headers}") |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 80 | |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 81 | # Optionally build test executables. |
| 82 | if (BUILD_TESTS) |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 83 | add_executable(serialization_npy_test |
| 84 | test/src/serialization_npy_test.cpp |
| 85 | ) |
| 86 | |
| 87 | target_link_libraries(serialization_npy_test |
| 88 | tosa_serialization_lib |
| 89 | ) |
| 90 | endif() |
Kevin Cheng | 87de41f | 2021-11-03 22:09:42 -0700 | [diff] [blame] | 91 | |
| 92 | set(TOSA_SERIALIZATION_LIB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_serialization_lib") |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 93 | # Follow GNU packaging norms for installation directory structure. |
| 94 | include(GNUInstallDirs) |
Kevin Cheng | 87de41f | 2021-11-03 22:09:42 -0700 | [diff] [blame] | 95 | install( |
| 96 | TARGETS tosa_serialization_lib EXPORT TosaSerializationLibTargets |
Colm Donelan | 2a3ca93 | 2022-08-25 16:00:19 +0100 | [diff] [blame] | 97 | PUBLIC_HEADER |
| 98 | ARCHIVE |
Kevin Cheng | 87de41f | 2021-11-03 22:09:42 -0700 | [diff] [blame] | 99 | ) |
| 100 | |
| 101 | install(EXPORT TosaSerializationLibTargets |
| 102 | FILE TosaSerializationLibTargets.cmake |
| 103 | NAMESPACE tosa:: |
| 104 | DESTINATION ${TOSA_SERIALIZATION_LIB_CMAKE_DIR} |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 105 | ) |