xref: /aosp_15_r20/external/armnn/cmake/Utils.cmake (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1*89c4ff92SAndroid Build Coastguard Worker#
2*89c4ff92SAndroid Build Coastguard Worker# Copyright © 2018 Arm Ltd and Contributors. All rights reserved.
3*89c4ff92SAndroid Build Coastguard Worker# SPDX-License-Identifier: MIT
4*89c4ff92SAndroid Build Coastguard Worker#
5*89c4ff92SAndroid Build Coastguard Worker
6*89c4ff92SAndroid Build Coastguard Worker# Function which creates appropriate "source groups" (filter folders in Visual Studio) for the given list of source files
7*89c4ff92SAndroid Build Coastguard Workerfunction(createSourceGroups source1)
8*89c4ff92SAndroid Build Coastguard Worker    set(sources ${source1} ${ARGN})
9*89c4ff92SAndroid Build Coastguard Worker    foreach(source ${sources})
10*89c4ff92SAndroid Build Coastguard Worker        get_filename_component(source_path ${source} PATH)
11*89c4ff92SAndroid Build Coastguard Worker        string(REPLACE "/" "\\" source_path_backslashes "${source_path}")
12*89c4ff92SAndroid Build Coastguard Worker        source_group(${source_path_backslashes} FILES ${source})
13*89c4ff92SAndroid Build Coastguard Worker    endforeach()
14*89c4ff92SAndroid Build Coastguard Workerendfunction()
15*89c4ff92SAndroid Build Coastguard Worker
16*89c4ff92SAndroid Build Coastguard Worker# Further processes a target and its list of source files adding extra touches useful for some generators
17*89c4ff92SAndroid Build Coastguard Worker# (filter folders, group targets in folders, etc.).
18*89c4ff92SAndroid Build Coastguard Worker# All optional arguments are treated as additional source files.
19*89c4ff92SAndroid Build Coastguard Workerfunction(setup_target targetName source1)
20*89c4ff92SAndroid Build Coastguard Worker    set(sources ${source1} ${ARGN})
21*89c4ff92SAndroid Build Coastguard Worker
22*89c4ff92SAndroid Build Coastguard Worker    createSourceGroups(${sources})
23*89c4ff92SAndroid Build Coastguard Worker
24*89c4ff92SAndroid Build Coastguard Worker    # Enable USE_FOLDERS. This is required by the set_target_properties(... FOLDER ...) call below.
25*89c4ff92SAndroid Build Coastguard Worker    # We prefer to set it here rather than globally at the top of the file so that we only modify
26*89c4ff92SAndroid Build Coastguard Worker    # the Cmake environment if/when the functionality is actually required.
27*89c4ff92SAndroid Build Coastguard Worker    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
28*89c4ff92SAndroid Build Coastguard Worker    file(RELATIVE_PATH projectFolder ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
29*89c4ff92SAndroid Build Coastguard Worker    set_target_properties(${targetName} PROPERTIES FOLDER "${projectFolder}")
30*89c4ff92SAndroid Build Coastguard Workerendfunction()
31*89c4ff92SAndroid Build Coastguard Worker
32*89c4ff92SAndroid Build Coastguard Worker# Convenience replacement of add_executable(), which besides adding an executable to the project
33*89c4ff92SAndroid Build Coastguard Worker# further configures the target via setup_target().
34*89c4ff92SAndroid Build Coastguard Worker# All optional arguments are treated as additional source files.
35*89c4ff92SAndroid Build Coastguard Workerfunction(add_executable_ex targetName source1)
36*89c4ff92SAndroid Build Coastguard Worker    set(sources ${source1} ${ARGN})
37*89c4ff92SAndroid Build Coastguard Worker    add_executable(${targetName} ${sources})
38*89c4ff92SAndroid Build Coastguard Worker    setup_target(${targetName} ${sources})
39*89c4ff92SAndroid Build Coastguard Workerendfunction()
40*89c4ff92SAndroid Build Coastguard Worker
41*89c4ff92SAndroid Build Coastguard Worker# Convenience replacement of add_library(), which besides adding a library to the project
42*89c4ff92SAndroid Build Coastguard Worker# further configures the target via setup_target().
43*89c4ff92SAndroid Build Coastguard Worker# All optional arguments are treated as additional source files.
44*89c4ff92SAndroid Build Coastguard Workerfunction(add_library_ex targetName libraryType source1)
45*89c4ff92SAndroid Build Coastguard Worker    set(sources ${source1} ${ARGN})
46*89c4ff92SAndroid Build Coastguard Worker    add_library(${targetName} ${libraryType} ${sources})
47*89c4ff92SAndroid Build Coastguard Worker    setup_target(${targetName} ${sources})
48*89c4ff92SAndroid Build Coastguard Workerendfunction()
49