meson: Use boost as a dependency

Currently boost library is found via the 'cpp.find_library' call. With
this method local build of the project requires host to have the boost
libraries installed.
Since the meson have a subproject system to download missing
dependencies, rewrite boost requirement to a 'dependency' object. This
way it would be possible to build the project locally on the system
without the boost library installed.

Tested:
Both local meson build and Yocto build are performed successfully.

Change-Id: I082aeb1d6c09627ea53f58cb6cd375f080401d57
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
diff --git a/.gitignore b/.gitignore
index 955db77..f0b223f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,6 @@
 /subprojects/*
 !/subprojects/*.wrap
 subprojects/CLI11.wrap
-subprojects/boost.wrap
 subprojects/function2.wrap
 subprojects/googletest.wrap
 subprojects/stdplus.wrap
diff --git a/libipmid/meson.build b/libipmid/meson.build
index e573ed4..ebd932c 100644
--- a/libipmid/meson.build
+++ b/libipmid/meson.build
@@ -1,5 +1,5 @@
 ipmid_pre = [
-  boost_coroutine,
+  boost,
   phosphor_dbus_interfaces_dep,
   phosphor_logging_dep,
   sdbusplus_dep,
diff --git a/meson.build b/meson.build
index 4d762d8..6ec5dca 100644
--- a/meson.build
+++ b/meson.build
@@ -7,6 +7,7 @@
     'werror=true',
     'warning_level=3',
     'cpp_std=c++23',
+    'b_lto=true',
   ])
 
 # Setting up config data
@@ -108,13 +109,40 @@
   language: 'cpp')
 
 # Dependencies
+
+boost = dependency(
+  'boost',
+  modules: [
+    'coroutine',
+  ],
+  required : false,
+)
+
+if not boost.found()
+  cmake = import('cmake')
+  opt = cmake.subproject_options()
+  opt.add_cmake_defines({
+    'BOOST_INCLUDE_LIBRARIES': 'asio;bimap;callable_traits;context;coroutine;interprocess;multiprecision;process',
+    'CMAKE_POSITION_INDEPENDENT_CODE': true
+  })
+  boost_cmake = cmake.subproject('boost', required: true, options: opt)
+  boost_asio = boost_cmake.dependency('boost_asio').as_system()
+  boost_bimap = boost_cmake.dependency('boost_bimap').as_system()
+  boost_callable_traits = boost_cmake.dependency('boost_callable_traits').as_system()
+  boost_context = boost_cmake.dependency('boost_context').as_system()
+  boost_coroutine = boost_cmake.dependency('boost_coroutine').as_system()
+  boost_interprocess = boost_cmake.dependency('boost_interprocess').as_system()
+  boost_multiprecision = boost_cmake.dependency('boost_multiprecision').as_system()
+  boost_process = boost_cmake.dependency('boost_process').as_system()
+  boost = [boost_asio, boost_bimap, boost_callable_traits, boost_context, boost_coroutine, boost_interprocess, boost_multiprecision, boost_process]
+endif
+
 phosphor_logging_dep = dependency('phosphor-logging')
 phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
 sdeventplus_dep = dependency('sdeventplus')
 systemd = dependency('systemd')
 crypto = dependency('libcrypto', version : '>=1.0.2g')
 pam = cpp.find_library('pam', required: true)
-boost_coroutine = cpp.find_library('boost_coroutine', required: true)
 sdbusplus_dep = dependency('sdbusplus')
 stdplus_dep = dependency('stdplus')
 
@@ -196,7 +224,7 @@
   stdplus_dep,
   phosphor_logging_dep,
   phosphor_dbus_interfaces_dep,
-  boost_coroutine,
+  boost,
   crypto,
   ipmid_dep,
   channellayer_dep,
diff --git a/softoff/meson.build b/softoff/meson.build
index f34ad98..cdc5d03 100644
--- a/softoff/meson.build
+++ b/softoff/meson.build
@@ -6,7 +6,7 @@
   sdbusplus_dep,
   systemd,
   softoff_dbus,
-  boost_coroutine
+  boost
 ]
 
 softpower_lib = static_library(
diff --git a/subprojects/boost.wrap b/subprojects/boost.wrap
new file mode 100644
index 0000000..5912c6f
--- /dev/null
+++ b/subprojects/boost.wrap
@@ -0,0 +1,9 @@
+[wrap-file]
+directory = boost-1.84.0
+
+source_url = https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.gz
+source_hash = 4d27e9efed0f6f152dc28db6430b9d3dfb40c0345da7342eaa5a987dde57bd95
+source_filename = 1_84_0.tar.gz
+
+[provide]
+boost = boost_dep
diff --git a/test/meson.build b/test/meson.build
index c8918f9..b2b9929 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -58,7 +58,7 @@
     include_directories: root_inc,
     build_by_default: false,
     implicit_include_directories: false,
-    dependencies: [boost_coroutine, phosphor_logging_dep, crypto, systemd, sdbusplus_dep, gtest, gmock]
+    dependencies: [boost, phosphor_logging_dep, crypto, systemd, sdbusplus_dep, gtest, gmock]
   ))
 
 # Build/add closesession_unittest to test suite