project_include.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # This is for tracking the top level project path
  2. if(BOOTLOADER_BUILD)
  3. set(main_project_path "${CMAKE_BINARY_DIR}/../..")
  4. else()
  5. set(main_project_path "${IDF_PROJECT_PATH}")
  6. endif()
  7. get_filename_component(secure_boot_signing_key
  8. "${CONFIG_SECURE_BOOT_SIGNING_KEY}"
  9. ABSOLUTE BASE_DIR "${main_project_path}")
  10. if(NOT EXISTS ${secure_boot_signing_key})
  11. # If the signing key is not found, create a phony gen_secure_boot_signing_key target that
  12. # fails the build. fail_at_build_time also touches CMakeCache.txt to cause a cmake run next time
  13. # (to pick up a new signing key if one exists, etc.)
  14. fail_at_build_time(gen_secure_boot_signing_key
  15. "Secure Boot Signing Key ${CONFIG_SECURE_BOOT_SIGNING_KEY} does not exist. Generate using:"
  16. "\tespsecure.py generate_signing_key ${CONFIG_SECURE_BOOT_SIGNING_KEY}")
  17. else()
  18. add_custom_target(gen_secure_boot_signing_key)
  19. endif()
  20. if(BOOTLOADER_BUILD OR NOT IDF_BUILD_ARTIFACTS)
  21. return() # don't keep recursing, generate on project builds
  22. endif()
  23. # Glue to build the bootloader subproject binary as an external
  24. # cmake project under this one
  25. #
  26. #
  27. set(bootloader_build_dir "${IDF_BUILD_ARTIFACTS_DIR}/bootloader")
  28. set(bootloader_binary_files
  29. "${bootloader_build_dir}/bootloader.elf"
  30. "${bootloader_build_dir}/bootloader.bin"
  31. "${bootloader_build_dir}/bootloader.map"
  32. )
  33. # These additional files may get generated
  34. if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
  35. set(bootloader_binary_files
  36. ${bootloader_binary_files}
  37. "${bootloader_build_dir}/bootloader-reflash-digest.bin"
  38. "${bootloader_build_dir}/secure-bootloader-key-192.bin"
  39. "${bootloader_build_dir}/secure-bootloader-key-256.bin"
  40. )
  41. endif()
  42. if((NOT CONFIG_SECURE_BOOT_ENABLED) OR
  43. CONFIG_SECURE_BOOTLOADER_REFLASHABLE OR
  44. CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH)
  45. externalproject_add(bootloader
  46. # TODO: support overriding the bootloader in COMPONENT_PATHS
  47. SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/subproject"
  48. BINARY_DIR "${bootloader_build_dir}"
  49. CMAKE_ARGS -DSDKCONFIG=${SDKCONFIG} -DIDF_PATH=${IDF_PATH}
  50. -DSECURE_BOOT_SIGNING_KEY=${secure_boot_signing_key}
  51. -DEXTRA_COMPONENT_DIRS=${CMAKE_CURRENT_LIST_DIR}
  52. INSTALL_COMMAND ""
  53. BUILD_ALWAYS 1 # no easy way around this...
  54. BUILD_BYPRODUCTS ${bootloader_binary_files}
  55. DEPENDS gen_secure_boot_signing_key
  56. )
  57. else()
  58. fail_at_build_time(bootloader "Invalid bootloader target: bad sdkconfig?")
  59. endif()
  60. # this is a hack due to an (annoying) shortcoming in cmake, it can't
  61. # extend the 'clean' target to the external project
  62. # see thread: https://cmake.org/pipermail/cmake/2016-December/064660.html
  63. #
  64. # So for now we just have the top-level build remove the final build products...
  65. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  66. ADDITIONAL_MAKE_CLEAN_FILES
  67. ${bootloader_binary_files})