1 function(_ARMCompute_Import)
2 include(FindPackageHandleStandardArgs)
4 list(APPEND ARMCompute_LIB_SEARCH_PATHS ${ARMCompute_PREFIX})
6 find_path(INCLUDE_DIR NAMES arm_compute/core/ITensor.h PATHS ${ARMCompute_INCLUDE_SEARCH_PATHS})
8 find_library(CORE_LIBRARY NAMES arm_compute_core PATHS ${ARMCompute_LIB_SEARCH_PATHS} CMAKE_FIND_ROOT_PATH_BOTH)
9 find_library(RUNTIME_LIBRARY NAMES arm_compute PATHS ${ARMCompute_LIB_SEARCH_PATHS} CMAKE_FIND_ROOT_PATH_BOTH)
10 find_library(GRAPH_LIBRARY NAMES arm_compute_graph PATHS ${ARMCompute_LIB_SEARCH_PATHS} CMAKE_FIND_ROOT_PATH_BOTH)
12 message(STATUS "Search acl in ${ARMCompute_LIB_SEARCH_PATHS}")
15 nnas_find_package(ARMComputeSource QUIET)
16 if (NOT ARMComputeSource_FOUND)
17 set(ARMCompute_FOUND FALSE PARENT_SCOPE)
20 set(INCLUDE_DIR ${ARMComputeSource_DIR} ${ARMComputeSource_DIR}/include)
21 endif(NOT INCLUDE_DIR)
24 set(ARMCompute_FOUND FALSE PARENT_SCOPE)
25 message(STATUS "Cannot find libarm_compute_core.so")
29 if(NOT RUNTIME_LIBRARY)
30 message(STATUS "Cannot find libarm_compute.so")
31 set(ARMCompute_FOUND FALSE PARENT_SCOPE)
36 message(STATUS "Cannot find libarm_compute_graph.so")
37 set(ARMCompute_FOUND FALSE PARENT_SCOPE)
41 if(NOT TARGET arm_compute_core)
42 add_library(arm_compute_core INTERFACE)
43 target_include_directories(arm_compute_core SYSTEM INTERFACE ${INCLUDE_DIR})
44 target_link_libraries(arm_compute_core INTERFACE dl ${LIB_PTHREAD})
45 target_link_libraries(arm_compute_core INTERFACE ${CORE_LIBRARY})
46 endif(NOT TARGET arm_compute_core)
48 if(NOT TARGET arm_compute)
49 add_library(arm_compute INTERFACE)
50 target_include_directories(arm_compute SYSTEM INTERFACE ${INCLUDE_DIR})
51 target_link_libraries(arm_compute INTERFACE ${RUNTIME_LIBRARY})
52 target_link_libraries(arm_compute INTERFACE arm_compute_core)
53 endif(NOT TARGET arm_compute)
55 if(NOT TARGET arm_compute_graph)
56 add_library(arm_compute_graph INTERFACE)
57 target_include_directories(arm_compute_graph SYSTEM INTERFACE ${INCLUDE_DIR})
58 target_link_libraries(arm_compute_graph INTERFACE ${GRAPH_LIBRARY})
59 target_link_libraries(arm_compute_graph INTERFACE arm_compute)
60 endif(NOT TARGET arm_compute_graph)
62 set(ARMCompute_FOUND TRUE PARENT_SCOPE)
63 endfunction(_ARMCompute_Import)
65 ### Check whether library exists
66 function(_ARMCompute_Check VAR LIBDIR)
69 if(NOT EXISTS "${LIBDIR}/libarm_compute_core.so")
73 if(NOT EXISTS "${LIBDIR}/libarm_compute.so")
77 if(NOT EXISTS "${LIBDIR}/libarm_compute_graph.so")
81 set(${VAR} ${FOUND} PARENT_SCOPE)
82 endfunction(_ARMCompute_Check)
84 # Let's build and install ARMCompute libraries
85 # NOTE This function silently returns on error
86 function(_ARMCompute_Build ARMCompute_INSTALL_PREFIX)
87 ### Check whether library exists
88 _ARMCompute_Check(ARMCompute_FOUND ${ARMCompute_INSTALL_PREFIX})
92 endif(ARMCompute_FOUND)
94 ### Let's build with SCONS
95 nnas_find_package(ARMComputeSource QUIET)
97 if(NOT ARMComputeSource_FOUND)
99 endif(NOT ARMComputeSource_FOUND)
101 find_program(SCONS_PATH scons)
104 message(WARNING "SCONS NOT FOUND. Please install SCONS to build ARMCompute.")
106 endif(NOT SCONS_PATH)
109 string(TOLOWER "${CMAKE_BUILD_TYPE}" SCON_BUILD_TYPE)
110 else(CMAKE_BUILD_TYPE)
111 set(SCON_BUILD_TYPE "release")
112 endif(CMAKE_BUILD_TYPE)
114 #### Architecture-specific configurations
115 if(TARGET_ARCH STREQUAL "armv7l")
116 set(BUILD_ARCH "armv7a")
117 set(BUILD_DIR "${BUILD_ARCH}-${TARGET_OS}.${SCON_BUILD_TYPE}")
120 if(TARGET_ARCH STREQUAL "aarch64")
121 set(BUILD_ARCH "arm64-v8a")
122 set(BUILD_DIR "${BUILD_ARCH}-${TARGET_OS}.${SCON_BUILD_TYPE}")
125 #### Platform-specific configurations
126 #### TODO Support android
128 #### Mode-specific configurations
129 if(SCON_BUILD_TYPE STREQUAL "debug")
130 list(APPEND SCONS_OPTIONS "debug=1")
133 #### Generic configurations
134 list(APPEND SCONS_OPTIONS "neon=1")
135 list(APPEND SCONS_OPTIONS "opencl=1")
136 list(APPEND SCONS_OPTIONS "examples=0")
137 list(APPEND SCONS_OPTIONS "Werror=0")
138 list(APPEND SCONS_OPTIONS "os=${TARGET_OS}")
140 if(DEFINED ACL_BUILD_THREADS)
141 set(N ${ACL_BUILD_THREADS})
142 else(DEFINED ACL_BUILD_THREADS)
143 include(ProcessorCount)
145 endif(DEFINED ACL_BUILD_THREADS)
147 if((NOT N EQUAL 0) AND BUILD_EXT_MULTITHREAD)
148 list(APPEND SCONS_OPTIONS -j${N})
150 if(DEFINED BUILD_ARCH)
151 list(APPEND SCONS_OPTIONS "arch=${BUILD_ARCH}")
152 endif(DEFINED BUILD_ARCH)
154 if(DEFINED BUILD_DIR)
155 list(APPEND SCONS_OPTIONS "build_dir=${BUILD_DIR}")
156 endif(DEFINED BUILD_DIR)
158 message(STATUS "Build ARMCompute with ${SCONS_PATH} ('${SCONS_OPTIONS}'")
160 # Build ARMCompute libraries with SCONS
161 # NOTE ARMCompute SConstruct unconditioanlly appends "arm-linux-gnueabihf-" prefix for linux
162 execute_process(COMMAND /usr/bin/env CC=gcc CXX=g++ "${SCONS_PATH}" ${SCONS_OPTIONS}
163 WORKING_DIRECTORY ${ARMComputeSource_DIR}
164 RESULT_VARIABLE ARMCompute_BUILD)
166 # Install ARMCompute libraries to overlay
167 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${ARMCompute_INSTALL_PREFIX}"
168 WORKING_DIRECTORY ${ARMComputeSource_DIR}
169 RESULT_VARIABLE ARMCompute_BUILD)
170 execute_process(COMMAND ${CMAKE_COMMAND} -E copy "build/${BUILD_DIR}/libarm_compute_core.so" "${ARMCompute_INSTALL_PREFIX}"
171 COMMAND ${CMAKE_COMMAND} -E copy "build/${BUILD_DIR}/libarm_compute.so" "${ARMCompute_INSTALL_PREFIX}"
172 COMMAND ${CMAKE_COMMAND} -E copy "build/${BUILD_DIR}/libarm_compute_graph.so" "${ARMCompute_INSTALL_PREFIX}"
173 WORKING_DIRECTORY ${ARMComputeSource_DIR}
174 RESULT_VARIABLE ARMCompute_BUILD)
175 endfunction(_ARMCompute_Build)
177 set(ARMCompute_PREFIX ${EXT_OVERLAY_DIR}/lib)
179 _ARMCompute_Build("${ARMCompute_PREFIX}")
180 endif(BUILD_ARMCOMPUTE)