forked from pavelliavonau/cmakeconverter
/
flags.py
239 lines (212 loc) · 13 KB
/
flags.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# -*- coding: utf-8 -*-
import os
import ntpath as path
import message as msg
class Flags(object):
def __init__(self, data):
self.tree = data['vcxproj']['tree']
self.ns = data['vcxproj']['ns']
self.cmake = data['cmake']
self.win_deb_flags = ''
self.win_rel_flags = ''
def write_flags(self):
self.cmake.write('################# Flags ################\n'
'# Defines Flags for Windows and Linux. #\n'
'########################################\n\n')
self.define_win_flags()
self.define_lin_flags()
def define_lin_flags(self):
# Define FLAGS for Linux compiler
linux_flags = '-std=c++11'
# TODO recast this part to "set_target_properties" in class: dependencies
# references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns)
# if references:
# for ref in references:
# reference = str(ref.get('Include'))
# lib = os.path.splitext(path.basename(reference))[0]
# if (lib == 'lemon' or lib == 'zlib') and '-fPIC' not in linux_flags:
# linux_flags += ' -fPIC'
self.cmake.write('if(NOT MSVC)\n')
self.cmake.write(' set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ' + linux_flags + '")\n')
self.cmake.write(' if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")\n')
self.cmake.write(' set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")\n')
self.cmake.write(' endif()\n')
self.cmake.write('endif(NOT MSVC)\n\n')
def define_win_flags(self):
# Warning
warning = self.tree.xpath('//ns:WarningLevel', namespaces=self.ns)[0]
if warning.text != '':
lvl = ' /W' + warning.text[-1:]
self.win_deb_flags += lvl
self.win_rel_flags += lvl
msg.send('Warning : ' + warning.text, 'ok')
else:
msg.send('No Warning level.', '')
""" PropertyGroup """
prop_deb_x86 = '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'"]'
prop_deb_x64 = '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|x64\'"]'
prop_rel_x86 = '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|Win32\'"]'
prop_rel_x64 = '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|x64\'"]'
# WholeProgramOptimization
gl_debug_x86 = self.tree.find(prop_deb_x86 + '/ns:WholeProgramOptimization', namespaces=self.ns)
gl_debug_x64 = self.tree.find(prop_deb_x64 + '/ns:WholeProgramOptimization', namespaces=self.ns)
if gl_debug_x86 is not None and gl_debug_x64 is not None:
if 'true' in gl_debug_x86.text and 'true' in gl_debug_x64.text:
self.win_deb_flags += ' /GL'
msg.send('WholeProgramOptimization for Debug', 'ok')
else:
msg.send('No WholeProgramOptimization for Debug', '')
gl_release_x86 = self.tree.find(prop_rel_x86 + '/ns:WholeProgramOptimization', namespaces=self.ns)
gl_release_x64 = self.tree.find(prop_rel_x64 + '/ns:WholeProgramOptimization', namespaces=self.ns)
if gl_release_x86 is not None and gl_release_x64 is not None:
if 'true' in gl_release_x86.text and 'true' in gl_release_x64.text:
self.win_rel_flags += ' /GL'
msg.send('WholeProgramOptimization for Release', 'ok')
else:
msg.send('No WholeProgramOptimization for Release', '')
# UseDebugLibraries
md_debug_x86 = self.tree.find(prop_deb_x86 + '/ns:UseDebugLibraries', namespaces=self.ns)
md_debug_x64 = self.tree.find(prop_deb_x64 + '/ns:UseDebugLibraries', namespaces=self.ns)
if md_debug_x64 is not None and md_debug_x86 is not None:
if 'true' in md_debug_x86.text and 'true' in md_debug_x64.text:
self.win_deb_flags += ' /MD'
msg.send('UseDebugLibrairies for Debug', 'ok')
else:
msg.send('No UseDebugLibrairies for Debug', '')
md_release_x86 = self.tree.find(prop_rel_x86 + '/ns:UseDebugLibraries', namespaces=self.ns)
md_release_x64 = self.tree.find(prop_rel_x64 + '/ns:UseDebugLibraries', namespaces=self.ns)
if md_release_x86 is not None and md_release_x64 is not None:
if 'true' in md_release_x86.text and 'true' in md_release_x64.text:
self.win_rel_flags += ' /MD'
msg.send('UseDebugLibrairies for Release', 'ok')
else:
msg.send('No UseDebugLibrairies for Release', '')
""" ItemDefinitionGroup """
item_deb_x86 = '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'"]'
item_deb_x64 = '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|x64\'"]'
item_rel_x86 = '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|Win32\'"]'
item_rel_x64 = '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Release|x64\'"]'
# RuntimeLibrary
mdd_debug_x86 = self.tree.find(item_deb_x86 + '/ns:ClCompile/ns:RuntimeLibrary', namespaces=self.ns)
mdd_debug_x64 = self.tree.find(item_deb_x64 + '/ns:ClCompile/ns:RuntimeLibrary', namespaces=self.ns)
if mdd_debug_x64 is not None and mdd_debug_x86 is not None:
if 'MultiThreadedDebugDLL' in mdd_debug_x86.text and 'MultiThreadedDebugDLL' in mdd_debug_x64.text:
self.win_deb_flags += ' /MDd'
msg.send('RuntimeLibrary for Debug', 'ok')
else:
msg.send('No RuntimeLibrary for Debug', '')
mdd_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:RuntimeLibrary', namespaces=self.ns)
mdd_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:RuntimeLibrary', namespaces=self.ns)
if mdd_release_x86 is not None and mdd_release_x64 is not None:
if 'MultiThreadedDebugDLL' in mdd_release_x86.text and 'MultiThreadedDebugDLL' in mdd_release_x64.text:
self.win_rel_flags += ' /MDd'
msg.send('RuntimeLibrary for Release', 'ok')
else:
msg.send('No RuntimeLibrary for Release', '')
# Optimization
opt_debug_x86 = self.tree.find(item_deb_x86 + '/ns:ClCompile/ns:Optimization', namespaces=self.ns)
opt_debug_x64 = self.tree.find(item_deb_x64 + '/ns:ClCompile/ns:Optimization', namespaces=self.ns)
if opt_debug_x86 is not None and opt_debug_x64 is not None:
if 'Disabled' in opt_debug_x64.text and 'Disabled' in opt_debug_x86.text:
self.win_deb_flags += ' /Od'
msg.send('Optimization for Debug', 'ok')
else:
msg.send('No Optimization for Debug', '')
opt_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:Optimization', namespaces=self.ns)
opt_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:Optimization', namespaces=self.ns)
if opt_release_x86 is not None and opt_release_x64 is not None:
if 'MaxSpeed' in opt_release_x64.text and 'MaxSpeed' in opt_release_x86.text:
self.win_rel_flags += ' /Od'
msg.send('Optimization for Release', 'ok')
else:
msg.send('No Optimization for Release', '')
# IntrinsicFunctions
oi_debug_x86 = self.tree.find(item_deb_x86 + '/ns:ClCompile/ns:IntrinsicFunctions', namespaces=self.ns)
oi_debug_x64 = self.tree.find(item_deb_x64 + '/ns:ClCompile/ns:IntrinsicFunctions', namespaces=self.ns)
if oi_debug_x86 is not None and oi_debug_x64 is not None:
if 'true' in oi_debug_x86.text and 'true' in oi_debug_x64.text:
self.win_deb_flags += ' /Oi'
msg.send('IntrinsicFunctions for Debug', 'ok')
else:
msg.send('No IntrinsicFunctions for Debug', '')
oi_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:IntrinsicFunctions', namespaces=self.ns)
oi_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:IntrinsicFunctions', namespaces=self.ns)
if oi_release_x86 is not None and oi_release_x64 is not None:
if 'true' in oi_release_x86.text and 'true' in oi_release_x64.text:
self.win_rel_flags += ' /Oi'
msg.send('IntrinsicFunctions for Release', 'ok')
else:
msg.send('No IntrinsicFunctions for Release', '')
# RuntimeTypeInfo
gr_debug_x86 = self.tree.find(item_deb_x86 + '/ns:ClCompile/ns:RuntimeTypeInfo', namespaces=self.ns)
gr_debug_x64 = self.tree.find(item_deb_x64 + '/ns:ClCompile/ns:RuntimeTypeInfo', namespaces=self.ns)
if gr_debug_x64 is not None and gr_debug_x86 is not None:
if 'true' in gr_debug_x64.text and gr_debug_x86.text:
self.win_deb_flags += ' /GR'
msg.send('RuntimeTypeInfo for Debug', 'ok')
else:
msg.send('No RuntimeTypeInfo for Debug', '')
gr_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:RuntimeTypeInfo', namespaces=self.ns)
gr_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:RuntimeTypeInfo', namespaces=self.ns)
if gr_release_x86 is not None and gr_release_x64 is not None:
if 'true' in gr_release_x64.text and gr_release_x86.text:
self.win_rel_flags += ' /GR'
msg.send('RuntimeTypeInfo for Release', 'ok')
else:
msg.send('No RuntimeTypeInfo for Release', '')
# FunctionLevelLinking
gy_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:FunctionLevelLinking', namespaces=self.ns)
gy_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:FunctionLevelLinking', namespaces=self.ns)
if gy_release_x86 is not None and gy_release_x64 is not None:
if 'true' in gy_release_x86.text and 'true' in gy_release_x64.text:
self.win_rel_flags += ' /Gy'
msg.send('FunctionLevelLinking for release.', 'ok')
else:
msg.send('No FunctionLevelLinking for release.', '')
# GenerateDebugInformation
zi_debug_x86 = self.tree.find(item_deb_x86 + '/ns:Link/ns:GenerateDebugInformation', namespaces=self.ns)
zi_debug_x64 = self.tree.find(item_deb_x64 + '/ns:Link/ns:GenerateDebugInformation', namespaces=self.ns)
if zi_debug_x86 is not None and zi_debug_x64 is not None:
if 'true' in zi_debug_x86.text and zi_debug_x64.text:
self.win_deb_flags += ' /Zi'
msg.send('GenerateDebugInformation for debug.', 'ok')
else:
msg.send('No GenerateDebugInformation for debug.', '')
zi_release_x86 = self.tree.find(item_rel_x86 + '/ns:Link/ns:GenerateDebugInformation', namespaces=self.ns)
zi_release_x64 = self.tree.find(item_rel_x64 + '/ns:Link/ns:GenerateDebugInformation', namespaces=self.ns)
if zi_release_x86 is not None and zi_release_x64 is not None:
if 'true' in zi_release_x86.text and zi_release_x64.text:
self.win_rel_flags += ' /Zi'
msg.send('GenerateDebugInformation for release.', 'ok')
else:
msg.send('No GenerateDebugInformation for release.', '')
# ExceptionHandling
ehs_debug_x86 = self.tree.find(item_deb_x86 + '/ns:ClCompile/ns:ExceptionHandling', namespaces=self.ns)
ehs_debug_x64 = self.tree.find(item_deb_x64 + '/ns:ClCompile/ns:ExceptionHandling', namespaces=self.ns)
if ehs_debug_x86 is not None and ehs_debug_x64 is not None:
if 'false' in ehs_debug_x86.text and ehs_debug_x64.text:
msg.send('No ExceptionHandling for debug.', '')
else:
self.win_deb_flags += ' /EHsc'
msg.send('ExceptionHandling for debug.', 'ok')
ehs_release_x86 = self.tree.find(item_rel_x86 + '/ns:ClCompile/ns:ExceptionHandling', namespaces=self.ns)
ehs_release_x64 = self.tree.find(item_rel_x64 + '/ns:ClCompile/ns:ExceptionHandling', namespaces=self.ns)
if ehs_release_x86 is not None and ehs_release_x64 is not None:
if 'false' in ehs_release_x86.text and ehs_release_x64.text:
msg.send('No ExceptionHandling option for release.', '')
else:
self.win_rel_flags += ' /EHsc'
msg.send('ExceptionHandling for release.', 'ok')
# Define FLAGS for Windows
self.cmake.write('if(MSVC)\n')
if self.win_deb_flags != '':
msg.send('Debug FLAGS found = ' + self.win_deb_flags, 'ok')
self.cmake.write(' set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}' + self.win_deb_flags + '")\n')
else:
msg.send('No Debug FLAGS found', '')
if self.win_rel_flags != '':
msg.send('Release FLAGS found = ' + self.win_rel_flags, 'ok')
self.cmake.write(' set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}' + self.win_rel_flags + '")\n')
else:
msg.send('No Release FLAGS found', '')
self.cmake.write('endif(MSVC)\n')