Rewrite Makefile as CMakeLists.txt 74/14674/4
authorAleksander Zdyb <a.zdyb@partner.samsung.com>
Wed, 29 Jan 2014 14:20:04 +0000 (15:20 +0100)
committerAleksander Zdyb <a.zdyb@partner.samsung.com>
Fri, 31 Jan 2014 13:19:23 +0000 (14:19 +0100)
FunctionFS transport can be enabled by passing
-DUSE_FUNCTION_FS to cmake.

Unit tests building can be enabled by passing
-DBUILD_UNIT_TESTS to cmake

Signed-off-by: Aleksander Zdyb <a.zdyb@partner.samsung.com>
Change-Id: Ia4f394ab301a74b83e5846ba19931f0637f0d241

CMakeLists.txt [new file with mode: 0644]
Makefile [deleted file]
packaging/sdbd.spec
test/CMakeLists.txt [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c112d31
--- /dev/null
@@ -0,0 +1,101 @@
+# 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()
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 6fef698..0000000
--- a/Makefile
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-#
-# 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)/*
index c6a8de4e5ecdfaf1966e61c4b67c7c1dceadb186..d5656180b95f57b5b077bcd4f95277eba4bbda9b 100644 (file)
@@ -11,6 +11,7 @@ Source1002:    sdbd_emulator.service
 Source1003:    %{name}.manifest
 
 BuildRequires: capi-system-info-devel >= 0.2.0
+BuildRequires: cmake >= 2.8.3
 Requires: sys-assert
 Requires: dbus
 
@@ -23,6 +24,7 @@ Description: SDB daemon.
 cp %{SOURCE1003} .
 
 %build
+%cmake
 make %{?jobs:-j%jobs}
 
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ddc80ad
--- /dev/null
@@ -0,0 +1,40 @@
+# 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")