Improve code to use the same CC and CXX as wxWidgets, including flags that may be added on to wx's CC/CXX.

This commit is contained in:
Robin Dunn
2020-12-01 16:18:14 -08:00
parent cbb0cfc9b6
commit 201228c529
2 changed files with 84 additions and 49 deletions

View File

@@ -15,6 +15,7 @@ import sys
import os
import glob
import fnmatch
import shlex
import re
import shutil
import subprocess
@@ -195,6 +196,7 @@ class Configuration(object):
'/EHsc',
# '/GX-' # workaround for internal compiler error in MSVC on some machines
]
self.cxxflags = self.cflags[:]
self.lflags = None
# These confuse WAF, but since it already reliably picks the correct
@@ -206,6 +208,7 @@ class Configuration(object):
# Other MSVC flags...
# Uncomment these to have debug info for all kinds of builds
#self.cflags += ['/Od', '/Z7']
#self.cxxflags += ['/Od', '/Z7']
#self.lflags = ['/DEBUG', ]
@@ -219,13 +222,15 @@ class Configuration(object):
self.libdirs = []
self.libs = []
self.cflags = self.getWxConfigValue('--cxxflags')
self.cflags = self.cflags.split()
self.cflags = self.getWxConfigValue('--cflags').split()
self.cxxflags = self.getWxConfigValue('--cxxflags').split()
if self.debug:
self.cflags.append('-ggdb')
self.cflags.append('-O0')
for lst in [self.cflags, self.cxxflags]:
lst.append('-ggdb')
lst.append('-O0')
else:
self.cflags.append('-O3')
for lst in [self.cflags, self.cxxflags]:
lst.append('-O3')
lflags = self.getWxConfigValue('--libs')
self.MONOLITHIC = (lflags.find("_xrc") == -1)
@@ -235,30 +240,24 @@ class Configuration(object):
self.WXRELEASE = self.getWxConfigValue('--release')
self.WXPREFIX = self.getWxConfigValue('--prefix')
# Set CC, CXX and maybe LDSHARED based on what was configured for
# wxWidgets, but not if those values are in the environment.
self.CC = self.CXX = self.LDSHARED = None
if not os.environ.get('CC'):
compiler, flags = self.unpackCompilerCommand(self.getWxConfigValue('--cc'))
self.CC = os.environ["CC"] = compiler
for flag in flags:
if flag not in self.cflags:
self.cflags.insert(0, flag)
# wxMac settings
if sys.platform[:6] == "darwin":
self.WXPLAT = '__WXMAC__'
if self.WXPORT == 'osx_carbon':
# Flags and such for a Darwin (Max OS X) build of Python
self.WXPLAT2 = '__WXOSX_CARBON__'
else:
self.WXPLAT2 = '__WXOSX_COCOA__'
self.libs = ['stdc++']
if not self.ARCH == "":
for arch in self.ARCH.split(','):
self.cflags.append("-arch")
self.cflags.append(arch)
self.lflags.append("-arch")
self.lflags.append(arch)
if not os.environ.get('CC') or not os.environ.get('CXX'):
self.CC = os.environ["CC"] = self.getWxConfigValue('--cc')
self.CXX = os.environ["CXX"] = self.getWxConfigValue('--cxx')
if not os.environ.get('CXX'):
compiler, flags = self.unpackCompilerCommand(self.getWxConfigValue('--cxx'))
self.CXX = os.environ["CXX"] = compiler
for flag in flags:
if flag not in self.cxxflags:
self.cxxflags.insert(0, flag)
if sys.platform[:6] == "darwin" and not os.environ.get('LDSHARED'):
# We want to use the linker command from wx to make sure
# we get the right sysroot, but we also need to ensure that
# the other linker flags that distutils wants to use are
@@ -267,7 +266,7 @@ class Configuration(object):
# remove the compiler command
del LDSHARED[0]
# remove any -sysroot flags and their arg
while 1:
while True:
try:
index = LDSHARED.index('-isysroot')
# Strip this argument and the next one:
@@ -281,7 +280,26 @@ class Configuration(object):
self.LDSHARED = os.environ["LDSHARED"] = LDSHARED
# wxGTK settings
# Other wxMac-only settings
if sys.platform[:6] == "darwin":
self.WXPLAT = '__WXMAC__'
if self.WXPORT == 'osx_carbon':
# Flags and such for a Darwin (Max OS X) build of Python
self.WXPLAT2 = '__WXOSX_CARBON__'
else:
self.WXPLAT2 = '__WXOSX_COCOA__'
if not self.ARCH == "":
for arch in self.ARCH.split(','):
for lst in [self.cflags, self.cxxflags]:
lst.append("-arch")
lst.append(arch)
self.lflags.append("-arch")
self.lflags.append(arch)
# wxGTK-only settings
else:
# Set flags for other Unix type platforms
if self.WXPORT == 'gtk':
@@ -296,7 +314,7 @@ class Configuration(object):
self.WXPLAT = '__WXGTK__'
portcfg = os.popen('pkg-config gtk+-3.0 --cflags', 'r').read()[:-1]
elif self.WXPORT == 'x11':
msg("WARNING: The wxX11 port is no supported")
msg("WARNING: The wxX11 port is not supported")
self.WXPLAT = '__WXX11__'
portcfg = ''
self.BUILD_BASE = self.BUILD_BASE + '-' + self.WXPORT
@@ -307,6 +325,7 @@ class Configuration(object):
raise SystemExit("Unknown WXPORT value: " + self.WXPORT)
self.cflags += portcfg.split()
self.cxxflags += portcfg.split()
# Some distros (e.g. Mandrake) put libGLU in /usr/X11R6/lib, but
# wx-config doesn't output that for some reason. For now, just
@@ -318,9 +337,11 @@ class Configuration(object):
# Move the various -I, -D, etc. flags we got from the config scripts
# into the distutils lists.
self.cflags = self.adjustCFLAGS(self.cflags, self.defines, self.includes)
self.cxxflags = self.adjustCFLAGS(self.cxxflags, self.defines, self.includes)
self.lflags = self.adjustLFLAGS(self.lflags, self.libdirs, self.libs)
self.cflags.insert(0, '-UNDEBUG')
self.cxxflags.insert(0, '-UNDEBUG')
if self.debug and self.WXPORT == 'msw' and self.COMPILER != 'mingw32':
self.defines.append( ('_DEBUG', None) )
@@ -430,6 +451,16 @@ class Configuration(object):
return value
def unpackCompilerCommand(self, cmd):
"""
It's possible for the CC and CXX values coming from wx-config to have
some extra parameters tacked on. Let's split them apart.
"""
cmd = shlex.split(cmd)
compiler = cmd[0]
flags = cmd[1:]
return compiler, flags
def build_locale_dir(self, destdir, verbose=1):
"""Build a locale dir under the wxPython package."""

