Allows to compile without libsystemd
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 16 Mar 2017 09:10:58 +0000 (10:10 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 17 Mar 2017 12:01:40 +0000 (13:01 +0100)
This fixes a problem with bitbake when building
native packages.

Change-Id: I28586720010237db578ec55cb5254212c88240e7
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/CMakeLists.txt
src/utils-systemd.c

index b4894b6..903a7de 100644 (file)
@@ -41,7 +41,7 @@ set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
 
 include(FindPkgConfig)
 
-pkg_check_modules(EXTRAS REQUIRED libxml-2.0 openssl xmlsec1 xmlsec1-openssl json-c libsystemd>=222)
+pkg_check_modules(EXTRAS REQUIRED libxml-2.0 openssl xmlsec1 xmlsec1-openssl json-c)
 add_compile_options(${EXTRAS_CFLAGS})
 include_directories(${EXTRAS_INCLUDE_DIRS})
 link_libraries(${EXTRAS_LIBRARIES})
@@ -56,6 +56,15 @@ else()
        add_definitions(-DUSE_LIBZIP=0)
 endif()
 
+pkg_check_modules(libsystemd libsystemd>=222)
+if(libsystemd_FOUND)
+       add_compile_options(${libsystemd_CFLAGS})
+       include_directories(${libsystemd_INCLUDE_DIRS})
+       link_libraries(${libsystemd_LIBRARIES})
+else()
+       add_definitions(-DNO_LIBSYSTEMD)
+endif()
+
 ###########################################################################
 
 if(SIMULATE_SECMGR)
@@ -100,7 +109,6 @@ add_library(utils STATIC
        utils-dir.c
        utils-file.c
        utils-json.c
-       utils-jbus.c
        utils-systemd.c
        verbose.c
        )
@@ -144,38 +152,43 @@ target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
 
 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
 
-###########################################################################
-# the daemons
-MESSAGE(STATUS "Creating daemons")
-
-add_executable(afm-user-daemon afm-user-daemon.c)
-target_link_libraries(afm-user-daemon afm secwrp wgt utils)
-install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
-
-add_executable(afm-system-daemon afm-system-daemon.c)
-target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
-install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
-
-###########################################################################
-# the binding for afb
-
-pkg_check_modules(AFB afb-daemon)
-if(AFB_FOUND)
-       message(STATUS "Creation afm-main-binding for AFB-DAEMON")
-       ###############################################################
-       pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
-       ###############################################################
-       add_library(afm-main-binding MODULE afm-main-binding.c)
-       target_compile_options(afm-main-binding PRIVATE ${AFB_CFLAGS})
-       target_include_directories(afm-main-binding PRIVATE ${AFB_INCLUDE_DIRS})
-       target_link_libraries(afm-main-binding utils ${AFB_LIBRARIES})
-       set_target_properties(afm-main-binding PROPERTIES
-               PREFIX ""
-               LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-binding.export-map"
-       )
-       install(TARGETS afm-main-binding LIBRARY DESTINATION ${afb_binding_install_dir})
-else()
-       message(STATUS "Not creating the binding for AFB-DAEMON")
+if(libsystemd_FOUND)
+       ###########################################################################
+       # the daemons
+
+       MESSAGE(STATUS "Creating daemons")
+
+       add_library(jbus STATIC utils-jbus.c)
+
+       add_executable(afm-user-daemon afm-user-daemon.c)
+       target_link_libraries(afm-user-daemon afm secwrp wgt utils jbus)
+       install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+       add_executable(afm-system-daemon afm-system-daemon.c)
+       target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils jbus)
+       install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+       ###########################################################################
+       # the binding for afb
+
+       pkg_check_modules(AFB afb-daemon)
+       if(AFB_FOUND)
+               message(STATUS "Creation afm-main-binding for AFB-DAEMON")
+               ###############################################################
+               pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
+               ###############################################################
+               add_library(afm-main-binding MODULE afm-main-binding.c)
+               target_compile_options(afm-main-binding PRIVATE ${AFB_CFLAGS})
+               target_include_directories(afm-main-binding PRIVATE ${AFB_INCLUDE_DIRS})
+               target_link_libraries(afm-main-binding utils jbus ${AFB_LIBRARIES})
+               set_target_properties(afm-main-binding PROPERTIES
+                       PREFIX ""
+                       LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-binding.export-map"
+               )
+               install(TARGETS afm-main-binding LIBRARY DESTINATION ${afb_binding_install_dir})
+       else()
+               message(STATUS "Not creating the binding for AFB-DAEMON")
+       endif()
 endif()
 
 ###########################################################################
index b8c3c0b..d804144 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <systemd/sd-bus.h>
-#include <systemd/sd-bus-protocol.h>
+#ifndef NO_LIBSYSTEMD
+# include <systemd/sd-bus.h>
+# include <systemd/sd-bus-protocol.h>
+#else
+  struct sd_bus;
+# define sd_bus_default_user(p)   ((*(p)=NULL),(-ENOTSUP))
+# define sd_bus_default_system(p) ((*(p)=NULL),(-ENOTSUP))
+# define sd_bus_call_method(...)  (-ENOTSUP)
+#endif
 
 #include "utils-systemd.h"