Remove root cover file cover.xcf, now replace by cove.svg
[apps/agl-service-can-low-level.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 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 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)
74 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)
75 add_library(uds STATIC ${PROJECT_LIBDIR}/uds-c/src/uds/extras.c ${PROJECT_LIBDIR}/uds-c/src/uds/uds.c)
76 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)
77 ###########################################################################
78 # the binding for afb
79
80 message(STATUS "Creation of ${PROJECT_NAME} binding for AFB-DAEMON")
81 ###########################################################################
82 add_library(${PROJECT_NAME} MODULE ${PROJECT_NAME}.cpp configuration.cpp configuration-generated.cpp
83         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
84         diagnostic/diagnostic-message.cpp diagnostic/diagnostic-manager.cpp diagnostic/active-diagnostic-request.cpp
85         utils/signals.cpp utils/openxc-utils.cpp utils/timer.cpp utils/socket.cpp)
86 target_link_libraries(${PROJECT_NAME} pthread bitfield uds isotp openxc)
87
88 set_target_properties(${PROJECT_NAME} PROPERTIES
89         PREFIX ""
90         LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map"
91 )
92
93 ###########################################################################
94 # WGT packaging
95
96 message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
97 ###########################################################################
98 configure_file(config.xml.in config.xml)
99 configure_file(can_buses.json.in can_buses.json)
100
101 add_custom_command(
102         OUTPUT ${PROJECT_NAME}.wgt
103         DEPENDS ${PROJECT_NAME} bitfield isotp uds openxc config.xml.in can_buses.json.in
104         COMMAND rm -rf package
105         COMMAND mkdir -p package/${PROJECT_LIBDIR} package/htdocs package/etc
106         COMMAND cp config.xml package/
107         COMMAND cp can_buses.json package/etc
108         COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_ICON} package/icon.png
109         COMMAND cp ${PROJECT_NAME}.so package/libs
110         COMMAND wgtpkg-pack -f -o ${PROJECT_NAME}.wgt package
111 )
112 add_custom_target(widget ALL DEPENDS ${PROJECT_NAME}.wgt)
113
114 ###########################################################################
115 # WGT install
116
117 #message(STATUS "Creation of ${PROJECT_NAME}.wgt package for AppFW")
118 ###########################################################################
119 install(CODE "execute_process(
120         COMMAND scp -r ${CMAKE_SOURCE_DIR} src/${PROJECT_NAME}.wgt ${TARGET}:/tmp
121         COMMAND ssh ${TARGET} \"/usr/bin/afm-util remove ${PROJECT_NAME}@${PROJECT_VERSION} && /usr/bin/afm-util install /tmp/${PROJECT_NAME}.wgt\")"
122         )