build: add support for meson

Change-Id: I5a76281cc6060afffc1d77e52f03acb34669856c
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..1fd04b5
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,158 @@
+project(
+    'openpower-proc-control',
+    'cpp',
+    default_options: [
+        'warning_level=3',
+        'werror=true',
+        'cpp_std=c++17'
+    ],
+    license: 'Apache-2.0',
+    version: '1.0',
+)
+add_project_arguments('-Wno-psabi', language: 'cpp')
+
+cxx = meson.get_compiler('cpp')
+
+extra_sources = []
+extra_dependencies = []
+extra_unit_files = []
+
+unit_subs = configuration_data()
+unit_subs.set('bindir', get_option('bindir'))
+unit_subs.set('ENABLE_PHAL_TRUE', '')
+
+if get_option('phal').enabled() and get_option('p9').enabled()
+    error('phal and p9 cannot be selected at the same time')
+endif
+
+build_p9 = not get_option('p9').disabled()
+build_openfsi = not get_option('openfsi').disabled()
+build_phal = get_option('phal').enabled()
+
+if get_option('phal').enabled() and not get_option('p9').disabled()
+    build_p9 = false
+endif
+
+summary('building p9', build_p9)
+summary('building openfsi', build_openfsi)
+summary('building phal', build_phal)
+
+if build_p9
+    extra_sources += [
+        'procedures/p9/cleanup_pcie.cpp',
+        'procedures/p9/set_sync_fsi_clock_mode.cpp',
+        'procedures/p9/start_host.cpp',
+        'procedures/p9/start_host_mpreboot.cpp',
+    ]
+endif
+if build_openfsi
+    extra_sources += [
+        'procedures/openfsi/scan.cpp',
+    ]
+endif
+if build_phal
+    extra_sources += [
+        'procedures/phal/start_host.cpp',
+        'procedures/phal/set_SPI_mux.cpp',
+        'phalerror/create_pel.cpp',
+        'phalerror/phal_error.cpp',
+    ]
+    extra_dependencies += [
+        dependency('libdt-api'),
+        dependency('fmt'),
+        cxx.find_library('ekb'),
+        cxx.find_library('ipl'),
+    ]
+    extra_unit_files = [
+        'set-spi-mux.service',
+        'phal-reinit-devtree.service',
+    ]
+    unit_subs.set('ENABLE_PHAL_TRUE', '#')
+endif
+
+executable(
+    'openpower-proc-control',
+    [
+        'cfam_access.cpp',
+        'ext_interface.cpp',
+        'filedescriptor.cpp',
+        'proc_control.cpp',
+        'registration.cpp',
+        'targeting.cpp',
+        'procedures/common/cfam_overrides.cpp',
+        'procedures/common/cfam_reset.cpp',
+        'procedures/common/enter_mpreboot.cpp',
+        'procedures/common/collect_sbe_hb_data.cpp',
+    ] + extra_sources,
+    dependencies: [
+        dependency('libgpiodcxx'),
+        cxx.find_library('pdbg'),
+        dependency('phosphor-dbus-interfaces'),
+        dependency('phosphor-logging'),
+        dependency('sdbusplus'),
+        dependency('threads'),
+    ] + extra_dependencies
+)
+
+executable(
+    'openpower-proc-nmi',
+    [
+        'nmi_main.cpp',
+        'nmi_interface.cpp',
+    ],
+    dependencies: [
+        cxx.find_library('pdbg'),
+        dependency('phosphor-dbus-interfaces'),
+        dependency('phosphor-logging'),
+        dependency('sdbusplus'),
+   ]
+)
+
+unit_files = [
+    'pcie-poweroff@.service',
+    'xyz.openbmc_project.Control.Host.NMI.service',
+    'op-stop-instructions@.service',
+    'op-cfam-reset.service',
+    'op-continue-mpreboot@.service',
+    'op-enter-mpreboot@.service',
+] + extra_unit_files
+
+systemd_system_unit_dir = dependency('systemd').get_pkgconfig_variable(
+    'systemdsystemunitdir',
+    define_variable: ['prefix', get_option('prefix')])
+foreach u : unit_files
+    configure_file(
+        configuration: unit_subs,
+        input: u + '.in',
+        install: true,
+        install_dir: systemd_system_unit_dir,
+        output: u
+    )
+endforeach
+
+if not get_option('tests').disabled()
+    gtest = dependency('gtest', main: true, disabler: true, required: false)
+    if not gtest.found() and build_tests.enabled()
+        cmake = import('cmake')
+        gtest_subproject = cmake.subproject('gtest')
+        cm_gtest = gtest_subproject.dependency('gtest')
+        cm_gtest_main = gtest_subproject.dependency('gtest_main')
+        gtest = declare_dependency(dependencies: [cm_gtest, cm_gtest_main, threads])
+    endif
+
+    test(
+        'utest',
+        executable(
+            'utest',
+            'test/utest.cpp',
+            'targeting.cpp',
+            'filedescriptor.cpp',
+            dependencies: [
+                gtest,
+                dependency('phosphor-logging'),
+            ],
+            implicit_include_directories: false,
+            include_directories: '.',
+        )
+    )
+endif