CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # wolfSSL Espressif Example Project/main CMakeLists.txt
  2. # v1.1
  3. #
  4. # wolfssl benchmark test
  5. #
  6. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
  7. set(COMPONENT_SRCS "main.c")
  8. set(COMPONENT_ADD_INCLUDEDIRS ".")
  9. set (git_cmd "git")
  10. if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
  11. #
  12. # wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
  13. #
  14. message(STATUS "")
  15. message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
  16. message(STATUS "")
  17. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
  18. endif()
  19. idf_component_register(SRCS main.c
  20. INCLUDE_DIRS "."
  21. "./include")
  22. #
  23. # LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
  24. #
  25. # Save the THIS_VAR as a string in a macro called VAR_OUPUT
  26. #
  27. # VAR_OUPUT: the name of the macro to define
  28. # THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
  29. # VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
  30. #
  31. function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
  32. # is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
  33. string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
  34. # if we had a successful operation, save the THIS_VAR in VAR_OUPUT
  35. if(${IS_VALID_VALUE})
  36. # strip newline chars in THIS_VAR parameter and save in VAR_VALUE
  37. string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
  38. # we'll could percolate the value to the parent for possible later use
  39. # set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
  40. # but we're only using it here in this function
  41. set(${VAR_OUPUT} ${VAR_VALUE})
  42. # we'll print what we found to the console
  43. message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
  44. # the interesting part is defining the VAR_OUPUT name a value to use in the app
  45. add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
  46. else()
  47. # if we get here, check the execute_process command and parameters.
  48. message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
  49. set(${VAR_OUPUT} "Unknown")
  50. endif()
  51. endfunction() # LIBWOLFSSL_SAVE_INFO
  52. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  53. # LIBWOLFSSL_VERSION_GIT_HASH
  54. execute_process(COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  55. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
  56. # LIBWOLFSSL_VERSION_GIT_SHORT_HASH
  57. execute_process(COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
  58. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
  59. # LIBWOLFSSL_VERSION_GIT_HASH_DATE
  60. execute_process(COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
  61. LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
  62. endif()
  63. message(STATUS "")