build.cmake 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. # idf_build_get_property
  2. #
  3. # @brief Retrieve the value of the specified property related to ESP-IDF build.
  4. #
  5. # @param[out] var the variable to store the value in
  6. # @param[in] property the property to get the value of
  7. #
  8. # @param[in, optional] GENERATOR_EXPRESSION (option) retrieve the generator expression for the property
  9. # instead of actual value
  10. function(idf_build_get_property var property)
  11. cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
  12. if(__GENERATOR_EXPRESSION)
  13. set(val "$<TARGET_PROPERTY:__idf_build_target,${property}>")
  14. else()
  15. get_property(val TARGET __idf_build_target PROPERTY ${property})
  16. endif()
  17. set(${var} ${val} PARENT_SCOPE)
  18. endfunction()
  19. # idf_build_set_property
  20. #
  21. # @brief Set the value of the specified property related to ESP-IDF build. The property is
  22. # also added to the internal list of build properties if it isn't there already.
  23. #
  24. # @param[in] property the property to set the value of
  25. # @param[out] value value of the property
  26. #
  27. # @param[in, optional] APPEND (option) append the value to the current value of the
  28. # property instead of replacing it
  29. function(idf_build_set_property property value)
  30. cmake_parse_arguments(_ "APPEND" "" "" ${ARGN})
  31. if(__APPEND)
  32. set_property(TARGET __idf_build_target APPEND PROPERTY ${property} ${value})
  33. else()
  34. set_property(TARGET __idf_build_target PROPERTY ${property} ${value})
  35. endif()
  36. # Keep track of set build properties so that they can be exported to a file that
  37. # will be included in early expansion script.
  38. idf_build_get_property(build_properties __BUILD_PROPERTIES)
  39. if(NOT property IN_LIST build_properties)
  40. idf_build_set_property(__BUILD_PROPERTIES "${property}" APPEND)
  41. endif()
  42. endfunction()
  43. # idf_build_unset_property
  44. #
  45. # @brief Unset the value of the specified property related to ESP-IDF build. Equivalent
  46. # to setting the property to an empty string; though it also removes the property
  47. # from the internal list of build properties.
  48. #
  49. # @param[in] property the property to unset the value of
  50. function(idf_build_unset_property property)
  51. idf_build_set_property(${property} "") # set to an empty value
  52. idf_build_get_property(build_properties __BUILD_PROPERTIES) # remove from tracked properties
  53. list(REMOVE_ITEM build_properties ${property})
  54. idf_build_set_property(__BUILD_PROPERTIES "${build_properties}")
  55. endfunction()
  56. #
  57. # Retrieve the IDF_PATH repository's version, either using a version
  58. # file or Git revision. Sets the IDF_VER build property.
  59. #
  60. function(__build_get_idf_git_revision)
  61. idf_build_get_property(idf_path IDF_PATH)
  62. git_describe(idf_ver_git "${idf_path}" "--match=v*.*")
  63. if(EXISTS "${idf_path}/version.txt")
  64. file(STRINGS "${idf_path}/version.txt" idf_ver_t)
  65. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${idf_path}/version.txt")
  66. else()
  67. set(idf_ver_t ${idf_ver_git})
  68. endif()
  69. # cut IDF_VER to required 32 characters.
  70. string(SUBSTRING "${idf_ver_t}" 0 31 idf_ver)
  71. idf_build_set_property(COMPILE_DEFINITIONS "-DIDF_VER=\"${idf_ver}\"" APPEND)
  72. git_submodule_check("${idf_path}")
  73. idf_build_set_property(IDF_VER ${idf_ver})
  74. endfunction()
  75. #
  76. # Sets initial list of build specifications (compile options, definitions, etc.) common across
  77. # all library targets built under the ESP-IDF build system. These build specifications are added
  78. # privately using the directory-level CMake commands (add_compile_options, include_directories, etc.)
  79. # during component registration.
  80. #
  81. function(__build_set_default_build_specifications)
  82. unset(compile_definitions)
  83. unset(compile_options)
  84. unset(c_compile_options)
  85. unset(cxx_compile_options)
  86. list(APPEND compile_definitions "-D_GNU_SOURCE")
  87. list(APPEND compile_options "-ffunction-sections"
  88. "-fdata-sections"
  89. # warning-related flags
  90. "-Wall"
  91. "-Werror=all"
  92. "-Wno-error=unused-function"
  93. "-Wno-error=unused-variable"
  94. "-Wno-error=deprecated-declarations"
  95. "-Wextra"
  96. "-Wno-unused-parameter"
  97. "-Wno-sign-compare"
  98. # always generate debug symbols (even in release mode, these don't
  99. # go into the final binary so have no impact on size
  100. "-ggdb")
  101. list(APPEND c_compile_options "-std=gnu99")
  102. list(APPEND cxx_compile_options "-std=gnu++11")
  103. list(APPEND link_options "-Wl,--gc-sections")
  104. idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
  105. idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
  106. idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
  107. idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
  108. idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
  109. endfunction()
  110. #
  111. # Initialize the build. This gets called upon inclusion of idf.cmake to set internal
  112. # properties used for the processing phase of the build.
  113. #
  114. function(__build_init idf_path)
  115. set(target ${IDF_TARGET})
  116. # Create the build target, to which the ESP-IDF build properties, dependencies are attached to.
  117. # Must be global so as to be accessible from any subdirectory in custom projects.
  118. add_library(__idf_build_target STATIC IMPORTED GLOBAL)
  119. # Set the Python path (which may be passed in via -DPYTHON=) and store in a build property
  120. set_default(PYTHON "python")
  121. file(TO_CMAKE_PATH ${PYTHON} PYTHON)
  122. idf_build_set_property(PYTHON ${PYTHON})
  123. idf_build_set_property(IDF_PATH ${idf_path})
  124. idf_build_set_property(__PREFIX idf)
  125. idf_build_set_property(__CHECK_PYTHON 1)
  126. __build_set_default_build_specifications()
  127. # Add internal components to the build
  128. idf_build_get_property(idf_path IDF_PATH)
  129. idf_build_get_property(prefix __PREFIX)
  130. file(GLOB component_dirs ${idf_path}/components/*)
  131. list(SORT component_dirs)
  132. foreach(component_dir ${component_dirs})
  133. # A potential component must be a directory
  134. if(IS_DIRECTORY ${component_dir})
  135. __component_dir_quick_check(is_component ${component_dir})
  136. if(is_component)
  137. __component_add(${component_dir} ${prefix})
  138. endif()
  139. endif()
  140. endforeach()
  141. if("${target}" STREQUAL "linux")
  142. set(requires_common freertos log esp_rom esp_common)
  143. idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
  144. else()
  145. # Set components required by all other components in the build
  146. #
  147. # - lwip is here so that #include <sys/socket.h> works without any special provisions
  148. # - esp_hw_support is here for backward compatibility
  149. set(requires_common cxx newlib freertos esp_hw_support heap log lwip soc hal esp_rom esp_common esp_system)
  150. idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
  151. endif()
  152. __build_get_idf_git_revision()
  153. __kconfig_init()
  154. endfunction()
  155. # idf_build_component
  156. #
  157. # @brief Present a directory that contains a component to the build system.
  158. # Relative paths are converted to absolute paths with respect to current directory.
  159. # All calls to this command must be performed before idf_build_process.
  160. #
  161. # @note This command does not guarantee that the component will be processed
  162. # during build (see the COMPONENTS argument description for command idf_build_process)
  163. #
  164. # @param[in] component_dir directory of the component
  165. function(idf_build_component component_dir)
  166. idf_build_get_property(prefix __PREFIX)
  167. __component_add(${component_dir} ${prefix} 0)
  168. endfunction()
  169. #
  170. # Resolve the requirement component to the component target created for that component.
  171. #
  172. function(__build_resolve_and_add_req var component_target req type)
  173. __component_get_target(_component_target ${req})
  174. __component_get_property(_component_registered ${component_target} __COMPONENT_REGISTERED)
  175. if(NOT _component_target OR NOT _component_registered)
  176. message(FATAL_ERROR "Failed to resolve component '${req}'.")
  177. endif()
  178. __component_set_property(${component_target} ${type} ${_component_target} APPEND)
  179. set(${var} ${_component_target} PARENT_SCOPE)
  180. endfunction()
  181. #
  182. # Build a list of components (in the form of component targets) to be added to the build
  183. # based on public and private requirements. This list is saved in an internal property,
  184. # __BUILD_COMPONENT_TARGETS.
  185. #
  186. function(__build_expand_requirements component_target)
  187. # Since there are circular dependencies, make sure that we do not infinitely
  188. # expand requirements for each component.
  189. idf_build_get_property(component_targets_seen __COMPONENT_TARGETS_SEEN)
  190. __component_get_property(component_registered ${component_target} __COMPONENT_REGISTERED)
  191. if(component_target IN_LIST component_targets_seen OR NOT component_registered)
  192. return()
  193. endif()
  194. idf_build_set_property(__COMPONENT_TARGETS_SEEN ${component_target} APPEND)
  195. get_property(reqs TARGET ${component_target} PROPERTY REQUIRES)
  196. get_property(priv_reqs TARGET ${component_target} PROPERTY PRIV_REQUIRES)
  197. foreach(req ${reqs})
  198. __build_resolve_and_add_req(_component_target ${component_target} ${req} __REQUIRES)
  199. __build_expand_requirements(${_component_target})
  200. endforeach()
  201. foreach(req ${priv_reqs})
  202. __build_resolve_and_add_req(_component_target ${component_target} ${req} __PRIV_REQUIRES)
  203. __build_expand_requirements(${_component_target})
  204. endforeach()
  205. idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
  206. if(NOT component_target IN_LIST build_component_targets)
  207. idf_build_set_property(__BUILD_COMPONENT_TARGETS ${component_target} APPEND)
  208. __component_get_property(component_lib ${component_target} COMPONENT_LIB)
  209. idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND)
  210. idf_build_get_property(prefix __PREFIX)
  211. __component_get_property(component_prefix ${component_target} __PREFIX)
  212. __component_get_property(component_alias ${component_target} COMPONENT_ALIAS)
  213. idf_build_set_property(BUILD_COMPONENT_ALIASES ${component_alias} APPEND)
  214. # Only put in the prefix in the name if it is not the default one
  215. if(component_prefix STREQUAL prefix)
  216. __component_get_property(component_name ${component_target} COMPONENT_NAME)
  217. idf_build_set_property(BUILD_COMPONENTS ${component_name} APPEND)
  218. else()
  219. idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND)
  220. endif()
  221. endif()
  222. endfunction()
  223. #
  224. # Write a CMake file containing set build properties, owing to the fact that an internal
  225. # list of properties is maintained in idf_build_set_property() call. This is used to convert
  226. # those set properties to variables in the scope the output file is included in.
  227. #
  228. function(__build_write_properties output_file)
  229. idf_build_get_property(build_properties __BUILD_PROPERTIES)
  230. foreach(property ${build_properties})
  231. idf_build_get_property(val ${property})
  232. set(build_properties_text "${build_properties_text}\nset(${property} \"${val}\")")
  233. endforeach()
  234. file(WRITE ${output_file} "${build_properties_text}")
  235. endfunction()
  236. #
  237. # Check if the Python interpreter used for the build has all the required modules.
  238. #
  239. function(__build_check_python)
  240. idf_build_get_property(check __CHECK_PYTHON)
  241. if(check)
  242. idf_build_get_property(python PYTHON)
  243. idf_build_get_property(idf_path IDF_PATH)
  244. message(STATUS "Checking Python dependencies...")
  245. execute_process(COMMAND "${python}" "${idf_path}/tools/check_python_dependencies.py"
  246. RESULT_VARIABLE result)
  247. if(result EQUAL 1)
  248. # check_python_dependencies returns error code 1 on failure
  249. message(FATAL_ERROR "Some Python dependencies must be installed. Check above message for details.")
  250. elseif(NOT result EQUAL 0)
  251. # means check_python_dependencies.py failed to run at all, result should be an error message
  252. message(FATAL_ERROR "Failed to run Python dependency check. Python: ${python}, Error: ${result}")
  253. endif()
  254. endif()
  255. endfunction()
  256. #
  257. # Prepare for component processing expanding each component's project include
  258. #
  259. macro(__build_process_project_includes)
  260. # Include the sdkconfig cmake file, since the following operations require
  261. # knowledge of config values.
  262. idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
  263. include(${sdkconfig_cmake})
  264. # Make each build property available as a read-only variable
  265. idf_build_get_property(build_properties __BUILD_PROPERTIES)
  266. foreach(build_property ${build_properties})
  267. idf_build_get_property(val ${build_property})
  268. set(${build_property} "${val}")
  269. endforeach()
  270. # Check that the CMake target value matches the Kconfig target value.
  271. __target_check()
  272. idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
  273. # Include each component's project_include.cmake
  274. foreach(component_target ${build_component_targets})
  275. __component_get_property(dir ${component_target} COMPONENT_DIR)
  276. __component_get_property(_name ${component_target} COMPONENT_NAME)
  277. set(COMPONENT_NAME ${_name})
  278. set(COMPONENT_DIR ${dir})
  279. set(COMPONENT_PATH ${dir}) # this is deprecated, users are encouraged to use COMPONENT_DIR;
  280. # retained for compatibility
  281. if(EXISTS ${COMPONENT_DIR}/project_include.cmake)
  282. include(${COMPONENT_DIR}/project_include.cmake)
  283. endif()
  284. endforeach()
  285. endmacro()
  286. #
  287. # Utility macro for setting default property value if argument is not specified
  288. # for idf_build_process().
  289. #
  290. macro(__build_set_default var default)
  291. set(_var __${var})
  292. if(NOT "${${_var}}" STREQUAL "")
  293. idf_build_set_property(${var} "${${_var}}")
  294. else()
  295. idf_build_set_property(${var} "${default}")
  296. endif()
  297. unset(_var)
  298. endmacro()
  299. #
  300. # Import configs as build instance properties so that they are accessible
  301. # using idf_build_get_config(). Config has to have been generated before calling
  302. # this command.
  303. #
  304. function(__build_import_configs)
  305. # Include the sdkconfig cmake file, since the following operations require
  306. # knowledge of config values.
  307. idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
  308. include(${sdkconfig_cmake})
  309. idf_build_set_property(__CONFIG_VARIABLES "${CONFIGS_LIST}")
  310. foreach(config ${CONFIGS_LIST})
  311. set_property(TARGET __idf_build_target PROPERTY ${config} "${${config}}")
  312. endforeach()
  313. endfunction()
  314. # idf_build_process
  315. #
  316. # @brief Main processing step for ESP-IDF build: config generation, adding components to the build,
  317. # dependency resolution, etc.
  318. #
  319. # @param[in] target ESP-IDF target
  320. #
  321. # @param[in, optional] PROJECT_DIR (single value) directory of the main project the buildsystem
  322. # is processed for; defaults to CMAKE_SOURCE_DIR
  323. # @param[in, optional] PROJECT_VER (single value) version string of the main project; defaults
  324. # to 1
  325. # @param[in, optional] PROJECT_NAME (single value) main project name, defaults to CMAKE_PROJECT_NAME
  326. # @param[in, optional] SDKCONFIG (single value) sdkconfig output path, defaults to PROJECT_DIR/sdkconfig
  327. # if PROJECT_DIR is set and CMAKE_SOURCE_DIR/sdkconfig if not
  328. # @param[in, optional] SDKCONFIG_DEFAULTS (single value) config defaults file to use for the build; defaults
  329. # to none (Kconfig defaults or previously generated config are used)
  330. # @param[in, optional] BUILD_DIR (single value) directory for build artifacts; defautls to CMAKE_BINARY_DIR
  331. # @param[in, optional] COMPONENTS (multivalue) select components to process among the components
  332. # known by the build system
  333. # (added via `idf_build_component`). This argument is used to trim the build.
  334. # Other components are automatically added if they are required
  335. # in the dependency chain, i.e.
  336. # the public and private requirements of the components in this list
  337. # are automatically added, and in
  338. # turn the public and private requirements of those requirements,
  339. # so on and so forth. If not specified, all components known to the build system
  340. # are processed.
  341. macro(idf_build_process target)
  342. set(options)
  343. set(single_value PROJECT_DIR PROJECT_VER PROJECT_NAME BUILD_DIR SDKCONFIG)
  344. set(multi_value COMPONENTS SDKCONFIG_DEFAULTS)
  345. cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" ${ARGN})
  346. idf_build_set_property(BOOTLOADER_BUILD "${BOOTLOADER_BUILD}")
  347. # Check build target is specified. Since this target corresponds to a component
  348. # name, the target component is automatically added to the list of common component
  349. # requirements.
  350. if(target STREQUAL "")
  351. message(FATAL_ERROR "Build target not specified.")
  352. endif()
  353. idf_build_set_property(IDF_TARGET ${target})
  354. __build_set_default(PROJECT_DIR ${CMAKE_SOURCE_DIR})
  355. __build_set_default(PROJECT_NAME ${CMAKE_PROJECT_NAME})
  356. __build_set_default(PROJECT_VER 1)
  357. __build_set_default(BUILD_DIR ${CMAKE_BINARY_DIR})
  358. idf_build_get_property(project_dir PROJECT_DIR)
  359. __build_set_default(SDKCONFIG "${project_dir}/sdkconfig")
  360. __build_set_default(SDKCONFIG_DEFAULTS "")
  361. # Check for required Python modules
  362. __build_check_python()
  363. idf_build_get_property(target IDF_TARGET)
  364. if(NOT "${target}" STREQUAL "linux")
  365. idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${target} APPEND)
  366. endif()
  367. # Call for component manager to download dependencies for all components
  368. idf_build_set_property(IDF_COMPONENT_MANAGER "$ENV{IDF_COMPONENT_MANAGER}")
  369. idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER)
  370. if(idf_component_manager)
  371. if(idf_component_manager EQUAL "0")
  372. message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
  373. elseif(idf_component_manager EQUAL "1")
  374. set(managed_components_list_file ${build_dir}/managed_components_list.temp.cmake)
  375. set(local_components_list_file ${build_dir}/local_components_list.temp.yml)
  376. set(__contents "components:\n")
  377. idf_build_get_property(__component_targets __COMPONENT_TARGETS)
  378. foreach(__component_target ${__component_targets})
  379. __component_get_property(__component_name ${__component_target} COMPONENT_NAME)
  380. __component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
  381. set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n")
  382. endforeach()
  383. file(WRITE ${local_components_list_file} "${__contents}")
  384. # Call for the component manager to prepare remote dependencies
  385. execute_process(COMMAND ${PYTHON}
  386. "-m"
  387. "idf_component_manager.prepare_components"
  388. "--project_dir=${project_dir}"
  389. "prepare_dependencies"
  390. "--local_components_list_file=${local_components_list_file}"
  391. "--managed_components_list_file=${managed_components_list_file}"
  392. RESULT_VARIABLE result
  393. ERROR_VARIABLE error)
  394. if(NOT result EQUAL 0)
  395. message(FATAL_ERROR "${error}")
  396. endif()
  397. include(${managed_components_list_file})
  398. # Add managed components to list of all components
  399. # `managed_components` contains the list of components installed by the component manager
  400. # It is defined in the temporary managed_components_list_file file
  401. set(__COMPONENTS "${__COMPONENTS};${managed_components}")
  402. file(REMOVE ${managed_components_list_file})
  403. file(REMOVE ${local_components_list_file})
  404. else()
  405. message(WARNING "IDF_COMPONENT_MANAGER environment variable is set to unknown value "
  406. "\"${idf_component_manager}\". If you want to use component manager set it to 1.")
  407. endif()
  408. else()
  409. idf_build_get_property(__component_targets __COMPONENT_TARGETS)
  410. set(__components_with_manifests "")
  411. foreach(__component_target ${__component_targets})
  412. __component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
  413. if(EXISTS "${__component_dir}/idf_component.yml")
  414. set(__components_with_manifests "${__components_with_manifests}\t${__component_dir}\n")
  415. endif()
  416. endforeach()
  417. if(NOT "${__components_with_manifests}" STREQUAL "")
  418. message(WARNING "\"idf_component.yml\" file was found for components:\n${__components_with_manifests}"
  419. "However, the component manager is not enabled.")
  420. endif()
  421. endif()
  422. # Perform early expansion of component CMakeLists.txt in CMake scripting mode.
  423. # It is here we retrieve the public and private requirements of each component.
  424. # It is also here we add the common component requirements to each component's
  425. # own requirements.
  426. __component_get_requirements()
  427. idf_build_get_property(component_targets __COMPONENT_TARGETS)
  428. # Finally, do component expansion. In this case it simply means getting a final list
  429. # of build component targets given the requirements set by each component.
  430. # Check if we need to trim the components first, and build initial components list
  431. # from that.
  432. if(__COMPONENTS)
  433. unset(component_targets)
  434. foreach(component ${__COMPONENTS})
  435. __component_get_target(component_target ${component})
  436. if(NOT component_target)
  437. message(FATAL_ERROR "Failed to resolve component '${component}'.")
  438. endif()
  439. list(APPEND component_targets ${component_target})
  440. endforeach()
  441. endif()
  442. foreach(component_target ${component_targets})
  443. __build_expand_requirements(${component_target})
  444. endforeach()
  445. idf_build_unset_property(__COMPONENT_TARGETS_SEEN)
  446. # Get a list of common component requirements in component targets form (previously
  447. # we just have a list of component names)
  448. idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
  449. foreach(common_req ${common_reqs})
  450. __component_get_target(component_target ${common_req})
  451. __component_get_property(lib ${component_target} COMPONENT_LIB)
  452. idf_build_set_property(___COMPONENT_REQUIRES_COMMON ${lib} APPEND)
  453. endforeach()
  454. # Generate config values in different formats
  455. idf_build_get_property(sdkconfig SDKCONFIG)
  456. idf_build_get_property(sdkconfig_defaults SDKCONFIG_DEFAULTS)
  457. __kconfig_generate_config("${sdkconfig}" "${sdkconfig_defaults}")
  458. __build_import_configs()
  459. # All targets built under this scope is with the ESP-IDF build system
  460. set(ESP_PLATFORM 1)
  461. idf_build_set_property(COMPILE_DEFINITIONS "-DESP_PLATFORM" APPEND)
  462. # Perform component processing (inclusion of project_include.cmake, adding component
  463. # subdirectories, creating library targets, linking libraries, etc.)
  464. __build_process_project_includes()
  465. idf_build_get_property(idf_path IDF_PATH)
  466. add_subdirectory(${idf_path} ${build_dir}/esp-idf)
  467. unset(ESP_PLATFORM)
  468. endmacro()
  469. # idf_build_executable
  470. #
  471. # @brief Specify the executable the build system can attach dependencies to (for generating
  472. # files used for linking, targets which should execute before creating the specified executable,
  473. # generating additional binary files, generating files related to flashing, etc.)
  474. function(idf_build_executable elf)
  475. # Set additional link flags for the executable
  476. idf_build_get_property(link_options LINK_OPTIONS)
  477. # Using LINK_LIBRARIES here instead of LINK_OPTIONS, as the latter is not in CMake 3.5.
  478. set_property(TARGET ${elf} APPEND PROPERTY LINK_LIBRARIES "${link_options}")
  479. # Propagate link dependencies from component library targets to the executable
  480. idf_build_get_property(link_depends __LINK_DEPENDS)
  481. set_property(TARGET ${elf} APPEND PROPERTY LINK_DEPENDS "${link_depends}")
  482. # Set the EXECUTABLE_NAME and EXECUTABLE properties since there are generator expression
  483. # from components that depend on it
  484. get_filename_component(elf_name ${elf} NAME_WE)
  485. get_target_property(elf_dir ${elf} BINARY_DIR)
  486. idf_build_set_property(EXECUTABLE_NAME ${elf_name})
  487. idf_build_set_property(EXECUTABLE ${elf})
  488. idf_build_set_property(EXECUTABLE_DIR "${elf_dir}")
  489. # Add dependency of the build target to the executable
  490. add_dependencies(${elf} __idf_build_target)
  491. endfunction()
  492. # idf_build_get_config
  493. #
  494. # @brief Get value of specified config variable
  495. function(idf_build_get_config var config)
  496. cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
  497. if(__GENERATOR_EXPRESSION)
  498. set(val "$<TARGET_PROPERTY:__idf_build_target,${config}>")
  499. else()
  500. get_property(val TARGET __idf_build_target PROPERTY ${config})
  501. endif()
  502. set(${var} ${val} PARENT_SCOPE)
  503. endfunction()