From 214554b69cbf4b42c8a003eb51b6efc0332edc67 Mon Sep 17 00:00:00 2001 From: Aleksander Zdyb Date: Wed, 29 Jan 2014 15:20:04 +0100 Subject: [PATCH] Rewrite Makefile as CMakeLists.txt 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 Change-Id: Ia4f394ab301a74b83e5846ba19931f0637f0d241 --- CMakeLists.txt | 101 ++++++++++++++++++++++++++++++++++++++++++++ Makefile | 55 ------------------------ packaging/sdbd.spec | 2 + test/CMakeLists.txt | 40 ++++++++++++++++++ 4 files changed, 143 insertions(+), 55 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c112d31 --- /dev/null +++ b/CMakeLists.txt @@ -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 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)/* diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index c6a8de4..d565618 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -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 index 0000000..ddc80ad --- /dev/null +++ b/test/CMakeLists.txt @@ -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") -- 2.34.1