support for qt 5.2

This commit is contained in:
Nick Bolton
2014-02-14 16:21:02 +00:00
parent cfc1aa2569
commit bf361d153b
17 changed files with 471 additions and 158 deletions

View File

@@ -32,7 +32,7 @@ class Generator(object):
class MakefilesGenerator(Generator):
def __init__(self):
super(MakefilesGenerator, self).__init__('Unix Makefiles', 'build', '..', 'bin')
super(MakefilesGenerator, self).__init__('Unix Makefiles')
def getBuildDir(self, target):
return super(MakefilesGenerator, self).getBuildDir(target) + '/' + target
@@ -48,6 +48,14 @@ class MakefilesGenerator(Generator):
def getSourceDir(self):
return super(MakefilesGenerator, self).getSourceDir() + '/..'
class XcodeGenerator(Generator):
def __init__(self):
super(XcodeGenerator, self).__init__('Xcode')
def getBinDir(self, target=''):
xcodeTarget = target[0].upper() + target[1:]
return super(XcodeGenerator, self).getBinDir(target) + '/' + xcodeTarget
class EclipseGenerator(Generator):
def __init__(self):

View File

@@ -17,7 +17,7 @@
# TODO: split this file up, it's too long!
import sys, os, ConfigParser, shutil, re, ftputil, zipfile
from generators import Generator, EclipseGenerator, MakefilesGenerator
from generators import Generator, EclipseGenerator, XcodeGenerator, MakefilesGenerator
if sys.version_info >= (2, 4):
import subprocess
@@ -60,8 +60,11 @@ class InternalCommands:
# by default, prompt user for input
no_prompts = False
# by default, don't compile the gui
enable_make_gui = False
# by default, compile the core
enableMakeCore = True
# by default, compile the gui
enableMakeGui = True
# by default, let cmake decide
macSdk = None
@@ -85,7 +88,7 @@ class InternalCommands:
darwin_generators = {
1 : MakefilesGenerator(),
2 : Generator('Xcode'),
2 : XcodeGenerator(),
3 : EclipseGenerator(),
}
@@ -150,16 +153,41 @@ class InternalCommands:
zip.extractall(dir)
def configure(self, target='', extraArgs=''):
cmake_args = ''
# ensure latest setup and do not ask config for generator (only fall
# back to prompt if not specified as arg)
self.ensure_setup_latest()
if sys.platform == "darwin":
if self.macSdk:
sdkDir = self.getMacSdkDir()
if not os.path.exists(sdkDir):
raise Exception("Mac SDK not found at: " + sdkDir)
os.environ["MACOSX_DEPLOYMENT_TARGET"] = self.macSdk
else:
raise Exception("Arg missing: --mac-sdk <version>");
# default is release
if target == '':
print 'Defaulting target to: ' + self.defaultTarget
target = self.defaultTarget
# allow user to skip qui compile
if self.enableMakeCore:
self.configureCore(target, extraArgs)
# allow user to skip qui compile
if self.enableMakeGui:
self.configureGui(target, extraArgs)
self.setConfRun(target)
def configureCore(self, target="", extraArgs=""):
# ensure that we have access to cmake
_cmake_cmd = self.persist_cmake()
# now that we know we've got the latest setup, we can ask the config
# file for the generator (but again, we only fall back to this if not
# specified as arg).
@@ -168,20 +196,16 @@ class InternalCommands:
if generator != self.findGeneratorFromConfig():
print('Generator changed, running setup.')
self.setup(target)
cmake_args = ''
if generator.cmakeName != '':
cmake_args += ' -G "' + generator.cmakeName + '"'
# default is release
if target == '':
print 'Defaulting target to: ' + self.defaultTarget
target = self.defaultTarget
# for makefiles always specify a build type (debug, release, etc)
if generator.cmakeName.find('Unix Makefiles') != -1:
cmake_args += ' -DCMAKE_BUILD_TYPE=' + target.capitalize()
if self.macSdk:
elif sys.platform == "darwin":
path = "/Developer/SDKs/MacOSX" + self.macSdk + ".sdk/"
cmake_args += " -DCMAKE_OSX_SYSROOT=" + path
cmake_args += " -DCMAKE_OSX_DEPLOYMENT_TARGET=" + self.macSdk
@@ -191,9 +215,6 @@ class InternalCommands:
config = self.getConfig()
config.set('cmake', 'mac_sdk', self.macSdk)
self.write_config(config)
elif sys.platform == "darwin":
# seems that this is now needed on 10.8
raise Exception("Arg missing: --mac-sdk <version>");
# if not visual studio, use parent dir
sourceDir = generator.getSourceDir()
@@ -219,36 +240,66 @@ class InternalCommands:
if err != 0:
raise Exception('CMake encountered error: ' + str(err))
def configureGui(self, target="", extraArgs=""):
# make sure we have qmake
self.persist_qmake()
# allow user to skip qui compile
if self.enable_make_gui:
# make sure we have qmake
self.persist_qmake()
qmake_cmd_string = self.qmake_cmd + " " + self.qtpro_filename + " -r"
qmake_cmd_string = self.qmake_cmd + " " + self.qtpro_filename + " -r"
if sys.platform == "darwin":
# create makefiles on mac (not xcode).
qmake_cmd_string += " -spec macx-g++"
(major, minor) = self.getMacVersion()
if major == 10 and minor <= 4:
# 10.4: universal (intel and power pc)
qmake_cmd_string += ' CONFIG+="ppc i386"'
print "QMake command: " + qmake_cmd_string
# run qmake from the gui dir
self.try_chdir(self.gui_dir)
err = os.system(qmake_cmd_string)
self.restore_chdir()
if err != 0:
raise Exception('QMake encountered error: ' + str(err))
if sys.platform == "darwin":
self.setConfRun(target)
# create makefiles on mac (not xcode).
qmake_cmd_string += " -spec macx-g++"
(major, minor) = self.getMacVersion()
if major == 10 and minor <= 4:
# 10.4: universal (intel and power pc)
qmake_cmd_string += ' CONFIG+="ppc i386"'
sdkDir = self.getMacSdkDir()
shortForm = "macosx" + self.macSdk
version = str(major) + "." + str(minor)
qmake_cmd_string += " QMAKE_MACOSX_DEPLOYMENT_TARGET=" + version
(qMajor, qMinor, qRev) = self.getQmakeVersion()
if qMajor <= 4:
# 4.6: qmake takes full sdk dir.
qmake_cmd_string += " QMAKE_MAC_SDK=" + sdkDir
else:
# 5.2: now we need to use the .path setting.
qmake_cmd_string += " QMAKE_MAC_SDK=" + shortForm
qmake_cmd_string += " QMAKE_MAC_SDK." + shortForm + ".path=" + sdkDir
print "QMake command: " + qmake_cmd_string
# run qmake from the gui dir
self.try_chdir(self.gui_dir)
err = os.system(qmake_cmd_string)
self.restore_chdir()
if err != 0:
raise Exception('QMake encountered error: ' + str(err))
def getQmakeVersion(self):
import commands
version = commands.getoutput("qmake --version")
result = re.search('(\d+)\.(\d+)\.(\d)', version)
if not result:
raise Exception("Could not get qmake version.")
major = int(result.group(1))
minor = int(result.group(2))
rev = int(result.group(3))
return (major, minor, rev)
def getMacSdkDir(self):
return "/Developer/SDKs/MacOSX" + self.macSdk + ".sdk"
# http://tinyurl.com/cs2rxxb
def fixCmakeEclipseBug(self):
print "Fixing CMake Eclipse bugs..."
@@ -334,6 +385,16 @@ class InternalCommands:
self.ensure_setup_latest()
# allow user to skip core compile
if self.enableMakeCore:
self.makeCore(targets)
# allow user to skip qui compile
if self.enableMakeGui:
self.makeGui(targets)
def makeCore(self, targets):
generator = self.getGeneratorFromConfig().cmakeName
config = self.getConfig()
@@ -353,10 +414,78 @@ class InternalCommands:
self.runBuildCommand(cmd, target)
else:
raise Exception('Build command not supported with generator: ' + generator)
def makeGui(self, targets, args=""):
if sys.platform == 'win32':
gui_make_cmd = self.w32_make_cmd
elif sys.platform in ['linux2', 'sunos5', 'freebsd7', 'darwin']:
gui_make_cmd = self.make_cmd + " -w"
else:
raise Exception('Unsupported platform: ' + sys.platform)
gui_make_cmd += args
print 'Make GUI command: ' + gui_make_cmd
if sys.platform == 'win32':
for target in targets:
self.try_chdir(self.gui_dir)
err = os.system(gui_make_cmd + ' ' + target)
self.restore_chdir()
if err != 0:
raise Exception(gui_make_cmd + ' failed with error: ' + str(err))
else:
self.try_chdir(self.gui_dir)
err = os.system(gui_make_cmd)
self.restore_chdir()
# allow user to skip qui compile
if self.enable_make_gui:
self.make_gui(targets)
if err != 0:
raise Exception(gui_make_cmd + ' failed with error: ' + str(err))
if sys.platform == 'darwin' and not "clean" in args:
for target in targets:
self.macPostMakeGui(target)
def macPostMakeGui(self, target):
dir = self.getGenerator().binDir
if self.enableMakeCore:
# copy core binaries into the bundle, since the gui
# now looks for the binaries in the current app dir.
targetDir = self.getGenerator().getBinDir(target)
bundleBinDir = dir + "/Synergy.app/Contents/MacOS/"
shutil.copy(targetDir + "/synergyc", bundleBinDir)
shutil.copy(targetDir + "/synergys", bundleBinDir)
shutil.copy(targetDir + "/syntool", bundleBinDir)
# use qt to copy libs to bundle so no dependencies are needed. do not create a
# dmg at this point, since we need to sign it first, and then create our own
# after signing (so that qt does not affect the signed app bundle).
bin = "macdeployqt Synergy.app -verbose=2"
self.try_chdir(dir)
err = os.system(bin)
self.restore_chdir()
(qMajor, qMinor, qRev) = self.getQmakeVersion()
if qMajor <= 4:
frameworkRootDir = "/Library/Frameworks"
else:
# TODO: auto-detect, qt can now be installed anywhere.
frameworkRootDir = "/Developer/Qt5.2.1/5.2.1/clang_64/lib"
# copy the missing Info.plist files for the frameworks.
shutil.copy(frameworkRootDir + "/QtCore.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtCore.framework/Resources/")
shutil.copy(frameworkRootDir + "/QtGui.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtGui.framework/Resources/")
shutil.copy(frameworkRootDir + "/QtNetwork.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtNetwork.framework/Resources/")
if err != 0:
raise Exception(bin + " failed with error: " + str(err))
def signmac(self, identity):
self.try_chdir("bin")
@@ -408,6 +537,15 @@ class InternalCommands:
if len(targets) == 0:
targets += [self.defaultTarget,]
# allow user to skip core clean
if self.enableMakeCore:
self.cleanCore(targets)
# allow user to skip qui clean
if self.enableMakeGui:
self.cleanGui(targets)
def cleanCore(self, targets):
generator = self.getGeneratorFromConfig().cmakeName
if generator.startswith('Visual Studio'):
@@ -439,72 +577,9 @@ class InternalCommands:
if err != 0:
raise Exception('Clean failed: ' + str(err))
# allow user to skip qui compile
clean_targets = []
if self.enable_make_gui:
for target in targets:
clean_targets.append(target + '-clean')
self.make_gui(clean_targets)
def make_gui(self, targets):
if sys.platform == 'win32':
gui_make_cmd = self.w32_make_cmd
elif sys.platform in ['linux2', 'sunos5', 'freebsd7', 'darwin']:
gui_make_cmd = self.make_cmd + " -w"
else:
raise Exception('Unsupported platform: ' + sys.platform)
print 'Make GUI command: ' + gui_make_cmd
if sys.platform == 'win32':
for target in targets:
self.try_chdir(self.gui_dir)
err = os.system(gui_make_cmd + ' ' + target)
self.restore_chdir()
if err != 0:
raise Exception(gui_make_cmd + ' failed with error: ' + str(err))
else:
self.try_chdir(self.gui_dir)
err = os.system(gui_make_cmd)
self.restore_chdir()
if err != 0:
raise Exception(gui_make_cmd + ' failed with error: ' + str(err))
if sys.platform == 'darwin':
self.macPostMakeGui()
def macPostMakeGui(self):
dir = self.getGenerator().binDir
# copy synergy[cs] binaries into the bundle, since the gui
# now looks for the binaries in the current app dir.
shutil.copy(dir + "/synergyc", dir + "/Synergy.app/Contents/MacOS/")
shutil.copy(dir + "/synergys", dir + "/Synergy.app/Contents/MacOS/")
shutil.copy(dir + "/syntool", dir + "/Synergy.app/Contents/MacOS/")
# use qt to copy libs to bundle so no dependencies are needed. do not create a
# dmg at this point, since we need to sign it first, and then create our own
# after signing (so that qt does not affect the signed app bundle).
bin = "macdeployqt Synergy.app -verbose=2"
self.try_chdir(dir)
err = os.system(bin)
self.restore_chdir()
# copy the missing Info.plist files for the frameworks.
shutil.copy("/Library/Frameworks/QtCore.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtCore.framework/Resources/")
shutil.copy("/Library/Frameworks/QtGui.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtGui.framework/Resources/")
shutil.copy("/Library/Frameworks/QtNetwork.framework/Contents/Info.plist",
dir + "/Synergy.app/Contents/Frameworks/QtNetwork.framework/Resources/")
if err != 0:
raise Exception(bin + " failed with error: " + str(err))
def cleanGui(self, targets):
self.makeGui(targets, " clean")
def open(self):
generator = self.getGeneratorFromConfig().cmakeName
@@ -1143,24 +1218,13 @@ class InternalCommands:
print str(k) + ': ' + generators[k].cmakeName
def getMacVersion(self):
# if we've built with an older sdk, then use that as the
# os version for package names, etc.
config = self.getConfig()
if config.has_option("cmake", "mac_sdk"):
macSdk = config.get("cmake", "mac_sdk")
split = macSdk.split('.')
major = int(split[0])
minor = int(split[1])
return (major, minor)
import commands
versions = commands.getoutput('/usr/bin/sw_vers')
result = re.search('ProductVersion:\t(\d+)\.(\d+)', versions)
if not self.macSdk:
raise Exception("Mac OS X SDK not set.")
result = re.search('(\d+)\.(\d+)', self.macSdk)
if not result:
print versions
raise Exception(
'Could not find Mac OS X version in sw_vers output.')
raise Exception("Could not find Mac OS X version.")
major = int(result.group(1))
minor = int(result.group(2))
@@ -1221,8 +1285,10 @@ class CommandHandler:
self.ic.no_prompts = True
elif o in ('-g', '--generator'):
self.ic.generator_id = a
elif o == '--make-gui':
self.ic.enable_make_gui = True
elif o == '--skip-gui':
self.ic.enableMakeGui = False
elif o == '--skip-core':
self.ic.enableMakeCore = False
elif o in ('-d', '--debug'):
self.build_targets += ['debug',]
elif o in ('-r', '--release'):