blob: 87e0825aac16db561918a618046d630a18b14434 [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001#TOSA serialization library
2
Colm Donelan2a3ca932022-08-25 16:00:19 +01003# Copyright (c) 2020-2022, ARM Limited.
Eric Kunze2364dcd2021-04-26 11:06:57 -07004#
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
19cmake_minimum_required(VERSION 3.13.4)
20project(TosaSerialization)
21
22set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
23set(CMAKE_CXX_STANDARD_REQUIRED YES)
24
25set(CMAKE_VERBOSE_MAKEFILE ON)
26
Colm Donelan2a3ca932022-08-25 16:00:19 +010027option(BUILD_TESTS "Build test applications" ON)
28option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
29
Eric Kunze2364dcd2021-04-26 11:06:57 -070030include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Eric Kunze2364dcd2021-04-26 11:06:57 -070031
Colm Donelan2a3ca932022-08-25 16:00:19 +010032add_library(tosa_serialization_lib
Eric Kunze2364dcd2021-04-26 11:06:57 -070033 src/tosa_serialization_handler.cpp
34 src/numpy_utils.cpp
Kevin Cheng87de41f2021-11-03 22:09:42 -070035)
Eric Kunze2364dcd2021-04-26 11:06:57 -070036
Colm Donelan2a3ca932022-08-25 16:00:19 +010037# Verify we have a valid flatbuffers include path.
38# We will explicitly exclude the system include directories and only
39# accept either a user supplied value or the local third_party/flatbuffers.
40find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
41 NO_DEFAULT_PATH
42 HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
43 PATH_SUFFIXES include)
44message(STATUS "Flatbuffers include located at: ${FLATBUFFERS_INCLUDE_PATH}")
45include_directories(${FLATBUFFERS_INCLUDE_PATH})
Eric Kunze2364dcd2021-04-26 11:06:57 -070046
Colm Donelan2a3ca932022-08-25 16:00:19 +010047# Next is the library.
48# We will explicitly exclude the system lib directories and only accept
49# either a user supplied value or the local third_party/flatbuffers.
50find_library(FLATBUFFERS_LIBRARY
51 NAMES libflatbuffers.a flatbuffers
52 NO_DEFAULT_PATH
53 HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
54 PATH_SUFFIXES lib)
55
56if(FLATBUFFERS_LIBRARY)
57 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
58 target_link_libraries(tosa_serialization_lib PRIVATE ${FLATBUFFERS_LIBRARY})
59else()
60 # It's not there we treat third_party/flatbuffers as a sub project.
61 # In this case we'll need to build the downloaded source.
62 # Turn off unnecessary flatbuffers targets
63 set(FLATBUFFERS_BUILD_TESTS OFF)
64 add_subdirectory(third_party/flatbuffers)
65 target_link_libraries(tosa_serialization_lib PRIVATE flatbuffers)
66endif()
67
68set(public_headers)
69list(APPEND public_headers
70 include/attribute.h
71 include/attribute.def
72 include/numpy_utils.h
73 include/tosa_generated.h
74 include/tosa_serialization_handler.h
Eric Kunze2364dcd2021-04-26 11:06:57 -070075)
76
Colm Donelan2a3ca932022-08-25 16:00:19 +010077set_target_properties(tosa_serialization_lib PROPERTIES PUBLIC_HEADER "${public_headers}")
Eric Kunze2364dcd2021-04-26 11:06:57 -070078
Colm Donelan2a3ca932022-08-25 16:00:19 +010079# Optionally build test executables.
80if (BUILD_TESTS)
81 add_executable(serialization_read_write
82 test/src/serialization_read_write.cpp
83 )
Eric Kunze2364dcd2021-04-26 11:06:57 -070084
Colm Donelan2a3ca932022-08-25 16:00:19 +010085 target_link_libraries(serialization_read_write
86 tosa_serialization_lib
87 )
88
89 add_executable(serialization_npy_test
90 test/src/serialization_npy_test.cpp
91 )
92
93 target_link_libraries(serialization_npy_test
94 tosa_serialization_lib
95 )
96endif()
Kevin Cheng87de41f2021-11-03 22:09:42 -070097
98set(TOSA_SERIALIZATION_LIB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/tosa_serialization_lib")
Colm Donelan2a3ca932022-08-25 16:00:19 +010099# Follow GNU packaging norms for installation directory structure.
100include(GNUInstallDirs)
Kevin Cheng87de41f2021-11-03 22:09:42 -0700101install(
102 TARGETS tosa_serialization_lib EXPORT TosaSerializationLibTargets
Colm Donelan2a3ca932022-08-25 16:00:19 +0100103 PUBLIC_HEADER
104 ARCHIVE
Kevin Cheng87de41f2021-11-03 22:09:42 -0700105)
106
107install(EXPORT TosaSerializationLibTargets
108 FILE TosaSerializationLibTargets.cmake
109 NAMESPACE tosa::
110 DESTINATION ${TOSA_SERIALIZATION_LIB_CMAKE_DIR}
Eric Kunze2364dcd2021-04-26 11:06:57 -0700111)