aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Grohmann <davide.grohmann@arm.com>2023-11-07 09:47:55 +0100
committerDavide Grohmann <davide.grohmann@arm.com>2023-11-07 10:28:36 +0100
commitaac878345685413ca85e2d4d941406cf98386921 (patch)
tree7cb42d11066f5b0878ec8053da5392d4dfaf4850
parent4881c29247d4b411de446b13d9bd58ea93737aac (diff)
downloadserialization_lib-aac878345685413ca85e2d4d941406cf98386921.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)