CMakeLists.txt 4.3 KB

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