| 1 |
Import('defenv') |
| 2 |
print("Using Microsoft tools configuration (%s)" % defenv.get('MSVS_VERSION','<Default>')) |
| 3 |
|
| 4 |
### flags |
| 5 |
|
| 6 |
import SCons |
| 7 |
if SCons.__version__ == '1.3.0': |
| 8 |
# workaround for http://scons.tigris.org/issues/show_bug.cgi?id=2614 |
| 9 |
# force inclusion of Platform SDK, sometimes ignored by SCons 1.3.0 due to environment contamination |
| 10 |
defenv.Tool('mssdk') |
| 11 |
|
| 12 |
def entry(x,u): |
| 13 |
if x == 'WinMain' and u: |
| 14 |
x = 'w' + x |
| 15 |
return '/entry:' + x |
| 16 |
|
| 17 |
defenv['ENTRY_FLAG'] = entry |
| 18 |
defenv['MAP_FLAG'] = '/map' |
| 19 |
defenv['NODEFLIBS_FLAG'] = '/NODEFAULTLIB' |
| 20 |
defenv['C_FLAG'] = '/TC' |
| 21 |
defenv['CPP_FLAG'] = '/TP' |
| 22 |
defenv['CPP_REQUIRES_STDLIB'] = 0 |
| 23 |
defenv['SUBSYS_CON'] = '/subsystem:console' |
| 24 |
defenv['SUBSYS_WIN'] = '/subsystem:windows' |
| 25 |
defenv['MSVCRT_FLAG'] = '/MD' |
| 26 |
defenv['MSVCRT_NEEDSMANIFEST'] = False |
| 27 |
defenv['STDCALL'] = '__stdcall' |
| 28 |
|
| 29 |
msvs_version = float(defenv['MSVS_VERSION'].replace('Exp','')) |
| 30 |
if msvs_version >= 8.0: |
| 31 |
defenv['EXCEPTION_FLAG'] = '/EHsc' |
| 32 |
defenv.Append(CCFLAGS = ['/GS-']) |
| 33 |
defenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS', '_CRT_SECURE_NO_DEPRECATE', '_CRT_NON_CONFORMING_SWPRINTFS']) |
| 34 |
defenv['MSVCRT_FLAG'] = '/MT' # Avoid msvcr?0.dll dependency |
| 35 |
else: |
| 36 |
defenv['EXCEPTION_FLAG'] = '/GX' |
| 37 |
if msvs_version < 10.0: |
| 38 |
# not even /ALIGN:512 works for vc10... fails to load process |
| 39 |
defenv.Append(LINKFLAGS = ['/opt:nowin98']) |
| 40 |
if defenv['MSTOOLKIT'] and msvs_version < 8.0: |
| 41 |
defenv['MSVCRT_FLAG'] = '/ML' # TK2003 does not have all libs |
| 42 |
if msvs_version >= 11.0: |
| 43 |
defenv['SUBSYS_CON'] = '/subsystem:console,5.01' # support windows xp |
| 44 |
defenv['SUBSYS_WIN'] = '/subsystem:windows,5.01' # support windows xp |
| 45 |
|
| 46 |
def setoptimizeflags(env): |
| 47 |
if not env['DEBUG']: |
| 48 |
env.Append(CCFLAGS = ['/Gy']) |
| 49 |
env.Append(LINKFLAGS = ['/OPT:REF']) |
| 50 |
env.Append(LINKFLAGS = ['/OPT:ICF,9']) |
| 51 |
#if msvs_version >= 7.0: |
| 52 |
# env.Append(CCFLAGS = ['/GL']) # FIXME: Creates problems with memset in VS v8.0 (CL v14.00) |
| 53 |
# env.Append(LINKFLAGS = ['/LTCG']) |
| 54 |
return |
| 55 |
|
| 56 |
### defines |
| 57 |
|
| 58 |
defenv.Append(CPPDEFINES = [('NSISCALL', '$STDCALL')]) |
| 59 |
|
| 60 |
### asm |
| 61 |
|
| 62 |
if 'x86' in defenv.get('TARGET_ARCH','x86'): |
| 63 |
defenv.Append(ASFLAGS = ['/coff']) # ML64 does not support /coff |
| 64 |
|
| 65 |
### debug |
| 66 |
|
| 67 |
if defenv['DEBUG']: |
| 68 |
defenv.Append(CCFLAGS = ['/Zi']) |
| 69 |
defenv.Append(CCFLAGS = ['/Fd${TARGET.dir}\\${TARGET.dir.file}.pdb']) |
| 70 |
defenv.Append(LINKFLAGS = ['/debug']) |
| 71 |
defenv['MSVCRT_FLAG'] = defenv['MSVCRT_FLAG'] + 'd' |
| 72 |
elif msvs_version >= 14.0 or defenv['TARGET_ARCH'] == 'arm64': |
| 73 |
defenv.Append(LINKFLAGS = ['/nocoffgrpinfo']) |
| 74 |
|
| 75 |
### workarounds |
| 76 |
|
| 77 |
# Some Platform SDK version includes a bad version of libcp.lib. |
| 78 |
# if stl usage causes link failure, copy the good libcp.lib |
| 79 |
# from one of the other lib folders and use it instead. |
| 80 |
|
| 81 |
confenv = defenv.Clone() |
| 82 |
conf = confenv.Configure() |
| 83 |
|
| 84 |
# For VS 2005 and up, the single threaded version of C runtime |
| 85 |
# need not be explicitly linked. |
| 86 |
if float(defenv['MSVS_VERSION'].replace('Exp','')) < 8.0: |
| 87 |
libcptest = """ |
| 88 |
#include <fstream> |
| 89 |
int main() { |
| 90 |
// %s |
| 91 |
std::ofstream header("test", std::ofstream::out); |
| 92 |
return 0; |
| 93 |
} |
| 94 |
""" |
| 95 |
|
| 96 |
conf.env.Prepend(LIBPATH = Dir('#/.sconf_temp').abspath) |
| 97 |
conf.env.Append(CCFLAGS = ['$EXCEPTION_FLAG']) |
| 98 |
|
| 99 |
if not conf.TryLink(libcptest % 'no change', '.cpp'): |
| 100 |
import os, shutil |
| 101 |
|
| 102 |
libdirs = (defenv['ENV']['LIB']).split(os.pathsep) + defenv['LIBPATH'] |
| 103 |
|
| 104 |
for libdir in libdirs: |
| 105 |
libdir = confenv.subst(libdir) |
| 106 |
try: |
| 107 |
libcp = r'%s\libcp.lib' % libdir |
| 108 |
shutil.copy(libcp, Dir('#/.sconf_temp').abspath) |
| 109 |
if conf.TryLink(libcptest % (r'using %s' % libcp), '.cpp'): |
| 110 |
defenv.PrependENVPath('LIB', Dir('#/.sconf_temp').abspath) |
| 111 |
break |
| 112 |
except IOError: |
| 113 |
continue |
| 114 |
else: |
| 115 |
print("*** Couldn't find a good version of libcp.lib") |
| 116 |
Exit(2) |
| 117 |
|
| 118 |
conf.Finish() |
| 119 |
|
| 120 |
# Linking to msvcr?0.dll (/MD) might require a manifest |
| 121 |
|
| 122 |
confenv = defenv.Clone() |
| 123 |
conf = confenv.Configure() |
| 124 |
if msvs_version >= 7.0: |
| 125 |
conf.env.Append(CCFLAGS = [defenv['MSVCRT_FLAG']]) |
| 126 |
code = """ |
| 127 |
#include <stdlib.h> |
| 128 |
int main() { return atoi("0"); } |
| 129 |
""" |
| 130 |
result = True # TryLink should not fail but default to True just in case so distribution will fail as well |
| 131 |
if conf.TryLink(code, '.cpp'): |
| 132 |
import os |
| 133 |
result = os.path.exists('%s.manifest' % conf.lastTarget) |
| 134 |
defenv['MSVCRT_NEEDSMANIFEST'] = result |
| 135 |
conf.Finish() |
| 136 |
|
| 137 |
# SCons 3.0.5 started including /nologo for rc.exe but it's not always supported |
| 138 |
|
| 139 |
confenv = defenv.Clone() |
| 140 |
conf = confenv.Configure() |
| 141 |
if not conf.TryAction('$RCCOM', '', '.rc')[0]: |
| 142 |
defenv['RCFLAGS'] = '' |
| 143 |
conf.Finish() |
| 144 |
|
| 145 |
### unicode |
| 146 |
tdefenv = defenv.Clone() |
| 147 |
if tdefenv['UNICODE']: |
| 148 |
tdefenv.Append(CPPDEFINES = ['_UNICODE', 'UNICODE']) |
| 149 |
|
| 150 |
### stub environment |
| 151 |
|
| 152 |
stub_env = defenv.Clone() |
| 153 |
|
| 154 |
setoptimizeflags(stub_env) |
| 155 |
stub_env.Append(CPPPATH = ['#$BUILD_CONFIG']) |
| 156 |
|
| 157 |
if not defenv['DEBUG']: |
| 158 |
stub_env.Append(CCFLAGS = ['/O1']) # optimize for size |
| 159 |
stub_env.Append(CCFLAGS = ['/W3']) # level 3 warnings |
| 160 |
stub_env.Append(CCFLAGS = ['/FAcs']) # full listing files |
| 161 |
stub_env.Append(CCFLAGS = ['/Fa${TARGET}.lst']) # listing file name |
| 162 |
|
| 163 |
stub_env.Append(LINKFLAGS = ['$NODEFLIBS_FLAG']) # no default libraries |
| 164 |
stub_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file |
| 165 |
|
| 166 |
if msvs_version >= 10.0: |
| 167 |
if stub_env['TARGET_ARCH'] != 'arm64': # LNK1246: '/FIXED' not compatible with 'ARM64' target machine |
| 168 |
stub_env.Append(LINKFLAGS = ['/FIXED']) # no relocations that our resource editor ignores |
| 169 |
|
| 170 |
stub_uenv = stub_env.Clone() |
| 171 |
stub_uenv.Append(CPPDEFINES = ['_UNICODE', 'UNICODE']) |
| 172 |
|
| 173 |
### makensis environment |
| 174 |
|
| 175 |
makensis_env = tdefenv.Clone() |
| 176 |
|
| 177 |
makensis_env.Append(CPPPATH = ['#$BUILD_CONFIG']) |
| 178 |
|
| 179 |
if not defenv['DEBUG']: |
| 180 |
makensis_env.Append(CCFLAGS = ['/O2']) # optimize for speed |
| 181 |
makensis_env.Append(CCFLAGS = ['$EXCEPTION_FLAG']) # enable exceptions |
| 182 |
makensis_env.Append(CCFLAGS = ['/W3']) # level 3 warnings |
| 183 |
makensis_env.Append(CCFLAGS = ['/FAcs']) # full listing files |
| 184 |
makensis_env.Append(CCFLAGS = ['/Fa${TARGET}.lst']) # listing file name |
| 185 |
makensis_env.Append(CCFLAGS = [defenv['MSVCRT_FLAG']]) |
| 186 |
|
| 187 |
makensis_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file |
| 188 |
makensis_env.Append(LINKFLAGS = ['$SUBSYS_CON']) # console executable |
| 189 |
if defenv['UNICODE']: |
| 190 |
makensis_env.Append(LINKFLAGS = ['/STACK:2097152']) # need 2 MB of stack in Unicode (default is 1 MB) |
| 191 |
|
| 192 |
### plugin environment |
| 193 |
|
| 194 |
plugin_env = defenv.Clone(no_import_lib = 1) |
| 195 |
|
| 196 |
setoptimizeflags(plugin_env) |
| 197 |
if defenv['TARGET_ARCH'] == 'amd64': |
| 198 |
plugin_env.Append(LINKFLAGS = ['/MACHINE:AMD64']) # Contrib\System\Resource will not link without this |
| 199 |
|
| 200 |
if not defenv['DEBUG']: |
| 201 |
plugin_env.Append(CCFLAGS = ['/O1']) # optimize for size |
| 202 |
plugin_env.Append(CCFLAGS = ['/W3']) # level 3 warnings |
| 203 |
|
| 204 |
plugin_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file |
| 205 |
|
| 206 |
plugin_uenv = plugin_env.Clone() |
| 207 |
plugin_uenv.Append(CPPDEFINES = ['_UNICODE', 'UNICODE']) |
| 208 |
|
| 209 |
### util environment |
| 210 |
|
| 211 |
util_env = tdefenv.Clone() |
| 212 |
|
| 213 |
setoptimizeflags(util_env) |
| 214 |
if not defenv['DEBUG']: |
| 215 |
util_env.Append(CCFLAGS = ['/O1']) # optimize for speed |
| 216 |
util_env.Append(CCFLAGS = ['/W3']) # level 3 warnings |
| 217 |
util_env.Append(CCFLAGS = [defenv['MSVCRT_FLAG']]) |
| 218 |
|
| 219 |
util_env.Append(LINKFLAGS = ['$MAP_FLAG']) # generate map file |
| 220 |
|
| 221 |
### cross-platform util environment |
| 222 |
|
| 223 |
cp_util_env = util_env.Clone() |
| 224 |
|
| 225 |
cp_util_env.Append(CPPPATH = ['#$BUILD_CONFIG']) |
| 226 |
|
| 227 |
### test environment |
| 228 |
|
| 229 |
test_env = defenv.Clone() |
| 230 |
|
| 231 |
test_env.Append(CPPPATH = ['#$BUILD_CONFIG']) |
| 232 |
|
| 233 |
### weird compiler requirements |
| 234 |
|
| 235 |
def check_requirement(ctx, func, trigger): |
| 236 |
ctx.Message('Checking for %s requirement... ' % func) |
| 237 |
|
| 238 |
flags = ctx.env['LINKFLAGS'] |
| 239 |
|
| 240 |
ctx.env.Append(LINKFLAGS = ['$NODEFLIBS_FLAG']) |
| 241 |
ctx.env.Append(LINKFLAGS = ['/entry:main']) |
| 242 |
|
| 243 |
test = """ |
| 244 |
int main() { |
| 245 |
%s |
| 246 |
return 0; |
| 247 |
} |
| 248 |
""" % trigger |
| 249 |
|
| 250 |
result = not ctx.TryLink(test, '.c') |
| 251 |
ctx.Result(result) |
| 252 |
|
| 253 |
ctx.env['LINKFLAGS'] = flags |
| 254 |
|
| 255 |
return result |
| 256 |
|
| 257 |
def add_file_to_emitter(env, emitter_name, file, obj_name=None): |
| 258 |
if obj_name is None: |
| 259 |
obj_name = emitter_name |
| 260 |
try: |
| 261 |
original_emitter = env[emitter_name] |
| 262 |
if type(original_emitter) == list: |
| 263 |
original_emitter = original_emitter[0] |
| 264 |
except KeyError: |
| 265 |
original_emitter = None |
| 266 |
|
| 267 |
def emitter(target, source, env): |
| 268 |
if original_emitter: |
| 269 |
target, source = original_emitter(target, source, env) |
| 270 |
|
| 271 |
if '$NODEFLIBS_FLAG' not in env['LINKFLAGS']: |
| 272 |
return target, source |
| 273 |
|
| 274 |
return target, source + env.Object(obj_name, file) |
| 275 |
|
| 276 |
env[emitter_name] = emitter |
| 277 |
|
| 278 |
def add_file(file, obj_name=None): |
| 279 |
file = File(file) |
| 280 |
add_file_to_emitter(stub_env, 'PROGEMITTER', file, obj_name) |
| 281 |
add_file_to_emitter(stub_uenv, 'PROGEMITTER', file, obj_name) |
| 282 |
add_file_to_emitter(util_env, 'PROGEMITTER', file, obj_name) |
| 283 |
add_file_to_emitter(plugin_env, 'SHLIBEMITTER', file, obj_name) |
| 284 |
add_file_to_emitter(plugin_uenv, 'SHLIBEMITTER', file, obj_name) |
| 285 |
|
| 286 |
# |
| 287 |
# MSVC 6 SP6 doesn't like direct shifting of 64-bit integers. |
| 288 |
# It generates a call to ___aullshr which requires libc, which |
| 289 |
# we don't like. However, it does agree to work properly with |
| 290 |
# a call to Int64ShrlMod32. |
| 291 |
# |
| 292 |
|
| 293 |
conf = stub_env.Configure() |
| 294 |
conf.env.Append(LINKFLAGS = ['/entry:WinMain']) |
| 295 |
|
| 296 |
int64test = """ |
| 297 |
#include <windows.h> |
| 298 |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow) { |
| 299 |
ULARGE_INTEGER *i = 0; |
| 300 |
return (int)(i->QuadPart >> 10); |
| 301 |
} |
| 302 |
""" |
| 303 |
|
| 304 |
if not conf.TryLink(int64test, '.c'): |
| 305 |
stub_env.Append(CPPDEFINES = ['_NSIS_NO_INT64_SHR']) |
| 306 |
stub_uenv.Append(CPPDEFINES = ['_NSIS_NO_INT64_SHR']) |
| 307 |
|
| 308 |
conf.Finish() |
| 309 |
|
| 310 |
# |
| 311 |
# MSVC 2005 requires the memset CRT function to be present |
| 312 |
# and the stubs might need memcpy (entry struct copy on x64) |
| 313 |
# BUGBUG: The tests are currently broken on x64 and designed to fail! |
| 314 |
# |
| 315 |
|
| 316 |
conf = defenv.Configure(custom_tests = { 'CheckRequirement' : check_requirement }) |
| 317 |
if conf.CheckRequirement('memset', 'char c[128] = "test";switch(sizeof(void*)){case 8:break;case sizeof(void*):return 1;}'): |
| 318 |
add_file('memset.c', 'memset') |
| 319 |
|
| 320 |
memcpy_test = """ |
| 321 |
switch(sizeof(void*)){case 8:break;case sizeof(void*):return 1;} |
| 322 |
""" |
| 323 |
if conf.CheckRequirement('memcpy', memcpy_test): |
| 324 |
add_file('memcpy.c', 'memcpy') |
| 325 |
stub_env.Append(CPPDEFINES = ['_NSIS_NODEFLIB_CRTMEMCPY']) |
| 326 |
stub_uenv.Append(CPPDEFINES = ['_NSIS_NODEFLIB_CRTMEMCPY']) |
| 327 |
|
| 328 |
conf.Finish() |
| 329 |
|
| 330 |
### return |
| 331 |
|
| 332 |
Return('stub_env makensis_env plugin_env util_env cp_util_env test_env stub_uenv plugin_uenv') |