File: functions.cmake

package info (click to toggle)
odil 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 5,092 kB
  • sloc: cpp: 54,080; python: 3,896; xml: 182; makefile: 94
file content (32 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Group files by their folder
macro(GroupFiles fileGroup)
    # Beautify fileGroup (HEADER_FILES -> Header Files)
    string(REPLACE "_" " " fileGroupName ${fileGroup})	# Replace underscores with spaces
    string(TOLOWER ${fileGroupName} fileGroupName)		# To lower
    set(finalFileGroupName)
    string(REGEX MATCHALL "([^ ]+)" fileGroupNameSplit ${fileGroupName}) # Split each word
    foreach(fileGroupNameWord ${fileGroupNameSplit})	# Set to upper the first letter of each word
        string(SUBSTRING ${fileGroupNameWord} 0 1 firstLetter)
        string(SUBSTRING ${fileGroupNameWord} 1 -1 otherLetters)
        string(TOUPPER ${firstLetter} firstLetter)
        if(finalFileGroupName)
            set(finalFileGroupName "${finalFileGroupName} ")
        endif()
        set(finalFileGroupName "${finalFileGroupName}${firstLetter}${otherLetters}")
    endforeach()

    # Put each file in the correct group
    foreach(currentFile ${${fileGroup}})
        set(folder ${currentFile})
        get_filename_component(filename ${folder} NAME) # Get the file name
        string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" folder ${folder})	# Get the folder relative to the current one
        string(REPLACE "${filename}" "" folder ${folder})					# Remove the file name
        set(groupName "${finalFileGroupName}")
        if(NOT folder STREQUAL "") # Parse the remaining directories hierarchy
            string(REGEX REPLACE "/+$" "" baseFolder ${folder}) # Remove trailing slash
            string(REPLACE "/" "\\" baseFolder ${baseFolder})	# Forward to backward slashes
            set(groupName "${groupName}\\${baseFolder}")		# Put together the entire group name
        endif()
        source_group("${groupName}" FILES ${currentFile})		# Put the file in this group
    endforeach()
endmacro()