project.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. # Designed to be included from an IDF app's CMakeLists.txt file
  2. cmake_minimum_required(VERSION 3.5)
  3. # The mere inclusion of this CMake file sets up some interal build properties.
  4. # These properties can be modified in between this inclusion the the idf_build_process
  5. # call.
  6. include(${CMAKE_CURRENT_LIST_DIR}/idf.cmake)
  7. set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py")
  8. # Internally, the Python interpreter is already set to 'python'. Re-set here
  9. # to be absolutely sure.
  10. set_default(PYTHON "python")
  11. file(TO_CMAKE_PATH ${PYTHON} PYTHON)
  12. idf_build_set_property(PYTHON ${PYTHON})
  13. # On processing, checking Python required modules can be turned off if it was
  14. # already checked externally.
  15. if(PYTHON_DEPS_CHECKED)
  16. idf_build_set_property(__CHECK_PYTHON 0)
  17. endif()
  18. # Store CMake arguments that need to be passed into all CMake sub-projects as well
  19. # (bootloader, ULP, etc)
  20. #
  21. # It's not possible to tell if CMake was called with --warn-uninitialized, so to also
  22. # have these warnings in sub-projects we set a cache variable as well and then check that.
  23. if(WARN_UNINITIALIZED)
  24. idf_build_set_property(EXTRA_CMAKE_ARGS --warn-uninitialized)
  25. else()
  26. idf_build_set_property(EXTRA_CMAKE_ARGS "")
  27. endif()
  28. # Initialize build target for this build using the environment variable or
  29. # value passed externally.
  30. __target_init()
  31. #
  32. # Get the project version from either a version file or the Git revision. This is passed
  33. # to the idf_build_process call. Dependencies are also set here for when the version file
  34. # changes (if it is used).
  35. #
  36. function(__project_get_revision var)
  37. set(_project_path "${CMAKE_CURRENT_LIST_DIR}")
  38. if(NOT DEFINED PROJECT_VER)
  39. if(EXISTS "${_project_path}/version.txt")
  40. file(STRINGS "${_project_path}/version.txt" PROJECT_VER)
  41. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_project_path}/version.txt")
  42. else()
  43. git_describe(PROJECT_VER_GIT "${_project_path}")
  44. if(PROJECT_VER_GIT)
  45. set(PROJECT_VER ${PROJECT_VER_GIT})
  46. else()
  47. message(STATUS "Project is not inside a git repository, or git repository has no commits;"
  48. " will not use 'git describe' to determine PROJECT_VER.")
  49. set(PROJECT_VER 1)
  50. endif()
  51. endif()
  52. endif()
  53. set(${var} "${PROJECT_VER}" PARENT_SCOPE)
  54. endfunction()
  55. #
  56. # Output the built components to the user. Generates files for invoking idf_monitor.py
  57. # that doubles as an overview of some of the more important build properties.
  58. #
  59. function(__project_info test_components)
  60. idf_build_get_property(prefix __PREFIX)
  61. idf_build_get_property(_build_components BUILD_COMPONENTS)
  62. idf_build_get_property(build_dir BUILD_DIR)
  63. idf_build_get_property(idf_path IDF_PATH)
  64. list(SORT _build_components)
  65. unset(build_components)
  66. unset(build_component_paths)
  67. foreach(build_component ${_build_components})
  68. __component_get_target(component_target "${build_component}")
  69. __component_get_property(_name ${component_target} COMPONENT_NAME)
  70. __component_get_property(_prefix ${component_target} __PREFIX)
  71. __component_get_property(_alias ${component_target} COMPONENT_ALIAS)
  72. __component_get_property(_dir ${component_target} COMPONENT_DIR)
  73. if(_alias IN_LIST test_components)
  74. list(APPEND test_component_paths ${_dir})
  75. else()
  76. if(_prefix STREQUAL prefix)
  77. set(component ${_name})
  78. else()
  79. set(component ${_alias})
  80. endif()
  81. list(APPEND build_components ${component})
  82. list(APPEND build_component_paths ${_dir})
  83. endif()
  84. endforeach()
  85. set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
  86. idf_build_get_property(PROJECT_PATH PROJECT_DIR)
  87. idf_build_get_property(BUILD_DIR BUILD_DIR)
  88. idf_build_get_property(SDKCONFIG SDKCONFIG)
  89. idf_build_get_property(SDKCONFIG_DEFAULTS SDKCONFIG_DEFAULTS)
  90. idf_build_get_property(PROJECT_EXECUTABLE EXECUTABLE)
  91. set(PROJECT_BIN ${CMAKE_PROJECT_NAME}.bin)
  92. idf_build_get_property(IDF_VER IDF_VER)
  93. idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
  94. include(${sdkconfig_cmake})
  95. idf_build_get_property(COMPONENT_KCONFIGS KCONFIGS)
  96. idf_build_get_property(COMPONENT_KCONFIGS_PROJBUILD KCONFIG_PROJBUILDS)
  97. # Write project description JSON file
  98. idf_build_get_property(build_dir BUILD_DIR)
  99. make_json_list("${build_components};${test_components}" build_components_json)
  100. make_json_list("${build_component_paths};${test_component_paths}" build_component_paths_json)
  101. configure_file("${idf_path}/tools/cmake/project_description.json.in"
  102. "${build_dir}/project_description.json")
  103. # We now have the following component-related variables:
  104. #
  105. # build_components is the list of components to include in the build.
  106. # build_component_paths is the paths to all of these components, obtained from the component dependencies file.
  107. #
  108. # Print the list of found components and test components
  109. string(REPLACE ";" " " build_components "${build_components}")
  110. string(REPLACE ";" " " build_component_paths "${build_component_paths}")
  111. message(STATUS "Components: ${build_components}")
  112. message(STATUS "Component paths: ${build_component_paths}")
  113. if(test_components)
  114. string(REPLACE ";" " " test_components "${test_components}")
  115. string(REPLACE ";" " " test_component_paths "${test_component_paths}")
  116. message(STATUS "Test components: ${test_components}")
  117. message(STATUS "Test component paths: ${test_component_paths}")
  118. endif()
  119. endfunction()
  120. function(__project_init components_var test_components_var)
  121. # Use EXTRA_CFLAGS, EXTRA_CXXFLAGS and EXTRA_CPPFLAGS to add more priority options to the compiler
  122. # EXTRA_CPPFLAGS is used for both C and C++
  123. # Unlike environments' CFLAGS/CXXFLAGS/CPPFLAGS which work for both host and target build,
  124. # these works only for target build
  125. set(extra_cflags "$ENV{EXTRA_CFLAGS}")
  126. set(extra_cxxflags "$ENV{EXTRA_CXXFLAGS}")
  127. set(extra_cppflags "$ENV{EXTRA_CPPFLAGS}")
  128. spaces2list(extra_cflags)
  129. spaces2list(extra_cxxflags)
  130. spaces2list(extra_cppflags)
  131. idf_build_set_property(C_COMPILE_OPTIONS "${extra_cflags}" APPEND)
  132. idf_build_set_property(CXX_COMPILE_OPTIONS "${extra_cxxflags}" APPEND)
  133. idf_build_set_property(COMPILE_OPTIONS "${extra_cppflags}" APPEND)
  134. function(__project_component_dir component_dir)
  135. get_filename_component(component_dir "${component_dir}" ABSOLUTE)
  136. if(EXISTS ${component_dir}/CMakeLists.txt)
  137. idf_build_component(${component_dir})
  138. else()
  139. file(GLOB component_dirs ${component_dir}/*)
  140. foreach(component_dir ${component_dirs})
  141. if(EXISTS ${component_dir}/CMakeLists.txt)
  142. get_filename_component(base_dir ${component_dir} NAME)
  143. __component_dir_quick_check(is_component ${component_dir})
  144. if(is_component)
  145. idf_build_component(${component_dir})
  146. endif()
  147. endif()
  148. endforeach()
  149. endif()
  150. endfunction()
  151. idf_build_set_property(IDF_COMPONENT_MANAGER "$ENV{IDF_COMPONENT_MANAGER}")
  152. # Add component directories to the build, given the component filters, exclusions
  153. # extra directories, etc. passed from the root CMakeLists.txt.
  154. if(COMPONENT_DIRS)
  155. # User wants to fully override where components are pulled from.
  156. spaces2list(COMPONENT_DIRS)
  157. idf_build_set_property(__COMPONENT_TARGETS "")
  158. foreach(component_dir ${COMPONENT_DIRS})
  159. __project_component_dir(${component_dir})
  160. endforeach()
  161. else()
  162. # Add project manifest and lock file to the list of dependencies
  163. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/idf_project.yml")
  164. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/dependencies.lock")
  165. idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER)
  166. if(idf_component_manager)
  167. if(idf_component_manager EQUAL "0")
  168. message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
  169. elseif(idf_component_manager EQUAL "1")
  170. set(managed_components_list_file ${CMAKE_BINARY_DIR}/managed_components_list.temp.cmake)
  171. # Call for package manager to prepare remote dependencies
  172. execute_process(COMMAND ${PYTHON}
  173. "-m"
  174. "idf_component_manager.prepare_components"
  175. "--project_dir=${CMAKE_CURRENT_LIST_DIR}"
  176. "prepare_dependencies"
  177. "--managed_components_list_file=${managed_components_list_file}"
  178. RESULT_VARIABLE result
  179. ERROR_VARIABLE error)
  180. if(NOT result EQUAL 0)
  181. message(FATAL_ERROR "${error}")
  182. endif()
  183. # Include managed components
  184. include(${managed_components_list_file})
  185. file(REMOVE ${managed_components_list_file})
  186. else()
  187. message(WARNING "IDF_COMPONENT_MANAGER environment variable is set to unknown value "
  188. "\"${idf_component_manager}\". If you want to use component manager set it to 1.")
  189. endif()
  190. elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/idf_project.yml")
  191. message(WARNING "\"idf_project.yml\" file is found in project directory, "
  192. "but component manager is not enabled. Please set IDF_COMPONENT_MANAGER environment variable.")
  193. endif()
  194. spaces2list(EXTRA_COMPONENT_DIRS)
  195. foreach(component_dir ${EXTRA_COMPONENT_DIRS})
  196. __project_component_dir("${component_dir}")
  197. endforeach()
  198. __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/components")
  199. # Look for components in the usual places: CMAKE_CURRENT_LIST_DIR/main,
  200. # CMAKE_CURRENT_LIST_DIR/components, and the extra component dirs
  201. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")
  202. __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/main")
  203. endif()
  204. endif()
  205. spaces2list(COMPONENTS)
  206. spaces2list(EXCLUDE_COMPONENTS)
  207. idf_build_get_property(component_targets __COMPONENT_TARGETS)
  208. foreach(component_target ${component_targets})
  209. __component_get_property(component_name ${component_target} COMPONENT_NAME)
  210. set(include 1)
  211. if(COMPONENTS AND NOT component_name IN_LIST COMPONENTS)
  212. set(include 0)
  213. endif()
  214. if(EXCLUDE_COMPONENTS AND component_name IN_LIST EXCLUDE_COMPONENTS)
  215. set(include 0)
  216. endif()
  217. if(include)
  218. list(APPEND components ${component_name})
  219. endif()
  220. endforeach()
  221. if(TESTS_ALL OR BUILD_TESTS OR TEST_COMPONENTS OR TEST_EXCLUDE_COMPONENTS)
  222. spaces2list(TEST_COMPONENTS)
  223. spaces2list(TEST_EXCLUDE_COMPONENTS)
  224. idf_build_get_property(component_targets __COMPONENT_TARGETS)
  225. foreach(component_target ${component_targets})
  226. __component_get_property(component_dir ${component_target} COMPONENT_DIR)
  227. __component_get_property(component_name ${component_target} COMPONENT_NAME)
  228. if(component_name IN_LIST components)
  229. set(include 1)
  230. if(TEST_COMPONENTS AND NOT component_name IN_LIST TEST_COMPONENTS)
  231. set(include 0)
  232. endif()
  233. if(TEST_EXCLUDE_COMPONENTS AND component_name IN_LIST TEST_EXCLUDE_COMPONENTS)
  234. set(include 0)
  235. endif()
  236. if(include AND EXISTS ${component_dir}/test)
  237. __component_add(${component_dir}/test ${component_name})
  238. list(APPEND test_components ${component_name}::test)
  239. endif()
  240. endif()
  241. endforeach()
  242. endif()
  243. set(${components_var} "${components}" PARENT_SCOPE)
  244. set(${test_components_var} "${test_components}" PARENT_SCOPE)
  245. endfunction()
  246. # Trick to temporarily redefine project(). When functions are overriden in CMake, the originals can still be accessed
  247. # using an underscore prefixed function of the same name. The following lines make sure that __project calls
  248. # the original project(). See https://cmake.org/pipermail/cmake/2015-October/061751.html.
  249. function(project)
  250. endfunction()
  251. function(_project)
  252. endfunction()
  253. macro(project project_name)
  254. # Initialize project, preparing COMPONENTS argument for idf_build_process()
  255. # call later using external COMPONENT_DIRS, COMPONENTS_DIRS, EXTRA_COMPONENTS_DIR,
  256. # EXTRA_COMPONENTS_DIRS, COMPONENTS, EXLUDE_COMPONENTS, TEST_COMPONENTS,
  257. # TEST_EXLUDE_COMPONENTS, TESTS_ALL, BUILD_TESTS
  258. __project_init(components test_components)
  259. __target_set_toolchain()
  260. if(CCACHE_ENABLE)
  261. find_program(CCACHE_FOUND ccache)
  262. if(CCACHE_FOUND)
  263. message(STATUS "ccache will be used for faster recompilation")
  264. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  265. else()
  266. message(WARNING "enabled ccache in build but ccache program not found")
  267. endif()
  268. endif()
  269. # The actual call to project()
  270. __project(${project_name} C CXX ASM)
  271. # Generate compile_commands.json (needs to come after project call).
  272. set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
  273. # Since components can import third-party libraries, the original definition of project() should be restored
  274. # before the call to add components to the build.
  275. function(project)
  276. set(project_ARGV ARGV)
  277. __project(${${project_ARGV}})
  278. # Set the variables that project() normally sets, documented in the
  279. # command's docs.
  280. #
  281. # https://cmake.org/cmake/help/v3.5/command/project.html
  282. #
  283. # There is some nuance when it comes to setting version variables in terms of whether
  284. # CMP0048 is set to OLD or NEW. However, the proper behavior should have bee already handled by the original
  285. # project call, and we're just echoing the values those variables were set to.
  286. set(PROJECT_NAME "${PROJECT_NAME}" PARENT_SCOPE)
  287. set(PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}" PARENT_SCOPE)
  288. set(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" PARENT_SCOPE)
  289. set(PROJECT_VERSION "${PROJECT_VERSION}" PARENT_SCOPE)
  290. set(PROJECT_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}" PARENT_SCOPE)
  291. set(PROJECT_VERSION_MINOR "${PROJECT_VERSION_MINOR}" PARENT_SCOPE)
  292. set(PROJECT_VERSION_PATCH "${PROJECT_VERSION_PATCH}" PARENT_SCOPE)
  293. set(PROJECT_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}" PARENT_SCOPE)
  294. set(${PROJECT_NAME}_BINARY_DIR "${${PROJECT_NAME}_BINARY_DIR}" PARENT_SCOPE)
  295. set(${PROJECT_NAME}_SOURCE_DIR "${${PROJECT_NAME}_SOURCE_DIR}" PARENT_SCOPE)
  296. set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}" PARENT_SCOPE)
  297. set(${PROJECT_NAME}_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}" PARENT_SCOPE)
  298. set(${PROJECT_NAME}_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}" PARENT_SCOPE)
  299. set(${PROJECT_NAME}_VERSION_PATCH "${${PROJECT_NAME}_VERSION_PATCH}" PARENT_SCOPE)
  300. set(${PROJECT_NAME}_VERSION_TWEAK "${${PROJECT_NAME}_VERSION_TWEAK}" PARENT_SCOPE)
  301. endfunction()
  302. # Prepare the following arguments for the idf_build_process() call using external
  303. # user values:
  304. #
  305. # SDKCONFIG_DEFAULTS is from external SDKCONFIG_DEFAULTS
  306. # SDKCONFIG is from external SDKCONFIG
  307. # BUILD_DIR is set to project binary dir
  308. #
  309. # PROJECT_NAME is taken from the passed name from project() call
  310. # PROJECT_DIR is set to the current directory
  311. # PROJECT_VER is from the version text or git revision of the current repo
  312. set(_sdkconfig_defaults "$ENV{SDKCONFIG_DEFAULTS}")
  313. if(NOT _sdkconfig_defaults)
  314. if(EXISTS "${CMAKE_SOURCE_DIR}/sdkconfig.defaults")
  315. set(_sdkconfig_defaults "${CMAKE_SOURCE_DIR}/sdkconfig.defaults")
  316. else()
  317. set(_sdkconfig_defaults "")
  318. endif()
  319. endif()
  320. if(SDKCONFIG_DEFAULTS)
  321. set(_sdkconfig_defaults "${SDKCONFIG_DEFAULTS}")
  322. endif()
  323. foreach(sdkconfig_default ${_sdkconfig_defaults})
  324. get_filename_component(sdkconfig_default "${sdkconfig_default}" ABSOLUTE)
  325. if(NOT EXISTS "${sdkconfig_default}")
  326. message(FATAL_ERROR "SDKCONFIG_DEFAULTS '${sdkconfig_default}' does not exist.")
  327. endif()
  328. list(APPEND sdkconfig_defaults ${sdkconfig_default})
  329. endforeach()
  330. if(SDKCONFIG)
  331. get_filename_component(sdkconfig "${SDKCONFIG}" ABSOLUTE)
  332. else()
  333. set(sdkconfig "${CMAKE_CURRENT_LIST_DIR}/sdkconfig")
  334. endif()
  335. if(BUILD_DIR)
  336. get_filename_component(build_dir "${BUILD_DIR}" ABSOLUTE)
  337. if(NOT EXISTS "${build_dir}")
  338. message(FATAL_ERROR "BUILD_DIR '${build_dir}' does not exist.")
  339. endif()
  340. else()
  341. set(build_dir ${CMAKE_BINARY_DIR})
  342. endif()
  343. __project_get_revision(project_ver)
  344. message(STATUS "Building ESP-IDF components for target ${IDF_TARGET}")
  345. idf_build_process(${IDF_TARGET}
  346. SDKCONFIG_DEFAULTS "${sdkconfig_defaults}"
  347. SDKCONFIG ${sdkconfig}
  348. BUILD_DIR ${build_dir}
  349. PROJECT_NAME ${CMAKE_PROJECT_NAME}
  350. PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR}
  351. PROJECT_VER "${project_ver}"
  352. COMPONENTS "${components};${test_components}")
  353. # Special treatment for 'main' component for standard projects (not part of core build system).
  354. # Have it depend on every other component in the build. This is
  355. # a convenience behavior for the standard project; thus is done outside of the core build system
  356. # so that it treats components equally.
  357. #
  358. # This behavior should only be when user did not set REQUIRES/PRIV_REQUIRES manually.
  359. idf_build_get_property(build_components BUILD_COMPONENT_ALIASES)
  360. if(idf::main IN_LIST build_components)
  361. __component_get_target(main_target idf::main)
  362. __component_get_property(reqs ${main_target} REQUIRES)
  363. __component_get_property(priv_reqs ${main_target} PRIV_REQUIRES)
  364. idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
  365. if(reqs STREQUAL common_reqs AND NOT priv_reqs) #if user has not set any requirements
  366. if(test_components)
  367. list(REMOVE_ITEM build_components ${test_components})
  368. endif()
  369. list(REMOVE_ITEM build_components idf::main)
  370. __component_get_property(lib ${main_target} COMPONENT_LIB)
  371. set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${build_components}")
  372. get_property(type TARGET ${lib} PROPERTY TYPE)
  373. if(type STREQUAL STATIC_LIBRARY)
  374. set_property(TARGET ${lib} APPEND PROPERTY LINK_LIBRARIES "${build_components}")
  375. endif()
  376. endif()
  377. endif()
  378. set(project_elf ${CMAKE_PROJECT_NAME}.elf)
  379. # Create a dummy file to work around CMake requirement of having a source file while adding an
  380. # executable. This is also used by idf_size.py to detect the target
  381. set(project_elf_src ${CMAKE_BINARY_DIR}/project_elf_src_${IDF_TARGET}.c)
  382. add_custom_command(OUTPUT ${project_elf_src}
  383. COMMAND ${CMAKE_COMMAND} -E touch ${project_elf_src}
  384. VERBATIM)
  385. add_custom_target(_project_elf_src DEPENDS "${project_elf_src}")
  386. add_executable(${project_elf} "${project_elf_src}")
  387. add_dependencies(${project_elf} _project_elf_src)
  388. if(__PROJECT_GROUP_LINK_COMPONENTS)
  389. target_link_libraries(${project_elf} "-Wl,--start-group")
  390. endif()
  391. if(test_components)
  392. target_link_libraries(${project_elf} "-Wl,--whole-archive")
  393. foreach(test_component ${test_components})
  394. if(TARGET ${test_component})
  395. target_link_libraries(${project_elf} ${test_component})
  396. endif()
  397. endforeach()
  398. target_link_libraries(${project_elf} "-Wl,--no-whole-archive")
  399. endif()
  400. idf_build_get_property(build_components BUILD_COMPONENT_ALIASES)
  401. if(test_components)
  402. list(REMOVE_ITEM build_components ${test_components})
  403. endif()
  404. target_link_libraries(${project_elf} ${build_components})
  405. set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map")
  406. target_link_libraries(${project_elf} "-Wl,--cref -Wl,--Map=${mapfile}")
  407. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  408. ADDITIONAL_MAKE_CLEAN_FILES
  409. "${mapfile}" "${project_elf_src}")
  410. idf_build_get_property(idf_path IDF_PATH)
  411. idf_build_get_property(python PYTHON)
  412. set(idf_size ${python} ${idf_path}/tools/idf_size.py)
  413. if(DEFINED OUTPUT_JSON AND OUTPUT_JSON)
  414. list(APPEND idf_size "--json")
  415. endif()
  416. # Add size targets, depend on map file, run idf_size.py
  417. add_custom_target(size
  418. DEPENDS ${project_elf}
  419. COMMAND ${idf_size} ${mapfile}
  420. )
  421. add_custom_target(size-files
  422. DEPENDS ${project_elf}
  423. COMMAND ${idf_size} --files ${mapfile}
  424. )
  425. add_custom_target(size-components
  426. DEPENDS ${project_elf}
  427. COMMAND ${idf_size} --archives ${mapfile}
  428. )
  429. unset(idf_size)
  430. # Add DFU build and flash targets
  431. __add_dfu_targets()
  432. idf_build_executable(${project_elf})
  433. __project_info("${test_components}")
  434. endmacro()