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