meson.build 3.44 KB
Newer Older
1 2
project('spdlog', ['cpp'],
  license         : 'MIT',
3
  version         : run_command(find_program('scripts/extract_version.py')).stdout().strip(),
4 5 6 7 8 9
  default_options : [
    'warning_level=3',
    'cpp_std=c++11',
    'buildtype=release',
    'b_colorout=always',
  ],
10 11 12 13 14 15 16 17 18 19 20 21
)

# ------------------------
# ---   Dependencies   ---
# ------------------------
dep_list = []
compile_args = []

# Threads
dep_list += dependency('threads')

# Check for FMT
22
if get_option('external_fmt')
23
  if not meson.version().version_compare('>=0.49.0')
24
    warning('Finding fmt can fail with meson versions before 0.49.0')
25 26 27 28 29
  endif
  dep_list     += dependency('fmt')
  compile_args += '-DSPDLOG_FMT_EXTERNAL'
endif

gabime's avatar
gabime committed
30 31 32 33
if get_option('no_exceptions')
  compile_args += '-DSPDLOG_NO_EXCEPTIONS'
endif

34 35 36 37 38 39
# ------------------------------------
# ---   Compiled library version   ---
# ------------------------------------

spdlog_inc = include_directories('./include')

gabime's avatar
gabime committed
40 41 42 43 44 45 46 47 48
spdlog_srcs = files([
    'src/async.cpp',
    'src/color_sinks.cpp',
    'src/file_sinks.cpp',
    'src/fmt.cpp',
    'src/spdlog.cpp',
    'src/stdout_sinks.cpp'
])

49
if get_option('library_type') == 'static'
gabime's avatar
gabime committed
50 51 52
  spdlog = static_library(
    'spdlog',
    spdlog_srcs,
53 54 55
    cpp_args            : [compile_args] + ['-DSPDLOG_COMPILED_LIB'],
    include_directories : spdlog_inc,
    dependencies        : dep_list,
gabime's avatar
gabime committed
56 57
    install             : not meson.is_subproject()
    )
58
else
gabime's avatar
gabime committed
59 60
  spdlog = shared_library('spdlog',
    spdlog_srcs,
61 62 63 64 65 66
    cpp_args            : [compile_args] + ['-DSPDLOG_COMPILED_LIB'],
    include_directories : spdlog_inc,
    dependencies        : dep_list,
    install             : not meson.is_subproject(),
  )
endif
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

spdlog_dep = declare_dependency(
  link_with           : spdlog,
  include_directories : spdlog_inc,
  compile_args        : compile_args + ['-DSPDLOG_COMPILED_LIB'],
  dependencies        : dep_list,
  version             : meson.project_version(),
)

# ----------------------------------
# ---   Header only dependency   ---
# ----------------------------------

spdlog_headeronly_dep = declare_dependency(
  include_directories : spdlog_inc,
  compile_args        : compile_args,
  dependencies        : dep_list,
  version             : meson.project_version(),
)

# ------------------------
# ---   Installation   ---
# ------------------------

91 92 93 94 95 96 97 98 99 100 101 102
# Do not install when spdlog is used as a subproject
if not meson.is_subproject()
  install_subdir('include/spdlog', install_dir: get_option('includedir'))

  pkg = import('pkgconfig')
  pkg.generate(spdlog,
    name         : 'spdlog',
    description  : 'Fast C++ logging library',
    url          : 'https://github.com/gabime/spdlog',
    extra_cflags : ['-DSPDLOG_COMPILED_LIB']
  )
endif
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

# -------------------------------------
# ---   Conditionally add subdirs   ---
# -------------------------------------

if get_option('enable_tests')
  subdir('tests')
endif

if get_option('enable_examples')
  subdir('example')
endif

if get_option('enable_benchmarks')
  subdir('bench')
endif

# -------------------
# ---   Summary   ---
# -------------------

summary_str = '''spdlog build summary:

126
  - using external fmt:  @0@
127 128 129
  - building tests:      @1@
  - building examples:   @2@
  - building benchmarks: @3@
130
  - library type:        @4@
gabime's avatar
gabime committed
131
  - no exceptions:       @5@
132
'''.format(
133
  get_option('external_fmt'),
134 135
  get_option('enable_tests'),
  get_option('enable_examples'),
136
  get_option('enable_benchmarks'),
gabime's avatar
gabime committed
137 138
  get_option('library_type'),
  get_option('no_exceptions')
139 140 141
)

message(summary_str)