[CMAKE/VS]
authorAmine Khaldi <amine.khaldi@reactos.org>
Wed, 28 Aug 2013 21:37:54 +0000 (21:37 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Wed, 28 Aug 2013 21:37:54 +0000 (21:37 +0000)
* Introduce the support for organizing the solution into a hierarchy of folders that matches our codebase layout.
* You can enable this feature by adding -DUSE_FOLDER_STRUCTURE=1 to your configure phase (the VSSolution one).
* Based on a patch by Yuntian Zhang with my improvements.
CORE-7412

svn path=/trunk/; revision=59860

reactos/cmake/CMakeMacros.cmake
reactos/cmake/msvc.cmake

index 63a99ce..e1fec95 100644 (file)
@@ -345,6 +345,32 @@ if(NOT MSVC_IDE)
         _add_executable(${name} ${ARGN})
         add_clean_target(${name})
     endfunction()
+elseif(USE_FOLDER_STRUCTURE)
+    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+    string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
+
+    function(add_custom_target name)
+        _add_custom_target(${name} ${ARGN})
+        string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
+        set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
+    endfunction()
+
+    function(add_library name)
+        _add_library(${name} ${ARGN})
+        get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
+        if(_target_excluded AND ${name} MATCHES "^lib.*")
+            set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
+        else()
+            string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
+            set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
+        endif()
+    endfunction()
+
+    function(add_executable name)
+        _add_executable(${name} ${ARGN})
+        string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
+        set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
+    endfunction()
 endif()
 
 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
index 24c9875..f0c0014 100644 (file)
@@ -45,6 +45,9 @@ endif()
 
 if(MSVC_IDE)
     add_compile_flags("/MP")
+    if(NOT DEFINED USE_FOLDER_STRUCTURE)
+        set(USE_FOLDER_STRUCTURE FALSE)
+    endif()
 endif()
 
 if(${_MACHINE_ARCH_FLAG} MATCHES X86)