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