[PATCH ipmi-fru-parser] RFC: use cmake.

Joel Stanley joel at jms.id.au
Mon Mar 7 15:00:51 AEDT 2016


On Fri, Mar 4, 2016 at 9:00 AM, OpenBMC Patches
<openbmc-patches at stwcx.xyz> wrote:
> From: Patrick Williams <patrick at stwcx.xyz>
>
> There was a previous proposal to consider autotools (see
> openbmc/ipmi-fru-parser#7).  This is an alternative implementation
> using cmake.

I'm not a fan of autotools; I have not chosen to use it on small
projects in the past.

That said, I have stopped working on projects due to cmake's
downsides. It's overly complex, and no clear way to implement rules,
making it hard for newbies and experienced developers alike.

I would prefer to see autotools implemented by one of our team members
that has experience with it, and they can help the rest of us maintain
it.

I noticed in my feeds a new project created by some of the Xorg
developers that is a nice example of a clean, well structured project
that uses systemd, dbus, and autotools can be found here:

 https://github.com/libratbag/ratbagd

Cheers,

Joel

> ---
>  .gitignore        | 12 +++++++++
>  CMakeLists.txt    | 30 ++++++++++++++++++++++
>  Makefile          | 75 -------------------------------------------------------
>  cmake/sdbus.cmake | 16 ++++++++++++
>  4 files changed, 58 insertions(+), 75 deletions(-)
>  create mode 100644 .gitignore
>  create mode 100644 CMakeLists.txt
>  delete mode 100644 Makefile
>  create mode 100644 cmake/sdbus.cmake
>
> diff --git a/.gitignore b/.gitignore
> new file mode 100644
> index 0000000..727471a
> --- /dev/null
> +++ b/.gitignore
> @@ -0,0 +1,12 @@
> +#### vi files ####
> +*.swp
> +#### --- vi --- ####
> +
> +#### CMAKE Files ####
> +CMakeCache.txt
> +CMakeFiles
> +CMakeScripts
> +Makefile
> +cmake_install.cmake
> +install_manifest.txt
> +#### --- CMAKE --- ####
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> new file mode 100644
> index 0000000..0a00985
> --- /dev/null
> +++ b/CMakeLists.txt
> @@ -0,0 +1,30 @@
> +cmake_minimum_required(VERSION 3.1)
> +project(ipmi-fru-parser)
> +
> +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
> +set(CMAKE_CXX_STANDARD 14)
> +set(CMAKE_CXX_STANDARD_REQUIRED on)
> +
> +include("cmake/sdbus.cmake")
> +
> +add_library(writefrudata SHARED
> +    frup.c
> +    writefrudata.C
> +)
> +target_link_libraries(writefrudata ${SYSTEMD_LIBRARY})
> +install(TARGETS writefrudata LIBRARY DESTINATION lib/host-ipmid)
> +
> +add_library(strgfnhandler SHARED
> +    strgfnhandler.C
> +)
> +target_link_libraries(strgfnhandler writefrudata)
> +install(TARGETS strgfnhandler LIBRARY DESTINATION lib)
> +
> +add_executable(phosphor-read-eeprom
> +    argument.C
> +    readeeprom.C
> +)
> +target_link_libraries(phosphor-read-eeprom writefrudata)
> +target_link_libraries(phosphor-read-eeprom ${SYSTEMD_LIBRARY})
> +
> +install(TARGETS phosphor-read-eeprom RUNTIME DESTINATION bin)
> diff --git a/Makefile b/Makefile
> deleted file mode 100644
> index dc66a77..0000000
> --- a/Makefile
> +++ /dev/null
> @@ -1,75 +0,0 @@
> -LIBS += libwritefrudata.so
> -HOST_LIBS += libstrgfnhandler.so
> -libwritefrudata.so_OBJS  += frup.o writefrudata.o
> -libstrgfnhandler.so_OBJS += strgfnhandler.o
> -
> -EXES += phosphor-read-eeprom
> -
> -phosphor-read-eeprom_OBJS  += readeeprom.o argument.o
> -phosphor-read-eeprom_EXTRA_LIBS  += writefrudata
> -libstrgfnhandler.so_EXTRA_LIBS  += writefrudata
> -libwritefrudata.so_NEEDED  += libsystemd
> -phosphor-read-eeprom_NEEDED  += libsystemd
> -
> -#### -----------------------------------------------------------------------####
> -#                                                                              #
> -##                       Compilare Regulas Sequi                              ##
> -#                                                                              #
> -#### -----------------------------------------------------------------------####
> -OPTFLAGS ?= -O3 -g -pipe -G -K
> -CFLAGS ?= $(OPTFLAGS)
> -CXXFLAGS ?= $(OPTFLAGS)
> -CFLAGS += -Wall -flto -fPIC
> -CXXFLAGS += --std=gnu++14 -Wall -flto -fPIC
> -
> -__PKG_CONFIG = $(if $1,$(shell pkg-config $2 $1))
> -__EXTRA_LIB_RESOLV = $(if $1,$1)
> -
> -define __BUILD_EXE
> -$1 : $$($1_OBJS) | $$(LIBS) $$(HOST_LIBS)
> -               $$(LINK.cpp) -o $$@ $$^ $(call __EXTRA_LIB_RESOLV,$(addprefix -l,$($1_EXTRA_LIBS))) -L. $(call __PKG_CONFIG,$($1_NEEDED),--libs)
> -
> -$(eval CXXFLAGS += $(call __PKG_CONFIG,$($1_NEEDED),--cflags))
> -
> -#include $$($1_OBJS:.o=.d)
> -endef
> -
> -$(foreach exe,$(EXES),$(eval $(call __BUILD_EXE,$(exe))))
> -
> -define __BUILD_LIB
> -$1 : $$($1_OBJS) | $$(addsuffix .so,$$(addprefix lib,$$($1_EXTRA_LIBS)))
> -               $$(LINK.cpp) -fPIC -shared -o $$@ $$^ $(call __EXTRA_LIB_RESOLV,$(addprefix -l,$($1_EXTRA_LIBS))) -L. $(call __PKG_CONFIG,$($1_NEEDED),--libs)
> -
> -$(eval CXXFLAGS += $(call __PKG_CONFIG,$($1_NEEDED),--cflags))
> -
> -#include $$($1_OBJS:.o=.d)
> -endef
> -
> -$(foreach lib,$(LIBS),$(eval $(call __BUILD_LIB,$(lib))))
> -$(foreach lib,$(HOST_LIBS),$(eval $(call __BUILD_LIB,$(lib))))
> -
> -.PHONY: clean
> -clean:
> -               $(RM) $(foreach exe,$(EXES),$(exe) $($(exe)_OBJS)) \
> -                         $(foreach lib,$(LIBS),$(lib) $($(lib)_OBJS)) \
> -                         $(foreach lib,$(HOST_LIBS),$(lib) $($(lib)_OBJS))
> -
> -DESTDIR ?= /
> -BINDIR ?= /usr/bin
> -LIBDIR ?= /usr/lib
> -
> -.PHONY: install
> -install:
> -               $(if $(EXES),\
> -               install -m 0755 -d $(DESTDIR)$(BINDIR) && \
> -               install -m 0755 $(EXES) $(DESTDIR)$(BINDIR) \
> -               )
> -               $(if $(LIBS),\
> -               install -m 0755 -d $(DESTDIR)$(LIBDIR)/host-ipmid && \
> -               install -m 0755 $(HOST_LIBS) $(DESTDIR)$(LIBDIR)/host-ipmid && \
> -               install -m 0755 $(LIBS) $(DESTDIR)$(LIBDIR) \
> -               )
> -
> -.DEFAULT_GOAL: all
> -.PHONY: all
> -all: $(EXES) $(LIBS)
> diff --git a/cmake/sdbus.cmake b/cmake/sdbus.cmake
> new file mode 100644
> index 0000000..90806f3
> --- /dev/null
> +++ b/cmake/sdbus.cmake
> @@ -0,0 +1,16 @@
> +find_library(SYSTEMD_LIBRARY systemd)
> +if(NOT SYSTEMD_LIBRARY)
> +    message(FATAL_ERROR "Cannot find libsystemd.")
> +endif(NOT SYSTEMD_LIBRARY)
> +
> +find_path(SYSTEMD_SDBUS_INCLUDE "systemd/sd-bus.h")
> +if(NOT SYSTEMD_SDBUS_INCLUDE)
> +    message(FATAL_ERROR "Cannot find sd-bus.h, libsystemd doesn't support?")
> +endif(NOT SYSTEMD_SDBUS_INCLUDE)
> +include_directories(${SYSTEMD_SDBUS_INCLUDE})
> +
> +INCLUDE (CheckLibraryExists)
> +CHECK_LIBRARY_EXISTS(systemd sd_bus_open SYSTEMD_LIBRARY SYSTEMD_HAVE_SDBUS)
> +if(NOT SYSTEMD_HAVE_SDBUS)
> +    message(FATAL_ERROR "libsystemd doesn't support sdbus functions.")
> +endif(NOT SYSTEMD_HAVE_SDBUS)
> --
> 2.7.1
>
>
> _______________________________________________
> openbmc mailing list
> openbmc at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/openbmc


More information about the openbmc mailing list