aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Grohmann <davide.grohmann@arm.com>2023-11-07 09:47:55 +0100
committerEric Kunze <eric.kunze@arm.com>2024-02-02 10:40:19 -0800
commitafeeb6dbbc2e98188794e08e0ed5d8e590b6f661 (patch)
treeea9e3a3b3a9e6f31b94e165b7cc1053a5b033bdd
parentbd8c5295bef8fced1ad11323cc7204c620ccd1fb (diff)
downloadserialization_lib-afeeb6dbbc2e98188794e08e0ed5d8e590b6f661.tar.gz
Allow serialization_lib to use an external flatbuffers target
Before this change the only way to build the serialization_lib was to have the flatbuffers lib pre-built before calling cmake or to allow serialization_lib to build its own flatbuffers library. This commit make sure that you can build serialization_lib as part of the cmake build that builds flatbuffers (not in advance) by checking that flatbuffers is in the TARGET list. In that case it is simply linked by the serialization_lib library. Signed-off-by: Davide Grohmann <davide.grohmann@arm.com> Change-Id: I5a9d5f263ccfb36273977d6e6a2c8083598b0afb
-rw-r--r--CMakeLists.txt61
1 files changed, 33 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d373694..ac34b75 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,35 +36,40 @@ add_library(tosa_serialization_lib
src/numpy_utils.cpp
)
-# Verify we have a valid flatbuffers include path.
-# We will explicitly exclude the system include directories and only
-# accept either a user supplied value or the local third_party/flatbuffers.
-find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
- NO_DEFAULT_PATH
- HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
- PATH_SUFFIXES include)
-message(STATUS "Flatbuffers include located at: ${FLATBUFFERS_INCLUDE_PATH}")
-include_directories(${FLATBUFFERS_INCLUDE_PATH})
-
-# Next is the library.
-# We will explicitly exclude the system lib directories and only accept
-# either a user supplied value or the local third_party/flatbuffers.
-find_library(FLATBUFFERS_LIBRARY
- NAMES libflatbuffers.a flatbuffers
- NO_DEFAULT_PATH
- HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
- PATH_SUFFIXES lib)
-
-if(FLATBUFFERS_LIBRARY)
- message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
- target_link_libraries(tosa_serialization_lib PRIVATE ${FLATBUFFERS_LIBRARY})
+# If flatbuffers is built externally just link it
+if (TARGET flatbuffers)
+ target_link_libraries(tosa_serialization_lib PRIVATE flatbuffers)
else()
- # It's not there we treat third_party/flatbuffers as a sub project.
- # In this case we'll need to build the downloaded source.
- # Turn off unnecessary flatbuffers targets
- set(FLATBUFFERS_BUILD_TESTS OFF)
- add_subdirectory(third_party/flatbuffers)
- target_link_libraries(tosa_serialization_lib PRIVATE flatbuffers)
+ # Verify we have a valid flatbuffers include path.
+ # We will explicitly exclude the system include directories and only
+ # accept either a user supplied value or the local third_party/flatbuffers.
+ find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
+ NO_DEFAULT_PATH
+ HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
+ PATH_SUFFIXES include)
+ message(STATUS "Flatbuffers include located at: ${FLATBUFFERS_INCLUDE_PATH}")
+ include_directories(${FLATBUFFERS_INCLUDE_PATH})
+
+ # Next is the library.
+ # We will explicitly exclude the system lib directories and only accept
+ # either a user supplied value or the local third_party/flatbuffers.
+ find_library(FLATBUFFERS_LIBRARY
+ NAMES libflatbuffers.a flatbuffers
+ NO_DEFAULT_PATH
+ HINTS ${FLATBUFFERS_ROOT} ./third_party/flatbuffers
+ PATH_SUFFIXES lib)
+
+ if(FLATBUFFERS_LIBRARY)
+ message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
+ target_link_libraries(tosa_serialization_lib PRIVATE ${FLATBUFFERS_LIBRARY})
+ else()
+ # It's not there we treat third_party/flatbuffers as a sub project.
+ # In this case we'll need to build the downloaded source.
+ # Turn off unnecessary flatbuffers targets
+ set(FLATBUFFERS_BUILD_TESTS OFF)
+ add_subdirectory(third_party/flatbuffers)
+ target_link_libraries(tosa_serialization_lib PRIVATE flatbuffers)
+ endif()
endif()
set(public_headers)