From 9bf145d98746d60d7d757ab6a8bc0c016d9c4360 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Tue, 20 Dec 2011 11:38:56 -0800 Subject: inline gtest to simplify windows build --- HACKING | 8 ++------ configure.py | 39 +++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/HACKING b/HACKING index b49b857..ca16e24 100644 --- a/HACKING +++ b/HACKING @@ -43,14 +43,10 @@ Generating the manual: ./ninja manual Windows development on Linux (this is kind of hacky right now): +- Get the gtest source, unpack it into your source dir - sudo apt-get install gcc-mingw32 wine - export CC=i586-mingw32msvc-cc CXX=i586-mingw32msvc-c++ AR=i586-mingw32msvc-ar -- ./configure.py --platform=mingw --host=linux -- Build gtest: - - unpack it into your source dir - - ./configure - - to work around missing _TlsAlloc I had to hack the libtool script to - append -lmingw32 -lkernel32 at the *end* of the link line +- ./configure.py --platform=mingw --host=linux --with-gtest=gtest-1.6.0 - Build ninja: /path/to/linux/ninja - Run: ./ninja.exe (implicitly runs through wine(!)) diff --git a/configure.py b/configure.py index 6b4c0d3..8bb5d24 100755 --- a/configure.py +++ b/configure.py @@ -41,7 +41,7 @@ parser.add_option('--profile', metavar='TYPE', choices=profilers, help='enable profiling (' + '/'.join(profilers) + ')',) parser.add_option('--with-gtest', metavar='PATH', - help='use gtest built in directory PATH') + help='use gtest unpacked in directory PATH') (options, args) = parser.parse_args() platform = options.platform @@ -74,6 +74,10 @@ def doc(filename): return os.path.join('doc', filename) def cxx(name, **kwargs): return n.build(built(name + '.o'), 'cxx', src(name + '.cc'), **kwargs) +def binary(name): + if platform == 'mingw': + return name + '.exe' + return name n.variable('builddir', 'build') n.variable('cxx', os.environ.get('CXX', 'g++')) @@ -91,8 +95,6 @@ libs = [] if platform == 'mingw': cflags.remove('-fvisibility=hidden'); - cflags.append('-Igtest-1.6.0/include') - ldflags.append('-Lgtest-1.6.0/lib/.libs') ldflags.append('-static') else: if options.profile == 'gmon': @@ -169,11 +171,8 @@ libs.append('-lninja') n.comment('Main executable is library plus main() function.') objs = cxx('ninja') -binary = 'ninja' -if platform == 'mingw': - binary = 'ninja.exe' -n.build(binary, 'link', objs, implicit=ninja_lib, - variables=[('libs', libs)]) +ninja = n.build(binary('ninja'), 'link', objs, implicit=ninja_lib, + variables=[('libs', libs)]) n.newline() n.comment('Tests all build into ninja_test executable.') @@ -181,15 +180,23 @@ n.comment('Tests all build into ninja_test executable.') variables = [] test_cflags = None test_ldflags = None +test_libs = libs +objs = [] if options.with_gtest: path = options.with_gtest + + gtest_all_incs = '-I%s -I%s' % (path, os.path.join(path, 'include')) + objs += n.build(built('gtest-all.o'), 'cxx', + os.path.join(path, 'src/gtest-all.cc'), + variables=[('cflags', gtest_all_incs)]) + objs += n.build(built('gtest_main.o'), 'cxx', + os.path.join(path, 'src/gtest_main.cc'), + variables=[('cflags', gtest_all_incs)]) + test_cflags = cflags + ['-I%s' % os.path.join(path, 'include')] - test_libs = libs + [os.path.join(path, 'lib/.libs/lib%s.a' % lib) - for lib in ['gtest_main', 'gtest']] else: - test_libs = libs + ['-lgtest_main', '-lgtest'] + test_libs.extend(['-lgtest_main', '-lgtest']) -objs = [] for name in ['build_log_test', 'build_test', 'clean_test', @@ -207,14 +214,14 @@ for name in ['build_log_test', if platform != 'mingw': test_libs.append('-lpthread') -n.build('ninja_test', 'link', objs, implicit=ninja_lib, +n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib, variables=[('ldflags', test_ldflags), ('libs', test_libs)]) n.newline() n.comment('Perftest executable.') objs = cxx('parser_perftest') -n.build('parser_perftest', 'link', objs, implicit=ninja_lib, +n.build(binary('parser_perftest'), 'link', objs, implicit=ninja_lib, variables=[('libs', '-L$builddir -lninja')]) n.newline() @@ -252,7 +259,7 @@ n.build('doxygen', 'doxygen', doc('doxygen.config'), implicit=mainpage) n.newline() -if platform != 'mingw': +if host != 'mingw': n.comment('Regenerate build files if build script changes.') n.rule('configure', command='./configure.py $configure_args', @@ -262,6 +269,6 @@ if platform != 'mingw': n.newline() n.comment('Build only the main binary by default.') -n.default(binary) +n.default(ninja) print 'wrote %s.' % BUILD_FILENAME -- cgit v0.12