2019-04-28 03:38:23 -04:00
|
|
|
idf_component_register(SRCS "mbedtls.c"
|
|
|
|
INCLUDE_DIRS "port/include" "mbedtls/include"
|
|
|
|
REQUIRES lwip)
|
2018-01-11 21:49:13 -05:00
|
|
|
|
2018-11-11 02:44:54 -05:00
|
|
|
# Only build mbedtls libraries
|
|
|
|
set(ENABLE_TESTING CACHE BOOL OFF)
|
|
|
|
set(ENABLE_PROGRAMS CACHE BOOL OFF)
|
|
|
|
|
|
|
|
# Use same policy between IDF and mbedtls build
|
|
|
|
function(project)
|
|
|
|
set(_args ARGV)
|
|
|
|
_project(${${_args}})
|
|
|
|
cmake_policy(SET CMP0022 NEW)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Needed to for include_next includes to work from within mbedtls
|
2019-05-09 22:53:08 -04:00
|
|
|
include_directories("${COMPONENT_DIR}/port/include")
|
2018-11-11 02:44:54 -05:00
|
|
|
|
2018-12-17 22:43:22 -05:00
|
|
|
# Workaround issue with creating symbolic links due to issues with native
|
|
|
|
# path conversion (TO_NATIVE_PATH). The following summarizes what CMake invocations
|
|
|
|
# this workaround is for:
|
|
|
|
#
|
|
|
|
# 1. CMake from command line + Ninja = No errors
|
|
|
|
# 2. CMake from command line + MinGW Makefiles = Forward slash for paths, mklink mistakes path for a switch
|
|
|
|
# 3. CMake from MSYS + Ninja = No errors
|
|
|
|
# 4. CMake from MSYS + Unix Makefiles/MSYS Makefiles = Forward slash for paths, mklink mistakes path for a switch
|
|
|
|
#
|
|
|
|
# There are references to the issue in case (2) and (4) in https://github.com/ARMmbed/mbedtls/issues/1496,
|
|
|
|
# https://cmake.org/pipermail/cmake/2006-July/010193.html, and https://cmake.org/Bug/view.php?id=5939.
|
|
|
|
#
|
|
|
|
# This workaround is meant to circumvent logic inside link_to_source() function in mbedtls/mbedtls/CMakeLists.txt.
|
|
|
|
if(CMAKE_HOST_WIN32)
|
|
|
|
set(msystem $ENV{MSYSTEM})
|
|
|
|
if(MSYS OR msystem)
|
|
|
|
# Solves case (4). When in MSYS environment, instead opt to use the Unix equivalent of mklink.
|
|
|
|
set(CMAKE_HOST_UNIX 1)
|
|
|
|
else()
|
|
|
|
# Solves case (2). When invoked from command line, create the symbolic links ahead of link_to_source() invocations
|
|
|
|
# using a 'hybrid' path format resilient intermediary - in this case a Python wrapper for mklink. This is more unweildy
|
|
|
|
# than necessary, since string(REPLACE "/" "\\" ... does not actually work.
|
|
|
|
set(target_links "mbedtls/include/mbedtls"
|
|
|
|
"mbedtls/scripts")
|
|
|
|
foreach(target_link ${target_links})
|
|
|
|
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${target_link} link)
|
2019-05-09 22:53:08 -04:00
|
|
|
file(TO_NATIVE_PATH ${COMPONENT_DIR}/${target_link} target)
|
2018-12-13 05:24:06 -05:00
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
idf_build_get_property(python PYTHON)
|
2018-12-17 22:43:22 -05:00
|
|
|
if(NOT EXISTS ${link})
|
2019-05-09 22:53:08 -04:00
|
|
|
if(IS_DIRECTORY ${target})
|
|
|
|
set(command ${python} ${COMPONENT_DIR}/mklink.py /j ${link} ${target})
|
2018-12-17 22:43:22 -05:00
|
|
|
else()
|
2019-05-09 22:53:08 -04:00
|
|
|
set(command ${python} ${COMPONENT_DIR}/mklink.py /h ${link} ${target})
|
2018-12-17 22:43:22 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(COMMAND ${command}
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
ERROR_VARIABLE output)
|
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
if(NOT ${result} EQUAL 0)
|
2018-12-17 22:43:22 -05:00
|
|
|
message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2018-11-30 06:48:05 -05:00
|
|
|
endif()
|
|
|
|
|
2018-11-11 02:44:54 -05:00
|
|
|
# Import mbedtls library targets
|
|
|
|
add_subdirectory(mbedtls)
|
|
|
|
|
2018-11-08 00:56:33 -05:00
|
|
|
# Use port specific implementation of net_socket.c instead of one from mbedtls
|
|
|
|
get_target_property(src_tls mbedtls SOURCES)
|
|
|
|
list(REMOVE_ITEM src_tls net_sockets.c)
|
|
|
|
set_property(TARGET mbedtls PROPERTY SOURCES ${src_tls})
|
|
|
|
|
2018-11-11 02:44:54 -05:00
|
|
|
set(mbedtls_targets mbedtls mbedcrypto mbedx509)
|
|
|
|
|
|
|
|
# Add port files to mbedtls targets
|
2019-05-09 22:53:08 -04:00
|
|
|
target_sources(mbedtls PRIVATE "${COMPONENT_DIR}/port/esp_bignum.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp_hardware.c"
|
2019-05-13 00:32:45 -04:00
|
|
|
"${COMPONENT_PATH}/port/esp_sha.c"
|
2019-05-09 22:53:08 -04:00
|
|
|
"${COMPONENT_DIR}/port/esp_sha1.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp_sha256.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp_sha512.c"
|
|
|
|
"${COMPONENT_DIR}/port/mbedtls_debug.c"
|
|
|
|
"${COMPONENT_DIR}/port/net_sockets.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp32/aes.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp32/sha.c")
|
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_mem.c")
|
2018-11-11 02:44:54 -05:00
|
|
|
|
|
|
|
foreach(target ${mbedtls_targets})
|
|
|
|
target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Link mbedtls libraries to component library
|
2019-06-04 07:05:33 -04:00
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE ${mbedtls_targets})
|