1#!/usr/bin/env python
2from waflib.extras import autowaf as autowaf
3from waflib import Options
4import os
5
6# Version of this package (even if built as a child)
7EVORAL_VERSION = '0.0.0'
8
9# Library version (UNIX style major, minor, micro)
10# major increment <=> incompatible changes
11# minor increment <=> compatible changes (additions)
12# micro increment <=> no interface changes
13# Version history:
14#   0.0.0 = 0,0,0
15EVORAL_LIB_VERSION = '0.0.0'
16
17# Variables for 'waf dist'
18APPNAME = 'evoral'
19VERSION = EVORAL_VERSION
20
21# Mandatory variables
22top = '.'
23out = 'build'
24
25def options(opt):
26    opt.load('compiler_c')
27    opt.load('compiler_cxx')
28    autowaf.set_options(opt)
29    opt.add_option('--test', action='store_true', default=False, dest='build_tests',
30                    help="Build unit tests")
31    opt.add_option('--test-coverage', action='store_true', default=False, dest='test_coverage',
32                    help="Use gcov to test for code coverage")
33    opt.add_option('--internal-shared-libs', action='store_true', default=True, dest='internal_shared_libs',
34                   help='Build internal libs as shared libraries')
35
36def configure(conf):
37    conf.load('compiler_c')
38    conf.load('compiler_cxx')
39    autowaf.configure(conf)
40    #autowaf.display_header('Evoral Configuration')
41
42    autowaf.check_pkg(conf, 'cppunit', uselib_store='CPPUNIT', atleast_version='1.12.0', mandatory=False)
43    autowaf.check_pkg(conf, 'glib-2.0', uselib_store='GLIB', atleast_version='2.2')
44    autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.14.0')
45    autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD', atleast_version='2.14.0')
46    if not autowaf.is_child():
47        autowaf.check_pkg(conf, 'libpbd-4', uselib_store='LIBPBD', atleast_version='4.0.0', mandatory=True)
48
49    # Boost headers
50    autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp')
51    autowaf.check_header(conf, 'cxx', 'boost/weak_ptr.hpp')
52
53    conf.env['BUILD_TESTS'] = Options.options.build_tests
54    conf.env['TEST_COVERAGE'] = Options.options.test_coverage
55
56    if Options.options.internal_shared_libs:
57        conf.define('INTERNAL_SHARED_LIBS', 1)
58    #autowaf.display_msg(conf, "Unit tests", str(conf.env['BUILD_TESTS']))
59    #print
60
61def build(bld):
62    # Headers
63    #bld.install_files('${INCLUDEDIR}/evoral', 'evoral/*.h')
64    #bld.install_files('${INCLUDEDIR}/evoral', 'evoral/*.h')
65
66    # Pkgconfig file
67    #autowaf.build_pc(bld, 'EVORAL', EVORAL_VERSION, 'GLIBMM GTHREAD')
68
69    libsmf = bld(features = 'c cstlib')
70    libsmf.source = '''
71            libsmf/smf.c
72            libsmf/smf_decode.c
73            libsmf/smf_load.c
74            libsmf/smf_save.c
75            libsmf/smf_tempo.c
76    '''
77    libsmf.export_includes = ['./libsmf']
78    libsmf.defines      = ['SMF_VERSION="1.2"', 'LIBSMF_DLL_EXPORTS']
79    libsmf.includes     = ['./src']
80    libsmf.name         = 'libsmf_internal'
81    libsmf.target       = 'smf_internal'
82    libsmf.uselib       = 'GLIB'
83    libsmf.use          = [ 'libtemporal' ]
84    libsmf.install_path = None
85    if bld.env['build_target'] != 'mingw':
86        libsmf.cxxflags     = [ bld.env['compiler_flags_dict']['pic'] ]
87        libsmf.cflags       = [ bld.env['compiler_flags_dict']['pic'] ]
88
89    lib_source = '''
90            Control.cc
91            ControlList.cc
92            ControlSet.cc
93            Curve.cc
94            Event.cc
95            Note.cc
96            SMF.cc
97            Sequence.cc
98            TimeConverter.cc
99            debug.cc
100    '''
101
102    # Library
103    if bld.is_defined ('INTERNAL_SHARED_LIBS'):
104        obj              = bld.shlib(features = 'c cxx cshlib cxxshlib', source=lib_source)
105        # DLL exports for this library
106        obj.defines      = [ 'LIBEVORAL_DLL_EXPORTS' ]
107    else:
108        obj              = bld.stlib(features = 'c cxx cstlib cxxstlib', source=lib_source)
109        obj.cxxflags     = [ bld.env['compiler_flags_dict']['pic'] ]
110        obj.cflags       = [ bld.env['compiler_flags_dict']['pic'] ]
111        obj.defines      = [ ]
112
113    obj.export_includes = ['.']
114    obj.includes       = ['.', './src']
115    obj.name           = 'libevoral'
116    obj.target         = 'evoral'
117    obj.uselib         = 'GLIBMM GTHREAD SMF XML LIBPBD OSX'
118    obj.use            = 'libsmf_internal libpbd'
119    obj.vnum           = EVORAL_LIB_VERSION
120    obj.install_path   = bld.env['LIBDIR']
121    obj.defines       += [ 'PACKAGE="libevoral"' ]
122
123    if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
124        # Static library (for unit test code coverage)
125        obj = bld(features = 'cxx cstlib')
126        obj.source         = lib_source
127        obj.export_includes = ['.']
128        obj.includes       = ['.', './src']
129        obj.name           = 'libevoral_static'
130        obj.target         = 'evoral_static'
131        obj.uselib         = 'GLIBMM GTHREAD SMF XML LIBPBD'
132        obj.use            = 'libsmf_internal libpbd'
133        obj.vnum           = EVORAL_LIB_VERSION
134        obj.install_path   = ''
135        if bld.env['TEST_COVERAGE']:
136            obj.linkflags      = ['--coverage']
137            obj.cflags         = ['--coverage']
138            obj.cxxflags       = ['--coverage']
139        obj.defines        = ['PACKAGE="libevoral"']
140
141        # Unit tests
142        obj              = bld(features = 'cxx cxxprogram')
143        obj.source       = '''
144                test/SequenceTest.cc
145                test/SMFTest.cc
146                test/RangeTest.cc
147                test/NoteTest.cc
148                test/CurveTest.cc
149                test/testrunner.cc
150        '''
151        obj.includes     = ['.', './src']
152        obj.use          = 'libevoral_static'
153        obj.uselib       = 'GLIBMM GTHREAD SMF XML LIBPBD OSX CPPUNIT'
154        obj.target       = 'run-tests'
155        obj.name         = 'libevoral-tests'
156        obj.install_path = ''
157        obj.defines      = ['PACKAGE="libevoraltest"']
158        if bld.env['TEST_COVERAGE']:
159            obj.linkflags      = ['--coverage']
160            obj.cflags         = ['--coverage']
161            obj.cxxflags       = ['--coverage']
162
163def test(ctx):
164    autowaf.pre_test(ctx, APPNAME)
165    print(os.getcwd())
166    os.environ['EVORAL_TEST_PATH'] = os.path.abspath('../test/testdata/')
167    autowaf.run_tests(ctx, APPNAME, ['./run-tests'])
168    autowaf.post_test(ctx, APPNAME)
169