@@ -59,6 +59,15 @@ set(ARM_COMPUTE_SVE2_ARCH armv8.6-a+sve2+fp16+dotprod CACHE STRING "Architecture
59
59
set (ARM_COMPUTE_C_STANDARD 99 CACHE STRING "C Standard to use for the library." )
60
60
set (ARM_COMPUTE_CXX_STANDARD 14 CACHE STRING "CXX Standard to use for the library." )
61
61
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
+
62
71
include (${CMAKE_CURRENT_LIST_DIR} /cmake/configurations.cmake )
63
72
include (${CMAKE_CURRENT_LIST_DIR} /cmake/compilers/setup.cmake )
64
73
include (${CMAKE_CURRENT_LIST_DIR} /cmake/version.cmake )
@@ -67,12 +76,15 @@ if(ARM_COMPUTE_ENABLE_OPENMP)
67
76
find_package (OpenMP REQUIRED )
68
77
endif ()
69
78
79
+ # Introduce CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_INCLUDEDIR variables
80
+ include (GNUInstallDirs )
81
+
70
82
# Set lib build type accordingly
71
83
if (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." )
73
85
set (ARM_COMPUTE_LIB_BUILD_TYPE SHARED )
74
86
else ()
75
- message (STATUS "Will build the Arm Compute Library with static libraries." )
87
+ message (STATUS "Building Arm Compute Library with static libraries." )
76
88
set (ARM_COMPUTE_LIB_BUILD_TYPE STATIC )
77
89
endif ()
78
90
@@ -176,12 +188,23 @@ add_library(
176
188
# Linking to arm_compute[_graph] should automatically bring includes and dependent libs with it
177
189
foreach (TARGET IN ITEMS arm_compute arm_compute_graph )
178
190
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
+ )
180
196
set_target_properties (${TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} " )
181
197
endforeach ()
182
198
199
+ # Linking to this target should automatically bring includes and dependent libs with it.
183
200
list (APPEND ARM_COMPUTE_TARGETS arm_compute arm_compute_graph arm_compute_core arm_compute_core_fp16 arm_compute_sve arm_compute_sve2 )
184
201
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
+
185
208
# Library target sources.
186
209
add_subdirectory (src )
187
210
@@ -200,6 +223,11 @@ if(ARM_COMPUTE_BUILD_TESTING)
200
223
INCLUDE_DIRECTORIES "${ARM_COMPUTE_PUBLIC_INCLUDE} ;${ARM_COMPUTE_COMMON_INCLUDE} "
201
224
COMPILE_DEFINITIONS "${ARM_COMPUTE_DEFINES} "
202
225
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
203
231
)
204
232
list (APPEND ARM_COMPUTE_TARGETS arm_compute_validation arm_compute_benchmark )
205
233
endif (ARM_COMPUTE_BUILD_TESTING )
@@ -217,6 +245,10 @@ if(ARM_COMPUTE_BUILD_EXAMPLES)
217
245
utils/GraphUtils.cpp
218
246
utils/CommonGraphOptions.cpp
219
247
)
248
+ target_include_directories (${test_name} PRIVATE
249
+ $< BUILD_INTERFACE:${ARM_COMPUTE_PUBLIC_INCLUDE} >
250
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
251
+ )
220
252
endforeach ()
221
253
222
254
# NEON Examples
@@ -226,6 +258,10 @@ if(ARM_COMPUTE_BUILD_EXAMPLES)
226
258
"examples/${test_name} .cpp"
227
259
utils/Utils.cpp
228
260
)
261
+ target_include_directories (${test_name} PRIVATE
262
+ $< BUILD_INTERFACE:${ARM_COMPUTE_PUBLIC_INCLUDE} >
263
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
264
+ )
229
265
endforeach ()
230
266
231
267
# Set common properties
@@ -262,11 +298,79 @@ set_target_properties(
262
298
)
263
299
264
300
# Install libraries
265
- include (GNUInstallDirs )
266
301
install (
267
302
TARGETS
268
303
${ARM_COMPUTE_TARGETS}
304
+ EXPORT ${PROJECT_NAME} Targets
269
305
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
270
306
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
271
307
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
272
308
)
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