targets.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. include(component_utils)
  2. macro(idf_set_target)
  3. # Input is IDF_TARGET environement variable
  4. set(env_idf_target $ENV{IDF_TARGET})
  5. if(NOT env_idf_target)
  6. # IDF_TARGET not set in environment, see if it is set in cache
  7. if(IDF_TARGET)
  8. set(env_idf_target ${IDF_TARGET})
  9. else()
  10. set(env_idf_target esp32)
  11. message(STATUS "IDF_TARGET not set, using default target: ${env_idf_target}")
  12. endif()
  13. else()
  14. # IDF_TARGET set both in environment and in cache, must be the same
  15. if(NOT ${IDF_TARGET} STREQUAL ${env_idf_target})
  16. message(FATAL_ERROR "IDF_TARGET in CMake cache does not match "
  17. "IDF_TARGET environment variable. To change the target, clear "
  18. "the build directory and sdkconfig file, and build the project again")
  19. endif()
  20. endif()
  21. # IDF_TARGET will be used by Kconfig, make sure it is set
  22. set(ENV{IDF_TARGET} ${env_idf_target})
  23. # Finally, set IDF_TARGET in cache
  24. set(IDF_TARGET ${env_idf_target} CACHE STRING "IDF Build Target")
  25. message(STATUS "Building for target ${IDF_TARGET}")
  26. endmacro()
  27. macro(idf_check_config_target)
  28. if(NOT ${IDF_TARGET} STREQUAL ${CONFIG_IDF_TARGET})
  29. message(FATAL_ERROR "CONFIG_IDF_TARGET in sdkconfig does not match "
  30. "IDF_TARGET environement variable. To change the target, delete "
  31. "sdkconfig file and build the project again.")
  32. endif()
  33. endmacro()
  34. macro(idf_set_toolchain)
  35. # First try to load the toolchain file from the tools/cmake/ directory of IDF
  36. set(toolchain_file_global $ENV{IDF_PATH}/tools/cmake/toolchain-${IDF_TARGET}.cmake)
  37. if(EXISTS ${toolchain_file_global})
  38. set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_global})
  39. else()
  40. # Try to load the toolchain file from the directory of ${IDF_TARGET} component
  41. components_find_all("${IDF_COMPONENT_DIRS}" ALL_COMPONENT_PATHS ALL_COMPONENTS ALL_TEST_COMPONENTS)
  42. find_component_path(${IDF_TARGET} "${ALL_COMPONENTS}" "${ALL_COMPONENT_PATHS}" target_component_path)
  43. set(toolchain_file_component ${target_component_path}/toolchain-${IDF_TARGET}.cmake)
  44. if(EXISTS ${toolchain_file_component})
  45. set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_component})
  46. else()
  47. message(FATAL_ERROR "Toolchain file toolchain-${IDF_TARGET}.cmake not found,"
  48. "checked ${toolchain_file_global} and ${toolchain_file_component}")
  49. endif()
  50. endif()
  51. endmacro()