--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the License);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an AS IS BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+cmake_minimum_required (VERSION 2.8.3)
+project (sdbd)
+
+option(USE_FUNCTION_FS "Use FunctionFS" NO)
+option(BUILD_UNIT_TESTS "Build unit tests" NO)
+
+set(sdbd_SRCS
+ src/sdb.c
+ src/fdevent.c
+ src/transport.c
+ src/transport_local.c
+ src/transport_usb.c
+ src/sockets.c
+ src/services.c
+ src/file_sync_service.c
+ src/utils.c
+ src/socket_inaddr_any_server.c
+ src/socket_local_client.c
+ src/socket_local_server.c
+ src/socket_loopback_client.c
+ src/socket_loopback_server.c
+ src/socket_network_client.c
+ src/properties.c
+ src/sdktools.c
+ src/strutils.c
+ src/libsmack.c
+ src/init.c
+ src/fileutils.c
+ src/commandline_sdbd.c
+)
+
+include_directories(src)
+
+if(USE_FUNCTION_FS)
+ list(APPEND sdbd_SRCS src/usb_funcfs_client.c)
+else()
+ list(APPEND sdbd_SRCS src/usb_linux_client.c)
+endif()
+
+add_executable(sdbd ${sdbd_SRCS})
+
+set_property(
+ TARGET sdbd
+ PROPERTY COMPILE_DEFINITIONS
+ SDB_HOST=0
+ _DROP_PRIVILEGE
+ _FILE_OFFSET_BITS=64
+)
+
+set_property(
+ TARGET sdbd
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ _XOPEN_SOURCE
+ _GNU_SOURCE
+ HAVE_FORKEXEC
+)
+
+if(USE_FUNCTION_FS)
+ set_property(
+ TARGET sdbd
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ USB_FUNCFS
+ )
+endif()
+
+include(FindPkgConfig)
+
+# Get capi-system-info
+pkg_check_modules(CAPI_SYSTEM_INFO REQUIRED capi-system-info)
+include_directories(${CAPI_SYSTEM_INFO_INCLUDE_DIRS})
+
+# Get pthreads
+find_package(Threads REQUIRED)
+
+# Add libraries (-l...)
+target_link_libraries (sdbd ${CMAKE_THREAD_LIBS_INIT} ${CAPI_SYSTEM_INFO_LDFLAGS})
+
+install(TARGETS sdbd DESTINATION /usr/sbin)
+install(FILES script/sdbd DESTINATION /etc/init.d)
+
+
+# Optionally build unit tests binary -- could be helpful during further development
+if(BUILD_UNIT_TESTS)
+ enable_testing()
+ add_subdirectory(test)
+endif()
+++ /dev/null
-#
-#
-# Makefile for sdbd
-#
-
-SDBD_SRC_FILES := \
- src/sdb.c \
- src/fdevent.c \
- src/transport.c \
- src/transport_local.c \
- src/transport_usb.c \
- src/sockets.c \
- src/services.c \
- src/file_sync_service.c \
- src/usb_linux_client.c \
- src/utils.c \
- src/socket_inaddr_any_server.c \
- src/socket_local_client.c \
- src/socket_local_server.c \
- src/socket_loopback_client.c \
- src/socket_loopback_server.c \
- src/socket_network_client.c \
- src/properties.c \
- src/sdktools.c \
- src/strutils.c \
- src/libsmack.c \
- src/init.c \
- src/fileutils.c \
- src/commandline_sdbd.c
-
-SDBD_CFLAGS := -O2 -g -DSDB_HOST=0 -Wall -Wno-unused-parameter
-SDBD_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-SDBD_CFLAGS += -DHAVE_FORKEXEC -fPIE -D_DROP_PRIVILEGE -D_FILE_OFFSET_BITS=64
-SDBD_LFLAGS := -lcapi-system-info
-IFLAGS := -Iinclude -Isrc -I/usr/include/system
-OBJDIR := bin
-INSTALLDIR := usr/sbin
-INITSCRIPTDIR := etc/init.d
-
-MODULE := sdbd
-
-all : $(MODULE)
-
-sdbd : $(SDBD_SRC_FILES)
- mkdir -p $(OBJDIR)
- $(CC) -pthread -o $(OBJDIR)/$(MODULE) $(SDBD_CFLAGS) $(IFLAGS) $(SDBD_SRC_FILES) $(SDBD_LFLAGS)
-
-install :
- mkdir -p $(DESTDIR)/$(INSTALLDIR)
- install $(OBJDIR)/$(MODULE) $(DESTDIR)/$(INSTALLDIR)/$(MODULE)
- mkdir -p $(DESTDIR)/$(INITSCRIPTDIR)
- install script/sdbd $(DESTDIR)/$(INITSCRIPTDIR)/sdbd
-
-clean :
- rm -rf $(OBJDIR)/*
Source1003: %{name}.manifest
BuildRequires: capi-system-info-devel >= 0.2.0
+BuildRequires: cmake >= 2.8.3
Requires: sys-assert
Requires: dbus
cp %{SOURCE1003} .
%build
+%cmake
make %{?jobs:-j%jobs}
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the License);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an AS IS BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+cmake_minimum_required (VERSION 2.8.3)
+project (sdbd_tests)
+
+include(FindPkgConfig)
+pkg_check_modules(CHECK check>=0.9.8 REQUIRED)
+
+enable_testing()
+
+add_executable(sdbd_tests ../src/commandline_sdbd.c test_commandline_sdbd.c)
+
+set_property(
+ TARGET sdbd_tests
+ APPEND PROPERTY COMPILE_DEFINITIONS
+ _XOPEN_SOURCE
+ _GNU_SOURCE
+)
+
+include_directories(../src)
+
+include_directories(${CHECK_INCLUDE_DIRS})
+target_link_libraries (sdbd_tests ${CHECK_LDFLAGS})
+
+add_test(InternalUnitTests sdbd_tests)
+set_tests_properties(InternalUnitTests PROPERTIES
+ PASS_REGULAR_EXPRESSION "100%: Checks: [0-9]+, Failures: 0, Errors: 0")