对不起,我是新手制作和CMake,但我试图将此示例AWS IoT转换为CMake。除了包含mbedTLS库之外,我还成功完成了其中的大部分工作。它看起来像是该库的子品牌,然后它被包含在内。
任何线索都会受到赞赏,或进一步阅读该主题。
#This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully.
.prevent_execution:
exit 0
CC = gcc
#remove @ for no make command prints
DEBUG = @
APP_DIR = .
APP_INCLUDE_DIRS += -I $(APP_DIR)
APP_NAME = subscribe_publish_sample
APP_SRC_FILES = $(APP_NAME).c
#IoT client directory
IOT_CLIENT_DIR = ../../..
PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c')
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
#TLS - mbedtls
MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS
TLS_LIB_DIR = $(MBEDTLS_DIR)/library
TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread
#Aggregate all include and src directories
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
SRC_FILES += $(APP_SRC_FILES)
SRC_FILES += $(IOT_SRC_FILES)
# Logging level control
LOG_FLAGS += -DIOT_DEBUG
LOG_FLAGS += -DIOT_INFO
LOG_FLAGS += -DIOT_WARN
LOG_FLAGS += -DIOT_ERROR
COMPILER_FLAGS += $(LOG_FLAGS)
#If the processor is big endian uncomment the compiler flag
#COMPILER_FLAGS += -DREVERSED
MBED_TLS_MAKE_CMD = cd $(MBEDTLS_DIR) && make
PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD)
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
all:
$(PRE_MAKE_CMD)
$(DEBUG)$(MAKE_CMD)
$(POST_MAKE_CMD)
clean:
rm -f $(APP_DIR)/$(APP_NAME)
$(MBED_TLS_MAKE_CMD) clean
这是我到目前为止所做的。
cmake_minimum_required(VERSION 3.5)
project(Gateway)
include_directories("${PROJECT_BINARY_DIR}" "external_libs/jsmin" "platform/linux/mbedtls" "platform/linux/common" "include")
set(SOURCE_FILES subscribe_publish_sample.c)
file(GLOB IOT_CLIENT_SOURCES "src/*.c")
file(GLOB IOT_CLIENT_EXTERNAL_SOURCES "external_libs/jsmn/*.c")
file(GLOB PLATFORM_SOURCES "platform/linux/mbedtls/*.c")
file(GLOB PLATFORM_COMMON_SOURCES "platform/linux/common/*.c")
add_executable(Gateway ${SOURCE_FILES} ${IOT_CLINT_SOURCES} ${IOT_CLIENT_EXTERNAL_SOURCES} ${PLATFORM_SOURCES} ${PLATFORM_COMMON_SOURCES})
答案 0 :(得分:1)
Aprox文件夹结构:
aws_iot
| - embedded C sdk folders
| - ....
sample
| - include
| - aws_iot_config.h
| - src
| - subscribe_publish_sample.c
原始Makefile(更新版本)
.prevent_execution:
exit 0
#This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully.
CC = gcc
#remove @ for no make command prints
DEBUG=@
APP_DIR = .
APP_INCLUDE_DIRS += -I $(APP_DIR)
APP_NAME=subscribe_publish_sample
APP_SRC_FILES=$(APP_NAME).c
#IoT client directory
IOT_CLIENT_DIR=../../aws_iot_src
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/utils
PLATFORM_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
#MQTT Paho Embedded C client directory
MQTT_DIR = ../../aws_mqtt_embedded_client_lib
MQTT_C_DIR = $(MQTT_DIR)/MQTTClient-C/src
MQTT_EMB_DIR = $(MQTT_DIR)/MQTTPacket/src
MQTT_INCLUDE_DIR += -I $(MQTT_EMB_DIR)
MQTT_INCLUDE_DIR += -I $(MQTT_C_DIR)
MQTT_SRC_FILES += $(shell find $(MQTT_EMB_DIR)/ -name '*.c')
MQTT_SRC_FILES += $(MQTT_C_DIR)/MQTTClient.c
#TLS - openSSL
TLS_LIB_DIR = /usr/lib/
TLS_INCLUDE_DIR = -I /usr/include/openssl
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
LD_FLAG := -ldl -lssl -lcrypto
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
#Aggregate all include and src directories
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR)
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
SRC_FILES += $(MQTT_SRC_FILES)
SRC_FILES += $(APP_SRC_FILES)
SRC_FILES += $(IOT_SRC_FILES)
# Logging level control
LOG_FLAGS += -DIOT_DEBUG
LOG_FLAGS += -DIOT_INFO
LOG_FLAGS += -DIOT_WARN
LOG_FLAGS += -DIOT_ERROR
COMPILER_FLAGS += -g
COMPILER_FLAGS += $(LOG_FLAGS)
#If the processor is big endian uncomment the compiler flag
#COMPILER_FLAGS += -DREVERSED
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
all:
$(PRE_MAKE_CMD)
$(DEBUG)$(MAKE_CMD)
$(POST_MAKE_CMD)
clean:
rm -f $(APP_DIR)/$(APP_NAME)
转换CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(sample)
# Setup appropriate path to C SDK
set(AWS_IOT_ROOT_DIR ../aws_iot)
#IoT client directory
#> IOT_CLIENT_DIR=../../aws_iot_src
set(IOT_CLIENT_DIR ${AWS_IOT_ROOT_DIR}/aws_iot_src)
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
#> IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/utils
include_directories(
${IOT_CLIENT_DIR}/protocol/mqtt
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
${IOT_CLIENT_DIR}/utils
)
#> PLATFORM_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
set(PLATFORM_DIR ${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl)
#> PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
set(PLATFORM_COMMON_DIR ${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common)
#> IOT_SRC_FILES += $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
#> IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
#> IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
file(GLOB IOT_SRC_FILES
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
${PLATFORM_DIR}/*.c
${PLATFORM_COMMON_DIR}/*.c
)
#MQTT Paho Embedded C client directory
#> MQTT_DIR = ../../aws_mqtt_embedded_client_lib
set(MQTT_DIR ${AWS_IOT_ROOT_DIR}/aws_mqtt_embedded_client_lib)
#> MQTT_C_DIR = $(MQTT_DIR)/MQTTClient-C/src
set(MQTT_C_DIR ${MQTT_DIR}/MQTTClient-C/src)
#> MQTT_EMB_DIR = $(MQTT_DIR)/MQTTPacket/src
set(MQTT_EMB_DIR ${MQTT_DIR}/MQTTPacket/src)
#> MQTT_SRC_FILES += $(shell find $(MQTT_EMB_DIR)/ -name '*.c')
#> MQTT_SRC_FILES += $(MQTT_C_DIR)/MQTTClient.c
file(GLOB MQTT_SRC_FILES
${MQTT_EMB_DIR}/*.c
${MQTT_C_DIR}/MQTTClient.c
)
#TLS - openSSL
#> TLS_LIB_DIR = /usr/lib/
#> TLS_INCLUDE_DIR = -I /usr/include/openssl
set(TLS_INCLUDE_DIR /usr/include/openssl)
find_package(OpenSSL REQUIRED openssl)
# this just for debug purpose
message("OPENSSL_ROOT_DIR is ${OPENSSL_ROOT_DIR}")
message("OPENSSL_LIBRARIES is ${OPENSSL_LIBRARIES}")
#Aggregate all include and src directories
#> MQTT_INCLUDE_DIR += -I $(MQTT_EMB_DIR)
#> MQTT_INCLUDE_DIR += -I $(MQTT_C_DIR)
#> INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
#> INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR)
#> INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
#> INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
include_directories(
include
${TLS_INCLUDE_DIR}
${MQTT_EMB_DIR}
${MQTT_C_DIR}
)
#> SRC_FILES += $(MQTT_SRC_FILES)
#> SRC_FILES += $(APP_SRC_FILES)
set(SOURCE_FILES
${IOT_SRC_FILES}
${MQTT_SRC_FILES}
)
#> MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
add_executable(subscribe_publish_sample src/subscribe_publish_sample.c ${SOURCE_FILES})
target_link_libraries(subscribe_publish_sample ${OPENSSL_LIBRARIES} )
看看这个CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(sample)
# Define correct path to embedded C sdk
set(AWS_IOT_ROOT_DIR ../aws_iot)
set(IOT_CLIENT_DIR ${AWS_IOT_ROOT_DIR}/aws_iot_src)
include_directories(
${IOT_CLIENT_DIR}/protocol/mqtt
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
${IOT_CLIENT_DIR}/utils
)
set(MQTT_DIR ${AWS_IOT_ROOT_DIR}/aws_mqtt_embedded_client_lib)
set(MQTT_C_DIR ${MQTT_DIR}/MQTTClient-C/src)
set(MQTT_EMB_DIR ${MQTT_DIR}/MQTTPacket/src)
include_directories(
${MQTT_EMB_DIR}
${MQTT_C_DIR}
)
set(TLS_INCLUDE_DIR /usr/include/openssl)
include_directories(
include
${TLS_INCLUDE_DIR}
)
set(PLATFORM_DIR ${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl)
set(PLATFORM_COMMON_DIR ${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common)
file(GLOB IOT_SRC_FILES
${IOT_CLIENT_DIR}/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
${PLATFORM_DIR}/*.c
${PLATFORM_COMMON_DIR}/*.c
)
file(GLOB MQTT_SRC_FILES
${MQTT_EMB_DIR}/*.c
${MQTT_C_DIR}/MQTTClient.c
)
set(SOURCE_FILES
${IOT_SRC_FILES}
${MQTT_SRC_FILES})
find_package(OpenSSL REQUIRED openssl)
add_executable(subscribe_publish_sample src/subscribe_publish_sample.c ${SOURCE_FILES})
target_link_libraries(subscribe_publish_sample ${OPENSSL_LIBRARIES} )