CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cmake_minimum_required(VERSION 3.5)
  2. set(srcs
  3. src/esp_targets.c
  4. src/md5_hash.c
  5. src/esp_loader.c
  6. src/protocol_common.c
  7. )
  8. if (DEFINED ESP_PLATFORM)
  9. if (${CONFIG_SERIAL_FLASHER_INTERFACE_UART})
  10. list(APPEND srcs
  11. src/protocol_uart.c
  12. src/slip.c
  13. port/esp32_port.c
  14. )
  15. elseif (${CONFIG_SERIAL_FLASHER_INTERFACE_SPI})
  16. list(APPEND srcs
  17. src/protocol_spi.c
  18. port/esp32_spi_port.c
  19. )
  20. endif()
  21. # Register component to esp-idf build system
  22. if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.0")
  23. # esp_timer component was introduced in v4.2
  24. set(priv_requires driver)
  25. if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.1")
  26. list(APPEND priv_requires esp_timer)
  27. endif()
  28. idf_component_register(SRCS ${srcs}
  29. INCLUDE_DIRS include port
  30. PRIV_INCLUDE_DIRS private_include
  31. PRIV_REQUIRES ${priv_requires})
  32. set(target ${COMPONENT_LIB})
  33. component_compile_options(-Wstrict-prototypes)
  34. else()
  35. # Remove when dropping support for IDF 3.3
  36. set(COMPONENT_SRCS ${srcs})
  37. set(COMPONENT_ADD_INCLUDEDIRS include port)
  38. set(COMPONENT_PRIV_INCLUDEDIRS private_include)
  39. register_component()
  40. set(target ${COMPONENT_TARGET})
  41. endif()
  42. else()
  43. if (NOT DEFINED SERIAL_FLASHER_INTERFACE_UART AND NOT DEFINED SERIAL_FLASHER_INTERFACE_SPI)
  44. set(SERIAL_FLASHER_INTERFACE_UART true)
  45. endif()
  46. if (DEFINED SERIAL_FLASHER_INTERFACE_UART)
  47. list(APPEND srcs
  48. src/protocol_uart.c
  49. src/slip.c
  50. )
  51. elseif (DEFINED SERIAL_FLASHER_INTERFACE_SPI)
  52. list(APPEND srcs src/protocol_spi.c)
  53. endif()
  54. # Create traditional CMake target
  55. add_library(flasher ${srcs})
  56. target_include_directories(flasher PUBLIC include port PRIVATE private_include)
  57. if(PORT STREQUAL "STM32")
  58. target_link_libraries(flasher PUBLIC stm_cube)
  59. target_sources(flasher PRIVATE port/stm32_port.c)
  60. elseif(PORT STREQUAL "RASPBERRY_PI")
  61. find_library(pigpio_LIB pigpio)
  62. target_link_libraries(flasher PUBLIC ${pigpio_LIB})
  63. target_sources(flasher PRIVATE port/raspberry_port.c)
  64. else()
  65. message(FATAL_ERROR "Selected port is not supported")
  66. endif()
  67. set(target flasher)
  68. endif()
  69. if (DEFINED SERIAL_FLASHER_INTERFACE_UART OR CONFIG_SERIAL_FLASHER_INTERFACE_UART STREQUAL "y")
  70. target_compile_definitions(${target}
  71. PUBLIC
  72. SERIAL_FLASHER_INTERFACE_UART
  73. )
  74. if (DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
  75. target_compile_definitions(${target} PUBLIC MD5_ENABLED=1)
  76. endif()
  77. elseif (DEFINED SERIAL_FLASHER_INTERFACE_SPI OR CONFIG_SERIAL_FLASHER_INTERFACE_SPI STREQUAL "y")
  78. target_compile_definitions(${target}
  79. PUBLIC
  80. SERIAL_FLASHER_INTERFACE_SPI
  81. )
  82. endif()
  83. if(DEFINED SERIAL_FLASHER_DEBUG_TRACE OR CONFIG_SERIAL_FLASHER_DEBUG_TRACE)
  84. target_compile_definitions(${target} PUBLIC SERIAL_FLASHER_DEBUG_TRACE)
  85. endif()
  86. if(DEFINED CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS AND DEFINED CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
  87. target_compile_definitions(${target}
  88. PUBLIC
  89. SERIAL_FLASHER_RESET_HOLD_TIME_MS=${CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS}
  90. SERIAL_FLASHER_BOOT_HOLD_TIME_MS=${CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS}
  91. )
  92. else()
  93. if(NOT DEFINED SERIAL_FLASHER_RESET_HOLD_TIME_MS)
  94. target_compile_definitions(${target}
  95. PUBLIC
  96. SERIAL_FLASHER_RESET_HOLD_TIME_MS=100
  97. )
  98. endif()
  99. if(NOT DEFINED SERIAL_FLASHER_BOOT_HOLD_TIME_MS)
  100. target_compile_definitions(${target}
  101. PUBLIC
  102. SERIAL_FLASHER_BOOT_HOLD_TIME_MS=50
  103. )
  104. endif()
  105. endif()