[PATCH] D72117: [cmake] Use source-groups in Polly

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 16:04:00 PST 2020


ctetreau created this revision.
Herald added subscribers: llvm-commits, mgorny.
Herald added a reviewer: bollu.
Herald added a project: LLVM.

- Configure CMake to setup source-groups for Polly. Source groups

describe how source files should be organized in IDEs. By default, all
headers are dumped into one folder under PollyCore and all source files
into another. On disk, these files are organized into folders, but this
isn't reflected in the IDE. This change uses CMake source groups to have
the IDE reflect the on disk layout. This will make it easier to visualize
the project structure for users of Visual Studio and XCode

Change-Id: Ifc8f0cc79850df3d88b7ed165a8554715a3a2753


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72117

Files:
  polly/cmake/polly_macros.cmake
  polly/lib/CMakeLists.txt


Index: polly/lib/CMakeLists.txt
===================================================================
--- polly/lib/CMakeLists.txt
+++ polly/lib/CMakeLists.txt
@@ -73,6 +73,17 @@
 set_target_properties(obj.Polly PROPERTIES FOLDER "Polly")
 set_target_properties(Polly PROPERTIES FOLDER "Polly")
 
+if (MSVC_IDE OR XCODE)
+  # Configure source groups for Polly source files. By default, in the IDE there
+  # will be a source and include folder. In the source folder will be all the
+  # source files in a flat list, and in the include folder will be all the
+  # headers in a flat list. Sets the CMake source_group for each folder such
+  # the organization of the sources and headers in the IDE matches how it is
+  # laid out on disk
+  setup_polly_source_groups(${CMAKE_CURRENT_LIST_DIR}
+    ${CMAKE_CURRENT_LIST_DIR}/../include/polly)
+endif()
+
 # Create the library that can be linked into LLVM's tools and Polly's unittests.
 # It depends on all library it needs, such that with
 # LLVM_POLLY_LINK_INTO_TOOLS=ON, its dependencies like PollyISL are linked as
Index: polly/cmake/polly_macros.cmake
===================================================================
--- polly/cmake/polly_macros.cmake
+++ polly/cmake/polly_macros.cmake
@@ -86,3 +86,28 @@
     endforeach()
   endif()
 endfunction()
+
+# Recursive helper for setup_source_group. Traverse the file system and add
+# source files matching the glob_expr to the prefix, recursing into
+# subdirectories as they are encountered
+function(setup_polly_source_groups_helper pwd prefix glob_expr)
+  file(GLOB children RELATIVE ${pwd} ${pwd}/*)
+  foreach(child ${children})
+    if (IS_DIRECTORY ${pwd}/${child})
+      setup_polly_source_groups_helper(${pwd}/${child}
+        "${prefix}\\${child}" ${glob_expr})
+    endif()
+  endforeach()
+
+  file(GLOB to_add ${pwd}/${glob_expr})
+  source_group(${prefix} FILES ${to_add})
+endfunction(setup_polly_source_groups_helper)
+
+# Set up source groups in order to nicely organize source files in IDEs
+macro(setup_polly_source_groups src_root hdr_root)
+  # FIXME: The helper can be eliminated if the CMake version is increased
+  # to 3.8 or higher. If this is done, the TREE version of source_group can
+  # be used
+  setup_polly_source_groups_helper(${src_root} "Source Files" "*.cpp")
+  setup_polly_source_groups_helper(${hdr_root} "Header Files" "*.h")
+endmacro(setup_polly_source_groups)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72117.235964.patch
Type: text/x-patch
Size: 2409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200103/9480b30b/attachment.bin>


More information about the llvm-commits mailing list