CMakeLists.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # For more information about build system see
  2. # https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
  3. # The following five lines of boilerplate have to be in your project's
  4. # CMakeLists in this exact order for cmake to work correctly
  5. cmake_minimum_required(VERSION 3.16)
  6. set(driver_components esp_eth esp_wifi openthread)
  7. # General rules for all these tests
  8. # * No optional dependencies
  9. # * Forbidden dependencies are only driver components
  10. set(forbidden_deps ${driver_components})
  11. set(optional_deps)
  12. # Check manually if the ESP_NETIF is configured in sdkconfig
  13. # Note that we cannot use Kconfig values at this stage, and therefore we have to parse
  14. # the sdkconfig manually for the relevant "config" (CONFIG_TESTAPP_COMPONENT_...),
  15. # in case the sdkconfig doesn't exist (clean build), we choose the default.
  16. message(STATUS "Checking if sdkconfig contains CONFIG_TESTAPP_COMPONENT related config:")
  17. set(config_file "${CMAKE_CURRENT_SOURCE_DIR}/sdkconfig")
  18. if(EXISTS ${config_file})
  19. # If the config file exists, check for the non-default settings - LWIP or ESP-NETIF-without-LWIP
  20. # otherwise (file missing or defalut settings) go with ESP_NETIF
  21. file(READ ${config_file} config_file_content)
  22. string(FIND "${config_file_content}" "CONFIG_TESTAPP_COMPONENT_LWIP=y" match_lwip)
  23. string(FIND "${config_file_content}" "CONFIG_TESTAPP_COMPONENT_ESP_NETIF_WITHOUT_LWIP=y" match_netif_no_lwip)
  24. if(NOT ${match_lwip} EQUAL -1)
  25. set(CHECK_DEPS_FOR_LWIP 1)
  26. elseif(NOT ${match_netif_no_lwip} EQUAL -1)
  27. set(CHECK_DEPS_FOR_ESP_NETIF_WITHOUT_LWIP 1)
  28. endif()
  29. endif()
  30. if(CHECK_DEPS_FOR)
  31. message(STATUS "CONFIG_TESTAPP_COMPONENT_LWIP")
  32. set(component_under_test lwip)
  33. set(expected_build_components lwip)
  34. elseif(CHECK_DEPS_FOR_ESP_NETIF_WITHOUT_LWIP)
  35. message(STATUS "CONFIG_TESTAPP_COMPONENT_ESP_NETIF_WITHOUT_LWIP")
  36. set(component_under_test esp_netif)
  37. set(expected_build_components esp_netif)
  38. list(APPEND optional_deps mbedtls)
  39. list(APPEND forbidden_deps lwip) # lwip mustn't be pulled in, in "esp-netif without lwip" setup
  40. list(APPEND EXTRA_COMPONENT_DIRS "esp_netif_stack")
  41. else()
  42. message(STATUS "CONFIG_TESTAPP_COMPONENT_ESP_NETIF")
  43. set(component_under_test esp_netif)
  44. set(expected_build_components esp_netif lwip)
  45. endif()
  46. set(COMPONENTS ${component_under_test} main ${optional_deps})
  47. include($ENV{IDF_PATH}/tools/cmake/project.cmake)
  48. idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH_ENABLED 1)
  49. project(network_components)
  50. # Get the actual build commponents included in the build
  51. idf_build_get_property(build_components BUILD_COMPONENTS)
  52. message(STATUS "Build components needed my main and ${component_under_test}:")
  53. foreach(comp ${build_components})
  54. message(STATUS "${comp}")
  55. endforeach()
  56. # Check for all the components, these shall not be included
  57. foreach(comp ${forbidden_deps})
  58. if(${comp} IN_LIST build_components)
  59. message(FATAL_ERROR "Component ${comp} shall not be included when building only ${component_under_test}")
  60. else()
  61. message(STATUS "-> OK: ${comp} is not included when building only ${component_under_test}")
  62. endif()
  63. endforeach()
  64. # Check for all needed components, these must be included
  65. foreach(comp ${expected_build_components})
  66. if(${comp} IN_LIST build_components)
  67. message(STATUS "-> OK: ${comp} is pulled by ${component_under_test}")
  68. else()
  69. message(FATAL_ERROR "${comp} is expected by adding ${component_under_test}")
  70. endif()
  71. endforeach()