diff --git a/buildutils/build.py b/buildutils/build.py index 5797c46..c85a5cc 100644 --- a/buildutils/build.py +++ b/buildutils/build.py @@ -2,6 +2,8 @@ import subprocess import os +import shutil +import sys import tempfile def build_libcapnp(bundle_dir, build_dir, verbose=False): @@ -11,23 +13,46 @@ def build_libcapnp(bundle_dir, build_dir, verbose=False): bundle_dir = os.path.abspath(bundle_dir) capnp_dir = os.path.join(bundle_dir, 'capnproto-c++') build_dir = os.path.abspath(build_dir) + tmp_dir = os.path.join(capnp_dir, 'build') + if not os.path.exists(tmp_dir): + os.mkdir(tmp_dir) - with tempfile.TemporaryFile() as f: - stdout = f - if verbose: - stdout = None - cxxflags = os.environ.get('CXXFLAGS', None) - os.environ['CXXFLAGS'] = (cxxflags or '') + ' -fPIC -O2 -DNDEBUG' - conf = subprocess.Popen(['./configure', '--disable-shared', '--prefix', build_dir], cwd=capnp_dir, stdout=stdout) - returncode = conf.wait() - if returncode != 0: - raise RuntimeError('Configure failed') + cxxflags = os.environ.get('CXXFLAGS', None) + os.environ['CXXFLAGS'] = (cxxflags or '') + ' -O2 -DNDEBUG' - make = subprocess.Popen(['make', '-j4', 'install'], cwd=capnp_dir, stdout=stdout) - returncode = make.wait() - if cxxflags is None: - del os.environ['CXXFLAGS'] - else: - os.environ['CXXFLAGS'] = cxxflags - if returncode != 0: - raise RuntimeError('Make failed') + # Enable ninja for compilation if available + build_type = [] + if shutil.which('ninja'): + build_type = ['-G', 'Ninja'] + + # TODO Determine VS version + + args = [ + 'cmake', + '-DCMAKE_POSITION_INDEPENDENT_CODE=1', + '-DBUILD_TESTING=OFF', + '-DBUILD_SHARED_LIBS=OFF', + '-DCMAKE_INSTALL_PREFIX:PATH={}'.format(build_dir), + capnp_dir, + ] + args.extend(build_type) + conf = subprocess.Popen(args, cwd=tmp_dir, stdout=sys.stdout) + returncode = conf.wait() + if returncode != 0: + raise RuntimeError('CMake failed') + + # Run build through cmake + build = subprocess.Popen([ + 'cmake', + '--build', + '.', + '--target', + 'install', + ], cwd=tmp_dir, stdout=sys.stdout) + returncode = build.wait() + if cxxflags is None: + del os.environ['CXXFLAGS'] + else: + os.environ['CXXFLAGS'] = cxxflags + if returncode != 0: + raise RuntimeError('capnproto compilation failed') diff --git a/buildutils/bundle.py b/buildutils/bundle.py index 817797b..c9e83df 100644 --- a/buildutils/bundle.py +++ b/buildutils/bundle.py @@ -33,7 +33,7 @@ pjoin = os.path.join # Constants # -bundled_version = (0, 7, 4) +bundled_version = (0, 7, 0) libcapnp_name = "capnproto-c++-%i.%i.%i.tar.gz" % (bundled_version) libcapnp_url = "https://capnproto.org/" + libcapnp_name @@ -92,10 +92,6 @@ def fetch_libcapnp(savedir, url=None): shutil.move(with_version, dest) else: cpp_dir = os.path.join(with_version, 'c++') - conf = Popen(['autoreconf', '-i'], cwd=cpp_dir) - returncode = conf.wait() - if returncode != 0: - raise RuntimeError('Autoreconf failed. Make sure autotools are installed on your system.') shutil.move(cpp_dir, dest)