2019-08-01 10:30:53 +08:00
|
|
|
cmake_minimum_required(VERSION 2.5)
|
|
|
|
project(uiot_c_sdk)
|
|
|
|
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
|
|
|
|
option(ENABLE_LOG_ERROR "是否打开ERROR日志输出" ON)
|
|
|
|
option(ENABLE_LOG_WARN "是否打开WARN日志输出" ON)
|
2019-08-29 17:31:02 +08:00
|
|
|
option(ENABLE_LOG_INFO "是否打开INFO日志输出" OFF)
|
2019-08-01 10:30:53 +08:00
|
|
|
option(ENABLE_LOG_DEBUG "是否打开DEBUG日志输出" OFF)
|
|
|
|
option(ENABLE_IOT_TRACE "是否打开函数跟踪" OFF)
|
|
|
|
|
|
|
|
option(ENABLE_FEATURE_MQTT_COMM "是否打开MQTT通道的总开关" ON)
|
|
|
|
option(ENABLE_FEATURE_DEVICE_SHADOW "是否打开设备影子的总开关" ON)
|
|
|
|
option(ENABLE_FEATURE_OTA "是否打开OTA固件升级总开关" ON)
|
|
|
|
option(ENABLE_FEATURE_DEVICE_MODEL "是否打开物模型的总开关" ON)
|
|
|
|
option(ENABLE_FEATURE_AUTH_MODE_DYNAMIC "是否打开设备动态注册" ON)
|
2019-08-29 17:31:02 +08:00
|
|
|
option(ENABLE_FEATURE_UPLOAD_FILE "是否打开设备文件上传" ON)
|
2019-08-01 10:30:53 +08:00
|
|
|
option(ENABLE_TLS_SUPPORT "是否打开TLS支持" ON)
|
|
|
|
option(ENABLE_SDK_TESTS "是否打开SDK测试用例编译" ON)
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "-DFORCE_SSL_VERIFY -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread")
|
|
|
|
|
|
|
|
include_directories(platform/os/linux src/sdk-impl src/utils src/certs)
|
|
|
|
|
|
|
|
AUX_SOURCE_DIRECTORY(platform/os/linux PLATFORM_OS_LINUX)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/utils UTILS)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/certs CERTS)
|
|
|
|
|
|
|
|
set(src_iot_platform ${PLATFORM_OS_LINUX})
|
|
|
|
set(src_iot_sdk ${UTILS} ${CERTS})
|
|
|
|
|
|
|
|
if (ENABLE_LOG_ERROR)
|
|
|
|
message("ENABLE_LOG_ERROR = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LOG_ERROR")
|
|
|
|
else ()
|
|
|
|
message("ENABLE_LOG_ERROR = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_LOG_WARN)
|
|
|
|
message("ENABLE_LOG_WARN = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LOG_WARN")
|
|
|
|
else ()
|
|
|
|
message("ENABLE_LOG_WARN = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_LOG_INFO)
|
|
|
|
message("ENABLE_LOG_INFO = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LOG_INFO")
|
|
|
|
else ()
|
|
|
|
message("ENABLE_LOG_INFO = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_LOG_DEBUG)
|
|
|
|
message("ENABLE_LOG_DEBUG = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_LOG_DEBUG")
|
|
|
|
else ()
|
|
|
|
message("ENABLE_LOG_DEBUG = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_IOT_TRACE)
|
|
|
|
message("ENABLE_IOT_TRACE = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_IOT_TRACE")
|
|
|
|
else ()
|
|
|
|
message("ENABLE_IOT_TRACE = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_MQTT_COMM)
|
|
|
|
message("ENABLE_FEATURE_MQTT_COMM = y")
|
|
|
|
include_directories(src/mqtt/include)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/mqtt/src MQTT_SRC)
|
|
|
|
set(src_iot_sdk ${src_iot_sdk} ${MQTT_SRC})
|
|
|
|
else ()
|
|
|
|
message("ENABLE_FEATURE_MQTT_COMM = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_AUTH_MODE_DYNAMIC)
|
|
|
|
message("FEATURE_AUTH_MODE_DYNAMIC = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAUTH_MODE_DYNAMIC")
|
|
|
|
else ()
|
|
|
|
message("FEATURE_AUTH_MODE_DYNAMIC = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_DEVICE_SHADOW)
|
|
|
|
message("ENABLE_FEATURE_DEVICE_SHADOW = y")
|
|
|
|
include_directories(src/shadow/include)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/shadow/src SHADOW_SRC)
|
|
|
|
set(src_iot_sdk ${src_iot_sdk} ${SHADOW_SRC})
|
|
|
|
else ()
|
|
|
|
message("ENABLE_FEATURE_DEVICE_SHADOW = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_OTA)
|
|
|
|
message("ENABLE_FEATURE_OTA = y")
|
|
|
|
include_directories(src/ota/include)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/ota/src OTA_SRC)
|
|
|
|
set(src_iot_sdk ${src_iot_sdk} ${OTA_SRC})
|
|
|
|
else ()
|
|
|
|
message("ENABLE_FEATURE_OTA = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (ENABLE_FEATURE_DEVICE_MODEL)
|
|
|
|
message("ENABLE_FEATURE_DEVICE_MODEL = y")
|
|
|
|
include_directories(src/dev_model/include)
|
|
|
|
AUX_SOURCE_DIRECTORY(src/dev_model/src DM_SRC)
|
|
|
|
set(src_iot_sdk ${src_iot_sdk} ${DM_SRC})
|
|
|
|
else ()
|
|
|
|
message("ENABLE_FEATURE_DEVICE_MODEL = n")
|
|
|
|
endif ()
|
|
|
|
|
2019-08-29 17:31:02 +08:00
|
|
|
if (ENABLE_FEATURE_UPLOAD_FILE)
|
|
|
|
message("ENABLE_FEATURE_UPLOAD_FILE = y")
|
2019-11-22 17:38:06 +08:00
|
|
|
AUX_SOURCE_DIRECTORY(src/upload_file UPLOAD_FILE_SRC)
|
|
|
|
set(src_iot_sdk ${src_iot_sdk} ${UPLOAD_FILE_SRC})
|
2019-08-29 17:31:02 +08:00
|
|
|
else ()
|
|
|
|
message("ENABLE_FEATURE_UPLOAD_FILE = n")
|
|
|
|
endif ()
|
|
|
|
|
2019-08-01 10:30:53 +08:00
|
|
|
if (ENABLE_TLS_SUPPORT)
|
|
|
|
message("FEATURE_SUPPORT_TLS = y")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSUPPORT_TLS")
|
|
|
|
include_directories(external_libs/mbedtls/include)
|
|
|
|
AUX_SOURCE_DIRECTORY(platform/ssl/mbedtls PLATFORM_TLS)
|
|
|
|
add_subdirectory(external_libs/mbedtls/library)
|
|
|
|
set(src_iot_platform ${src_iot_platform} ${PLATFORM_TLS})
|
|
|
|
else ()
|
|
|
|
message("FEATURE_SUPPORT_TLS = n")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
|
|
|
|
|
|
|
|
|
|
|
|
add_library(iot_sdk STATIC ${src_iot_sdk})
|
|
|
|
SET_TARGET_PROPERTIES(iot_sdk PROPERTIES LINKER_LANGUAGE C)
|
|
|
|
|
|
|
|
add_library(iot_platform STATIC ${src_iot_platform})
|
|
|
|
if (ENABLE_TLS_SUPPORT)
|
|
|
|
add_dependencies(iot_platform mbedtls mbedx509 mbedcrypto)
|
|
|
|
target_link_libraries(iot_platform mbedtls mbedx509 mbedcrypto)
|
|
|
|
endif ()
|
|
|
|
SET_TARGET_PROPERTIES(iot_platform PROPERTIES LINKER_LANGUAGE C)
|
|
|
|
|
|
|
|
if (ENABLE_SDK_TESTS)
|
|
|
|
add_subdirectory(external_libs/googletest)
|
|
|
|
add_subdirectory(tests/unit_test)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
add_subdirectory(samples)
|