-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmake_add_files.sh
executable file
·188 lines (154 loc) · 4.43 KB
/
cmake_add_files.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
readonly SOURCE_FILENAME=Sources.cmake
readonly HEADER_FILENAME=Headers.cmake
readonly SOURCE_MODULES_FILENAME=cmake/SourceModules.cmake
readonly HEADER_MODULES_FILENAME=cmake/HeaderModules.cmake
readonly TEST_MODULES_FILENAME=cmake/TestModules.cmake
readonly SORT_METHOD=sort
add_sources()
{
local SRC_DIR=$1
local ADD_TO_MODULE_LIST=$2
local CMAKE_VARNAME="SOURCE_LIST"
local MODULE_LIST_FILE=$SOURCE_MODULES_FILENAME
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en "set(SOURCE_MODULES\n" > $MODULE_LIST_FILE
fi
echo "Source dir is '$SRC_DIR'"
local directories=($(find $SRC_DIR -type d | grep -v "Tests"))
echo "Directory list is ${directories[*]}"
for dir in ${directories[*]}; do
cd $dir &>/dev/null
local src_files=($(find -maxdepth 1 -type f -name "*.cpp" | LC_COLLATE=C ${SORT_METHOD}))
cd - &>/dev/null
if (( ${#src_files[*]} != 0 ))
then
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en "\t""\${CMAKE_CURRENT_SOURCE_DIR}/$dir""\n" >> $MODULE_LIST_FILE
fi
local FILE=$dir/$SOURCE_FILENAME
echo "Add to $FILE:"
echo -en "set ($CMAKE_VARNAME\n"
echo -en "set ($CMAKE_VARNAME\n" > $FILE
for src_file in ${src_files[*]}; do
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${src_file:2}\n"
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${src_file:2}\n" >> $FILE;
done
echo -en ")\n"
echo -en ")\n" >> $FILE;
echo
else
if [[ -e "$dir/$SOURCE_FILENAME" ]]
then
echo Remove $dir/$SOURCE_FILENAME
rm -rf $dir/$SOURCE_FILENAME
echo
fi
fi
done
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en ")\n" >> $MODULE_LIST_FILE
fi
}
add_headers()
{
local INC_DIR=$1
local ADD_TO_MODULE_LIST=$2
local CMAKE_VARNAME="HEADER_LIST"
local MODULE_LIST_FILE=$HEADER_MODULES_FILENAME
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en "set(HEADER_MODULES\n" > $MODULE_LIST_FILE
fi
echo "Header dir is '$INC_DIR'"
local directories=($(find $INC_DIR -type d | grep -v "Tests"))
echo "Directory list is ${directories[*]}"
for dir in ${directories[*]}; do
cd $dir &>/dev/null
local inc_files=($(find -maxdepth 1 -type f -name "*.hpp" | LC_COLLATE=C ${SORT_METHOD}) $(find -maxdepth 1 -type f -name "*.h" | LC_COLLATE=C ${SORT_METHOD}))
cd - &>/dev/null
if (( ${#inc_files[*]} != 0 ))
then
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
if echo $dir | grep -v "Test"
then
echo -en "\t""\${CMAKE_CURRENT_SOURCE_DIR}/$dir""\n" >> $MODULE_LIST_FILE
fi
fi
local FILE=$dir/$HEADER_FILENAME
echo "Add to $dir/$FILE:"
echo -en "set ($CMAKE_VARNAME\n"
echo -en "set ($CMAKE_VARNAME\n" > $FILE
for inc_file in ${inc_files[*]}; do
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${inc_file:2}\n"
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${inc_file:2}\n" >> $FILE;
done
echo -en ")\n"
echo -en ")\n" >> $FILE;
else
echo Remove $dir/$HEADER_FILENAME
rm -rf $dir/$HEADER_FILENAME
fi
echo
done
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en ")\n" >> $MODULE_LIST_FILE
fi
}
add_tests()
{
local SRC_DIR=$1
local ADD_TO_MODULE_LIST=$2
local CMAKE_VARNAME="SOURCE_LIST"
local MODULE_LIST_FILE=$TEST_MODULES_FILENAME
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en "set(TEST_MODULES\n" > $MODULE_LIST_FILE
fi
echo "Source dir is '$SRC_DIR'"
local directories=($(find $SRC_DIR -type d | grep "Tests"))
echo "Directory list is ${directories[*]}"
for dir in ${directories[*]}; do
cd $dir &>/dev/null
local src_files=($(find -maxdepth 1 -type f -name "*.?pp" | LC_COLLATE=C ${SORT_METHOD}))
cd - &>/dev/null
if (( ${#src_files[*]} != 0 ))
then
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en "\t""\${CMAKE_CURRENT_SOURCE_DIR}/$dir""\n" >> $MODULE_LIST_FILE
fi
local FILE=$dir/$SOURCE_FILENAME
echo "Add to $FILE:"
echo -en "set ($CMAKE_VARNAME\n"
echo -en "set ($CMAKE_VARNAME\n" > $FILE
for src_file in ${src_files[*]}; do
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${src_file:2}\n"
echo -en "\t\${CMAKE_CURRENT_SOURCE_DIR}/${src_file:2}\n" >> $FILE;
done
echo -en ")\n"
echo -en ")\n" >> $FILE;
echo
else
if [[ -e "$dir/$SOURCE_FILENAME" ]]
then
echo Remove $dir/$SOURCE_FILENAME
rm -rf $dir/$SOURCE_FILENAME
echo
fi
fi
done
if [[ "$ADD_TO_MODULE_LIST" == "true" ]]
then
echo -en ")\n" >> $MODULE_LIST_FILE
fi
}
add_sources src false
add_headers src false
add_headers include/FlameIDE false
add_tests src false