build: Some minor refactoring
Change-Id: I169d24356b883ba73327e1c6ab8d87a2398ced90
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/.gitignore b/.gitignore
index 6da54be..13d3d3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
build*/
subprojects/*
-!subprojects/*.wrap
+!subprojects/googletest.wrap
+!subprojects/phosphor-host-ipmid.wrap
diff --git a/meson.build b/meson.build
index e66c3c3..cac384b 100644
--- a/meson.build
+++ b/meson.build
@@ -3,48 +3,40 @@
'cpp',
version: '1.0',
default_options: [
- 'buildtype=debugoptimized',
'cpp_std=c++23',
'warning_level=3',
'werror=true',
],
- meson_version: '>=1.1.1',
-)
+ meson_version: '>=1.1.1')
-conf_data = configuration_data()
-conf_data.set('ENABLE_GOOGLE', get_option('google_oen').allowed().to_int())
-configure_file(
- output: 'config.h',
- configuration: conf_data,
-)
+ethstats_pre = declare_dependency(
+ include_directories: include_directories('.'),
+ dependencies: dependency('libipmid'))
-ipmid_dep = dependency('libipmid')
-
-ethstatscmd_common_lib = static_library(
+ethstats_lib = static_library(
'ethstatscmd_common',
'ethstats.cpp',
'handler.cpp',
- dependencies: [
- ipmid_dep,
- ],
-)
+ implicit_include_directories: false,
+ dependencies: ethstats_pre)
-ethstatscmd_common_dep = declare_dependency(
- link_with: ethstatscmd_common_lib,
-)
+ethstats_dep = declare_dependency(
+ dependencies: ethstats_pre,
+ link_with: ethstats_lib)
-ethstatscmd_lib = library(
+conf_data = configuration_data()
+conf_data.set10('ENABLE_GOOGLE', get_option('google_oen'))
+
+shared_library(
'ethstatscmd',
+ configure_file(output: 'config.h', configuration: conf_data),
'main.cpp',
- dependencies: [
- ethstatscmd_common_dep,
- ipmid_dep,
- ],
- override_options: [ 'b_lundef=false' ],
+ implicit_include_directories: false,
+ dependencies: ethstats_dep,
+ override_options: 'b_lundef=false',
version: meson.project_version(),
install: true,
- install_dir: get_option('libdir') / 'ipmid-providers',
-)
+ install_dir: get_option('libdir') / 'ipmid-providers')
if get_option('tests').allowed()
subdir('test')
diff --git a/meson_options.txt b/meson_options.txt
index 70c130e..5c5aace 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,12 +1,2 @@
-option(
- 'tests',
- type: 'feature',
- value: 'enabled',
- description: 'Build tests',
-)
-option(
- 'google_oen',
- type: 'feature',
- value: 'enabled',
- description: 'Enable the Google OEN handler',
-)
+option('tests', type: 'feature', description: 'Build tests')
+option('google_oen', type: 'boolean', description: 'Enable the Google OEN handler')
diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap
new file mode 100644
index 0000000..56da9ef
--- /dev/null
+++ b/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD
diff --git a/subprojects/phosphor-host-ipmid.wrap b/subprojects/phosphor-host-ipmid.wrap
index 29bb550..55261f6 100644
--- a/subprojects/phosphor-host-ipmid.wrap
+++ b/subprojects/phosphor-host-ipmid.wrap
@@ -4,5 +4,3 @@
[provide]
libipmid = ipmid_dep
-libchannellayer = channellayer_dep
-libuserlayer = userlayer_dep
diff --git a/test/ethstats_unittest.cpp b/test/ethstats.cpp
similarity index 99%
rename from test/ethstats_unittest.cpp
rename to test/ethstats.cpp
index 41a2c62..db60319 100644
--- a/test/ethstats_unittest.cpp
+++ b/test/ethstats.cpp
@@ -1,4 +1,5 @@
#include "ethstats.hpp"
+
#include "handler_mock.hpp"
#include <cstdint>
diff --git a/test/meson.build b/test/meson.build
index 727f53e..4fccb10 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,19 +1,36 @@
-gtest_dep = dependency('gtest', main: true)
-gmock_dep = dependency('gmock')
+gtest = dependency('gtest', main: true, disabler: true, required: false)
+gmock = dependency('gmock', disabler: true, required: false)
+if not gtest.found() or not gmock.found()
+ gtest_opts = import('cmake').subproject_options()
+ gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
+ gtest_proj = import('cmake').subproject(
+ 'googletest',
+ options: gtest_opts,
+ required: false)
+ if gtest_proj.found()
+ gtest = declare_dependency(
+ dependencies: [
+ dependency('threads'),
+ gtest_proj.dependency('gtest'),
+ gtest_proj.dependency('gtest_main'),
+ ])
+ gmock = gtest_proj.dependency('gmock')
+ else
+ assert(not get_option('tests').enabled(), 'Googletest is required')
+ endif
+endif
-test(
- 'test_ethstats',
- executable(
- 'test-ethstats',
- 'ethstats_unittest.cpp',
- include_directories: [
- '..',
- ],
- dependencies: [
- ethstatscmd_common_dep,
- gmock_dep,
- gtest_dep,
- ipmid_dep,
- ],
- ),
-)
+gtests = {
+ 'ethstats': [ethstats_dep, gmock, gtest],
+}
+
+foreach t, deps : gtests
+ test(
+ t,
+ executable(
+ t.underscorify(), t + '.cpp',
+ build_by_default: false,
+ implicit_include_directories: false,
+ cpp_args: '-Wno-missing-braces',
+ dependencies: deps))
+endforeach