aboutsummaryrefslogtreecommitdiff
path: root/cmake/Utils.cmake
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-03-09 14:13:49 +0000
committertelsoa01 <telmo.soares@arm.com>2018-03-09 14:13:49 +0000
commit4fcda0101ec3d110c1d6d7bee5c83416b645528a (patch)
treec9a70aeb2887006160c1b3d265c27efadb7bdbae /cmake/Utils.cmake
downloadarmnn-4fcda0101ec3d110c1d6d7bee5c83416b645528a.tar.gz
Release 18.02
Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6
Diffstat (limited to 'cmake/Utils.cmake')
-rw-r--r--cmake/Utils.cmake43
1 files changed, 43 insertions, 0 deletions
diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake
new file mode 100644
index 0000000000..3a9d93a15c
--- /dev/null
+++ b/cmake/Utils.cmake
@@ -0,0 +1,43 @@
+# Function which creates appropriate "source groups" (filter folders in Visual Studio) for the given list of source files
+function(createSourceGroups source1)
+ set(sources ${source1} ${ARGN})
+ foreach(source ${sources})
+ get_filename_component(source_path ${source} PATH)
+ string(REPLACE "/" "\\" source_path_backslashes "${source_path}")
+ source_group(${source_path_backslashes} FILES ${source})
+ endforeach()
+endfunction()
+
+# Further processes a target and its list of source files adding extra touches useful for some generators
+# (filter folders, group targets in folders, etc.).
+# All optional arguments are treated as additional source files.
+function(setup_target targetName source1)
+ set(sources ${source1} ${ARGN})
+
+ createSourceGroups(${sources})
+
+ # Enable USE_FOLDERS. This is required by the set_target_properties(... FOLDER ...) call below.
+ # We prefer to set it here rather than globally at the top of the file so that we only modify
+ # the Cmake environment if/when the functionality is actually required.
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+ file(RELATIVE_PATH projectFolder ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
+ set_target_properties(${targetName} PROPERTIES FOLDER "${projectFolder}")
+endfunction()
+
+# Convenience replacement of add_executable(), which besides adding an executable to the project
+# further configures the target via setup_target().
+# All optional arguments are treated as additional source files.
+function(add_executable_ex targetName source1)
+ set(sources ${source1} ${ARGN})
+ add_executable(${targetName} ${sources})
+ setup_target(${targetName} ${sources})
+endfunction()
+
+# Convenience replacement of add_library(), which besides adding a library to the project
+# further configures the target via setup_target().
+# All optional arguments are treated as additional source files.
+function(add_library_ex targetName libraryType source1)
+ set(sources ${source1} ${ARGN})
+ add_library(${targetName} ${libraryType} ${sources})
+ setup_target(${targetName} ${sources})
+endfunction()