aboutsummaryrefslogtreecommitdiff
path: root/cmake/macros/GroupSources.cmake
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2015-03-29 16:13:22 +0200
committerNaios <naios-dev@live.de>2015-03-29 16:13:22 +0200
commited4722b6e6314e9dce920fe90138dc714c734251 (patch)
tree86be10038d4b7f565dd316835f34e2be574e4f6a /cmake/macros/GroupSources.cmake
parent83bbe00785a7ee7c8141d83bfe94a1415466c64d (diff)
CMake: Use source_groups to represent the source tree
* It let ide's (like vs) display the source tree. * Disabled by default. * Soft requirement is cmake >= 2.8.12 . * Offers 2 modes: flat & hierarchical. * For detailed description see #14471 * Thanks @click for help and advises. * Closes #14471 (cherry picked from commit c386711972260aa7b877cdc8cb49d24576ce1902) Conflicts: src/server/authserver/CMakeLists.txt
Diffstat (limited to 'cmake/macros/GroupSources.cmake')
-rw-r--r--cmake/macros/GroupSources.cmake46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmake/macros/GroupSources.cmake b/cmake/macros/GroupSources.cmake
new file mode 100644
index 00000000000..3acb03e7b4c
--- /dev/null
+++ b/cmake/macros/GroupSources.cmake
@@ -0,0 +1,46 @@
+# Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+macro(GroupSources dir)
+ # Skip this if WITH_SOURCE_TREE is not set (empty string).
+ if (NOT ${_WITH_SOURCE_TREE} STREQUAL "")
+ # Include all header and c files
+ file(GLOB_RECURSE elements RELATIVE ${dir} *.h *.hpp *.c *.cpp *.cc)
+
+ foreach(element ${elements})
+ # Extract filename and directory
+ get_filename_component(element_name ${element} NAME)
+ get_filename_component(element_dir ${element} DIRECTORY)
+
+ if (NOT ${element_dir} STREQUAL "")
+ # If the file is in a subdirectory use it as source group.
+ if (${_WITH_SOURCE_TREE} STREQUAL "flat")
+ # Build flat structure by using only the first subdirectory.
+ string(FIND ${element_dir} "/" delemiter_pos)
+ if (NOT ${delemiter_pos} EQUAL -1)
+ string(SUBSTRING ${element_dir} 0 ${delemiter_pos} group_name)
+ source_group("${group_name}" FILES ${dir}/${element})
+ else()
+ # Build hierarchical structure.
+ # File is in root directory.
+ source_group("${element_dir}" FILES ${dir}/${element})
+ endif()
+ else()
+ # Use the full hierarchical structure to build source_groups.
+ string(REPLACE "/" "\\" group_name ${element_dir})
+ source_group("${group_name}" FILES ${dir}/${element})
+ endif()
+ else()
+ # If the file is in the root directory, place it in the root source_group.
+ source_group("\\" FILES ${dir}/${element})
+ endif()
+ endforeach()
+ endif()
+endmacro()