packaging: add exec.conf to profile_tv
[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
23 ############################# cmake packages ##################################
24
25 INCLUDE(FindPkgConfig)
26
27 ############################# compiler flags ##################################
28
29 SET(SDBD_SRCS
30         src/sdb.c
31         src/fdevent.c
32         src/transport.c
33         src/transport_local.c
34         src/transport_usb.c
35         src/sockets.c
36         src/services.c
37         src/file_sync_service.c
38         src/usb_linux_client.c
39         src/utils.c
40         src/socket_inaddr_any_server.c
41         src/socket_local_client.c
42         src/socket_local_server.c
43         src/socket_loopback_client.c
44         src/socket_loopback_server.c
45         src/socket_network_client.c
46         src/sdktools.c
47         src/strutils.c
48         src/commandline_sdbd.c
49         src/usb_linux_client.c
50         src/usb_funcfs_client.c
51         src/default_plugin_auth.c
52         src/default_plugin_basic.c
53         src/default_plugin_main.c
54         src/default_plugin_event.c
55         src/default_plugin_appcmd.c
56         src/default_plugin_shellcmd.c
57         src/hashtable.c
58         src/plugin.c
59         src/plugin_encrypt.c
60         src/descs_strings.c
61 )
62 SET(SDBD_SUBS
63         src/subprocess.c
64 )
65
66 include(FindPkgConfig)
67
68 pkg_check_modules(pkgs REQUIRED
69         libtzplatform-config
70         capi-system-info
71         vconf
72         glib-2.0
73         gio-2.0
74         dlog
75 )
76
77 FOREACH(flag ${pkgs_CFLAGS})
78         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
79 ENDFOREACH(flag)
80
81 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
82
83 INCLUDE_DIRECTORIES(src)
84
85 ADD_DEFINITIONS("-O2 -g -Wall -Wno-unused-parameter -fPIE")
86 ADD_DEFINITIONS("-DSDB_HOST=0")
87 ADD_DEFINITIONS("-D_XOPEN_SOURCE")
88 ADD_DEFINITIONS("-D_GNU_SOURCE")
89 ADD_DEFINITIONS("-DHAVE_FORKEXEC")
90 ADD_DEFINITIONS("-D_DROP_PRIVILEGE")
91 ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
92 ADD_DEFINITIONS("-DSUPPORT_ENCRYPT")
93
94 IF (_ARM_TARGET)
95         ADD_DEFINITIONS("-DANDROID_GADGET=1")
96 ENDIF (_ARM_TARGET)
97
98 IF(WEARABLE_PROFILE STREQUAL on)
99         ADD_DEFINITIONS("-D_WEARABLE")
100 ENDIF()
101
102 # Get systemd
103 pkg_check_modules(SYSTEMD REQUIRED libsystemd)
104 foreach(flag ${SYSTEMD_CFLAGS})
105         set(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
106 endforeach(flag)
107
108 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
109
110 find_package(Threads REQUIRED)
111
112 ADD_EXECUTABLE(sdbd ${SDBD_SRCS})
113 ADD_EXECUTABLE(sdbd-user ${SDBD_SUBS})
114 TARGET_LINK_LIBRARIES(sdbd -pie -lsmack -lresolv -ldl ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS} ${SYSTEMD_LDFLAGS})
115 TARGET_LINK_LIBRARIES(sdbd-user -pie ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS})
116
117 set_property(
118         TARGET sdbd
119         PROPERTY COMPILE_DEFINITIONS
120         SDB_HOST=0
121         _DROP_PRIVILEGE
122         _FILE_OFFSET_BITS=64
123 )
124
125 set_property(
126         TARGET sdbd
127         APPEND PROPERTY COMPILE_DEFINITIONS
128         _XOPEN_SOURCE
129         _GNU_SOURCE
130         HAVE_FORKEXEC
131 )
132
133 if(USE_FUNCTION_FS)
134         set_property(
135                 TARGET sdbd
136                 APPEND PROPERTY COMPILE_DEFINITIONS
137                 USB_FUNCFS
138         )
139 endif()
140
141 install(TARGETS sdbd sdbd-user DESTINATION /usr/sbin)
142 install(FILES script/sdbd DESTINATION /etc/init.d)
143
144 # Extract descriptors and strings for systemd socket activation
145 add_executable(extract_descs_strings src/extract_descs_strings.c src/descs_strings.c)
146 add_custom_command(OUTPUT descs strs
147                 COMMAND ./extract_descs_strings
148                 DEPENDS extract_descs_strings)
149 add_custom_target(descs_strings ALL DEPENDS descs strs)
150
151 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/descs DESTINATION /etc/sdbd)
152 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/strs DESTINATION /etc/sdbd)
153
154 # Optionally build unit tests binary -- could be helpful during further development
155 if(BUILD_UNIT_TESTS)
156         enable_testing()
157         add_subdirectory(test)
158 endif()