-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvcxproj2cmake.py
193 lines (171 loc) · 7.25 KB
/
vcxproj2cmake.py
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
189
190
191
192
193
#!/usr/bin python
#-*- encoding: utf-8 -*-
# Generate CMakeLists.txt from *.vcxproj
import xml.dom.minidom
includeDirs = []
sourceFiles = []
linkDirs = []
libs = []
projectName = ""
outDir = ""
link_mysql = ""
abseil_libs = "absl::absl_check \
absl::absl_log \
absl::algorithm \
absl::base \
absl::bind_front \
absl::bits \
absl::btree \
absl::cleanup \
absl::cord \
absl::core_headers \
absl::debugging \
absl::die_if_null \
absl::dynamic_annotations \
absl::flags \
absl::flat_hash_map \
absl::flat_hash_set \
absl::function_ref \
absl::hash \
absl::layout \
absl::log_initialize \
absl::log_severity \
absl::memory \
absl::node_hash_map \
absl::node_hash_set \
absl::optional \
absl::span \
absl::status \
absl::statusor \
absl::strings \
absl::synchronization \
absl::time \
absl::type_traits \
absl::utility \
absl::variant "
# parse vcxproj file
def parseVCProjFile(vcxprojFile):
xmldoc= xml.dom.minidom.parse(vcxprojFile)
for rootNode in xmldoc.childNodes:
for subNode in rootNode.childNodes:
if subNode.nodeName == "ItemGroup":
for itemNode in subNode.childNodes:
if itemNode.nodeName == "ClCompile":
path = itemNode._attrs["Include"].value
sourceFiles.append(path.replace("\\", "/"))
if itemNode.nodeName == "ClInclude":
path = itemNode._attrs["Include"].value
index = path.rfind("\\")
includeDirs.append(path[:index+1].replace("\\", "/"))
if subNode.nodeName == "PropertyGroup":
for propertyNode in subNode.childNodes:
if propertyNode.nodeName == "RootNamespace":
global projectName
projectName = propertyNode.firstChild.data
if propertyNode.nodeName == "OutDir":
global outDir
outDir = propertyNode.firstChild.data
if subNode.nodeName == "ItemDefinitionGroup":
for defineGroup in subNode.childNodes:
for defineNode in defineGroup.childNodes:
if defineNode.nodeName == "AdditionalIncludeDirectories":
for additionInc in defineNode.firstChild.data.split(";"):
if not additionInc.startswith("%"):
includeDirs.append(additionInc)
if defineNode.nodeName == "AdditionalLibraryDirectories":
for additionLib in defineNode.firstChild.data.split(";"):
if not additionLib.startswith("%"):
linkDirs.append(additionLib)
# write cmake file
def writeCMakeLists(vcxprojDir, target_type):
# mini version
fileLines = "cmake_minimum_required(VERSION 3.28)\n"
# set flags
fileLines += "set(CMAKE_VERBOSE_MAKEFILE on)\n"
fileLines += "set(CMAKE_CXX_STANDARD 23)\n"
fileLines += "set(CMAKE_CXX_STANDARD_REQUIRED ON)\n"
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")\n'
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread ")\n\n'
if link_mysql:
fileLines += 'set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MYSQL_INCLUDE}")\n\n'
fileLines += ('set(EXECUTABLE_OUTPUT_PATH %s)\n' % outDir)
fileLines += ('set(LIBRARY_OUTPUT_PATH %s)\n' % outDir)
if link_mysql:
fileLines += 'execute_process(COMMAND mysql_config --cflags OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)\n'
fileLines += 'execute_process(COMMAND mysql_config --libs OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)\n'
fileLines += 'execute_process(COMMAND mysql_config --include OUTPUT_VARIABLE MYSQL_INCLUDE OUTPUT_STRIP_TRAILING_WHITESPACE)\n'
fileLines += ("project(%s)\n\n" % projectName)
# add define
fileLines += 'add_definitions(-D__LINUX__)\n'
fileLines += 'add_definitions(-D__linux__)\n'
fileLines += "add_definitions(-DNOMINMAX)\n"
fileLines += "add_definitions(-DGOOGLE_CHECK_EQ=ABSL_CHECK_EQ)\n"
fileLines += "add_definitions(-DGOOGLE_LOG=ABSL_DLOG)\n"
fileLines += "add_definitions(-DGOOGLE_DCHECK=ABSL_DCHECK)\n"
fileLines += "add_definitions(-DENTT_ID_TYPE=uint64_t)\n\n"
fileLines += "add_definitions(-DABSL_PROPAGATE_CXX_STD=TRUE)\n\n"
# include directory
fileLines += "include_directories("
uniqIncludeDir = list(set(includeDirs))
for incUnit in uniqIncludeDir:
fileLines += (incUnit + " ")
fileLines += ")\n\n"
# link directory
fileLines += "link_directories("
uniqLinkDir = list(set(linkDirs))
for linkUnit in uniqLinkDir:
fileLines += (linkUnit + " ")
fileLines += " /usr/lib/x86_64-linux-gnu /usr/local/lib/ )\n\n"
# source file
fileLines += "set(SOURCE_FILE "
for sourceUnit in sourceFiles:
fileLines += (sourceUnit + " ")
fileLines += ")\n\n"
# add exec or lib
if target_type == "lib":
fileLines += ("add_library(%s ${SOURCE_FILE})\n\n" % projectName)
else:
fileLines += ("add_subdirectory(../../third_party/protobuf/third_party/abseil-cpp/ ../../build)\n\n")
fileLines += ("add_executable(%s ${SOURCE_FILE})\n\n" % projectName)
# link lib
fileLines += ("target_link_libraries(%s " % projectName)
for lib in libs:
fileLines += ("%s " % lib)
fileLines += " muduo_base muduo_net muduo_protobuf_codec muduo_protorpc_wire mrediscli "
fileLines += " ${MYSQL_LIBS} protobuf hiredis lua z utf8_validity "
fileLines += abseil_libs
fileLines += " )"
if target_type == "lib":
libs.append((("%s") %projectName))
# write file
file = open(vcxprojDir + "CMakeLists.txt", "w")
file.writelines(fileLines)
file.close()
# CMakeList.txt
def generate(vcxprojfile, vcxprojDir, target_type):
global includeDirs
global sourceFiles
global linkDirs
includeDirs = []
sourceFiles = []
linkDirs = []
if not vcxprojfile.endswith(".vcxproj"):
raise NameError("vcxproj file name error")
parseVCProjFile(vcxprojfile)
writeCMakeLists(vcxprojDir, target_type)
return projectName
#link_mysql = "mysqlclient"
generate("./third_party/third_party.vcxproj", "./third_party/", "lib")
generate("./pkg/config/config.vcxproj", "./pkg/config/", "lib")
generate("./pkg/common/common.vcxproj", "./pkg/common/", "lib")
generate("./pkg/logic/logic.vcxproj", "./pkg/logic/", "lib")
generate("./pkg/pbc/pbc.vcxproj", "./pkg/pbc/", "lib")
generate("./node/controller_server/centre.vcxproj", "./node/center/", "")
generate("./node/gate/gate.vcxproj", "./node/gate/", "")
generate("./node/game/game.vcxproj", "./node/game/", "")
generate("./client/client.vcxproj", "./client/", "")