iotstack-device-sdk-c/CMakeLists.txt

118 lines
3.6 KiB
CMake

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)
option(ENABLE_LOG_INFO "是否打开INFO日志输出" OFF)
option(ENABLE_LOG_DEBUG "是否打开DEBUG日志输出" OFF)
option(ENABLE_IOT_TRACE "是否打开函数跟踪" OFF)
option(ENABLE_FEATURE_MQTT_COMM "是否打开MQTT通道的总开关" ON)
option(ENABLE_FEATURE_OTA "是否打开OTA固件升级总开关" ON)
option(ENABLE_FEATURE_AUTH_MODE_DYNAMIC "是否打开设备动态注册" ON)
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_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_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)