Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide build-time switch to disable JSON support. #61

Merged
merged 2 commits into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enable_testing ()
# build tests, but disable running by default
option (BUILD_TESTS "Build tests" ON)
option (RUN_TESTS "Enable tests" OFF)
option (WITH_JSON "Enable JSON support" ON)
# cmdline: cmake -DBUILD_TESTS=ON -DRUN_TESTS=OFF ..

option (ENABLE_GCOV "Enable code coverage check" OFF)
Expand Down
2 changes: 1 addition & 1 deletion api/tests-static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set (test_static_api_runner_LIBRARIES
gtest
pthread
awa_static
lwm2m_common_static
awa_common_static
Awa_static
libb64_static
)
Expand Down
4 changes: 4 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (WITH_JSON)
add_definitions (-DWITH_JSON)
endif ()

add_subdirectory (src)

if (BUILD_TESTS)
Expand Down
15 changes: 11 additions & 4 deletions core/src/bootstrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set (awa_bootstrapd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_tlv.c
${CORE_SRC_DIR}/common/lwm2m_plaintext.c
${CORE_SRC_DIR}/common/lwm2m_prettyprint.c
${CORE_SRC_DIR}/common/lwm2m_json.c
${CORE_SRC_DIR}/common/lwm2m_opaque.c
${CORE_SRC_DIR}/common/lwm2m_tree_builder.c
)
Expand All @@ -17,10 +16,18 @@ set (awa_bootstrapd_INCLUDE_DIRS
${CORE_SRC_DIR}
${CORE_SRC_DIR}/common
${CORE_SRC_DIR}/bootstrap
${LIBB64_INCLUDE_DIR}
${LIBJSMN_INCLUDE_DIR}
)

if (WITH_JSON)
list (APPEND awa_bootstrapd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_json.c
)
# LIBJSMN_INCLUDE_DIR is a global, as it's set by an imported target
list (APPEND awa_bootstrapd_INCLUDE_DIRS
${LIBJSMN_INCLUDE_DIR}
)
endif ()

add_definitions (-DLWM2M_BOOTSTRAP)

if (ENABLE_GCOV_TEST)
Expand All @@ -30,7 +37,7 @@ endif ()

add_executable (awa_bootstrapd ${awa_bootstrapd_SOURCES})
target_include_directories (awa_bootstrapd PRIVATE ${awa_bootstrapd_INCLUDE_DIRS})
target_link_libraries (awa_bootstrapd lwm2m_common_static)
target_link_libraries (awa_bootstrapd awa_common_static)

