Skip to content

Commit

Permalink
MINIFICPP-1007 NaNoFi ecu integration with c2 over coap including win…
Browse files Browse the repository at this point in the history
…dows support
  • Loading branch information
Murtuza Shareef authored and msharee9 committed Dec 31, 2019
1 parent 8a2bb1b commit 68ce755
Show file tree
Hide file tree
Showing 59 changed files with 6,807 additions and 142 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ include_directories(thirdparty/ut)
set(UUID_FOUND "YES" CACHE STRING "" FORCE)
set(UUID_LIBRARIES "uuid" CACHE STRING "" FORCE)


if (DISABLE_CURL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_CURL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_CURL")
Expand All @@ -274,7 +273,6 @@ if(NOT DISABLE_CURL)
set(CURL_C_FLAGS "${CMAKE_C_FLAGS}")
set(CURL_CXX_FLAGS "${CMAKE_CXX_FLAGS}")


get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)

if ("${LIB64}" STREQUAL "TRUE" AND (NOT WIN32 AND NOT APPLE))
Expand Down Expand Up @@ -473,8 +471,8 @@ option(ENABLE_COAP "Enables the CoAP extension." OFF)
if (ENABLE_ALL OR ENABLE_COAP STREQUAL "ON")
createExtension(COAP-EXTENSION "COAP EXTENSIONS" "Enables LibCOAP Functionality." "extensions/coap" "extensions/coap/tests/")
if( NOT DISABLE_CURL)
add_dependencies(minifi-coap minifi-http-curl)
endif()
add_dependencies(minifi-coap minifi-http-curl)
endif()
endif()

