build: Switch to meson & c++20 & remove cmake
This commit would add the meson build system support
for the phosphor-post-code-manager repository and also
switch's the compiler standard to c++20 (so that we can
leverage the latest C++ constructs).
This commit also add's the cereal dependency. There are
source files that assume cereal header files will be present
without the meson build explicitly finding that dependency.
This leads to compile failure when running in subproject mode.
Tested By:
1. Compile post-code-manager using
meson builddir
ninja -C builddir
2. copy that executable on to bmc
3. was able to run it and make sure it hosts the dbus interfaces like
it used to.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I342108ea3843c3990385a432c4c540e20b9db4cc
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 2e4cd89..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
-project(post-code-manager CXX)
-option (
- ENABLE_BIOS_POST_CODE_LOG
- "Enable Bios Post Code Logging"
- OFF
-)
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-
-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
-include(GNUInstallDirs)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-set(DBUS_OBJECT_NAME "xyz/openbmc_project/State/Boot/PostCode0")
-set(DBUS_INTF_NAME "xyz.openbmc_project.State.Boot.PostCode")
-set(MAX_BOOT_CYCLE_COUNT 100 CACHE STRING "Max boot count Value")
-if(NOT MAX_BOOT_CYCLE_COUNT MATCHES "^([1-9][0-9]?|100)$")
- message(FATAL_ERROR "Maximum boot cycle count must be a number from 1 to 100")
-endif()
-
-add_definitions(-DDBUS_OBJECT_NAME="/${DBUS_OBJECT_NAME}")
-add_definitions(-DDBUS_INTF_NAME="${DBUS_INTF_NAME}")
-add_definitions(-DMAX_BOOT_CYCLE_COUNT=${MAX_BOOT_CYCLE_COUNT})
-
-set(SRC_FILES src/post_code.cpp
- src/main.cpp )
-set ( SERVICE_FILES
- service_files/xyz.openbmc_project.State.Boot.PostCode.service
- service_files/xyz.openbmc_project.State.Boot.PostCode@.service )
-
-# import sdbusplus
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(SDBUSPLUSPLUS sdbusplus REQUIRED)
-include_directories(${SDBUSPLUSPLUS_INCLUDE_DIRS})
-link_directories(${SDBUSPLUSPLUS_LIBRARY_DIRS})
-find_program(SDBUSPLUSPLUS sdbus++)
-
-# import phosphor-logging
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(LOGGING phosphor-logging REQUIRED)
-include_directories(${LOGGING_INCLUDE_DIRS})
-link_directories(${LOGGING_LIBRARY_DIRS})
-
-# phosphor-dbus-interfaces
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(DBUSINTERFACE phosphor-dbus-interfaces REQUIRED)
-include_directories(${DBUSINTERFACE_INCLUDE_DIRS})
-link_directories(${DBUSINTERFACE_LIBRARY_DIRS})
-
-add_executable(${PROJECT_NAME} ${SRC_FILES})
-target_link_libraries(${PROJECT_NAME} ${DBUSINTERFACE_LIBRARIES} )
-target_link_libraries(${PROJECT_NAME} "${SDBUSPLUSPLUS_LIBRARIES} -lphosphor_dbus")
-
-install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
-target_compile_definitions (
- ${PROJECT_NAME} PRIVATE $<$<BOOL:${ENABLE_BIOS_POST_CODE_LOG}>: -DENABLE_BIOS_POST_CODE_LOG>
-)
-install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
diff --git a/inc/post_code.hpp b/inc/post_code.hpp
index 98af300..498a0d8 100644
--- a/inc/post_code.hpp
+++ b/inc/post_code.hpp
@@ -14,6 +14,7 @@
// limitations under the License.
*/
#pragma once
+#include <config.h>
#include <fcntl.h>
#include <unistd.h>
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..2c44f72
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,79 @@
+project(
+ 'post-code-manager',
+ 'cpp',
+ default_options: [
+ 'cpp_std=c++20',
+ 'warning_level=3',
+ 'werror=true',
+ ],
+ license: 'Apache-2.0',
+ meson_version: '>=0.57.0',
+ version: '1.0',
+)
+
+
+conf_data = configuration_data()
+conf_data.set_quoted('DBUS_OBJECT_NAME', '/xyz/openbmc_project/State/Boot/PostCode0')
+conf_data.set_quoted('DBUS_INTF_NAME','xyz.openbmc_project.State.Boot.PostCode')
+conf_data.set('MAX_BOOT_CYCLE_COUNT',get_option('max-boot-cycle-count'))
+
+if get_option('bios-post-code-log').enabled()
+ add_project_arguments('-DENABLE_BIOS_POST_CODE_LOG',language: 'cpp')
+endif
+
+configure_file(output: 'config.h',
+ configuration: conf_data
+)
+
+sdbusplus = dependency(
+ 'sdbusplus',
+ fallback: ['sdbusplus', 'sdbusplus_dep']
+)
+
+phosphor_logging = dependency(
+ 'phosphor-logging',
+ fallback: [
+ 'phosphor-logging',
+ 'phosphor_logging_dep'])
+
+phosphor_dbus_interfaces = dependency(
+ 'phosphor-dbus-interfaces',
+ fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep']
+)
+
+cxx = meson.get_compiler('cpp')
+cereal_dep = dependency('cereal', required: false)
+has_cereal = cxx.has_header_symbol(
+ 'cereal/cereal.hpp',
+ 'cereal::specialize',
+ dependencies: cereal_dep,
+ required: false)
+if not has_cereal
+ cereal_opts = import('cmake').subproject_options()
+ cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
+ cereal_proj = import('cmake').subproject(
+ 'cereal',
+ options: cereal_opts,
+ required: false)
+ assert(cereal_proj.found(), 'cereal is required')
+ cereal_dep = cereal_proj.dependency('cereal')
+endif
+
+systemd_system_unit_dir = dependency('systemd').get_variable(
+ pkgconfig: 'systemdsystemunitdir')
+
+install_subdir('service_files',
+ install_dir : systemd_system_unit_dir,
+ strip_directory : true)
+
+executable(
+ 'post-code-manager',
+ 'src/main.cpp',
+ 'src/post_code.cpp',
+ install: true,
+ dependencies: [
+ sdbusplus,
+ phosphor_dbus_interfaces,
+ phosphor_logging,
+ cereal_dep],
+ include_directories: 'inc')
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..c3d63fd
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('max-boot-cycle-count', type:'integer', min:1, max: 100, description: 'Maximum boot cycles for which the post codes should be persisted', value:100)
+option('bios-post-code-log', type:'feature',description:'bios post code log',value:'disabled')
diff --git a/subprojects/cereal.wrap b/subprojects/cereal.wrap
new file mode 100644
index 0000000..a4cb7ec
--- /dev/null
+++ b/subprojects/cereal.wrap
@@ -0,0 +1,4 @@
+[wrap-git]
+url = https://github.com/USCiLab/cereal.git
+revision = HEAD
+# need at least for C++20 fixes 3e4d1b84cab4891368d2179a61a7ba06a5693e7f
diff --git a/subprojects/phosphor-dbus-interfaces.wrap b/subprojects/phosphor-dbus-interfaces.wrap
new file mode 100644
index 0000000..935a8b2
--- /dev/null
+++ b/subprojects/phosphor-dbus-interfaces.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-dbus-interfaces.git
+revision = HEAD
diff --git a/subprojects/phosphor-logging.wrap b/subprojects/phosphor-logging.wrap
new file mode 100644
index 0000000..a039fcf
--- /dev/null
+++ b/subprojects/phosphor-logging.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-logging.git
+revision = HEAD
diff --git a/subprojects/sdbusplus.wrap b/subprojects/sdbusplus.wrap
new file mode 100644
index 0000000..d470130
--- /dev/null
+++ b/subprojects/sdbusplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdbusplus.git
+revision = HEAD