meson.build 5.1 KB
Newer Older
1
project('libgit2-glib', 'c',
Alberto Fanjul's avatar
Alberto Fanjul committed
2
        version: '0.27.7',
3 4 5 6
        default_options: [
          'buildtype=debugoptimized'
        ],
        license: 'LGPL2+',
7
        meson_version: '>= 0.48.0')
8 9 10 11 12 13 14

libgit2_glib_version = meson.project_version()
version_array = libgit2_glib_version.split('.')
libgit2_glib_major_version = version_array[0].to_int()
libgit2_glib_minor_version = version_array[1].to_int()
libgit2_glib_micro_version = version_array[2].to_int()

15
libgit2_glib_api_version = '1.0'
16
libgit2_glib_api_name = '@0@-@1@'.format(meson.project_name(), libgit2_glib_api_version)
17

18 19
libgit2_glib_ns = 'Ggit'

20 21
libgit2_glib_buildtype = get_option('buildtype')

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# The interface age is reset every time we add new API; this
# should only happen during development cycles, otherwise the
# interface age is the same as the micro version
if libgit2_glib_minor_version.is_odd()
  libgit2_glib_interface_age = 0
else
  libgit2_glib_interface_age = libgit2_glib_micro_version
endif

soversion = 0
# maintaining compatibility with the previous libtool versioning
# current = minor * 100 + micro - interface
# revision = interface
current = libgit2_glib_minor_version * 100 + libgit2_glib_micro_version - libgit2_glib_interface_age
revision = libgit2_glib_interface_age
libversion = '@0@.@1@.@2@'.format(soversion, current, revision)

libgit2_glib_prefix = get_option('prefix')
libgit2_glib_libdir = join_paths(libgit2_glib_prefix, get_option('libdir'))
libgit2_glib_includedir = join_paths(libgit2_glib_prefix, get_option('includedir'))
libgit2_glib_datadir = join_paths(libgit2_glib_prefix, get_option('datadir'))

44 45
libgit2_glib_pkgincludedir = join_paths(libgit2_glib_includedir, libgit2_glib_api_name, meson.project_name())

46 47
cc = meson.get_compiler('c')

48
# Compiler and Debugging flags
49
if cc.get_id() == 'msvc'
50 51
  # Compiler options taken from msvc_recommended_pragmas.h
  # in GLib, based on _Win32_Programming_ by Rector and Newcomer
52
  common_flags = ['-FImsvc_recommended_pragmas.h']
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
else
  test_cflags = [
    '-ffast-math',
    '-fstrict-aliasing',
    '-Wpointer-arith',
    '-Wmissing-declarations',
    '-Wformat=2',
    '-Wstrict-prototypes',
    '-Wmissing-prototypes',
    '-Wnested-externs',
    '-Wold-style-definition',
    '-Wdeclaration-after-statement',
    '-Wunused',
    '-Wuninitialized',
    '-Wshadow',
    '-Wmissing-noreturn',
    '-Wmissing-format-attribute',
    '-Wredundant-decls',
    '-Wlogical-op',
    '-Wcast-align',
    '-Wno-unused-local-typedefs',
    '-Werror=implicit',
    '-Werror=init-self',
    '-Werror=main',
    '-Werror=missing-braces',
    '-Werror=return-type',
    '-Werror=array-bounds',
    '-Werror=write-strings'
  ]
82 83

  common_flags = cc.get_supported_arguments(test_cflags)
84 85
endif

86 87
if libgit2_glib_buildtype.contains('debug')
  common_flags += [ '-DLIBGIT2_GLIB_ENABLE_DEBUG' ]
88

89 90
  if libgit2_glib_buildtype.contains('optimized')
    common_flags += [ '-DG_DISABLE_CAST_CHECKS' ]
91
  endif
92 93 94 95
else
  common_flags += [
    '-DG_DISABLE_CAST_CHECKS',
    '-DG_DISABLE_CHECKS'
96 97 98
  ]
endif

99 100 101
# Workaround for meson's bug
# https://github.com/mesonbuild/meson/pull/1896
if get_option('b_ndebug') == true
102
  common_flags += [ '-DG_DISABLE_ASSERT' ]
103 104
endif

105 106 107 108
add_project_arguments(common_flags, language: 'c')

# Termios
have_termios = cc.has_header('termios.h')
109 110 111 112 113 114

extra_args= []

core_inc = include_directories('.')

# Required dependencies
115 116
git2_req = '0.25.0'
glib_req = '2.44.0'
117

118 119 120
glib_dep = dependency('glib-2.0', version: '>=' + glib_req)
gobject_dep = dependency('gobject-2.0', version: '>=' + glib_req)
gio_dep = dependency('gio-2.0', version: '>=' + glib_req)
121

122
libgit2_dep = dependency('libgit2', version: '>=' + git2_req)
123

124 125
enable_gir = get_option('introspection')
if enable_gir
126
  # XXX: Not nice, but probably our best option
127
  enable_gir = find_program('g-ir-scanner', required: false).found() and not meson.is_cross_build()
128 129
endif

130 131 132 133
enable_vapi = get_option('vapi')
if enable_vapi
  assert(enable_gir, 'vapi support was requested, but introspection support is mandatory.')
  assert(add_languages('vala', required: false), 'vapi support was requested, but vala not found.')
134 135

  meson.add_install_script('meson_vapi_link.py', libgit2_glib_datadir)
136 137
endif

138
# Check for libgit2 ssh support
139 140 141
enable_ssh = get_option('ssh')
if enable_ssh
  libgit2_ssh_src = '''
142 143 144 145 146 147 148
    #include <git2.h>
    int
    main(int argc, const char *argv[])
    {
            git_libgit2_init ();
            return ((git_libgit2_features() & GIT_FEATURE_SSH) != 0) ? 0 : 1;
    }
149
  '''
150

151
  assert(cc.compiles(libgit2_ssh_src, name: 'libgit2 supports SSH'), 'libgit2 ssh support was requested, but not found. Use -Dssh=false to build without it.')
152 153
endif

154 155 156 157 158 159 160 161 162 163
# Check for python
enable_python = get_option('python')
if enable_python
  python = import('python3')

  python_req = '3.2.3'

  dependency('pygobject-3.0', version: '>= 3.0.0')
  assert(python.language_version().version_compare('>= ' + python_req), 'python support was requested, but version >= ' + python_req + ' not found.')

164
  meson.add_install_script('meson_python_compile.py', libgit2_glib_libdir)
165 166
endif

167
gnome = import('gnome')
168
pkg = import('pkgconfig')
169 170 171 172 173

subdir('libgit2-glib')
subdir('examples')
subdir('tests')

174 175
if get_option('gtk_doc')
  subdir('docs/reference')
176
endif