From eac4adb5bf493ba7d1b00ef6ecd6b56a42ea3f3d Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Tue, 25 Aug 2020 13:05:59 +0100 Subject: Export Armnn cmake Change-Id: I3c317e835aba5feafda240393ca26b6aebe8d655 Signed-off-by: Derek Lamberti --- CMakeLists.txt | 92 +++++++++++++++++++++++++---- cmake/ArmnnConfig.cmake.in | 20 +++++++ cmake/GlobalConfig.cmake | 4 +- profiling/common/src/CMakeLists.txt | 7 +++ src/armnnSerializer/CMakeLists.txt | 5 +- src/backends/reference/RefLayerSupport.cpp | 2 +- src/profiling/PeriodicCounterCapture.cpp | 2 +- src/profiling/backends/BackendProfiling.cpp | 2 +- 8 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 cmake/ArmnnConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2f331a09..3eb2e78e8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,11 +567,17 @@ add_library_ex(armnn SHARED ${armnn_sources}) target_compile_definitions(armnn PRIVATE "ARMNN_COMPILING_DLL") -target_include_directories(armnn PRIVATE src/armnn) -target_include_directories(armnn PRIVATE src/armnnUtils) -target_include_directories(armnn PRIVATE src/backends) -target_include_directories(armnn PRIVATE src/profiling) -target_include_directories(armnn PRIVATE profiling/common/include) +target_include_directories(armnn + PUBLIC + $ + $ + PRIVATE + src/armnn + src/armnnUtils + src/backends + src/profiling + profiling/common/include +) target_link_libraries(armnn armnnUtils pipeCommon) @@ -580,9 +586,6 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL Windows) target_link_libraries(armnn Ws2_32.lib) endif() -install(TARGETS armnn - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(BUILD_CAFFE_PARSER) install(TARGETS armnnCaffeParser LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -601,9 +604,11 @@ endif() install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -target_link_libraries(armnn ${Boost_THREAD_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ${Boost_SYSTEM_LIBRARY}) +target_link_libraries(armnn + ${Boost_THREAD_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${Boost_FILESYSTEM_LIBRARY} + ) if(ARMCOMPUTENEON OR ARMCOMPUTECL) target_link_libraries(armnn ${ARMCOMPUTE_LIBRARIES}) @@ -1027,7 +1032,7 @@ if (BUILD_ARMNN_SERIALIZER AND (BUILD_TF_PARSER OR BUILD_TF_LITE_PARSER OR BUILD ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY}) addDllCopyCommands(ArmnnConverter) - endif() +endif() if(BUILD_BASE_PIPE_SERVER) add_subdirectory(profiling/server/src/basePipeServer) @@ -1101,6 +1106,67 @@ if(BUILD_GATORD_MOCK) endif() +#################################################### +# export targets +set(armnn_export_targets) +list(APPEND armnn_export_targets + armnn + armnnUtils +) + +install( + TARGETS ${armnn_export_targets} + EXPORT armnn-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +#################################################### +## Set export alias +set_target_properties(armnn + PROPERTIES + EXPORT_NAME Armnn +) + +## Export target scrips +install( + EXPORT armnn-targets + FILE ArmnnTargets.cmake + NAMESPACE Armnn:: + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +#################################################### +## Create ArmnnConfig.cmake +include(CMakePackageConfigHelpers) +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}) + +message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" ) +message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" ) +configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/ArmnnConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/ArmnnConfig.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} +) + +#################################################### +## Install Armnn config file +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/ArmnnConfig.cmake + DESTINATION ${INSTALL_CONFIGDIR} +) + +#################################################### +## Export from build tree +export( + EXPORT armnn-targets + FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnTargets.cmake + NAMESPACE Armnn:: +) + +#################################################### +## Build Python bindings if (BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC) add_subdirectory(python/pyarmnn) -endif() +endif() \ No newline at end of file diff --git a/cmake/ArmnnConfig.cmake.in b/cmake/ArmnnConfig.cmake.in new file mode 100644 index 0000000000..1e572fea1d --- /dev/null +++ b/cmake/ArmnnConfig.cmake.in @@ -0,0 +1,20 @@ + +get_filename_component(ARMNN_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) +set(ARMNN_CONFIG_FILE ${CMAKE_CURRENT_LIST_FILE}) +MESSAGE(STATUS "Found Armnn: ${ARMNN_CONFIG_FILE}") + +include(CMakeFindDependencyMacro) + +list(APPEND CMAKE_MODULE_PATH ${ARMNN_CMAKE_DIR}) + +add_definitions("-DBOOST_ALL_NO_LIB") +find_package(Boost 1.59 REQUIRED COMPONENTS system filesystem program_options) +include_directories(SYSTEM "${Boost_INCLUDE_DIRS}") +link_directories(${Boost_LIBRARY_DIRS}) + +if(NOT TARGET Armnn::Armnn) + MESSAGE(STATUS "Armnn Import: ${ARMNN_CMAKE_DIR}/ArmnnTargets.cmake") + include("${ARMNN_CMAKE_DIR}/ArmnnTargets.cmake") +endif() + +set(ARMNN_LIBRARIES Armnn::Armnn) \ No newline at end of file diff --git a/cmake/GlobalConfig.cmake b/cmake/GlobalConfig.cmake index b093e5d527..cc44efdd0b 100644 --- a/cmake/GlobalConfig.cmake +++ b/cmake/GlobalConfig.cmake @@ -123,6 +123,8 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) +include(CMakeFindDependencyMacro) + if (NOT BUILD_PIPE_ONLY) # Boost message(STATUS "Finding Boost") @@ -151,7 +153,7 @@ if (NOT BUILD_PIPE_ONLY) endif() # pthread -find_package (Threads) +find_dependency(Threads) # Favour the protobuf passed on command line if(BUILD_TF_PARSER OR BUILD_CAFFE_PARSER OR BUILD_ONNX_PARSER) diff --git a/profiling/common/src/CMakeLists.txt b/profiling/common/src/CMakeLists.txt index 9505fb8869..3a27a53f8e 100644 --- a/profiling/common/src/CMakeLists.txt +++ b/profiling/common/src/CMakeLists.txt @@ -27,4 +27,11 @@ if(BUILD_TIMELINE_DECODER) # to simplify the build. No extra .so file to deploy to boards etc. add_library_ex(pipeCommon STATIC ${pipeCommon_sources}) + # install the target + install( + TARGETS pipeCommon + EXPORT armnn-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) endif() diff --git a/src/armnnSerializer/CMakeLists.txt b/src/armnnSerializer/CMakeLists.txt index ccc924e641..9c90af2e11 100755 --- a/src/armnnSerializer/CMakeLists.txt +++ b/src/armnnSerializer/CMakeLists.txt @@ -42,6 +42,9 @@ if(BUILD_ARMNN_SERIALIZER) target_link_libraries(armnnSerializer armnn ${FLATBUFFERS_LIBRARY}) install(TARGETS armnnSerializer - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + EXPORT armnn-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) set_target_properties(armnnSerializer PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) endif() diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index f6c214e2c6..5e3c96d31d 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -1916,7 +1916,7 @@ bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, "Reference splitter: output type not supported"); - for (const TensorInfo output : outputs) + for (const TensorInfo& output : outputs) { supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, "Reference splitter: input type not supported"); diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp index 8ff5e7e049..d914e85cfb 100644 --- a/src/profiling/PeriodicCounterCapture.cpp +++ b/src/profiling/PeriodicCounterCapture.cpp @@ -59,7 +59,7 @@ void PeriodicCounterCapture::DispatchPeriodicCounterCapturePacket( const armnn::BackendId& backendId, const std::vector& timestampValues) { // Report counter values - for (const auto timestampInfo : timestampValues) + for (const auto& timestampInfo : timestampValues) { std::vector backendCounterValues = timestampInfo.counterValues; for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) diff --git a/src/profiling/backends/BackendProfiling.cpp b/src/profiling/backends/BackendProfiling.cpp index 4e6de93062..135174b478 100644 --- a/src/profiling/backends/BackendProfiling.cpp +++ b/src/profiling/backends/BackendProfiling.cpp @@ -32,7 +32,7 @@ IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator() void BackendProfiling::ReportCounters(const std::vector& timestamps) { - for (const auto timestampInfo : timestamps) + for (const auto& timestampInfo : timestamps) { std::vector backendCounterValues = timestampInfo.counterValues; for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) -- cgit v1.2.1