Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 1 | # |
Ryan OShea | b554054 | 2022-07-06 09:52:52 +0100 | [diff] [blame] | 2 | # Copyright © 2017, 2019-2020, 2022-2023 Arm Ltd and Contributors. All rights reserved. |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | if(BUILD_ARMNN_SERIALIZER) |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 6 | # We're using NO_SYSTEM_ENVIRONMENT_PATH to prevent a system installed |
| 7 | # flatc being found and used. |
Matthew Bentham | 6894718 | 2019-06-10 17:11:31 +0100 | [diff] [blame] | 8 | find_program(FLATC flatc |
| 9 | HINTS ${FLATC_DIR} |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 10 | NO_SYSTEM_ENVIRONMENT_PATH |
Matthew Bentham | 6894718 | 2019-06-10 17:11:31 +0100 | [diff] [blame] | 11 | DOC "Path to 'flatc', the flatbuffers compiler") |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 12 | |
Matthew Bentham | 6894718 | 2019-06-10 17:11:31 +0100 | [diff] [blame] | 13 | if (NOT FLATC) |
| 14 | message(SEND_ERROR "flatc not found. Specify the full path of the flatc executable with -DFLATC=<flatc path>") |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 15 | else() |
| 16 | message("Using flatc was from: ${FLATC}") |
Matthew Bentham | 6894718 | 2019-06-10 17:11:31 +0100 | [diff] [blame] | 17 | endif() |
| 18 | |
Matteo Martincigh | 286080f | 2019-05-31 13:02:11 +0100 | [diff] [blame] | 19 | add_custom_command( |
| 20 | # Generate an ArmnnSchema_generated.h file if it doesn't exist, or update it when necessary otherwise |
Mike Kelly | f74937e | 2022-05-20 17:18:59 +0100 | [diff] [blame] | 21 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/../../generated/ArmnnSchema_generated.h DEPENDS ArmnnSchema.fbs |
| 22 | COMMAND ${FLATC} -o ${CMAKE_CURRENT_SOURCE_DIR}/../../generated --cpp ${CMAKE_CURRENT_SOURCE_DIR}/ArmnnSchema.fbs |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 23 | ) |
Mike Kelly | f74937e | 2022-05-20 17:18:59 +0100 | [diff] [blame] | 24 | set_property(SOURCE Serializer.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../generated/ArmnnSchema_generated.h) |
| 25 | set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../generated/) |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 26 | |
| 27 | set(armnn_serializer_sources) |
| 28 | list(APPEND armnn_serializer_sources |
| 29 | ../../include/armnnSerializer/ISerializer.hpp |
| 30 | ../../include/armnnDeserializer/IDeserializer.hpp |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 31 | Serializer.hpp |
| 32 | Serializer.cpp |
| 33 | SerializerUtils.hpp |
| 34 | SerializerUtils.cpp |
| 35 | ../armnnDeserializer/Deserializer.hpp |
| 36 | ../armnnDeserializer/Deserializer.cpp |
| 37 | ) |
| 38 | |
Ryan OShea | a3dc95e | 2023-03-20 11:10:40 +0000 | [diff] [blame] | 39 | include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}") |
| 40 | |
| 41 | if(BUILD_SHARED_LIBS) |
Francis Murtagh | cb223b7 | 2022-12-13 17:21:55 +0000 | [diff] [blame] | 42 | # We're going to export both a STATIC library and a SHARED library here. |
Sadik Armagan | 8f397a1 | 2022-06-17 15:38:22 +0100 | [diff] [blame] | 43 | # In some instances it's easier to include the serializer directly into |
| 44 | # the target executable or library rather than have yet another .so. |
Francis Murtagh | cb223b7 | 2022-12-13 17:21:55 +0000 | [diff] [blame] | 45 | add_library(armnnSerializer-static STATIC ${armnn_serializer_sources}) |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 46 | add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources}) |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 47 | |
Ryan OShea | b554054 | 2022-07-06 09:52:52 +0100 | [diff] [blame] | 48 | target_include_directories(armnnSerializer-static PRIVATE ../armnn) |
| 49 | target_include_directories(armnnSerializer-static PRIVATE ../armnnUtils) |
| 50 | target_include_directories(armnnSerializer-static PRIVATE ../../generated) |
Ryan OShea | a3dc95e | 2023-03-20 11:10:40 +0000 | [diff] [blame] | 51 | |
| 52 | set_target_properties(armnnSerializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 53 | set_target_properties(armnnSerializer-static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 54 | else() |
| 55 | add_library_ex(armnnSerializer STATIC ${armnn_serializer_sources}) |
| 56 | set_target_properties(armnnSerializer PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
Ryan OShea | b554054 | 2022-07-06 09:52:52 +0100 | [diff] [blame] | 57 | endif() |
Mike Kelly | f74937e | 2022-05-20 17:18:59 +0100 | [diff] [blame] | 58 | |
Ryan OShea | a3dc95e | 2023-03-20 11:10:40 +0000 | [diff] [blame] | 59 | target_include_directories(armnnSerializer PRIVATE ../armnn) |
| 60 | target_include_directories(armnnSerializer PRIVATE ../armnnUtils) |
| 61 | target_include_directories(armnnSerializer PRIVATE ../../generated) |
| 62 | |
Mike Kelly | f74937e | 2022-05-20 17:18:59 +0100 | [diff] [blame] | 63 | list(APPEND armnn_serializer_sources |
| 64 | ArmnnSchema_generated.h |
| 65 | ) |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 66 | |
| 67 | # System include to suppress warnings for flatbuffers generated files |
| 68 | target_include_directories(armnnSerializer SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 69 | |
| 70 | target_link_libraries(armnnSerializer armnn ${FLATBUFFERS_LIBRARY}) |
Ryan OShea | a3dc95e | 2023-03-20 11:10:40 +0000 | [diff] [blame] | 71 | if (BUILD_SHARED_LIBS) |
Ryan OShea | b554054 | 2022-07-06 09:52:52 +0100 | [diff] [blame] | 72 | install(TARGETS armnnSerializer-static |
| 73 | EXPORT armnn-targets |
| 74 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 75 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 76 | ) |
| 77 | endif() |
Sadik Armagan | 8f397a1 | 2022-06-17 15:38:22 +0100 | [diff] [blame] | 78 | |
Matthew Bentham | a7b7928 | 2019-06-03 13:00:50 +0100 | [diff] [blame] | 79 | install(TARGETS armnnSerializer |
Derek Lamberti | eac4adb | 2020-08-25 13:05:59 +0100 | [diff] [blame] | 80 | EXPORT armnn-targets |
| 81 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 82 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 83 | ) |
Matteo Martincigh | bccc345 | 2019-10-18 14:59:19 +0100 | [diff] [blame] | 84 | set_target_properties(armnnSerializer PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) |
Matthew Bentham | a7b7928 | 2019-06-03 13:00:50 +0100 | [diff] [blame] | 85 | endif() |