summaryrefslogtreecommitdiff
path: root/cmake/IdeSplitSources.cmake
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-04-03 19:51:22 +0200
committerPatrick Steinhardt <ps@pks.im>2020-06-01 14:06:20 +0200
commitbc02bcd920eac0ca5a930a8272737db10fc4be1f (patch)
tree7bf9f6cc739d4b2127adb2704cdd3a8b9c3bdbe0 /cmake/IdeSplitSources.cmake
parent172a28860b3e4743d7ccd4409f6f51bc7c00fdfd (diff)
downloadlibgit2-bc02bcd920eac0ca5a930a8272737db10fc4be1f.tar.gz
cmake: move modules into the "cmake/" top level dir
Our custom CMake module currently live in "cmake/Modules". As the "cmake/" directory doesn't contain anything except the "Modules" directory, it doesn't really make sense to have the additional intermediate directory. So let's instead move the modules one level up into the "cmake/" top level directory.
Diffstat (limited to 'cmake/IdeSplitSources.cmake')
-rw-r--r--cmake/IdeSplitSources.cmake22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake
new file mode 100644
index 000000000..e2e09b4ce
--- /dev/null
+++ b/cmake/IdeSplitSources.cmake
@@ -0,0 +1,22 @@
+# This function splits the sources files up into their appropriate
+# subdirectories. This is especially useful for IDEs like Xcode and
+# Visual Studio, so that you can navigate into the libgit2_clar project,
+# and see the folders within the tests folder (instead of just seeing all
+# source and tests in a single folder.)
+FUNCTION(IDE_SPLIT_SOURCES target)
+ IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
+ GET_TARGET_PROPERTY(sources ${target} SOURCES)
+ FOREACH(source ${sources})
+ IF(source MATCHES ".*/")
+ STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
+ IF(rel)
+ STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
+ IF(rel)
+ STRING(REPLACE "/" "\\\\" rel ${rel})
+ SOURCE_GROUP(${rel} FILES ${source})
+ ENDIF()
+ ENDIF()
+ ENDIF()
+ ENDFOREACH()
+ ENDIF()
+ENDFUNCTION()