CMakeLists.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 Espressif projects
  21. #
  22. # Version 5.6.0.009 for FIND_WOLFSSL_DIRECTORY
  23. #
  24. # See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html
  25. #
  26. cmake_minimum_required(VERSION 3.16)
  27. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
  28. set(CMAKE_CURRENT_SOURCE_DIR ".")
  29. set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl component
  30. set(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}" )
  31. # find the user name to search for possible "wolfssl-username"
  32. message(STATUS "USERNAME = $ENV{USERNAME}")
  33. if( "$ENV{USER}" STREQUAL "" ) # the bash user
  34. if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
  35. message(STATUS "could not find USER or USERNAME")
  36. else()
  37. # the bash user is not blank, so we'll use it.
  38. set(THIS_USER "$ENV{USERNAME}")
  39. endif()
  40. else()
  41. # the bash user is not blank, so we'll use it.
  42. set(THIS_USER "$ENV{USER}")
  43. endif()
  44. message(STATUS "THIS_USER = ${THIS_USER}")
  45. # COMPONENT_NAME = wolfssl
  46. # The component name is the directory name. "No feature to change this".
  47. # See https://github.com/espressif/esp-idf/issues/8978#issuecomment-1129892685
  48. # set the root of wolfSSL:
  49. # set(WOLFSSL_ROOT "C:/some path/with/spaces")
  50. # set(WOLFSSL_ROOT "c:/workspace/wolfssl-gojimmypi")
  51. # set(WOLFSSL_ROOT "/mnt/c/some path/with/spaces")
  52. # or use this logic to assign value from Environment Variable WOLFSSL_ROOT,
  53. # or assume this is an example 7 subdirectories below:
  54. # We are typically in [root]/IDE/Espressif/ESP-IDF/examples/wolfssl_test/components/wolfssl
  55. # The root of wolfSSL is 7 directories up from here:
  56. # function: IS_WOLFSSL_SOURCE
  57. # parameter: DIRECTORY_PARAMETER - the directory to test
  58. # output: RESULT = contains contents of DIRECTORY_PARAMETER for wolfssl directory, otherwise blank.
  59. function(IS_WOLFSSL_SOURCE DIRECTORY_PARAMETER RESULT)
  60. if (EXISTS "${DIRECTORY_PARAMETER}/wolfcrypt/src")
  61. set(${RESULT} "${DIRECTORY_PARAMETER}" PARENT_SCOPE)
  62. else()
  63. set(${RESULT} "" PARENT_SCOPE)
  64. endif()
  65. endfunction()
  66. # function: FIND_WOLFSSL_DIRECTORY
  67. # parameter: OUTPUT_FOUND_WOLFSSL_DIRECTORY contains root of source code, otherwise blank
  68. #
  69. function(FIND_WOLFSSL_DIRECTORY OUTPUT_FOUND_WOLFSSL_DIRECTORY)
  70. message(STATUS "Starting FIND_WOLFSSL_DIRECTORY")
  71. set(CURRENT_SEARCH_DIR "$ENV{WOLFSSL_ROOT}")
  72. if( "${CURRENT_SEARCH_DIR}" STREQUAL "" )
  73. message(STATUS "The WOLFSSL_ROOT environment variable is not set. Searching...")
  74. else()
  75. get_filename_component(CURRENT_SEARCH_DIR "$ENV{WOLFSSL_ROOT}" ABSOLUTE)
  76. IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR}" FOUND_WOLFSSL)
  77. if("${FOUND_WOLFSSL}")
  78. message(STATUS "Found WOLFSSL_ROOT via Environment Variable:")
  79. else()
  80. message(FATAL_ERROR "WOLFSSL_ROOT Environment Variable defined, but path not found:")
  81. message(STATUS "$ENV{WOLFSSL_ROOT}")
  82. endif()
  83. endif()
  84. # we'll start in the CMAKE_CURRENT_SOURCE_DIR, typically [something]/projectname/components/wolfssl
  85. message(STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}")
  86. get_filename_component(CURRENT_SEARCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
  87. message(STATUS "CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}")
  88. string(LENGTH ${CURRENT_SEARCH_DIR} CURRENT_SEARCH_DIR_LENGTH)
  89. # loop through all the parents, looking for wolfssl
  90. while(NOT CURRENT_SEARCH_DIR STREQUAL "/" AND NOT CURRENT_SEARCH_DIR STREQUAL "" )
  91. string(LENGTH ${CURRENT_SEARCH_DIR} CURRENT_SEARCH_DIR_LENGTH)
  92. # wolfSSL may simply be in a parent directory, such as for local examples in wolfssl repo
  93. IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR}" FOUND_WOLFSSL)
  94. if( FOUND_WOLFSSL )
  95. message(STATUS "Found wolfssl in CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}")
  96. set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR} PARENT_SCOPE)
  97. return()
  98. endif()
  99. if( THIS_USER )
  100. # Check for "wolfssl-[username]" subdirectory as we recurse up the directory tree
  101. set(CURRENT_SEARCH_DIR_ALT ${CURRENT_SEARCH_DIR}/wolfssl-${THIS_USER})
  102. message(STATUS "Looking in ${CURRENT_SEARCH_DIR}")
  103. #if(EXISTS ${CURRENT_SEARCH_DIR_ALT} AND IS_DIRECTORY ${CURRENT_SEARCH_DIR_ALT} AND EXISTS "${CURRENT_SEARCH_DIR_ALT}/wolfcrypt/src")
  104. IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR_ALT}" FOUND_WOLFSSL )
  105. if ( FOUND_WOLFSSL )
  106. message(STATUS "Found wolfssl in user-suffix CURRENT_SEARCH_DIR_ALT = ${CURRENT_SEARCH_DIR_ALT}")
  107. set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR_ALT} PARENT_SCOPE)
  108. return()
  109. endif()
  110. endif()
  111. # Next check for no user suffix "wolfssl" subdirectory as we recurse up the directory tree
  112. set(CURRENT_SEARCH_DIR_ALT ${CURRENT_SEARCH_DIR}/wolfssl)
  113. # if(EXISTS ${CURRENT_SEARCH_DIR} AND IS_DIRECTORY ${CURRENT_SEARCH_DIR} AND EXISTS "${CURRENT_SEARCH_DIR}/wolfcrypt/src")
  114. IS_WOLFSSL_SOURCE("${CURRENT_SEARCH_DIR_ALT}" FOUND_WOLFSSL )
  115. if ( FOUND_WOLFSSL )
  116. message(STATUS "Found wolfssl in CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}")
  117. set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} ${CURRENT_SEARCH_DIR} PARENT_SCOPE)
  118. return()
  119. endif()
  120. # Move up one directory level
  121. set(PRIOR_SEARCH_DIR "${CURRENT_SEARCH_DIR}")
  122. get_filename_component(CURRENT_SEARCH_DIR "${CURRENT_SEARCH_DIR}" DIRECTORY)
  123. message(STATUS "Next CURRENT_SEARCH_DIR = ${CURRENT_SEARCH_DIR}")
  124. if( "${PRIOR_SEARCH_DIR}" STREQUAL "${CURRENT_SEARCH_DIR}" )
  125. # when the search directory is empty, we'll give up
  126. set(CURRENT_SEARCH_DIR "")
  127. endif()
  128. endwhile()
  129. # If not found, set the output variable to empty before exiting
  130. set(${OUTPUT_FOUND_WOLFSSL_DIRECTORY} "" PARENT_SCOPE)
  131. endfunction()
  132. if(CMAKE_BUILD_EARLY_EXPANSION)
  133. message(STATUS "wolfssl component CMAKE_BUILD_EARLY_EXPANSION:")
  134. idf_component_register(
  135. REQUIRES "${COMPONENT_REQUIRES}"
  136. PRIV_REQUIRES # esp_hw_support
  137. esp_timer
  138. driver # this will typically only be needed for wolfSSL benchmark
  139. )
  140. else()
  141. # not CMAKE_BUILD_EARLY_EXPANSION
  142. message(STATUS "************************************************************************************************")
  143. message(STATUS "wolfssl component config:")
  144. message(STATUS "************************************************************************************************")
  145. # search for wolfSSL
  146. FIND_WOLFSSL_DIRECTORY(WOLFSSL_ROOT)
  147. if(WOLFSSL_ROOT)
  148. message(STATUS "NEW Found wolfssl directory at: ${WOLFSSL_ROOT}")
  149. else()
  150. message(STATUS "NEW wolfssl directory not found.")
  151. # Abort. We need wolfssl _somewhere_.
  152. message(FATAL_ERROR "Could not find wolfssl in ${WOLFSSL_ROOT}.\n"
  153. "Try setting WOLFSSL_ROOT environment variable or git clone.")
  154. endif()
  155. set(INCLUDE_PATH ${WOLFSSL_ROOT})
  156. set(COMPONENT_SRCDIRS "\"${WOLFSSL_ROOT}/src/\""
  157. "\"${WOLFSSL_ROOT}/wolfcrypt/src\""
  158. "\"${WOLFSSL_ROOT}/wolfcrypt/src/port/Espressif\""
  159. "\"${WOLFSSL_ROOT}/wolfcrypt/src/port/atmel\""
  160. "\"${WOLFSSL_ROOT}/wolfcrypt/benchmark\"" # the benchmark application
  161. "\"${WOLFSSL_ROOT}/wolfcrypt/test\"" # the test application
  162. ) # COMPONENT_SRCDIRS
  163. message(STATUS "This COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
  164. set(WOLFSSL_PROJECT_DIR "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
  165. # Espressif may take several passes through this makefile. Check to see if we found IDF
  166. string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "" WOLFSSL_FOUND_IDF)
  167. # get a list of all wolfcrypt assembly files; we'll exclude them as they don't target Xtensa
  168. file(GLOB EXCLUDE_ASM *.S)
  169. file(GLOB_RECURSE EXCLUDE_ASM ${CMAKE_SOURCE_DIR} "${WOLFSSL_ROOT}/wolfcrypt/src/*.S")
  170. message(STATUS "IDF_PATH = $ENV{IDF_PATH}")
  171. message(STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
  172. message(STATUS "EXCLUDE_ASM = ${EXCLUDE_ASM}")
  173. #
  174. # Check to see if there's both a local copy and EDP-IDF copy of the wolfssl and/or wolfssh components.
  175. #
  176. if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  177. #
  178. # wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
  179. #
  180. message(STATUS "")
  181. message(STATUS "**************************************************************************************")
  182. message(STATUS "")
  183. message(STATUS "Error: Found components/wolfssl in both local project and IDF_PATH")
  184. message(STATUS "")
  185. message(STATUS "To proceed: ")
  186. message(STATUS "")
  187. message(STATUS "Remove either the local project component: ${WOLFSSL_PROJECT_DIR} ")
  188. message(STATUS "or the Espressif shared component installed at: $ENV{IDF_PATH}/components/wolfssl/ ")
  189. message(STATUS "")
  190. message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
  191. message(STATUS "")
  192. message(STATUS "**************************************************************************************")
  193. message(STATUS "")
  194. # Optional: if you change the above FATAL_ERROR to STATUS you can warn at runtime with this macro definition:
  195. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
  196. else()
  197. if( EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  198. #
  199. # wolfSSL found in ESP-IDF components and is assumed to be already configured in user_settings.h via setup.
  200. #
  201. message(STATUS "")
  202. message(STATUS "Using components/wolfssl in IDF_PATH = $ENV{IDF_PATH}")
  203. message(STATUS "")
  204. else()
  205. #
  206. # wolfSSL is not an ESP-IDF component.
  207. # We need to now determine if it is local and if so if it is part of the wolfSSL repo,
  208. # or if wolfSSL is simply installed as a local component.
  209. #
  210. if( EXISTS "${WOLFSSL_PROJECT_DIR}" )
  211. #
  212. # wolfSSL found in local project.
  213. #
  214. if( EXISTS "${WOLFSSL_PROJECT_DIR}/wolfcrypt/" )
  215. message(STATUS "")
  216. message(STATUS "Using installed project ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
  217. message(STATUS "")
  218. #
  219. # Note we already checked above and confirmed there's not another wolfSSL installed in the ESP-IDF components.
  220. #
  221. # We won't do anything else here, as it will be assumed the original install completed successfully.
  222. #
  223. else() # full wolfSSL not installed in local project
  224. #
  225. # This is the developer repo mode. wolfSSL will be assumed to be not installed to ESP-IDF nor local project
  226. # In this configuration, we are likely running a wolfSSL example found directly in the repo.
  227. #
  228. message(STATUS "")
  229. message(STATUS "Using developer repo ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
  230. message(STATUS "")
  231. message(STATUS "************************************************************************************************")
  232. # When in developer mode, we are typically running wolfSSL examples such as benchmark or test directories.
  233. # However, the as-cloned or distributed wolfSSL does not have the ./include/ directory, so we'll add it as needed.
  234. #
  235. # first check if there's a [root]/include/user_settings.h
  236. if( EXISTS "${WOLFSSL_ROOT}/include/user_settings.h" )
  237. message(FATAL_ERROR "Found stray wolfSSL user_settings.h in "
  238. "${WOLFSSL_ROOT}/include/user_settings.h "
  239. " (please move it to ${WOLFSSL_PROJECT_DIR}/include/user_settings.h )")
  240. else()
  241. # we won't overwrite an existing user settings file, just note that we already have one:
  242. if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/user_settings.h" )
  243. message(STATUS "Using existing wolfSSL user_settings.h in "
  244. "${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
  245. else()
  246. message(STATUS "Installing wolfSSL user_settings.h to "
  247. "${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
  248. file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/user_settings.h"
  249. DESTINATION "${CMAKE_HOME_DIRECTORY}/wolfssl/include/")
  250. endif()
  251. endif() # user_settings.h
  252. # next check if there's a [root]/include/config.h
  253. if( EXISTS "${WOLFSSL_ROOT}/include/config.h" )
  254. message(FATAL_ERROR "Found stray wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h (please move it to ${WOLFSSL_PROJECT_DIR}/include/config.h")
  255. else()
  256. # we won't overwrite an existing user settings file, just note that we already have one:
  257. if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/config.h" )
  258. message(STATUS "Using existing wolfSSL config.h ${WOLFSSL_PROJECT_DIR}/include/config.h")
  259. else()
  260. message(STATUS "Installing wolfSSL config.h to ${WOLFSSL_PROJECT_DIR}/include/config.h")
  261. file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/dummy_config_h" DESTINATION "${WOLFSSL_PROJECT_DIR}/include/")
  262. file(RENAME "${WOLFSSL_PROJECT_DIR}/include/dummy_config_h" "${WOLFSSL_PROJECT_DIR}/include/config.h")
  263. endif() # Project config.h
  264. endif() # WOLFSSL_ROOT config.h
  265. message(STATUS "************************************************************************************************")
  266. message(STATUS "")
  267. endif()
  268. else()
  269. # we did not find a ./components/wolfssl/include/ directory from this pass of cmake.
  270. if($WOLFSSL_FOUND_IDF)
  271. message(STATUS "")
  272. message(STATUS "WARNING: wolfSSL not found.")
  273. message(STATUS "")
  274. else()
  275. # probably needs to be re-parsed by Espressif
  276. message(STATUS "wolfSSL found IDF. Project Source:${PROJECT_SOURCE_DIR}")
  277. endif() # else we have not found ESP-IDF yet
  278. endif() # else not a local wolfSSL component
  279. endif() #else not an ESP-IDF component
  280. endif() # else not local copy and EDP-IDF wolfSSL
  281. # RTOS_IDF_PATH is typically:
  282. # "/Users/{username}/Desktop/esp-idf/components/freertos/include/freertos"
  283. # depending on the environment, we may need to swap backslashes with forward slashes
  284. string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
  285. string(REPLACE "\\" "/" WOLFSSL_ROOT ${WOLFSSL_ROOT})
  286. if(IS_DIRECTORY "${RTOS_IDF_PATH}")
  287. message(STATUS "Found current RTOS path: ${RTOS_IDF_PATH}")
  288. else()
  289. # ESP-IDF prior version 4.4x has a different RTOS directory structure
  290. string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/include/freertos")
  291. if(IS_DIRECTORY "${RTOS_IDF_PATH}")
  292. message(STATUS "Found legacy RTOS path: ${RTOS_IDF_PATH}")
  293. else()
  294. message(STATUS "Could not find RTOS path")
  295. endif()
  296. endif()
  297. set(COMPONENT_ADD_INCLUDEDIRS
  298. "./include" # this is the location of wolfssl user_settings.h
  299. "\"${WOLFSSL_ROOT}/\""
  300. "\"${WOLFSSL_ROOT}/wolfssl/\""
  301. "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\""
  302. "\"${RTOS_IDF_PATH}/\""
  303. )
  304. if(IS_DIRECTORY ${IDF_PATH}/components/cryptoauthlib)
  305. list(APPEND COMPONENT_ADD_INCLUDEDIRS "../cryptoauthlib/lib")
  306. endif()
  307. list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/\"")
  308. list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\"")
  309. set(COMPONENT_SRCEXCLUDE
  310. "\"${WOLFSSL_ROOT}/src/bio.c\""
  311. "\"${WOLFSSL_ROOT}/src/conf.c\""
  312. "\"${WOLFSSL_ROOT}/src/misc.c\""
  313. "\"${WOLFSSL_ROOT}/src/pk.c\""
  314. "\"${WOLFSSL_ROOT}/src/ssl_asn1.c\"" # included by ssl.c
  315. "\"${WOLFSSL_ROOT}/src/ssl_bn.c\"" # included by ssl.c
  316. "\"${WOLFSSL_ROOT}/src/ssl_certman.c\"" # included by ssl.c
  317. "\"${WOLFSSL_ROOT}/src/ssl_crypto.c\"" # included by ssl.c
  318. "\"${WOLFSSL_ROOT}/src/ssl_misc.c\"" # included by ssl.c
  319. "\"${WOLFSSL_ROOT}/src/x509.c\""
  320. "\"${WOLFSSL_ROOT}/src/x509_str.c\""
  321. "\"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c\""
  322. "\"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c\""
  323. "\"${EXCLUDE_ASM}\""
  324. )
  325. spaces2list(COMPONENT_REQUIRES)
  326. separate_arguments(COMPONENT_SRCDIRS NATIVE_COMMAND "${COMPONENT_SRCDIRS}")
  327. separate_arguments(COMPONENT_SRCEXCLUDE NATIVE_COMMAND "${COMPONENT_SRCEXCLUDE}")
  328. separate_arguments(COMPONENT_ADD_INCLUDEDIRS NATIVE_COMMAND "${COMPONENT_ADD_INCLUDEDIRS}")
  329. #
  330. # See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#example-component-requirements
  331. #
  332. message(STATUS "COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
  333. message(STATUS "COMPONENT_ADD_INCLUDEDIRS = ${COMPONENT_ADD_INCLUDEDIRS}")
  334. message(STATUS "COMPONENT_REQUIRES = ${COMPONENT_REQUIRES}")
  335. message(STATUS "COMPONENT_SRCEXCLUDE = ${COMPONENT_SRCEXCLUDE}")
  336. #
  337. # see https://docs.espressif.com/projects/esp-idf/en/stable/esp32/migration-guides/release-5.x/build-system.html?highlight=space%20path
  338. #
  339. set(EXTRA_COMPONENT_DIRS "${COMPONENT_SRCDIRS}")
  340. idf_component_register(
  341. SRC_DIRS "${COMPONENT_SRCDIRS}"
  342. INCLUDE_DIRS "${COMPONENT_ADD_INCLUDEDIRS}"
  343. REQUIRES "${COMPONENT_REQUIRES}"
  344. EXCLUDE_SRCS "${COMPONENT_SRCEXCLUDE}"
  345. PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark
  346. )
  347. # some optional diagnostics
  348. if (0)
  349. get_cmake_property(_variableNames VARIABLES)
  350. list (SORT _variableNames)
  351. message(STATUS "")
  352. message(STATUS "ALL VARIABLES BEGIN")
  353. message(STATUS "")
  354. foreach (_variableName ${_variableNames})
  355. message(STATUS "${_variableName}=${${_variableName}}")
  356. endforeach()
  357. message(STATUS "")
  358. message(STATUS "ALL VARIABLES END")
  359. message(STATUS "")
  360. endif()
  361. # target_sources(wolfssl PRIVATE "\"${WOLFSSL_ROOT}/wolfssl/\"" "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt\"")
  362. endif() # CMAKE_BUILD_EARLY_EXPANSION
  363. # check to see if there's both a local copy and EDP-IDF copy of the wolfssl components
  364. if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  365. message(STATUS "")
  366. message(STATUS "")
  367. message(STATUS "********************************************************************")
  368. message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
  369. message(STATUS "********************************************************************")
  370. message(STATUS "")
  371. endif()
  372. # end multiple component check
  373. #
  374. # LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
  375. #
  376. # Save the THIS_VAR as a string in a macro called VAR_OUPUT
  377. #
  378. # VAR_OUPUT: the name of the macro to define
  379. # THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
  380. # VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
  381. #
  382. function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
  383. # is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
  384. string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
  385. # if we had a successful operation, save the THIS_VAR in VAR_OUPUT
  386. if(${IS_VALID_VALUE})
  387. # strip newline chars in THIS_VAR parameter and save in VAR_VALUE
  388. string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
  389. # we'll could percolate the value to the parent for possible later use
  390. # set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
  391. # but we're only using it here in this function
  392. set(${VAR_OUPUT} ${VAR_VALUE})
  393. # we'll print what we found to the console
  394. message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
  395. # the interesting part is defining the VAR_OUPUT name a value to use in the app
  396. add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
  397. else()
  398. # if we get here, check the execute_process command and parameters.
  399. message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
  400. set(${VAR_OUPUT} "Unknown")
  401. endif()
  402. endfunction() # LIBWOLFSSL_SAVE_INFO
  403. # create some programmatic #define values that will be used by ShowExtendedSystemInfo().
  404. # see wolfcrypt\src\port\Espressif\esp32_utl.c
  405. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  406. set (git_cmd "git")
  407. message(STATUS "Adding macro definitions:")
  408. # LIBWOLFSSL_VERSION_GIT_ORIGIN: git config --get remote.origin.url
  409. execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "config" "--get" "remote.origin.url" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  410. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_ORIGIN "${TMP_OUT}" "${TMP_RES}")
  411. # LIBWOLFSSL_VERSION_GIT_BRANCH: git rev-parse --abbrev-ref HEAD
  412. execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  413. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_BRANCH "${TMP_OUT}" "${TMP_RES}")
  414. # LIBWOLFSSL_VERSION_GIT_HASH: git rev-parse HEAD
  415. execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  416. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
  417. # LIBWOLFSSL_VERSION_GIT_SHORT_HASH: git rev-parse --short HEAD
  418. execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  419. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
  420. # LIBWOLFSSL_VERSION_GIT_HASH_DATE git show --no-patch --no-notes --pretty=\'\%cd\'
  421. execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
  422. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
  423. message(STATUS "************************************************************************************************")
  424. message(STATUS "wolfssl component config complete!")
  425. message(STATUS "************************************************************************************************")
  426. endif()