Désolé je suis nouveau à faire et CMake mais j'essaye de convertir cet exemple AWS IoT faire dans CMake. J'ai réussi à en faire la majeure partie en dehors de l'inclusion de la bibliothèque mbedTLS. On dirait qu'il y a une sous-marque de cette bibliothèque et ensuite elle est incluse.Conversion de créer à CMake avec des bibliothèques externes
Tous les indices seraient appréciés, ou d'autres lectures sur le sujet.
#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
C'est ce que j'ai jusqu'à présent.
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})
https://github.com/aws/aws-iot-device-sdk-embedded-C
En CMake [add_subdirectory] (https://cmake.org/cmake/help/v3.0/command/add_subdirectory.html) peut être utilisé pour le processus 'CMakeLists.txt' dans ce répertoire aussi. Probablement, vous devez utiliser cette commande. – Tsyvarev