Rewrite Makefile as CMakeLists.txt
[sdk/target/sdbd.git] / CMakeLists.txt
1 # Copyright (c) 2014 Samsung Electronics Co., Ltd
2 #
3 # Licensed under the Apache License, Version 2.0 (the License);
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an AS IS BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 cmake_minimum_required (VERSION 2.8.3)
17 project (sdbd)
18
19 option(USE_FUNCTION_FS "Use FunctionFS" NO)
20 option(BUILD_UNIT_TESTS "Build unit tests" NO)
21
22 set(sdbd_SRCS
23         src/sdb.c
24         src/fdevent.c
25         src/transport.c
26         src/transport_local.c
27         src/transport_usb.c
28         src/sockets.c
29         src/services.c
30         src/file_sync_service.c
31         src/utils.c
32         src/socket_inaddr_any_server.c
33         src/socket_local_client.c
34         src/socket_local_server.c
35         src/socket_loopback_client.c
36         src/socket_loopback_server.c
37         src/socket_network_client.c
38         src/properties.c
39         src/sdktools.c
40         src/strutils.c
41         src/libsmack.c
42         src/init.c
43         src/fileutils.c
44         src/commandline_sdbd.c
45 )
46
47 include_directories(src)
48
49 if(USE_FUNCTION_FS)
50         list(APPEND sdbd_SRCS src/usb_funcfs_client.c)
51 else()
52         list(APPEND sdbd_SRCS src/usb_linux_client.c)
53 endif()
54
55 add_executable(sdbd ${sdbd_SRCS})
56
57 set_property(
58         TARGET sdbd
59         PROPERTY COMPILE_DEFINITIONS
60         SDB_HOST=0
61         _DROP_PRIVILEGE
62         _FILE_OFFSET_BITS=64
63 )
64
65 set_property(
66         TARGET sdbd
67         APPEND PROPERTY COMPILE_DEFINITIONS
68         _XOPEN_SOURCE
69         _GNU_SOURCE
70         HAVE_FORKEXEC
71 )
72
73 if(USE_FUNCTION_FS)
74         set_property(
75                 TARGET sdbd
76                 APPEND PROPERTY COMPILE_DEFINITIONS
77                 USB_FUNCFS
78         )
79 endif()
80
81 include(FindPkgConfig)
82
83 # Get capi-system-info
84 pkg_check_modules(CAPI_SYSTEM_INFO REQUIRED capi-system-info)
85 include_directories(${CAPI_SYSTEM_INFO_INCLUDE_DIRS})
86
87 # Get pthreads
88 find_package(Threads REQUIRED)
89
90 # Add libraries (-l...)
91 target_link_libraries (sdbd ${CMAKE_THREAD_LIBS_INIT} ${CAPI_SYSTEM_INFO_LDFLAGS})
92
93 install(TARGETS sdbd DESTINATION /usr/sbin)
94 install(FILES script/sdbd DESTINATION /etc/init.d)
95
96
97 # Optionally build unit tests binary -- could be helpful during further development
98 if(BUILD_UNIT_TESTS)
99         enable_testing()
100         add_subdirectory(test)
101 endif()