xref: /aosp_15_r20/external/armnn/src/armnnSerializer/CMakeLists.txt (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1#
2# Copyright © 2017, 2019-2020, 2022-2023 Arm Ltd and Contributors. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5if(BUILD_ARMNN_SERIALIZER)
6    # We're using NO_SYSTEM_ENVIRONMENT_PATH to prevent a system installed
7    # flatc being found and used.
8    find_program(FLATC flatc
9                 HINTS ${FLATC_DIR}
10                 NO_SYSTEM_ENVIRONMENT_PATH
11                 DOC "Path to 'flatc', the flatbuffers compiler")
12
13    if (NOT FLATC)
14        message(SEND_ERROR "flatc not found. Specify the full path of the flatc executable with -DFLATC=<flatc path>")
15    else()
16        message("Using flatc was from: ${FLATC}")
17    endif()
18
19    add_custom_command(
20        # Generate an ArmnnSchema_generated.h file if it doesn't exist, or update it when necessary otherwise
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
23    )
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/)
26
27    set(armnn_serializer_sources)
28    list(APPEND armnn_serializer_sources
29        ../../include/armnnSerializer/ISerializer.hpp
30        ../../include/armnnDeserializer/IDeserializer.hpp
31        Serializer.hpp
32        Serializer.cpp
33        SerializerUtils.hpp
34        SerializerUtils.cpp
35        ../armnnDeserializer/Deserializer.hpp
36        ../armnnDeserializer/Deserializer.cpp
37        )
38
39    if(BUILD_BARE_METAL OR EXECUTE_NETWORK_STATIC)
40        add_library_ex(armnnSerializer STATIC ${armnn_serializer_sources})
41    else()
42        # We're going to export both a STATIC library and a SHARED library here.
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.
45        add_library(armnnSerializer-static STATIC ${armnn_serializer_sources})
46        add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources})
47    endif()
48
49    include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
50
51    set_target_properties(armnnSerializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
52    target_include_directories(armnnSerializer PRIVATE ../armnn)
53    target_include_directories(armnnSerializer PRIVATE ../armnnUtils)
54    target_include_directories(armnnSerializer PRIVATE ../../generated)
55    if (NOT BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
56        target_include_directories(armnnSerializer-static PRIVATE ../armnn)
57        target_include_directories(armnnSerializer-static PRIVATE ../armnnUtils)
58        target_include_directories(armnnSerializer-static PRIVATE ../../generated)
59    endif()
60
61    list(APPEND armnn_serializer_sources
62        ArmnnSchema_generated.h
63        )
64
65    # System include to suppress warnings for flatbuffers generated files
66    target_include_directories(armnnSerializer SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
67
68    target_link_libraries(armnnSerializer armnn ${FLATBUFFERS_LIBRARY})
69    if (NOT BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
70        install(TARGETS armnnSerializer-static
71                EXPORT  armnn-targets
72                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
73                ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
74        )
75    endif()
76
77    install(TARGETS armnnSerializer
78            EXPORT  armnn-targets
79            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
80            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
81    )
82    set_target_properties(armnnSerializer PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
83endif()
84