if (WIN32)
Expand Down
4 changes: 2 additions & 2 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configurations": [
{
"name": "x64-Release",
"generator": "Visual Studio 15 2017",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
Expand Down Expand Up @@ -73,7 +73,7 @@
},
{
"name": "ENABLE_COAP",
"value": "OFF"
"value": "ON"
},
{
"name": "DISABLE_LIBARCHIVE",
Expand Down
81 changes: 49 additions & 32 deletions extensions/coap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ include_directories(protocols nanofi controllerservice server)
include_directories(../http-curl/)

file(GLOB CSOURCES "nanofi/*.c")
file(GLOB SOURCES "*.cpp" "protocols/*.cpp" "processors/*.cpp" "controllerservice/*.cpp" "server/*.cpp" )
file(GLOB SOURCES "*.cpp" "protocols/*.cpp" "controllerservice/*.cpp" "server/*.cpp" )

add_library(nanofi-coap-c STATIC ${CSOURCES})
set(BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(DIR "${BASE_DIR}/thirdparty/libcoap-src")
add_library(minifi-coap STATIC ${SOURCES})
set_property(TARGET minifi-coap PROPERTY POSITION_INDEPENDENT_CODE ON)

if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(minifi-coap "${CMAKE_THREAD_LIBS_INIT}")
endif()
if (NOT WIN32)
set(BYPRODUCT "${BASE_DIR}/thirdparty/libcoap-src/.libs/libcoap-2.a")

set(BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/extensions/coap")
# determine version of GNUTLSs
set(BYPRODUCT "${BASE_DIR}/extensions/coap/thirdparty/libcoap-src/.libs/libcoap-2.a")
set(DIR "${BASE_DIR}/extensions/coap/thirdparty/libcoap-src")
ExternalProject_Add(
ExternalProject_Add(
coap-external
GIT_REPOSITORY "https://github.com/obgm/libcoap.git"
GIT_TAG "00486a4f46e0278dd24a8ff3411416ff420cde29"
PREFIX "${BASE_DIR}/extensions/coap/thirdparty/libcoap"
GIT_TAG "00486a4f46e0278dd24a8ff3411416ff420cde29"
PREFIX "${BASE_DIR}/thirdparty/libcoap"
BUILD_IN_SOURCE true
SOURCE_DIR "${DIR}"
BUILD_COMMAND make
Expand All @@ -52,27 +47,50 @@ endif()
PATCH_COMMAND ./autogen.sh && ./configure --disable-examples --disable-dtls --disable-tests --disable-documentation
STEP_TARGETS build
EXCLUDE_FROM_ALL TRUE
)
add_definitions("-DWITH_POSIX=1")

add_library(coaplib STATIC IMPORTED)
set_target_properties(coaplib PROPERTIES IMPORTED_LOCATION "${BYPRODUCT}")
add_dependencies(coaplib coap-external)
set(COAP_FOUND "YES" CACHE STRING "" FORCE)
set(COAP_INCLUDE_DIRS "${DIR}/include" CACHE STRING "" FORCE)
set(COAP_LIBRARIES coaplib CACHE STRING "" FORCE)
set(COAP_LIBRARY coaplib CACHE STRING "" FORCE)
set(COAP_LIBRARY coaplib CACHE STRING "" FORCE)
target_link_libraries(minifi-coap ${CMAKE_DL_LIBS})
)
add_definitions("-DWITH_POSIX=1")
add_library(coap STATIC IMPORTED)
set_target_properties(coap PROPERTIES IMPORTED_LOCATION "${BYPRODUCT}")
add_dependencies(coap coap-external)
set(COAP_FOUND "YES" CACHE STRING "" FORCE)
set(COAP_INCLUDE_DIRS "${DIR}/include" CACHE STRING "" FORCE)
include_directories(${COAP_INCLUDE_DIRS})
else()
configure_file(DownloadCoapCMakeLists.txt.in "${CMAKE_CURRENT_BINARY_DIR}/coap_download/CMakeLists.txt" @ONLY)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/libcoap_windows.patch" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/coap_download")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "Visual Studio 15 2017 Win64" . WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/coap_download")
execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/coap_download")

include_directories(${COAP_INCLUDE_DIRS})
set(COAP_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/coap_download/libcoap-src")

file(GLOB COAP_SOURCE_FILES "${COAP_SOURCE_DIR}/src/*.c")
list(REMOVE_ITEM COAP_SOURCE_FILES ${COAP_SOURCE_DIR}/src/coap_io_lwip.c)

configure_file(${COAP_SOURCE_DIR}/coap_config.h.windows ${COAP_SOURCE_DIR}/coap_config.h)
configure_file(${COAP_SOURCE_DIR}/include/coap2/coap.h.windows ${COAP_SOURCE_DIR}/include/coap2/coap.h)

add_library(coap STATIC ${COAP_SOURCE_FILES})

target_include_directories(coap PUBLIC "${COAP_SOURCE_DIR}")
target_include_directories(coap PUBLIC "${COAP_SOURCE_DIR}/include")
target_include_directories(coap PUBLIC "${COAP_SOURCE_DIR}/include/coap2")

endif()
set(COAP_LIBRARIES coap CACHE STRING "" FORCE)

add_library(nanofi-coap-c STATIC ${CSOURCES})
add_dependencies(minifi-coap nanofi-coap-c)
add_dependencies(nanofi-coap-c coap)
target_link_libraries(nanofi-coap-c PUBLIC ${COAP_LIBRARIES} ${CMAKE_DL_LIBS})
target_link_libraries(minifi-coap PUBLIC nanofi-coap-c PRIVATE ${CMAKE_DL_LIBS})

if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(minifi-coap PUBLIC "${CMAKE_THREAD_LIBS_INIT}")
endif()

target_link_libraries (nanofi-coap-c ${COAP_LIBRARIES})
target_link_libraries (nanofi-coap-c ${HTTP-CURL})
target_link_libraries (minifi-coap nanofi-coap-c ${COAP_LIBRARIES})
if (WIN32)
set_target_properties(minifi-coap PROPERTIES
LINK_FLAGS "/WHOLEARCHIVE"
LINK_FLAGS "/WHOLEARCHIVE"
)
elseif (APPLE)
set_target_properties(minifi-coap PROPERTIES
Expand All @@ -85,5 +103,4 @@ else ()
endif ()

SET (COAP-EXTENSION minifi-coap PARENT_SCOPE)
register_extension(minifi-coap)

register_extension(minifi-coap)
19 changes: 19 additions & 0 deletions extensions/coap/DownloadCoapCMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.0)
include(ExternalProject)

find_package(Patch REQUIRED)

set(PATCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(LIBCOAP_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/libcoap-src")

ExternalProject_Add(
libcoap-external
GIT_REPOSITORY "https://github.com/obgm/libcoap.git"
GIT_TAG "d6c25a9a0757af9d13842b7aae9713136e720567"
#GIT_TAG "00486a4f46e0278dd24a8ff3411416ff420cde29"
SOURCE_DIR "${LIBCOAP_SRC_DIR}"
PATCH_COMMAND "${Patch_EXECUTABLE}" "-p1" "-i" "${PATCH_DIR}/libcoap_windows.patch"
BUILD_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
)
13 changes: 13 additions & 0 deletions extensions/coap/libcoap_windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/coap_config.h.windows b/coap_config.h.windows
index dbbe509..c281161 100644
--- a/coap_config.h.windows
+++ b/coap_config.h.windows
@@ -67,7 +67,7 @@
#define snprintf _snprintf
#endif

-#define HAVE_OPENSSL 1
+//#define HAVE_OPENSSL 1

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net"
1 change: 1 addition & 0 deletions extensions/coap/nanofi/coap_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int8_t free_pdu(CoapPDU * pdu) {
}
coap_delete_optlist(pdu->optlist);
coap_session_release(pdu->session);
free_app_data(pdu->ctx);
coap_free_context(pdu->ctx);
free(pdu);
return 0;
Expand Down
1 change: 0 additions & 1 deletion extensions/coap/nanofi/coap_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern "C" {
#endif

#include <coap2/coap.h>
#include <netdb.h>
#include "coap_message.h"
#include "coap_functions.h"

Expand Down

0 comments on commit 68ce755

Please sign in to comment.