-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclioninit
More file actions
executable file
·71 lines (63 loc) · 2.24 KB
/
clioninit
File metadata and controls
executable file
·71 lines (63 loc) · 2.24 KB
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
#!/usr/bin/python
#coding=utf-8
"""
为clion的初始化CMakeList.txt
到项目根目录执行该命令即可初始化CMakeList.txt
"""
#config param
cmake_version = "3.3"
source_file_type = [".h",".hpp",".c",".cc",".cpp","tcc"]
include_file_type = [".h",".hpp"]
exclude_sourse_file_name = ["thirdparty"] #避免建索引过慢,boost实在太大了
exclude_include_file_name = ["boost","memcache"]
import os
import sys
include_directories_set = set()
source_files = []
def ShouldExclude(path,issrc):
exclude_file_name = None
if issrc:
exclude_file_name = exclude_sourse_file_name
else:
exclude_file_name = exclude_include_file_name
for i in exclude_file_name:
if path.find(i) != -1:
return True
return False
def SplitDirectory(path):
retlist = path.split("/")
for i in range(2, len(retlist)+1):
include_directories_set.add("/".join(retlist[1:i]))
def ScanDirectory():
include_directories_set.add(".")
for rt, dirs, files in os.walk("."):
needInclude = False
for i in files:
if ShouldExclude(rt, True) == False:
for sft in source_file_type:
if i[-len(sft):] == sft:
source_files.append((rt + "/" + i)[2:])
break
if ShouldExclude(rt, False) == False:
for ift in include_file_type:
if i[-len(ift):] == ift:
needInclude = True
break
if needInclude:
SplitDirectory(rt)
if __name__ == "__main__":
f = open('CMakeLists.txt', 'w')
ScanDirectory()
f.write("#Init by clioninit.py\n")
f.write("cmake_minimum_required(VERSION " + cmake_version + ")\n")
f.write("project(" + os.path.basename(os.getcwd()) + ")\n\n")
f.write("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11\")\n\n")
f.write("set(SOURCE_FILES\n")
for i in source_files:
f.write(" " + i + "\n")
f.write(")\n\n")
f.write("add_executable(" + os.path.basename(os.getcwd()) + " ${SOURCE_FILES})\n")
include_directories = list(include_directories_set)
include_directories.sort()
for i in include_directories:
f.write("include_directories(" + i + ")\n")