build: use nlohmann-json dependency
Many sources files want to use the 'json.hpp' file from nlohmann,
but when this is installed as a subproject it isn't in the default
search path, unless a dependency to it is explicitly added. In
most cases this is pulled in via the 'Thresholds.hpp' file which is
in-turn linked in by the thresholds static library.
In meson, static libraries shouldn't be linked against directly but
instead indirectly through a 'dependency' relationship, otherwise the
implicit header file needs are not able to be communicated up to users
of the library (such as Thresholds -> json.hpp here). Revamp the
static library relationships to use 'dependencies' rather than
'link_with' so that the header file needs are properly expressed.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Id78aee6af03f10c555aa84edbe9ec44ac04ec342
diff --git a/meson.build b/meson.build
index 6c55635..90ce161 100644
--- a/meson.build
+++ b/meson.build
@@ -63,11 +63,16 @@
thresholds_a = static_library(
'thresholds_a',
'src/Thresholds.cpp',
- dependencies: [ sdbusplus ],
+ dependencies: [ sdbusplus, nlohmann_json ],
implicit_include_directories: false,
include_directories: 'include',
)
+thresholds_dep = declare_dependency(
+ link_with: [ thresholds_a ],
+ dependencies: [ nlohmann_json ],
+)
+
utils_a = static_library(
'utils_a',
['src/Utils.cpp', 'src/SensorPaths.cpp'],
@@ -76,14 +81,24 @@
include_directories: 'include',
)
+utils_dep = declare_dependency(
+ link_with: [ utils_a ],
+ dependencies: [ sdbusplus ],
+)
+
pwmsensor_a = static_library(
'pwmsensor_a',
'src/PwmSensor.cpp',
- dependencies: [ sdbusplus ],
+ dependencies: [ sdbusplus, thresholds_dep ],
implicit_include_directories: false,
include_directories: 'include',
)
+pwmsensor_dep = declare_dependency(
+ link_with: [ pwmsensor_a ],
+ dependencies: [ sdbusplus, thresholds_dep ],
+)
+
subdir('include')
subdir('service_files')
subdir('src')
diff --git a/src/meson.build b/src/meson.build
index c1f77ca..9b6def6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -11,14 +11,12 @@
dependencies: [
gpiodcxx,
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -30,16 +28,14 @@
dependencies: [
gpiodcxx,
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: [
'../include'
] + peci_incdirs,
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -49,14 +45,12 @@
'ExitAirTempSensor.cpp',
dependencies: [
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -67,16 +61,14 @@
'TachSensor.cpp',
'PwmSensor.cpp',
dependencies: [
+ gpiodcxx,
sdbusplus,
- gpiodcxx
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -87,14 +79,12 @@
'HwmonTempSensor.cpp',
dependencies: [
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -104,16 +94,14 @@
'ChassisIntrusionSensor.cpp',
'IntrusionSensorMain.cpp',
dependencies: [
+ gpiodcxx,
i2c,
sdbusplus,
- gpiodcxx,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- utils_a,
- ],
)
endif
@@ -123,14 +111,12 @@
'IpmbSensor.cpp',
dependencies: [
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -141,14 +127,12 @@
dependencies: [
i2c,
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- utils_a,
- thresholds_a,
- ],
)
endif
@@ -161,16 +145,14 @@
'NVMeMCTPContext.cpp',
dependencies: [
i2c,
- sdbusplus,
mctp,
- ],
+ sdbusplus,
+ thresholds_dep,
+ utils_dep,
+ ],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- utils_a,
- thresholds_a,
- ],
)
endif
@@ -181,16 +163,14 @@
'PSUSensor.cpp',
'PSUSensorMain.cpp',
dependencies: [
+ pwmsensor_dep,
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- pwmsensor_a,
- thresholds_a,
- utils_a,
- ],
)
endif
@@ -201,13 +181,11 @@
'ExternalSensorMain.cpp',
dependencies: [
sdbusplus,
+ thresholds_dep,
+ utils_dep,
],
implicit_include_directories: false,
include_directories: '../include',
install: true,
- link_with: [
- thresholds_a,
- utils_a,
- ],
)
endif