diff options
author | Edward Thomson <ethomson@github.com> | 2017-02-05 08:08:21 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2017-02-05 08:08:21 -0500 |
commit | e78aafe83a66da72f213a78c46e197b0214e052f (patch) | |
tree | d661115bbd958d99fe9e3e56b2d572a027292430 | |
parent | 76be185108b60f53670fc4f8b67f0e2aa522d7c6 (diff) | |
download | libgit2-ethomson/cmake_object_library.tar.gz |
cmake: break out the ugly split sources fnethomson/cmake_object_library
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/Modules/IdeSplitSources.cmake | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bfcdd3f3..10d128000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ INCLUDE(CheckStructHasMember) INCLUDE(AddCFlagIfSupported) INCLUDE(FindPkgConfig) INCLUDE(FindStatNsec) +INCLUDE(IdeSplitSources) # Build options # diff --git a/cmake/Modules/IdeSplitSources.cmake b/cmake/Modules/IdeSplitSources.cmake new file mode 100644 index 000000000..3a4a531a5 --- /dev/null +++ b/cmake/Modules/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 git2_tests 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 ${CMAKE_CURRENT_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() |