if (ENABLE_GCOV_TEST)
target_link_libraries (awa_bootstrapd gcov)
Expand Down
19 changes: 13 additions & 6 deletions core/src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ set (awa_clientd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_tlv.c
${CORE_SRC_DIR}/common/lwm2m_plaintext.c
${CORE_SRC_DIR}/common/lwm2m_prettyprint.c
${CORE_SRC_DIR}/common/lwm2m_json.c
${CORE_SRC_DIR}/common/lwm2m_opaque.c
${CORE_SRC_DIR}/common/lwm2m_tree_builder.c
${CORE_SRC_DIR}/common/lwm2m_observers.c
${CORE_SRC_DIR}/common/lwm2m_ipc.c
lwm2m_object_tree.c
lwm2m_object_tree.c

######################## TODO REMOVE ########################
# TODO: extract components common to both Core and API
# FIXME: API_SRC_DIR is not in the cmake cache at the time this is read
Expand All @@ -46,14 +45,12 @@ set (awa_clientd_SOURCES
# (it is not possible to link with an OBJECT library, so these are not automatic)
get_property (LIB_XML_INCLUDE_DIR TARGET libxml_static PROPERTY INCLUDE_DIRECTORIES)
get_property (LIB_B64_INCLUDE_DIR TARGET libb64_static PROPERTY INCLUDE_DIRECTORIES)
get_property (LIB_JSMN_INCLUDE_DIR TARGET libjsmn_static PROPERTY INCLUDE_DIRECTORIES)
get_property (LIB_HMAC_INCLUDE_DIR TARGET libhmac_static PROPERTY INCLUDE_DIRECTORIES)

set (awa_clientd_INCLUDE_DIRS
${LIB_XML_INCLUDE_DIR}
${LIB_B64_INCLUDE_DIR}
${LIB_HMAC_INCLUDE_DIR}
${LIBJSMN_INCLUDE_DIR}

${CORE_SRC_DIR}
${CORE_SRC_DIR}/common
Expand All @@ -69,6 +66,16 @@ set (awa_clientd_INCLUDE_DIRS
#############################################################
)

if (WITH_JSON)
list (APPEND awa_clientd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_json.c
)
# LIBJSMN_INCLUDE_DIR is a global, as it's set by an imported target
list (APPEND awa_clientd_INCLUDE_DIRS
${LIBJSMN_INCLUDE_DIR}
)
endif ()

add_definitions (-DLWM2M_CLIENT)

if (ENABLE_GCOV)
Expand All @@ -83,7 +90,7 @@ set_property (TARGET awa_static PROPERTY POSITION_INDEPENDENT_CODE ON)

add_executable (awa_clientd lwm2m_client.c)
target_include_directories (awa_clientd PRIVATE ${awa_clientd_INCLUDE_DIRS})
target_link_libraries (awa_clientd awa_static lwm2m_common_static libb64_static libhmac_static)
target_link_libraries (awa_clientd awa_static awa_common_static libb64_static libhmac_static)

if (ENABLE_GCOV)
target_link_libraries (awa_clientd gcov)
Expand Down
39 changes: 27 additions & 12 deletions core/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set (lwm2m_common_SOURCES
set (awa_common_SOURCES
lwm2m_list.c
coap_abstraction_libcoap.c
lwm2m_debug.c
Expand All @@ -17,26 +17,41 @@ set (lwm2m_common_SOURCES
# path here. the API tests depend on core, which depends on the API.
set (API_INCLUDE_DIR ../../../api/include CACHE INTERNAL "API_INCLUDE_DIR")

set (lwm2m_common_INCLUDE_DIRS
set (awa_common_INCLUDE_DIRS
${LIBCOAP_INCLUDE_DIR}
${LIBJSMN_INCLUDE_DIR}
${API_INCLUDE_DIR}
)

set (awa_common_LIBS
libxml_static
libcoap_static
libb64_static
)

if (WITH_JSON)
# LIBJSMN_INCLUDE_DIR is a global, as it's set by an imported target
list (APPEND awa_common_INCLUDE_DIRS
${LIBJSMN_INCLUDE_DIR}
)
list (APPEND awa_common_LIBS
libjsmn_static
)
endif ()

# Virtual library to avoid building .o files twice:
#add_library(lwm2m_common_object OBJECT ${lwm2m_common_SOURCES})
#target_include_directories (lwm2m_common_object PRIVATE ${lwm2m_common_INCLUDE_DIRS})
#add_library(lwm2m_common_object OBJECT ${awa_common_SOURCES})
#target_include_directories (lwm2m_common_object PRIVATE ${awa_common_INCLUDE_DIRS})
#set_property(TARGET lwm2m_common_object PROPERTY POSITION_INDEPENDENT_CODE ON)

#add_library (lwm2m_common_static STATIC $<TARGET_OBJECTS:lwm2m_common_object>)
add_library (lwm2m_common_static STATIC ${lwm2m_common_SOURCES})
set_target_properties (lwm2m_common_static PROPERTIES OUTPUT_NAME "lwm2mcommon")
set_target_properties (lwm2m_common_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
#add_library (awa_common_static STATIC $<TARGET_OBJECTS:lwm2m_common_object>)
add_library (awa_common_static STATIC ${awa_common_SOURCES})
set_target_properties (awa_common_static PROPERTIES OUTPUT_NAME "lwm2mcommon")
set_target_properties (awa_common_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
# TODO: remove this line after sorting out the libcoap_static include path
target_include_directories(lwm2m_common_static PUBLIC ${lwm2m_common_INCLUDE_DIRS})
target_include_directories(awa_common_static PUBLIC ${awa_common_INCLUDE_DIRS})

# Combine libxml and libcoap into lwm2m_common_static:
target_link_libraries (lwm2m_common_static libxml_static libcoap_static libjsmn_static libb64_static)
# Combine libxml and libcoap into awa_common_static:
target_link_libraries (awa_common_static ${awa_common_LIBS})

# Currently disabled as libxml isn't PIC
#add_library (lwm2m_common_shared SHARED $<TARGET_OBJECTS:lwm2m_common_object>)
Expand Down
8 changes: 6 additions & 2 deletions core/src/common/lwm2m_serdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ const static SerdesMapEntry serdesList[] =
{ ContentType_CustomPrettyPrint, &ppSerDes },

#ifndef CONTIKI
#ifdef WITH_JSON
{ ContentType_ApplicationOmaLwm2mJson, &jsonSerDes },
#endif
#endif // WITH_JSON
#endif // CONTIKI
{ ContentType_ApplicationOmaLwm2mTLV, &tlvSerDes },
{ ContentType_ApplicationPlainText, &plainTextSerDes },
{ ContentType_ApplicationOctetStream, &opaqueSerDes },

// Mapping for old types
{ ContentType_ApplicationOmaLwm2mText, &plainTextSerDes },
#ifndef CONTIKI
#ifdef WITH_JSON
{ ContentType_ApplicationJson, &jsonSerDes },
#endif
#endif // WITH_JSON
#endif // CONTIKI
{ ContentType_ApplicationOmaLwm2mOpaque, &opaqueSerDes },
};
#define NUM_SERIALISERS (sizeof(serdesList)/sizeof(SerdesMapEntry))
Expand Down
18 changes: 12 additions & 6 deletions core/src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ set (awa_serverd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_tlv.c
${CORE_SRC_DIR}/common/lwm2m_plaintext.c
${CORE_SRC_DIR}/common/lwm2m_prettyprint.c
${CORE_SRC_DIR}/common/lwm2m_json.c
${CORE_SRC_DIR}/common/lwm2m_opaque.c
${CORE_SRC_DIR}/common/lwm2m_tree_builder.c
${CORE_SRC_DIR}/common/lwm2m_ipc.c

######################## TODO REMOVE ########################
# TODO: extract components common to both Core and API
# FIXME: API_SRC_DIR is not in the cmake cache at the time this is read
Expand All @@ -38,27 +37,34 @@ set (awa_serverd_SOURCES
# (it is not possible to link with an OBJECT library, so these are not automatic)
get_property (LIB_XML_INCLUDE_DIR TARGET libxml_static PROPERTY INCLUDE_DIRECTORIES)
get_property (LIB_B64_INCLUDE_DIR TARGET libb64_static PROPERTY INCLUDE_DIRECTORIES)
get_property (LIB_JSMN_INCLUDE_DIR TARGET libjsmn_static PROPERTY INCLUDE_DIRECTORIES)

set (awa_serverd_INCLUDE_DIRS
${LIB_XML_INCLUDE_DIR}
${LIB_B64_INCLUDE_DIR}
${LIBJSMN_INCLUDE_DIR}

${CORE_SRC_DIR}
${CORE_SRC_DIR}/common
${CORE_SRC_DIR}/server

######################## TODO REMOVE ########################
# TODO: extract components common to both Core and API
# FIXME: API_INCLUDE_DIR is not in the cmake cache at the time this is read
# FIXME: API_INCLUDE_DIR is not in the cmake cache at the time this is read
#${API_INCLUDE_DIR}
#${API_SRC_DIR}
${CORE_SRC_DIR}/../../api/src
${CORE_SRC_DIR}/../../api/include
#############################################################
)

if (WITH_JSON)
list (APPEND awa_serverd_SOURCES
${CORE_SRC_DIR}/common/lwm2m_json.c
)
# LIBJSMN_INCLUDE_DIR is a global, as it's set by an imported target
list (APPEND awa_serverd_INCLUDE_DIRS
${LIBJSMN_INCLUDE_DIR})
endif ()

add_definitions (-DLWM2M_SERVER)

if (ENABLE_GCOV)
Expand All @@ -81,7 +87,7 @@ set_target_properties (awa_serverd_shared PROPERTIES OUTPUT_NAME "lwm2mserver")

add_executable (awa_serverd lwm2m_server.c)
target_include_directories (awa_serverd PRIVATE ${awa_serverd_INCLUDE_DIRS})
target_link_libraries (awa_serverd awa_serverd_static lwm2m_common_static)
target_link_libraries (awa_serverd awa_serverd_static awa_common_static)

if (ENABLE_GCOV)
target_link_libraries (awa_serverd gcov)
Expand Down
9 changes: 7 additions & 2 deletions core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set (test_core_runner_SOURCES
test_object_store_interface.cc
test_template.cc
test_tlv.cc
test_json.cc
test_definition_registry.cc
test_plaintext.cc
test_prettyprint.cc
Expand All @@ -30,9 +29,15 @@ set (test_core_runner_LIBRARIES
pthread
libcoap_static
awa_static
lwm2m_common_static
awa_common_static
)

if (WITH_JSON)
list (APPEND test_core_runner_SOURCES
test_json.cc
)
endif ()

set (CMAKE_CXX_FLAGS "-Wall -Werror -g -std=c++11")

add_definitions (-DLWM2M_CLIENT -D__STDC_FORMAT_MACROS)
Expand Down
5 changes: 4 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ add_subdirectory (b64)
add_subdirectory (hmac)
add_subdirectory (libcoap)
add_subdirectory (xml)
add_subdirectory (jsmn)

if (WITH_JSON)
add_subdirectory (jsmn)
endif ()

if (BUILD_TESTS)
# gtest is CMake-enabled
Expand Down
5 changes: 3 additions & 2 deletions lib/jsmn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ ExternalProject_Add(libjsmn
PATCH_COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in ${CMAKE_BINARY_DIR}/libjsmn-src/CMakeLists.txt
)

# for now use a global variable for this until we find a way of setting the property on the libjsmn_static target
# target properties are not allowed for imported targets, so for now use a global variable
# for this until we find a way of setting the property on the libjsmn_static target
set (LIBJSMN_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libjsmn-src ${CMAKE_BINARY_DIR}/libjsmn-build CACHE INTERNAL "")

add_library(libjsmn_static STATIC IMPORTED GLOBAL)
set_target_properties(libjsmn_static PROPERTIES IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/libjsmn-build/libjsmn.a")
#set_target_properties(libjsmn_static PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${LIBJSMN_INCLUDE_DIR})