Added new cpp files.
[apps/low-level-can-service.git] / src / CMakeLists.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 project(low-can-binding)
21
22 cmake_minimum_required(VERSION 3.3)
23
24 include(GNUInstallDirs)
25
26 set(TARGET "root@192.168.1.206")
27 set(PROJECT_VERSION "0.1")
28 set(PROJECT_ICON "icon.png")
29 set(PROJECT_LIBDIR "libs")
30
31 set(CMAKE_BUILD_TYPE Debug)
32
33 ###########################################################################
34
35 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
36
37 add_compile_options(-Wall -Wextra -Wconversion)
38 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
39 add_compile_options(-Werror=maybe-uninitialized)
40 add_compile_options(-Werror=implicit-function-declaration)
41 add_compile_options(-ffunction-sections -fdata-sections)
42 add_compile_options(-Wl,--as-needed -Wl,--gc-sections)
43 add_compile_options(-fPIC)
44 add_compile_options(-D_REENTRANT)
45
46 set(CMAKE_C_FLAGS_PROFILING    "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
47 set(CMAKE_C_FLAGS_DEBUG        "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
48 set(CMAKE_C_FLAGS_RELEASE      "-g -O0 -Wall -Werror")
49 set(CMAKE_C_FLAGS_CCOV         "-g -O0 --coverage")
50
51 set(CMAKE_CXX_FLAGS_PROFILING    "-g -O0 -std=c++11 -pg -Wp,-U_FORTIFY_SOURCE")
52 set(CMAKE_CXX_FLAGS_DEBUG        "-g -O0 -std=c++11 -ggdb -Wp,-U_FORTIFY_SOURCE")
53 set(CMAKE_CXX_FLAGS_RELEASE      "-g -O2 -std=c++11")
54 set(CMAKE_CXX_FLAGS_CCOV         "-g -O2 -std=c++11 --coverage")
55
56 ###########################################################################
57
58 include(FindPkgConfig)
59
60 pkg_check_modules(EXTRAS REQUIRED json-c afb-daemon)
61 add_compile_options(${EXTRAS_CFLAGS})
62 add_compile_options(${EXTRAS_CXXFLAGS})
63
64 # Needed to compile openxc-message-format library.
65 #
66 # The reason you need to do this is that some of your messages contain tag
67 # numbers or field sizes that are larger than what can fit in the default
68 # 8 bit descriptors.
69 add_definitions(-DPB_FIELD_16BIT)
70
71 # Needed extra directories to hit the required headers files.
72 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)
73
74 ###########################################################################
75 # the library used by the binding : openxc, bitfield, uds, isotp
76
77 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)
78 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)
79 add_library(uds STATIC ${PROJECT_LIBDIR}/uds-c/src/uds/extras.c ${PROJECT_LIBDIR}/uds-c/src/uds/uds.c)
80 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)
81 ###########################################################################
82 # the binding for afb
83
84 message(STATUS "Creation of ${PROJECT_NAME} binding for AFB-DAEMON")
85 ###########################################################################
86 add_library(${PROJECT_NAME} MODULE ${PROJECT_NAME}.cpp configuration.cpp
87         can/can-bus.cpp can/can-bus-dev.cpp can/can-message.cpp can/can-signals.cpp can/can-decoder.cpp
88         obd2/obd2-signals.cpp obd2/diagnostic-manager.cpp
89         utils/signals.cpp utils/openxc-utils.cpp utils/timer.cpp utils/socket.cpp)
90 target_link_libraries(${PROJECT_NAME} ${EXTRAS_LIBRARIES} bitfield isotp uds openxc pthread)
91
92 set_target_properties(${PROJECT_NAME} PROPERTIES
93         PREFIX ""
94         LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map"
95 )
96
97 ###########################################################################
98 # WGT packaging
99
100 message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
101 ###########################################################################
102 configure_file(config.xml.in config.xml)
103 configure_file(can_buses.json.in can_buses.json)
104
105 add_custom_command(
106         OUTPUT ${PROJECT_NAME}.wgt
107         DEPENDS ${PROJECT_NAME} bitfield isotp uds openxc config.xml.in can_buses.json.in
108         COMMAND rm -rf package
109         COMMAND mkdir -p package/${PROJECT_LIBDIR} package/htdocs
110         COMMAND cp config.xml package/
111         COMMAND cp can_buses.json package/
112         COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_ICON} package/icon.png
113         COMMAND cp ${PROJECT_NAME}.so package/libs
114         COMMAND wgtpkg-pack -f -o ${PROJECT_NAME}.wgt package
115 )
116 add_custom_target(widget ALL DEPENDS ${PROJECT_NAME}.wgt)
117
118 ###########################################################################
119 # WGT install
120
121 #message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
122 ###########################################################################
123 install(CODE "execute_process(
124         COMMAND scp -r ${CMAKE_SOURCE_DIR} ${PROJECT_NAME}.wgt ${TARGET}:/tmp
125         COMMAND ssh ${TARGET} \"/usr/bin/afm-util remove ${PROJECT_NAME}@${PROJECT_VERSION} && /usr/bin/afm-util install /tmp/${PROJECT_NAME}.wgt\")"
126         )