CMakeLists.txt 3.8 KB

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