@@ -59,6 +59,15 @@ set(ARM_COMPUTE_SVE2_ARCH armv8.6-a+sve2+fp16+dotprod CACHE STRING "Architecture
5959set (ARM_COMPUTE_C_STANDARD 99 CACHE STRING "C Standard to use for the library." )
6060set (ARM_COMPUTE_CXX_STANDARD 14 CACHE STRING "CXX Standard to use for the library." )
6161
62+ # If this is the top-level project and the installation directory hasn't been set, set it
63+ # to be <project-root>/install/
64+ if (PROJECT_IS_TOP_LEVEL)
65+ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
66+ set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR} /install" CACHE PATH "Install path" FORCE)
67+ message (STATUS "CMAKE_INSTALL_PREFIX was not set, using default: ${CMAKE_INSTALL_PREFIX} " )
68+ endif ()
69+ endif ()
70+
6271include (${CMAKE_CURRENT_LIST_DIR} /cmake/configurations .cmake)
6372include (${CMAKE_CURRENT_LIST_DIR} /cmake/compilers/setup.cmake)
6473include (${CMAKE_CURRENT_LIST_DIR} /cmake/version .cmake)
@@ -67,12 +76,15 @@ if(ARM_COMPUTE_ENABLE_OPENMP)
6776 find_package (OpenMP REQUIRED)
6877endif ()
6978
79+ # Introduce CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_INCLUDEDIR variables
80+ include (GNUInstallDirs)
81+
7082# Set lib build type accordingly
7183if (ARM_COMPUTE_BUILD_SHARED_LIB)
72- message (STATUS "Will build the Arm Compute Library with shared libraries." )
84+ message (STATUS "Building Arm Compute Library with shared libraries." )
7385 set (ARM_COMPUTE_LIB_BUILD_TYPE SHARED)
7486else ()
75- message (STATUS "Will build the Arm Compute Library with static libraries." )
87+ message (STATUS "Building Arm Compute Library with static libraries." )
7688 set (ARM_COMPUTE_LIB_BUILD_TYPE STATIC )
7789endif ()
7890
@@ -176,12 +188,23 @@ add_library(
176188# Linking to arm_compute[_graph] should automatically bring includes and dependent libs with it
177189foreach (TARGET IN ITEMS arm_compute arm_compute_graph)
178190 target_link_libraries (${TARGET} PUBLIC ${ARM_COMPUTE_LINK_LIBS} )
179- target_include_directories (${TARGET} PUBLIC ${ARM_COMPUTE_PUBLIC_INCLUDE} )
191+ target_include_directories (${TARGET} PUBLIC
192+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} >
193+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /include >
194+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
195+ )
180196 set_target_properties (${TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} " )
181197endforeach ()
182198
199+ # Linking to this target should automatically bring includes and dependent libs with it.
183200list (APPEND ARM_COMPUTE_TARGETS arm_compute arm_compute_graph arm_compute_core arm_compute_core_fp16 arm_compute_sve arm_compute_sve2)
184201
202+ # Create an alias targets so that a user can download ArmCompute via FetchContent and
203+ # still link to ArmCompute::Core and ArmCompute::Graph. Otherwise these targets would not
204+ # be available at configure-time (as required by FetchContent)
205+ add_library (${PROJECT_NAME} ::Core ALIAS arm_compute)
206+ add_library (${PROJECT_NAME} ::Graph ALIAS arm_compute_graph)
207+
185208# Library target sources.
186209add_subdirectory (src)
187210
@@ -200,6 +223,11 @@ if(ARM_COMPUTE_BUILD_TESTING)
200223 INCLUDE_DIRECTORIES "${ARM_COMPUTE_PUBLIC_INCLUDE} ;${ARM_COMPUTE_COMMON_INCLUDE} "
201224 COMPILE_DEFINITIONS "${ARM_COMPUTE_DEFINES} "
202225 LINK_LIBRARIES "arm_compute;arm_compute_graph"
226+
227+ # Adjusted for relative location of installed arm_compute lib
228+ INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR} "
229+ BUILD_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR} "
230+ INSTALL_RPATH_USE_LINK_PATH TRUE
203231 )
204232 list (APPEND ARM_COMPUTE_TARGETS arm_compute_validation arm_compute_benchmark)
205233endif (ARM_COMPUTE_BUILD_TESTING)
@@ -217,6 +245,10 @@ if(ARM_COMPUTE_BUILD_EXAMPLES)
217245 utils/GraphUtils.cpp
218246 utils/CommonGraphOptions.cpp
219247 )
248+ target_include_directories (${test_name} PRIVATE
249+ $<BUILD_INTERFACE:${ARM_COMPUTE_PUBLIC_INCLUDE} >
250+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
251+ )
220252 endforeach ()
221253
222254 # NEON Examples
@@ -226,6 +258,10 @@ if(ARM_COMPUTE_BUILD_EXAMPLES)
226258 "examples/${test_name} .cpp"
227259 utils/Utils.cpp
228260 )
261+ target_include_directories (${test_name} PRIVATE
262+ $<BUILD_INTERFACE:${ARM_COMPUTE_PUBLIC_INCLUDE} >
263+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
264+ )
229265 endforeach ()
230266
231267 # Set common properties
@@ -262,11 +298,79 @@ set_target_properties(
262298)
263299
264300# Install libraries
265- include (GNUInstallDirs)
266301install (
267302 TARGETS
268303 ${ARM_COMPUTE_TARGETS}
304+ EXPORT ${PROJECT_NAME} Targets
269305 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
270306 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
271307 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
272308)
309+
310+ # Introduce the functions write_basic_package_version_file(...) and
311+ # configure_package_config_file(...) into the current workspace
312+ include (CMakePackageConfigHelpers)
313+
314+ # Set filenames and installation destinations
315+ set (ARM_COMPUTE_CONFIG_FILE ${PROJECT_NAME} Config.cmake)
316+ set (ARM_COMPUTE_CONFIG_VERSION_FILE ${PROJECT_NAME} ConfigVersion.cmake)
317+ set (ARM_COMPUTE_TARGETS_NAME ${PROJECT_NAME} Targets)
318+ set (ARM_COMPUTE_TARGETS_FILE "${CMAKE_CURRENT_BINARY_DIR} /${ARM_COMPUTE_TARGETS_NAME} .cmake" )
319+ set (ARM_COMPUTE_CONFIG_TEMPLATE_FILE "cmake/${ARM_COMPUTE_CONFIG_FILE} .in" )
320+ set (ARM_COMPUTE_CONFIG_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR} /${ARM_COMPUTE_CONFIG_FILE} " )
321+ set (ARM_COMPUTE_CONFIG_VERSION_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR} /${ARM_COMPUTE_CONFIG_VERSION_FILE} " )
322+ set (ARM_COMPUTE_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} " )
323+
324+ # Add all targets to the build-tree export set
325+ export (
326+ EXPORT ${PROJECT_NAME} Targets
327+ NAMESPACE ${PROJECT_NAME} ::
328+ FILE "${ARM_COMPUTE_TARGETS_FILE} "
329+ )
330+
331+ # Install the exported targets to allow other projects to find this project with find_package()
332+ install (
333+ EXPORT ${PROJECT_NAME} Targets
334+ NAMESPACE ${PROJECT_NAME} ::
335+ DESTINATION "${ARM_COMPUTE_CONFIG_INSTALL_DIR} "
336+ )
337+
338+ # Install header files
339+ # N.B. The absence of a trailing slash is *important*. Do not add one.
340+ install (
341+ DIRECTORY
342+ "${CMAKE_CURRENT_LIST_DIR} /include/"
343+ "${CMAKE_CURRENT_LIST_DIR} /arm_compute"
344+ "${CMAKE_CURRENT_LIST_DIR} /utils"
345+ "${CMAKE_CURRENT_LIST_DIR} /support"
346+ "${CMAKE_CURRENT_LIST_DIR} /third_party/kleidiai"
347+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
348+ )
349+
350+ # Install the header files from the src/ directory (only) preserving the folder structure
351+ install (
352+ DIRECTORY "${CMAKE_CURRENT_LIST_DIR} /src/"
353+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} /src"
354+ FILES_MATCHING
355+ PATTERN "*.h" PATTERN "*.hpp"
356+ )
357+
358+ # Generate the *Config.cmake file for find_package()
359+ configure_package_config_file(
360+ "${ARM_COMPUTE_CONFIG_TEMPLATE_FILE} "
361+ "${ARM_COMPUTE_CONFIG_OUTPUT_FILE} "
362+ INSTALL_DESTINATION ${ARM_COMPUTE_CONFIG_INSTALL_DIR}
363+ )
364+
365+ # Configure *ConfigVersion.cmake which exports the version info
366+ write_basic_package_version_file(
367+ "${ARM_COMPUTE_CONFIG_VERSION_OUTPUT_FILE} "
368+ VERSION ${${PROJECT_NAME} _VERSION}
369+ COMPATIBILITY AnyNewerVersion
370+ )
371+
372+ # Install the generated *Config.cmake for find_package()
373+ install (
374+ FILES "${ARM_COMPUTE_CONFIG_OUTPUT_FILE} " "${ARM_COMPUTE_CONFIG_VERSION_OUTPUT_FILE} "
375+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME}
376+ )
0 commit comments