CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #
  2. # Copyright (C) 2006-2023 wolfSSL Inc.
  3. #
  4. # This file is part of wolfSSL.
  5. #
  6. # wolfSSL is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # wolfSSL is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  19. #
  20. # cmake for wolfssl
  21. #
  22. cmake_minimum_required(VERSION 3.5)
  23. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
  24. set(CMAKE_CURRENT_SOURCE_DIR ".")
  25. # We are currently in [root]/IDE/Espressif/ESP-IDF/examples/wolfssl_test/components/wolfssl
  26. # The root of wolfSSL is 7 directories up from here:
  27. get_filename_component(WOLFSSL_ROOT "../../../../../../../" ABSOLUTE)
  28. # Espressif may take several passes through this makefile. Check to see if we found IDF
  29. string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "" WOLFSSL_FOUND_IDF)
  30. if($WOLFSSL_FOUND_IDF)
  31. message(STATUS "IDF_PATH = $ENV{IDF_PATH}")
  32. message(STATUS "WOLFSSL_ROOT = ${WOLFSSL_ROOT}")
  33. message(STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
  34. endif()
  35. # get a list of all wolfcrypt assembly files; we'll exclude them as they don't target Xtensa
  36. FILE(GLOB EXCLUDE_ASM *.S)
  37. file(GLOB_RECURSE EXCLUDE_ASM ${CMAKE_SOURCE_DIR} "${WOLFSSL_ROOT}/wolfcrypt/src/*.S")
  38. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  39. message(STATUS "EXCLUDE_ASM = ${EXCLUDE_ASM}")
  40. endif()
  41. set(INCLUDE_PATH ${WOLFSSL_ROOT})
  42. set(COMPONENT_SRCDIRS "${WOLFSSL_ROOT}/src/"
  43. "${WOLFSSL_ROOT}/wolfcrypt/src/"
  44. "${WOLFSSL_ROOT}/wolfcrypt/src/port/Espressif/"
  45. "${WOLFSSL_ROOT}/wolfcrypt/src/port/atmel/"
  46. "${WOLFSSL_ROOT}/wolfcrypt/benchmark/"
  47. "${WOLFSSL_ROOT}/wolfcrypt/test/"
  48. )
  49. set(COMPONENT_REQUIRES lwip)
  50. # check to see if there's both a local copy and EDP-IDF copy of the wolfssl and/or wolfssh components
  51. if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  52. #
  53. # wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
  54. #
  55. message(STATUS "")
  56. message(STATUS "**************************************************************************************")
  57. message(STATUS "")
  58. message(STATUS "Error: Found components/wolfssl in both local project and IDF_PATH")
  59. message(STATUS "")
  60. message(STATUS "To proceed: ")
  61. message(STATUS "")
  62. message(STATUS "Remove either the local project component: ${CMAKE_HOME_DIRECTORY}/components/wolfssl/ ")
  63. message(STATUS "or the Espressif shared component installed at: $ENV{IDF_PATH}/components/wolfssl/ ")
  64. message(STATUS "")
  65. message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
  66. message(STATUS "")
  67. message(STATUS "**************************************************************************************")
  68. message(STATUS "")
  69. # Optional: if you change the above FATAL_ERROR to STATUS you can warn at runtime with this macro definition:
  70. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
  71. else()
  72. if( EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  73. #
  74. # wolfSSL found in ESP-IDF components and is assumed to be already configured in user_settings.h via setup.
  75. #
  76. message(STATUS "")
  77. message(STATUS "Using components/wolfssl in IDF_PATH = $ENV{IDF_PATH}")
  78. message(STATUS "")
  79. else()
  80. #
  81. # wolfSSL is not an ESP-IDF component. We need to now determine if it is local and if so if it is part of the wolfSSL repo
  82. # or if wolfSSL is simply installed as a local component.
  83. #
  84. if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" )
  85. #
  86. # wolfSSL found in local project.
  87. #
  88. if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/include/" )
  89. message(STATUS "")
  90. message(STATUS "Using installed project ./components/wolfssl in CMAKE_HOME_DIRECTORY = $ENV{CMAKE_HOME_DIRECTORY}")
  91. message(STATUS "")
  92. #
  93. # Note we already checked above and confirmed there's not another wolfSSL installed in the ESP-IDF components.
  94. #
  95. # We won't do anything else here, as it will be assumed the original install completed successfully.
  96. #
  97. else()
  98. #
  99. # This is the developer repo mode. wolfSSL will be assume to be not installed to ESP-IDF nor local project
  100. # In this configuration, we are likely running a wolfSSL example found directly in the repo.
  101. #
  102. message(STATUS "")
  103. message(STATUS "Using developer repo ./components/wolfssl in CMAKE_HOME_DIRECTORY = $ENV{CMAKE_HOME_DIRECTORY}")
  104. message(STATUS "")
  105. message(STATUS "************************************************************************************************")
  106. # When in developer mode, we are typically running wolfSSL examples such as benchmark or test directories.
  107. # However, the as-cloned or distributed wolfSSL does not have the ./include/ directory, so we'll add it as needed.
  108. #
  109. # first check if there's a [root]/include/user_settings.h
  110. if( EXISTS "${WOLFSSL_ROOT}/include/user_settings.h" )
  111. # we won't overwrite an existing user settings file, just note that we already have one:
  112. message(STATUS "Found wolfSSL user_settings.h in ${WOLFSSL_ROOT}/include/user_settings.h")
  113. else()
  114. message(STATUS "Installing wolfSSL user_settings.h to ${WOLFSSL_ROOT}/include/user_settings.h")
  115. file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/user_settings.h" DESTINATION "${WOLFSSL_ROOT}/include/")
  116. endif() # user_settings.h
  117. # next check if there's a [root]/include/config.h
  118. if( EXISTS "${WOLFSSL_ROOT}/include/config.h" )
  119. message(STATUS "Found wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h")
  120. else()
  121. message(STATUS "Installing wolfSSL config.h to ${WOLFSSL_ROOT}/include/config.h")
  122. file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/dummy_config_h" DESTINATION "${WOLFSSL_ROOT}/include/")
  123. file(RENAME "${WOLFSSL_ROOT}/include/dummy_config_h" "${WOLFSSL_ROOT}/include/config.h")
  124. endif() # config.h
  125. message(STATUS "************************************************************************************************")
  126. message(STATUS "")
  127. endif()
  128. else()
  129. # we did not find a ./components/wolfssl/include/ directory from this pass of cmake.
  130. if($WOLFSSL_FOUND_IDF)
  131. message(STATUS "")
  132. message(STATUS "WARNING: wolfSSL not found.")
  133. message(STATUS "")
  134. else()
  135. # probably needs to be re-parsed by Espressif
  136. message(STATUS "wolfSSL found IDF. Project Source:${PROJECT_SOURCE_DIR}")
  137. endif() # else we have not found ESP-IDF yet
  138. endif() # else not a local wolfSSL component
  139. endif() #else not an ESP-IDF component
  140. endif() # else not local copy and EDP-IDF wolfSSL
  141. # RTOS_IDF_PATH is typically:
  142. # "/Users/{username}/Desktop/esp-idf/components/freertos/include/freertos"
  143. # depending on the environment, we may need to swap backslashes with forward slashes
  144. string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/include/freertos")
  145. # ESP-IDF after version 4.4x has a different RTOS directory structure
  146. string(REPLACE "\\" "/" RTOS_IDF_PATH5 "$ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
  147. if(IS_DIRECTORY ${IDF_PATH}/components/freertos/FreeRTOS-Kernel/)
  148. set(COMPONENT_ADD_INCLUDEDIRS
  149. "."
  150. "${WOLFSSL_ROOT}/include"
  151. "${RTOS_IDF_PATH5}"
  152. "${WOLFSSL_ROOT}"
  153. )
  154. else()
  155. set(COMPONENT_ADD_INCLUDEDIRS
  156. "."
  157. "${WOLFSSL_ROOT}/include"
  158. "${RTOS_IDF_PATH}"
  159. "${WOLFSSL_ROOT}"
  160. )
  161. endif()
  162. if(IS_DIRECTORY ${IDF_PATH}/components/cryptoauthlib)
  163. list(APPEND COMPONENT_ADD_INCLUDEDIRS "../cryptoauthlib/lib")
  164. endif()
  165. set(COMPONENT_SRCEXCLUDE
  166. "${WOLFSSL_ROOT}/src/bio.c"
  167. "${WOLFSSL_ROOT}/src/conf.c"
  168. "${WOLFSSL_ROOT}/src/misc.c"
  169. "${WOLFSSL_ROOT}/src/pk.c"
  170. "${WOLFSSL_ROOT}/src/ssl_asn1.c" # included by ssl.c
  171. "${WOLFSSL_ROOT}/src/ssl_bn.c" # included by ssl.c
  172. "${WOLFSSL_ROOT}/src/ssl_certman.c" # included by ssl.c
  173. "${WOLFSSL_ROOT}/src/ssl_misc.c" # included by ssl.c
  174. "${WOLFSSL_ROOT}/src/x509.c"
  175. "${WOLFSSL_ROOT}/src/x509_str.c"
  176. "${WOLFSSL_ROOT}/wolfcrypt/src/evp.c"
  177. "${WOLFSSL_ROOT}/wolfcrypt/src/misc.c"
  178. "${EXCLUDE_ASM}"
  179. )
  180. set(COMPONENT_PRIV_INCLUDEDIRS ${IDF_PATH}/components/driver/include)
  181. register_component()
  182. # some optional diagnostics
  183. if (0)
  184. get_cmake_property(_variableNames VARIABLES)
  185. list (SORT _variableNames)
  186. message(STATUS "")
  187. message(STATUS "ALL VARIABLES BEGIN")
  188. message(STATUS "")
  189. foreach (_variableName ${_variableNames})
  190. message(STATUS "${_variableName}=${${_variableName}}")
  191. endforeach()
  192. message(STATUS "")
  193. message(STATUS "ALL VARIABLES END")
  194. message(STATUS "")
  195. endif()
  196. # check to see if there's both a local copy and EDP-IDF copy of the wolfssl components
  197. if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  198. message(STATUS "")
  199. message(STATUS "")
  200. message(STATUS "********************************************************************")
  201. message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
  202. message(STATUS "********************************************************************")
  203. message(STATUS "")
  204. endif()
  205. # end multiple component check