CMakeLists.txt 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # wolfSSL Espressif Example Project CMakeLists.txt
  2. # v1.3
  3. #
  4. # The following lines of boilerplate have to be in your project's
  5. # CMakeLists in this exact order for cmake to work correctly
  6. cmake_minimum_required(VERSION 3.16)
  7. # Optional no watchdog typically used for test & benchmark
  8. add_compile_options(-DWOLFSSL_ESP_NO_WATCHDOG=1)
  9. # The wolfSSL CMake file should be able to find the source code.
  10. # Otherwise, assign an environment variable or set it here:
  11. #
  12. # set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
  13. #
  14. # Optional WOLFSSL_CMAKE_SYSTEM_NAME detection to find
  15. # USE_MY_PRIVATE_CONFIG path for my_private_config.h
  16. #
  17. # Expected path varies:
  18. #
  19. # WSL: /mnt/c/workspace
  20. # Linux: ~/workspace
  21. # Windows: C:\workspace
  22. #
  23. if(WIN32)
  24. # Windows-specific configuration here
  25. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
  26. message("Detected Windows")
  27. endif()
  28. if(CMAKE_HOST_UNIX)
  29. message("Detected UNIX")
  30. endif()
  31. if(APPLE)
  32. message("Detected APPLE")
  33. endif()
  34. if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
  35. # Windows-specific configuration here
  36. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
  37. message("Detected WSL")
  38. endif()
  39. if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
  40. # Windows-specific configuration here
  41. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
  42. message("Detected Linux")
  43. endif()
  44. if(APPLE)
  45. # Windows-specific configuration here
  46. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
  47. message("Detected Apple")
  48. endif()
  49. # End optional WOLFSSL_CMAKE_SYSTEM_NAME
  50. # Check that there are not conflicting wolfSSL components
  51. # The ESP Registry Component will be in ./managed_components/wolfssl__wolfssl
  52. # The local component wolfSSL directory will be in ./components/wolfssl
  53. if( EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" AND EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl" )
  54. # These exclude statements don't seem to be honored by the $ENV{IDF_PATH}/tools/cmake/project.cmake'
  55. # add_subdirectory("${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" EXCLUDE_FROM_ALL)
  56. # add_subdirectory("${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl/include" EXCLUDE_FROM_ALL)
  57. # So we'll error out and let the user decide how to proceed:
  58. message(WARNING "\nFound wolfSSL components in\n"
  59. "./managed_components/wolfssl__wolfssl\n"
  60. "and\n"
  61. "./components/wolfssl\n"
  62. "in project directory: \n"
  63. "${CMAKE_HOME_DIRECTORY}")
  64. message(FATAL_ERROR "\nPlease use either the ESP Registry Managed Component or the wolfSSL component directory but not both.\n"
  65. "If removing the ./managed_components/wolfssl__wolfssl directory, remember to also remove "
  66. "or rename the idf_component.yml file typically found in ./main/")
  67. else()
  68. message(STATUS "No conflicting wolfSSL components found.")
  69. endif()
  70. # Ensure the this wolfSSL component directory is included
  71. set(WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
  72. list(APPEND EXTRA_COMPONENT_DIRS ${WOLFSSL_PATH})
  73. # Not only is a project-level "set(COMPONENTS" not needed here, this will cause
  74. # an unintuitive error about Unknown CMake command "esptool_py_flash_project_args".
  75. include($ENV{IDF_PATH}/tools/cmake/project.cmake)
  76. project(wolfssl_template)