26
wscript
View File

@@ -125,8 +125,10 @@ def configure(conf):
conf.env.INCLUDES_WX = cfg.includes
conf.env.DEFINES_WX = cfg.wafDefines
conf.env.CFLAGS_WX = cfg.cflags
conf.env.CXXFLAGS_WX = cfg.cflags
conf.env.CFLAGS = cfg.cflags
conf.env.CXXFLAGS = cfg.cxxflags
conf.env.CFLAGS_WX = list()
conf.env.CXXFLAGS_WX = list()
conf.env.LIBPATH_WX = cfg.libdirs
conf.env.LIB_WX = cfg.libs
conf.env.LIBFLAGS_WX = cfg.lflags
@@ -192,20 +194,22 @@ def configure(conf):
conf.env['LIB_PYEXT'][0] += '_d'
else:
else: # not isWindows
# TODO: Double-check that this works when using an installed wxWidgets
wxConfigDir = cfg.findWxConfigDir(conf.options.wx_config)
# Configuration stuff for non-Windows ports using wx-config
# First finish configuring the Config object
conf.env.wx_config = conf.options.wx_config
cfg.finishSetup(conf.env.wx_config, conf.env.debug)
conf.env.CFLAGS = cfg.cflags[:]
conf.env.CXXFLAGS = cfg.cxxflags[:]
conf.env.CFLAGS_WX = list()
conf.env.CXXFLAGS_WX = list()
conf.env.CFLAGS_WXPY = list()
conf.env.CXXFLAGS_WXPY = list()
# finish configuring the Config object
conf.env.wx_config = conf.options.wx_config
cfg.finishSetup(conf.env.wx_config, conf.env.debug)
# Check wx-config exists and fetch some values from it
rpath = ' --no-rpath' if not conf.options.no_magic else ''
conf.check_cfg(path=conf.options.wx_config, package='',
@@ -364,14 +368,14 @@ def configure(conf):
# Some Mac-specific stuff
if isDarwin:
conf.env.MACOSX_DEPLOYMENT_TARGET = "10.6"
conf.env.MACOSX_DEPLOYMENT_TARGET = "10.10"
if conf.options.mac_arch:
conf.env.ARCH_WXPY = conf.options.mac_arch.split(',')
#import pprint
#pprint.pprint( [(k, conf.env[k]) for k in conf.env.keys()] )
# import pprint
# pprint.pprint( [(k, conf.env[k]) for k in conf.env.keys()] )
# sys.exit(0)
#