Skip to content
Snippets Groups Projects
meson.build 2.55 KiB
project('usadelndsoc', ['cpp'],
        version : '0.1',
        meson_version: '>= 0.58.0',
        default_options : ['cpp_std=c++17', 'build.cpp_std=c++17'])

cpp = meson.get_compiler('cpp')

cppad_dep = dependency('cppad', version: '>= 2024')
eigen3_dep = dependency('eigen3')

if not cppad_dep.found()
  cppad_dep = cpp.find_library('libcppad_lib',
                               dirs : [get_option('cppad_lib')],
                               has_headers : ['cppad/cppad.h'],
                               header_include_directories : [get_option('cppad_inc')])
  if not cppad_dep.found()
    cppad_dep = cpp.find_library('cppad_lib',
                                 dirs : [get_option('cppad_lib')],
                                 has_headers : ['cppad/cppad.h'],
                                 header_include_directories : [get_option('cppad_inc')],
                                 required : true)
  endif
endif

if not eigen3_dep.found()
  if cpp.has_header('Eigen/Core', include_directories : [get_option('eigen_lib')])
    eigen3_dep = declare_dependency(include_directories : [get_option('eigen_lib')])
  else
    error('Eigen/Core header not found')
  endif
endif

py_mod = import('python')
py3 = py_mod.find_installation('python3')
py3_dep = py3.dependency()

incdir_numpy = run_command(py3,
  [
    '-c',
    'import numpy; print(numpy.get_include())'
  ],
  check: true
).stdout().strip()
numpy_dep = declare_dependency(
  compile_args : ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'],
  include_directories : [include_directories(incdir_numpy)],
  dependencies  : [py3_dep],
)

incdir_pybind11 = run_command(py3,
  [
    '-c',
    'import pybind11; print(pybind11.get_include())'
  ],
  check: true
).stdout().strip()
inc_pybind11 = include_directories(incdir_pybind11)
pybind11_dep = declare_dependency(
  include_directories : [include_directories(incdir_pybind11)],
  dependencies : [py3_dep]
)
deps = [cppad_dep, eigen3_dep]


cppad_vertest = '#include <string_view>\n#include <cppad/configure.hpp>\nstatic_assert(std::string_view(CPPAD_PACKAGE_STRING) @0@);'
old_cppad = cpp.compiles(cppad_vertest.format('< "cppad-2024"'), dependencies: cppad_dep)
bad_cppad = not old_cppad and cpp.compiles(cppad_vertest.format('<= "cppad-20240000.4"'), dependencies: cppad_dep)

cpp_extra_args = []
if old_cppad
  error('CppAD >= 2024 required')
endif
if bad_cppad
  cpp_extra_args += ['-DHAVE_CPPAD_WORKAROUND_2024']
endif
if cpp_extra_args != []
  summary('CppAD workarounds', cpp_extra_args)
  add_global_arguments(cpp_extra_args, language: 'cpp')
endif

subdir('usadelndsoc')
subdir('doc')