[Bf-blender-cvs] [22b705d2cbe] master: Cmake: Add `WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS` option

mano-wii noreply at git.blender.org
Sat Jun 15 20:46:47 CEST 2019


Commit: 22b705d2cbe7fd12a181c6db096fb8d84b5c2240
Author: mano-wii
Date:   Sat Jun 15 15:44:47 2019 -0300
Branches: master
https://developer.blender.org/rB22b705d2cbe7fd12a181c6db096fb8d84b5c2240

Cmake: Add `WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS` option

This allows grouping files in a filter corresponding to the source files name.

Differential Revision: https://developer.blender.org/D5077

===================================================================

M	CMakeLists.txt
M	build_files/cmake/macros.cmake

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 177b88874e2..314bf520c7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -561,6 +561,9 @@ if(WIN32)
   option(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS "Organize the visual studio projects according to source folder structure." ON)
   mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS)
 
+  option(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS "Organize the source files in filters matching the source folders." ON)
+  mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS)
+
   option(WINDOWS_PYTHON_DEBUG "Include the files needed for debugging python scripts with visual studio 2017+." OFF)
   mark_as_advanced(WINDOWS_PYTHON_DEBUG)
 endif()
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 71bf7811135..4a03243af4e 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -173,23 +173,36 @@ function(blender_source_group
   sources
   )
 
-  # Group by location on disk
-  source_group("Source Files" FILES CMakeLists.txt)
-
-  foreach(_SRC ${sources})
-    get_filename_component(_SRC_EXT ${_SRC} LAST_EXT)
-    if((${_SRC_EXT} MATCHES ".h") OR
-       (${_SRC_EXT} MATCHES ".hpp") OR
-       (${_SRC_EXT} MATCHES ".hh"))
-
-      set(GROUP_ID "Header Files")
-    elseif(${_SRC_EXT} MATCHES ".glsl")
-      set(GROUP_ID "Shaders")
-    else()
-      set(GROUP_ID "Source Files")
-    endif()
-    source_group("${GROUP_ID}" FILES ${_SRC})
-  endforeach()
+  #if enabled, use the sources directories as filters.
+  if(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS)
+    foreach(_SRC ${sources})
+      # remove ../'s
+      get_filename_component(_SRC_DIR ${_SRC} REALPATH)
+      get_filename_component(_SRC_DIR ${_SRC_DIR} DIRECTORY)
+      if(${_SRC_DIR} MATCHES "${CMAKE_CURRENT_SOURCE_DIR}/")
+        string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" GROUP_ID ${_SRC_DIR})
+        string(REPLACE "/" "\\" GROUP_ID ${GROUP_ID})
+        source_group("${GROUP_ID}" FILES ${_SRC})
+      endif()
+    endforeach()
+  else()
+    # Group by location on disk
+    source_group("Source Files" FILES CMakeLists.txt)
+    foreach(_SRC ${sources})
+      get_filename_component(_SRC_EXT ${_SRC} LAST_EXT)
+      if((${_SRC_EXT} MATCHES ".h") OR
+         (${_SRC_EXT} MATCHES ".hpp") OR
+         (${_SRC_EXT} MATCHES ".hh"))
+
+        set(GROUP_ID "Header Files")
+      elseif(${_SRC_EXT} MATCHES ".glsl")
+        set(GROUP_ID "Shaders")
+      else()
+        set(GROUP_ID "Source Files")
+      endif()
+      source_group("${GROUP_ID}" FILES ${_SRC})
+    endforeach()
+  endif()
 endfunction()



More information about the Bf-blender-cvs mailing list