Unsubscribe instead of subscribe if can't adding to recurring request
[apps/low-level-can-service.git] / low-can-binding / subCMakeLists.txt
1 ###########################################################################
2 # Copyright 2016 IoT.bzh
3 #
4 # author: José Bollo <jose.bollo@iot.bzh>
5 # author: Stéphane Desneux <stephane.desneux@iot.bzh>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
19
20 include(GNUInstallDirs)
21
22 set(TARGET "root@192.168.1.206")
23 set(PROJECT_VERSION "0.1")
24 set(PROJECT_ICON "icon.png")
25 set(PROJECT_LIBDIR "libs")
26
27 set(CMAKE_BUILD_TYPE Debug)
28
29 ###########################################################################
30
31 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
32
33 add_compile_options(-Wall -Wextra -Wconversion)
34 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
35 add_compile_options(-Werror=maybe-uninitialized)
36 add_compile_options(-Werror=implicit-function-declaration)
37 add_compile_options(-ffunction-sections -fdata-sections)
38 add_compile_options(-Wl,--as-needed -Wl,--gc-sections)
39 add_compile_options(-fPIC)
40 add_compile_options(-D_REENTRANT)
41
42 set(CMAKE_C_FLAGS_PROFILING    "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
43 set(CMAKE_C_FLAGS_DEBUG        "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
44 set(CMAKE_C_FLAGS_RELEASE      "-g -O0 -Wall -Werror")
45 set(CMAKE_C_FLAGS_CCOV         "-g -O0 --coverage")
46
47 set(CMAKE_CXX_FLAGS_PROFILING    "-g -O0 -std=c++11 -pg -Wp,-U_FORTIFY_SOURCE")
48 set(CMAKE_CXX_FLAGS_DEBUG        "-g -O0 -std=c++11 -ggdb -Wp,-U_FORTIFY_SOURCE")
49 set(CMAKE_CXX_FLAGS_RELEASE      "-g -O2 -std=c++11")
50 set(CMAKE_CXX_FLAGS_CCOV         "-g -O2 -std=c++11 --coverage")
51
52 ###########################################################################
53
54 include(FindPkgConfig)
55
56 pkg_check_modules(EXTRAS REQUIRED json-c libsystemd afb-daemon)
57 add_compile_options(${EXTRAS_CFLAGS})
58 add_compile_options(${EXTRAS_CXXFLAGS})
59
60 # Needed to compile openxc-message-format library.
61 #
62 # The reason you need to do this is that some of your messages contain tag
63 # numbers or field sizes that are larger than what can fit in the default
64 # 8 bit descriptors.
65 add_definitions(-DPB_FIELD_16BIT)
66
67 # Needed extra directories to hit the required headers files.
68 include_directories(${EXTRAS_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR} ${PROJECT_LIBDIR}/openxc-message-format/gen/cpp ${PROJECT_LIBDIR}/nanopb/  ${PROJECT_LIBDIR}/uds-c/src  ${PROJECT_LIBDIR}/bitfield-c/src ${PROJECT_LIBDIR}/isotp-c/src)
69 link_libraries(${EXTRAS_LIBRARIES})
70 ###########################################################################
71 # the library used by the binding : openxc, bitfield, uds, isotp
72
73 # Bindings to compile
74 # --------------------
75 file(GLOB filelist "${PROJECT_LIBDIR}/*")
76 foreach(filename ${filelist})
77   if(IS_DIRECTORY ${filename})
78     message(STATUS "${filename}")
79     file(GLOB_RECURSE c_list "*.[chpx]")
80     string(REGEX REPLACE "^.*\/(.*)$" "\\1" LIB_NAME ${filename})
81     add_library(${LIB_NAME} STATIC ${c_list})
82   endif(IS_DIRECTORY ${filename})
83 endforeach()
84
85 #add_library(bitfield STATIC ${PROJECT_LIBDIR}/bitfield-c/src/bitfield/8byte.c ${PROJECT_LIBDIR}/bitfield-c/src/bitfield/bitarray.c ${PROJECT_LIBDIR}/bitfield-c/src/bitfield/bitfield.c ${PROJECT_LIBDIR}/bitfield-c/src/canutil/read.c ${PROJECT_LIBDIR}/bitfield-c/src/canutil/write.c)
86 #add_library(isotp STATIC ${PROJECT_LIBDIR}/isotp-c/src/isotp/isotp.c ${PROJECT_LIBDIR}/isotp-c/src/isotp/receive.c ${PROJECT_LIBDIR}/isotp-c/src/isotp/send.c)
87 #add_library(uds STATIC ${PROJECT_LIBDIR}/uds-c/src/uds/extras.c ${PROJECT_LIBDIR}/uds-c/src/uds/uds.c)
88 #add_library(openxc STATIC ${PROJECT_LIBDIR}/openxc-message-format/gen/cpp/openxc.pb.c ${PROJECT_LIBDIR}/nanopb/pb_encode.c ${PROJECT_LIBDIR}/nanopb/pb_decode.c ${PROJECT_LIBDIR}/nanopb/pb_common.c)
89 ###########################################################################
90 # the binding for afb
91
92 message(STATUS "Creation of ${PROJECT_NAME} binding for AFB-DAEMON")
93 ###########################################################################
94 add_library(${PROJECT_NAME} MODULE ${PROJECT_NAME}.cpp configuration.cpp configuration-generated.cpp
95         can/can-bus.cpp can/can-bus-dev.cpp can/can-message-set.cpp can/can-message-definition.cpp can/can-message.cpp can/can-signals.cpp can/can-decoder.cpp
96         diagnostic/diagnostic-message.cpp diagnostic/diagnostic-manager.cpp diagnostic/active-diagnostic-request.cpp
97         utils/signals.cpp utils/openxc-utils.cpp utils/timer.cpp utils/socket.cpp)
98 target_link_libraries(${PROJECT_NAME} pthread bitfield-c uds-c isotp-c openxc-message-format)
99
100 set_target_properties(${PROJECT_NAME} PROPERTIES
101         PREFIX ""
102         LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map"
103 )
104
105 ###########################################################################
106 # WGT packaging
107
108 message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
109 ###########################################################################
110 configure_file(config.xml.in config.xml)
111 configure_file(can_buses.json.in can_buses.json)
112
113 add_custom_command(
114         OUTPUT ${PROJECT_NAME}.wgt
115         DEPENDS ${PROJECT_NAME} bitfield isotp uds openxc config.xml.in can_buses.json.in
116         COMMAND rm -rf package
117         COMMAND mkdir -p package/${PROJECT_LIBDIR} package/htdocs package/etc
118         COMMAND cp config.xml package/
119         COMMAND cp can_buses.json package/etc
120         COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_ICON} package/icon.png
121         COMMAND cp ${PROJECT_NAME}.so package/libs
122         COMMAND wgtpkg-pack -f -o ${PROJECT_NAME}.wgt package
123 )
124 add_custom_target(widget ALL DEPENDS ${PROJECT_NAME}.wgt)
125
126 ###########################################################################
127 # WGT install
128
129 #message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
130 ###########################################################################
131 install(CODE "execute_process(
132         COMMAND scp -r src/${PROJECT_NAME}.wgt ${CMAKE_SOURCE_DIR} ${TARGET}:/tmp)"
133         CODE "execute_process(
134         COMMAND ssh ${TARGET} \"/usr/bin/afm-util remove ${PROJECT_NAME}@${PROJECT_VERSION} && /usr/bin/afm-util install /tmp/${PROJECT_NAME}.wgt\")"
135         )