Findpicotool.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Finds (or builds) the picotool executable
  2. #
  3. # This will define the following imported targets
  4. #
  5. # picotool
  6. #
  7. cmake_minimum_required(VERSION 3.17)
  8. if (NOT TARGET picotool)
  9. include(ExternalProject)
  10. if (DEFINED ENV{PICOTOOL_FETCH_FROM_GIT_PATH} AND (NOT PICOTOOL_FETCH_FROM_GIT_PATH))
  11. set(PICOTOOL_FETCH_FROM_GIT_PATH $ENV{PICOTOOL_FETCH_FROM_GIT_PATH})
  12. message("Using PICOTOOL_FETCH_FROM_GIT_PATH from environment ('${PICOTOOL_FETCH_FROM_GIT_PATH}')")
  13. endif ()
  14. include(FetchContent)
  15. if (PICOTOOL_FETCH_FROM_GIT_PATH)
  16. get_filename_component(picotool_INSTALL_DIR "${PICOTOOL_FETCH_FROM_GIT_PATH}" ABSOLUTE)
  17. else ()
  18. get_filename_component(picotool_INSTALL_DIR "${FETCHCONTENT_BASE_DIR}" ABSOLUTE)
  19. endif ()
  20. set(picotool_INSTALL_DIR ${picotool_INSTALL_DIR} CACHE PATH "Directory where picotool has been installed" FORCE)
  21. set(picotool_BUILD_TARGET picotoolBuild)
  22. set(picotool_TARGET picotool)
  23. if (NOT TARGET ${picotool_BUILD_TARGET})
  24. if (NOT PICOTOOL_FETCH_FROM_GIT_PATH)
  25. message(WARNING
  26. "No installed picotool with version ${picotool_VERSION_REQUIRED} found - building from source\n"
  27. "It is recommended to build and install picotool separately, or to set PICOTOOL_FETCH_FROM_GIT_PATH "
  28. "to a common directory for all your SDK projects"
  29. )
  30. endif()
  31. message("Downloading Picotool")
  32. FetchContent_Populate(picotool QUIET
  33. GIT_REPOSITORY https://github.com/raspberrypi/picotool.git
  34. GIT_TAG develop
  35. SOURCE_DIR ${picotool_INSTALL_DIR}/picotool-src
  36. BINARY_DIR ${picotool_INSTALL_DIR}/picotool-build
  37. SUBBUILD_DIR ${picotool_INSTALL_DIR}/picotool-subbuild
  38. )
  39. add_custom_target(picotoolForceReconfigure
  40. ${CMAKE_COMMAND} -E touch_nocreate "${CMAKE_SOURCE_DIR}/CMakeLists.txt"
  41. VERBATIM)
  42. ExternalProject_Add(${picotool_BUILD_TARGET}
  43. PREFIX picotool
  44. SOURCE_DIR ${picotool_SOURCE_DIR}
  45. BINARY_DIR ${picotool_BINARY_DIR}
  46. INSTALL_DIR ${picotool_INSTALL_DIR}
  47. DEPENDS picotoolForceReconfigure
  48. CMAKE_ARGS
  49. "--no-warn-unused-cli"
  50. "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}"
  51. "-DPICO_SDK_PATH:FILEPATH=${PICO_SDK_PATH}"
  52. "-DPICOTOOL_NO_LIBUSB=1"
  53. "-DPICOTOOL_FLAT_INSTALL=1"
  54. "-DCMAKE_INSTALL_PREFIX=${picotool_INSTALL_DIR}"
  55. "-DCMAKE_RULE_MESSAGES=OFF" # quieten the build
  56. "-DCMAKE_INSTALL_MESSAGE=NEVER" # quieten the install
  57. BUILD_ALWAYS 1 # force dependency checking
  58. EXCLUDE_FROM_ALL TRUE
  59. TEST_COMMAND
  60. ${picotool_INSTALL_DIR}/picotool/picotool
  61. version ${picotool_VERSION_REQUIRED}
  62. TEST_AFTER_INSTALL TRUE
  63. )
  64. endif()
  65. set(picotool_EXECUTABLE ${picotool_INSTALL_DIR}/picotool/picotool)
  66. add_executable(${picotool_TARGET} IMPORTED GLOBAL)
  67. set_property(TARGET ${picotool_TARGET} PROPERTY IMPORTED_LOCATION
  68. ${picotool_EXECUTABLE})
  69. add_dependencies(${picotool_TARGET} ${picotool_BUILD_TARGET})
  70. endif()