From 0ac58c8d14aa1a172a68f7cc297230cff0df9d84 Mon Sep 17 00:00:00 2001
From: jcarpent <jcarpent@laas.fr>
Date: Thu, 23 Apr 2015 17:14:59 +0200
Subject: [PATCH] [cmake] Add new macro to create tree of src files in IDE e.g.
 Xcode, Qt Creator, etc

---
 src/CMakeLists.txt | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4d7472d0d..5d4854d8e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,14 +1,23 @@
-MACRO (ADD_HEADERS_GROUP NAME LIST_OF_FILES)
-  SOURCE_GROUP ( "Header Files\\${NAME}" FILES ${${LIST_OF_FILES}} )
-ENDMACRO (ADD_HEADERS_GROUP) 
+MACRO(ADD_GROUP GROUP_NAME FILENAMES)
+  FOREACH(filename ${${FILENAMES}})
+    GET_FILENAME_COMPONENT(filenamePath ${filename} PATH)
+    IF(NOT (filenamePath STREQUAL ""))
+      STRING(REGEX REPLACE "/" "\\\\" filenamePath ${filenamePath}) 
+      SOURCE_GROUP("${GROUP_NAME}\\${filenamePath}" FILES ${filename})
+    ELSE()
+      SOURCE_GROUP("${GROUP_NAME}" FILES ${filename})
+    ENDIF()
+  ENDFOREACH()
+ENDMACRO(ADD_GROUP) 
 
-MACRO (ADD_HEADERS_SUB_GROUP GROUP SUB_GROUP LIST_OF_FILES)
-  SOURCE_GROUP ( "Header Files\\${GROUP}\\${SUB_GROUP}" FILES ${${LIST_OF_FILES}} )
-ENDMACRO (ADD_HEADERS_SUB_GROUP) 
+MACRO(ADD_HEADER_GROUP FILENAMES)
+  ADD_GROUP("Header Files" ${FILENAMES})
+ENDMACRO(ADD_HEADER_GROUP FILENAMES)
+
+MACRO(ADD_SOURCE_GROUP FILENAMES)
+  ADD_GROUP("Source Files" ${FILENAMES})
+ENDMACRO(ADD_SOURCE_GROUP FILENAMES)
 
-MACRO (ADD_SOURCES_GROUP NAME LIST_OF_FILES)
-  SOURCE_GROUP ( "Source Files\\${NAME}" FILES ${${LIST_OF_FILES}} )
-ENDMACRO (ADD_SOURCES_GROUP) 
 
 # ----------------------------------------------------
 # --- PYTHON -----------------------------------------
@@ -77,20 +86,12 @@ IF (UNIX )
     ADD_LIBRARY ( ${PROJECT_NAME} SHARED ${HEADERS} ${${PROJECT_NAME}_SOURCES} )
 		SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
     
-		ADD_HEADERS_GROUP ("math" ${PROJECT_NAME}_MATH_HEADERS )  
+		ADD_HEADER_GROUP(HEADERS)  
+		ADD_SOURCE_GROUP(${PROJECT_NAME}_SOURCES)  
 
     # Install target libpinocchio.so
     INSTALL(FILES
       "${CMAKE_BINARY_DIR}/src/lib${PROJECT_NAME}.so"
       DESTINATION ${CMAKE_INSTALL_LIBDIR})
 
-    ADD_HEADERS_GROUP ("tools" ${PROJECT_NAME}_TOOLS_HEADERS )
-    ADD_HEADERS_GROUP ("spatial" ${PROJECT_NAME}_SPATIAL_HEADERS )
-    ADD_HEADERS_GROUP ("multibody" ${PROJECT_NAME}_MULTIBODY_HEADERS )
-    ADD_HEADERS_SUB_GROUP ("multibody" "joint" ${PROJECT_NAME}_MULTIBODY_JOINT_HEADERS )
-    ADD_HEADERS_SUB_GROUP ("multibody" "parser" ${PROJECT_NAME}_MULTIBODY_PARSER_HEADERS )
-    ADD_HEADERS_GROUP ("algorithm" ${PROJECT_NAME}_ALGORITHM_HEADERS )
-    ADD_HEADERS_GROUP ("simulation" ${PROJECT_NAME}_SIMULATION_HEADERS )
-    ADD_HEADERS_GROUP ("python" ${PROJECT_NAME}_PYTHON_HEADERS )
-
 ENDIF ( )
-- 
GitLab