-
Notifications
You must be signed in to change notification settings - Fork 47
/
ide.cmake
110 lines (101 loc) · 3.17 KB
/
ide.cmake
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright (C) 2017-2019 LAAS-CNRS, JRL AIST-CNRS, INRIA.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
function(LARGEST_COMMON_PREFIX a b prefix)
string(LENGTH ${a} len_a)
string(LENGTH ${b} len_b)
if(${len_a} LESS ${len_b})
set(len ${len_a})
else()
set(len ${len_b})
endif()
set(${prefix} "" PARENT_SCOPE)
foreach(size RANGE 1 ${len})
string(SUBSTRING ${a} 0 ${size} sub_a)
string(SUBSTRING ${b} 0 ${size} sub_b)
if(${sub_a} STREQUAL ${sub_b})
set(${prefix} ${sub_a} PARENT_SCOPE)
else()
break()
endif()
endforeach()
endfunction()
function(ADD_GROUP GROUP_NAME FILENAMES)
set(REDUCED_FILENAMES)
foreach(filename ${${FILENAMES}})
get_filename_component(filenamePath ${filename} PATH)
get_filename_component(filenameName ${filename} NAME)
string(
REGEX REPLACE
"${PROJECT_BINARY_DIR}/"
""
filenamePath
"${filenamePath}/"
)
string(
REGEX REPLACE
"${PROJECT_SOURCE_DIR}/"
""
filenamePath
"${filenamePath}/"
)
string(REGEX REPLACE "//" "/" filenamePath ${filenamePath})
list(APPEND REDUCED_FILENAMES ${filenamePath})
endforeach()
# Find the largest common prefix
list(LENGTH REDUCED_FILENAMES num_files)
math(EXPR max_id "${num_files}-1")
if(${num_files} GREATER 2)
list(GET REDUCED_FILENAMES 0 str_a)
foreach(id RANGE 1 ${max_id})
list(GET REDUCED_FILENAMES ${id} str_b)
largest_common_prefix(${str_a} ${str_b} prefix)
set(str_a ${prefix})
if("${str_a}" STREQUAL "")
break()
endif()
endforeach()
else()
set(prefix "")
endif()
foreach(id RANGE 0 ${max_id})
list(GET ${FILENAMES} ${id} filename)
list(GET REDUCED_FILENAMES ${id} filenamePath)
if(NOT ("${prefix}" STREQUAL ""))
string(REGEX REPLACE "${prefix}" "" filenamePath "${filenamePath}")
endif()
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()
endfunction(ADD_GROUP)
# ADD_HEADER_GROUP
# ----------------
#
# Add FILENAMES to "Header Files" group when using IDE Cmake Generator
#
macro(ADD_HEADER_GROUP FILENAMES)
add_group("Header Files" ${FILENAMES})
endmacro(ADD_HEADER_GROUP FILENAMES)
# ADD_SOURCE_GROUP
# ----------------
#
# Add FILENAMES to "Source Files" group when using IDE Cmake Generator
#
macro(ADD_SOURCE_GROUP FILENAMES)
add_group("Source Files" ${FILENAMES})
endmacro(ADD_SOURCE_GROUP FILENAMES)