Add CMake option to compile with J1939 45/21745/1
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 26 Jun 2019 07:14:42 +0000 (09:14 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Wed, 26 Jun 2019 15:55:05 +0000 (17:55 +0200)
Add option USE_FEATURE_J1939 to compile j1939 in file config.cmake
This will be set up by default depending on the presence on the
building host of the J1939 CAN module headers.

Bug-AGL: SPEC-2386

Change-Id: I54d4594ff01d4e509bfa0862f3cb486562024aed
Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh>
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
conf.d/cmake/config.cmake
low-can-binding/CMakeLists.txt

index 9e9a15b..e6da31a 100644 (file)
@@ -40,6 +40,21 @@ set(PROJECT_CMAKE_CONF_DIR "conf.d")
 # ----------------------------------
 set(BUILD_TYPE "RELEASE" CACHE STRING "Default Build variant chosen. (Overwritten by cli if given)")
 
+# Activate J1939
+# Need module in kernel
+# --------------
+
+execute_process(COMMAND ls /usr/include/linux/can/j1939.h RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
+
+if(result)
+       message("Feature J1939 disabled")
+       set(WITH_FEATURE_J1939 OFF)
+else()
+       message("Feature J1939 enabled")
+       set(WITH_FEATURE_J1939 ON)
+       add_definitions(-DUSE_FEATURE_J1939)
+endif()
+
 # Kernel selection if needed. You can choose between a
 # mandatory version to impose a minimal version.
 # Or check Kernel minimal version and just print a Warning
index d09757d..296fa7d 100644 (file)
 ###########################################################################
 
 # Add target to project dependency list
+
 PROJECT_TARGET_ADD(low-can)
 
        # Define project Targets
-       add_library(${TARGET_NAME} MODULE
+       set (SOURCES
                #binding/${TARGET_NAME}-hat.cpp
                binding/${TARGET_NAME}-cb.cpp
                binding/${TARGET_NAME}-subscription.cpp
@@ -45,6 +46,14 @@ PROJECT_TARGET_ADD(low-can)
                utils/config-parser.cpp
                binding/application-generated.cpp)
 
+       if(WITH_FEATURE_J1939)
+               set(SOURCES_J1939
+               # Empty for the moment to not break the build until all modifications are set
+               )
+       endif()
+
+       add_library(${TARGET_NAME} MODULE ${SOURCES} ${SOURCES_J1939})
+
        set(OPENAPI_DEF "binding/low-can-apidef" CACHE STRING "name and path to the JSON API definition without extension")
        # Binder exposes a unique public entry point
        SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES