From a8e02144a9f675a987f237b4a28b44d9d84f55a1 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Sat, 16 Dec 2023 11:23:08 -0800 Subject: [PATCH] wolfssh server example: update local wolfssl component cmake to 5.6.0.011 --- .../components/wolfssl/CMakeLists.txt | 270 ++++++++++-------- 1 file changed, 153 insertions(+), 117 deletions(-) diff --git a/ide/Espressif/ESP-IDF/examples/wolfssh_server/components/wolfssl/CMakeLists.txt b/ide/Espressif/ESP-IDF/examples/wolfssh_server/components/wolfssl/CMakeLists.txt index 7f482a4f8..e82e19b60 100644 --- a/ide/Espressif/ESP-IDF/examples/wolfssh_server/components/wolfssl/CMakeLists.txt +++ b/ide/Espressif/ESP-IDF/examples/wolfssh_server/components/wolfssl/CMakeLists.txt @@ -19,6 +19,8 @@ # # cmake for wolfssl Espressif projects # +# Version 5.6.0.011 for detect test/benchmark +# # See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html # @@ -26,6 +28,23 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS") set(CMAKE_CURRENT_SOURCE_DIR ".") set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl component +set(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}" ) + +# find the user name to search for possible "wolfssl-username" +message(STATUS "USERNAME = $ENV{USERNAME}") +if( "$ENV{USER}" STREQUAL "" ) # the bash user + if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user + message(STATUS "could not find USER or USERNAME") + else() + # the bash user is not blank, so we'll use it. + set(THIS_USER "$ENV{USERNAME}") + endif() +else() + # the bash user is not blank, so we'll use it. + set(THIS_USER "$ENV{USER}") +endif() +message(STATUS "THIS_USER = ${THIS_USER}") + # COMPONENT_NAME = wolfssl # The component name is the directory name. "No feature to change this". @@ -41,11 +60,104 @@ set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl # We are typically in [root]/IDE/Espressif/ESP-IDF/examples/wolfssl_test/components/wolfssl # The root of wolfSSL is 7 directories up from here: +# function: IS_WOLFSSL_SOURCE +# parameter: DIRECTORY_PARAMETER - the directory to test +# output: RESULT = contains contents of DIRECTORY_PARAMETER for wolfssl directory, otherwise blank. +function(IS_WOLFSSL_SOURCE DIRECTORY_PARAMETER RESULT) + if (EXISTS "${DIRECTORY_PARAMETER}/wolfcrypt/src") + set(${RESULT} "${DIRECTORY_PARAMETER}" PARENT_SCOPE) + else() + set(${RESULT} "" PARENT_SCOPE) + endif() +endfunction() + +# function: FIND_WOLFSSL_DIRECTORY +# parameter: OUTPUT_FOUND_WOLFSSL_DIRECTORY contains root of source code, otherwise blank +# +function(FIND_WOLFSSL_DIRECTORY OUTPUT_FOUND_WOLFSSL_DIRECTORY) + message(STATUS "Starting FIND_WOLFSSL_DIRECTORY") + set(CURRENT_SEARCH_DIR "$ENV{WOLFSSL_ROOT}") + if( "${CURRENT_SEARCH_DIR}" STREQUAL "" ) + message(STATUS "The WOLFSSL_ROOT environment variable is not set. Searching...") + else() + get_filename_component(CURRENT_SEARCH_DIR "$ENV{WOLFSSL_ROOT}" ABSOLUTE) + IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR}" FOUND_WOLFSSL) + if("${FOUND_WOLFSSL}") + message(STATUS "Found WOLFSSL_ROOT via Environment Variable:") + else() + message(FATAL_ERROR "WOLFSSL_ROOT Environment Variable defined, but path not found:") + message(STATUS "$ENV{WOLFSSL_ROOT}") + endif() + endif() + + # we'll start in the CMAKE_CURRENT_SOURCE_DIR, typically [something]/projectname/components/wolfssl + message(STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}") + get_filename_component(CURRENT_SEARCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) + message(STATUS "CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}") + string(LENGTH ${CURRENT_SEARCH_DIR} CURRENT_SEARCH_DIR_LENGTH) + + # loop through all the parents, looking for wolfssl + while(NOT CURRENT_SEARCH_DIR STREQUAL "/" AND NOT CURRENT_SEARCH_DIR STREQUAL "" ) + string(LENGTH ${CURRENT_SEARCH_DIR} CURRENT_SEARCH_DIR_LENGTH) + # wolfSSL may simply be in a parent directory, such as for local examples in wolfssl repo + IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR}" FOUND_WOLFSSL) + if( FOUND_WOLFSSL ) + message(STATUS "Found wolfssl in CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}") + set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR} PARENT_SCOPE) + return() + endif() + + if( THIS_USER ) + # Check for "wolfssl-[username]" subdirectory as we recurse up the directory tree + set(CURRENT_SEARCH_DIR_ALT ${CURRENT_SEARCH_DIR}/wolfssl-${THIS_USER}) + message(STATUS "Looking in ${CURRENT_SEARCH_DIR}") + + #if(EXISTS ${CURRENT_SEARCH_DIR_ALT} AND IS_DIRECTORY ${CURRENT_SEARCH_DIR_ALT} AND EXISTS "${CURRENT_SEARCH_DIR_ALT}/wolfcrypt/src") + IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR_ALT}" FOUND_WOLFSSL ) + if ( FOUND_WOLFSSL ) + message(STATUS "Found wolfssl in user-suffix CURRENT_SEARCH_DIR_ALT = ${CURRENT_SEARCH_DIR_ALT}") + set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR_ALT} PARENT_SCOPE) + return() + endif() + endif() + + # Next check for no user suffix "wolfssl" subdirectory as we recurse up the directory tree + set(CURRENT_SEARCH_DIR_ALT ${CURRENT_SEARCH_DIR}/wolfssl) + # if(EXISTS ${CURRENT_SEARCH_DIR} AND IS_DIRECTORY ${CURRENT_SEARCH_DIR} AND EXISTS "${CURRENT_SEARCH_DIR}/wolfcrypt/src") + IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR_ALT}" FOUND_WOLFSSL ) + if ( FOUND_WOLFSSL ) + message(STATUS "Found wolfssl in CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}") + set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR} PARENT_SCOPE) + return() + endif() + + # Move up one directory level + set(PRIOR_SEARCH_DIR "${CURRENT_SEARCH_DIR}") + get_filename_component(CURRENT_SEARCH_DIR "${CURRENT_SEARCH_DIR}" DIRECTORY) + message(STATUS "Next CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}") + if( "${PRIOR_SEARCH_DIR}" STREQUAL "${CURRENT_SEARCH_DIR}" ) + # when the search directory is empty, we'll give up + set(CURRENT_SEARCH_DIR "") + endif() + endwhile() + + # If not found, set the output variable to empty before exiting + set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} "" PARENT_SCOPE) +endfunction() + + +# Example usage: + + + + if(CMAKE_BUILD_EARLY_EXPANSION) message(STATUS "wolfssl component CMAKE_BUILD_EARLY_EXPANSION:") idf_component_register( REQUIRES "${COMPONENT_REQUIRES}" - PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark + PRIV_REQUIRES # esp_hw_support + esp_timer + driver # this will typically only be needed for wolfSSL benchmark ) else() @@ -54,132 +166,41 @@ else() message(STATUS "wolfssl component config:") message(STATUS "************************************************************************************************") - # Check to see if we're already in wolfssl, and only if WOLFSSL_ROOT not specified - if ("${WOLFSSL_ROOT}" STREQUAL "") - # wolfssl examples are 7 directories deep from wolfssl repo root - # 1 2 3 4 5 6 7 - set(THIS_RELATIVE_PATH "../../../../../../..") - get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE) - message(STATUS "Searching in path = ${THIS_SEARCH_PATH}") - - if (EXISTS "${THIS_SEARCH_PATH}/wolfcrypt/src") - # we're already in wolfssl examples! - get_filename_component(WOLFSSL_ROOT "${THIS_SEARCH_PATH}" ABSOLUTE) - message(STATUS "Using wolfSSL example with root ${WOLFSSL_ROOT}") - else() - # We're in some other repo such as wolfssh, so we'll search for an - # adjacent-level directory for wolfssl. (8 directories up, then down one) - # - # For example wolfSSL examples: - # C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\wolfssl_benchmark\components\wolfssl - # - # For example wolfSSH examples: - # C:\workspace\wolfssh-gojimmypi\ide\Espressif\ESP-IDF\examples\wolfssh_benchmark\components\wolfssl - # - # 1 2 3 4 5 6 7 8 - set(THIS_RELATIVE_PATH "../../../../../../../..") - get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE) - message(STATUS "Searching next in path = ${THIS_SEARCH_PATH}") - endif() + # search for wolfSSL + FIND_WOLFSSL_DIRECTORY(WOLFSSL_ROOT) + if(WOLFSSL_ROOT) + message(STATUS "NEW Found wolfssl directory at: ${WOLFSSL_ROOT}") + else() + message(STATUS "NEW wolfssl directory not found.") + # Abort. We need wolfssl _somewhere_. + message(FATAL_ERROR "Could not find wolfssl in ${WOLFSSL_ROOT}.\n" + "Try setting WOLFSSL_ROOT environment variable or git clone.") endif() - # search other possible locations - if ("${WOLFSSL_ROOT}" STREQUAL "") - # there's not a hard-coded WOLFSSL_ROOT value above, so let's see if we can find it. - if( "$ENV{WOLFSSL_ROOT}" STREQUAL "" ) - message(STATUS "Environment Variable WOLFSSL_ROOT not set. Will search common locations.") - - message(STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}") - get_filename_component(THIS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) - message(STATUS "THIS_DIR = ${THIS_DIR}") - - # find the user name to search for possible "wolfssl-username" - message(STATUS "USERNAME = $ENV{USERNAME}") - if( "$ENV{USER}" STREQUAL "" ) # the bash user - if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user - message(STATUS "could not find USER or USERNAME") - else() - # the bash user is not blank, so we'll use it. - set(THIS_USER "$ENV{USERNAME}") - endif() - else() - # the bash user is not blank, so we'll use it. - set(THIS_USER "$ENV{USER}") - endif() - message(STATUS "THIS_USER = ${THIS_USER}") - - # This same makefile is used for both the wolfssl component, and other - # components that may depend on wolfssl, such as wolfssh. Therefore - # we need to determine if this makefile is in the wolfssl repo, or - # some other repo. - - if( "{THIS_USER}" STREQUAL "" ) - # This is highly unusual to not find a user name. - # In this case, we'll just search for a "wolfssl" directory: - message(STATUS "No username found!") - get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE) - else() - # We found an environment USER name! - # The first place to look for wolfssl will be in a user-clone called "wolfssl-[username]" - message(STATUS "Using [THIS_USER = ${THIS_USER}] to see if there's a [relative path]/wolfssl-${THIS_USER} directory.") - get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl-${THIS_USER}" ABSOLUTE) - - if( EXISTS "${WOLFSSL_ROOT}" ) - message(STATUS "Found wolfssl in user-suffix ${WOLFSSL_ROOT}") - else() - # If there's not a user-clone called "wolfssl-[username]", - # perhaps there's simply a git clone called "wolfssl"? - message(STATUS "Did not find wolfssl-${THIS_USER}; continuing search...") - get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE) - - if( EXISTS "${WOLFSSL_ROOT}" ) - message(STATUS "Found wolfssl in standard ${WOLFSSL_ROOT}") - else() - # Things are looking pretty bleak. We'll likely not be able to compile. - message(STATUS "Did not find wolfssl in ${WOLFSSL_ROOT}") - endif() - endif() - endif() - - else() - # there's an environment variable, so use it. - set(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}") + set(INCLUDE_PATH ${WOLFSSL_ROOT}) - if( EXISTS "${WOLFSSL_ROOT}" ) - get_filename_component(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}" ABSOLUTE) - message(STATUS "Found WOLFSSL_ROOT via Environment Variable:") - else() - message(FATAL_ERROR "WOLFSSL_ROOT Environment Variable defined, but path not found:") - message(STATUS "$ENV{WOLFSSL_ROOT}") - endif() - endif() - # end of search for wolfssl component root - else() - # There's already a value assigned; we won't search for anything else. - message(STATUS "Found user-specified WOLFSSL_ROOT value.") - endif() # WOLFSSL_ROOT user defined + set(WOLFSSL_EXTRA_PROJECT_DIR "${WOLFSSL_ROOT}/src/") - # After all the logic above, does our WOLFSSL_ROOT actually exist? - if( EXISTS "${WOLFSSL_ROOT}" ) - message(STATUS "WOLFSSL_ROOT = ${WOLFSSL_ROOT}") - else() - # Abort. We need wolfssl _somewhere_. - message(FATAL_ERROR "Could not find wolfssl in ${WOLFSSL_ROOT}. Try setting environment variable or git clone.") + if( ${CMAKE_PROJECT_NAME} STREQUAL "wolfssl_benchmark" ) + set(WOLFSSL_EXTRA_PROJECT_DIR "${WOLFSSL_ROOT}/wolfcrypt/benchmark") endif() - - set(INCLUDE_PATH ${WOLFSSL_ROOT}) + if( ${CMAKE_PROJECT_NAME} STREQUAL "wolfssl_test" ) + set(WOLFSSL_EXTRA_PROJECT_DIR "${WOLFSSL_ROOT}/wolfcrypt/test") + endif() set(COMPONENT_SRCDIRS "\"${WOLFSSL_ROOT}/src/\"" "\"${WOLFSSL_ROOT}/wolfcrypt/src\"" "\"${WOLFSSL_ROOT}/wolfcrypt/src/port/Espressif\"" "\"${WOLFSSL_ROOT}/wolfcrypt/src/port/atmel\"" - # "\"${WOLFSSL_ROOT}/wolfcrypt/benchmark\"" # the benchmark application - # "\"${WOLFSSL_ROOT}/wolfcrypt/test\"" # the test application - ) # COMPONENT_SRCDIRS + "\"${WOLFSSL_EXTRA_PROJECT_DIR}\"" + ) # COMPONENT_SRCDIRS + message(STATUS "This COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}") set(WOLFSSL_PROJECT_DIR "${CMAKE_HOME_DIRECTORY}/components/wolfssl") + add_definitions(-DWOLFSSL_USER_SETTINGS_DIR="${WOLFSSL_PROJECT_DIR}/include/user_settings.h") + # Espressif may take several passes through this makefile. Check to see if we found IDF string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "" WOLFSSL_FOUND_IDF) @@ -267,10 +288,10 @@ else() # we won't overwrite an existing user settings file, just note that we already have one: if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/user_settings.h" ) message(STATUS "Using existing wolfSSL user_settings.h in " - "${WOLFSSL_PROJECT_DIR}/include/user_settings.h") + "${WOLFSSL_PROJECT_DIR}/include/user_settings.h") else() message(STATUS "Installing wolfSSL user_settings.h to " - "${WOLFSSL_PROJECT_DIR}/include/user_settings.h") + "${WOLFSSL_PROJECT_DIR}/include/user_settings.h") file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/user_settings.h" DESTINATION "${CMAKE_HOME_DIRECTORY}/wolfssl/include/") endif() @@ -278,7 +299,12 @@ else() # next check if there's a [root]/include/config.h if( EXISTS "${WOLFSSL_ROOT}/include/config.h" ) - message(FATAL_ERROR "Found stray wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h (please move it to ${WOLFSSL_PROJECT_DIR}/include/config.h") + message(STATUS "******************************************************************************") + message(STATUS "******************************************************************************") + message(STATUS "Found stray wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h" ) + message(STATUS " Please move it to ${WOLFSSL_PROJECT_DIR}/include/config.h" ) + message(STATUS "******************************************************************************") + message(STATUS "******************************************************************************") else() # we won't overwrite an existing user settings file, just note that we already have one: if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/config.h" ) @@ -353,13 +379,22 @@ else() "\"${WOLFSSL_ROOT}/src/misc.c\"" "\"${WOLFSSL_ROOT}/src/pk.c\"" "\"${WOLFSSL_ROOT}/src/ssl_asn1.c\"" # included by ssl.c - "\"${WOLFSSL_ROOT}/src/ssl_certman.c\"" # included by ssl.c "\"${WOLFSSL_ROOT}/src/ssl_bn.c\"" # included by ssl.c + "\"${WOLFSSL_ROOT}/src/ssl_certman.c\"" # included by ssl.c + "\"${WOLFSSL_ROOT}/src/ssl_crypto.c\"" # included by ssl.c "\"${WOLFSSL_ROOT}/src/ssl_misc.c\"" # included by ssl.c "\"${WOLFSSL_ROOT}/src/x509.c\"" "\"${WOLFSSL_ROOT}/src/x509_str.c\"" "\"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c\"" "\"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_arm32.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_arm64.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_armthumb.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_c32.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_c64.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_cortexm.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_x86_64.c\"" + "\"${WOLFSSL_ROOT}/wolfcrypt/src/sp_sm2_x86_64_asm.S\"" "\"${EXCLUDE_ASM}\"" ) @@ -404,6 +439,7 @@ else() endif() # target_sources(wolfssl PRIVATE "\"${WOLFSSL_ROOT}/wolfssl/\"" "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt\"") + endif() # CMAKE_BUILD_EARLY_EXPANSION